@font-face {
  font-family: "Outfit";
  src: url("fonts/outfit-latin.woff2") format("woff2");
  font-weight: 100 900;
  font-style: normal;
  font-display: swap;
}

@font-face {
  font-family: "Itim";
  src: url("fonts/itim-latin.woff2") format("woff2");
  font-weight: 400;
  font-style: normal;
  font-display: swap;
}

@property --bT {
  syntax: "<length>";
  inherits: false;
  initial-value: 0px;
}
@property --bR {
  syntax: "<length>";
  inherits: false;
  initial-value: 0px;
}
@property --bB {
  syntax: "<length>";
  inherits: false;
  initial-value: 0px;
}
@property --bL {
  syntax: "<length>";
  inherits: false;
  initial-value: 0px;
}

:root {
  --sun: #f8c630;
  --sun-light: #ffe06a;
  --sun-deep: #e8ad16;
  --sun-shade: #cf9410;
  --ink: #173042;
  --ink-soft: #5d6770;
  --paper: #ffffff;
  --cloud: #f2f4f3;
  --line: #dfe5e6;
  --sage: #8bd644;
  --sage-deep: #367f42;
  --coral: #ef6545;
  --tan: #ffd77a;
  --backdrop: #ddb028;
  --play-bg: var(--sun);
  --hole: #d99f16;
  --board: #e8ad16;
  --danger: #a12f22;
  --scrim: rgba(82, 60, 10, 0.42);
  --sun-pattern: rgba(255, 235, 130, 0.24);
  --outline: 2px;
  --lift: 0 5px 0 var(--sun-shade), 0 8px 18px rgba(91, 61, 5, 0.2);
  --lift-pressed: 0 2px 0 var(--sun-shade), 0 4px 9px rgba(91, 61, 5, 0.18);
  --soft-shadow: 0 12px 26px rgba(91, 61, 5, 0.18), 0 2px 6px rgba(23, 48, 66, 0.08);
  --panel-shadow: 0 8px 0 rgba(196, 143, 9, 0.42), 0 14px 28px rgba(91, 61, 5, 0.16);
  --radius: 20px;
  --font-ui: "Outfit", system-ui, -apple-system, "Segoe UI", sans-serif;
  --font-play: "Itim", "Chalkboard SE", "Comic Sans MS", var(--font-ui);
  --settle-ms: 280ms;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  min-height: 100%;
  background: var(--paper);
  color: var(--ink);
  font-family: var(--font-ui);
  font-weight: 500;
  -webkit-tap-highlight-color: transparent;
  -webkit-font-smoothing: antialiased;
}

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

body.playing {
  overflow: hidden;
  position: fixed;
  inset: 0;
  width: 100%;
  touch-action: none;
}

#app {
  max-width: 480px;
  margin: 0 auto;
  min-height: 100dvh;
  min-height: 100svh;
  position: relative;
  background: var(--paper);
}

.screen {
  min-height: 100dvh;
  min-height: 100svh;
  display: flex;
  flex-direction: column;
}

.hidden,
.hidden-canvas,
[hidden] {
  display: none !important;
}

h1,
h2,
h3,
h4 {
  margin: 0;
  font-weight: 700;
  letter-spacing: -0.01em;
}

button {
  font: inherit;
  color: inherit;
  cursor: pointer;
}

svg {
  display: block;
}

/* ---------- Shared bits ---------- */

.eyebrow,
.lede,
.fine {
  margin: 0;
}

.eyebrow {
  text-transform: uppercase;
  letter-spacing: 0.12em;
  font-size: 0.72rem;
  font-weight: 700;
  color: var(--ink-soft);
}

.fine {
  color: var(--ink-soft);
  font-size: 0.88rem;
  line-height: 1.4;
}

.badge-pill {
  display: inline-flex;
  align-items: center;
  height: 30px;
  padding: 0 14px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.55);
  font-size: 0.78rem;
  font-weight: 700;
  letter-spacing: 0.04em;
}

.logo-tile {
  display: inline-grid;
  place-items: center;
  width: 1.55em;
  height: 1.55em;
  margin: 0 -0.08em;
  border-radius: 0.36em;
  background: var(--paper);
  color: var(--ink);
  font-family: var(--font-play);
  font-weight: 400;
  line-height: 1;
  box-shadow: 0 6px 14px rgba(120, 92, 10, 0.18);
  transform: rotate(-4deg);
  position: relative;
}

.logo-tile:nth-child(even) {
  transform: rotate(5deg) translateY(0.12em);
}

.logo-tile:nth-child(3n) {
  transform: rotate(-2deg) translateY(-0.06em);
}

.logo-tile.t-sage {
  background: var(--sage);
}

.logo-tile.t-coral {
  background: var(--coral);
  color: var(--paper);
  z-index: 1;
}

.logo-tile.t-tan {
  background: var(--tan);
}

/* ---------- Home ---------- */

#home {
  padding: 0;
}

.hero {
  position: relative;
  display: grid;
  justify-items: center;
  gap: 14px;
  padding: calc(16px + env(safe-area-inset-top, 0px)) calc(20px + env(safe-area-inset-right, 0px)) 64px
    calc(20px + env(safe-area-inset-left, 0px));
  background: radial-gradient(120% 90% at 50% 0%, var(--sun-light) 0%, var(--sun) 55%, var(--sun-deep) 100%);
  text-align: center;
  overflow: hidden;
}

.hero::after {
  content: "";
  position: absolute;
  left: -20%;
  right: -20%;
  bottom: -1px;
  height: 46px;
  background: var(--paper);
  border-radius: 50% 50% 0 0 / 100% 100% 0 0;
}

.home-top {
  justify-self: stretch;
  display: grid;
  grid-template-columns: 44px minmax(0, 1fr) 44px;
  align-items: center;
  gap: 8px;
  margin: 0;
  min-height: 44px;
}

.home-mark {
  margin: 0;
  text-align: center;
  color: var(--ink-soft);
  font-style: italic;
  font-weight: 500;
}

.profile-btn {
  display: block;
  width: 44px;
  height: 44px;
  padding: 0;
  border: 2px solid var(--paper);
  border-radius: 50%;
  background: var(--paper);
  box-shadow: 0 4px 10px rgba(120, 92, 10, 0.22);
  overflow: hidden;
  transition: transform 0.12s ease;
}

.profile-btn img {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.profile-btn:active {
  transform: scale(0.94);
}

.home-settings {
  justify-self: end;
  display: grid;
  place-items: center;
  width: 44px;
  height: 44px;
  padding: 0;
  border: 0;
  border-radius: 14px;
  background: transparent;
}

.home-settings svg {
  box-sizing: content-box;
  width: 16px;
  height: 16px;
  padding: 8px;
  border-radius: 12px;
  background: rgba(255, 255, 255, 0.78);
  box-shadow: 0 3px 8px rgba(120, 92, 10, 0.16);
  fill: none;
  stroke: var(--ink);
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
  transition: transform 0.12s ease;
}

.home-settings:active svg {
  transform: scale(0.92);
}

.logo {
  display: flex;
  justify-content: center;
  font-size: clamp(1.25rem, 6.4vw, 1.7rem);
  padding: 6px 0 4px;
}

.lede {
  color: rgba(22, 22, 22, 0.72);
  font-size: 0.98rem;
  line-height: 1.35;
  max-width: 30ch;
}

.daily-card {
  position: relative;
  z-index: 1;
  justify-self: stretch;
  display: grid;
  grid-template-columns: auto 1fr auto;
  align-items: center;
  gap: 12px;
  margin-top: 4px;
  padding: 12px 14px 12px 12px;
  border: 0;
  border-radius: var(--radius);
  background: var(--paper);
  text-align: left;
  box-shadow: var(--soft-shadow);
  transition: transform 0.15s ease;
}

.daily-card:active {
  transform: scale(0.98);
}

.daily-icon {
  display: grid;
  place-items: center;
  width: 46px;
  height: 62px;
  border-radius: 14px;
  background: var(--coral);
  color: var(--paper);
  font-size: 1.4rem;
  transform: rotate(-5deg);
}

.daily-icon[hidden],
.daily-thumb[hidden] {
  display: none;
}

.daily-thumb {
  display: block;
  width: 46px;
  height: 62px;
  object-fit: cover;
  border-radius: 14px;
  background: var(--cloud);
}

.daily-text {
  display: grid;
  gap: 1px;
  min-width: 0;
}

.daily-kicker {
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--ink-soft);
}

