/* ============================================================
   Marigold — warm, soft, iPhone-first.
   Palette: cream, sage, dusty rose, warm plum, marigold-orange.
   ============================================================ */

:root {
  --cream:        #fdf6ec;
  --cream-deep:   #f6ebd9;
  --sand:         #efe2cb;
  --rose:         #d9a18a;
  --rose-deep:    #c08367;
  --plum:         #6f4e57;
  --plum-soft:    #8a6770;
  --ink:          #3a2f29;
  --ink-soft:     #6e5b50;
  --ink-muted:    #9e8b80;
  --sage:         #9bb39a;
  --sage-deep:    #6f8e6f;
  --marigold:     #d97f3a;
  --marigold-deep:#b5612a;
  --yellow:       #e8c25c;
  --line:         rgba(58, 47, 41, 0.10);
  --shadow:       0 1px 0 rgba(58, 47, 41, 0.04), 0 12px 24px -16px rgba(58, 47, 41, 0.16);
  --radius:       16px;
  --radius-sm:    10px;
  --tap:          44px;
}

*, *::before, *::after { box-sizing: border-box; }

html, body { height: 100%; }
html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  background: var(--cream);
  color: var(--ink);
  font-family: ui-sans-serif, system-ui, -apple-system, "Segoe UI", "Helvetica Neue", sans-serif;
  font-size: 16px;
  line-height: 1.45;
  -webkit-font-smoothing: antialiased;
  /* iPhone safe area */
  padding-top: env(safe-area-inset-top);
  padding-bottom: env(safe-area-inset-bottom);
}

h1, h2, h3, .brand, .title {
  font-family: ui-serif, Georgia, "Iowan Old Style", "Apple Garamond", "Palatino", serif;
  font-weight: 600;
  letter-spacing: -0.01em;
}

a { color: var(--rose-deep); text-decoration: none; }
a:hover { text-decoration: underline; }

/* ------------------------------------------------------------
   Topbar (used on every game page)
   ------------------------------------------------------------ */
.topbar {
  display: grid;
  grid-template-columns: var(--tap) 1fr var(--tap);
  align-items: center;
  padding: 8px 12px;
  border-bottom: 1px solid var(--line);
  background: var(--cream);
  position: sticky; top: 0; z-index: 5;
}
.topbar.topbar-4 {
  grid-template-columns: var(--tap) 1fr var(--tap) var(--tap);
}
.topbar .back, .topbar .stats-link, .topbar .help-btn {
  display: inline-flex;
  align-items: center; justify-content: center;
  width: var(--tap); height: var(--tap);
  font-size: 22px;
  color: var(--plum);
  border-radius: 999px;
}
.topbar .help-btn {
  appearance: none;
  border: none;
  background: transparent;
  font-family: ui-serif, Georgia, serif;
  font-weight: 700;
  cursor: pointer;
}
.topbar .help-btn:hover { background: var(--cream-deep); }
.topbar .help-btn:active { transform: scale(0.95); }
.topbar .title {
  text-align: center;
  font-size: 22px;
  margin: 0;
  color: var(--plum);
}

/* ------------------------------------------------------------
   Generic blocks
   ------------------------------------------------------------ */
.btn {
  appearance: none;
  border: none;
  background: var(--rose-deep);
  color: var(--cream);
  font: inherit;
  font-weight: 600;
  padding: 12px 18px;
  min-height: var(--tap);
  border-radius: 999px;
  cursor: pointer;
  transition: transform 0.05s ease, background 0.15s ease;
}
.btn:hover { background: var(--plum); }
.btn:active { transform: scale(0.98); }
.btn:disabled {
  background: var(--sand); color: var(--ink-muted); cursor: not-allowed;
}
.btn-ghost {
  background: transparent;
  color: var(--plum);
  border: 1.5px solid var(--line);
}
.btn-ghost:hover { background: var(--cream-deep); color: var(--plum); }
.link-btn {
  background: none; border: none; color: var(--rose-deep);
  font: inherit; cursor: pointer; padding: 0;
}
.link-btn:hover { text-decoration: underline; }

.message {
  text-align: center;
  color: var(--plum-soft);
  min-height: 1.2em;
  font-size: 14px;
  margin: 8px 0;
}
.muted { color: var(--ink-muted); }

