:root {
  --stage: #14182e;
  --ink: #1c2140;
  --glass: #f7f8ff;
  --paper: #fffdf8;
  --line: #d5daf0;
  --sapphire: #3d6bff;
  --ruby: #e23d5a;
  --emerald: #1f9d6a;
  --amber: #f0a202;
  --violet: #7a4de0;
  --shadow: #0c1024;
  color-scheme: dark;
  font-family: "Avenir Next", Avenir, "Segoe UI", sans-serif;
}

* { box-sizing: border-box; }

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

body {
  background:
    radial-gradient(ellipse at 12% -8%, rgba(61, 107, 255, 0.38), transparent 46%),
    radial-gradient(ellipse at 110% 8%, rgba(226, 61, 90, 0.2), transparent 42%),
    var(--stage);
  color: var(--glass);
  min-height: 100dvh;
  padding:
    env(safe-area-inset-top)
    env(safe-area-inset-right)
    env(safe-area-inset-bottom)
    env(safe-area-inset-left);
  -webkit-tap-highlight-color: transparent;
}

button { font: inherit; touch-action: manipulation; cursor: pointer; }
button:disabled { opacity: 0.45; cursor: default; }
button:focus-visible {
  outline: 3px solid var(--amber);
  outline-offset: 3px;
}

.home, .play {
  width: min(920px, 100%);
  margin: 0 auto;
  padding: 22px 18px 32px;
}

.gem {
  position: relative;
  width: 96px;
  height: 96px;
  margin: 8px auto 0;
  overflow: hidden;
  border-radius: 28px;
}
.gem svg { display: block; }
.gem::after {
  content: "";
  position: absolute;
  inset: 0;
  background: linear-gradient(105deg, transparent 32%, rgba(255, 255, 255, 0.72) 50%, transparent 68%);
  animation: shine 1.6s ease 0.35s 1 both;
  pointer-events: none;
}
@keyframes shine {
  from { transform: translateX(-130%); }
  to { transform: translateX(130%); }
}

.brand {
  font-family: "Iowan Old Style", Palatino, "Palatino Linotype", Georgia, serif;
  font-weight: 600;
  font-size: clamp(44px, 7vw, 68px);
  letter-spacing: -0.03em;
  text-align: center;
  margin: 8px 0 0;
}
.hello {
  text-align: center;
  margin: 0 0 22px;
  color: #c5cce8;
  font-size: 18px;
}