.daily-card strong {
  font-family: var(--font-play);
  font-weight: 400;
  font-size: 1.3rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.daily-meta {
  padding: 5px 10px;
  border-radius: 10px;
  background: var(--cloud);
  font-size: 0.78rem;
  font-weight: 700;
  max-width: 9.5em;
  text-align: center;
  line-height: 1.2;
}

.daily-card.locked .daily-icon {
  background: var(--line);
  color: var(--ink-soft);
}

.daily-card.locked strong {
  color: var(--ink-soft);
}

.map {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  align-items: start;
  gap: 14px;
  padding: 4px calc(20px + env(safe-area-inset-right, 0px)) 16px calc(20px + env(safe-area-inset-left, 0px));
  flex: 1;
}

.home-bar {
  position: sticky;
  bottom: 0;
  z-index: 5;
  background: linear-gradient(180deg, rgba(255, 255, 255, 0) 0%, var(--paper) 28%);
}

.map-pager {
  display: grid;
  grid-template-columns: 44px minmax(0, 1fr) 44px;
  align-items: center;
  gap: 12px;
  padding: 12px calc(20px + env(safe-area-inset-right, 0px)) 0 calc(20px + env(safe-area-inset-left, 0px));
}

.map-page-btn {
  display: grid;
  place-items: center;
  width: 44px;
  height: 44px;
  padding: 0;
  border: var(--outline) solid var(--ink);
  border-radius: 14px;
  background: var(--paper);
  box-shadow: var(--lift);
  transition: transform 0.1s ease, box-shadow 0.1s ease;
}

.map-page-btn:active:not(:disabled) {
  transform: translateY(3px);
  box-shadow: var(--lift-pressed);
}

.map-page-btn:disabled {
  opacity: 0.35;
  box-shadow: none;
  cursor: default;
}

.map-page-btn svg {
  width: 20px;
  height: 20px;
  fill: none;
  stroke: var(--ink);
  stroke-width: 2.2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.map-page-label {
  margin: 0;
  text-align: center;
  font-family: var(--font-play);
  font-size: 1.05rem;
}

.puzzle-card {
  position: relative;
  display: grid;
  padding: 8px;
  border: 0;
  border-radius: var(--radius);
  background: var(--paper);
  text-align: left;
  box-shadow: 0 10px 24px rgba(22, 22, 22, 0.08), 0 0 0 1px var(--line);
  transition: transform 0.15s ease;
}

.puzzle-card:active {
  transform: scale(0.97);
}

.puzzle-card img {
  display: block;
  width: 100%;
  height: 118px;
  object-fit: cover;
  border-radius: 15px;
  background: var(--cloud);
}

.puzzle-card .meta {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 6px;
  padding: 10px 4px 4px;
}

.puzzle-card strong {
  font-size: 0.98rem;
  font-weight: 700;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.puzzle-card span {
  flex-shrink: 0;
  padding: 3px 8px;
  border-radius: 8px;
  background: var(--sun);
  font-family: var(--font-play);
  font-size: 0.85rem;
}

.puzzle-card.done::after {
  content: "✓";
  position: absolute;
  top: 0;
  right: 0;
  display: grid;
  place-items: center;
  width: 32px;
  height: 32px;
  border-radius: 11px;
  background: var(--sage);
  color: var(--ink);
  font-weight: 800;
  transform: translate(25%, -25%) rotate(6deg);
  box-shadow: 0 4px 10px rgba(22, 22, 22, 0.15);
}

.puzzle-card.locked img {
  filter: grayscale(1) brightness(1.15) contrast(0.7);
  opacity: 0.55;
}

.puzzle-card.locked .meta {
  opacity: 0.55;
}

.puzzle-card.locked span {
  background: var(--cloud);
}

.puzzle-card.locked::before {
  content: "";
  position: absolute;
  top: 8px;
  left: 8px;
  right: 8px;
  height: 118px;
  border-radius: 15px;
  background: center / 26px no-repeat
    url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23161616' stroke-width='2.2' stroke-linecap='round' stroke-linejoin='round'%3E%3Crect x='5' y='11' width='14' height='10' rx='3'/%3E%3Cpath d='M8 11V8a4 4 0 0 1 8 0v3'/%3E%3C/svg%3E");
  z-index: 1;
}

.dock {
  display: grid;
  grid-template-columns: 1fr 1fr;
  align-items: stretch;
  gap: 12px;
  padding: 18px calc(20px + env(safe-area-inset-right, 0px)) calc(20px + env(safe-area-inset-bottom, 0px))
    calc(20px + env(safe-area-inset-left, 0px));
}

.map-pager:not([hidden]) + .dock {
  padding-top: 10px;
}

.mode-btn,
.sheet .primary {
  border: var(--outline) solid var(--ink);
  background: var(--paper);
  color: var(--ink);
  box-shadow: var(--lift);
  transition: transform 0.1s ease, box-shadow 0.1s ease;
}

.mode-btn:active,
.sheet .primary:active {
  transform: translateY(3px);
  box-shadow: var(--lift-pressed);
}

.mode-btn {
  display: grid;
  justify-items: center;
  align-content: center;
  gap: 0;
  width: 100%;
  min-height: 68px;
  margin: 0 0 5px;
  padding: 12px 10px 10px;
  border-radius: 26px;
}

.mode-btn-label {
  font-size: 1.05rem;
  font-weight: 800;
  letter-spacing: 0.12em;
  text-transform: uppercase;
}

.mode-btn-sub {
  font-family: var(--font-play);
  font-size: 0.9rem;
  color: var(--ink-soft);
}

/* ---------- Play ---------- */

#play {
  position: relative;
  height: 100dvh;
  height: 100svh;
  overflow: hidden;
  overscroll-behavior: none;
  touch-action: none;
  gap: 12px;
  background: var(--play-bg);
  padding: calc(12px + env(safe-area-inset-top, 0px)) calc(14px + env(safe-area-inset-right, 0px))
    calc(12px + env(safe-area-inset-bottom, 0px)) calc(14px + env(safe-area-inset-left, 0px));
}

.play-title {
  position: absolute;
  width: 1px;
  height: 1px;
  margin: -1px;
  padding: 0;
  overflow: hidden;
  clip: rect(0 0 0 0);
  clip-path: inset(50%);
  white-space: nowrap;
  border: 0;
}

.play-top {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  flex: 0 0 auto;
  min-height: 48px;
}

.square-btn {
  position: absolute;
  left: 0;
  top: 50%;
  display: grid;
  place-items: center;
  width: 44px;
  height: 44px;
  padding: 0;
  border: 0;
  border-radius: 14px;
  background: var(--paper);
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.12), 0 6px 14px rgba(0, 0, 0, 0.12);
  transform: translateY(-50%);
  transition: transform 0.1s ease;
}

.square-btn:active {
  transform: translateY(calc(-50% + 2px));
}

.square-btn svg {
  width: 22px;
  height: 22px;
  fill: none;
  stroke: var(--ink);
  stroke-width: 2.2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.progress-stack {
  width: min(220px, 48%);
  display: grid;
  gap: 6px;
  min-width: 0;
}

.progress-wrap {
  display: grid;
  justify-items: center;
  gap: 3px;
  min-width: 0;
}

.progress-track {
  position: relative;
  width: 100%;
  height: 8px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.55);
  box-shadow: inset 0 1px 1px rgba(22, 22, 22, 0.12);
}

.progress-fill {
  height: 100%;
  width: 0%;
  min-width: 8px;
  border-radius: 999px;
  background: #8fd14f;
  box-shadow: none;
  transition: width 0.35s cubic-bezier(0.34, 1.4, 0.64, 1);
}

.progress-milestones {
  position: absolute;
  inset: 0;
  pointer-events: none;
}

.milestone {
  position: absolute;
  top: 50%;
  width: 14px;
  height: 14px;
  margin: -7px 0 0 -7px;
  border-radius: 4px;
  background: #2c6c78;
  border: 2px solid rgba(255, 255, 255, 0.9);
  transform: rotate(45deg);
  transition: background 0.25s ease, border-color 0.25s ease, transform 0.3s cubic-bezier(0.34, 1.6, 0.64, 1);
}

.milestone[data-at="20"] {
  left: 20%;
}

.milestone[data-at="50"] {
  left: 50%;
}

.milestone[data-at="80"] {
  left: 80%;
}

.milestone.lit {
  background: var(--coral);
  border-color: var(--paper);
  transform: rotate(45deg) scale(1.12);
}

.progress-label {
  min-width: 0;
  text-align: center;
  color: var(--paper);
  font-weight: 800;
  font-size: 0.95rem;
  line-height: 1.1;
  font-variant-numeric: tabular-nums;
}

.opponent-wrap .progress-track {
  height: 6px;
}

.opponent-fill {
  min-width: 6px;
  background: var(--coral);
}

.opponent-label {
  font-size: 0.78rem;
  font-weight: 700;
  color: rgba(255, 255, 255, 0.88);
}

.race-timer {
  position: absolute;
  right: 0;
  top: 50%;
  transform: translateY(-50%);
  padding: 3px 10px;
  border-radius: 999px;
  background: var(--paper);
  color: var(--ink);
  font-family: var(--font-play);
  font-size: 0.95rem;
  font-variant-numeric: tabular-nums;
  letter-spacing: 0.04em;
}

.play-stats {
  display: none;
}

.stat-chip {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  padding: 6px 8px 6px 16px;
  border-radius: 16px;
  background: var(--cloud);
  font-size: 0.78rem;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--ink-soft);
}

