:root {
  color-scheme: dark;
  --page: #10141b;
  --panel: #171d27;
  --panel-2: #202a37;
  --ink: #f8fbff;
  --muted: #aeb9c8;
  --line: #344256;
  --cyan: #2ecbe0;
  --green: #81c91d;
  --red: #df2a46;
  --orange: #f28d22;
  --gold: #f5cf48;
}

* {
  box-sizing: border-box;
}

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

body {
  overflow: hidden;
  color: var(--ink);
  background: var(--page);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

button,
input {
  font: inherit;
}

.shell {
  display: grid;
  grid-template-rows: 54px minmax(0, 1fr);
  min-height: 100vh;
}

.topbar {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto;
  align-items: center;
  gap: 10px;
  height: 54px;
  padding: 0 16px;
  background: var(--panel);
  border-bottom: 1px solid var(--line);
}

.brand-mark {
  width: 54px;
  height: 34px;
  object-fit: contain;
  filter: drop-shadow(0 2px 0 rgba(0, 0, 0, 0.28));
}

.topbar strong {
  overflow: hidden;
  font-weight: 800;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.top-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

.auth-panel {
  display: flex;
  align-items: center;
  gap: 8px;
  min-height: 36px;
  padding: 4px 8px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.04);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.05);
}

.auth-panel span {
  overflow: hidden;
  max-width: 126px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.auth-panel.is-signed-in span {
  color: var(--green);
}

.auth-panel.is-disabled span {
  color: var(--orange);
}

.auth-button {
  min-width: 70px;
  height: 28px;
  padding: 0 10px;
  border: 1px solid var(--line);
  border-radius: 7px;
  color: var(--ink);
  background: rgba(255, 255, 255, 0.07);
  font-size: 12px;
  font-weight: 900;
  cursor: pointer;
}

.auth-button:hover,
.auth-button:focus-visible {
  border-color: rgba(74, 190, 255, 0.7);
  outline: none;
  background: rgba(74, 190, 255, 0.15);
}

.icon-button {
  display: grid;
  place-items: center;
  position: relative;
  width: 36px;
  height: 36px;
  padding: 0;
  color: var(--ink);
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: 6px;
  cursor: pointer;
}

.icon-button > svg {
  grid-area: 1 / 1;
}

.icon-button .off-mark {
  display: none;
}

.icon-button.is-off {
  color: var(--muted);
}

.icon-button.is-off .off-mark {
  display: block;
}

.icon-button:hover,
.icon-button:focus-visible {
  border-color: var(--cyan);
  outline: none;
}

.game-card {
  display: grid;
  place-items: center;
  min-height: 0;
  padding: 16px;
}

.stage {
  position: relative;
  width: min(100%, calc((100vh - 86px) * 970 / 728));
  max-width: 970px;
  aspect-ratio: 970 / 728;
  overflow: hidden;
  background: #179ce8;
  border: 1px solid #188fd0;
  border-radius: 8px;
  box-shadow: 0 26px 80px rgba(0, 0, 0, 0.42);
}

canvas {
  display: block;
  width: 100%;
  height: 100%;
}

.game-controls {
  position: absolute;
  z-index: 6;
  top: 16px;
  left: 16px;
  display: flex;
  gap: 10px;
}

.game-controls[hidden] {
  display: none;
}

.round-control {
  display: grid;
  place-items: center;
  width: 54px;
  height: 54px;
  padding: 0;
  color: #fff;
  background: #f32918;
  border: 4px solid #071018;
  border-radius: 18px;
  box-shadow: 0 6px 0 rgba(0, 0, 0, 0.28);
  cursor: pointer;
}

.round-control.exit {
  border-radius: 10px 22px 22px 10px;
}

.round-control:hover,
.round-control:focus-visible {
  transform: translateY(-1px);
  outline: none;
}

.screen,
.hud {
  position: absolute;
  inset: 0;
}

.screen {
  z-index: 4;
  display: grid;
  place-items: center;
  padding: 32px;
  background: rgba(13, 20, 30, 0.28);
}

.screen[hidden],
.hud[hidden] {
  display: none;
}

.screen-menu {
  gap: 34px;
  background: rgba(26, 163, 232, 0.2);
}

.screen-practice {
  background: rgba(13, 20, 30, 0.38);
}

.logo {
  width: min(52%, 360px);
  height: auto;
  filter: drop-shadow(0 12px 0 rgba(0, 0, 0, 0.18));
}

.menu-actions,
.result-actions {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 12px;
}

.game-button {
  min-width: 176px;
  min-height: 58px;
  padding: 0 20px;
  color: #fff;
  font-weight: 900;
  text-transform: uppercase;
  letter-spacing: 0;
  border: 0;
  border-radius: 8px;
  cursor: pointer;
  box-shadow: inset 0 -7px 0 rgba(0, 0, 0, 0.22), 0 8px 0 rgba(0, 0, 0, 0.12);
}

.game-button:hover,
.game-button:focus-visible {
  transform: translateY(-1px);
  outline: none;
}

.game-button.primary {
  background: var(--red);
}

.game-button.secondary {
  background: var(--orange);
}

.game-button.accent {
  background: var(--green);
}

.game-button.login {
  background: var(--cyan);
}

.game-button:disabled {
  cursor: default;
  opacity: 0.72;
  transform: none;
}

.hud {
  z-index: 2;
  pointer-events: none;
  display: grid;
  grid-template-columns: 150px minmax(0, 1fr) 150px;
  align-items: start;
  gap: 12px;
  padding: 14px 14px 14px 148px;
}

.score-box,
.timer-box,
.question-box {
  padding: 12px 14px;
  background: rgba(20, 32, 44, 0.88);
  border: 1px solid rgba(255, 255, 255, 0.22);
  border-radius: 8px;
}

.score-box,
.timer-box {
  display: grid;
  gap: 2px;
}

.score-box span,
.timer-box span {
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
  text-transform: uppercase;
}

.score-box strong,
.timer-box strong {
  font-size: 28px;
  line-height: 1;
}

.question-box {
  min-height: 62px;
  font-size: 23px;
  font-weight: 900;
  text-align: center;
}

.hud.is-flags {
  grid-template-columns: minmax(0, 1fr) 150px;
  padding: 14px;
}

.hud.is-flags .score-box,
.hud.is-flags .question-box {
  display: none;
}

.hud.is-flags .timer-box {
  grid-column: 2;
  justify-self: end;
  width: 150px;
}

.flag-game {
  position: absolute;
  inset: 0;
  z-index: 3;
  display: grid;
  place-items: start center;
  padding: 88px 34px 42px;
  pointer-events: none;
}

.flag-game[hidden] {
  display: none;
}

.flag-panel {
  display: grid;
  position: relative;
  z-index: 2;
  gap: 10px;
  width: min(92%, 720px);
  pointer-events: auto;
}

.flag-status {
  display: grid;
  justify-items: center;
  gap: 2px;
  width: min(72%, 390px);
  justify-self: center;
  padding: 9px 18px 11px;
  background: #082d4b;
  border: 6px solid #071018;
  border-radius: 8px;
  box-shadow: 0 0 0 5px rgba(235, 238, 237, 0.88), 0 10px 0 rgba(0, 0, 0, 0.22);
}

.flag-status span {
  color: var(--muted);
  font-size: 12px;
  font-weight: 900;
  text-transform: uppercase;
}

.flag-status strong {
  font-size: clamp(24px, 4vw, 42px);
  line-height: 1.05;
  text-align: center;
}

.flag-progress {
  height: 14px;
  overflow: hidden;
  background: rgba(16, 24, 34, 0.84);
  border: 1px solid rgba(255, 255, 255, 0.22);
  border-radius: 999px;
}

.flag-progress span {
  display: block;
  width: 100%;
  height: 100%;
  background: var(--green);
  border-radius: inherit;
  transform: scaleX(1);
  transform-origin: left;
}

.flag-lamps {
  display: grid;
  grid-template-columns: repeat(8, 1fr);
  gap: 5px;
  width: min(62%, 340px);
  justify-self: center;
  padding: 4px 8px;
  background: rgba(7, 16, 24, 0.7);
  border-radius: 999px;
  box-shadow: inset 0 -3px 0 rgba(0, 0, 0, 0.22);
}

.flag-lamps span {
  height: 11px;
  background: #10395e;
  border: 1px solid rgba(255, 255, 255, 0.16);
  border-radius: 999px;
}

.flag-lamps span.is-on {
  background: #f5cf48;
  box-shadow: 0 0 12px rgba(245, 207, 72, 0.82);
}

.flag-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 16px 34px;
  padding: 6px 34px 0;
}

