:root {
  --paper: #e8e0c0;
  --ink: #211f23;
  --pink: #c98fa1;
  --cyan: #8dbfaf;
  --yellow: #d6bd72;
  --blue: #8097b6;
  --green: #79ad78;
  --wrong: #83404b;
  --wrong-soft: #d79aa2;
  --safe-top: max(12px, env(safe-area-inset-top));
  --safe-right: max(12px, env(safe-area-inset-right));
  --safe-bottom: max(12px, env(safe-area-inset-bottom));
  --safe-left: max(12px, env(safe-area-inset-left));
}

* {
  box-sizing: border-box;
}

html {
  width: 100%;
  height: 100%;
  min-width: 320px;
  min-height: 100%;
  background: var(--paper);
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
}

body {
  width: 100%;
  min-width: 320px;
  min-height: 100vh;
  min-height: 100dvh;
  margin: 0;
  overflow: hidden;
  color: var(--ink);
  background-color: var(--paper);
  background-image:
    radial-gradient(circle, rgba(33, 31, 35, 0.1) 1.2px, transparent 1.5px),
    linear-gradient(104deg, transparent 0 47%, rgba(201, 143, 161, 0.06) 47% 50%, transparent 50% 100%);
  background-position: 0 0, center;
  background-size: 15px 15px, 100% 100%;
  font-family: Arial, Helvetica, sans-serif;
  -webkit-font-smoothing: antialiased;
  -webkit-touch-callout: none;
  overscroll-behavior: none;
}

body::before,
body::after {
  position: fixed;
  z-index: -1;
  content: "";
  pointer-events: none;
}

body::before {
  inset: 5% auto auto -4%;
  width: 38vw;
  height: 20vh;
  background: var(--cyan);
  clip-path: polygon(2% 16%, 96% 0, 100% 83%, 7% 100%);
  opacity: 0.22;
  transform: rotate(-5deg);
}

body::after {
  right: -5vw;
  bottom: 3vh;
  width: 33vw;
  height: 22vh;
  background:
    radial-gradient(circle, var(--pink) 2px, transparent 2.5px) 0 0 / 13px 13px;
  opacity: 0.2;
  transform: rotate(7deg);
}

button {
  margin: 0;
  border: 0;
  color: inherit;
  font: inherit;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
  -webkit-user-select: none;
  user-select: none;
  cursor: pointer;
}

button:focus-visible {
  outline: 5px solid var(--blue);
  outline-offset: 4px;
}

button:disabled {
  cursor: default;
}

[hidden] {
  display: none !important;
}

.app-shell {
  width: 100%;
  min-height: 100vh;
  min-height: 100dvh;
  padding: var(--safe-top) var(--safe-right) var(--safe-bottom) var(--safe-left);
}

.screen {
  width: min(1180px, 100%);
  height: calc(100vh - 24px);
  height: calc(100dvh - var(--safe-top) - var(--safe-bottom));
  min-height: 0;
  margin: 0 auto;
}

.start-screen {
  position: relative;
  display: grid;
  grid-template-columns: minmax(250px, 0.82fr) minmax(390px, 1.18fr);
  grid-template-rows: 1fr auto;
  gap: clamp(18px, 3.5vw, 54px);
  align-items: center;
  overflow-y: auto;
  padding: clamp(12px, 2vw, 30px);
  scrollbar-width: none;
}

.start-screen::-webkit-scrollbar {
  display: none;
}

.start-controls {
  position: absolute;
  z-index: 12;
  top: clamp(10px, 1.2vw, 16px);
  left: clamp(10px, 1.4vw, 18px);
  display: flex;
  gap: 8px;
  align-items: center;
}

.settings-button {
  display: grid;
  width: 48px;
  min-width: 48px;
  height: 48px;
  min-height: 48px;
  padding: 10px;
  place-items: center;
  border: 0;
  background: transparent;
  box-shadow: none;
  transform: none;
}

.settings-button[aria-expanded="true"] {
  outline: 0;
  box-shadow: none;
  transform: none;
}

.settings-button[aria-expanded="true"] .settings-icon {
  transform: rotate(20deg);
}

.settings-button:active {
  box-shadow: none;
  transform: scale(0.92);
}

.settings-icon {
  width: 24px;
  height: 24px;
  overflow: visible;
  transition: transform 120ms steps(3, end);
}

.settings-icon path,
.settings-icon circle {
  fill: none;
  stroke: currentColor;
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-width: 2.8;
}

.language-picker {
  display: grid;
  gap: 5px;
  min-width: 0;
  margin: 0;
  padding: 0;
  border: 0;
}

