:root {
  --bg: #f6f1e7;
  --surface: #fffcf5;
  --ink: #2b2620;
  --muted: #7d7366;
  --line: #dcd2c1;
  --key: #e8e0d0;
  --on-color: #fffcf5;
  --correct: #279747;
  --present: #e0aa0a; /* light enough that its letters are dark, not white */
  --absent: #737985;
  /* Nessi groups, easiest to hardest (saffron, rose, olive, slate blue); light enough for dark text in both themes. */
  --q0: #f0c75e;
  --q1: #e28f95;
  --q2: #b3bd73;
  --q3: #9aaccf;
  --band-ink: #1f1a14;
  --found: #a7d4cc;
  --span: #efc552; /* Intreccio's spanning word and hint; bright enough for dark letters in both themes */
  --select: #ddd1bc;
  --serif: ui-serif, "Iowan Old Style", "Palatino Linotype", Georgia, serif;
  --sans: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  color-scheme: light dark;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #1c1a17;
    --surface: #262320;
    --ink: #eee7da;
    --muted: #a59b8d;
    --line: #3d3831;
    --key: #3a352e;
    --on-color: #fffcf5;
    --correct: #279747;
    --absent: #474c55;
    --found: #3f7c73;
    --select: #4c453b;
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; }

body {
  background: var(--bg);
  color: var(--ink);
  font-family: var(--sans);
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  -webkit-tap-highlight-color: transparent;
}

button { font: inherit; color: inherit; cursor: pointer; }
code { font-size: .95em; }

/* Header, footer, messages */

.bar {
  display: grid;
  grid-template-columns: 2rem 1fr auto auto;
  align-items: center;
  gap: .5rem;
  padding: .7rem 1rem;
  border-bottom: 1px solid var(--line);
}
.bar h1 { font-family: var(--serif); font-size: 1.35rem; margin: 0; }
.back { color: var(--ink); text-decoration: none; font-size: 2rem; line-height: 1; margin-top: -.2rem; }
.bar #date { color: var(--muted); font-size: .85rem; }
.icon-btn {
  display: grid;
  place-items: center;
  width: 2.25rem;
  height: 2.25rem;
  margin-right: -.4rem;
  padding: 0;
  border: 0;
  border-radius: .5rem;
  background: none;
}
.icon-btn svg { width: 1.3rem; height: 1.3rem; fill: var(--ink); }

main {
  flex: 1;
  width: 100%;
  max-width: 32rem;
  margin: 0 auto;
  padding: 1rem;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 1rem;
}

footer { text-align: center; color: var(--muted); font-size: .75rem; padding: .5rem 1rem 1rem; }
footer button { background: none; border: 0; padding: 0; color: inherit; text-decoration: underline; }

#toast {
  position: fixed;
  top: 4.25rem;
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: .5rem;
  z-index: 10;
  pointer-events: none;
  width: max-content;
  max-width: calc(100vw - 2rem);
}
.toast {
  background: var(--ink);
  color: var(--bg);
  padding: .6rem 1rem;
  border-radius: .5rem;
  font-weight: 600;
  font-size: .9rem;
  text-align: center;
  animation: toast 1.8s ease forwards;
}
@keyframes toast {
  0% { opacity: 0; transform: translateY(-.25rem); }
  8%, 85% { opacity: 1; transform: none; }
  100% { opacity: 0; }
}

/* On a phone the board and keyboard fill the screen, so Parole shows messages as a banner over its header. */
.bar { position: relative; }
.bar #toast { position: absolute; inset: 0; transform: none; width: auto; max-width: none; }
.bar .toast { display: grid; place-items: center; width: 100%; height: 100%; border-radius: 0; font-size: 1rem; }

.empty { color: var(--muted); margin-top: 3rem; }
.hint { color: var(--muted); margin: 0; font-size: .9rem; }

