:root {
  color-scheme: dark;
  --background: #1e1f22;
  --card: #2b2d31;
  --border: #3f4147;
  --text: #f2f3f5;
  --muted: #b5bac1;
  --accent: #5865f2;
  --accent-hover: #4752c4;
  --danger: #f38b8d;
  --good: #3ba55d;
  --shadow: rgb(0 0 0 / 40%);
}

/* Chosen in the ⚙️ menu; app.js sets data-theme on <html>. */
:root[data-theme='light'] {
  color-scheme: light;
  --background: #f2f3f5;
  --card: #ffffff;
  --border: #d4d7dc;
  --text: #060607;
  --muted: #5c5e66;
  --accent: #5865f2;
  --accent-hover: #4752c4;
  --danger: #d83c3e;
  --good: #248046;
  --shadow: rgb(0 0 0 / 15%);
}

* {
  box-sizing: border-box;
}

html,
body {
  height: 100%;
  margin: 0;
}

body {
  background: var(--background);
  color: var(--text);
  font-family: system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
  line-height: 1.5;
}

/* `display` rules below would otherwise win over the hidden attribute. */
[hidden] {
  display: none !important;
}

button {
  border: 0;
  border-radius: 8px;
  background: var(--accent);
  color: #fff;
  font: inherit;
  font-weight: 600;
  cursor: pointer;
}

button:hover {
  background: var(--accent-hover);
}

button:disabled {
  opacity: 0.6;
  cursor: default;
}

button:focus-visible,
input:focus-visible {
  outline: 2px solid var(--text);
  outline-offset: 2px;
}

/* --- the loading screen --- */

.boot {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100%;
  padding: 16px;
}

.card {
  width: 100%;
  max-width: 440px;
  padding: 28px 24px;
  border: 1px solid var(--border);
  border-radius: 16px;
  background: var(--card);
  text-align: center;
}

.card h1 {
  margin: 0 0 8px;
  font-size: 2rem;
}

.boot-globe {
  font-size: 4rem;
  line-height: 1;
  animation: bob 2.4s ease-in-out infinite;
}

.boot[data-stage='failed'] .boot-globe,
.boot[data-stage='outside'] .boot-globe {
  animation: none;
}

@keyframes bob {
  0%,
  100% {
    transform: translateY(0);
  }

  50% {
    transform: translateY(-6px);
  }
}

.status {
  min-height: 3em; /* two lines, so the bar doesn't jump when the text changes */
  margin: 0 0 16px;
  color: var(--muted);
}

/* The bar grows stage by stage (the stage names are the keys of STAGES in app.js). */
.progress {
  height: 6px;
  overflow: hidden;
  border-radius: 3px;
  background: var(--border);
}

.progress-bar {
  width: 0;
  height: 100%;
  border-radius: 3px;
  background: var(--accent);
  transition: width 0.4s ease-out, background-color 0.2s;
}

.boot[data-stage='backend'] .progress-bar {
  width: 15%;
}

.boot[data-stage='sdk'] .progress-bar {
  width: 35%;
}

.boot[data-stage='authorize'] .progress-bar {
  width: 55%;
}

.boot[data-stage='login'] .progress-bar {
  width: 75%;
}

.boot[data-stage='game'] .progress-bar {
  width: 90%;
}

.boot[data-stage='failed'] .progress-bar {
  width: 100%;
  background: var(--danger);
}

.boot[data-stage='outside'] .progress {
  visibility: hidden;
}

.hint {
  margin: 12px 0 0;
  font-size: 0.9rem;
}

.boot-retry {
  margin-top: 20px;
  padding: 10px 20px;
}

.tip {
  margin: 20px 0 0;
  color: var(--muted);
  font-size: 0.85rem;
}

.boot-details {
  margin-top: 20px;
  color: var(--muted);
  font-size: 0.8rem;
  text-align: left;
}

.boot-details summary {
  text-align: center;
  cursor: pointer;
}

.boot-detail {
  margin: 8px 0 0;
  white-space: pre-line;
  overflow-wrap: anywhere;
}

.build {
  margin: 24px 0 0;
  color: var(--muted);
  font-size: 0.8rem;
}

.boot-details .build {
  margin-top: 8px;
}

.errors {
  position: fixed;
  right: 8px;
  bottom: 8px;
  left: 8px;
  z-index: 10;
  max-height: 40%;
  margin: 0;
  padding: 12px;
  overflow: auto;
  border: 1px solid var(--danger);
  border-radius: 8px;
  background: var(--card);
  color: var(--danger);
  font-family: ui-monospace, 'Cascadia Mono', Consolas, monospace;
  font-size: 0.8rem;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

/* --- the game --- */

.app {
  display: flex;
  flex-direction: column;
  height: 100%;
  animation: fade-in 0.3s ease-out;
}

@keyframes fade-in {
  from {
    opacity: 0;
  }
}

/* For players who asked their system for less motion. */
@media (prefers-reduced-motion: reduce) {
  .boot-globe,
  .app {
    animation: none;
  }

  .progress-bar {
    transition: none;
  }
}

.top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 8px 12px;
  border-bottom: 1px solid var(--border);
  background: var(--card);
  /* The settings panel hangs from the bar. */
  position: relative;
}