.timer-popover {
  position: absolute;
  z-index: 20;
  top: 74px;
  left: 0;
  width: min(340px, calc(100vw - 44px));
  max-height: calc(100dvh - var(--safe-top) - 108px);
  overflow-y: auto;
  padding: 20px 20px 18px;
  border: 4px solid var(--ink);
  background: var(--paper);
  box-shadow: 9px 10px 0 var(--ink), -6px -5px 0 var(--pink);
  transform: rotate(-1deg);
}

.timer-popover::before {
  position: absolute;
  top: -13px;
  left: 24px;
  width: 20px;
  height: 20px;
  border-top: 4px solid var(--ink);
  border-left: 4px solid var(--ink);
  background: var(--paper);
  content: "";
  transform: rotate(45deg);
}

.timer-close-button {
  position: absolute;
  z-index: 1;
  top: 8px;
  right: 8px;
  display: grid;
  width: 48px;
  height: 48px;
  padding: 10px;
  place-items: center;
  border: 3px solid var(--ink);
  background: var(--pink);
  box-shadow: 3px 3px 0 var(--ink);
  transform: rotate(2deg);
}

.timer-close-button svg {
  width: 24px;
  height: 24px;
}

.timer-close-button path {
  fill: none;
  stroke: currentColor;
  stroke-linecap: round;
  stroke-width: 2.8;
}

.timer-form {
  display: grid;
  gap: 12px;
}

.timer-form h2 {
  max-width: calc(100% - 48px);
  margin: 0;
  font-family: "Times New Roman", Times, serif;
  font-size: clamp(1.75rem, 7vw, 2.35rem);
  line-height: 0.95;
}

.timer-form p,
.timer-form label {
  margin: 0;
  font-family: "Courier New", Courier, monospace;
  font-weight: 700;
  line-height: 1.2;
}

.timer-form label {
  margin-top: 3px;
  font-size: 0.84rem;
}

.timer-input-row {
  display: flex;
  gap: 10px;
  align-items: center;
}

.timer-input-row input {
  width: 110px;
  min-height: 58px;
  padding: 7px 10px;
  border: 3px solid var(--ink);
  border-radius: 0;
  background: var(--yellow);
  box-shadow: 4px 4px 0 var(--ink);
  color: var(--ink);
  font-family: "Times New Roman", Times, serif;
  font-size: 2rem;
  font-weight: 900;
  font-variant-numeric: tabular-nums;
  text-align: center;
}

.timer-input-row input:focus-visible {
  outline: 5px solid var(--blue);
  outline-offset: 4px;
}

.timer-input-row span {
  font-family: "Courier New", Courier, monospace;
  font-weight: 900;
}

.timer-range {
  font-size: 0.78rem;
  opacity: 0.72;
}

.timer-save-button {
  min-height: 58px;
  padding: 10px 18px;
  border: 3px solid var(--ink);
  background: var(--green);
  box-shadow: 5px 5px 0 var(--ink);
  font-weight: 900;
  transform: rotate(-1deg);
}

.timer-save-button:active,
.timer-close-button:active {
  box-shadow: 2px 2px 0 var(--ink);
  transform: translate(3px, 3px);
}

.language-options {
  display: flex;
  gap: 8px;
}

.language-button {
  display: grid;
  width: 72px;
  min-width: 72px;
  height: 72px;
  min-height: 72px;
  padding: 8px 7px 6px;
  place-items: center;
  align-content: center;
  gap: 5px;
  border: 3px solid var(--ink);
  background: var(--paper);
  box-shadow: 4px 5px 0 rgba(33, 31, 35, 0.55);
  opacity: 0.62;
  transform: rotate(-2deg);
  transition: transform 80ms steps(2, end), opacity 80ms steps(2, end);
}

.language-button:nth-child(2) {
  transform: rotate(2deg);
}

.language-button.is-selected {
  z-index: 1;
  outline: 4px solid var(--ink);
  outline-offset: 3px;
  box-shadow: 6px 7px 0 var(--yellow);
  opacity: 1;
  transform: rotate(-1deg) translateY(-2px);
}

.language-button:nth-child(2).is-selected {
  transform: rotate(1deg) translateY(-2px);
}

.language-button:active {
  box-shadow: 2px 2px 0 var(--ink);
  transform: translate(3px, 3px) rotate(0);
}

.flag {
  position: relative;
  display: block;
  width: 40px;
  height: 26px;
  overflow: hidden;
  border: 2px solid var(--ink);
  box-shadow: 2px 2px 0 rgba(33, 31, 35, 0.22);
}

.flag-germany {
  background: linear-gradient(
    to bottom,
    var(--ink) 0 33.333%,
    var(--wrong) 33.333% 66.666%,
    var(--yellow) 66.666% 100%
  );
}

.flag-us {
  background: repeating-linear-gradient(
    to bottom,
    var(--wrong) 0 3px,
    var(--paper) 3px 6px
  );
}

