
:root {
  --ink: #102724;
  --ink-soft: #35514d;
  --paper: #f3f1e9;
  --paper-deep: #e8e4d8;
  --card: #fffefa;
  --board: #102724;
  --board-deep: #091b19;
  --cream: #f7f2d8;
  --mint: #77e5cd;
  --mint-deep: #2fb798;
  --yellow: #ffd84d;
  --coral: #ff806d;
  --line: rgba(16, 39, 36, 0.12);
  --shadow: 0 20px 60px rgba(32, 46, 42, 0.12);
}

* {
  box-sizing: border-box;
}

html {
  min-width: 320px;
  background: var(--paper);
}

body {
  min-height: 100vh;
  margin: 0;
  overflow-x: hidden;
  color: var(--ink);
  background:
    radial-gradient(circle at 8% 12%, rgba(255, 216, 77, 0.16), transparent 23rem),
    radial-gradient(circle at 94% 82%, rgba(119, 229, 205, 0.15), transparent 26rem),
    var(--paper);
  font-family:
    "Avenir Next", "Noto Sans TC", "PingFang TC", "Microsoft JhengHei",
    system-ui, sans-serif;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

button {
  color: inherit;
  font: inherit;
}

button:focus-visible {
  outline: 3px solid rgba(47, 183, 152, 0.4);
  outline-offset: 3px;
}

.game-app {
  width: min(100%, 1480px);
  min-height: 100vh;
  margin: 0 auto;
  padding: 0 30px 30px;
}

.topbar {
  position: relative;
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: space-between;
  min-height: 82px;
  border-bottom: 1px solid var(--line);
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  user-select: none;
}

.brand > span:last-child {
  display: flex;
  align-items: baseline;
  gap: 9px;
}

.brand strong {
  font-size: 1.12rem;
  font-weight: 850;
  letter-spacing: 0.05em;
}

.brand small,
.eyebrow {
  color: #718480;
  font-size: 0.66rem;
  font-weight: 800;
  letter-spacing: 0.16em;
}

.brand-mark {
  position: relative;
  display: block;
  width: 38px;
  height: 38px;
  border-radius: 12px;
  background: var(--ink);
  box-shadow: 0 7px 16px rgba(16, 39, 36, 0.18);
}

.brand-mark i {
  position: absolute;
  width: 7px;
  height: 7px;
  border: 2px solid var(--cream);
  border-radius: 50%;
}

.brand-mark i:nth-child(1) {
  left: 8px;
  top: 9px;
}

.brand-mark i:nth-child(2) {
  right: 7px;
  top: 8px;
}

.brand-mark i:nth-child(3) {
  right: 10px;
  bottom: 7px;
  border-color: var(--yellow);
}

.brand-mark::before,
.brand-mark::after {
  position: absolute;
  content: "";
  height: 2px;
  border-radius: 99px;
  background: var(--cream);
  transform-origin: left center;
}

.brand-mark::before {
  left: 14px;
  top: 12px;
  width: 11px;
  transform: rotate(-3deg);
}

.brand-mark::after {
  left: 27px;
  top: 14px;
  width: 11px;
  transform: rotate(75deg);
}

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

.streak-pill,
.quiet-button {
  display: inline-flex;
  min-height: 40px;
  align-items: center;
  justify-content: center;
  gap: 7px;
  padding: 0 14px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: rgba(255, 254, 250, 0.64);
  color: var(--ink-soft);
  font-size: 0.78rem;
  font-weight: 700;
  backdrop-filter: blur(12px);
}

.streak-pill span {
  color: #d69f00;
}

.streak-pill b {
  color: var(--ink);
  font-variant-numeric: tabular-nums;
}

.quiet-button {
  cursor: pointer;
  transition: 160ms ease;
}

.quiet-button:hover {
  border-color: rgba(16, 39, 36, 0.25);
  background: var(--card);
  transform: translateY(-1px);
}

.game-layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 330px;
  gap: clamp(24px, 3vw, 48px);
  align-items: start;
  padding-top: 24px;
}

.board-column {
  min-width: 0;
}

.board-heading {
  display: flex;
  min-height: 68px;
  align-items: flex-start;
  justify-content: space-between;
  gap: 24px;
}

.board-heading h1 {
  margin: 5px 0 0;
  font-size: clamp(1.55rem, 2.5vw, 2.5rem);
  font-weight: 820;
  letter-spacing: -0.045em;
  line-height: 1.1;
}

.level-code {
  flex: 0 0 auto;
  margin-top: 9px;
  padding: 8px 12px;
  border: 1px solid var(--line);
  border-radius: 9px;
  color: #617671;
  background: rgba(255, 254, 250, 0.62);
  font-family: var(--font-geist-mono, ui-monospace), monospace;
  font-size: 0.69rem;
  letter-spacing: 0.04em;
}

.level-code b {
  color: var(--ink);
}

.stage-frame {
  padding: 10px;
  border: 1px solid rgba(16, 39, 36, 0.1);
  border-radius: 30px;
  background: rgba(255, 254, 250, 0.7);
  box-shadow: var(--shadow), inset 0 1px 0 rgba(255, 255, 255, 0.86);
}

.game-stage {
  position: relative;
  height: clamp(430px, calc(100vh - 265px), 650px);
  min-height: 430px;
  overflow: hidden;
  border-radius: 22px;
  isolation: isolate;
  background:
    radial-gradient(circle at 50% 45%, rgba(39, 76, 70, 0.78), transparent 60%),
    linear-gradient(145deg, var(--board), var(--board-deep));
  box-shadow:
    inset 0 0 80px rgba(0, 0, 0, 0.28),
    inset 0 1px 0 rgba(255, 255, 255, 0.05);
  touch-action: none;
  user-select: none;
}

.board-grain {
  position: absolute;
  inset: 0;
  z-index: -1;
  opacity: 0.34;
  background-image:
    radial-gradient(circle at 20% 30%, rgba(255, 255, 255, 0.1) 0 0.6px, transparent 0.9px),
    radial-gradient(circle at 75% 62%, rgba(255, 255, 255, 0.07) 0 0.7px, transparent 1px),
    linear-gradient(92deg, transparent 49.7%, rgba(255, 255, 255, 0.018) 50%, transparent 50.3%);
  background-size: 8px 9px, 11px 13px, 57px 100%;
  mix-blend-mode: soft-light;
}

.game-stage canvas {
  position: absolute;
  inset: 0;
  z-index: 1;
  width: 100%;
  height: 100%;
  pointer-events: none;
}

.node-dot {
  position: absolute;
  z-index: 3;
  display: grid;
  width: 54px;
  height: 54px;
  place-items: center;
  padding: 0;
  border: 0;
  border-radius: 50%;
  background: transparent;
  cursor: crosshair;
  transform: translate(-50%, -50%);
  -webkit-tap-highlight-color: transparent;
}

.node-dot > span {
  display: block;
  width: 23px;
  height: 23px;
  border: 3px solid rgba(247, 242, 216, 0.88);
  border-radius: 50%;
  background: var(--board);
  box-shadow:
    0 0 0 1px rgba(255, 255, 255, 0.1),
    0 0 10px rgba(247, 242, 216, 0.11);
  transition: 160ms ease;
}

.node-dot:hover > span,
.node-dot:focus-visible > span {
  width: 28px;
  height: 28px;
  border-color: #fffbe8;
  box-shadow: 0 0 0 7px rgba(247, 242, 216, 0.09);
}

.node-dot.is-visited > span {
  border-color: var(--mint);
}

.node-dot.is-current > span {
  width: 29px;
  height: 29px;
  border: 5px solid #17322e;
  background: var(--yellow);
  box-shadow:
    0 0 0 4px rgba(255, 216, 77, 0.82),
    0 0 0 11px rgba(255, 216, 77, 0.1),
    0 0 22px rgba(255, 216, 77, 0.54);
}

.node-dot.is-current::after,
.node-dot.is-start::after {
  position: absolute;
  inset: 3px;
  content: "";
  border: 1px solid rgba(255, 216, 77, 0.62);
  border-radius: 50%;
  animation: node-pulse 1.5s ease-out infinite;
}

.node-dot.is-start > span {
  border-color: var(--yellow);
  box-shadow:
    0 0 0 6px rgba(255, 216, 77, 0.1),
    0 0 20px rgba(255, 216, 77, 0.42);
}

.node-dot em {
  position: absolute;
  top: 46px;
  padding: 4px 8px;
  border-radius: 99px;
  color: #42360a;
  background: var(--yellow);
  font-size: 0.65rem;
  font-style: normal;
  font-weight: 900;
  letter-spacing: 0.1em;
  box-shadow: 0 6px 12px rgba(0, 0, 0, 0.18);
  pointer-events: none;
}

@keyframes node-pulse {
  0% {
    opacity: 0.9;
    transform: scale(0.72);
  }
  90%,
  100% {
    opacity: 0;
    transform: scale(1.45);
  }
}

.status-toast {
  position: absolute;
  z-index: 5;
  bottom: 18px;
  left: 50%;
  display: flex;
  min-height: 38px;
  max-width: calc(100% - 32px);
  align-items: center;
  gap: 8px;
  padding: 8px 14px;
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: 999px;
  color: rgba(255, 255, 255, 0.82);
  background: rgba(5, 19, 17, 0.72);
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.2);
  font-size: 0.74rem;
  font-weight: 650;
  text-align: center;
  transform: translateX(-50%);
  backdrop-filter: blur(12px);
  pointer-events: none;
}

.status-toast.is-silent {
  opacity: 0;
  visibility: hidden;
}

.status-light {
  width: 7px;
  height: 7px;
  flex: 0 0 auto;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.45);
}

.status-light-playing {
  background: var(--mint);
  box-shadow: 0 0 8px var(--mint);
}

.status-light-stuck {
  background: var(--coral);
  box-shadow: 0 0 8px var(--coral);
}

.status-light-won {
  background: var(--yellow);
  box-shadow: 0 0 8px var(--yellow);
}

.shake-0 {
  animation: board-shake-a 330ms ease;
}

.shake-1 {
  animation: board-shake-b 330ms ease;
}

@keyframes board-shake-a {
  20%,
  60% {
    transform: translateX(-6px);
  }
  40%,
  80% {
    transform: translateX(6px);
  }
}

@keyframes board-shake-b {
  20%,
  60% {
    transform: translateX(6px);
  }
  40%,
  80% {
    transform: translateX(-6px);
  }
}