.title {
  min-width: 0;
  margin: 0;
  overflow: hidden;
  font-size: 1.15rem;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.tabs {
  display: flex;
  gap: 6px;
}

.tab {
  padding: 6px 14px;
  background: transparent;
  color: var(--muted);
}

.tab:hover {
  background: var(--border);
}

.tab[aria-pressed='true'] {
  background: var(--accent);
  color: #fff;
}

/* Tabs and ⚙️ in one row that never wraps; on a narrow phone the title gives way instead. */
.top-actions {
  display: flex;
  flex-shrink: 0;
  align-items: center;
  gap: 6px;
}

.settings-button {
  width: 36px;
  height: 36px;
  padding: 0;
  font-size: 1.1rem;
  line-height: 1;
}

.settings-button[aria-expanded='true'] {
  background: var(--border);
}

/* The ⚙️ menu: under the button, above the globe. */
.settings {
  position: absolute;
  top: calc(100% + 4px);
  right: 8px;
  z-index: 6;
  display: grid;
  gap: 2px;
  min-width: 220px;
  padding: 6px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--card);
  box-shadow: 0 4px 16px var(--shadow);
}

.setting {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 10px;
  border-radius: 6px;
  cursor: pointer;
}

.setting:hover {
  background: var(--border);
}

.setting input {
  width: 20px;
  height: 20px;
  margin: 0;
  accent-color: var(--accent);
  cursor: pointer;
}

/* Phone (portrait): globe on top, guesses below. Wide window: side by side. */
.game {
  display: grid;
  flex: 1;
  grid-template-rows: minmax(0, 11fr) minmax(0, 9fr);
  min-height: 0;
}

@media (min-width: 720px) and (min-aspect-ratio: 1/1) {
  .game {
    grid-template-rows: minmax(0, 1fr);
    grid-template-columns: minmax(0, 3fr) minmax(280px, 2fr);
  }

  .panel {
    border-top: 0;
    border-left: 1px solid var(--border);
  }
}

.globe-wrap {
  position: relative;
  min-width: 0;
  min-height: 0;
}

.globe {
  display: block;
  width: 100%;
  height: 100%;
  cursor: grab;
  /* The globe handles dragging and pinching itself; the browser must not scroll or zoom the page. */
  touch-action: none;
}

.globe:active {
  cursor: grabbing;
}

.zoom {
  position: absolute;
  right: 10px;
  bottom: 10px;
  display: grid;
  gap: 6px;
}

.zoom button {
  width: 36px;
  height: 36px;
  background: var(--card);
  border: 1px solid var(--border);
  font-size: 1.2rem;
  line-height: 1;
}

.zoom button:hover {
  background: var(--border);
}

.panel {
  display: flex;
  flex-direction: column;
  gap: 8px;
  min-width: 0;
  min-height: 0;
  padding: 12px;
  border-top: 1px solid var(--border);
}

.count {
  margin: 0;
  color: var(--muted);
  font-size: 0.9rem;
}

.guess-form {
  position: relative;
  display: flex;
  gap: 8px;
}

.guess-input {
  flex: 1;
  min-width: 0;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--background);
  color: var(--text);
  /* 16px or more, or phones zoom the page when the field is focused. */
  font: inherit;
  font-size: 1rem;
}

.guess-button {
  padding: 10px 16px;
}

/* Opens upwards: on a phone the keyboard covers whatever is below the input. */
.suggestions {
  position: absolute;
  right: 0;
  bottom: calc(100% + 4px);
  left: 0;
  z-index: 5;
  margin: 0;
  padding: 4px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--card);
  box-shadow: 0 4px 16px var(--shadow);
  list-style: none;
}

/* In the wide layout the input sits at the top of the window, so there the list opens downwards. */
@media (min-width: 720px) and (min-aspect-ratio: 1/1) {
  .suggestions {
    top: calc(100% + 4px);
    bottom: auto;
  }
}

.suggestion {
  padding: 8px 10px;
  border-radius: 6px;
  cursor: pointer;
}

.suggestion:hover,
.suggestion.active {
  background: var(--accent);
  color: #fff;
}

.message {
  min-height: 1.5em;
  margin: 0;
  font-size: 0.95rem;
}

.message.error {
  color: var(--danger);
}

.win {
  padding: 12px;
  border: 1px solid var(--good);
  border-radius: 12px;
  text-align: center;
}

.win p {
  margin: 0;
}

.win-title {
  font-size: 1.3rem;
  font-weight: 700;
}

.win-squares {
  margin: 6px 0;
  overflow-wrap: anywhere;
}

.win-next,
.win-detail {
  color: var(--muted);
}

.countdown {
  color: var(--text);
  font-variant-numeric: tabular-nums;
}

.guesses {
  flex: 1;
  min-height: 0;
  margin: 0;
  padding: 0;
  overflow-y: auto;
  list-style: none;
}

.guess {
  display: grid;
  grid-template-columns: 1.6em minmax(0, 1fr) auto;
  gap: 8px;
  align-items: baseline;
  padding: 6px 4px;
  border-bottom: 1px solid var(--border);
  cursor: pointer;
}

.guess:hover {
  background: var(--card);
}

.guess .name {
  overflow-wrap: anywhere;
}

.guess .km {
  color: var(--muted);
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

/* --- ranking tab --- */

.ranking {
  flex: 1;
  width: 100%;
  max-width: 640px;
  min-height: 0;
  margin: 0 auto;
  padding: 4px 16px 24px;
  overflow-y: auto;
}

.ranking h2 {
  margin: 20px 0 8px;
  font-size: 1.05rem;
}

.rows {
  margin: 0;
  padding: 0;
  list-style: none;
}

.row {
  display: flex;
  flex-wrap: wrap;
  gap: 4px 10px;
  align-items: baseline;
  padding: 8px 4px;
  border-bottom: 1px solid var(--border);
}

.row .place {
  min-width: 1.8em;
}

.row .name {
  font-weight: 600;
  overflow-wrap: anywhere;
}

.row .points {
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}

.row .detail {
  margin-left: auto;
  color: var(--muted);
  font-size: 0.9rem;
}

.empty,
.note,
.rules {
  color: var(--muted);
}

.rules {
  margin-top: 24px;
  font-size: 0.9rem;
}