.flag-us::before {
  position: absolute;
  top: 0;
  left: 0;
  width: 51%;
  height: 54%;
  background-color: var(--blue);
  background-image: radial-gradient(circle, var(--paper) 0 1px, transparent 1.2px);
  background-size: 5px 5px;
  content: "";
}

.language-code {
  font-family: "Courier New", Courier, monospace;
  font-size: 0.78rem;
  font-weight: 900;
  line-height: 1;
}

.welcome {
  grid-row: 1 / span 2;
  align-self: center;
  padding: clamp(8px, 2vw, 22px);
}

.app-name,
.mode-label,
.score-card span,
#selected-mode {
  font-family: "Courier New", Courier, monospace;
  font-weight: 700;
  letter-spacing: 0.045em;
}

.app-name {
  display: inline-block;
  margin: 0 0 18px;
  padding: 7px 11px 5px;
  background: var(--yellow);
  box-shadow: 4px 4px 0 var(--ink);
  font-size: clamp(0.78rem, 1.6vw, 1rem);
  transform: rotate(-2deg);
}

h1 {
  max-width: 680px;
  margin: 0;
  font-family: "Times New Roman", Times, serif;
  font-size: clamp(4rem, 9.2vw, 8.8rem);
  font-weight: 900;
  line-height: 0.79;
  letter-spacing: -0.075em;
  color: var(--ink);
  transform: rotate(-1deg);
}

.learning-bear {
  position: absolute;
  z-index: 3;
  top: clamp(2px, 1vw, 12px);
  right: clamp(4px, 1.4vw, 18px);
  width: clamp(112px, 12vw, 165px);
  height: auto;
  filter: drop-shadow(5px 6px 0 rgba(33, 31, 35, 0.24));
  pointer-events: none;
  transform-origin: 50% 84%;
  transform: rotate(3deg);
  animation: bear-study 4.2s ease-in-out infinite;
}

.bear-gaze {
  --bear-look-x: 0%;
  --bear-look-y: 0%;
  position: absolute;
  z-index: 4;
  top: clamp(2px, 1vw, 12px);
  right: clamp(4px, 1.4vw, 18px);
  width: clamp(112px, 12vw, 165px);
  aspect-ratio: 320 / 387;
  pointer-events: none;
  transform-origin: 50% 84%;
  transform: rotate(3deg);
  animation: bear-study 4.2s ease-in-out infinite;
}

.bear-eye {
  position: absolute;
  overflow: hidden;
  border: 1px solid var(--ink);
  border-radius: 48% 48% 52% 52%;
  background: #f5ebcd;
  box-shadow: inset 0 -1px 0 rgba(33, 31, 35, 0.14);
}

.bear-eye-left {
  top: 31%;
  left: 37.2%;
  width: 7.8%;
  height: 7.8%;
  transform: rotate(-5deg);
}

.bear-eye-right {
  top: 28.4%;
  left: 58.1%;
  width: 6.25%;
  height: 7.8%;
  transform: none;
}

.bear-pupil {
  position: absolute;
  top: calc(55% + var(--bear-look-y, 0%));
  left: calc(50% + var(--bear-look-x, 0%));
  width: 43%;
  height: 43%;
  border-radius: 50%;
  background: var(--ink);
  transform: translate(-50%, -50%);
  transition:
    top 90ms steps(3, end),
    left 90ms steps(3, end);
}

.bear-pupil::after {
  position: absolute;
  top: 13%;
  left: 17%;
  width: 31%;
  height: 31%;
  border-radius: 50%;
  background: #fff8df;
  content: "";
}

.intro {
  max-width: 470px;
  margin: clamp(25px, 4vw, 48px) 0 0;
  font-family: Arial, Helvetica, sans-serif;
  font-size: clamp(1.1rem, 2.2vw, 1.55rem);
  font-weight: 700;
  line-height: 1.25;
}

.mode-picker {
  min-width: 0;
  margin: 0;
  padding: 0;
  border: 0;
}

.mode-picker legend {
  width: 100%;
  margin-bottom: clamp(14px, 2vw, 24px);
  font-family: "Courier New", Courier, monospace;
  font-size: clamp(1rem, 2vw, 1.25rem);
  font-weight: 700;
  text-align: center;
}

.mode-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: clamp(13px, 2.2vw, 28px);
}

.mode-card {
  position: relative;
  display: grid;
  min-width: 0;
  min-height: clamp(180px, 28vh, 280px);
  padding: clamp(20px, 3vw, 34px) clamp(12px, 2vw, 24px);
  place-items: center;
  align-content: center;
  border: 4px solid var(--ink);
  background: var(--cyan);
  box-shadow: 8px 9px 0 var(--ink);
  clip-path: polygon(1% 3%, 98% 0, 100% 96%, 4% 100%, 0 48%);
  transform: rotate(-3deg);
  transition:
    transform 90ms steps(2, end),
    box-shadow 90ms steps(2, end),
    filter 90ms steps(2, end),
    opacity 90ms steps(2, end);
}