.status-won {
  animation: board-win 900ms ease;
}

@keyframes board-win {
  0%,
  100% {
    box-shadow: inset 0 0 80px rgba(0, 0, 0, 0.28);
  }
  38% {
    box-shadow:
      inset 0 0 130px rgba(119, 229, 205, 0.5),
      0 0 55px rgba(119, 229, 205, 0.48);
  }
}

.success-layer {
  position: absolute;
  inset: 0;
  z-index: 12;
  display: grid;
  place-items: center;
  padding: 18px;
  background:
    radial-gradient(circle at 50% 48%, rgba(255, 216, 77, 0.22), transparent 24%),
    rgba(4, 18, 16, 0.5);
  backdrop-filter: blur(7px);
  animation: success-fade 320ms ease both;
}

.success-layer::before,
.success-layer::after {
  position: absolute;
  left: 50%;
  top: 50%;
  width: min(72vw, 620px);
  aspect-ratio: 1;
  border: 3px solid rgba(255, 216, 77, 0.72);
  border-radius: 50%;
  content: "";
  pointer-events: none;
  z-index: 1;
  box-shadow: 0 0 28px rgba(255, 216, 77, 0.55), inset 0 0 24px rgba(255, 216, 77, 0.32);
  mix-blend-mode: screen;
  transform: translate(-50%, -50%) scale(0.12);
  animation: success-ring-burst 1.2s cubic-bezier(0.12, 0.68, 0.2, 1) both;
}

.success-layer::after {
  width: min(48vw, 410px);
  border-width: 2px;
  border-color: rgba(247, 242, 216, 0.84);
  animation-delay: 90ms;
}

.failure-layer {
  position: absolute;
  inset: 0;
  z-index: 13;
  display: grid;
  place-items: center;
  padding: 18px;
  background: rgba(31, 6, 10, 0.78);
  backdrop-filter: blur(7px);
  animation: success-fade 220ms ease both;
}

.failure-card {
  position: relative;
  z-index: 2;
  width: min(360px, 100%);
  padding: 28px 28px 24px;
  border: 1px solid rgba(255, 220, 209, 0.8);
  border-radius: 26px;
  background: rgba(255, 248, 241, 0.98);
  box-shadow: 0 28px 80px rgba(0, 0, 0, 0.42);
  text-align: center;
  animation: failure-pop 420ms cubic-bezier(0.16, 1.18, 0.4, 1) both;
}

.failure-mark {
  display: grid;
  width: 62px;
  height: 62px;
  margin: -58px auto 17px;
  place-items: center;
  border: 7px solid #fff8f1;
  border-radius: 50%;
  color: #fff8f1;
  background: var(--coral);
  box-shadow:
    0 12px 24px rgba(208, 94, 87, 0.34),
    0 0 0 6px rgba(240, 138, 125, 0.22);
  font-size: 1.9rem;
  font-weight: 900;
}

.failure-card > p {
  margin: 0 0 5px;
  color: #b64d4c;
  font-size: 0.65rem;
  font-weight: 900;
  letter-spacing: 0.2em;
}

.failure-card h2 {
  margin: 0;
  color: #432b2a;
  font-size: clamp(1.5rem, 3vw, 2rem);
  letter-spacing: -0.04em;
}

.failure-copy {
  display: block;
  margin: 10px 0 18px;
  color: #816d6a;
  font-size: 0.78rem;
  line-height: 1.65;
}

.retry-button {
  display: inline-flex;
  width: 100%;
  min-height: 50px;
  align-items: center;
  justify-content: center;
  gap: 8px;
  border: 0;
  border-radius: 13px;
  color: #fff8f1;
  background: #a84442;
  box-shadow: 0 9px 18px rgba(168, 68, 66, 0.25);
  font-weight: 850;
  cursor: pointer;
  transition: 160ms ease;
}

.retry-button:hover {
  background: #8f3838;
  transform: translateY(-2px);
}

.success-card {
  position: relative;
  z-index: 2;
  width: min(390px, 100%);
  padding: 28px 28px 24px;
  border: 1px solid rgba(255, 255, 255, 0.78);
  border-radius: 26px;
  background: rgba(255, 254, 250, 0.97);
  box-shadow: 0 28px 80px rgba(0, 0, 0, 0.36);
  text-align: center;
  animation: success-pop 560ms cubic-bezier(0.16, 1.25, 0.4, 1) both;
}

.success-check {
  display: grid;
  width: 62px;
  height: 62px;
  margin: -58px auto 17px;
  place-items: center;
  border: 7px solid #f8f3dd;
  border-radius: 50%;
  color: var(--ink);
  background: var(--mint);
  box-shadow:
    0 12px 24px rgba(47, 183, 152, 0.34),
    0 0 0 6px rgba(119, 229, 205, 0.25);
  font-size: 1.75rem;
  font-weight: 1000;
}

.success-card > p {
  margin: 0 0 5px;
  color: var(--mint-deep);
  font-size: 0.65rem;
  font-weight: 900;
  letter-spacing: 0.2em;
}

.success-card h2 {
  margin: 0;
  font-size: clamp(1.5rem, 3vw, 2rem);
  letter-spacing: -0.04em;
}

.result-stars {
  display: flex;
  justify-content: center;
  gap: 4px;
  margin: 10px 0 16px;
}

.result-stars span {
  color: #d8d7cf;
  font-size: 1.35rem;
  transform: scale(0.9);
}

.result-stars span.on {
  color: #f4b900;
  filter: drop-shadow(0 3px 4px rgba(207, 152, 0, 0.2));
  transform: scale(1);
}

.result-facts {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  margin-bottom: 18px;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: #f7f5ef;
}

.result-facts span {
  display: flex;
  flex-direction: column;
  gap: 3px;
  padding: 10px 8px;
}

.result-facts span + span {
  border-left: 1px solid var(--line);
}

.result-facts small {
  color: #7c8b87;
  font-size: 0.65rem;
}

.result-facts b {
  font-size: 0.9rem;
  font-variant-numeric: tabular-nums;
}

.next-button {
  width: 100%;
  min-height: 50px;
  border: 0;
  border-radius: 13px;
  color: var(--cream);
  background: var(--ink);
  box-shadow: 0 9px 18px rgba(16, 39, 36, 0.22);
  font-weight: 850;
  cursor: pointer;
  transition: 160ms ease;
}

.success-retry-button {
  width: 100%;
  min-height: 50px;
  margin-bottom: 9px;
  border: 1px solid var(--line);
  border-radius: 13px;
  color: var(--ink);
  background: #f3f1e8;
  box-shadow: 0 6px 14px rgba(16, 39, 36, 0.08);
  font-weight: 850;
  cursor: pointer;
  transition: 160ms ease;
}

.success-retry-button:hover {
  background: #e9e6d9;
  transform: translateY(-2px);
}

.next-button:hover {
  background: #1b4841;
  transform: translateY(-2px);
}

.confetti {
  position: absolute;
  left: 50%;
  top: 50%;
  width: 0;
  height: 0;
  z-index: 1;
  pointer-events: none;
}

.confetti i {
  position: absolute;
  width: 9px;
  height: 16px;
  border-radius: 2px;
  background: var(--yellow);
  animation: confetti-burst 1.05s cubic-bezier(0.2, 0.75, 0.25, 1) var(--d) both;
}

.confetti i:nth-child(3n + 1) {
  background: var(--mint);
}

.confetti i:nth-child(3n + 2) {
  background: var(--coral);
}

@keyframes success-fade {
  from {
    opacity: 0;
  }
}

@keyframes success-pop {
  from {
    opacity: 0;
    transform: translateY(18px) scale(0.78) rotate(-2deg);
  }
  to {
    opacity: 1;
    transform: translateY(0) scale(1) rotate(0);
  }
}

@keyframes failure-pop {
  from {
    opacity: 0;
    transform: translateY(14px) scale(0.86) rotate(1deg);
  }
  to {
    opacity: 1;
    transform: translateY(0) scale(1) rotate(0);
  }
}

@keyframes confetti-burst {
  from {
    opacity: 1;
    transform: translate(-50%, -50%) rotate(0);
  }
  to {
    opacity: 0;
    transform: translate(var(--x), var(--y)) rotate(var(--r));
  }
}

@keyframes success-ring-burst {
  0% {
    opacity: 0;
    transform: translate(-50%, -50%) scale(0.12);
  }
  14% {
    opacity: 1;
  }
  100% {
    opacity: 0;
    transform: translate(-50%, -50%) scale(1);
  }
}

.board-toolbar {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  min-height: 62px;
  gap: 12px;
}

.board-toolbar > button {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  width: max-content;
  min-height: 39px;
  padding: 0 12px;
  border: 0;
  border-radius: 10px;
  color: var(--ink-soft);
  background: transparent;
  font-size: 0.78rem;
  font-weight: 750;
  cursor: pointer;
}

.board-toolbar > button:last-child {
  justify-self: end;
}

.board-toolbar > button:hover:not(:disabled) {
  background: rgba(255, 254, 250, 0.75);
}

.board-toolbar > button:disabled {
  opacity: 0.35;
  cursor: not-allowed;
}

kbd {
  display: inline-grid;
  min-width: 22px;
  height: 20px;
  place-items: center;
  padding: 0 5px;
  border: 1px solid rgba(16, 39, 36, 0.11);
  border-bottom-width: 2px;
  border-radius: 5px;
  color: #83918e;
  background: rgba(255, 255, 255, 0.54);
  font-family: ui-monospace, monospace;
  font-size: 0.59rem;
}

.live-timer {
  display: flex;
  align-items: baseline;
  justify-content: center;
  gap: 8px;
  font-variant-numeric: tabular-nums;
}

.live-timer span {
  color: #889692;
  font-size: 0.58rem;
  font-weight: 850;
  letter-spacing: 0.14em;
}

.live-timer b {
  min-width: 59px;
  font-family: ui-monospace, "SFMono-Regular", Consolas, monospace;
  font-size: 0.85rem;
}

.control-panel {
  position: sticky;
  top: 18px;
  display: flex;
  flex-direction: column;
  gap: 11px;
}

.panel-section {
  padding: 18px;
  border: 1px solid var(--line);
  border-radius: 20px;
  background: rgba(255, 254, 250, 0.8);
  box-shadow: 0 10px 30px rgba(38, 52, 48, 0.055);
  backdrop-filter: blur(12px);
}

.section-title {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 14px;
}

.section-title.compact {
  margin-bottom: 10px;
}