.flag-choice {
  position: relative;
  display: grid;
  place-items: center;
  min-height: 112px;
  padding: 14px 18px;
  background: rgba(8, 45, 75, 0.58);
  border: 3px solid rgba(255, 255, 255, 0.72);
  border-radius: 8px;
  box-shadow: inset 0 -5px 0 rgba(0, 0, 0, 0.18), 0 8px 0 rgba(0, 0, 0, 0.18);
  cursor: pointer;
  animation: flagPopIn 260ms cubic-bezier(0.19, 1, 0.22, 1) both;
  animation-delay: var(--enter-delay, 0ms);
}

.flag-choice:hover,
.flag-choice:focus-visible {
  outline: none;
  transform: translateY(-2px);
}

.flag-choice img {
  display: block;
  width: 100%;
  max-width: 150px;
  max-height: 76px;
  object-fit: contain;
  background: rgba(255, 255, 255, 0.96);
  border-radius: 3px;
  box-shadow: 0 4px 0 rgba(0, 0, 0, 0.16);
}

.flag-choice.is-correct {
  border-color: var(--green);
  box-shadow: inset 0 -5px 0 rgba(0, 0, 0, 0.18), 0 0 0 5px rgba(129, 201, 29, 0.34), 0 8px 0 rgba(0, 0, 0, 0.18);
}