.actions { display: flex; gap: .5rem; justify-content: center; flex-wrap: wrap; }
.btn {
  border: 1.5px solid var(--ink);
  background: transparent;
  border-radius: 999px;
  padding: .55rem 1.1rem;
  font-weight: 600;
}
.btn.primary { background: var(--ink); color: var(--bg); }
.btn:disabled { opacity: .35; cursor: default; }

.shake { animation: shake .35s; }
@keyframes shake {
  20%, 60% { transform: translateX(-5px); }
  40%, 80% { transform: translateX(5px); }
}
@keyframes pop {
  50% { transform: scale(1.08); }
}

/* Home */

.home-head { text-align: center; padding: 2.5rem 1rem .5rem; }
.home-head h1 { font-family: var(--serif); font-size: 2.2rem; margin: 0; }
.home-head p { color: var(--muted); margin: .3rem 0 0; }

.cards { display: grid; gap: .9rem; width: 100%; }
.card {
  display: grid;
  grid-template-columns: 3.25rem 1fr;
  column-gap: 1rem;
  row-gap: .2rem;
  align-items: center;
  padding: 1.1rem 1.2rem;
  border: 1px solid var(--line);
  border-radius: 1rem;
  background: var(--surface);
  color: inherit;
  text-decoration: none;
  transition: transform .15s;
}
.card:hover { transform: translateY(-2px); }
.card .icon { grid-row: span 3; width: 100%; }
.card h2 { font-family: var(--serif); font-size: 1.3rem; margin: 0; }
.card p { margin: 0; color: var(--muted); font-size: .9rem; }
.card .status { font-size: .75rem; font-weight: 700; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); }
.card.done .status { color: var(--correct); }

/* Parole */

.board {
  display: grid;
  gap: .35rem;
  width: min(100%, 22rem, calc((100dvh - 20rem) * .83));
}
.row { display: grid; grid-template-columns: repeat(5, 1fr); gap: .35rem; }
.tile {
  aspect-ratio: 1;
  display: grid;
  place-items: center;
  font-family: var(--serif);
  font-weight: 700;
  font-size: clamp(1.3rem, 7vw, 1.9rem);
  text-transform: uppercase;
  border: 2px solid var(--line);
  border-radius: .45rem;
  background: var(--surface);
}
.tile.filled { border-color: var(--muted); animation: pop .1s; }
.tile.correct, .tile.present, .tile.absent { color: var(--on-color); border-color: transparent; }
.tile.correct { background: var(--correct); }
.tile.present { background: var(--present); color: var(--band-ink); }
.tile.absent { background: var(--absent); }
.tile.flip { animation: flip .5s ease both; }
@keyframes flip {
  50% { transform: rotateX(90deg); }
}

.keyboard { width: 100%; display: flex; flex-direction: column; gap: .4rem; margin-top: auto; }
.krow { display: flex; gap: .3rem; justify-content: center; }
.key {
  flex: 1;
  max-width: 2.7rem;
  height: 3.3rem;
  padding: 0;
  border: 0;
  border-radius: .4rem;
  background: var(--key);
  font-weight: 700;
  font-size: 1rem;
  text-transform: uppercase;
  touch-action: manipulation;
  user-select: none;
}
.key.wide { flex: 1.6; max-width: 4.3rem; font-size: .72rem; }
.key.correct, .key.present, .key.absent { color: var(--on-color); }
.key.correct { background: var(--correct); }
.key.present { background: var(--present); color: var(--band-ink); }
.key.absent { background: var(--absent); }

/* Nessi */

.groups { display: flex; flex-direction: column; gap: .5rem; width: 100%; }
.groups:empty { display: none; }
.band {
  border-radius: .6rem;
  padding: .65rem;
  text-align: center;
  text-transform: uppercase;
  color: var(--band-ink);
  animation: pop .25s;
}
.band strong { display: block; font-size: .9rem; letter-spacing: .03em; }
.band span { font-size: .85rem; }
.band.missed { opacity: .65; }
.l0 { background: var(--q0); }
.l1 { background: var(--q1); }
.l2 { background: var(--q2); }
.l3 { background: var(--q3); }