.section-title h2 {
  margin: 2px 0 0;
  font-size: 1rem;
  letter-spacing: -0.02em;
}

.auto-label {
  padding: 4px 7px;
  border-radius: 7px;
  color: #347a6c;
  background: rgba(119, 229, 205, 0.18);
  font-size: 0.62rem;
  font-weight: 850;
}

.difficulty-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 6px;
}

.difficulty-grid button {
  display: flex;
  min-width: 0;
  min-height: 57px;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  padding: 4px 2px;
  border: 1px solid rgba(16, 39, 36, 0.11);
  border-radius: 11px;
  background: rgba(255, 255, 255, 0.52);
  cursor: pointer;
  transition: 160ms ease;
}

.difficulty-grid button:hover {
  border-color: rgba(16, 39, 36, 0.28);
  transform: translateY(-1px);
}

.difficulty-grid button.active {
  border-color: var(--ink);
  color: var(--cream);
  background: var(--ink);
  box-shadow: 0 7px 14px rgba(16, 39, 36, 0.2);
}

.difficulty-grid b {
  font-size: 0.74rem;
}

.difficulty-grid small {
  color: #84918f;
  font-size: 0.59rem;
}

.difficulty-grid button.active small {
  color: rgba(247, 242, 216, 0.62);
}

.round-stats {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  margin-top: 13px;
}

.round-stats span {
  display: flex;
  min-width: 0;
  flex-direction: column;
  gap: 2px;
  padding: 9px 10px;
  border-radius: 10px;
  background: rgba(232, 228, 216, 0.46);
}

.round-stats small {
  color: #7c8b87;
  font-size: 0.6rem;
}

