:root {
  color-scheme: light;
  font-family: ui-rounded, "Nunito", "Avenir Next", system-ui, sans-serif;
  background: #e8e3d7;
  color: #22241f;
  -webkit-tap-highlight-color: transparent;
}

/* A long press (hold for the preview) must not select text or open the iPhone callout. */
body { -webkit-user-select: none; user-select: none; -webkit-touch-callout: none; }
input, textarea, [contenteditable="true"], [data-selectable] { -webkit-user-select: text; user-select: text; -webkit-touch-callout: default; }

* { box-sizing: border-box; }

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

body {
  min-width: 320px;
  background:
    radial-gradient(circle at 18% 0%, #fffdf6 0 17%, transparent 42%),
    #e8e3d7;
}

button, a { font: inherit; }

button {
  min-height: 44px;
  border: 1px solid #c7c1b3;
  border-radius: 14px;
  padding: 9px 14px;
  color: inherit;
  background: #fffdf8;
  cursor: pointer;
  touch-action: manipulation;
}

button:focus-visible, a:focus-visible { outline: 3px solid #176e83; outline-offset: 3px; }
button:disabled { opacity: .42; cursor: not-allowed; }

.shell {
  width: min(100%, 430px);
  min-height: 100dvh;
  margin: 0 auto;
  padding: calc(68px + env(safe-area-inset-top)) 12px calc(22px + env(safe-area-inset-bottom));
}

.topbar, .top-actions, .level-row, .map-heading, .controls, .result-actions {
  display: flex;
  align-items: center;
}

.topbar { min-height: 44px; justify-content: space-between; gap: 8px; }
.top-actions { gap: 5px; }

.lab-link {
  display: inline-flex;
  align-items: center;
  min-height: 44px;
  color: #31574b;
  font-size: 14px;
  font-weight: 800;
  text-decoration: none;
}

.quiet-button, .icon-button {
  min-height: 44px;
  border-color: transparent;
  padding: 7px 9px;
  background: transparent;
  color: #4c5148;
  font-size: 13px;
  font-weight: 750;
}

.icon-button { width: 44px; padding: 0; font-size: 21px; }

.title-screen { padding: clamp(58px, 13vh, 118px) 14px 32px; text-align: center; }
.eyebrow { margin: 0 0 7px; color: #757a70; font-size: 12px; font-weight: 800; letter-spacing: .13em; text-transform: uppercase; }
h1 { margin: 0; font-size: clamp(32px, 10vw, 45px); line-height: 1.05; letter-spacing: -.045em; }
.subtitle { max-width: 32ch; margin: 17px auto 25px; color: #5c6159; font-size: 16px; line-height: 1.45; }
.instruction { min-height: 1.4em; margin: 11px 2px; color: #62685d; font-size: 14px; line-height: 1.4; }
.title-screen .subtitle, .title-screen .instruction { display: none; }

.primary-button {
  border-color: #24645f;
  color: #fffdf8;
  background: #24645f;
  box-shadow: 0 4px 0 #174942;
  font-weight: 850;
}
.primary-button:active { transform: translateY(2px); box-shadow: 0 2px 0 #174942; }

#play-screen { padding: 12px 0 0; }
.level-row { justify-content: space-between; gap: 12px; padding: 0 3px; }
.level-name { margin: 0; font-size: 18px; font-weight: 850; }
.move-count { margin: 0; color: #686d63; font-size: 13px; font-variant-numeric: tabular-nums; }

.board-shell {
  position: relative;
  width: 100%;
  overflow: hidden;
  border: 1px solid #cfc7b7;
  border-radius: 22px;
  background: #fffdf8;
  box-shadow: 0 6px 20px rgb(62 51 30 / .10);
}

#board { display: block; width: 100%; height: auto; touch-action: none; -webkit-user-select: none; user-select: none; -webkit-touch-callout: none; }
/* two lines reserved so the wrong-drawer line (P1CF06) does not shift the page mid-drag */
.message { min-height: 2.7em; margin: 11px 5px 6px; color: #51574e; font-size: 14px; line-height: 1.35; }
.message.refused { color: #9b3b31; }

.controls { justify-content: center; gap: 9px; padding: 8px 0 11px; }
.controls button { min-width: 92px; font-weight: 750; }

.result-card {
  margin: 4px 0 12px;
  padding: 20px 16px 16px;
  border: 1px solid #a7c7a6;
  border-radius: 20px;
  background: #f5fbef;
  text-align: center;
}
.result-title { margin: 0; color: #24594c; font-size: 24px; font-weight: 900; }
.result-marks { margin: 7px 0 5px; font-size: 16px; font-weight: 800; }
.share-line { min-height: 1.4em; margin: 0 auto 14px; color: #5a6758; font-size: 13px; line-height: 1.4; }
.result-actions { justify-content: center; flex-wrap: wrap; gap: 8px; }
.result-actions button { font-weight: 750; }

.map-heading { justify-content: space-between; gap: 15px; padding: 12px 4px 3px; }
.map-heading h1 { font-size: 32px; }
.level-map { display: grid; grid-template-columns: minmax(0, 1fr); gap: 9px; margin-top: 18px; }
.level-tile { min-height: 76px; padding: 10px 7px; text-align: left; }
.level-tile strong, .level-tile small { display: block; }
.level-tile strong { font-size: 17px; }
.level-tile small { margin-top: 4px; color: #687067; font-size: 11px; line-height: 1.25; }
.level-tile.complete { border-color: #79a982; background: #f4fbef; }
.level-tile.today-tile { grid-column: 1 / -1; min-height: 64px; }

.hand-demo {
  position: absolute;
  z-index: 2;
  display: none;
  width: 42px;
  height: 42px;
  margin: -21px 0 0 -21px;
  border-radius: 50%;
  background: rgb(255 255 255 / .86);
  box-shadow: 0 2px 9px rgb(0 0 0 / .16);
  color: #24594c;
  font-size: 25px;
  line-height: 42px;
  text-align: center;
  pointer-events: none;
}
.hand-demo.running { display: block; animation: hand-pulse 1.8s ease-in-out infinite; }
@keyframes hand-pulse { 0%, 100% { transform: scale(.78); opacity: .15; } 42%, 60% { transform: scale(1); opacity: 1; } }

.success-effect { position: absolute; inset: 0; z-index: 3; overflow: hidden; pointer-events: none; }
.success-effect i { position: absolute; top: 47%; left: 50%; width: 9px; height: 9px; border-radius: 2px; opacity: 0; background: #e5a52d; }
.success-effect.on i { animation: confetti .72s ease-out both; }
.success-effect i:nth-child(2) { background: #4d91ae; animation-delay: .05s; }
.success-effect i:nth-child(3) { background: #bb5f70; animation-delay: .1s; }
.success-effect i:nth-child(4) { background: #5d9663; animation-delay: .02s; }
.success-effect i:nth-child(5) { background: #9d71ad; animation-delay: .12s; }
@keyframes confetti { 0% { transform: translate(0, 0) rotate(0); opacity: 1; } 100% { transform: translate(var(--x, 0), var(--y, 0)) rotate(240deg); opacity: 0; } }
.success-effect i:nth-child(1) { --x: -112px; --y: -105px; }.success-effect i:nth-child(2) { --x: 106px; --y: -96px; }.success-effect i:nth-child(3) { --x: 130px; --y: 92px; }.success-effect i:nth-child(4) { --x: -126px; --y: 78px; }.success-effect i:nth-child(5) { --x: 8px; --y: -145px; }

.load-error { margin: 54px 8px; padding: 18px; border: 1px solid #c4695e; border-radius: 14px; background: #fff5f2; color: #742f27; line-height: 1.4; }
.reduced-motion *, .reduced-motion *::before, .reduced-motion *::after { animation-duration: .001ms !important; animation-iteration-count: 1 !important; scroll-behavior: auto !important; }
@media (prefers-reduced-motion: reduce) { *, *::before, *::after { animation-duration: .001ms !important; animation-iteration-count: 1 !important; scroll-behavior: auto !important; } }
@media (min-width: 700px) { .shell { margin-top: 18px; min-height: calc(100dvh - 36px); border: 1px solid rgb(117 110 96 / .2); border-radius: 28px; background: rgb(255 253 248 / .62); box-shadow: 0 20px 60px rgb(58 48 30 / .12); } }

/* One screen (taste/ONE_SCREEN.md, P1FS20): the win card is a sheet pinned to the bottom of the screen, Next level first and full width. */
.result-card:not([hidden]) {
  position: fixed; z-index: 30; left: 50%; bottom: 0; width: min(100%, 430px); transform: translateX(-50%);
  display: flex; flex-direction: column; max-height: min(62dvh, calc(100dvh - 72px)); overflow-y: auto; overscroll-behavior: contain;
  margin: 0; padding: 14px 14px max(14px, env(safe-area-inset-bottom)); border-radius: 14px 14px 0 0; border-bottom: 0;
  box-shadow: 0 -8px 28px rgb(0 0 0 / .18);
}
.result-card .result-title { order: 0; }
.result-card .result-marks { order: 1; margin: 2px 0 10px; }
.result-card .result-actions { order: 2; }
.result-card .share-line { order: 3; margin: 10px 0 0; }
.result-actions #next-button:not([hidden]), .result-actions #levels-button:not([hidden]) { flex: 1 1 100%; order: -1; }
/* Below par, losing binds: Try again leads and Next level drops to the second row. */
.result-actions.below-par #again-button { flex: 1 1 100%; order: -1; }
.result-actions.below-par #next-button:not([hidden]) { flex: 1 1 auto; order: 0; }