.grid4 { display: grid; grid-template-columns: repeat(4, 1fr); gap: .5rem; width: 100%; }
.grid4:empty { display: none; }
.word {
  height: 4.5rem;
  padding: .2rem;
  border: 0;
  border-radius: .6rem;
  background: var(--key);
  font-weight: 700;
  font-size: clamp(.68rem, 3.3vw, .95rem);
  text-transform: uppercase;
  overflow-wrap: anywhere;
  touch-action: manipulation;
  user-select: none;
  transition: background .1s, color .1s;
}
.word.sel { background: var(--ink); color: var(--bg); }

.mistakes { display: flex; gap: .4rem; align-items: center; color: var(--muted); font-size: .9rem; }
.dot { width: .75rem; height: .75rem; border-radius: 50%; background: var(--ink); }
.dot.used { background: var(--line); }

/* Intreccio */

.theme { text-align: center; }
.theme small { display: block; color: var(--muted); text-transform: uppercase; letter-spacing: .08em; font-size: .7rem; font-weight: 700; }
.theme strong { font-family: var(--serif); font-size: 1.35rem; }
.current { min-height: 1.8rem; font-weight: 700; letter-spacing: .12em; font-size: 1.3rem; }
.current.msg { letter-spacing: normal; font-size: 1.05rem; color: var(--muted); padding-top: .2rem; }

.tgrid {
  position: relative;
  display: grid;
  grid-template-columns: repeat(6, 1fr);
  width: min(100%, 22rem, calc((100dvh - 18rem) * .75));
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
}
.tgrid svg { position: absolute; inset: 0; width: 100%; height: 100%; pointer-events: none; }
.tgrid polyline { fill: none; stroke-width: .3; stroke-linecap: round; stroke-linejoin: round; }
.cell {
  aspect-ratio: 1;
  display: grid;
  place-items: center;
  position: relative;
  z-index: 1;
  font-weight: 700;
  font-size: clamp(1.05rem, 5.2vw, 1.4rem);
  cursor: pointer;
}
.cell span { width: 76%; aspect-ratio: 1; border-radius: 50%; display: grid; place-items: center; }
.cell.sel span { background: var(--select); }
.cell.found span { background: var(--found); }
.cell.span span { background: var(--span); color: var(--band-ink); }
.tgrid .sel { stroke: var(--select); }
.tgrid .found { stroke: var(--found); }
.tgrid .span { stroke: var(--span); }

/* Hints: the circled letters of a theme word; a second hint adds a dashed thread from its first letter. */
.cell.clue span { outline: 2px dashed var(--ink); outline-offset: 1px; }
.cell.clue:not(.sel) span { background: var(--bg); } /* hides the thread behind the letters */
.cell.clue-start span { outline-style: solid; }
.tgrid polyline.clue { stroke: var(--muted); stroke-width: .07; stroke-dasharray: .12 .1; }

/* The word count and the hint button share one row under the grid. */
.tw-bar { display: flex; flex-wrap: wrap; align-items: center; justify-content: center; gap: .5rem 1rem; }

/* Hint button: a bar along its bottom edge grows as non-theme words are found; the whole button fills once a hint is ready. */
.meter { position: relative; overflow: hidden; isolation: isolate; min-width: 7rem; }
.meter-fill {
  position: absolute;
  inset: auto 0 0;
  height: .3rem;
  z-index: -1;
  background: var(--span);
  transform: scaleX(var(--fill, 0));
  transform-origin: left;
  transition: transform .3s ease-out;
}
.meter:disabled { opacity: 1; color: var(--muted); border-color: var(--line); }
.meter:not(:disabled) { color: var(--band-ink); border-color: var(--span); }
.meter:not(:disabled) .meter-fill { height: 100%; }
@media (prefers-reduced-motion: reduce) { .meter-fill { transition: none; } }