.card {
  background: #fff;
  border-radius: var(--radius);
  padding: 28px 24px;
  max-width: 380px;
  width: 92%;
  box-shadow: var(--shadow);
}

.centered {
  min-height: 100dvh;
  display: grid;
  place-items: center;
  padding: 24px 16px;
}

.card .brand { font-size: 32px; margin: 0 0 4px; color: var(--marigold-deep); }
.card form { display: grid; gap: 12px; margin-top: 18px; }
.card input[type=email] {
  font: inherit; padding: 12px 14px; min-height: var(--tap);
  border: 1.5px solid var(--line); border-radius: var(--radius-sm);
  background: var(--cream);
}
.card input:focus { outline: none; border-color: var(--rose); }

/* ------------------------------------------------------------
   Home / tile picker
   ------------------------------------------------------------ */
.home-header {
  text-align: center;
  padding: 32px 16px 8px;
}
.brand { font-size: 40px; margin: 0; color: var(--marigold-deep); }
.brand-sub { color: var(--plum-soft); margin: 4px 0 0; font-style: italic; }

.tiles {
  display: grid;
  gap: 14px;
  padding: 16px;
  max-width: 520px;
  margin: 0 auto;
}
.tile {
  display: grid;
  grid-template-columns: 88px 1fr;
  gap: 14px;
  background: #fff;
  border-radius: var(--radius);
  padding: 14px;
  box-shadow: var(--shadow);
  color: var(--ink);
  text-decoration: none;
  transition: transform 0.08s ease, box-shadow 0.15s ease;
}
.tile:hover { transform: translateY(-1px); }
.tile-art {
  background: var(--cream-deep);
  border-radius: var(--radius-sm);
  display: grid; place-items: center;
  aspect-ratio: 1 / 1;
}
.tile-art svg { width: 70%; height: 70%; fill: var(--plum-soft); }
.tile-quint .art-on { fill: var(--sage-deep); }
.tile-knit  .art-on-a { fill: var(--yellow); }
.tile-knit  .art-on-b { fill: var(--sage); }
.tile-knit  .art-on-c { fill: var(--rose); }
.tile-pollen .art-center { fill: var(--marigold); }
.tile-pollen circle { fill: var(--yellow); }
.tile-pollen .art-center { fill: var(--marigold); }

.tile h2 { margin: 4px 0 2px; font-size: 22px; color: var(--plum); }
.tile p  { margin: 0; color: var(--ink-soft); font-size: 14px; }
.tile-status {
  display: inline-block; margin-top: 8px;
  font-size: 12px; color: var(--ink-muted);
}
.tile-status.done { color: var(--sage-deep); font-weight: 600; }

.home-foot {
  text-align: center;
  padding: 28px 16px calc(env(safe-area-inset-bottom) + 28px);
  color: var(--ink-muted); font-size: 13px;
}
.home-foot .inline { display: inline; }
.dot-sep { padding: 0 8px; }

/* ------------------------------------------------------------
   Quint board
   ------------------------------------------------------------ */
.quint-main {
  display: grid; gap: 10px;
  padding: 14px 12px;
  max-width: 420px; margin: 0 auto;
  height: calc(100dvh - 60px);
  grid-template-rows: 1fr auto auto;
  align-content: stretch;
}
.quint-board {
  display: grid;
  grid-template-rows: repeat(6, 1fr);
  gap: 6px;
  justify-content: center; align-content: center;
  width: 100%;
}
.quint-row {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 6px;
  width: min(100%, 320px);
  margin: 0 auto;
}
.quint-cell {
  aspect-ratio: 1 / 1;
  border-radius: 8px;
  border: 2px solid var(--line);
  display: grid; place-items: center;
  font-family: ui-serif, Georgia, serif;
  font-weight: 700;
  font-size: clamp(20px, 7vw, 32px);
  color: var(--ink);
  background: var(--cream);
  user-select: none;
  transition: transform 0.12s ease;
}
.quint-cell.filled {
  border-color: var(--plum-soft);
  transform: scale(1.02);
}
.quint-cell.flipped {
  color: #fff;
  border-color: transparent;
  animation: flip 0.45s ease-out both;
  animation-delay: calc(var(--i, 0) * 110ms);
}
.quint-cell.hit  { background: var(--sage-deep); }
.quint-cell.near { background: var(--marigold); }
.quint-cell.miss { background: var(--plum-soft); }

