/* Patchvale (was Hearth Tiles) v2 prototype.
 * Concept: a valley painted in daylight. Outdoors and soft, the opposite of Settled In's
 * architect's plan: the land is the only colour, textured (furrowed fields, rippled water,
 * round canopies, tiny houses with chimneys) and slightly wobbly through one SVG filter.
 * Around it, ink on pale mist, hairline rules, no boxes, no shadows.
 * At the end of a day the light goes golden, the water glints and the chimneys smoke.
 *
 * PALETTE IS A PROPOSAL / PLACEHOLDER, not final:
 *   mist #eef1ec  ink #22302b  muted #5e6b64  rule #cdd4cc
 *   field #e8dc9a  forest #5b8a55 (canopy #3f6e43)  water #6aa7c6  road #a07f58
 *   village earth #eadfc6, walls #f7f2e6, roofs #b85a41   evening gold #ffcf70
 */
:root {
  --mist: #eef1ec; --ink: #22302b; --muted: #5e6b64; --rule: #cdd4cc;
  --field: #e8dc9a; --forest: #5b8a55; --water: #6aa7c6; --road: #a07f58; --roof: #b85a41;
  --gold: #ffcf70; --good: #3a7a3f; --warn: #a2522f;
  font: 16px/1.45 ui-rounded, "SF Pro Rounded", system-ui, sans-serif;
  color: var(--ink); background: var(--mist);
}
* { box-sizing: border-box; }
body { margin: 0; min-height: 100vh; display: flex; flex-direction: column; }
.defs { position: absolute; width: 0; height: 0; overflow: hidden; }

.bar { display: flex; align-items: baseline; gap: 1rem; padding: .75rem 1.25rem; border-bottom: 1px solid var(--rule); }
.bar h1 { font-size: 1.15rem; margin: 0; font-weight: 700; }
.date { color: var(--muted); }
.spacer { flex: 1; }
button.tally { border: 0; padding: 0; background: none; color: var(--ink); cursor: default; }
button.tally.done { cursor: pointer; }
button.tally:hover { background: none; color: var(--ink); }
.tally b { font-size: 1.3rem; font-variant-numeric: tabular-nums; }
.vs { color: var(--muted); margin: 0 .25rem; }
.legal { color: var(--muted); font-size: .85rem; white-space: nowrap; }
.legal a { color: inherit; text-underline-offset: 3px; }

main { flex: 1; display: grid; grid-template-columns: 1fr 19.5rem; min-height: 0; }
.stage { position: relative; overflow: hidden; }
#board { width: 100%; height: calc(100vh - 3.4rem); display: block; touch-action: manipulation; }
aside { border-left: 1px solid var(--rule); padding: 1rem 1.25rem; overflow: auto; max-height: calc(100vh - 3.4rem); }
aside section { padding-bottom: .9rem; margin-bottom: .9rem; border-bottom: 1px solid var(--rule); }
aside section:last-child { border-bottom: 0; }
h2 { font-size: 1rem; margin: 0 0 .5rem; }

.now { display: flex; align-items: center; gap: .75rem; }
#nowTile { width: 8.5rem; height: 8.5rem; }
.rot { display: flex; flex-direction: column; gap: .4rem; }
.next { display: flex; align-items: center; gap: .5rem; margin-top: .5rem; }
.next svg { width: 3.4rem; height: 3.4rem; }
.lbl { color: var(--muted); font-size: .9rem; }
.breakdown { margin: 0 0 .2rem; font-variant-numeric: tabular-nums; }
.breakdown b { font-size: 1.05rem; }
#closedList { margin: 0; }

button { font: inherit; color: var(--ink); background: none; border: 1px solid var(--ink); border-radius: 3px; padding: .3rem .8rem; cursor: pointer; }
button:hover { background: var(--ink); color: var(--mist); }
.rot button { font-size: 1.3rem; padding: .1rem .6rem; }
button.link { border: 0; padding: 0; text-decoration: underline; text-underline-offset: 3px; }
button.link:hover { background: none; color: var(--muted); }
a.button { color: var(--ink); border: 1px solid var(--ink); border-radius: 3px; padding: .3rem .8rem; text-decoration: none; }
a.button:hover { background: var(--ink); color: var(--mist); }
#accountBtn { white-space: nowrap; }