.stat-chip strong {
  min-width: 2.2em;
  padding: 2px 10px;
  border: 2px solid var(--ink);
  border-radius: 11px;
  background: var(--paper);
  color: var(--ink);
  font-family: var(--font-play);
  font-weight: 400;
  font-size: 1.15rem;
  letter-spacing: 0;
  text-align: center;
}

.stage {
  flex: 1 1 auto;
  min-height: 0;
  display: grid;
  place-items: start center;
  container-type: size;
}

.frame {
  position: relative;
  width: min(100cqw, calc(100cqh * 3 / 4));
  height: min(100cqh, calc(100cqw * 4 / 3));
  padding: 0;
  border-radius: 4px;
  background: transparent;
  box-shadow: none;
}

@media (max-height: 560px) {
  #play {
    gap: 8px;
  }

  .sheet canvas {
    max-height: 28dvh;
  }
}

.board {
  position: relative;
  width: 100%;
  height: 100%;
  background: transparent;
  border-radius: 4px;
  overflow: hidden;
  touch-action: none;
}

.pieces,
.lift {
  position: absolute;
  inset: 0;
  pointer-events: none;
}

.pieces {
  z-index: 2;
  filter: drop-shadow(0 1px 1px rgba(8, 40, 40, 0.45));
}

.lift {
  z-index: 30;
  will-change: transform;
}

.board-glow {
  position: absolute;
  inset: 0;
  border-radius: inherit;
  pointer-events: none;
  box-shadow: 0 0 0 4px var(--sun), 0 0 34px 10px rgba(248, 198, 48, 0.75);
  z-index: 20;
}

.hole {
  position: absolute;
  background: rgba(8, 40, 40, 0.16);
  pointer-events: none;
  z-index: 1;
}

@property --notch-tl {
  syntax: "<number>";
  inherits: false;
  initial-value: 0;
}
@property --notch-tr {
  syntax: "<number>";
  inherits: false;
  initial-value: 0;
}
@property --notch-br {
  syntax: "<number>";
  inherits: false;
  initial-value: 0;
}
@property --notch-bl {
  syntax: "<number>";
  inherits: false;
  initial-value: 0;
}

.card {
  position: absolute;
  margin: 0;
  padding: 0;
  /* Transparent border still insets the photo. The white edge is four
     rectangular strips: a real border miters to nothing where a welded
     side is 0px, which breaks the outline on the 2px stroke. */
  border-style: solid;
  border-color: transparent;
  border-width: 0;
  border-radius: 0;
  --edge: #fff;
  --card-art: none;
  --art-w: auto;
  --art-h: auto;
  --art-x: 0px;
  --art-y: 0px;
  background-color: var(--line);
  background-image:
    linear-gradient(var(--edge), var(--edge)),
    linear-gradient(var(--edge), var(--edge)),
    linear-gradient(var(--edge), var(--edge)),
    linear-gradient(var(--edge), var(--edge)),
    var(--card-art);
  background-size:
    100% var(--bT),
    var(--bR) 100%,
    100% var(--bB),
    var(--bL) 100%,
    var(--art-w) var(--art-h);
  background-position:
    left top,
    right top,
    left bottom,
    left top,
    var(--art-x) var(--art-y);
  background-repeat: no-repeat;
  background-origin: border-box, border-box, border-box, border-box, padding-box;
  background-clip: border-box, border-box, border-box, border-box, padding-box;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
  -webkit-user-drag: none;
  cursor: grab;
  pointer-events: auto;
  z-index: 1;
  --notch-tl: 0;
  --notch-tr: 0;
  --notch-br: 0;
  --notch-bl: 0;
  --notch-r: 2px;
}

/* The card that fills a concave notch has no white strip on either welded
   side, so the rounded bite would otherwise be bare photo. A quarter-disk
   continues the white edge around that corner. */
.card::after {
  content: "";
  position: absolute;
  inset: 0;
  border-radius: inherit;
  pointer-events: none;
  background:
    radial-gradient(circle at top left, var(--edge) var(--notch-r), transparent var(--notch-r)) top left /
      calc(var(--notch-tl) * var(--notch-r) * 2) calc(var(--notch-tl) * var(--notch-r) * 2) no-repeat,
    radial-gradient(circle at top right, var(--edge) var(--notch-r), transparent var(--notch-r)) top right /
      calc(var(--notch-tr) * var(--notch-r) * 2) calc(var(--notch-tr) * var(--notch-r) * 2) no-repeat,
    radial-gradient(circle at bottom right, var(--edge) var(--notch-r), transparent var(--notch-r)) bottom right /
      calc(var(--notch-br) * var(--notch-r) * 2) calc(var(--notch-br) * var(--notch-r) * 2) no-repeat,
    radial-gradient(circle at bottom left, var(--edge) var(--notch-r), transparent var(--notch-r)) bottom left /
      calc(var(--notch-bl) * var(--notch-r) * 2) calc(var(--notch-bl) * var(--notch-r) * 2) no-repeat;
}

.card:active {
  cursor: grabbing;
}

.card.dragging {
  z-index: 2;
  transition: none !important;
  cursor: grabbing;
  box-shadow: 0 10px 14px rgba(8, 40, 40, 0.4);
}