.mode-card::before {
  position: absolute;
  top: -8px;
  left: 50%;
  width: 42%;
  height: 23px;
  background: rgba(214, 189, 114, 0.86);
  border-right: 1px dashed rgba(33, 31, 35, 0.3);
  border-left: 1px dashed rgba(33, 31, 35, 0.3);
  content: "";
  transform: translateX(-50%) rotate(2deg);
}

.mode-card:nth-child(2) {
  background: var(--pink);
  transform: rotate(3deg);
}

.mode-card.is-selected {
  z-index: 1;
  outline: 7px solid var(--ink);
  outline-offset: 5px;
  box-shadow: 11px 12px 0 var(--yellow);
  filter: saturate(1);
  opacity: 1;
  transform: rotate(-1deg) translateY(-5px);
}

.mode-card:not(.is-selected) {
  filter: saturate(0.68);
  opacity: 0.78;
}

.selection-label {
  position: absolute;
  z-index: 2;
  top: 9px;
  right: 8px;
  display: none;
  padding: 7px 10px 5px;
  border: 2px solid var(--paper);
  background: var(--ink);
  box-shadow: 3px 4px 0 rgba(33, 31, 35, 0.3);
  color: var(--paper);
  font-family: "Courier New", Courier, monospace;
  font-size: clamp(0.68rem, 1.35vw, 0.9rem);
  font-weight: 700;
  letter-spacing: 0.02em;
  line-height: 1;
  transform: rotate(3deg);
}

.mode-card.is-selected .selection-label {
  display: block;
}

.mode-card:nth-child(2).is-selected {
  transform: rotate(1deg) translateY(-5px);
}

.mode-card:active {
  box-shadow: 3px 4px 0 var(--ink);
  transform: rotate(0) translate(5px, 5px);
}

.mode-sample {
  display: block;
  font-size: clamp(2.7rem, 6vw, 5.1rem);
  font-weight: 900;
  letter-spacing: -0.13em;
  line-height: 1;
}

.letter-sample {
  font-family: "Times New Roman", Times, serif;
  font-style: italic;
}

.mode-name {
  display: block;
  margin-top: clamp(12px, 2vh, 22px);
  font-family: Arial, Helvetica, sans-serif;
  font-size: clamp(1.4rem, 3vw, 2.25rem);
  font-weight: 900;
  line-height: 1;
}

.mode-note {
  display: block;
  margin-top: 8px;
  font-family: "Courier New", Courier, monospace;
  font-size: clamp(0.75rem, 1.6vw, 1rem);
  font-weight: 700;
}

.start-area {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: clamp(14px, 2vw, 24px);
  padding-bottom: 6px;
}

#selected-mode {
  max-width: 180px;
  margin: 0;
  padding: 8px 10px 6px;
  background: var(--ink);
  color: var(--paper);
  font-size: clamp(0.8rem, 1.5vw, 1rem);
  line-height: 1.15;
  transform: rotate(1deg);
}

.start-button {
  min-width: clamp(150px, 18vw, 220px);
  min-height: 78px;
  padding: 13px 34px;
  border: 4px solid var(--ink);
  background: var(--yellow);
  box-shadow: 8px 8px 0 var(--ink);
  font-family: Arial, Helvetica, sans-serif;
  font-size: clamp(1.8rem, 3vw, 2.6rem);
  font-weight: 900;
  transform: rotate(-2deg);
}

.start-button:active {
  box-shadow: 3px 3px 0 var(--ink);
  transform: translate(5px, 5px) rotate(-1deg);
}

.game-screen {
  position: relative;
  display: grid;
  grid-template-rows: auto auto minmax(0, 1fr);
  gap: clamp(8px, 1.4vh, 16px);
  overflow: hidden;
  padding: clamp(3px, 0.7vw, 9px);
}

.game-bar {
  display: grid;
  grid-template-areas:
    "actions scoreboard timer"
    "actions scoreboard repeat";
  grid-template-columns: minmax(108px, 1fr) auto minmax(108px, 1fr);
  grid-template-rows: auto auto;
  column-gap: clamp(8px, 1.5vw, 18px);
  row-gap: 5px;
  align-items: center;
}

.game-actions {
  display: flex;
  grid-area: actions;
  gap: clamp(8px, 1vw, 12px);
  justify-self: start;
}

.small-button {
  min-width: 108px;
  min-height: 72px;
  padding: 11px 16px;
  border: 3px solid var(--ink);
  background: var(--paper);
  box-shadow: 5px 5px 0 var(--ink);
  font-weight: 900;
  line-height: 1.05;
}

.small-button:active {
  box-shadow: 2px 2px 0 var(--ink);
  transform: translate(3px, 3px);
}

.back-button {
  grid-area: back;
  transform: rotate(-2deg);
}