[hidden] { display: none !important; }

/* Archive */

a.btn { color: var(--ink); text-decoration: none; margin-top: .5rem; }

.days { list-style: none; margin: 0; padding: 0; width: 100%; }
.day {
  display: grid;
  grid-template-columns: 1fr repeat(3, 4.75rem);
  align-items: center;
  width: 100%;
  border-bottom: 1px solid var(--line);
}
.day-head { border: 0; margin-bottom: -.75rem; }
.day-head span { text-align: center; font-size: .7rem; font-weight: 700; color: var(--muted); }
.day-date { font-weight: 600; font-size: .95rem; }
.slot { display: grid; place-items: center; height: 3rem; text-decoration: none; }
.mark {
  display: inline-grid;
  place-items: center;
  width: 1.75rem;
  height: 1.75rem;
  border-radius: 50%;
  border: 2px solid var(--line);
  color: var(--on-color);
  font-size: .85rem;
  font-weight: 700;
  vertical-align: middle;
}
.mark.none { border-color: transparent; color: var(--muted); }
.solved .mark, .mark.solved { background: var(--correct); border-color: var(--correct); }
.missed .mark, .mark.missed { background: var(--absent); border-color: var(--absent); }
.playing .mark, .mark.playing { border-color: var(--present); background: linear-gradient(90deg, var(--present) 50%, transparent 0); }
.legend { color: var(--muted); font-size: .8rem; display: flex; align-items: center; gap: .4rem; flex-wrap: wrap; justify-content: center; }
.legend .mark { width: 1.1rem; height: 1.1rem; font-size: .6rem; margin-left: .4rem; }

/* Statistics dialog */

dialog.stats {
  width: min(24rem, calc(100vw - 2rem));
  padding: 0;
  border: 0;
  border-radius: 1rem;
  background: var(--surface);
  color: var(--ink);
  box-shadow: 0 1.5rem 4rem rgb(0 0 0 / .3);
}
dialog.stats[open] { animation: rise .25s ease-out; }
dialog.stats::backdrop { background: rgb(28 26 23 / .5); }
@keyframes rise {
  from { opacity: 0; transform: translateY(1rem); }
}
.stats-body { position: relative; padding: 1.75rem 1.25rem 1.5rem; text-align: center; }
.stats-body:focus { outline: none; } /* focused on open so the close button shows no ring */
.stats .close {
  position: absolute;
  top: .4rem;
  right: .4rem;
  width: 2.75rem;
  height: 2.75rem;
  border: 0;
  background: none;
  color: var(--muted);
  font-size: 1.75rem;
  line-height: 1;
}
.stats .headline { font-family: var(--serif); font-size: 1.4rem; font-weight: 700; margin: 0 2rem 1.25rem; }
.stats h2, .stats h3 { margin: 0 0 .75rem; color: var(--muted); font-size: .72rem; letter-spacing: .08em; text-transform: uppercase; }
.numbers { display: grid; grid-auto-columns: 1fr; grid-auto-flow: column; gap: .5rem; margin-bottom: 1.5rem; }
.numbers strong { display: block; font-family: var(--serif); font-size: 2rem; line-height: 1.1; }
.numbers span { color: var(--muted); font-size: .72rem; }
.dist {
  display: grid;
  grid-template-columns: max-content 1fr;
  align-items: center;
  gap: .3rem .5rem;
  margin: 0 0 1.5rem;
  padding: 0;
  list-style: none;
}
.dist li { display: contents; }
.dist-label { color: var(--muted); font-size: .8rem; text-align: right; }
.dist-bar {
  justify-self: start;
  min-width: 1.75rem;
  padding: .15rem .5rem;
  border-radius: .3rem;
  background: var(--absent);
  color: var(--on-color);
  font-size: .8rem;
  font-weight: 700;
  text-align: right;
}
.dist-bar.mine { background: var(--correct); }
