:root {
  --bg: #ffffff;
  --fg: #121212;
  --muted: #5a5a5a;
  --line: #dcdcdc;
  --sel: #dbd8c5;
  --theme: #aedfee;
  --span: #f8cd05;
  --hint: #121212;
  --label: #aedfee;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #121213;
    --fg: #f2f2f2;
    --muted: #a5a5a5;
    --line: #3a3a3c;
    --sel: #57544a;
    --theme: #2f7c97;
    --span: #b8970a;
    --hint: #f2f2f2;
    --label: #2f7c97;
  }
}
* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); color: var(--fg); }
body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  -webkit-tap-highlight-color: transparent;
  min-height: 100dvh;
}
button { font: inherit; color: inherit; cursor: pointer; }

.top {
  display: flex; align-items: center; justify-content: space-between;
  padding: 8px 16px; border-bottom: 1px solid var(--line);
}
.top h1 { margin: 0; font-size: 1.6rem; letter-spacing: .02em; font-family: Georgia, "Times New Roman", serif; }
.icon {
  width: 36px; height: 36px; border-radius: 50%; border: 2px solid var(--fg);
  background: none; font-weight: 700; font-size: 1rem; line-height: 1;
}

main { max-width: 440px; margin: 0 auto; padding: 10px 16px 24px; }

.theme { border: 1px solid var(--line); border-radius: 8px; overflow: hidden; text-align: center; }
.theme-label { background: var(--label); font-size: .78rem; font-weight: 700; letter-spacing: .12em; padding: 4px; }
.theme-clue { font-size: 1.2rem; font-weight: 700; padding: 8px; }

.current {
  height: 2.6rem; display: flex; align-items: center; justify-content: center;
  font-size: 1.7rem; font-weight: 700; letter-spacing: .04em; text-transform: uppercase;
}

.board-wrap { width: 100%; max-width: min(360px, calc((100dvh - 270px) * 0.75)); margin: 0 auto; }
.board {
  position: relative; display: grid;
  grid-template-columns: repeat(6, 1fr); grid-template-rows: repeat(8, 1fr);
  aspect-ratio: 6 / 8; width: 100%;
  touch-action: none; user-select: none; -webkit-user-select: none;
}
#lines { position: absolute; inset: 0; width: 100%; height: 100%; pointer-events: none; z-index: 0; }
.cell {
  position: relative; z-index: 1; display: flex; align-items: center; justify-content: center;
  font-size: clamp(1.3rem, 6.5vw, 1.85rem); font-weight: 500;
}
.cell span {
  width: 78%; aspect-ratio: 1; border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  border: 2px solid transparent; transition: background .12s;
}
.cell.sel span { background: var(--sel); }
.cell.found span { background: var(--theme); }
.cell.span span { background: var(--span); }
.cell.hinted span { border: 2px dashed var(--hint); }
.cell.flash span { animation: pop .35s ease; }
@keyframes pop { 50% { transform: scale(1.15); } }

.bar { display: flex; align-items: center; justify-content: space-between; margin-top: 14px; gap: 12px; }
.hint {
  border: 2px solid var(--fg); border-radius: 999px; background: none;
  padding: 10px 26px; font-weight: 600;
}
.hint:disabled { opacity: .4; cursor: default; }
.progress { font-size: 1rem; text-align: right; }
.progress b { font-weight: 800; }
.date { text-align: center; color: var(--muted); font-size: .85rem; margin: 14px 0 0; }

dialog {
  border: none; border-radius: 12px; padding: 20px 22px; max-width: min(92vw, 400px);
  background: var(--bg); color: var(--fg); box-shadow: 0 10px 40px rgba(0,0,0,.25);
}
dialog::backdrop { background: rgba(0,0,0,.45); }
dialog h2 { margin-top: 0; font-family: Georgia, serif; }
dialog ul { padding-left: 1.1rem; line-height: 1.45; }
dialog form { margin: 0; }
.sp { background: var(--span); padding: 0 4px; border-radius: 4px; color: #121212; }
.primary, dialog button {
  border: 2px solid var(--fg); border-radius: 999px; padding: 10px 22px; background: none; font-weight: 600;
}
.primary { background: var(--fg); color: var(--bg); }
.row { display: flex; gap: 10px; justify-content: center; margin-top: 12px; }
.emoji { font-size: 1.6rem; text-align: center; line-height: 1.5; letter-spacing: .1em; }
.done-clue { text-align: center; font-weight: 700; }
.small { text-align: center; color: var(--muted); font-size: .85rem; }
#done-stats { text-align: center; }
.archive { list-style: none; padding: 0; max-height: 50vh; overflow: auto; }
.archive a { display: block; padding: 10px 4px; border-bottom: 1px solid var(--line); color: inherit; text-decoration: none; }
.archive a.today { font-weight: 700; }

.toast {
  position: fixed; left: 50%; top: 84px; transform: translateX(-50%);
  background: var(--fg); color: var(--bg); padding: 8px 14px; border-radius: 6px; font-weight: 600;
  opacity: 0; transition: opacity .2s; pointer-events: none; z-index: 10;
}
.toast.show { opacity: 1; }

/* ---------- mòbil ---------- */
body { touch-action: manipulation; overscroll-behavior-y: none; }
.top { padding-top: max(8px, env(safe-area-inset-top)); padding-left: max(16px, env(safe-area-inset-left)); padding-right: max(16px, env(safe-area-inset-right)); }
main { padding-bottom: max(24px, env(safe-area-inset-bottom)); }
dialog { max-height: 88dvh; overflow-y: auto; overscroll-behavior: contain; }
a { color: inherit; }

.credit { text-align: center; color: var(--muted); font-size: .8rem; margin: 6px 0 0; }
.credit a, .small a { color: inherit; text-underline-offset: 2px; }

/* ---------- demostració ---------- */
.demo { margin: 6px auto 4px; width: min(220px, 70%); }
.demo-word {
  height: 1.8rem; text-align: center; font-weight: 700; font-size: 1.15rem; letter-spacing: .05em;
}
.demo-word.ok { color: var(--muted); }
.demo-board {
  position: relative; display: grid; aspect-ratio: 4 / 3;
  grid-template-columns: repeat(4, 1fr); grid-template-rows: repeat(3, 1fr);
}
.demo-board svg { position: absolute; inset: 0; width: 100%; height: 100%; pointer-events: none; }
.demo-board .cell { font-size: 1.15rem; }
.demo-board .cell.found span { animation: pop .35s ease; }
.demo-board .finger { fill: var(--fg); opacity: .18; }

.install { border: 1px dashed var(--line); border-radius: 8px; padding: 6px 12px 12px; margin-bottom: 12px; text-align: center; }
.install p { margin: 8px 0; font-size: .92rem; }