.music-button {
  display: flex;
  grid-area: music;
  min-width: 112px;
  min-height: 72px;
  gap: 7px;
  align-items: center;
  justify-content: center;
  background: var(--green);
  transform: rotate(1deg);
}

.music-button.is-off {
  background: var(--paper);
  color: rgba(33, 31, 35, 0.72);
}

.music-button:disabled {
  opacity: 0.58;
}

.music-icon {
  width: 25px;
  height: 25px;
  flex: 0 0 auto;
  overflow: visible;
}

.music-icon path {
  fill: none;
  stroke: currentColor;
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-width: 2.2;
}

.music-icon circle {
  fill: currentColor;
}

.music-button.is-off .music-icon {
  opacity: 0.48;
}

.repeat-button {
  grid-area: repeat;
  justify-self: end;
  background: var(--cyan);
  transform: rotate(2deg);
}

.scoreboard {
  display: flex;
  grid-area: scoreboard;
  justify-content: center;
  gap: clamp(7px, 1.5vw, 16px);
}

.score-card {
  display: grid;
  min-width: clamp(86px, 11vw, 130px);
  min-height: 72px;
  margin: 0;
  padding: 7px 12px 6px;
  place-items: center;
  border: 3px solid var(--ink);
  background: var(--yellow);
  box-shadow: 4px 4px 0 var(--ink);
  transform: rotate(-1deg);
}

.highscore-card {
  background: var(--pink);
  transform: rotate(1deg);
}

.parent-timer {
  display: block;
  grid-area: timer;
  align-self: end;
  justify-self: end;
  margin: 0 5px 0 0;
  padding: 0;
  border: 0;
  background: transparent;
  box-shadow: none;
  color: var(--ink);
  font-family: "Courier New", Courier, monospace;
  font-size: clamp(0.78rem, 1.4vw, 0.95rem);
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  line-height: 1;
  letter-spacing: 0.04em;
  opacity: 0.7;
  transform: none;
}

.parent-timer strong {
  font: inherit;
}

.score-card span {
  font-size: clamp(0.65rem, 1.2vw, 0.8rem);
  line-height: 1;
}

.score-card strong {
  font-family: "Times New Roman", Times, serif;
  font-size: clamp(1.9rem, 3.5vw, 2.7rem);
  line-height: 0.82;
}

.round-heading {
  display: grid;
  grid-template-columns: minmax(80px, auto) 1fr minmax(110px, auto);
  gap: clamp(8px, 1.6vw, 18px);
  align-items: center;
  min-height: 64px;
  padding: 3px clamp(2px, 1vw, 12px);
}

.mode-label {
  margin: 0;
  padding: 7px 10px;
  background: var(--ink);
  color: var(--paper);
  font-size: clamp(0.76rem, 1.5vw, 1rem);
  text-align: center;
  transform: rotate(-2deg);
}

.round-heading h2 {
  margin: 0;
  font-family: "Times New Roman", Times, serif;
  font-size: clamp(1.85rem, 4.2vw, 3.8rem);
  line-height: 0.9;
  text-align: center;
}

.round-heading h2:focus {
  outline: none;
}

.feedback {
  min-width: 110px;
  margin: 0;
  font-family: "Courier New", Courier, monospace;
  font-size: clamp(0.78rem, 1.6vw, 1rem);
  font-weight: 700;
  line-height: 1.1;
  text-align: center;
}

.feedback.is-wrong {
  color: var(--wrong);
}

.feedback.is-correct {
  color: #3d6747;
}

.board {
  position: relative;
  display: block;
  gap: clamp(12px, 1.8vmin, 20px);
  min-width: 0;
  min-height: 0;
  padding: clamp(13px, 2.2vmin, 25px);
  align-items: stretch;
  overflow: hidden;
  border: 3px dashed rgba(33, 31, 35, 0.55);
  background:
    linear-gradient(rgba(232, 224, 192, 0.7), rgba(232, 224, 192, 0.7)),
    repeating-linear-gradient(0deg, transparent 0 27px, rgba(128, 151, 182, 0.2) 28px 29px);
  clip-path: polygon(0.6% 1%, 99% 0, 100% 98.8%, 1.4% 100%);
}

.answer-card {
  --rotation: 0deg;
  --card-x: 12px;
  --card-y: 12px;
  --card-size: 72px;
  --card-font-scale: 0.68;
  --card-color: var(--cyan);
  position: absolute;
  top: var(--card-y);
  left: var(--card-x);
  display: grid;
  width: var(--card-size);
  height: var(--card-size);
  min-width: 72px;
  min-height: 72px;
  padding: 4px;
  place-items: center;
  border: clamp(3px, 0.45vmin, 5px) solid var(--ink);
  background: var(--card-color);
  box-shadow: 4px 5px 0 var(--ink);
  clip-path: polygon(2% 1%, 98% 3%, 100% 96%, 4% 100%, 0 44%);
  font-family: Arial, Helvetica, sans-serif;
  font-size: calc(var(--card-size) * var(--card-font-scale));
  font-weight: 900;
  font-variant-numeric: tabular-nums;
  line-height: 0.8;
  transform: rotate(var(--rotation));
  transition: box-shadow 80ms steps(2, end), filter 80ms steps(2, end);
  will-change: transform;
}