.tiles {
  display: grid;
  grid-template-columns: 1fr;
  gap: 14px;
}
.tile {
  display: block;
  width: 100%;
  text-align: left;
  border: 0;
  border-radius: 22px;
  min-height: 96px;
  padding: 18px 20px;
  color: white;
  transform: translateY(0);
}
.tile-name { display: block; font-size: 26px; font-weight: 700; letter-spacing: -0.02em; }
.tile-line { display: block; margin-top: 4px; font-size: 16px; opacity: 0.92; }
.tile-sapphire { background: var(--sapphire); box-shadow: 0 6px 0 #2146c4; }
.tile-ruby { background: var(--ruby); box-shadow: 0 6px 0 #a11e38; }
.tile-emerald { background: var(--emerald); box-shadow: 0 6px 0 #0e6b46; }
.tile-amber { background: var(--amber); box-shadow: 0 6px 0 #b67800; color: var(--ink); }
.tile-violet { background: var(--violet); box-shadow: 0 6px 0 #4d2ea8; }
.tile:active { transform: translateY(4px); }
.tile-sapphire:active { box-shadow: 0 2px 0 #2146c4; }
.tile-ruby:active { box-shadow: 0 2px 0 #a11e38; }
.tile-emerald:active { box-shadow: 0 2px 0 #0e6b46; }
.tile-amber:active { box-shadow: 0 2px 0 #b67800; }
.tile-violet:active { box-shadow: 0 2px 0 #4d2ea8; }

@media (min-width: 700px) {
  .tiles { grid-template-columns: 1fr 1fr; }
  .tile-wide { grid-column: 1 / -1; }
}

.topbar {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 14px;
}
.back {
  background: var(--glass);
  color: var(--ink);
  border: 0;
  border-radius: 999px;
  min-height: 44px;
  padding: 0 16px;
  font-weight: 700;
  box-shadow: 0 3px 0 var(--shadow);
}
.back:active { transform: translateY(2px); box-shadow: 0 1px 0 var(--shadow); }
.game-title {
  font-family: "Iowan Old Style", Palatino, "Palatino Linotype", Georgia, serif;
  font-size: clamp(28px, 4vw, 40px);
  font-weight: 600;
  margin: 0;
  letter-spacing: -0.02em;
}

.stage { color: var(--glass); }

.panel {
  background: var(--glass);
  color: var(--ink);
  border-radius: 24px;
  padding: 16px;
}
.lead { font-size: 20px; margin: 4px 0 14px; }
.status { font-size: 20px; font-weight: 700; margin: 0; }
.count { margin: 0; font-size: 18px; }
.row {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  align-items: center;
  margin-top: 14px;
}
.choice-panel { display: flex; flex-direction: column; gap: 12px; align-items: stretch; }
.choice-panel .row, .choice-panel .lead { margin: 0; }

.btn {
  background: var(--ink);
  color: var(--glass);
  border: 0;
  border-radius: 999px;
  min-height: 48px;
  padding: 0 18px;
  font-weight: 700;
  box-shadow: 0 4px 0 #0b0e1c;
}
.btn:active { transform: translateY(2px); box-shadow: 0 2px 0 #0b0e1c; }
.btn.big { min-height: 72px; font-size: 22px; }
.btn.ghost {
  background: transparent;
  color: var(--ink);
  box-shadow: none;
  border: 2px solid #c5cbe6;
}
.btn.ghost:active { transform: none; }
.btn.ghost.on { background: var(--ink); color: var(--glass); border-color: var(--ink); }
.btn.amber { background: var(--amber); color: var(--ink); box-shadow: 0 4px 0 #b67800; }
.banner {
  margin: 12px 0 0;
  padding: 12px 14px;
  border-radius: 16px;
  background: #fff4cc;
  font-weight: 700;
}

.ttt { max-width: 520px; margin: 0 auto; }
.ttt .status, .ttt .tally { color: var(--glass); }
.ttt .tally { text-align: center; letter-spacing: 0.02em; }
.ttt .btn.ghost { color: var(--glass); border-color: rgba(247, 248, 255, 0.45); }
.ttt .btn.ghost:active { color: var(--glass); }
.ttt-board {
  width: min(78vw, 62vh, 460px);
  height: min(78vw, 62vh, 460px);
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  grid-template-rows: repeat(3, minmax(0, 1fr));
  gap: 8px;
  background: #0e1224;
  padding: 8px;
  border-radius: 22px;
  margin: 12px auto;
}
.ttt-cell {
  appearance: none;
  background: var(--glass);
  border: 0;
  border-radius: 12px;
  min-width: 0;
  min-height: 0;
  padding: 0;
  display: grid;
  place-items: center;
}
.ttt-cell:active { background: #e4e9ff; }
.ttt-cell.win { background: #ffe39a; }
.mark {
  font-family: "Iowan Old Style", Palatino, "Palatino Linotype", Georgia, serif;
  font-size: clamp(44px, 10vw, 76px);
  line-height: 1;
  font-weight: 700;
}
.mark.x { color: var(--sapphire); }
.mark.o { color: var(--ruby); }

.pair {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
  margin-top: 12px;
}
.picture {
  position: relative;
  border-radius: 16px;
  overflow: hidden;
  background: white;
  line-height: 0;
}
.art svg { display: block; width: 100%; height: auto; }
.hotspot {
  position: absolute;
  border: 0;
  padding: 0;
  background: transparent;
  border-radius: 50%;
}
.hotspot.found {
  background: rgba(224, 179, 37, 0.32);
  box-shadow: inset 0 0 0 4px #e0b325;
}
.hotspot.hint { box-shadow: inset 0 0 0 4px var(--amber); animation: pulse 1.2s ease infinite; }
@keyframes pulse {
  50% { box-shadow: inset 0 0 0 7px var(--amber); }
}

.clue { font-size: clamp(22px, 3vw, 30px); font-weight: 700; margin: 0 0 8px; line-height: 1.25; }
.miss { margin: 0 0 8px; color: var(--ruby); font-weight: 700; }

.draw-layout {
  display: grid;
  grid-template-columns: 168px 1fr;
  gap: 16px;
  align-items: start;
}
.prompt-title {
  font-family: "Iowan Old Style", Palatino, "Palatino Linotype", Georgia, serif;
  font-size: 28px;
  margin: 0 0 8px;
}
.ref-art svg {
  width: 150px;
  height: auto;
  display: block;
  background: var(--paper);
  border-radius: 16px;
  border: 2px solid var(--line);
}
.hint { margin: 8px 0 0; color: #3c4468; }
.paper {
  width: min(100%, 54vh, 520px);
  aspect-ratio: 1;
  display: block;
  background: var(--paper);
  border-radius: 18px;
  border: 2px solid var(--line);
  touch-action: none;
  box-shadow: 0 6px 0 var(--shadow);
}
.tools { margin-top: 12px; }
.swatches { display: flex; flex-wrap: wrap; gap: 8px; }
.swatch {
  width: 44px;
  height: 44px;
  border-radius: 50%;
  border: 3px solid white;
  box-shadow: 0 0 0 1px #c5cbe6;
  padding: 0;
}
.swatch.on { box-shadow: 0 0 0 3px var(--amber); }
.note { min-height: 1.3em; font-weight: 700; color: var(--ruby); margin: 8px 0 0; }
.stars {
  font-size: 32px;
  letter-spacing: 4px;
  margin: 8px 0 0;
  color: #c4840a;
}
.grade p { margin: 4px 0 8px; font-size: 18px; font-weight: 700; }

.factory {
  display: grid;
  grid-template-columns: 200px 1fr;
  gap: 16px 20px;
  align-items: start;
}
.ticket { grid-column: 1 / -1; background: #fff4cc; border-radius: 16px; padding: 12px 14px; }
.ticket p { margin: 0 0 8px; }
.ticket-label { font-size: 16px; font-weight: 700; color: #8a6408; margin: 0 0 4px; }
.preview { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; }
.mini { width: 22px; height: 22px; border-radius: 50%; display: block; border: 1px solid rgba(28, 33, 64, 0.2); }
.mini-top { font-weight: 700; margin-left: 4px; }
.sundae {
  position: relative;
  width: 180px;
  height: 360px;
  margin: 0 auto;
}
.pile {
  position: absolute;
  left: 50%;
  bottom: 124px;
  transform: translateX(-50%);
  z-index: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  width: 150px;
}
.sundae[data-vessel="glass"] .pile { bottom: 48px; }
.sundae[data-vessel="glass"] .scoop { width: 108px; height: 56px; margin-top: -24px; }
.sundae[data-vessel="glass"] .stack .scoop:first-child { margin-top: 0; }
.stack { position: relative; width: 140px; display: flex; flex-direction: column; align-items: center; z-index: 1; }
.scoop {
  position: relative;
  width: 132px;
  height: 72px;
  border-radius: 50%;
  margin-top: -34px;
  border: 2px solid rgba(28, 33, 64, 0.12);
  box-shadow: inset -12px -8px 0 rgba(0, 0, 0, 0.08), inset 8px 8px 0 rgba(255, 255, 255, 0.35);
}
.stack .scoop:first-child { margin-top: 0; }
.sprinkle { position: absolute; width: 4px; height: 11px; border-radius: 3px; }
.cookie {
  position: absolute;
  right: -8px;
  top: 16px;
  width: 28px;
  height: 28px;
  border-radius: 50%;
  background: #e0b56a;
}
.cookie i {
  position: absolute;
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: #6b3a2a;
}
.cookie i:nth-child(1) { left: 5px; top: 8px; }
.cookie i:nth-child(2) { left: 14px; top: 15px; }
.cookie i:nth-child(3) { left: 15px; top: 6px; }
.drizzle { position: absolute; left: 50%; top: 6px; transform: translateX(-50%); z-index: 3; pointer-events: none; }
.cherry {
  width: 22px;
  height: 22px;
  border-radius: 50%;
  background: var(--ruby);
  position: relative;
  z-index: 4;
  margin-bottom: -4px;
}
.cherry::after {
  content: "";
  position: absolute;
  left: 9px;
  bottom: 16px;
  width: 3px;
  height: 14px;
  background: #2f8f4e;
  border-radius: 2px;
}
.cream {
  width: 108px;
  height: 50px;
  background: white;
  border-radius: 50%;
  margin-bottom: -22px;
  z-index: 3;
  box-shadow: inset 0 -8px 0 #e4e7f4;
}
.vessel {
  position: absolute;
  left: 50%;
  bottom: 0;
  transform: translateX(-50%);
  z-index: 2;
  line-height: 0;
}
.sundae[data-vessel="glass"] .vessel { z-index: 0; }
.controls .status { margin-bottom: 8px; }
.flavors {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 8px;
  margin-top: 12px;
}
.flavor {
  min-height: 52px;
  border-radius: 14px;
  border: 2px solid rgba(28, 33, 64, 0.15);
  font-weight: 700;
  text-transform: capitalize;
  padding: 6px;
}
.toppings { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 10px; }
.toppings .btn { text-transform: capitalize; }

@media (max-width: 720px) {
  .pair { grid-template-columns: 1fr; }
  .draw-layout, .factory { grid-template-columns: 1fr; }
  .flavors { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .ref-art svg { width: 120px; }
}

@media (prefers-reduced-motion: reduce) {
  .gem::after, .hotspot.hint { animation: none; }
  .tile:active, .btn:active, .back:active { transform: none; }
}