.card.settling {
  transition:
    left var(--settle-ms) ease,
    top var(--settle-ms) ease,
    width var(--settle-ms) ease,
    height var(--settle-ms) ease,
    border-width var(--settle-ms) ease,
    border-radius var(--settle-ms) ease,
    --bT var(--settle-ms) ease,
    --bR var(--settle-ms) ease,
    --bB var(--settle-ms) ease,
    --bL var(--settle-ms) ease,
    --notch-tl var(--settle-ms) ease,
    --notch-tr var(--settle-ms) ease,
    --notch-br var(--settle-ms) ease,
    --notch-bl var(--settle-ms) ease;
  z-index: 1;
}

.card.settling.dropped {
  z-index: 25;
}

.block-outline {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  z-index: 16;
  overflow: visible;
}

.block-outline path {
  fill: none;
  stroke: var(--sun);
  stroke-width: 3;
  stroke-linejoin: round;
  filter: drop-shadow(0 0 6px rgba(248, 198, 48, 0.95));
}

.block-edge {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  z-index: 4;
  overflow: visible;
}

.block-edge path {
  fill: none;
  stroke: #fff;
  stroke-linejoin: miter;
  stroke-linecap: butt;
}

.sparkle {
  position: absolute;
  width: 8px;
  height: 8px;
  border-radius: 2px;
  background: var(--sun);
  pointer-events: none;
  z-index: 40;
  animation: sparkle-pop 0.55s ease-out forwards;
}

.sparkle:nth-child(3n) {
  background: var(--coral);
}

.sparkle:nth-child(3n + 1) {
  background: var(--sage);
}

@keyframes sparkle-pop {
  0% {
    transform: scale(0.4) translate(0, 0) rotate(0deg);
    opacity: 1;
  }
  100% {
    transform: scale(1) translate(var(--dx), var(--dy)) rotate(140deg);
    opacity: 0;
  }
}

.toast {
  position: absolute;
  left: 50%;
  top: 30%;
  z-index: 35;
  padding: 8px 20px;
  border: var(--outline) solid var(--ink);
  border-radius: 18px;
  background: var(--paper);
  font-family: var(--font-play);
  font-size: 1.5rem;
  white-space: nowrap;
  box-shadow: 0 5px 0 var(--ink);
  pointer-events: none;
  transform: translate(-50%, -50%) rotate(-3deg);
  animation: toast-pop 0.32s cubic-bezier(0.34, 1.7, 0.64, 1);
}

@keyframes toast-pop {
  from {
    transform: translate(-50%, -50%) rotate(-3deg) scale(0.6);
    opacity: 0;
  }
}

.countdown-overlay {
  position: absolute;
  inset: 0;
  z-index: 48;
  display: grid;
  place-items: center;
  background: rgba(55, 132, 156, 0.55);
  backdrop-filter: blur(3px);
  -webkit-backdrop-filter: blur(3px);
  pointer-events: none;
}

.countdown-overlay span {
  display: grid;
  place-items: center;
  min-width: 1.5em;
  height: 1.5em;
  padding: 0 0.2em;
  border: 4px solid var(--ink);
  border-radius: 0.32em;
  background: var(--paper);
  font-family: var(--font-play);
  font-size: clamp(4rem, 18vw, 5.5rem);
  line-height: 1;
  box-shadow: 0 8px 0 var(--ink);
  transform: rotate(-4deg);
}

.win-stamp {
  position: absolute;
  inset: 0;
  z-index: 45;
  display: grid;
  place-content: center;
  gap: 18px;
  background: rgba(55, 132, 156, 0.55);
  backdrop-filter: blur(2px);
  -webkit-backdrop-filter: blur(2px);
  pointer-events: none;
  animation: stamp-in 0.45s cubic-bezier(0.34, 1.6, 0.64, 1);
}

.win-badge {
  display: flex;
  justify-content: center;
  font-size: 3rem;
}

.win-sub {
  margin: 0;
  justify-self: center;
  padding: 6px 16px;
  border-radius: 999px;
  background: var(--paper);
  font-weight: 700;
  text-align: center;
}

@keyframes stamp-in {
  from {
    transform: translateY(-24px) scale(1.15);
    opacity: 0;
  }
  to {
    transform: none;
    opacity: 1;
  }
}

.level-splash {
  position: absolute;
  inset: 0;
  z-index: 46;
  display: grid;
  place-items: center;
  padding: 24px;
  background: rgba(55, 132, 156, 0.55);
  backdrop-filter: blur(3px);
  -webkit-backdrop-filter: blur(3px);
  animation: splash-fade 0.25s ease-out;
}

.level-splash.leaving {
  opacity: 0;
  transition: opacity 0.25s ease-in;
}

.level-splash-card {
  display: grid;
  justify-items: center;
  gap: 10px;
  min-width: min(100%, 260px);
  padding: 22px 28px 20px;
  border: 4px solid var(--ink);
  border-radius: 28px;
  background: var(--paper);
  text-align: center;
  box-shadow: 0 8px 0 var(--ink);
  transform: rotate(-2deg);
  animation: stamp-in 0.45s cubic-bezier(0.34, 1.6, 0.64, 1);
}

.level-splash-difficulty {
  margin: 0;
  padding: 4px 14px;
  border: var(--outline) solid var(--ink);
  border-radius: 999px;
  background: var(--sun);
  font-size: 0.8rem;
  font-weight: 700;
  letter-spacing: 0.1em;
  text-transform: uppercase;
}

.level-splash-difficulty.very {
  background: var(--coral);
  color: var(--paper);
}

.level-splash-card h3 {
  font-family: var(--font-play);
  font-size: clamp(2rem, 9vw, 2.6rem);
  font-weight: 400;
  line-height: 1.05;
}

.level-splash-meta {
  margin: 0;
  color: var(--ink-soft);
  font-size: 0.9rem;
  font-weight: 600;
}

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

/* ---------- Sheets ---------- */

.overlay {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: grid;
  place-items: center;
  padding: calc(16px + env(safe-area-inset-top, 0px)) calc(16px + env(safe-area-inset-right, 0px))
    calc(16px + env(safe-area-inset-bottom, 0px)) calc(16px + env(safe-area-inset-left, 0px));
  background: rgba(120, 170, 168, 0.55);
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
  overflow: auto;
  -webkit-overflow-scrolling: touch;
}

.overlay.hidden {
  display: none;
}

.sheet {
  width: min(100%, 420px);
  max-height: min(92dvh, 720px);
  overflow: auto;
  display: grid;
  gap: 14px;
  padding: 26px 22px 22px;
  border-radius: 32px;
  background: var(--paper);
  text-align: center;
  box-shadow: 0 30px 60px rgba(30, 60, 60, 0.3);
  animation: sheet-in 0.32s cubic-bezier(0.34, 1.4, 0.64, 1);
}

@keyframes sheet-in {
  from {
    transform: translateY(24px) scale(0.96);
    opacity: 0;
  }
}

.sheet h3 {
  font-size: 1.55rem;
}

.sheet p {
  margin: 0;
  line-height: 1.4;
}

.sheet button {
  min-height: 52px;
  padding: 12px 16px;
  border: 0;
  border-radius: 18px;
  background: var(--cloud);
  font-weight: 700;
  font-size: 1rem;
  transition: transform 0.1s ease;
}

.sheet button:active {
  transform: scale(0.97);
}

.sheet button:disabled {
  opacity: 0.5;
  box-shadow: none;
  transform: none;
}

.sheet .primary {
  margin-bottom: 5px;
  background: var(--sun);
  box-shadow: 0 5px 0 0 var(--sun-deep), 0 5px 0 var(--outline) var(--ink);
}

