/* Grid Works: gallery white, Fraunces for titles, DM Sans for everything else,
   Heidi's emerald for what you've done. Calm: lots of space, nothing shouty. */
:root {
  --ink: #26221e;
  --soft: #7a7166;
  --line: #e4ddd1;
  --paper: #fffdf9;
  --bg: #f6f4ef;
  --wall: #efece6;
  --emerald: #145a5c;
  --emerald-hi: #2e8a87;
  --mine: #1d6b5f;
  --clash: #b5553a;
  --gold: #c9a24a;
  --head: Fraunces, Georgia, "Times New Roman", serif;
  --font: "DM Sans", "Helvetica Neue", Helvetica, Arial, sans-serif;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body {
  margin: 0; height: 100%; background: var(--bg); color: var(--ink); font-family: var(--font);
  overscroll-behavior: none; user-select: none; -webkit-user-select: none; -webkit-touch-callout: none;
}
body { overflow: hidden; }
button { font: inherit; color: inherit; cursor: pointer; touch-action: manipulation; }
.hidden { display: none !important; }

#app { position: relative; height: 100%; max-width: 560px; margin: 0 auto; }
.screen { position: absolute; inset: 0; display: flex; flex-direction: column; padding: calc(var(--safe-top) + 14px) 16px calc(var(--safe-bottom) + 14px); overflow-y: auto; }

/* --- buttons ------------------------------------------------------------------------ */
.btn { border: 1.5px solid var(--ink); background: var(--paper); border-radius: 999px; padding: 0.7em 1.3em; font-weight: 600; font-size: 1rem; }
.btn.big { background: var(--ink); color: var(--paper); }
.btn.ghost { border-color: var(--line); }
.btn.icon { padding: 0.7em 0.9em; }
.btn:active { transform: translateY(1px); }
.row { display: flex; gap: 10px; justify-content: center; flex-wrap: wrap; }
.col { display: flex; flex-direction: column; gap: 10px; }
.link { border: 0; background: none; color: var(--soft); text-decoration: underline; font-size: 0.85rem; padding: 0.2em; }
.count { font-weight: 500; color: var(--soft); }
.icon-btn { border: 0; background: none; font-size: 1.7rem; width: 44px; height: 44px; line-height: 1; border-radius: 50%; color: var(--ink); }

/* --- today ---------------------------------------------------------------------------- */
.poster { display: flex; justify-content: space-between; align-items: flex-start; gap: 12px; padding: 8px 2px 18px; border-bottom: 1px solid var(--line); margin-bottom: 14px; }
.eyebrow { font-size: 0.72rem; letter-spacing: 0.18em; text-transform: uppercase; color: var(--soft); font-weight: 600; }
.logo { font-family: var(--head); font-weight: 600; font-size: 2.6rem; line-height: 1; margin: 0.12em 0 0.18em; letter-spacing: -0.01em; }
.today-date { font-family: var(--head); font-style: italic; font-size: 1.05rem; }
.palette-line { display: flex; align-items: center; gap: 8px; margin-top: 8px; font-size: 0.8rem; color: var(--soft); }
.swatches { display: inline-flex; }
.swatches { box-shadow: 0 0 0 1px var(--line); }
.swatches i { width: 12px; height: 12px; display: inline-block; }
.portrait { width: 96px; height: 96px; border-radius: 50%; background: #e8e2d6; flex: none; }

.levels { display: flex; flex-direction: column; gap: 10px; }
.level { display: grid; grid-template-columns: 64px 1fr auto; gap: 14px; align-items: center; text-align: left; background: var(--paper); border: 1px solid var(--line); border-radius: 14px; padding: 10px 14px 10px 10px; }
.level:active { background: #faf7f1; }
.level .thumb { width: 64px; height: 64px; border-radius: 4px; box-shadow: 0 0 0 3px #fff, 0 0 0 4px #d8d1c4, 0 4px 10px rgba(40, 30, 20, 0.12); background: #f1ece3; display: block; }
.level .thumb.blank { background-image: linear-gradient(var(--line) 1px, transparent 1px), linear-gradient(90deg, var(--line) 1px, transparent 1px); background-size: calc(100% / 3) calc(100% / 3); }
.level .name { font-family: var(--head); font-weight: 600; font-size: 1.25rem; display: flex; align-items: baseline; gap: 8px; }
.level .dots { font-family: var(--font); font-size: 0.7rem; letter-spacing: 2px; color: var(--soft); }
.level .blurb { font-size: 0.82rem; color: var(--soft); margin-top: 2px; line-height: 1.3; }
.level .status { font-size: 0.82rem; font-weight: 600; text-align: right; white-space: nowrap; color: var(--soft); }
.level .status.done { color: var(--mine); }
.level .status small { display: block; font-weight: 500; color: var(--soft); }
.level .another { grid-column: 2 / 4; justify-self: start; margin-top: 2px; }
.home-note { text-align: center; font-family: var(--head); font-style: italic; color: var(--soft); min-height: 1.3em; margin: 16px 0 6px; }
.home-buttons { display: flex; gap: 10px; justify-content: center; margin: 6px 0 14px; }
.family-slot { margin-top: auto; }

/* --- playing ---------------------------------------------------------------------------- */
#play { padding-left: 10px; padding-right: 10px; overflow: hidden; }
.topbar { display: flex; align-items: center; gap: 6px; min-height: 44px; margin-bottom: 6px; }
.topbar.plain { margin-bottom: 10px; }
.top-title { flex: 1; display: flex; flex-direction: column; line-height: 1.15; }
.top-title b { font-family: var(--head); font-size: 1.2rem; font-weight: 600; }
.top-title span { font-size: 0.75rem; color: var(--soft); }
.timer { border: 0; background: none; font-variant-numeric: tabular-nums; font-weight: 600; color: var(--soft); font-size: 0.95rem; min-width: 56px; padding: 8px 4px; }
.timer.off { font-size: 0; }
.timer.off::after { content: '◷'; font-size: 1.1rem; }

.grid-wrap { display: flex; justify-content: center; }
.grid {
  --size: min(calc(100vw - 20px), 540px, calc(100dvh - var(--safe-top) - var(--safe-bottom) - 330px)); /* main.js fits it exactly */
  width: var(--size); height: var(--size); display: grid; grid-template-columns: repeat(9, 1fr); grid-template-rows: repeat(9, 1fr);
  background: var(--paper); border: 2px solid var(--ink); border-radius: 6px; overflow: hidden; touch-action: manipulation;
}
.cell { position: relative; display: flex; align-items: center; justify-content: center; border-right: 1px solid var(--line); border-bottom: 1px solid var(--line); font-size: calc(var(--size) / 9 * 0.56); font-weight: 500; transition: background-color 0.15s; }
.cell:nth-child(9n) { border-right: 0; }
.cell:nth-child(n+73) { border-bottom: 0; }
.cell.br { border-right: 2px solid var(--ink); }
.cell.bb { border-bottom: 2px solid var(--ink); }
.cell.given { font-weight: 700; color: var(--ink); }
.cell.mine { color: var(--mine); }
.cell.peer { background-color: #f1eee8; }
.cell.same { box-shadow: inset 0 0 0 2px rgba(38, 34, 30, 0.35); }
.cell.sel { box-shadow: inset 0 0 0 3px var(--emerald); }
.cell.clash { color: var(--clash); }
.cell.clash::after { content: ''; position: absolute; left: 22%; right: 22%; bottom: 12%; height: 2px; background: var(--clash); border-radius: 1px; }
.cell.wrong { color: var(--clash); }
.cell.hl { background-color: #f7dc8c !important; box-shadow: inset 0 0 0 2px rgba(201, 162, 74, 0.7); }
.cell.hl-cell { box-shadow: inset 0 0 0 3px var(--gold); }
.cell.glow { animation: glow 1.4s ease-in-out infinite; }
.cell.shimmer { animation: shimmer 0.7s ease-out; }
.notes { position: absolute; inset: 2px; display: grid; grid-template-columns: repeat(3, 1fr); grid-template-rows: repeat(3, 1fr); }
.notes span { display: flex; align-items: center; justify-content: center; font-size: calc(var(--size) / 9 * 0.24); font-weight: 600; color: #6f675d; line-height: 1; }
.notes span.on-same { color: var(--paper); background: var(--emerald); border-radius: 3px; }
@keyframes glow { 50% { box-shadow: inset 0 0 0 3px var(--gold), 0 0 0 2px rgba(201, 162, 74, 0.4); } }
@keyframes shimmer { 0% { filter: brightness(1); } 40% { filter: brightness(1.12) saturate(1.3); } 100% { filter: none; } }

.say { display: flex; align-items: center; gap: 10px; height: 92px; margin: 6px 2px 2px; opacity: 0; transition: opacity 0.3s; }
.say.on { opacity: 1; }
.say-face { width: 46px; height: 46px; border-radius: 50%; background: #ece5d8; flex: none; }
.say p { margin: 0; font-size: 0.86rem; line-height: 1.3; background: var(--paper); border: 1px solid var(--line); border-radius: 12px; padding: 7px 11px; max-height: 100%; overflow-y: auto; }
.say.coach p { background: var(--ink); color: var(--paper); border-color: var(--ink); }

.tools { display: grid; grid-template-columns: repeat(4, 1fr); gap: 6px; margin: auto 0 8px; }
.tool { border: 0; background: none; display: flex; flex-direction: column; align-items: center; gap: 2px; font-size: 0.75rem; font-weight: 600; color: var(--soft); padding: 4px 0; border-radius: 10px; }
.tool .tool-ic { font-size: 1.35rem; color: var(--ink); line-height: 1.1; }
.tool i { font-style: normal; font-weight: 700; }
.tool.on { color: var(--emerald); background: #e6f0ec; }
.tool.on .tool-ic { color: var(--emerald); }
.tool.glow, .key.glow { animation: glowbtn 1.4s ease-in-out infinite; }
@keyframes glowbtn { 50% { box-shadow: 0 0 0 3px var(--gold); } }

.pad { display: grid; grid-template-columns: repeat(9, 1fr); gap: 4px; }
.key { position: relative; border: 1px solid var(--line); background: var(--paper); border-radius: 10px; height: min(64px, 10.5dvh); display: flex; flex-direction: column; align-items: center; justify-content: center; padding: 0; font-size: 1.6rem; font-weight: 500; }
.key .sw { position: absolute; left: 22%; right: 22%; bottom: 6px; height: 4px; border-radius: 2px; }
.key .left { position: absolute; top: 3px; right: 5px; font-size: 0.6rem; color: var(--soft); font-weight: 600; }
.key.used { opacity: 0.3; }
.key.notes-mode { font-size: 1.15rem; color: var(--emerald); }
.key:active { background: #f1ece3; }


/* --- the gallery ---------------------------------------------------------------------- */
.gallery-wall { background: var(--wall); }
.finish-inner { display: flex; flex-direction: column; align-items: center; gap: 16px; margin: auto 0; padding: 10px 0; }
.frame { padding: 14px; background: #fff; box-shadow: 0 0 0 1px #ddd6c9, 0 18px 40px rgba(40, 30, 20, 0.18); }
.frame canvas { display: block; }
.wall-label { align-self: stretch; max-width: 340px; margin: 0 auto; border-left: 2px solid #cfc7b8; padding: 2px 0 2px 12px; font-size: 0.88rem; line-height: 1.4; }
.wall-label .artist { font-weight: 700; }
.wall-label .work-title i { font-family: var(--head); font-size: 1.05rem; }
.wall-label .medium { color: var(--soft); }
.finish-score { text-align: center; }
.fin-line { font-size: 0.85rem; color: var(--soft); }
.points { font-family: var(--head); }
.points b { font-size: 2.4rem; font-weight: 600; margin-right: 6px; }
.points span { color: var(--soft); }
.fin-best { font-size: 0.85rem; font-weight: 600; color: var(--mine); min-height: 1.2em; }
.fin-family { font-size: 0.85rem; margin-top: 4px; }
.fin-heidi { font-family: var(--head); font-style: italic; text-align: center; margin: 0; }
#finish .frame, #finish .wall-label, #finish .finish-score, #finish .fin-heidi, #finish .row { animation: rise 0.6s ease-out both; }
#finish .wall-label { animation-delay: 1.5s; }
#finish .finish-score { animation-delay: 1.8s; }
#finish .fin-heidi { animation-delay: 2.1s; }
#finish .row { animation-delay: 2.3s; }
@keyframes rise { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: none; } }

.works-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: 26px 18px; padding: 8px 6px 30px; }
.work-tile { border: 0; background: none; padding: 0; display: flex; flex-direction: column; align-items: center; gap: 10px; }
.work-tile .mini-frame { padding: 7px; background: #fff; box-shadow: 0 0 0 1px #ddd6c9, 0 8px 18px rgba(40, 30, 20, 0.15); }
.work-tile canvas { display: block; }
.work-tile .cap { font-size: 0.72rem; line-height: 1.3; text-align: center; color: var(--soft); }
.work-tile .cap i { font-family: var(--head); color: var(--ink); font-size: 0.85rem; }
.works-empty { text-align: center; color: var(--soft); font-family: var(--head); font-style: italic; margin: 30px 20px; }

/* --- cards over everything --------------------------------------------------------------- */
.modal { position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; background: rgba(246, 244, 239, 0.86); padding: 16px; z-index: 5; backdrop-filter: blur(3px); }
.card { background: var(--paper); border: 1px solid var(--line); border-radius: 18px; padding: 20px 20px 18px; width: 100%; max-width: 420px; box-shadow: 0 16px 40px rgba(40, 30, 20, 0.12); max-height: 100%; overflow-y: auto; }
.card h2 { font-family: var(--head); font-weight: 600; margin: 0 0 10px; font-size: 1.5rem; }
.card p { line-height: 1.45; }
.how-list { padding-left: 18px; margin: 0 0 16px; font-size: 0.92rem; line-height: 1.4; }
.how-list li { margin-bottom: 7px; }
.settings-list { display: flex; flex-direction: column; margin-bottom: 14px; }
.setting { display: flex; justify-content: space-between; align-items: center; gap: 12px; padding: 11px 0; border-bottom: 1px solid var(--line); font-size: 0.95rem; }
.setting small { display: block; color: var(--soft); font-size: 0.78rem; }
.setting input { width: 46px; height: 26px; flex: none; accent-color: var(--emerald); }
.install-how { font-size: 0.95rem; }
.update-note { position: absolute; left: 50%; bottom: calc(var(--safe-bottom) + 10px); transform: translateX(-50%); background: var(--ink); color: var(--paper); font-size: 0.78rem; padding: 6px 12px; border-radius: 999px; white-space: nowrap; z-index: 6; }

/* --- Christmas gift ------------------------------------------------------------------------ */
.gift { position: absolute; inset: 0; z-index: 8; display: flex; align-items: center; justify-content: center; background: rgba(246, 244, 239, 0.94); padding: 20px; font-size: 22px; }
.gift-inner { position: relative; width: 100%; max-width: 420px; display: flex; flex-direction: column; align-items: center; }
.gift-box { position: relative; width: 7em; height: 7em; border: 0; background: none; padding: 0; cursor: pointer; animation: wiggle 2.2s ease-in-out infinite; }
.gift-base, .gift-lid { position: absolute; left: 50%; transform: translateX(-50%); }
.gift-base { bottom: 0; width: 5.6em; height: 4.4em; border-radius: 0.2em; background: linear-gradient(90deg, transparent 44%, var(--gold) 44% 56%, transparent 56%), var(--emerald); }
.gift-lid { bottom: 4.2em; width: 6.2em; height: 1.3em; border-radius: 0.2em; background: linear-gradient(90deg, transparent 44%, var(--gold) 44% 56%, transparent 56%), #0f4a4c; transition: transform 0.8s cubic-bezier(.3, 1.4, .5, 1), opacity 0.6s 0.2s; }
.gift-lid::before, .gift-lid::after { content: ""; position: absolute; bottom: 100%; width: 1.4em; height: 1.1em; border: 0.2em solid var(--gold); border-radius: 50% 50% 0 50%; }
.gift-lid::before { left: 1.6em; transform: rotate(-20deg); }
.gift-lid::after { right: 1.6em; transform: scaleX(-1) rotate(-20deg); }
.gift-tag { position: absolute; left: 50%; top: 100%; transform: translateX(-50%); margin-top: 0.7em; white-space: nowrap; font-family: var(--head); font-style: italic; font-size: 0.8em; color: var(--ink); }
.gift-card { display: none; background: var(--paper); border: 1px solid var(--line); border-radius: 0.8em; box-shadow: 0 0.4em 1.4em rgba(60, 45, 30, 0.12); padding: 1em 1.1em 1.2em; text-align: center; width: 100%; }
.gift-card h2 { font-family: var(--head); font-weight: 600; margin: 0 0 0.4em; font-size: 1.4em; line-height: 1.1; }
.gift-card p { margin: 0.45em 0; font-size: 0.8em; line-height: 1.45; }
.gift-card .gift-signature { margin-top: 0.8em; font-family: var(--head); font-style: italic; font-size: 0.9em; color: var(--emerald); }
.gift-card .btn { margin-top: 0.8em; font-size: 0.8em; }
.gift.open .gift-box { animation: none; cursor: default; height: 4.6em; margin-bottom: 0.6em; transition: height 0.4s 0.4s; }
.gift.open .gift-lid { transform: translate(-50%, -4em) rotate(-18deg); opacity: 0; }
.gift.open .gift-tag { display: none; }
.gift.open .gift-card { display: block; animation: rise 0.6s 0.35s ease-out both; }
@keyframes wiggle { 0%, 75%, 100% { transform: rotate(0); } 80% { transform: rotate(-4deg); } 88% { transform: rotate(4deg); } 94% { transform: rotate(-2deg); } }

/* short phones: a tighter pad */
@media (max-height: 700px) {
  .say { height: 84px; margin: 4px 2px 2px; }
  .say-face { width: 38px; height: 38px; }
  .tool { font-size: 0.7rem; }
}
