:root {
  color-scheme: light;
  --ink: #172033;
  --line: rgba(23, 32, 51, 0.16);
  --blue: #2563eb;
  --green: #15803d;
  --red: #c2410c;
  --gold: #d79b14;
  --panel: rgba(255, 255, 255, 0.94);
}

* {
  box-sizing: border-box;
}

html,
body {
  width: 100%;
  height: 100%;
  min-height: 100%;
  margin: 0;
  overflow: hidden;
  font-family: "Segoe UI", system-ui, sans-serif;
  color: var(--ink);
  background: #dff2ff;
}

body {
  min-height: 100dvh;
  overscroll-behavior: none;
}

button,
input,
a {
  font: inherit;
}

.game-shell {
  width: min(100vw, 1180px);
  height: 100vh;
  height: 100dvh;
  margin: 0 auto;
  display: grid;
  grid-template-rows: minmax(0, 1fr) auto;
  gap: 10px;
  padding: 12px 12px max(12px, env(safe-area-inset-bottom));
  position: relative;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

canvas {
  width: 100%;
  height: 100%;
  min-height: 0;
  border: 1px solid rgba(23, 32, 51, 0.18);
  border-radius: 8px;
  background: #bce4ff;
  box-shadow: 0 14px 45px rgba(19, 56, 101, 0.18);
  touch-action: none;
}

.image-button,
.fullscreen-button {
  position: absolute;
  z-index: 4;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 44px;
  border: 1px solid rgba(23, 32, 51, 0.18);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.86);
  color: #172033;
  line-height: 1;
  box-shadow: 0 12px 28px rgba(19, 56, 101, 0.14);
  text-decoration: none;
  font-weight: 900;
  backdrop-filter: blur(6px);
}

.fullscreen-button {
  top: 20px;
  right: 20px;
  width: 44px;
  padding: 0;
  font-size: 26px;
}

.back-image-button {
  top: 20px;
  left: 20px;
  padding: 0 14px;
  font-size: 13px;
}

.new-round-image-button {
  top: 20px;
  right: 72px;
  min-height: 44px;
  padding: 0 14px;
  font-size: 13px;
}

.fullscreen-button:disabled {
  display: none;
}

.math-panel {
  width: min(620px, 100%);
  margin: 0 auto;
}

.task-card {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: 0 8px 26px rgba(19, 56, 101, 0.11);
}

.scoreboard {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 6px;
  align-items: center;
  padding: 10px;
  text-align: center;
  font-weight: 900;
}

.scoreboard span {
  min-width: 0;
  padding: 8px 6px;
  border-radius: 8px;
  background: #eef7ff;
  font-size: 15px;
}

.task-card {
  padding: 10px;
}

.task-card p,
.task-card h1 {
  margin: 0;
}

#turnLabel {
  font-size: 14px;
  font-weight: 900;
  color: #315b87;
}

#questionText {
  margin-top: 3px;
  min-height: 32px;
  font-size: 21px;
  line-height: 1.2;
}

label {
  display: block;
  margin-bottom: 5px;
  font-size: 13px;
  font-weight: 900;
}

.answer-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 8px;
}

input {
  min-height: 46px;
  width: 100%;
  border: 2px solid rgba(23, 32, 51, 0.18);
  border-radius: 8px;
  padding: 0 12px;
  background: white;
  color: #172033;
  font-size: 22px;
  font-weight: 900;
}

button,
 .actions a {
  min-height: 46px;
  border: 0;
  border-radius: 8px;
  padding: 0 16px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  color: white;
  background: var(--blue);
  text-decoration: none;
  font-weight: 900;
  cursor: pointer;
  box-shadow: inset 0 -2px 0 rgba(0, 0, 0, 0.18);
}

.image-button,
.fullscreen-button {
  border: 1px solid rgba(23, 32, 51, 0.18);
  background: rgba(255, 255, 255, 0.86);
  color: #172033;
  box-shadow: 0 12px 28px rgba(19, 56, 101, 0.14);
}

#fireBtn {
  background: var(--gold);
  color: #211600;
}

button:active,
.actions a:active,
.image-button:active {
  transform: translateY(1px);
}

#hintText {
  min-height: 20px;
  margin-top: 8px;
  color: #4a5568;
  font-size: 14px;
  line-height: 1.25;
}

.overlay {
  position: fixed;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 20px;
  background: rgba(10, 24, 40, 0.5);
  z-index: 8;
}

.overlay.hidden {
  display: none;
}

.panel {
  width: min(440px, 100%);
  border-radius: 8px;
  padding: 24px;
  background: white;
  box-shadow: 0 24px 80px rgba(0, 0, 0, 0.25);
  text-align: center;
}

.panel h1 {
  margin: 0 0 10px;
  font-size: 38px;
  line-height: 1.08;
}

.panel p {
  margin: 0 0 18px;
  color: #4a5568;
  font-size: 16px;
  line-height: 1.45;
}

@media (max-width: 820px) {
  .game-shell {
    width: 100vw;
    padding: 8px 8px max(8px, env(safe-area-inset-bottom));
  }

  .math-panel {
    width: min(620px, 100%);
  }

  #questionText {
    font-size: 18px;
  }
}

@media (max-width: 520px) {
  .game-shell {
    gap: 6px;
    padding: 6px 6px max(6px, env(safe-area-inset-bottom));
  }

  canvas {
    border-radius: 6px;
  }

  .fullscreen-button {
    top: 12px;
    right: 12px;
    width: 40px;
    min-height: 40px;
    font-size: 23px;
  }

  .back-image-button {
    top: 12px;
    left: 12px;
    min-height: 40px;
    padding: 0 10px;
    font-size: 12px;
  }

  .new-round-image-button {
    top: 12px;
    right: 58px;
    min-height: 40px;
    padding: 0 10px;
    font-size: 12px;
  }

  .answer-row {
    grid-template-columns: 1fr;
  }

  button,
  .actions a,
  input {
    min-height: 44px;
  }
}