.answer-card:nth-child(3n + 2) {
  font-family: "Times New Roman", Times, serif;
}

.answer-card:nth-child(4n) {
  font-family: "Courier New", Courier, monospace;
}

.answer-card:active:not(:disabled) {
  box-shadow: 2px 3px 0 var(--ink);
  filter: brightness(0.96);
}

.answer-card.is-wrong {
  border-color: var(--wrong);
  background: var(--wrong-soft);
  animation: wrong-shake 430ms steps(2, end);
}

.answer-card.is-correct {
  z-index: 2;
  background: var(--green);
  outline: 7px solid var(--yellow);
  outline-offset: 3px;
  animation: correct-pop 650ms steps(3, end) both;
}

.answer-card:disabled:not(.is-correct) {
  filter: saturate(0.45) contrast(0.88);
  opacity: 0.72;
}

.speech-warning {
  position: fixed;
  z-index: 20;
  right: var(--safe-right);
  bottom: var(--safe-bottom);
  display: grid;
  width: min(440px, calc(100vw - 24px));
  padding: 16px 20px;
  border: 4px solid var(--ink);
  background: var(--yellow);
  box-shadow: 7px 7px 0 var(--ink);
  font-size: 1rem;
  line-height: 1.25;
  transform: rotate(-1deg);
}

.celebration {
  position: fixed;
  z-index: 31;
  inset: 0;
  display: grid;
  place-items: center;
  pointer-events: none;
}

.time-up-overlay {
  position: fixed;
  z-index: 60;
  inset: 0;
  display: grid;
  overflow-y: auto;
  padding: calc(var(--safe-top) + clamp(6px, 2vmin, 18px))
    calc(var(--safe-right) + clamp(6px, 2vmin, 18px))
    calc(var(--safe-bottom) + clamp(6px, 2vmin, 18px))
    calc(var(--safe-left) + clamp(6px, 2vmin, 18px));
  place-items: center;
  background: rgba(33, 31, 35, 0.58);
}

.time-up-dialog {
  position: relative;
  display: grid;
  width: min(560px, 100%);
  gap: clamp(8px, min(2.4vw, 2.4dvh), 22px);
  overflow: visible;
  padding: clamp(14px, min(5vw, 4dvh), 46px);
  place-items: center;
  border: 6px solid var(--ink);
  background: var(--paper);
  box-shadow: 12px 12px 0 var(--green), -10px -9px 0 var(--pink);
  text-align: center;
  transform: rotate(-1deg);
}

.time-up-sticker {
  width: clamp(36px, min(10vw, 9dvh), 62px);
  height: auto;
  aspect-ratio: 1;
  margin: 0;
  overflow: visible;
  filter: drop-shadow(4px 4px 0 var(--ink));
  transform: rotate(8deg);
}

.time-up-sticker path {
  fill: var(--yellow);
  stroke: var(--ink);
  stroke-linejoin: round;
  stroke-width: 3;
}

.time-up-dialog h2 {
  margin: 0;
  font-family: "Times New Roman", Times, serif;
  font-size: clamp(2rem, min(9vw, 10dvh), 5rem);
  line-height: 0.88;
}

.time-up-dialog > p {
  max-width: 430px;
  margin: 0;
  font-family: "Courier New", Courier, monospace;
  font-size: clamp(0.88rem, min(3.2vw, 3.4dvh), 1.3rem);
  font-weight: 700;
  line-height: 1.3;
}

.time-up-result {
  display: grid;
  min-width: clamp(130px, 28vw, 180px);
  padding: clamp(6px, 1.5dvh, 12px) clamp(12px, 3vw, 20px);
  place-items: center;
  border: 4px solid var(--ink);
  background: var(--green);
  box-shadow: 6px 6px 0 var(--ink);
  transform: rotate(1deg);
}

.time-up-result strong {
  font-family: "Times New Roman", Times, serif;
  font-size: clamp(2.5rem, min(10vw, 11dvh), 5.6rem);
  line-height: 0.85;
}

.time-up-ok {
  min-width: clamp(120px, 30vw, 150px);
  min-height: clamp(52px, 10dvh, 72px);
  padding: clamp(8px, 1.5dvh, 12px) clamp(20px, 5vw, 30px);
  border: 4px solid var(--ink);
  background: var(--yellow);
  box-shadow: 7px 7px 0 var(--ink);
  font-size: clamp(1.2rem, min(5vw, 4dvh), 1.7rem);
  font-weight: 900;
  transform: rotate(-2deg);
}