.sheet .primary:active {
  box-shadow: 0 2px 0 0 var(--sun-deep), 0 2px 0 var(--outline) var(--ink);
}

.profile-sheet {
  position: relative;
  overflow: visible;
  margin-top: 22px;
  padding: 40px 16px 18px;
  text-align: left;
}

.sheet h3.profile-banner {
  position: absolute;
  top: 0;
  left: 50%;
  transform: translate(-50%, -48%);
  margin: 0;
  padding: 8px 28px 7px;
  border: var(--outline) solid var(--ink);
  border-radius: 16px;
  background: var(--sun);
  color: var(--ink);
  font-size: 1.2rem;
  line-height: 1.1;
  box-shadow: 0 4px 0 var(--sun-deep);
  white-space: nowrap;
}

.sheet button.profile-close {
  position: absolute;
  top: 10px;
  right: 10px;
  display: grid;
  place-items: center;
  width: 44px;
  height: 44px;
  min-height: 44px;
  padding: 0;
  border-radius: 50%;
  background: var(--cloud);
}

.profile-close svg {
  width: 16px;
  height: 16px;
  fill: none;
  stroke: var(--ink);
  stroke-width: 2.4;
  stroke-linecap: round;
}

.profile-identity {
  display: grid;
  grid-template-columns: 72px minmax(0, 1fr);
  align-items: center;
  gap: 12px;
}

#profile-preview {
  width: 72px;
  height: 72px;
  border-radius: 50%;
  background: var(--cloud);
  box-shadow: 0 0 0 3px var(--paper), 0 0 0 5px var(--line);
}

.profile-name {
  position: relative;
  display: block;
  min-width: 0;
  /* Clear the absolutely positioned close button (44px, 10px from the sheet edge). */
  margin-right: 46px;
}

#profile-name {
  width: 100%;
  min-height: 52px;
  padding: 0 16px;
  border: 2px solid transparent;
  border-radius: 999px;
  background: var(--cloud);
  color: var(--ink);
  font-family: var(--font-play);
  font-size: 1.15rem;
  font-weight: 400;
  outline: none;
}

#profile-name:focus {
  border-color: var(--ink);
  background: var(--paper);
}

#profile-name.invalid {
  border-color: var(--coral);
  background: var(--paper);
}

.profile-sheet .profile-name-error {
  margin: -6px 0 0;
  color: #8f2d12;
  font-size: 0.88rem;
  font-weight: 700;
}

.avatar-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 10px;
  max-height: min(42dvh, 280px);
  margin: 0;
  padding: 12px;
  overflow: auto;
  border-radius: 22px;
  background: var(--cloud);
  -webkit-overflow-scrolling: touch;
}

.sheet button.avatar-choice {
  position: relative;
  aspect-ratio: 1;
  min-height: 0;
  padding: 0;
  border: 3px solid transparent;
  border-radius: 50%;
  background: transparent;
}

.avatar-choice img {
  display: block;
  width: 100%;
  height: 100%;
  border-radius: 50%;
  object-fit: cover;
}

.avatar-choice[aria-checked="true"] {
  border-color: var(--sage-deep);
}

.avatar-choice[aria-checked="true"]::after {
  content: "";
  position: absolute;
  right: -2px;
  bottom: -2px;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: var(--sage) center / 12px 12px no-repeat
    url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23161616' stroke-width='3.2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M5 12.5 10 17l9-10'/%3E%3C/svg%3E");
  box-shadow: 0 2px 4px rgba(22, 22, 22, 0.18);
}

.profile-btn:focus-visible,
.home-settings:focus-visible,
.mode-btn:focus-visible,
.avatar-choice:focus-visible,
.profile-close:focus-visible,
#profile-confirm:focus-visible {
  outline: 3px solid var(--ink);
  outline-offset: 2px;
}

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  margin: -1px;
  padding: 0;
  overflow: hidden;
  clip: rect(0 0 0 0);
  clip-path: inset(50%);
  white-space: nowrap;
  border: 0;
}

.sheet canvas {
  justify-self: center;
  width: auto;
  max-width: 100%;
  height: auto;
  max-height: 36dvh;
  border-radius: 20px;
  background: var(--cloud);
  box-shadow: 0 0 0 6px var(--paper), 0 0 0 8px var(--line);
  margin: 6px 0;
}

.sheet-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  align-items: start;
}

.stats-row {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
  margin: 0 0 8px;
  overflow: visible;
}

.stat {
  position: relative;
  display: grid;
  align-content: start;
  gap: 7px;
  margin: 0;
  padding: 6px 6px 10px;
  overflow: visible;
  border-radius: 18px;
  background: var(--paper);
  box-shadow:
    0 8px 16px rgba(120, 92, 10, 0.14),
    0 1px 2px rgba(22, 22, 22, 0.05),
    0 0 0 1px var(--line);
}

.stat dt {
  display: grid;
  place-items: center;
  min-height: 28px;
  margin: 0;
  padding: 5px 6px 7px;
  border-radius: 12px;
  font-size: 0.72rem;
  font-weight: 800;
  letter-spacing: 0.06em;
  line-height: 1;
  text-transform: uppercase;
  color: var(--ink);
}

.stat-time dt {
  background: linear-gradient(180deg, var(--sun-light) 0%, var(--sun) 70%, var(--sun-deep) 100%);
  box-shadow: inset 0 -3px 0 var(--sun-shade);
}

.stat-moves dt {
  background: linear-gradient(180deg, color-mix(in srgb, white 34%, var(--sage)) 0%, var(--sage) 72%, var(--sage-deep) 100%);
  box-shadow: inset 0 -3px 0 color-mix(in srgb, black 16%, var(--sage));
}

.stat-combo dt {
  background: linear-gradient(180deg, color-mix(in srgb, white 32%, var(--tan)) 0%, var(--tan) 72%, color-mix(in srgb, black 10%, var(--tan)) 100%);
  box-shadow: inset 0 -3px 0 color-mix(in srgb, black 16%, var(--tan));
}

.stat dd {
  margin: 0;
  padding: 1px 2px 0;
  font-family: var(--font-play);
  font-size: 1.5rem;
  font-weight: 400;
  line-height: 1;
  font-variant-numeric: tabular-nums;
  color: var(--ink);
  text-align: center;
}

.stat-badge-slot {
  position: absolute;
  left: 4px;
  right: 4px;
  bottom: 0;
  z-index: 1;
  display: flex;
  justify-content: center;
  pointer-events: none;
  transform: translateY(42%);
}

.stat-badge {
  display: grid;
  place-items: center;
  min-height: 18px;
  max-width: 100%;
  padding: 3px 7px 4px;
  border-radius: 999px;
  font-size: 0.62rem;
  font-weight: 800;
  letter-spacing: 0.04em;
  line-height: 1;
  text-transform: uppercase;
  white-space: nowrap;
  color: var(--ink);
  animation: badge-pop 0.32s cubic-bezier(0.34, 1.7, 0.64, 1);
}

.stat-badge[hidden] {
  display: none;
}

.stat-badge.is-best-all {
  background: linear-gradient(180deg, var(--sun-light) 0%, var(--sun) 70%, var(--sun-deep) 100%);
  box-shadow:
    inset 0 -2px 0 var(--sun-shade),
    0 3px 6px rgba(22, 22, 22, 0.16);
}

.stat-badge.is-best-day {
  background: linear-gradient(180deg, color-mix(in srgb, white 34%, var(--sage)) 0%, var(--sage) 72%, var(--sage-deep) 100%);
  box-shadow:
    inset 0 -2px 0 color-mix(in srgb, black 16%, var(--sage)),
    0 3px 6px rgba(22, 22, 22, 0.16);
}