.round-stats b {
  overflow: hidden;
  font-family: ui-monospace, monospace;
  font-size: 0.78rem;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.primary-actions {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.new-game-button,
.hint-button {
  display: flex;
  width: 100%;
  align-items: center;
  border-radius: 13px;
  cursor: pointer;
  transition: 170ms ease;
}

.new-game-button {
  min-height: 62px;
  gap: 11px;
  padding: 8px 13px;
  border: 0;
  color: var(--cream);
  background: var(--ink);
  box-shadow: 0 10px 20px rgba(16, 39, 36, 0.19);
  text-align: left;
}

.new-game-button > span:nth-child(2) {
  display: flex;
  min-width: 0;
  flex: 1;
  flex-direction: column;
  gap: 2px;
}

.new-game-button b {
  font-size: 0.82rem;
}

.new-game-button small {
  color: rgba(247, 242, 216, 0.58);
  font-size: 0.61rem;
}

.new-game-button:hover,
.hint-button:hover:not(:disabled) {
  transform: translateY(-2px);
}

.new-game-button:hover {
  background: #1b4841;
  box-shadow: 0 13px 24px rgba(16, 39, 36, 0.24);
}

.dice,
.hint-button > span:first-child {
  display: grid;
  width: 30px;
  height: 30px;
  flex: 0 0 auto;
  place-items: center;
  border-radius: 9px;
}

.dice {
  color: var(--ink);
  background: var(--yellow);
}

.hint-button {
  min-height: 44px;
  gap: 9px;
  padding: 5px 10px;
  border: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.55);
  color: var(--ink-soft);
  font-size: 0.73rem;
  font-weight: 750;
}

.hint-button > span:first-child {
  width: 27px;
  height: 27px;
  border: 1px solid rgba(16, 39, 36, 0.15);
  border-radius: 50%;
  font-weight: 900;
}

.hint-button kbd {
  margin-left: auto;
}

.hint-button:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

.how-to ol {
  display: flex;
  flex-direction: column;
  gap: 3px;
  margin: 0;
  padding: 0;
  list-style: none;
}

.how-to li {
  display: flex;
  min-height: 29px;
  align-items: center;
  gap: 10px;
  color: #536864;
  font-size: 0.7rem;
}

.how-to li b {
  width: 24px;
  color: var(--mint-deep);
  font-family: ui-monospace, monospace;
  font-size: 0.64rem;
}

.local-note {
  margin: 0;
  color: #87938f;
  font-size: 0.62rem;
  text-align: center;
}

.local-note span {
  margin-right: 3px;
  color: var(--mint-deep);
  font-size: 0.5rem;
}

@media (max-width: 1100px) {
  .game-layout {
    grid-template-columns: minmax(0, 1fr) 305px;
    gap: 24px;
  }

  .panel-section {
    padding: 15px;
  }

  .game-stage {
    height: clamp(430px, calc(100vh - 265px), 610px);
  }
}

@media (max-width: 900px) {
  .game-app {
    padding-inline: 22px;
  }

  .game-layout {
    grid-template-columns: 1fr;
  }

  .game-stage {
    height: min(66vh, 620px);
    min-height: 470px;
  }

  .control-panel {
    position: static;
    display: grid;
    grid-template-columns: 1fr 1fr;
  }

  .difficulty-section,
  .local-note {
    grid-column: 1 / -1;
  }

  .local-note {
    padding: 8px 0 18px;
  }
}

@media (max-width: 620px) {
  .game-app {
    padding: 0 14px 22px;
  }

  .topbar {
    min-height: 68px;
  }

  .brand > span:last-child {
    display: block;
  }

  .brand small {
    display: none;
  }

  .brand strong {
    font-size: 1rem;
  }

  .brand-mark {
    width: 35px;
    height: 35px;
  }

  .streak-pill {
    padding: 0 10px;
  }

  .quiet-button {
    width: 40px;
    padding: 0;
    font-size: 0;
  }

  .quiet-button span {
    font-size: 1rem;
  }

  .quiet-button .sound-label {
    display: none;
  }

  .game-layout {
    gap: 16px;
    padding-top: 17px;
  }

  .board-heading {
    min-height: 63px;
    gap: 12px;
  }

  .board-heading h1 {
    font-size: 1.48rem;
  }

  .level-code {
    margin-top: 5px;
    padding: 7px 8px;
    font-size: 0.6rem;
  }

  .stage-frame {
    padding: 7px;
    border-radius: 23px;
  }

  .game-stage {
    height: min(64svh, 460px);
    min-height: 370px;
    border-radius: 18px;
  }

  .node-dot {
    width: 50px;
    height: 50px;
  }

  .status-toast {
    bottom: 13px;
    width: max-content;
    font-size: 0.68rem;
  }

  .board-toolbar {
    min-height: 57px;
    gap: 4px;
  }

  .board-toolbar > button {
    gap: 4px;
    padding: 0 7px;
    font-size: 0.7rem;
  }

  .board-toolbar kbd {
    display: none;
  }

  .live-timer {
    flex-direction: column;
    gap: 1px;
  }

  .live-timer b {
    font-size: 0.75rem;
    text-align: center;
  }

  .control-panel {
    grid-template-columns: 1fr;
  }

  .difficulty-section,
  .local-note {
    grid-column: auto;
  }

  .panel-section {
    border-radius: 17px;
  }

  .success-card,
  .failure-card {
    padding: 25px 20px 20px;
  }

  .success-check {
    margin-top: -52px;
  }
}

@media (max-width: 370px) {
  .streak-pill {
    font-size: 0;
  }

  .streak-pill b,
  .streak-pill span {
    font-size: 0.76rem;
  }

  .level-code {
    display: none;
  }

  .game-stage {
    min-height: 350px;
  }
}

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

/* Clear, child-friendly controls and the tablet handoff panel. */
body {
  font-size: 18px;
}

.board-heading h1 {
  font-size: clamp(1.8rem, 2.8vw, 2.65rem);
}

.status-toast {
  min-height: 46px;
  padding: 10px 18px;
  font-size: 0.95rem;
}

.panel-section {
  padding: 22px;
}

.section-title h2 {
  font-size: 1.2rem;
}

.difficulty-grid button {
  min-height: 70px;
}

.difficulty-grid b {
  font-size: 0.95rem;
}

.difficulty-grid small {
  font-size: 0.72rem;
}

.round-stats small {
  font-size: 0.7rem;
}

.new-game-button b {
  font-size: 1rem;
}

.new-game-button small {
  font-size: 0.75rem;
}

.hint-button {
  min-height: 52px;
  font-size: 0.9rem;
}

.how-to li {
  font-size: 0.84rem;
}

.local-note {
  font-size: 0.74rem;
}

.qr-layer {
  position: fixed;
  inset: 0;
  z-index: 40;
  display: grid;
  place-items: center;
  padding: 18px;
  background: rgba(4, 18, 16, 0.82);
  backdrop-filter: blur(9px);
  animation: success-fade 220ms ease both;
}

.qr-card {
  position: relative;
  display: flex;
  width: min(390px, 100%);
  flex-direction: column;
  align-items: center;
  padding: 30px 28px 24px;
  border: 2px solid rgba(119, 229, 205, 0.55);
  border-radius: 26px;
  color: var(--ink);
  background: #fffef9;
  box-shadow: 0 28px 80px rgba(0, 0, 0, 0.42);
  text-align: center;
  animation: success-pop 480ms cubic-bezier(0.16, 1.18, 0.4, 1) both;
}

.qr-symbol {
  display: grid;
  width: 62px;
  height: 62px;
  margin: -60px auto 14px;
  place-items: center;
  border: 7px solid #fffef9;
  border-radius: 18px;
  color: var(--ink);
  background: var(--yellow);
  box-shadow: 0 9px 22px rgba(192, 146, 0, 0.3);
  font-size: 2.1rem;
  font-weight: 900;
}

.qr-card > p {
  margin: 0 0 5px;
  color: var(--mint-deep);
  font-size: 0.68rem;
  font-weight: 900;
  letter-spacing: 0.2em;
}

.qr-card h2 {
  margin: 0 0 16px;
  font-size: clamp(1.4rem, 3vw, 1.9rem);
}

.qr-card img {
  display: block;
  width: min(260px, 78vw);
  height: auto;
  aspect-ratio: 1;
  border: 10px solid #fff;
  border-radius: 12px;
  background: #fff;
  box-shadow: 0 7px 20px rgba(16, 39, 36, 0.14);
}

.qr-url {
  max-width: 100%;
  margin-top: 10px;
  overflow: hidden;
  color: #71817e;
  font-family: ui-monospace, monospace;
  font-size: 0.63rem;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.qr-close,
.qr-close-action {
  cursor: pointer;
}

.qr-close {
  position: absolute;
  top: 10px;
  right: 12px;
  display: grid;
  width: 38px;
  height: 38px;
  place-items: center;
  border: 0;
  border-radius: 50%;
  color: #59716b;
  background: rgba(16, 39, 36, 0.08);
  font-size: 1.5rem;
}

.qr-close-action {
  width: 100%;
  min-height: 50px;
  margin-top: 16px;
  border: 0;
  border-radius: 13px;
  color: var(--cream);
  background: var(--ink);
  font-size: 0.95rem;
  font-weight: 850;
}

@media (min-width: 901px) {
  .control-panel {
    width: 350px;
  }
}

@media (max-width: 620px) {
  .top-actions {
    gap: 5px;
  }

  .qr-card {
    padding-inline: 20px;
  }

  .qr-card img {
    width: min(230px, 72vw);
  }
}

/* Fullscreen game surface */
body {
  overflow: hidden;
  background: var(--board-deep);
}

.game-app {
  width: 100%;
  max-width: none;
  height: 100svh;
  min-height: 0;
  padding: 0;
}

.topbar {
  position: fixed;
  inset: 0 0 auto;
  z-index: 30;
  min-height: 74px;
  padding: 0 26px;
  border: 0;
  color: var(--cream);
  background: linear-gradient(180deg, rgba(4, 18, 16, 0.86), transparent);
  pointer-events: none;
}

.topbar .brand,
.topbar .top-actions {
  pointer-events: auto;
}

.brand strong {
  color: var(--cream);
}

.brand small {
  color: var(--mint);
}

.brand-mark {
  background: var(--cream);
}

.brand-mark i {
  border-color: var(--ink);
}

.brand-mark i:nth-child(3) {
  border-color: #a77a00;
}

.brand-mark::before,
.brand-mark::after {
  background: var(--ink);
}

.topbar .streak-pill,
.topbar .quiet-button {
  border-color: rgba(255, 255, 255, 0.12);
  color: rgba(255, 255, 255, 0.78);
  background: rgba(5, 22, 20, 0.58);
}

.topbar .streak-pill b {
  color: var(--cream);
}

.topbar .quiet-button:hover {
  border-color: rgba(255, 255, 255, 0.24);
  background: rgba(18, 51, 46, 0.82);
}

.game-layout,
.board-column {
  width: 100%;
  height: 100%;
  min-height: 0;
  padding: 0;
}

.game-layout {
  display: block;
}

.board-heading {
  position: fixed;
  z-index: 8;
  top: 88px;
  left: 30px;
  display: block;
  min-height: 0;
  color: var(--cream);
  pointer-events: none;
}

.board-heading .eyebrow {
  color: rgba(119, 229, 205, 0.82);
}

.board-heading h1 {
  margin-top: 4px;
  font-size: clamp(1.45rem, 2.3vw, 2.25rem);
  text-shadow: 0 5px 20px rgba(0, 0, 0, 0.25);
}

.level-code {
  position: fixed;
  top: 94px;
  right: 370px;
  margin: 0;
  border-color: rgba(255, 255, 255, 0.12);
  color: rgba(255, 255, 255, 0.55);
  background: rgba(4, 18, 16, 0.42);
  backdrop-filter: blur(10px);
}

.level-code b {
  color: var(--cream);
}

.stage-frame {
  position: absolute;
  inset: 0;
  padding: 0;
  border: 0;
  border-radius: 0;
  background: none;
  box-shadow: none;
}

.game-stage {
  width: 100%;
  height: 100svh;
  min-height: 0;
  border-radius: 0;
  background:
    radial-gradient(circle at 38% 48%, rgba(39, 86, 77, 0.82), transparent 48%),
    linear-gradient(145deg, #14302c, #071816 82%);
}

.game-stage::before {
  position: absolute;
  inset: 7px;
  z-index: 25;
  content: "";
  border: 10px solid #8b5a32;
  border-color: #a66e3a #704321 #5d351c #925b2e;
  border-radius: 7px;
  box-shadow:
    inset 0 0 0 2px rgba(255, 222, 166, 0.2),
    inset 0 0 20px rgba(0, 0, 0, 0.44),
    0 0 0 2px #3f2717;
  pointer-events: none;
}

.classroom-decor {
  position: absolute;
  inset: 0;
  z-index: 2;
  overflow: hidden;
  color: rgba(247, 242, 216, 0.22);
  font-family: "Comic Sans MS", "Bradley Hand", "DFKai-SB", cursive;
  pointer-events: none;
}

.chalk-caption {
  position: absolute;
  top: 91px;
  left: calc((100% - 350px) / 2);
  font-size: clamp(0.72rem, 1.2vw, 1rem);
  font-weight: 700;
  letter-spacing: 0.2em;
  transform: translateX(-50%) rotate(-1deg);
}

.chalk-caption::after {
  display: block;
  width: 92%;
  height: 5px;
  margin: 2px auto 0;
  content: "";
  border-top: 2px solid currentColor;
  border-radius: 50%;
}

.chalk-doodle {
  position: absolute;
  filter: blur(0.2px);
  text-shadow: 1px 1px rgba(255, 255, 255, 0.035);
}

.doodle-math {
  top: 34%;
  left: 3.6%;
  font-size: clamp(0.85rem, 1.5vw, 1.25rem);
  transform: rotate(-7deg);
}

.doodle-star {
  bottom: 22%;
  left: 6%;
  font-size: clamp(2.2rem, 5vw, 4.5rem);
  transform: rotate(12deg);
}

.doodle-abc {
  top: 43%;
  right: 354px;
  font-size: clamp(0.75rem, 1.25vw, 1.05rem);
  letter-spacing: 0.2em;
  transform: rotate(5deg);
}

.doodle-wave {
  right: 375px;
  bottom: 18%;
  font-size: 1.35rem;
  transform: rotate(-4deg);
}

.chalk-tray {
  position: absolute;
  right: 368px;
  bottom: 8px;
  left: 9%;
  height: 18px;
  border: 1px solid rgba(47, 24, 10, 0.8);
  border-radius: 2px 2px 7px 7px;
  background:
    linear-gradient(90deg, transparent 8%, rgba(255, 255, 255, 0.12) 24%, transparent 38%),
    linear-gradient(#a66c38, #5e351d);
  box-shadow:
    inset 0 3px rgba(255, 224, 174, 0.16),
    0 -3px 8px rgba(0, 0, 0, 0.28);
}

.chalk-piece {
  position: absolute;
  bottom: 9px;
  width: 44px;
  height: 7px;
  border-radius: 6px 2px 2px 6px;
  box-shadow: 0 2px 3px rgba(0, 0, 0, 0.25);
  transform: rotate(-2deg);
}

.chalk-white {
  left: 20%;
  background: #f4efd7;
}

.chalk-yellow {
  left: calc(20% + 56px);
  width: 34px;
  background: #e9cc62;
  transform: rotate(3deg);
}

.chalk-pink {
  left: calc(20% + 99px);
  width: 25px;
  background: #dc8d88;
  transform: rotate(-5deg);
}

.board-eraser {
  position: absolute;
  right: 10%;
  bottom: 8px;
  width: 72px;
  height: 24px;
  border-radius: 4px 4px 7px 7px;
  background: linear-gradient(#c9b693 0 32%, #5d5144 34% 100%);
  box-shadow: 0 4px 6px rgba(0, 0, 0, 0.32);
  transform: rotate(2deg);
}

.square-playfield {
  position: absolute;
  z-index: 3;
  top: 51%;
  left: calc((100% - 350px) / 2);
  width: min(78svh, calc(100vw - 430px));
  aspect-ratio: 1;
  transform: translate(-50%, -50%);
  touch-action: none;
  user-select: none;
}

.square-playfield canvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
}

.node-dot.is-hint > span {
  border-color: var(--yellow);
  box-shadow:
    0 0 0 7px rgba(255, 216, 77, 0.13),
    0 0 24px rgba(255, 216, 77, 0.58);
}

.node-dot.is-hint::after {
  position: absolute;
  inset: 3px;
  content: "";
  border: 1px solid rgba(255, 216, 77, 0.72);
  border-radius: 50%;
  animation: node-pulse 1.35s ease-out infinite;
}

.status-toast {
  bottom: 28px;
}

.board-toolbar {
  position: fixed;
  z-index: 10;
  bottom: 20px;
  left: calc((100% - 350px) / 2);
  width: min(520px, calc(100vw - 430px));
  min-height: 52px;
  padding: 0 8px;
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: 16px;
  color: var(--cream);
  background: rgba(5, 22, 20, 0.72);
  box-shadow: 0 12px 34px rgba(0, 0, 0, 0.25);
  transform: translateX(-50%);
  backdrop-filter: blur(16px);
}

.board-toolbar > button {
  color: rgba(255, 255, 255, 0.74);
}

.board-toolbar > button:hover:not(:disabled) {
  background: rgba(255, 255, 255, 0.08);
}

.board-toolbar kbd {
  border-color: rgba(255, 255, 255, 0.12);
  color: rgba(255, 255, 255, 0.45);
  background: rgba(255, 255, 255, 0.06);
}

.live-timer span {
  color: rgba(255, 255, 255, 0.45);
}

.control-panel {
  position: fixed;
  z-index: 12;
  top: 90px;
  right: 22px;
  bottom: 20px;
  display: flex;
  width: 320px;
  max-height: calc(100svh - 110px);
  overflow: auto;
  overscroll-behavior: contain;
  scrollbar-width: thin;
}

.control-panel .panel-section {
  position: relative;
  flex: 0 0 auto;
  border-color: rgba(79, 60, 30, 0.2);
  border-radius: 5px 12px 8px 6px;
  background: rgba(255, 249, 224, 0.94);
  box-shadow:
    0 8px 24px rgba(0, 0, 0, 0.2),
    inset 0 0 28px rgba(135, 105, 52, 0.05);
}

.control-panel .panel-section:first-child::before {
  position: absolute;
  top: -8px;
  left: 50%;
  width: 68px;
  height: 18px;
  content: "";
  background: rgba(226, 207, 149, 0.7);
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.08);
  transform: translateX(-50%) rotate(-2deg);
}

.success-layer {
  position: fixed;
}

.failure-layer {
  position: fixed;
}

.is-hidden {
  display: none !important;
}

@media (max-width: 900px) {
  .topbar {
    min-height: 64px;
    padding-inline: 16px;
  }

  .board-heading {
    top: 72px;
    left: 16px;
  }

  .board-heading h1 {
    font-size: 1.35rem;
  }

  .level-code {
    top: 76px;
    right: 16px;
  }

  .square-playfield {
    top: 43%;
    left: 50%;
    width: min(90vw, calc(100svh - 245px));
  }

  .game-stage::before {
    inset: 3px;
    border-width: 6px;
  }

  .chalk-caption {
    top: 76px;
    left: 50%;
  }

  .doodle-math {
    top: 29%;
    left: 4%;
  }

  .doodle-abc,
  .doodle-wave {
    display: none;
  }

  .doodle-star {
    bottom: 29%;
    left: 3%;
    opacity: 0.55;
  }

  .chalk-tray {
    right: 9%;
  }

  .board-toolbar {
    bottom: 148px;
    left: 50%;
    width: calc(100% - 24px);
  }

  .status-toast {
    bottom: 207px;
  }

  .control-panel {
    inset: auto 12px 10px;
    display: grid;
    width: auto;
    max-height: none;
    grid-template-columns: minmax(0, 1fr) 190px;
    gap: 8px;
    overflow: visible;
  }

  .control-panel .difficulty-section {
    grid-column: 1;
    padding: 10px;
  }

  .difficulty-section .section-title,
  .control-panel .round-stats-section,
  .control-panel .how-to,
  .control-panel .local-note {
    display: none;
  }

  .difficulty-grid {
    height: 100%;
  }

  .difficulty-grid button {
    min-height: 54px;
  }

  .control-panel .primary-actions {
    grid-column: 2;
    justify-content: center;
    padding: 8px;
  }

  .new-game-button {
    min-height: 50px;
  }
}

@media (max-width: 560px) {
  .brand > span:last-child {
    display: block;
  }

  .brand small,
  .level-code {
    display: none;
  }

  .streak-pill {
    padding-inline: 9px;
  }

  .quiet-button {
    width: 40px;
    padding: 0;
    font-size: 0;
  }

  .quiet-button span {
    font-size: 1rem;
  }

  .quiet-button .sound-label {
    display: none;
  }

  .board-heading {
    top: 67px;
  }

  .board-heading h1 {
    font-size: 1.2rem;
  }

  .square-playfield {
    top: 42%;
    width: min(94vw, calc(100svh - 235px));
  }

  .board-toolbar {
    bottom: 135px;
  }

  .status-toast {
    bottom: 191px;
  }

  .control-panel {
    grid-template-columns: minmax(0, 1fr) 150px;
  }

  .difficulty-grid {
    gap: 4px;
  }

  .difficulty-grid button {
    min-height: 48px;
  }

  .new-game-button {
    gap: 7px;
    padding-inline: 9px;
  }

  .new-game-button small,
  .new-game-button > span:last-child,
  .primary-actions .hint-button kbd {
    display: none;
  }

  .primary-actions .hint-button {
    min-height: 38px;
  }
}

/* Final readability pass for the full-screen classroom board. */
body {
  font-size: 18px;
}

.board-heading h1 {
  font-size: clamp(1.55rem, 2.8vw, 2.65rem);
}

.status-toast {
  min-height: 46px;
  padding: 10px 18px;
  font-size: 0.95rem;
}

.panel-section {
  padding: 22px;
}

.section-title h2 {
  font-size: 1.2rem;
}

.difficulty-grid button {
  min-height: 70px;
}

.difficulty-grid b {
  font-size: 0.95rem;
}

.difficulty-grid small {
  font-size: 0.72rem;
}

.round-stats small {
  font-size: 0.7rem;
}

.new-game-button b {
  font-size: 1rem;
}

.new-game-button small {
  font-size: 0.75rem;
}

.hint-button {
  min-height: 52px;
  font-size: 0.9rem;
}

.how-to li {
  font-size: 0.84rem;
}

.local-note {
  font-size: 0.74rem;
}

@media (max-width: 620px) {
  .qr-button span:last-child {
    display: none;
  }

  .difficulty-grid button {
    min-height: 56px;
  }
}

/* Make the two always-available movement controls unmistakable on touch screens. */
.board-toolbar > button {
  min-height: 60px;
  min-width: 128px;
  padding: 4px 13px;
  border: 2px solid rgba(16, 39, 36, 0.14);
  border-radius: 17px;
  background: rgba(255, 254, 250, 0.9);
  box-shadow: 0 8px 18px rgba(38, 52, 48, 0.1);
  font-size: 0.92rem;
  font-weight: 900;
}

.board-toolbar > button:hover:not(:disabled) {
  background: #fffef9;
  box-shadow: 0 10px 22px rgba(38, 52, 48, 0.16);
  transform: translateY(-2px);
}

.board-toolbar .action-icon {
  display: grid;
  width: 42px;
  height: 42px;
  flex: 0 0 42px;
  place-items: center;
  border: 2px solid currentColor;
  border-radius: 50%;
  font-size: 1.9rem;
  font-weight: 1000;
  line-height: 1;
}

.board-toolbar .action-icon-undo {
  color: #176c60;
  background: #d6f6ec;
}

.board-toolbar .action-icon-reset {
  color: #8a4c10;
  background: #ffedb5;
}

.board-toolbar .action-label {
  white-space: nowrap;
}

#reset-button {
  color: #6f3f12;
  border-color: rgba(190, 131, 19, 0.34);
  background: #fff9e6;
}

#undo-button:disabled {
  filter: grayscale(0.2);
}

@media (max-width: 620px) {
  .board-toolbar > button {
    min-width: 112px;
    min-height: 58px;
    padding-inline: 8px;
    gap: 6px;
    font-size: 0.82rem;
  }

  .board-toolbar .action-icon {
    width: 38px;
    height: 38px;
    flex-basis: 38px;
    font-size: 1.7rem;
  }
}

/* Tablet readability layout: bigger touch targets and a calmer control strip. */
@media (min-width: 621px) and (max-width: 1024px) {
  body {
    font-size: 20px;
  }

  .topbar {
    min-height: 88px;
    padding-inline: 28px;
  }

  .brand {
    gap: 15px;
  }

  .brand-mark {
    width: 46px;
    height: 46px;
    border-radius: 14px;
  }

  .brand strong {
    font-size: 1.42rem;
  }

  .brand small {
    font-size: 0.78rem;
  }

  .top-actions {
    gap: 12px;
  }

  .streak-pill,
  .quiet-button {
    min-height: 54px;
    padding-inline: 17px;
    border-width: 2px;
    font-size: 1rem;
  }

  .board-heading {
    top: 106px;
    left: 28px;
  }

  .board-heading h1 {
    font-size: clamp(1.9rem, 3.2vw, 2.45rem);
  }

  .level-code {
    top: 108px;
    right: 28px;
    padding: 10px 13px;
    font-size: 0.82rem;
  }

  .square-playfield {
    top: 42%;
    left: 50%;
    width: min(72vw, calc(100svh - 330px));
  }

  .node-dot {
    width: 64px;
    height: 64px;
  }

  .node-dot > span {
    width: 29px;
    height: 29px;
    border-width: 4px;
  }

  .node-dot:hover > span,
  .node-dot:focus-visible > span {
    width: 35px;
    height: 35px;
  }

  .node-dot.is-current > span {
    width: 38px;
    height: 38px;
  }

  .node-dot em {
    top: 53px;
    padding: 6px 10px;
    font-size: 0.78rem;
  }

  .status-toast {
    bottom: 286px;
    min-height: 54px;
    padding: 12px 20px;
    font-size: 1.08rem;
    font-weight: 800;
  }

  .board-toolbar {
    bottom: 214px;
    width: min(650px, calc(100% - 56px));
    min-height: 76px;
    padding: 8px 16px;
    border-radius: 20px;
  }

  .board-toolbar > button {
    min-width: 148px;
    min-height: 64px;
    padding-inline: 13px;
    font-size: 1rem;
  }

  .board-toolbar .action-icon {
    width: 48px;
    height: 48px;
    flex-basis: 48px;
    font-size: 2.05rem;
  }

  .live-timer b {
    font-size: 1.05rem;
  }

  .control-panel {
    inset: auto 20px 18px;
    display: grid;
    width: auto;
    max-height: none;
    grid-template-columns: minmax(0, 1fr) minmax(260px, 300px);
    gap: 14px;
    overflow: visible;
  }

  .control-panel .difficulty-section {
    grid-column: 1;
    padding: 16px 18px;
  }

  .difficulty-section .section-title {
    display: flex;
    margin-bottom: 10px;
  }

  .difficulty-section .section-title h2 {
    font-size: 1.35rem;
  }

  .difficulty-grid {
    height: auto;
    gap: 8px;
  }

  .difficulty-grid button {
    min-height: 78px;
    padding: 7px 4px;
    border-width: 2px;
    border-radius: 14px;
  }

  .difficulty-grid b {
    font-size: 1.08rem;
  }

  .difficulty-grid small {
    font-size: 0.78rem;
  }

  .control-panel .primary-actions {
    grid-column: 2;
    gap: 10px;
    padding: 14px;
  }

  .new-game-button {
    min-height: 76px;
    gap: 13px;
    padding: 10px 15px;
  }

  .new-game-button b {
    font-size: 1.12rem;
  }

  .new-game-button small {
    font-size: 0.8rem;
  }

  .dice,
  .hint-button > span:first-child {
    width: 38px;
    height: 38px;
    flex-basis: 38px;
    font-size: 1.2rem;
  }

  .hint-button {
    min-height: 60px;
    gap: 11px;
    padding-inline: 13px;
    font-size: 1rem;
  }

  .board-toolbar kbd,
  .hint-button kbd {
    display: none;
  }
}

/* Landscape tablets have room for a readable side panel instead of a tiny bottom strip. */
@media (min-width: 900px) and (max-width: 1100px) and (orientation: landscape) {
  .topbar {
    padding-inline: 30px;
  }

  .board-heading {
    top: 106px;
    left: 30px;
  }

  .level-code {
    right: 370px;
  }

  .square-playfield {
    top: 52%;
    left: calc((100% - 350px) / 2);
    width: min(72svh, calc(100vw - 420px));
  }

  .status-toast {
    bottom: 96px;
    left: calc((100% - 350px) / 2);
  }

  .board-toolbar {
    bottom: 20px;
    left: calc((100% - 350px) / 2);
    width: min(650px, calc(100vw - 420px));
  }

  .control-panel {
    inset: 98px 20px 18px auto;
    display: flex;
    width: 320px;
    max-height: calc(100svh - 116px);
    overflow-y: auto;
  }

  .control-panel .difficulty-section,
  .control-panel .primary-actions,
  .control-panel .round-stats-section,
  .control-panel .how-to,
  .control-panel .local-note {
    display: block;
    flex: 0 0 auto;
  }

  .control-panel .panel-section {
    padding: 18px;
  }

  .difficulty-section .section-title {
    display: flex;
  }

  .difficulty-grid {
    grid-template-columns: repeat(2, 1fr);
  }

  .difficulty-grid button {
    min-height: 72px;
  }

  .control-panel .primary-actions {
    display: flex;
    gap: 10px;
  }

  .new-game-button {
    min-height: 70px;
  }
}

/* Focus the right panel on one simple choice: difficulty. */
.topbar .new-game-quick-button {
  display: inline-flex;
  min-height: 54px;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 0 16px;
  border: 2px solid rgba(255, 216, 77, 0.4);
  border-radius: 999px;
  color: #fff8d7;
  background: rgba(116, 75, 12, 0.78);
  box-shadow: 0 7px 18px rgba(0, 0, 0, 0.2);
  font-size: 0.92rem;
  font-weight: 900;
  cursor: pointer;
  transition: 160ms ease;
}

.topbar .new-game-quick-button:hover {
  border-color: var(--yellow);
  background: rgba(146, 92, 11, 0.92);
  transform: translateY(-2px);
}

.new-game-quick-button > span:first-child {
  color: var(--yellow);
  font-size: 1.35rem;
  line-height: 1;
}

.control-panel {
  position: fixed;
  z-index: 12;
  top: 90px;
  right: 22px;
  bottom: auto;
  left: auto;
  display: flex;
  width: 320px;
  max-height: calc(100svh - 110px);
  flex-direction: column;
  gap: 10px;
  overflow: visible;
}

.control-panel > .round-stats-section,
.control-panel > .primary-actions,
.control-panel > .how-to,
.control-panel > .local-note {
  display: none !important;
}

.panel-toggle {
  display: grid;
  min-height: 72px;
  grid-template-columns: 44px minmax(0, 1fr) 28px;
  align-items: center;
  gap: 11px;
  padding: 10px 13px;
  border: 2px solid rgba(79, 60, 30, 0.22);
  border-radius: 14px 20px 14px 8px;
  color: var(--ink);
  background: rgba(255, 249, 224, 0.97);
  box-shadow:
    0 10px 26px rgba(0, 0, 0, 0.22),
    inset 0 0 24px rgba(135, 105, 52, 0.06);
  text-align: left;
  cursor: pointer;
  transition: 160ms ease;
}

.panel-toggle:hover {
  border-color: rgba(16, 39, 36, 0.42);
  transform: translateY(-2px);
}

.panel-toggle-icon {
  display: grid;
  width: 44px;
  height: 44px;
  place-items: center;
  border: 2px solid #9f7920;
  border-radius: 12px;
  color: #62460c;
  background: #ffe9a0;
  font-size: 1.45rem;
  line-height: 1;
}

.panel-toggle-copy {
  display: flex;
  min-width: 0;
  flex-direction: column;
  gap: 2px;
}

.panel-toggle-copy small {
  color: #71817e;
  font-size: 0.64rem;
  font-weight: 900;
  letter-spacing: 0.16em;
}

.panel-toggle-copy b {
  overflow: hidden;
  font-size: 1.2rem;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.panel-toggle-arrow {
  color: #8a671b;
  font-size: 1.55rem;
  font-weight: 900;
  text-align: center;
}

.control-panel .difficulty-section {
  display: block;
  padding: 18px;
}

.control-panel.is-collapsed .difficulty-section {
  display: none;
}

.control-panel.is-expanded .difficulty-section {
  display: block;
}

.difficulty-grid {
  height: auto !important;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
}

.difficulty-grid button {
  min-height: 126px;
  gap: 5px;
  padding: 9px 5px;
  border-width: 2px;
  border-radius: 15px;
}

.difficulty-art {
  display: block;
  width: 48px;
  height: 48px;
  border-radius: 8px;
  color: #50736b;
  background-image: radial-gradient(circle, currentColor 0 3px, transparent 3.5px);
  background-position: center;
  background-repeat: repeat;
}

.difficulty-art-easy {
  width: 48px;
  height: 48px;
  background-size: 12px 12px;
}

.difficulty-art-normal {
  width: 50px;
  height: 50px;
  background-size: 10px 10px;
}

.difficulty-art-hard {
  width: 54px;
  height: 54px;
  background-size: 9px 9px;
}

.difficulty-art-expert {
  width: 56px;
  height: 56px;
  background-size: 8px 8px;
}

.difficulty-grid button.active .difficulty-art {
  color: var(--yellow);
}

.difficulty-copy {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
}

.difficulty-copy b {
  font-size: 1rem;
}

.difficulty-copy small {
  font-size: 0.72rem;
}

/* The hint stays reachable without bringing back the crowded side panel. */
.board-toolbar {
  grid-template-columns: auto auto minmax(0, 1fr) auto;
}

.board-toolbar .toolbar-hint {
  display: inline-flex;
  min-width: 76px;
  min-height: 54px;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 4px 9px;
  border: 2px solid rgba(119, 229, 205, 0.34);
  border-radius: 15px;
  color: #d8fff3;
  background: rgba(24, 91, 79, 0.78);
  font-size: 0.86rem;
}

.toolbar-hint > span:first-child {
  display: grid;
  width: 31px;
  height: 31px;
  place-items: center;
  border: 2px solid currentColor;
  border-radius: 50%;
  font-size: 1.1rem;
  font-weight: 1000;
}

.toolbar-hint:hover:not(:disabled) {
  background: rgba(34, 122, 105, 0.92) !important;
}

.status-toast {
  top: 88px;
  bottom: auto;
}

@media (max-width: 900px) {
  .control-panel {
    top: auto;
    right: 18px;
    bottom: 18px;
    width: min(320px, calc(100% - 36px));
    max-height: calc(100svh - 110px);
  }

  .control-panel.is-expanded {
    max-height: min(470px, calc(100svh - 110px));
    overflow-y: auto;
  }

  .control-panel .difficulty-section {
    padding: 16px;
  }

  .difficulty-section .section-title {
    display: flex;
  }

  .status-toast {
    top: 78px;
  }
}

@media (max-width: 620px) {
  .topbar .new-game-quick-button {
    width: 44px;
    min-height: 44px;
    padding: 0;
    font-size: 0;
  }

  .topbar .new-game-quick-button > span:first-child {
    font-size: 1.25rem;
  }

  .control-panel {
    right: 12px;
    bottom: 12px;
    width: min(286px, calc(100% - 24px));
  }

  .panel-toggle {
    min-height: 64px;
  }

  .difficulty-grid button {
    min-height: 116px;
  }

  .board-toolbar > button {
    min-width: 88px;
  }

  .board-toolbar .toolbar-hint {
    min-width: 46px;
    width: 46px;
    padding: 3px;
  }

  .toolbar-hint-label {
    display: none;
  }
}

@media (min-width: 621px) and (max-width: 900px) {
  .topbar {
    gap: 10px;
    padding-inline: 18px;
  }

  .brand {
    min-width: 0;
    gap: 10px;
  }

  .brand > span:last-child {
    display: block;
    min-width: 0;
  }

  .brand strong {
    display: block;
    overflow: hidden;
    font-size: 1.2rem;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  .brand small {
    display: none;
  }

  .top-actions {
    flex-shrink: 0;
    gap: 8px;
  }

  .streak-pill {
    width: 56px;
    min-height: 52px;
    padding: 0;
    font-size: 0;
  }

  .streak-pill span,
  .streak-pill b {
    font-size: 1rem;
  }

  .quiet-button,
  .topbar .new-game-quick-button {
    width: 52px;
    min-height: 52px;
    padding: 0;
    font-size: 0;
  }

  .quiet-button > span:first-child,
  .topbar .new-game-quick-button > span:first-child {
    font-size: 1.35rem;
  }

  .sound-label,
  .qr-button span:last-child,
  .new-game-quick-button span:last-child {
    display: none;
  }
}

/* Random classroom notes and a wider, real-board chalk ledge. */
.chalk-doodle {
  transform: rotate(var(--sketch-tilt, 0deg));
}

.chalk-piece {
  transform: rotate(var(--chalk-tilt, -2deg));
}

.board-eraser {
  transform: rotate(var(--eraser-tilt, 2deg));
}

.chalk-tray {
  right: 3%;
  bottom: 5px;
  left: 3%;
  z-index: 4;
  height: 30px;
  border-width: 2px;
  border-radius: 4px 4px 10px 10px;
  box-shadow:
    inset 0 4px rgba(255, 224, 174, 0.2),
    inset 0 -6px rgba(38, 17, 7, 0.25),
    0 -5px 12px rgba(0, 0, 0, 0.32),
    0 4px 0 #3f2412;
}

.chalk-piece {
  bottom: 14px;
}

.chalk-piece-blue {
  background: #8fd3d6;
}

.board-eraser {
  bottom: 11px;
}

.tray-note {
  position: absolute;
  right: 20%;
  bottom: 6px;
  padding: 2px 9px;
  border: 1px dashed rgba(247, 242, 216, 0.4);
  border-radius: 3px;
  color: rgba(247, 242, 216, 0.72);
  font-size: 0.64rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  transform: rotate(-2deg);
}

.board-side-notes {
  position: absolute;
  top: 22%;
  bottom: 18%;
  z-index: 2;
  display: flex;
  width: 62px;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 11px 5px;
  border: 1px dashed rgba(247, 242, 216, 0.24);
  color: rgba(247, 242, 216, 0.54);
  font-family: "Comic Sans MS", "Bradley Hand", "DFKai-SB", cursive;
  text-align: center;
  transform: rotate(-1deg);
}

.board-side-notes-left {
  left: 16px;
  border-right-width: 3px;
  border-left: 0;
}

.board-side-notes-right {
  right: 16px;
  border-right: 0;
  border-left-width: 3px;
  transform: rotate(1deg);
}

.board-side-notes span {
  display: block;
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.side-note-label {
  color: rgba(255, 216, 77, 0.72);
  font-family: ui-monospace, monospace;
  font-size: 0.52rem;
  letter-spacing: 0.08em;
}

.side-note-main {
  color: rgba(247, 242, 216, 0.82);
  font-size: 0.88rem;
  font-weight: 900;
}

.side-note-sub {
  font-size: 0.62rem;
}

/* iPhone 12 Pro landscape: keep the puzzle large and move controls into a
   compact right-hand rail so the short viewport never gets crowded. */
@media (max-width: 900px) and (orientation: landscape) and (max-height: 500px) {
  .topbar {
    min-height: 56px;
    padding: 0 14px;
  }

  .brand {
    gap: 8px;
  }

  .brand-mark {
    width: 34px;
    height: 34px;
    border-radius: 10px;
  }

  .brand strong {
    font-size: 1rem;
  }

  .brand small,
  .topbar .streak-pill,
  .quiet-button span:last-child,
  .new-game-quick-button span:last-child {
    display: none;
  }

  .top-actions {
    gap: 6px;
  }

  .quiet-button,
  .topbar .new-game-quick-button {
    width: 42px;
    min-height: 42px;
    padding: 0;
    font-size: 0;
  }

  .quiet-button > span:first-child,
  .topbar .new-game-quick-button > span:first-child {
    font-size: 1.12rem;
  }

  .board-heading {
    top: 62px;
    left: 14px;
  }

  .board-heading h1 {
    max-width: 270px;
    font-size: 1.22rem;
  }

  .level-code {
    top: 62px;
    right: 250px;
    padding: 5px 8px;
    font-size: 0.58rem;
  }

  .square-playfield {
    top: 53%;
    left: 34%;
    width: min(64svh, calc(100vw - 300px));
  }

  .node-dot {
    width: 46px;
    height: 46px;
  }

  .node-dot > span {
    width: 22px;
    height: 22px;
    border-width: 3px;
  }

  .node-dot.is-current > span {
    width: 30px;
    height: 30px;
  }

  .doodle-abc,
  .doodle-wave {
    display: block;
  }

  .doodle-math {
    top: 26%;
    left: 8%;
    font-size: 0.72rem;
  }

  .doodle-star {
    bottom: 23%;
    left: 8%;
    font-size: 2.2rem;
  }

  .doodle-abc {
    top: 33%;
    right: 246px;
    font-size: 0.68rem;
  }

  .doodle-wave {
    right: 242px;
    bottom: 20%;
    font-size: 0.9rem;
  }

  .board-side-notes {
    top: 25%;
    bottom: 20%;
    width: 42px;
    gap: 5px;
    padding: 7px 3px;
  }

  .board-side-notes-left {
    left: 7px;
  }

  .board-side-notes-right {
    right: 7px;
  }

  .side-note-label {
    font-size: 0.42rem;
  }

  .side-note-main {
    font-size: 0.66rem;
  }

  .side-note-sub {
    font-size: 0.48rem;
  }

  .chalk-tray {
    right: 2%;
    bottom: 4px;
    left: 2%;
    height: 25px;
  }

  .chalk-piece {
    bottom: 11px;
    height: 6px;
  }

  .board-eraser {
    bottom: 8px;
    width: 54px;
    height: 19px;
  }

  .tray-note {
    right: 18%;
    bottom: 4px;
    font-size: 0.48rem;
  }

  .board-toolbar {
    bottom: 8px;
    left: 34%;
    width: min(390px, calc(100vw - 300px));
    min-height: 48px;
    gap: 5px;
    padding: 3px 5px;
    border-radius: 13px;
  }

  .board-toolbar > button {
    min-width: 58px;
    min-height: 43px;
    padding: 2px 5px;
    gap: 3px;
    font-size: 0.66rem;
  }

  .board-toolbar .action-icon {
    width: 31px;
    height: 31px;
    flex-basis: 31px;
    border-width: 1px;
    font-size: 1.25rem;
  }

  .board-toolbar .action-label,
  .toolbar-hint-label,
  .board-toolbar kbd {
    display: none;
  }

  .board-toolbar .toolbar-hint {
    min-width: 40px;
    width: 40px;
    min-height: 40px;
    padding: 2px;
  }

  .toolbar-hint > span:first-child {
    width: 27px;
    height: 27px;
    border-width: 1px;
    font-size: 0.9rem;
  }

  .live-timer {
    min-width: 52px;
    gap: 1px;
  }

  .live-timer span {
    font-size: 0.48rem;
  }

  .live-timer b {
    font-size: 0.65rem;
  }

  .status-toast {
    top: 61px;
    bottom: auto;
    left: 34%;
    width: auto;
    min-height: 34px;
    padding: 5px 10px;
    font-size: 0.64rem;
  }

  .control-panel {
    top: 62px;
    right: 10px;
    bottom: auto;
    width: 208px;
    max-height: calc(100svh - 72px);
  }

  .control-panel.is-expanded {
    width: 248px;
    max-height: calc(100svh - 72px);
  }

  .panel-toggle {
    min-height: 50px;
    grid-template-columns: 31px minmax(0, 1fr) 20px;
    gap: 7px;
    padding: 6px 8px;
    border-radius: 10px 14px 10px 6px;
  }

  .panel-toggle-icon {
    width: 31px;
    height: 31px;
    border-width: 1px;
    border-radius: 8px;
    font-size: 1rem;
  }

  .panel-toggle-copy small {
    font-size: 0.46rem;
  }

  .panel-toggle-copy b {
    font-size: 0.9rem;
  }

  .panel-toggle-arrow {
    font-size: 1.1rem;
  }

  .control-panel .difficulty-section {
    padding: 8px;
  }

  .difficulty-section .section-title {
    display: none;
  }

  .difficulty-grid {
    gap: 6px;
  }

  .difficulty-grid button {
    min-height: 78px;
    border-radius: 10px;
  }

  .difficulty-art {
    width: 31px;
    height: 31px;
    background-size: 8px 8px;
  }

  .difficulty-copy b {
    font-size: 0.72rem;
  }

  .difficulty-copy small {
    font-size: 0.54rem;
  }
}

/* Final classroom polish: childlike doodles, clear controls, and a hero win time. */
.classroom-decor .random-doodle {
  position: absolute;
  z-index: 1;
  display: inline-block;
  min-width: 0.7em;
  color: rgba(247, 242, 216, 0.55);
  font-weight: 800;
  line-height: 1;
  text-shadow: 1px 1px rgba(255, 255, 255, 0.08), 0 0 10px currentColor;
  transform: rotate(var(--sketch-tilt, 0deg)) scale(var(--doodle-scale, 1));
  animation: doodle-float 4.8s ease-in-out var(--doodle-delay, 0s) infinite alternate;
}

@keyframes doodle-float {
  from {
    margin-top: -2px;
  }
  to {
    margin-top: 3px;
  }
}

.board-toolbar {
  bottom: 46px;
}

.success-layer {
  z-index: 60;
}

.failure-layer {
  z-index: 61;
}

.result-facts {
  display: grid;
  grid-template-columns: 1fr;
  margin: 16px auto 22px;
  overflow: visible;
  border: 0;
  background: transparent;
}

.result-facts span:first-child {
  align-items: center;
  gap: 5px;
  padding: 14px 26px 18px;
  border: 2px solid rgba(47, 183, 152, 0.3);
  border-radius: 20px;
  background:
    radial-gradient(circle at 50% 0%, rgba(255, 216, 77, 0.28), transparent 65%),
    rgba(232, 255, 247, 0.82);
  box-shadow:
    0 0 0 5px rgba(119, 229, 205, 0.1),
    0 12px 26px rgba(47, 183, 152, 0.16),
    inset 0 0 22px rgba(255, 255, 255, 0.76);
  animation: success-time-pulse 1.8s ease-in-out infinite alternate;
}

.result-facts span:nth-child(n + 2) {
  display: none;
}

.result-facts span:first-child small {
  color: var(--mint-deep);
  font-size: 0.72rem;
  font-weight: 900;
  letter-spacing: 0.2em;
}

.result-facts span:first-child b {
  color: var(--ink);
  font-size: clamp(2.8rem, 8vw, 4.8rem);
  line-height: 0.96;
  letter-spacing: -0.08em;
  text-shadow: 0 4px 0 rgba(47, 183, 152, 0.12), 0 0 24px rgba(47, 183, 152, 0.24);
}

@keyframes success-time-pulse {
  from {
    transform: scale(0.98) rotate(-1deg);
  }
  to {
    transform: scale(1.02) rotate(1deg);
  }
}

@media (max-width: 900px) and (orientation: landscape) and (max-height: 500px) {
  .board-toolbar {
    bottom: 34px;
  }

  .classroom-decor .random-doodle {
    text-shadow: 1px 1px rgba(255, 255, 255, 0.08), 0 0 7px currentColor;
  }

  .result-facts span:first-child {
    padding: 10px 20px 13px;
  }

  .result-facts span:first-child b {
    font-size: clamp(2.35rem, 10vw, 3.7rem);
  }

  /* Keep the celebration card fully reachable in short landscape screens. */
  .success-layer,
  .failure-layer {
    align-items: center;
    overflow: hidden;
    padding: 10px;
  }

  .success-card,
  .failure-card {
    max-height: calc(100svh - 20px);
    overflow-y: auto;
    padding: 18px 20px 14px;
  }

  .success-check {
    width: 48px;
    height: 48px;
    margin: -43px auto 10px;
    border-width: 5px;
    font-size: 1.35rem;
  }

  .success-card > p {
    margin-bottom: 2px;
    font-size: 0.55rem;
  }

  .success-card h2 {
    font-size: 1.3rem;
  }

  .result-stars {
    gap: 2px;
    margin: 5px 0 8px;
  }

  .result-stars span {
    font-size: 1.05rem;
  }

  .result-facts {
    margin: 8px auto 12px;
  }

  .result-facts span:first-child {
    padding: 8px 16px 10px;
  }

  .result-facts span:first-child b {
    font-size: clamp(2.15rem, 9vw, 3rem);
  }

  .success-retry-button,
  .next-button {
    min-height: 40px;
  }
}

/* Fixed chalk borders: keep every doodle in the outer gutters, away from the dots. */
.classroom-decor .random-doodle {
  z-index: 1;
  color: rgba(247, 242, 216, 0.46);
  filter: blur(0.15px);
  text-shadow:
    1px 1px rgba(255, 255, 255, 0.12),
    -1px 0 rgba(247, 242, 216, 0.08);
  transform: rotate(var(--fixed-tilt, 0deg));
  animation: none !important;
}

.classroom-decor .random-doodle:nth-of-type(1) {
  top: 7%;
  left: 7%;
  font-size: 1.25rem;
  --fixed-tilt: -12deg;
}

.classroom-decor .random-doodle:nth-of-type(2) {
  top: 7%;
  left: 17%;
  font-size: 1.05rem;
  --fixed-tilt: 8deg;
}

.classroom-decor .random-doodle:nth-of-type(3) {
  top: 6%;
  left: 25%;
  color: rgba(233, 204, 98, 0.54);
  font-size: 1.35rem;
  --fixed-tilt: -5deg;
}

.classroom-decor .random-doodle:nth-of-type(4) {
  top: 8%;
  right: 25%;
  color: rgba(220, 141, 136, 0.52);
  font-size: 1.15rem;
  --fixed-tilt: 11deg;
}

.classroom-decor .random-doodle:nth-of-type(5) {
  top: 5%;
  right: 17%;
  font-size: 1.35rem;
  --fixed-tilt: -8deg;
}

.classroom-decor .random-doodle:nth-of-type(6) {
  top: 10%;
  right: 7%;
  color: rgba(143, 211, 214, 0.56);
  font-size: 1.05rem;
  --fixed-tilt: 5deg;
}

.classroom-decor .random-doodle:nth-of-type(7) {
  top: 23%;
  left: 5%;
  font-size: 1.15rem;
  --fixed-tilt: -18deg;
}

.classroom-decor .random-doodle:nth-of-type(8) {
  top: 37%;
  left: 12%;
  color: rgba(220, 141, 136, 0.5);
  font-size: 1.05rem;
  --fixed-tilt: 12deg;
}

.classroom-decor .random-doodle:nth-of-type(9) {
  top: 51%;
  left: 5%;
  color: rgba(233, 204, 98, 0.5);
  font-size: 1.35rem;
  --fixed-tilt: -7deg;
}

.classroom-decor .random-doodle:nth-of-type(10) {
  top: 65%;
  left: 13%;
  font-size: 0.95rem;
  --fixed-tilt: 17deg;
}

.classroom-decor .random-doodle:nth-of-type(11) {
  top: 78%;
  left: 5%;
  color: rgba(143, 211, 214, 0.5);
  font-size: 1.1rem;
  --fixed-tilt: -10deg;
}

.classroom-decor .random-doodle:nth-of-type(12) {
  top: 87%;
  left: 13%;
  font-size: 0.9rem;
  --fixed-tilt: 8deg;
}

.classroom-decor .random-doodle:nth-of-type(13) {
  top: 22%;
  right: 5%;
  color: rgba(143, 211, 214, 0.52);
  font-size: 1.2rem;
  --fixed-tilt: 13deg;
}

.classroom-decor .random-doodle:nth-of-type(14) {
  top: 36%;
  right: 12%;
  font-size: 1rem;
  --fixed-tilt: -9deg;
}

.classroom-decor .random-doodle:nth-of-type(15) {
  top: 50%;
  right: 5%;
  color: rgba(233, 204, 98, 0.52);
  font-size: 1.35rem;
  --fixed-tilt: 6deg;
}

.classroom-decor .random-doodle:nth-of-type(16) {
  top: 64%;
  right: 13%;
  font-size: 0.95rem;
  --fixed-tilt: -15deg;
}

.classroom-decor .random-doodle:nth-of-type(17) {
  top: 77%;
  right: 5%;
  color: rgba(220, 141, 136, 0.52);
  font-size: 1.1rem;
  --fixed-tilt: 10deg;
}

.classroom-decor .random-doodle:nth-of-type(18) {
  top: 87%;
  right: 13%;
  font-size: 0.9rem;
  --fixed-tilt: -6deg;
}

.classroom-decor .chalk-caption {
  z-index: 2;
  color: rgba(247, 242, 216, 0.72);
  text-shadow: 1px 1px rgba(255, 255, 255, 0.1), 0 0 1px currentColor;
  animation: none;
}

/* Show the player's completed route beside the score card. */
.success-dialog {
  position: relative;
  z-index: 2;
  display: grid;
  width: min(790px, 100%);
  grid-template-columns: minmax(300px, 390px) minmax(270px, 340px);
  align-items: center;
  justify-content: center;
  gap: 18px;
}

.success-dialog .success-card {
  width: 100%;
}

.success-replay {
  width: 100%;
  padding: 18px;
  overflow: hidden;
  border: 1px solid rgba(247, 242, 216, 0.3);
  border-radius: 26px;
  color: var(--cream);
  background:
    radial-gradient(circle at 82% 5%, rgba(255, 216, 77, 0.14), transparent 34%),
    linear-gradient(145deg, rgba(25, 75, 67, 0.98), rgba(8, 42, 37, 0.99));
  box-shadow:
    0 28px 80px rgba(0, 0, 0, 0.38),
    inset 0 0 42px rgba(0, 0, 0, 0.2);
  animation: replay-card-enter 620ms 90ms cubic-bezier(0.16, 1.15, 0.4, 1) both;
}

.success-replay-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 14px;
}

.success-replay-heading > div > span {
  display: block;
  margin-bottom: 3px;
  color: var(--mint);
  font-size: 0.56rem;
  font-weight: 900;
  letter-spacing: 0.18em;
}

.success-replay-heading h3 {
  margin: 0;
  color: #fffdf1;
  font-size: clamp(1.05rem, 2vw, 1.28rem);
  letter-spacing: -0.035em;
}

.replay-loop-badge {
  display: inline-flex;
  flex: 0 0 auto;
  align-items: center;
  gap: 6px;
  padding: 6px 8px;
  border: 1px solid rgba(119, 229, 205, 0.28);
  border-radius: 999px;
  color: #d9fff5;
  background: rgba(119, 229, 205, 0.1);
  font-size: 0.6rem;
  font-weight: 850;
}

.replay-loop-badge i {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--yellow);
  box-shadow: 0 0 0 4px rgba(255, 216, 77, 0.12), 0 0 9px rgba(255, 216, 77, 0.7);
  animation: replay-live-pulse 1.1s ease-in-out infinite alternate;
}

.success-replay-board {
  position: relative;
  width: 100%;
  aspect-ratio: 1;
  overflow: hidden;
  border: 1px solid rgba(247, 242, 216, 0.2);
  border-radius: 20px;
  background:
    radial-gradient(circle at 28% 22%, rgba(119, 229, 205, 0.09), transparent 30%),
    radial-gradient(circle at 76% 76%, rgba(255, 216, 77, 0.08), transparent 31%),
    repeating-linear-gradient(2deg, rgba(255, 255, 255, 0.012) 0 1px, transparent 1px 5px),
    #0c3731;
  box-shadow:
    inset 0 0 30px rgba(0, 0, 0, 0.3),
    0 10px 25px rgba(0, 0, 0, 0.16);
}

#success-replay-canvas {
  position: absolute;
  inset: 0;
  display: block;
  width: 100%;
  height: 100%;
}

.success-replay-stamp {
  position: absolute;
  right: 10px;
  bottom: 8px;
  color: rgba(247, 242, 216, 0.22);
  font-size: 0.58rem;
  font-weight: 900;
  letter-spacing: 0.16em;
  pointer-events: none;
  transform: rotate(-4deg);
}

.success-replay-caption {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  margin: 11px 0 0;
  color: rgba(247, 242, 216, 0.7);
  font-size: 0.67rem;
  font-weight: 700;
}

.success-replay-caption span {
  color: var(--yellow);
  font-size: 0.9rem;
}

@keyframes replay-card-enter {
  from {
    opacity: 0;
    transform: translateX(18px) scale(0.94) rotate(1deg);
  }
  to {
    opacity: 1;
    transform: translateX(0) scale(1) rotate(0);
  }
}

@keyframes replay-live-pulse {
  from {
    opacity: 0.55;
    transform: scale(0.8);
  }
  to {
    opacity: 1;
    transform: scale(1.15);
  }
}

@media (max-width: 720px) {
  .success-layer {
    align-items: start;
    overflow-y: auto;
  }

  .success-dialog {
    width: min(420px, 100%);
    grid-template-columns: 1fr;
    margin: 42px auto 24px;
  }
}

@media (max-width: 900px) and (orientation: landscape) and (max-height: 500px) {
  .success-layer {
    overflow-y: auto;
    padding: 8px;
  }

  .success-dialog {
    width: min(760px, 100%);
    grid-template-columns: minmax(270px, 1.12fr) minmax(225px, 0.88fr);
    gap: 10px;
    margin: auto;
  }

  .success-replay {
    padding: 10px;
    border-radius: 19px;
  }

  .success-replay-heading {
    gap: 7px;
    margin-bottom: 7px;
  }

  .success-replay-heading > div > span {
    font-size: 0.46rem;
  }

  .success-replay-heading h3 {
    font-size: 0.92rem;
  }

  .replay-loop-badge {
    gap: 4px;
    padding: 4px 6px;
    font-size: 0.52rem;
  }

  .success-replay-board {
    width: min(100%, calc(100svh - 112px));
    margin-inline: auto;
    border-radius: 14px;
  }

  .success-replay-caption {
    margin-top: 5px;
    font-size: 0.57rem;
  }
}

@media (prefers-reduced-motion: reduce) {
  .success-replay,
  .replay-loop-badge i {
    animation: none;
  }
}

/* Keep the round seed hidden from the fullscreen header. */
.level-code {
  display: none !important;
}

/* A fixed-size chevron keeps the panel toggle from shifting when it opens. */
.panel-toggle-arrow {
  display: grid;
  width: 28px;
  height: 28px;
  flex: 0 0 28px;
  place-items: center;
  border: 1px solid rgba(138, 103, 27, 0.3);
  border-radius: 50%;
  color: #8a671b;
  background: rgba(255, 233, 160, 0.42);
  font-size: 0 !important;
  line-height: 0;
  transition: color 160ms ease, background 160ms ease;
}

.panel-toggle-arrow::before {
  width: 7px;
  height: 7px;
  content: "";
  border-right: 2px solid currentColor;
  border-bottom: 2px solid currentColor;
  transform: rotate(45deg) translate(-1px, -1px);
  transition: transform 180ms ease;
}

.panel-toggle-arrow.is-open {
  color: var(--mint-deep);
  background: rgba(119, 229, 205, 0.18);
}

.panel-toggle-arrow.is-open::before {
  transform: rotate(225deg) translate(-1px, -1px);
}

@media (max-width: 900px) and (orientation: landscape) and (max-height: 500px) {
  .panel-toggle-arrow {
    width: 22px;
    height: 22px;
    flex-basis: 22px;
  }

  .panel-toggle-arrow::before {
    width: 6px;
    height: 6px;
    border-width: 1.5px;
  }
}