/* goals: live progress, met in green, out of reach struck through with a reason */
.goals { margin: 0; padding-left: 1.2rem; }
.goals li { margin-bottom: .55rem; }
.goals .gv { color: var(--muted); font-variant-numeric: tabular-nums; white-space: nowrap; }
.goals .track { display: block; height: 3px; background: var(--rule); margin-top: .25rem; }
.goals .track i { display: block; height: 100%; background: var(--ink); transition: width .3s; }
.goals li.met { color: var(--good); }
.goals li.met .gv { color: var(--good); }
.goals li.met .track i { background: var(--good); }
.goals li.dead .gt { text-decoration: line-through; color: var(--muted); }
.goals .warn { display: block; color: var(--warn); font-size: .85rem; }

.help p { margin: 0 0 .5rem; font-size: .9rem; color: var(--muted); }
kbd { font: inherit; border: 1px solid var(--rule); padding: 0 .3rem; border-radius: 3px; }
.key { display: flex; flex-wrap: wrap; gap: .2rem .5rem; align-items: center; }
.sw { display: inline-block; width: .8rem; height: .8rem; vertical-align: -1px; }
.sw.field { background: var(--field); } .sw.forest { background: var(--forest); } .sw.water { background: var(--water); }
.sw.road { background: var(--road); } .sw.village { background: var(--roof); }