.stat-badge.is-good {
  background: linear-gradient(180deg, color-mix(in srgb, white 32%, var(--tan)) 0%, var(--tan) 72%, color-mix(in srgb, black 10%, var(--tan)) 100%);
  box-shadow:
    inset 0 -2px 0 color-mix(in srgb, black 16%, var(--tan)),
    0 3px 6px rgba(22, 22, 22, 0.16);
}

@keyframes badge-pop {
  from {
    transform: scale(0.6);
    opacity: 0;
  }
}

.toggle {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 12px 14px 12px 16px;
  border-radius: 16px;
  background: var(--cloud);
  font-weight: 700;
  cursor: pointer;
}

.toggle input {
  order: 2;
  appearance: none;
  -webkit-appearance: none;
  position: relative;
  width: 50px;
  height: 30px;
  margin: 0;
  border-radius: 999px;
  background: var(--line);
  cursor: pointer;
  transition: background 0.2s ease;
}

.toggle input::after {
  content: "";
  position: absolute;
  top: 3px;
  left: 3px;
  width: 24px;
  height: 24px;
  border-radius: 50%;
  background: var(--paper);
  box-shadow: 0 2px 4px rgba(22, 22, 22, 0.2);
  transition: transform 0.2s cubic-bezier(0.34, 1.5, 0.64, 1);
}

.toggle input:checked {
  background: var(--sage-deep);
}

.toggle input:checked::after {
  transform: translateX(20px);
}

.field {
  display: grid;
  gap: 6px;
  text-align: left;
  font-size: 0.8rem;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--ink-soft);
}

.field input,
.field select,
#race-code-input {
  font: inherit;
  font-size: 1rem;
  font-weight: 600;
  letter-spacing: normal;
  text-transform: none;
  min-height: 50px;
  padding: 12px 14px;
  border: 2px solid transparent;
  border-radius: 16px;
  background: var(--cloud);
  color: var(--ink);
  outline: none;
}

.field input:focus,
.field select:focus,
#race-code-input:focus {
  border-color: var(--ink);
  background: var(--paper);
}

#race-code-input {
  font-family: var(--font-play);
  font-size: 1.4rem;
  font-weight: 400;
  letter-spacing: 0.3em;
  text-transform: uppercase;
  text-align: center;
}

.race-join-row {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 8px;
  align-items: start;
}

.race-status {
  min-height: 1.2em;
}

#race-waiting-code {
  font-family: var(--font-play);
  font-weight: 400;
  font-size: 2.6rem;
  letter-spacing: 0.25em;
  padding-left: 0.25em;
}

.race-ready-line {
  font-weight: 700;
  color: var(--sage-deep);
}

#race-result-title {
  overflow-wrap: anywhere;
}

.race-scoreboard {
  display: grid;
  gap: 12px;
}

.race-score-head,
.race-cat {
  display: grid;
  grid-template-columns: 1fr 72px 1fr;
  align-items: center;
  column-gap: 8px;
}

.race-player {
  display: grid;
  justify-items: center;
  gap: 2px;
  min-width: 0;
  padding: 10px 8px 12px;
  border-radius: 20px;
  background: var(--cloud);
}

.race-player h4 {
  margin: 0;
  max-width: 100%;
  min-width: 0;
  overflow: hidden;
  font-size: 0.92rem;
  font-weight: 700;
  color: var(--ink-soft);
  text-overflow: ellipsis;
  white-space: nowrap;
}

.race-player.is-winner {
  background: linear-gradient(180deg, var(--sun-light) 0%, var(--sun) 72%, var(--sun-deep) 100%);
  box-shadow: inset 0 -4px 0 var(--sun-shade), 0 0 0 2px var(--ink);
}

.race-player.is-winner h4 {
  color: var(--ink);
}

.race-points {
  display: grid;
  justify-items: center;
  margin: 0;
  line-height: 1;
}

.race-points span {
  font-family: var(--font-play);
  font-size: 2.35rem;
  font-weight: 400;
  color: var(--ink);
}

.race-points small {
  margin-top: 1px;
  font-size: 0.68rem;
  font-weight: 800;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--ink-soft);
}

.race-player.is-winner .race-points small {
  color: var(--ink);
}

.race-scoreboard.is-unscored .race-points,
.race-scoreboard.is-unscored .race-pips {
  display: none;
}

.race-pips {
  display: flex;
  gap: 5px;
  margin-top: 6px;
}

.race-pip {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--line);
  box-shadow: inset 0 -2px 0 rgba(22, 22, 22, 0.08);
}

.race-pip.is-won[data-cat="time"] {
  background: var(--sun);
  box-shadow: inset 0 -2px 0 var(--sun-shade), 0 0 0 1.5px var(--ink);
}

.race-pip.is-won[data-cat="moves"] {
  background: var(--sage);
  box-shadow: inset 0 -2px 0 color-mix(in srgb, black 16%, var(--sage)), 0 0 0 1.5px var(--ink);
}

.race-pip.is-won[data-cat="combo"] {
  background: var(--tan);
  box-shadow: inset 0 -2px 0 color-mix(in srgb, black 16%, var(--tan)), 0 0 0 1.5px var(--ink);
}

.race-player.is-winner .race-pip:not(.is-won) {
  background: rgba(22, 22, 22, 0.22);
  box-shadow: none;
}

.race-player.is-winner .race-pip.is-won[data-cat="time"] {
  background: var(--ink);
  box-shadow: inset 0 -2px 0 rgba(0, 0, 0, 0.28);
}

.race-score-vs {
  margin: 0;
  align-self: center;
  font-size: 0.72rem;
  font-weight: 800;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--ink-soft);
}

.race-cats {
  display: grid;
  gap: 8px;
}

.race-cat-label {
  display: grid;
  place-items: center;
  min-height: 28px;
  padding: 5px 4px 7px;
  border-radius: 12px;
  font-size: 0.68rem;
  font-weight: 800;
  letter-spacing: 0.05em;
  line-height: 1;
  text-transform: uppercase;
  color: var(--ink);
}

.race-cat[data-cat="time"] .race-cat-label {
  background: linear-gradient(180deg, var(--sun-light) 0%, var(--sun) 70%, var(--sun-deep) 100%);
  box-shadow: inset 0 -3px 0 var(--sun-shade);
}

.race-cat[data-cat="moves"] .race-cat-label {
  background: linear-gradient(180deg, color-mix(in srgb, white 34%, var(--sage)) 0%, var(--sage) 72%, var(--sage-deep) 100%);
  box-shadow: inset 0 -3px 0 color-mix(in srgb, black 16%, var(--sage));
}

.race-cat[data-cat="combo"] .race-cat-label {
  background: linear-gradient(180deg, color-mix(in srgb, white 32%, var(--tan)) 0%, var(--tan) 72%, color-mix(in srgb, black 10%, var(--tan)) 100%);
  box-shadow: inset 0 -3px 0 color-mix(in srgb, black 16%, var(--tan));
}

.race-cat-value {
  position: relative;
  display: grid;
  place-items: center;
  min-height: 48px;
  padding: 8px 6px;
  border-radius: 16px;
  background: var(--cloud);
  font-family: var(--font-play);
  font-size: 1.35rem;
  font-weight: 400;
  line-height: 1;
  font-variant-numeric: tabular-nums;
  color: var(--ink-soft);
}

.race-cat-value.is-best {
  color: var(--ink);
  background: var(--paper);
  box-shadow:
    0 6px 12px rgba(120, 92, 10, 0.16),
    0 0 0 2px var(--ink);
}

.race-cat[data-cat="time"] .race-cat-value.is-best {
  background: linear-gradient(180deg, var(--sun-light) 0%, var(--sun) 70%, var(--sun-deep) 100%);
}

