:root {
  color-scheme: light;
  --ink: #172033;
  --glass: rgba(255, 255, 255, 0.82);
  --line: rgba(23, 32, 51, 0.16);
  --blue: #2563eb;
  --green: #14804a;
  --gold: #d79b14;
}

* {
  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:
    radial-gradient(circle at 18% 14%, rgba(255, 255, 255, 0.82), transparent 21%),
    linear-gradient(135deg, #cfefff 0%, #edf8ff 45%, #d8f7ed 100%);
}

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;
  padding: 12px;
  position: relative;
}

canvas {
  width: 100%;
  height: 100%;
  display: block;
  border-radius: 8px;
  background: #72cae8;
  box-shadow: 0 18px 55px rgba(19, 56, 101, 0.22);
  touch-action: none;
}

.answer-panel,
.fullscreen-button,
.corner-actions a {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--glass);
  color: #172033;
  box-shadow: 0 12px 28px rgba(19, 56, 101, 0.16);
  backdrop-filter: blur(8px);
}

.task-panel {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
}

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

#taskKicker {
  color: #245370;
  font-size: 13px;
  font-weight: 900;
}

#taskText {
  margin-top: 3px;
  font-size: clamp(1.25rem, 3vw, 2rem);
  line-height: 1.08;
}

#taskHint {
  margin-top: 6px;
  color: #405166;
  font-size: 14px;
  line-height: 1.25;
}

.answer-panel {
  position: absolute;
  z-index: 6;
  left: 50%;
  top: 50%;
  width: min(360px, calc(100% - 44px));
  padding: 14px;
  transform: translate(-50%, -50%);
}

.answer-panel.hidden,
.success-mark.hidden {
  display: none;
}

.fraction-card {
  display: grid;
  gap: 4px;
  justify-items: center;
  margin-bottom: 10px;
  color: #172033;
  font-weight: 900;
}

.fraction-line {
  width: min(190px, 80%);
  border-top: 3px solid #172033;
}

label {
  display: block;
  margin-bottom: 8px;
  font-weight: 900;
}

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

input {
  width: 100%;
  min-height: 46px;
  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,
.corner-actions a {
  min-height: 44px;
  text-decoration: none;
  font-weight: 900;
}

#answerBtn {
  border: 0;
  border-radius: 8px;
  padding: 0 16px;
  background: var(--green);
  color: white;
  cursor: pointer;
  box-shadow: inset 0 -2px 0 rgba(0, 0, 0, 0.18);
}

#answerMessage {
  min-height: 20px;
  margin: 8px 0 0;
  color: #9f1239;
  font-size: 14px;
  font-weight: 800;
}

.success-mark {
  position: absolute;
  z-index: 7;
  left: 50%;
  top: 50%;
  display: grid;
  place-items: center;
  width: min(190px, 42vw);
  aspect-ratio: 1;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.9);
  color: #16a34a;
  font-size: clamp(6rem, 18vw, 11rem);
  font-weight: 900;
  line-height: 1;
  transform: translate(-50%, -50%);
  box-shadow: 0 20px 80px rgba(10, 45, 28, 0.28);
}

.overlay {
  position: fixed;
  inset: 0;
  z-index: 9;
  display: grid;
  place-items: center;
  padding: 20px;
  background: rgba(10, 24, 40, 0.48);
  overflow: auto;
  -webkit-overflow-scrolling: touch;
}

.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: 34px;
  line-height: 1.08;
}

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

.score-form {
  display: grid;
  gap: 8px;
  margin: 16px 0;
  padding: 14px;
  border-radius: 8px;
  background: #f4f8ff;
  text-align: left;
}

.score-form.hidden {
  display: none;
}

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

.score-row input {
  text-transform: uppercase;
  letter-spacing: 0.08em;
  text-align: center;
}

.score-message {
  min-height: 20px;
  margin: 0;
  font-size: 13px;
}

.highscore-panel {
  width: 100%;
  margin: 18px 0 16px;
  padding: 14px 16px;
  border: 1px solid rgba(23, 32, 51, 0.14);
  border-radius: 8px;
  background: #f8fbff;
  text-align: left;
}

.highscore-panel h2 {
  margin: 0 0 8px;
  font-size: 17px;
  line-height: 1.1;
}

.highscore-panel ol {
  margin: 0;
  padding-left: 24px;
}

.highscore-panel li {
  padding: 2px 0;
  font-size: 15px;
  font-weight: 800;
}

.highscore-panel span {
  display: inline-flex;
  justify-content: space-between;
  gap: 12px;
  width: 100%;
}

#highscoreStatus {
  margin: 8px 0 0;
  color: #4a5568;
  font-size: 12px;
  line-height: 1.25;
}

#restartBtn,
#saveScoreBtn {
  border: 0;
  border-radius: 8px;
  padding: 0 16px;
  background: var(--blue);
  color: white;
  cursor: pointer;
  box-shadow: inset 0 -2px 0 rgba(0, 0, 0, 0.18);
}

#saveScoreBtn {
  background: var(--gold);
  color: #201400;
}

.fullscreen-button {
  position: absolute;
  top: 22px;
  right: 22px;
  z-index: 5;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 44px;
  padding: 0;
  font-size: 26px;
  line-height: 1;
  cursor: pointer;
}

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

.corner-actions {
  position: fixed;
  left: 22px;
  bottom: max(22px, env(safe-area-inset-bottom));
  z-index: 6;
}

.corner-actions a {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0 18px;
}

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

@media (max-width: 720px) {
  .game-shell {
    padding: 6px;
  }

  canvas {
    border-radius: 6px;
  }

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

  .answer-panel {
    width: calc(100% - 24px);
    padding: 12px;
  }

  .corner-actions {
    left: 12px;
    bottom: max(12px, env(safe-area-inset-bottom));
  }

  .corner-actions a {
    min-height: 40px;
    padding: 0 14px;
  }

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

  .highscore-panel {
    padding: 10px 12px;
  }

  .highscore-panel li {
    font-size: 13px;
  }
}
