: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; hub.js sets data-theme on <html>. Games use these variables too. */
: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-icon {
  font-size: 4rem;
  line-height: 1;
  animation: bob 2.4s ease-in-out infinite;
}

.boot[data-stage='failed'] .boot-icon,
.boot[data-stage='outside'] .boot-icon {
  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 hub.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-button {
  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;
}

/* --- buttons the hub and the games share --- */

.primary-button {
  padding: 10px 16px;
  font-size: 1rem;
}

/* --- the shell: top bar, then the menu or a game --- */

.shell {
  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-icon,
  .shell,
  .game-root {
    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 {
  flex: 1; /* next to „← Gry”, pushing ⚙️ to the right */
  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 game. */
.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;
}


/* The game's own settings, under the theme; only while that game is open. */
.game-settings {
  display: grid;
  gap: 2px;
  padding-top: 2px;
  border-top: 1px solid var(--border);
}

/* Back to the list of games: an arrow and a word, like a browser's back. */
.back-button {
  display: flex;
  flex-shrink: 0;
  gap: 6px;
  align-items: center;
  padding: 6px 12px 6px 8px;
  color: var(--text);
  white-space: nowrap;
}

.back-arrow {
  font-size: 1.2rem;
  line-height: 1;
  transition: transform 0.15s ease-out;
}

.back-button:hover .back-arrow {
  transform: translateX(-3px);
}

@media (prefers-reduced-motion: reduce) {
  .back-arrow {
    transition: none;
  }
}

/* --- the menu --- */

.menu {
  flex: 1;
  width: 100%;
  max-width: 560px;
  min-height: 0;
  margin: 0 auto;
  padding: 16px;
  overflow-y: auto;
}

.menu-games {
  display: grid;
  gap: 12px;
  margin: 0;
  padding: 0;
  list-style: none;
}

.game-choice {
  display: flex;
  gap: 14px;
  align-items: center;
  width: 100%;
  padding: 14px 16px;
  border: 1px solid var(--border);
  background: var(--card);
  color: var(--text);
  text-align: left;
}

.game-choice:hover {
  border-color: var(--accent);
  background: var(--card);
}

.game-choice:disabled:hover {
  border-color: var(--border);
}

.choice-icon {
  font-size: 2.2rem;
  line-height: 1;
}

.choice-text {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.choice-name {
  font-size: 1.1rem;
  font-weight: 700;
}

.choice-about,
.choice-status {
  color: var(--muted);
  font-size: 0.9rem;
}

.choice-status:empty {
  display: none;
}

.menu .build {
  margin-top: 20px;
  text-align: center;
}

/* --- where games live: one section per game, only the open one shown --- */

.stage {
  display: flex;
  flex: 1;
  flex-direction: column;
  min-height: 0;
}

.game-root {
  display: flex;
  flex: 1;
  flex-direction: column;
  min-height: 0;
  animation: fade-in 0.3s ease-out;
}

/* --- lists the games share (rankings) --- */

.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;
}