.time-up-ok:active {
  box-shadow: 3px 3px 0 var(--ink);
  transform: translate(4px, 4px) rotate(-1deg);
}

.celebration p {
  margin: 0;
  padding: 16px 30px 10px;
  border: 6px solid var(--ink);
  background: var(--green);
  box-shadow: 12px 12px 0 var(--pink), -10px -10px 0 var(--cyan);
  font-family: "Times New Roman", Times, serif;
  font-size: clamp(4.5rem, 16vw, 11rem);
  font-weight: 900;
  line-height: 0.9;
  text-shadow: 4px 0 var(--pink), -4px 0 var(--cyan);
  transform: rotate(-4deg);
  animation: celebration-pop 600ms steps(3, end) both;
}

#fireworks {
  position: fixed;
  z-index: 30;
  inset: 0;
  width: 100vw;
  height: 100vh;
  height: 100dvh;
  pointer-events: none;
}

@keyframes wrong-shake {
  0%, 100% {
    transform: translateX(0) rotate(var(--rotation));
  }
  25% {
    transform: translateX(-12px) rotate(calc(var(--rotation) - 5deg));
  }
  50% {
    transform: translateX(12px) rotate(calc(var(--rotation) + 5deg));
  }
  75% {
    transform: translateX(-7px) rotate(calc(var(--rotation) - 3deg));
  }
}

@keyframes correct-pop {
  0% {
    transform: rotate(var(--rotation)) scale(1);
  }
  45% {
    transform: rotate(-5deg) scale(1.2);
  }
  100% {
    transform: rotate(2deg) scale(1.06);
  }
}

@keyframes celebration-pop {
  0% {
    opacity: 0;
    transform: rotate(7deg) scale(0.4);
  }
  65% {
    opacity: 1;
    transform: rotate(-6deg) scale(1.12);
  }
  100% {
    opacity: 1;
    transform: rotate(-4deg) scale(1);
  }
}

@keyframes bear-study {
  0%, 100% {
    transform: translateY(0) rotate(3deg) scale(1);
  }
  45% {
    transform: translateY(-4px) rotate(1.5deg) scale(1.012);
  }
  72% {
    transform: translateY(-2px) rotate(3.8deg) scale(0.996);
  }
}

@media (hover: hover) {
  .settings-button:hover,
  .timer-close-button:hover,
  .timer-save-button:hover,
  .time-up-ok:hover,
  .language-button:hover,
  .mode-card:hover,
  .start-button:hover,
  .small-button:hover,
  .answer-card:hover:not(:disabled) {
    filter: brightness(0.97) contrast(1.03);
  }
}

@media (max-width: 820px) {
  .start-screen {
    grid-template-columns: 1fr;
    grid-template-rows: auto auto auto;
    gap: clamp(14px, 2.8vh, 28px);
    padding: clamp(10px, 2vw, 22px);
    padding-top: clamp(114px, 17vh, 145px);
  }

  .welcome {
    grid-row: auto;
    padding: 0;
    text-align: center;
  }

  .app-name {
    margin-bottom: 12px;
  }

  h1 {
    margin-inline: auto;
    font-size: clamp(3.4rem, 12vw, 7rem);
    line-height: 0.82;
  }

  .intro {
    margin: 18px auto 0;
  }

  .mode-card {
    min-height: clamp(150px, 23vh, 225px);
  }

  .learning-bear {
    top: 3px;
    right: 4px;
    width: clamp(94px, 15vw, 124px);
  }

  .bear-gaze {
    top: 3px;
    right: 4px;
    width: clamp(94px, 15vw, 124px);
  }
}

@media (max-width: 520px) {
  .game-bar {
    grid-template-areas:
      "scoreboard scoreboard timer"
      "back music repeat";
    grid-template-columns: repeat(3, minmax(0, 1fr));
    align-items: stretch;
  }

  .game-actions {
    display: contents;
  }

  .scoreboard {
    grid-area: scoreboard;
    width: 100%;
    gap: 5px;
  }

  .parent-timer {
    align-self: center;
    margin-right: 6px;
    font-size: 0.82rem;
  }

  .score-card {
    min-width: 0;
    padding-right: 6px;
    padding-left: 6px;
    flex: 1 1 0;
  }

  .score-card strong {
    font-size: clamp(1.65rem, 8vw, 2.25rem);
  }

  .back-button {
    grid-area: back;
    justify-self: stretch;
  }

  .music-button {
    grid-area: music;
    min-width: 72px;
    padding-right: 8px;
    padding-left: 8px;
    justify-self: stretch;
  }

  .repeat-button {
    grid-area: repeat;
    justify-self: stretch;
  }

  .small-button {
    min-width: 72px;
  }

  .round-heading {
    grid-template-columns: auto 1fr;
  }

  .feedback {
    grid-column: 1 / -1;
    min-width: 0;
  }
}