.race-cat[data-cat="moves"] .race-cat-value.is-best {
  background: linear-gradient(180deg, color-mix(in srgb, white 34%, var(--sage)) 0%, var(--sage) 72%, var(--sage-deep) 100%);
}

.race-cat[data-cat="combo"] .race-cat-value.is-best {
  background: linear-gradient(180deg, color-mix(in srgb, white 32%, var(--tan)) 0%, var(--tan) 72%, color-mix(in srgb, black 10%, var(--tan)) 100%);
}

.race-cat-value.is-best::after {
  content: "";
  position: absolute;
  top: -5px;
  right: -5px;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: var(--ink) center / 11px 11px no-repeat
    url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23ffffff' stroke-width='3.4' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M5 12.5 10 17l9-10'/%3E%3C/svg%3E");
  box-shadow: 0 2px 4px rgba(22, 22, 22, 0.2);
}

/* ---------- Desktop preview ---------- */

@media (min-width: 720px) {
  html,
  body {
    background: var(--backdrop);
  }

  #app {
    box-shadow: 0 30px 80px rgba(30, 60, 60, 0.35);
  }
}

/* ---------- Sunny game revamp ---------- */

html,
body {
  background: var(--backdrop);
}

body {
  color: var(--ink);
}

#app,
#home,
#play {
  background-color: var(--sun);
  background-image:
    radial-gradient(circle at 18px 9px, var(--sun-pattern) 0 8px, transparent 8.5px),
    radial-gradient(circle at 6px 27px, var(--sun-pattern) 0 8px, transparent 8.5px),
    radial-gradient(circle at 30px 27px, var(--sun-pattern) 0 8px, transparent 8.5px);
  background-size: 36px 36px;
}

#app {
  overflow: hidden;
}

button,
input,
select {
  touch-action: manipulation;
}

button {
  -webkit-tap-highlight-color: transparent;
}

button:focus-visible,
input:focus-visible,
select:focus-visible,
[role="radio"]:focus-visible {
  outline: 3px solid var(--ink);
  outline-offset: 3px;
}

.hero {
  gap: 13px;
  padding-bottom: 22px;
  background: linear-gradient(180deg, rgba(255, 224, 106, 0.82), rgba(248, 198, 48, 0.34));
  overflow: visible;
}

.hero::after {
  display: none;
}

.home-top {
  min-height: 48px;
}

.home-mark {
  color: var(--ink);
  font-style: normal;
  font-size: 0.78rem;
  font-weight: 800;
  letter-spacing: 0.12em;
  text-transform: uppercase;
}

.profile-btn {
  border: 3px solid var(--paper);
  box-shadow: 0 3px 0 var(--sun-shade), 0 7px 14px rgba(91, 61, 5, 0.18);
}

.home-settings svg {
  width: 18px;
  height: 18px;
  padding: 9px;
  border: 2px solid rgba(23, 48, 66, 0.08);
  border-radius: 50%;
  background: var(--paper);
  box-shadow: 0 3px 0 rgba(196, 143, 9, 0.38), 0 6px 12px rgba(91, 61, 5, 0.14);
}

.logo {
  padding: 10px 0 5px;
  font-size: clamp(1.3rem, 6.6vw, 1.8rem);
}

.logo-tile {
  border: 2px solid rgba(23, 48, 66, 0.12);
  box-shadow: 0 4px 0 rgba(196, 143, 9, 0.38), 0 8px 14px rgba(91, 61, 5, 0.14);
}

.logo-tile.t-sage {
  background: var(--sage);
}

.logo-tile.t-coral {
  background: var(--coral);
}

.logo-tile.t-tan {
  background: var(--tan);
}

.lede {
  color: var(--ink);
  font-size: 0.94rem;
  font-weight: 650;
}

.daily-card {
  margin-top: 6px;
  padding: 10px 12px;
  border: 2px solid rgba(23, 48, 66, 0.08);
  border-radius: 18px;
  box-shadow: var(--panel-shadow);
}

.daily-card:active {
  transform: translateY(3px);
  box-shadow: 0 4px 0 rgba(196, 143, 9, 0.38), 0 8px 16px rgba(91, 61, 5, 0.12);
}

.daily-icon,
.daily-thumb {
  border: 2px solid rgba(23, 48, 66, 0.1);
  border-radius: 13px;
  box-shadow: inset 0 -3px 0 rgba(23, 48, 66, 0.09);
}

.daily-icon svg {
  width: 25px;
  height: 25px;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
}

.daily-kicker {
  color: var(--ink-soft);
}

.daily-card strong {
  color: var(--ink);
  font-family: var(--font-ui);
  font-size: 1.12rem;
  font-weight: 800;
}

.daily-meta {
  color: var(--ink);
  background: var(--cloud);
  border: 1px solid var(--line);
  border-radius: 999px;
}

.map {
  gap: 14px;
  padding-top: 10px;
  padding-bottom: 26px;
}

.puzzle-card {
  padding: 7px;
  border: 2px solid rgba(23, 48, 66, 0.08);
  border-radius: 18px;
  box-shadow: var(--panel-shadow);
}

.puzzle-card:active {
  transform: translateY(3px) scale(0.99);
  box-shadow: 0 4px 0 rgba(196, 143, 9, 0.38), 0 8px 16px rgba(91, 61, 5, 0.12);
}

.puzzle-card img,
.puzzle-card.locked::before {
  height: 122px;
  border-radius: 12px;
}

.puzzle-card .meta {
  padding: 9px 3px 3px;
}

.puzzle-card strong {
  color: var(--ink);
  font-size: 0.92rem;
  font-weight: 800;
}

.puzzle-card span {
  color: var(--ink);
  background: var(--sun-light);
  border-radius: 999px;
  font-family: var(--font-ui);
  font-size: 0.74rem;
  font-weight: 800;
}

.puzzle-card.done::after {
  width: 34px;
  height: 34px;
  color: var(--paper);
  background: var(--sage-deep);
  border: 3px solid var(--paper);
  box-shadow: 0 3px 0 rgba(23, 48, 66, 0.18);
}

.puzzle-card.locked {
  background: rgba(255, 255, 255, 0.78);
}

.puzzle-card.locked img {
  filter: grayscale(0.8) brightness(1.04) contrast(0.78);
}

.home-bar {
  background: linear-gradient(180deg, rgba(248, 198, 48, 0), var(--sun) 24%);
}

.map-pager {
  padding-top: 16px;
}

.map-page-btn,
.square-btn {
  border: 2px solid rgba(23, 48, 66, 0.08);
  border-radius: 50%;
  box-shadow: 0 3px 0 rgba(196, 143, 9, 0.42), 0 7px 14px rgba(91, 61, 5, 0.14);
}

.map-page-label {
  color: var(--ink);
  font-family: var(--font-ui);
  font-size: 0.86rem;
  font-weight: 800;
}

.dock {
  gap: 10px;
  padding-top: 14px;
}

.mode-btn {
  min-height: 62px;
  margin-bottom: 4px;
  border-color: rgba(23, 48, 66, 0.12);
  border-radius: 18px;
  background: var(--paper);
  box-shadow: 0 5px 0 rgba(196, 143, 9, 0.48), 0 9px 18px rgba(91, 61, 5, 0.15);
}

.mode-btn:first-child {
  background: linear-gradient(180deg, var(--sun-light), #ffd84f);
}

.mode-btn-label {
  color: var(--ink);
  font-size: 1rem;
  letter-spacing: 0.08em;
}

.mode-btn-sub {
  color: var(--ink-soft);
  font-family: var(--font-ui);
  font-size: 0.76rem;
  font-weight: 700;
}

#play {
  gap: 10px;
}

.play-top {
  min-height: 52px;
}