/* ---- board ---- */
.cand { fill: transparent; stroke: #b9c2b8; stroke-width: 1.2; stroke-dasharray: 3 3; cursor: pointer; }
.cand:hover { stroke: var(--ink); }
.ghost { opacity: .85; pointer-events: none; }
.delta { font: 700 15px ui-rounded, system-ui, sans-serif; fill: var(--ink); paint-order: stroke; stroke: var(--mist); stroke-width: 4px; pointer-events: none; }
.delta.small { font-size: 11px; font-weight: 600; }
.hexline { fill: none; stroke: #f4f2e6; stroke-opacity: .55; stroke-width: 1; }
.match { fill: var(--ink); }
.seam { stroke: #c0563e; stroke-width: 2.2; stroke-linecap: round; }
.vseam { stroke: #e2a92b; stroke-width: 3; stroke-linecap: round; fill: none; opacity: .4; }
.smoke { fill: #8f9188; opacity: 0; } /* grey puff: white vanished against the cream walls */
.sun { fill: var(--gold); opacity: 0; mix-blend-mode: multiply; pointer-events: none; }

/* ---- the end moment: light goes golden, water glints, chimneys smoke ---- */
.alive .sun { animation: dusk 1.6s ease-out forwards; }
.alive .glint { animation: glint 1.4s ease-in-out 2; }
.alive .smoke { transform-box: fill-box; transform-origin: center; animation: smoke 2.6s ease-out infinite; }
/* staggered starts as classes, not style attributes (the CSP blocks those) */
.glint.d1 { animation-delay: .12s; } .glint.d2 { animation-delay: .24s; } .glint.d3 { animation-delay: .36s; } .glint.d4 { animation-delay: .48s; }
.smoke.d1 { animation-delay: .33s; } .smoke.d2 { animation-delay: .66s; } .smoke.d3 { animation-delay: .99s; }
.smoke.d4 { animation-delay: 1.32s; } .smoke.d5 { animation-delay: 1.65s; } .smoke.d6 { animation-delay: 1.98s; }
@keyframes dusk { to { opacity: .3; } }
@keyframes glint { 50% { stroke: #fffbe8; stroke-width: 2.4; } }
@keyframes smoke {
  0% { opacity: 0; transform: translate(0, 0) scale(.7); }
  20% { opacity: .8; }
  100% { opacity: 0; transform: translate(5px, -24px) scale(2.6); }
}

/* view bar (when showing another board) */
.viewbar { position: absolute; left: 1.25rem; top: .9rem; background: var(--mist); padding: .2rem .5rem; border-left: 2px solid var(--ink); }

/* ---- result card: slides up over the sidebar, so the finished land stays in full view ---- */
main { position: relative; }
.card {
  position: absolute; right: 0; top: 0; bottom: 0; width: 19.5rem; overflow: auto;
  background: var(--mist); border-left: 1px solid var(--rule); border-top: 3px solid var(--ink);
  padding: 1rem 1.25rem 1.1rem; animation: slideup .45s cubic-bezier(.2, .8, .2, 1);
}
.card.won { border-top-color: #d99a1c; }
@keyframes slideup { from { transform: translateY(115%); opacity: 0; } }
.verdict { margin: 0; font-weight: 700; font-size: 1.15rem; }
.card.won .verdict::before { content: "★ "; color: #d99a1c; }
.big { margin: .15rem 0 .1rem; display: flex; align-items: baseline; gap: .7rem; }
#cScore { font-size: 3rem; font-weight: 700; line-height: 1; font-variant-numeric: tabular-nums; }
.vsm { color: var(--muted); }
.vsm b { color: var(--ink); }
.tries { margin: 0 0 .4rem; color: var(--muted); }
.tries .newbest { color: #a06d0c; font-weight: 700; }
#cTable { border-collapse: collapse; width: 100%; margin: .2rem 0 .6rem; font-variant-numeric: tabular-nums; font-size: .92rem; }
#cTable td { padding: .15rem 0; border-bottom: 1px solid var(--rule); }
#cTable td:last-child { text-align: right; }
#cTable tr.miss td { color: var(--muted); }
pre { margin: 0 0 .7rem; border-left: 2px solid var(--rule); padding: .15rem .8rem; font: .9rem/1.5 ui-monospace, monospace; white-space: pre-wrap; }
.row { display: flex; gap: .9rem; align-items: center; flex-wrap: wrap; }

dialog { border: 1px solid var(--ink); border-radius: 4px; background: var(--mist); color: var(--ink); padding: 1.25rem 1.5rem; width: 94vw; max-width: 70rem; }
dialog.small { max-width: 28rem; }
dialog.small h2 { margin-top: 0; }
dialog.small a { color: var(--ink); text-underline-offset: 3px; }
.promo:empty { display: none; }
dialog::backdrop { background: rgb(34 48 43 / .35); }
#valleySvg { width: 100%; height: 60vh; display: block; border-top: 1px solid var(--rule); border-bottom: 1px solid var(--rule); margin-bottom: .8rem; }
/* valley: one landscape. A blurred shore under everything, the selected day outlined on hover */
dialog#valley { position: fixed; }
.shore { fill: #d6dcc4; filter: blur(7px); }
.vhi { fill: rgb(255 255 255 / .18); stroke: var(--ink); stroke-width: 2; stroke-linejoin: round; pointer-events: none; }
.vtip { position: absolute; pointer-events: none; background: var(--mist); border-left: 2px solid var(--ink); padding: .15rem .5rem; font-size: .9rem; white-space: nowrap; }

@media (prefers-reduced-motion: reduce) {
  .card { animation: none; }
  .alive .sun { animation: none; opacity: .3; }
  .alive .glint, .alive .smoke { animation: none; }
  .goals .track i { transition: none; }
}

@media (max-width: 760px) {
  .bar { flex-wrap: wrap; gap: .1rem .75rem; padding: .6rem 1rem; }
  .bar h1, .tally, .date { white-space: nowrap; }
  #valleyBtn { order: 5; }
  .legal { order: 6; }
  #accountBtn { order: 5; }
  /* One screen, no scrolling: the board takes whatever height the header and the compact panel
     below it leave. dvh so the phone's browser bars don't push the panel off the bottom. */
  body { height: 100vh; height: 100dvh; min-height: 0; }
  main { grid-template-columns: 1fr; grid-template-rows: minmax(0, 1fr) auto; }
  .stage { min-height: 0; }
  #board { height: 100%; }
  aside { border-left: 0; border-top: 1px solid var(--rule); max-height: none; overflow: visible; padding: .5rem 1rem .4rem; }
  aside section { padding-bottom: .4rem; margin-bottom: .4rem; }
  /* the tile in hand, its turn buttons and what comes next, all in one row */
  .stack { display: flex; align-items: center; gap: 1rem; }
  #nowTile { width: 4.6rem; height: 4.6rem; }
  .rot { flex-direction: row; }
  .next { margin-top: 0; }
  .next svg { width: 2.6rem; height: 2.6rem; }
  #left { white-space: nowrap; }
  h2 { margin-bottom: .3rem; }
  .goals li { margin-bottom: .3rem; }
  .help { display: none; }
  aside section:nth-last-child(2) { border-bottom: 0; margin-bottom: 0; }
  .card { position: fixed; left: 0; right: 0; top: auto; bottom: 0; width: auto; max-height: 72vh; border-left: 0; }
}