@media (max-height: 520px) {
  .time-up-dialog {
    gap: 6px;
    padding: 10px 16px;
    border-width: 4px;
    box-shadow: 7px 7px 0 var(--green), -6px -5px 0 var(--pink);
  }

  .time-up-sticker {
    display: none;
  }

  .time-up-dialog h2 {
    font-size: clamp(1.75rem, 9dvh, 2.75rem);
  }

  .time-up-dialog > p {
    font-size: clamp(0.78rem, 3.3dvh, 0.95rem);
    line-height: 1.12;
  }

  .time-up-result {
    min-width: 120px;
    padding: 5px 12px;
    border-width: 3px;
  }

  .time-up-result strong {
    font-size: clamp(2.1rem, 10dvh, 3.1rem);
  }

  .time-up-ok {
    min-width: 120px;
    min-height: 46px;
    padding: 6px 20px;
    border-width: 3px;
    font-size: 1.15rem;
  }
}

@media (max-width: 390px) {
  .start-controls {
    gap: 5px;
  }

  .timer-popover {
    width: min(300px, calc(100vw - 34px));
    padding-right: 16px;
    padding-left: 16px;
  }

  .mode-grid {
    gap: 9px;
  }

  .mode-card {
    min-height: 145px;
    padding-inline: 7px;
    box-shadow: 5px 6px 0 var(--ink);
  }

  .mode-sample {
    font-size: 2.25rem;
  }

  .mode-name {
    font-size: 1.25rem;
  }

  .start-area {
    flex-direction: column;
  }

  #selected-mode {
    max-width: none;
  }
}

@media (orientation: landscape) {
  .board {
    gap: clamp(12px, 1.5vmin, 17px);
    padding: clamp(10px, 1.8vmin, 20px);
  }

}

@media (orientation: landscape) and (max-height: 650px) {
  .game-screen {
    gap: 5px;
  }

  .small-button,
  .score-card {
    min-height: 72px;
  }

  .round-heading {
    min-height: 50px;
  }

  .round-heading h2 {
    font-size: clamp(1.7rem, 4.5vh, 2.5rem);
  }

  .feedback,
  .mode-label {
    font-size: 0.72rem;
  }
}

@media (orientation: landscape) and (max-height: 650px) and (min-width: 600px) {
  .start-screen {
    grid-template-columns: minmax(210px, 0.75fr) minmax(350px, 1.25fr);
    grid-template-rows: 1fr auto;
    gap: 12px clamp(18px, 3vw, 34px);
    padding: 7px 12px;
  }

  .welcome {
    grid-row: 1 / span 2;
    padding: 6px;
    text-align: left;
  }

  .app-name {
    margin-bottom: 9px;
  }

  h1 {
    margin-inline: 0;
    font-size: clamp(3rem, 8vw, 5.4rem);
  }

  .intro {
    margin: 12px 0 0;
    font-size: clamp(0.95rem, 2.5vh, 1.15rem);
  }

  .mode-picker legend {
    margin-bottom: 9px;
    font-size: 0.9rem;
  }

  .mode-card {
    min-height: 138px;
    padding: 14px 9px 10px;
  }

  .mode-sample {
    font-size: clamp(2.2rem, 8vh, 3.5rem);
  }

  .mode-name {
    margin-top: 8px;
    font-size: clamp(1.2rem, 4vh, 1.75rem);
  }

  .start-area {
    gap: 12px;
  }

  .start-button {
    min-height: 72px;
  }

  .learning-bear {
    top: 1px;
    right: 3px;
    width: clamp(82px, 10vw, 104px);
  }

  .bear-gaze {
    top: 1px;
    right: 3px;
    width: clamp(82px, 10vw, 104px);
  }
}

@media (display-mode: standalone) {
  :root {
    --safe-top: max(16px, env(safe-area-inset-top));
    --safe-right: max(14px, env(safe-area-inset-right));
    --safe-bottom: max(16px, env(safe-area-inset-bottom));
    --safe-left: max(14px, env(safe-area-inset-left));
  }

  html,
  body {
    width: 100%;
    height: 100%;
  }

  body {
    position: fixed;
    inset: 0;
  }

  .app-shell {
    min-height: 100%;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    scroll-behavior: auto !important;
    transition-duration: 0.01ms !important;
  }

  .answer-card.is-wrong,
  .answer-card.is-correct,
  .celebration p {
    animation-duration: 0.01ms;
  }

  .learning-bear {
    animation: none;
    transform: rotate(3deg);
  }

  .bear-gaze {
    animation: none;
    transform: rotate(3deg);
  }

  .bear-pupil {
    top: 55%;
    left: 50%;
    transition: none;
  }
}