.flag-choice.is-wrong {
  opacity: 0.8;
  animation: flagWrong 320ms ease-out both;
}

.flag-choice.is-selected.is-correct {
  animation: flagCorrect 360ms ease-out both;
  z-index: 12;
}

.flag-feedback {
  min-height: 32px;
  color: var(--gold);
  font-size: 22px;
  font-weight: 900;
  text-align: center;
  text-shadow: 0 3px 0 rgba(0, 0, 0, 0.34);
}

.pause-screen {
  z-index: 7;
  background: rgba(9, 15, 23, 0.52);
}

.pause-panel {
  width: min(92%, 460px);
}

.practice-panel {
  width: min(92%, 520px);
}

@keyframes flagPopIn {
  from {
    opacity: 0;
    transform: translateY(-18px) scale(0.8);
  }

  70% {
    opacity: 1;
    transform: translateY(5px) scale(1.04);
  }

  to {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
}

@keyframes flagCorrect {
  50% {
    transform: translateY(-4px) scale(1.08);
  }

  to {
    transform: translateY(0) scale(1);
  }
}

@keyframes flagWrong {
  20% {
    transform: translateX(-10px) rotate(-3deg);
  }

  55% {
    transform: translateX(8px) rotate(3deg);
  }

  to {
    transform: translateX(0) rotate(0);
  }
}

.result-panel {
  display: grid;
  gap: 18px;
  width: min(94%, 560px);
  padding: 24px;
  text-align: center;
  background: rgba(28, 38, 51, 0.94);
  border: 1px solid rgba(255, 255, 255, 0.2);
  border-radius: 8px;
  box-shadow: 0 18px 50px rgba(0, 0, 0, 0.35);
}

.result-panel h1 {
  margin: 0;
  font-size: 34px;
  letter-spacing: 0;
}

.result-panel p {
  margin: 0;
  color: var(--muted);
  font-size: 18px;
  line-height: 1.45;
}

.name-field {
  display: grid;
  gap: 8px;
  text-align: left;
}

.name-field span {
  color: var(--muted);
  font-size: 13px;
  font-weight: 800;
  text-transform: uppercase;
}

.name-field input {
  width: 100%;
  min-height: 46px;
  padding: 0 12px;
  color: var(--ink);
  background: #101722;
  border: 1px solid var(--line);
  border-radius: 6px;
}

.leaderboard-panel {
  width: min(94%, 620px);
}

#scoreList {
  display: grid;
  gap: 8px;
  max-height: 310px;
  margin: 0;
  padding: 0;
  overflow: auto;
  list-style-position: inside;
}

#scoreList li {
  display: grid;
  grid-template-columns: 42px minmax(0, 1fr) auto;
  align-items: center;
  gap: 12px;
  padding: 10px 12px;
  text-align: left;
  background: rgba(255, 255, 255, 0.08);
  border-radius: 6px;
}

#scoreList .score-name {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

#scoreList .score-value {
  color: var(--gold);
  font-weight: 900;
}

@media (max-width: 720px) {
  body {
    overflow: auto;
  }

  .game-card {
    padding: 10px;
  }

  .topbar {
    gap: 8px;
    padding: 8px 10px;
  }

  .topbar strong {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  .auth-panel {
    gap: 6px;
    padding: 4px 6px;
  }

  .auth-panel span {
    display: none;
  }

  .auth-button {
    min-width: 62px;
    padding: 0 8px;
  }

  .stage {
    width: 100%;
    max-height: calc(100vh - 74px);
  }

  .hud {
    grid-template-columns: 1fr 1fr;
    padding: 72px 10px 10px;
  }

  .question-box {
    grid-column: 1 / -1;
    grid-row: 2;
    font-size: 18px;
  }

  .flag-game {
    padding: 116px 14px 18px;
  }

  .flag-panel {
    width: 100%;
    gap: 10px;
  }

  .flag-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 10px;
    padding: 0;
  }

  .flag-choice {
    min-height: 104px;
    padding: 12px;
  }

  .flag-lamps {
    width: 76%;
  }

  .game-controls {
    top: 10px;
    left: 10px;
  }

  .round-control {
    width: 44px;
    height: 44px;
    border-width: 3px;
  }

  .game-button {
    min-width: 138px;
    min-height: 52px;
  }
}