@keyframes flip {
  0%   { transform: rotateX(0); }
  50%  { transform: rotateX(90deg); }
  100% { transform: rotateX(0); }
}

.quint-keyboard {
  display: grid; gap: 6px;
  margin-top: 4px;
  padding-bottom: env(safe-area-inset-bottom);
}
.kbd-row { display: flex; justify-content: center; gap: 5px; }
.kbd-key {
  appearance: none; border: none;
  font: inherit;
  flex: 1 1 0;
  min-width: 0;
  min-height: 48px;
  border-radius: 8px;
  background: var(--cream-deep);
  color: var(--ink);
  font-weight: 600;
  text-transform: uppercase;
  cursor: pointer;
}
.kbd-key.kbd-wide { flex: 1.6 1 0; font-size: 13px; }
.kbd-key.hit  { background: var(--sage-deep); color: #fff; }
.kbd-key.near { background: var(--marigold); color: #fff; }
.kbd-key.miss { background: #c9b9a8; color: #fff; }
.kbd-key:active { transform: scale(0.96); }

/* ------------------------------------------------------------
   Knit
   ------------------------------------------------------------ */
.knit-main {
  padding: 12px;
  max-width: 460px; margin: 0 auto;
}
.knit-blurb { color: var(--ink-soft); margin: 4px 4px 12px; font-size: 14px; }
.knit-solved { display: grid; gap: 6px; margin-bottom: 8px; }
.knit-solved-row {
  border-radius: 10px;
  padding: 8px 10px;
  color: var(--ink);
  text-align: center;
  font-size: 13px;
  line-height: 1.3;
}
.knit-solved-row .cat-name {
  font-family: ui-serif, Georgia, serif; font-weight: 700; font-size: 14px;
}
.knit-solved-row .cat-words { font-size: 12px; opacity: 0.85; }
.k-yellow { background: #f0d57a; }
.k-sage   { background: #b9d2b1; }
.k-rose   { background: #e8b3a3; }
.k-plum   { background: #c2a0c4; }

.knit-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 6px;
}
.knit-tile {
  appearance: none; border: none;
  background: var(--cream-deep);
  color: var(--ink);
  font: inherit;
  font-weight: 600;
  text-transform: uppercase;
  font-size: clamp(11px, 3.2vw, 14px);
  letter-spacing: 0.02em;
  border-radius: 10px;
  aspect-ratio: 1 / 1;
  padding: 4px;
  display: grid; place-items: center;
  text-align: center;
  cursor: pointer;
  transition: background 0.12s, color 0.12s, transform 0.08s;
  word-break: break-word;
  hyphens: auto;
  overflow: hidden;
}
.knit-tile.tiny { font-size: clamp(9.5px, 2.6vw, 12px); }
.knit-tile:hover { background: var(--sand); }
.knit-tile.selected {
  background: var(--plum);
  color: #fff;
  transform: scale(0.98);
}

.knit-mistakes {
  display: flex; align-items: center; justify-content: center;
  gap: 10px; margin: 14px 0;
  color: var(--ink-soft); font-size: 14px;
}
.dots { display: inline-flex; gap: 6px; }
.dot {
  width: 10px; height: 10px; border-radius: 999px;
  background: var(--plum); display: inline-block;
}
.dot.spent { background: var(--line); }

.knit-controls {
  display: flex; gap: 8px; justify-content: center; margin-top: 8px;
}

/* ------------------------------------------------------------
   Pollen
   ------------------------------------------------------------ */
.pollen-main {
  padding: 12px;
  max-width: 440px; margin: 0 auto;
  display: grid; gap: 10px;
}
.pollen-tier-row {
  display: flex; align-items: baseline; justify-content: space-between;
}
.tier-name {
  font-family: ui-serif, Georgia, serif; font-weight: 700;
  color: var(--marigold-deep); font-size: 18px;
}
.tier-points { color: var(--ink-soft); font-size: 14px; }
.pollen-tier-bar {
  position: relative;
  height: 6px; border-radius: 999px;
  background: var(--cream-deep);
  overflow: visible;
}
.tier-fill {
  height: 100%; border-radius: 999px;
  background: linear-gradient(90deg, var(--rose), var(--marigold));
  transition: width 0.4s ease;
}
.tier-ticks {
  position: absolute; top: 0; left: 0; right: 0; height: 100%;
}
.tier-tick {
  position: absolute; top: -3px;
  width: 2px; height: 12px;
  background: var(--plum-soft); opacity: 0.5;
  border-radius: 1px;
  transform: translateX(-1px);
}

.pollen-entry {
  text-align: center;
  font-family: ui-serif, Georgia, serif;
  font-weight: 700;
  font-size: clamp(20px, 6vw, 30px);
  min-height: 1.6em;
  letter-spacing: 0.06em;
  color: var(--ink);
}
.pollen-entry .entry-center { color: var(--marigold-deep); }

.pollen-flower {
  display: grid;
  grid-template-columns: repeat(3, 64px);
  grid-template-rows: repeat(3, 64px);
  gap: 6px;
  justify-content: center; align-content: center;
  margin: 8px auto 4px;
}
.petal {
  appearance: none; border: none;
  background: var(--cream-deep);
  color: var(--ink);
  font: inherit;
  font-family: ui-serif, Georgia, serif;
  font-weight: 700;
  text-transform: uppercase;
  font-size: 22px;
  cursor: pointer;
  /* hexagon-ish corners via clip-path */
  clip-path: polygon(25% 5%, 75% 5%, 100% 50%, 75% 95%, 25% 95%, 0% 50%);
}
.petal-center { background: var(--marigold); color: #fff; }
.petal:active { transform: scale(0.95); }
/* arrange six outer petals around center */
.pollen-flower .petal:nth-child(1) { grid-area: 2 / 2; }   /* center */
.pollen-flower .petal:nth-child(2) { grid-area: 1 / 2; }   /* top */
.pollen-flower .petal:nth-child(3) { grid-area: 1 / 3; }   /* upper right */
.pollen-flower .petal:nth-child(4) { grid-area: 2 / 3; }   /* lower right */ /* approximate */
.pollen-flower .petal:nth-child(5) { grid-area: 3 / 2; }   /* bottom */
.pollen-flower .petal:nth-child(6) { grid-area: 2 / 1; }   /* lower left */ /* approximate */
.pollen-flower .petal:nth-child(7) { grid-area: 1 / 1; }   /* upper left */
/* center cell visually overlaps; nudge it slightly */
.pollen-flower .petal-center { transform: scale(1.04); }

.pollen-controls {
  display: flex; gap: 8px; justify-content: center; margin-top: 4px;
}
.pollen-found-wrap {
  margin-top: 8px;
  background: #fff;
  border-radius: var(--radius-sm);
  padding: 8px 12px;
  box-shadow: var(--shadow);
}
.pollen-found-wrap summary {
  cursor: pointer; color: var(--plum); font-weight: 600; padding: 6px 0;
}
.pollen-found {
  list-style: none; margin: 0; padding: 6px 0 4px;
  display: grid; grid-template-columns: 1fr 1fr; gap: 4px 12px;
  font-size: 14px; color: var(--ink-soft);
  max-height: 280px; overflow-y: auto;
}
.pollen-found li.pangram { color: var(--marigold-deep); font-weight: 700; }

/* ------------------------------------------------------------
   Done dialog
   ------------------------------------------------------------ */
.done-dialog {
  border: none; padding: 0;
  border-radius: var(--radius);
  background: #fff;
  box-shadow: 0 24px 64px -16px rgba(58, 47, 41, 0.4);
  max-width: 360px; width: 90%;
}
.done-dialog::backdrop { background: rgba(58, 47, 41, 0.4); }
.done-dialog h2 { margin: 0; padding: 20px 24px 4px; color: var(--marigold-deep); font-size: 22px; }
.done-dialog p { padding: 4px 24px 12px; color: var(--ink-soft); margin: 0; }
.done-dialog .btn, .done-dialog .btn-ghost {
  margin: 4px 12px 12px;
}

/* ------------------------------------------------------------
   Stats
   ------------------------------------------------------------ */
.stats-main {
  padding: 16px;
  max-width: 520px; margin: 0 auto;
}
.stats-summary {
  display: grid; gap: 10px; margin-bottom: 24px;
}
.summary-card {
  background: #fff;
  border-radius: var(--radius);
  padding: 16px 18px;
  box-shadow: var(--shadow);
}
.summary-card h2 {
  margin: 0 0 12px; font-size: 18px; color: var(--plum);
}
.summary-quint h2  { color: var(--sage-deep); }
.summary-knit h2   { color: var(--rose-deep); }
.summary-pollen h2 { color: var(--marigold-deep); }
.stat-grid {
  display: grid; grid-template-columns: repeat(5, 1fr); gap: 4px;
  text-align: center;
}
.stat-grid .big {
  display: block; font-family: ui-serif, Georgia, serif;
  font-weight: 700; font-size: 22px; color: var(--ink);
}
.stat-grid .lab {
  display: block; font-size: 11px; color: var(--ink-muted);
  text-transform: uppercase; letter-spacing: 0.04em;
}

.stats-recent h2 { font-size: 18px; color: var(--plum); margin: 0 0 8px; }
.stats-list { list-style: none; margin: 0; padding: 0; }
.stats-list li {
  display: grid;
  grid-template-columns: 90px 70px 1fr;
  align-items: center;
  padding: 10px 12px;
  border-bottom: 1px solid var(--line);
  font-size: 14px;
}
.r-date { color: var(--ink-muted); font-feature-settings: "tnum"; }
.r-game { color: var(--plum); font-weight: 600; }
.r-score.won { color: var(--sage-deep); }
.r-score.lost { color: var(--rose-deep); }

/* ------------------------------------------------------------
   Tweaks for small phones
   ------------------------------------------------------------ */
@media (max-width: 360px) {
  .quint-row { gap: 5px; }
  .quint-cell { font-size: 22px; }
  .kbd-key { min-height: 44px; }
  .pollen-flower { grid-template-columns: repeat(3, 58px); grid-template-rows: repeat(3, 58px); }
  .petal { font-size: 18px; }
  .tile { grid-template-columns: 72px 1fr; }
}
@media (min-width: 700px) {
  .tiles { grid-template-columns: repeat(3, 1fr); gap: 16px; }
  .tile  { grid-template-columns: 1fr; gap: 8px; padding: 18px; }
  .tile-art { aspect-ratio: 1 / 1; }
}

/* Reduce iOS double-tap zoom on tiles */
button { touch-action: manipulation; }

/* ------------------------------------------------------------
   How-to-play dialog (per-game)
   ------------------------------------------------------------ */
.help-dialog {
  border: none; padding: 0;
  border-radius: var(--radius);
  background: #fff;
  box-shadow: 0 24px 64px -16px rgba(58, 47, 41, 0.4);
  max-width: 380px; width: 92%;
  color: var(--ink);
}
.help-dialog::backdrop { background: rgba(58, 47, 41, 0.45); }
.help-dialog h2 {
  margin: 0; padding: 20px 24px 6px;
  color: var(--marigold-deep);
  font-size: 22px;
}
.help-list {
  list-style: none;
  margin: 0; padding: 4px 24px 16px;
}
.help-list li {
  padding: 8px 0;
  border-bottom: 1px solid var(--line);
  font-size: 15px;
  line-height: 1.45;
  color: var(--ink-soft);
}
.help-list li:last-child { border-bottom: none; }
.help-list strong { color: var(--ink); }
.help-list em { color: var(--plum); font-style: italic; }

/* Inline hint chips inside the help list */
.hint {
  display: inline-block;
  min-width: 22px;
  padding: 1px 8px;
  border-radius: 6px;
  font-weight: 700;
  font-family: ui-serif, Georgia, serif;
  color: #fff;
  text-align: center;
  margin-right: 2px;
}
.hint-hit    { background: var(--sage-deep); }
.hint-near   { background: var(--marigold); }
.hint-miss   { background: var(--plum-soft); }
.hint-center { background: var(--marigold); }

.help-dialog .btn { margin: 4px 24px 20px; }