.square-btn {
  box-shadow: 0 3px 0 rgba(196, 143, 9, 0.44), 0 7px 14px rgba(91, 61, 5, 0.15);
}

.progress-stack {
  width: min(230px, 53%);
  gap: 5px;
  padding: 7px 12px 6px;
  border: 2px solid rgba(23, 48, 66, 0.08);
  border-radius: 18px;
  background: var(--paper);
  box-shadow: 0 3px 0 rgba(196, 143, 9, 0.38), 0 7px 14px rgba(91, 61, 5, 0.12);
}

.progress-wrap {
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: center;
  justify-items: stretch;
  gap: 7px;
}

.progress-track {
  height: 10px;
  background: #e6ecec;
  box-shadow: inset 0 2px 2px rgba(23, 48, 66, 0.1);
}

.progress-fill {
  min-width: 10px;
  background: linear-gradient(180deg, #9ce652, var(--sage));
  box-shadow: inset 0 -2px 0 rgba(54, 127, 66, 0.28);
}

.milestone {
  width: 12px;
  height: 12px;
  margin: -6px 0 0 -6px;
  background: var(--ink-soft);
  border-color: var(--paper);
}

.milestone.lit {
  background: var(--coral);
}

.progress-label,
.opponent-label {
  color: var(--ink);
  font-size: 0.78rem;
}

.opponent-fill {
  background: var(--coral);
}

.race-timer {
  border: 2px solid rgba(23, 48, 66, 0.08);
  border-radius: 14px;
  font-family: var(--font-ui);
  font-weight: 800;
  box-shadow: 0 3px 0 rgba(196, 143, 9, 0.38);
}

.frame {
  border-radius: 14px;
  box-shadow: 0 8px 0 rgba(196, 143, 9, 0.42), 0 14px 26px rgba(91, 61, 5, 0.22);
}

.board {
  border-radius: 14px;
}

.pieces {
  filter: drop-shadow(0 1px 1px rgba(23, 48, 66, 0.38));
}

.hole {
  background: rgba(156, 108, 6, 0.22);
}

.card.dragging {
  box-shadow: 0 12px 18px rgba(91, 61, 5, 0.38);
}

.block-outline path {
  stroke: var(--coral);
  filter: drop-shadow(0 0 6px rgba(239, 101, 69, 0.78));
}

.board-glow {
  box-shadow: 0 0 0 4px var(--paper), 0 0 32px 10px rgba(255, 255, 255, 0.7);
}

.toast {
  top: 28%;
  border-color: rgba(23, 48, 66, 0.12);
  border-radius: 16px;
  background: var(--paper);
  font-family: var(--font-ui);
  font-size: 1.15rem;
  font-weight: 850;
  box-shadow: 0 5px 0 var(--sun-shade), 0 10px 20px rgba(91, 61, 5, 0.22);
}

.countdown-overlay,
.win-stamp,
.level-splash {
  background: var(--scrim);
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
}

.countdown-overlay span,
.level-splash-card {
  border-color: rgba(23, 48, 66, 0.12);
  box-shadow: 0 7px 0 var(--sun-shade), 0 16px 36px rgba(54, 36, 2, 0.3);
}

.countdown-overlay span {
  border-radius: 28px;
  color: var(--ink);
  font-family: var(--font-ui);
  font-weight: 900;
}

.win-badge .logo-tile {
  border-color: var(--paper);
}

.win-sub {
  color: var(--ink);
  box-shadow: 0 4px 0 rgba(196, 143, 9, 0.42);
}

.level-splash-card {
  border-radius: 24px;
  transform: none;
}

.level-splash-card h3 {
  color: var(--ink);
  font-family: var(--font-ui);
  font-weight: 850;
}

.level-splash-difficulty {
  border: 0;
  color: var(--ink);
  background: var(--sun);
}

.overlay {
  background: var(--scrim);
  backdrop-filter: blur(5px);
  -webkit-backdrop-filter: blur(5px);
}

.sheet {
  gap: 13px;
  padding: 24px 20px 20px;
  border: 2px solid rgba(23, 48, 66, 0.08);
  border-radius: 24px;
  box-shadow: 0 8px 0 rgba(196, 143, 9, 0.5), 0 24px 56px rgba(54, 36, 2, 0.3);
}

.sheet h3 {
  color: var(--ink);
  font-size: 1.6rem;
  font-weight: 850;
}

.sheet button {
  border: 1px solid var(--line);
  border-radius: 14px;
  color: var(--ink);
  background: var(--cloud);
}

.sheet .primary {
  border: 2px solid rgba(23, 48, 66, 0.1);
  color: var(--ink);
  background: linear-gradient(180deg, var(--sun-light), var(--sun));
  box-shadow: 0 5px 0 var(--sun-shade), 0 8px 16px rgba(91, 61, 5, 0.14);
}

.sheet h3.profile-banner {
  border-color: rgba(23, 48, 66, 0.1);
  border-radius: 14px;
  background: linear-gradient(180deg, var(--sun-light), var(--sun));
  box-shadow: 0 4px 0 var(--sun-shade);
}

#profile-preview {
  background: var(--cloud);
  box-shadow: 0 0 0 3px var(--paper), 0 0 0 5px var(--sun);
}

#profile-name,
.field input,
.field select,
#race-code-input {
  border-color: var(--line);
  background: var(--cloud);
}

#profile-name:focus,
.field input:focus,
.field select:focus,
#race-code-input:focus {
  border-color: var(--sun-shade);
  box-shadow: 0 0 0 3px rgba(248, 198, 48, 0.25);
}

.profile-sheet .profile-name-error {
  color: var(--danger);
}

.avatar-grid {
  border: 1px solid var(--line);
  background: var(--cloud);
}

.avatar-choice[aria-checked="true"] {
  border-color: var(--sun-shade);
  background: var(--sun-light);
}

.avatar-choice[aria-checked="true"]::after {
  background-color: var(--sage);
}

.sheet canvas {
  border-radius: 16px;
  box-shadow: 0 0 0 5px var(--paper), 0 0 0 7px var(--sun);
}

.stat {
  border: 1px solid var(--line);
  border-radius: 16px;
  box-shadow: 0 6px 14px rgba(91, 61, 5, 0.12);
}

.toggle {
  border: 1px solid var(--line);
  background: var(--cloud);
}

.toggle input:checked {
  background: var(--sage-deep);
}

.race-ready-line {
  color: var(--sage-deep);
}

.race-player,
.race-cat-value {
  border: 1px solid var(--line);
  background: var(--cloud);
}

.race-player.is-winner {
  border-color: rgba(23, 48, 66, 0.1);
  background: linear-gradient(180deg, var(--sun-light), var(--sun));
  box-shadow: inset 0 -4px 0 var(--sun-shade), 0 0 0 2px var(--ink);
}

.race-cat-value.is-best {
  box-shadow: 0 4px 0 var(--sun-shade), 0 0 0 2px var(--ink);
}

@media (max-width: 360px) {
  .hero,
  .map,
  .dock,
  .map-pager {
    padding-left: calc(14px + env(safe-area-inset-left, 0px));
    padding-right: calc(14px + env(safe-area-inset-right, 0px));
  }

  .map {
    gap: 10px;
  }

  .puzzle-card img,
  .puzzle-card.locked::before {
    height: 106px;
  }

  .sheet {
    padding-left: 16px;
    padding-right: 16px;
  }
}

@media (max-height: 560px) {
  .play-top {
    min-height: 46px;
  }

  .progress-stack {
    padding-block: 5px;
  }
}

@media (min-width: 720px) {
  #app {
    border-inline: 1px solid rgba(23, 48, 66, 0.12);
    box-shadow: 0 30px 80px rgba(54, 36, 2, 0.35);
  }
}

@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;
  }
}
