/* crucIAverba — design system aidea (frontend-design), adattato a CSS vanilla.
   Token oklch, base neutral-slate, primary viola-indaco, spazi generosi,
   ombre sottili a strati, motion expo-out. Deroga voluta: bordi quadrati. */

@font-face { font-family: "Artific"; src: url("fonts/Artific-Regular.woff2") format("woff2");  font-weight: 400; font-display: swap; }
@font-face { font-family: "Artific"; src: url("fonts/Artific-Medium.woff2") format("woff2");   font-weight: 500; font-display: swap; }
@font-face { font-family: "Artific"; src: url("fonts/Artific-SemiBold.woff2") format("woff2"); font-weight: 600; font-display: swap; }
@font-face { font-family: "Artific"; src: url("fonts/Artific-Bold.woff2") format("woff2");     font-weight: 700; font-display: swap; }

:root {
  --background: oklch(1 0 0);
  --foreground: oklch(0.141 0.005 285);
  --card: oklch(1 0 0);
  --secondary: oklch(0.96 0.004 285);
  --muted-foreground: oklch(0.5 0.01 285);
  --primary: oklch(0.627 0.196 292);
  --primary-foreground: oklch(1 0 0);
  --destructive: oklch(0.577 0.245 27.325);
  --border: oklch(0 0 0 / 10%);
  --ring: oklch(0 0 0 / 25%);
  --overlay: oklch(0.141 0.005 285 / 45%);
  --glass: oklch(1 0 0 / 80%);

  --cell-bg: oklch(1 0 0);
  --cell-block: oklch(0.141 0.005 285);
  --cell-num: oklch(0.5 0.01 285);
  --grid-line: oklch(0.141 0.005 285 / 35%);
  --slot-hl: oklch(0.627 0.196 292 / 12%);
  --cursor-hl: oklch(0.627 0.196 292 / 28%);
  --scrollbar-thumb: oklch(0.7 0.01 285);
  --scrollbar-thumb-hover: oklch(0.6 0.01 285);

  --ease: cubic-bezier(0.16, 1, 0.3, 1);
  --ease-over: cubic-bezier(0.34, 1.2, 0.64, 1);
  /* le celle si adattano a larghezza E altezza: la griglia sta SEMPRE intera
     nello schermo (niente scroll orizzontale, --cols colonne) e il blocco
     sticky lascia sotto una fascia di definizioni visibile */
  --cell: min(calc((100vw - 36px) / var(--cols, 20)),
              40px,
              max(18px, calc((100dvh - 250px) / var(--rows, 10))));
}
@media (prefers-color-scheme: dark) {
  :root {
    --background: oklch(0.14 0.005 285);
    --foreground: oklch(0.95 0 0);
    --card: oklch(0.17 0.008 285);
    --secondary: oklch(0.21 0.01 285);
    --muted-foreground: oklch(0.6 0 0);
    --border: oklch(1 0 0 / 8%);
    --ring: oklch(1 0 0 / 25%);
    --overlay: oklch(0 0 0 / 55%);
    --glass: oklch(0.14 0.005 285 / 80%);

    --cell-bg: oklch(0.24 0.008 285);
    --cell-block: oklch(0.07 0.004 285);
    --cell-num: oklch(0.72 0 0);
    --grid-line: oklch(0 0 0 / 60%);
    --slot-hl: oklch(0.627 0.196 292 / 22%);
    --cursor-hl: oklch(0.627 0.196 292 / 42%);
    --scrollbar-thumb: oklch(0.28 0.01 285);
    --scrollbar-thumb-hover: oklch(0.38 0.01 285);
  }
}

* { box-sizing: border-box; margin: 0; padding: 0; }
/* mai height:100% sul body: gli sticky (header, area di gioco) si sganciano
   quando lo scroll supera il fondo del loro genitore */
body {
  min-height: 100dvh;
  font-family: "Artific", system-ui, sans-serif;
  background: var(--background);
  color: var(--foreground);
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
}
button { font: inherit; color: inherit; background: none; border: 0; border-radius: 0; cursor: pointer; }
:focus-visible { outline: 3px solid var(--ring); outline-offset: 2px; }

/* ---------- header: sticky, traslucido, titolo centrato ---------- */
#topbar {
  position: sticky; top: 0; z-index: 20;
  height: 56px;
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  padding: 0 12px 0 20px;
  border-bottom: 1px solid var(--border);
  background: var(--glass);
  -webkit-backdrop-filter: blur(12px);
  backdrop-filter: blur(12px);
}
#topbar h1 {
  font-size: 1.25rem; font-weight: 600; letter-spacing: -0.025em;
  justify-self: center;
}
#topbar .ia { color: var(--primary); }
#hdr-left {
  justify-self: start;
  display: flex; align-items: center; gap: 8px;
  min-width: 0;
}
#logo {
  width: 26px; height: 26px;
  display: block; flex: 0 0 auto;
}
#date-label {
  font-size: 0.75rem; color: var(--muted-foreground);
  white-space: nowrap;
}
#hdr-right {
  justify-self: end;
  display: flex; align-items: center; gap: 10px;
  font-size: 0.75rem; color: var(--muted-foreground);
  font-variant-numeric: tabular-nums;
}
#view-btn {
  width: 36px; height: 36px;
  display: flex; align-items: center; justify-content: center;
  color: var(--muted-foreground);
  transition: color 150ms var(--ease), background 150ms var(--ease);
}
#view-btn:hover { color: var(--foreground); background: var(--secondary); }

/* ---------- layout ---------- */
/* niente padding-top sulla pagina: lo spazio sopra la griglia vive DENTRO il
   blocco sticky, cosi' la sua posizione naturale coincide con quella agganciata
   e all'inizio dello scroll non c'e' alcun movimento */
#app {
  max-width: 1152px;
  margin: 0 auto;
  padding: 0 16px calc(24px + env(safe-area-inset-bottom));
  display: flex; flex-direction: column; align-items: center;
  gap: 20px;
}
#loading { padding: 96px 24px; text-align: center; color: var(--muted-foreground); font-size: 0.875rem; }
#app[data-state="ready"] #loading { display: none; }

/* ---------- griglia ---------- */
#boardwrap {
  max-width: 100%;
  overflow: auto hidden;
  overscroll-behavior-x: contain;
  -webkit-overflow-scrolling: touch;
}
#board {
  display: grid;
  border: 2px solid var(--cell-block);
  background: var(--cell-block);
  width: max-content;
}
.cell {
  width: var(--cell); height: var(--cell);
  background: var(--cell-bg);
  border: 0.5px solid var(--grid-line);
  position: relative;
  display: flex; align-items: center; justify-content: center;
  font-weight: 600;
  font-size: calc(var(--cell) * 0.55);
  text-transform: uppercase;
  user-select: none;
  transition: background 120ms var(--ease);
}
.cell.block { background: var(--cell-block); border-color: var(--cell-block); cursor: default; }
.cell .num {
  position: absolute; top: 1px; left: 2px;
  font-size: max(7px, calc(var(--cell) * 0.26));
  font-weight: 500; color: var(--cell-num);
  line-height: 1; pointer-events: none;
}
/* i tint hanno alpha: vanno compositi sopra il bianco della cella, non sopra
   lo sfondo scuro della board che fa da reticolo */
.cell.in-slot { background: linear-gradient(var(--slot-hl), var(--slot-hl)) var(--cell-bg); }
.cell.cursor {
  background: linear-gradient(var(--cursor-hl), var(--cursor-hl)) var(--cell-bg);
  box-shadow: inset 0 0 0 2px var(--primary);
}
.cell.pop .val { animation: pop 140ms var(--ease-over); display: inline-block; }
@keyframes pop { 50% { transform: scale(1.18); } }
.cell:focus-visible { outline: 2px solid var(--primary); outline-offset: -2px; }
.cell { scroll-margin: 128px 12px 12px; }   /* header sticky + cluebar sticky */

/* ---------- area di gioco: definizione attiva + griglia, sticky ----------
   il blocco resta pinnato sotto l'header mentre sotto scorrono tutte le
   definizioni; su mobile resta cosi' visibile anche a tastiera nativa aperta */
#playarea {
  position: sticky; top: 56px; z-index: 15;
  width: 100%;
  display: flex; flex-direction: column; align-items: center;
  gap: 16px;
  padding: 20px 0 12px;
  background: var(--background);
  border-bottom: 1px solid var(--border);
}
#cluebar {
  display: flex; align-items: stretch;
  width: min(100%, 560px);
  min-height: 56px;
  background: linear-gradient(var(--slot-hl), var(--slot-hl)) var(--background);
}
.clue-nav {
  width: 44px; flex: 0 0 auto;
  font-size: 1.375rem; font-weight: 400;
  color: var(--muted-foreground);
  transition: color 150ms var(--ease);
}
.clue-nav:hover { color: var(--foreground); }
#cluetext {
  flex: 1; min-width: 0;
  display: flex; flex-direction: column; justify-content: center; gap: 2px;
  padding: 10px 4px; text-align: left;
}
#clue-label {
  font-size: 0.6875rem; font-weight: 500;
  letter-spacing: 0.04em; text-transform: uppercase;
  color: var(--muted-foreground);
}
#clue-len { display: none; }
#clue-body { font-size: 0.9375rem; line-height: 1.4; }

/* ---------- tutte le definizioni: sotto la griglia, a tutta larghezza ----------
   ogni sezione fluisce in colonne da ~15rem: tante quante ne stanno sullo
   schermo in quel momento, con lettura dall'alto in basso per colonna */
#cluepanel {
  width: 100%;
  padding-top: 4px;
}
.cluecol + .cluecol { margin-top: 24px; }
.cluecol ol {
  columns: 15rem;
  column-gap: 32px;
}
.cluecol li { break-inside: avoid; }
.cluecol h2 {
  font-size: 0.75rem; font-weight: 600;
  letter-spacing: 0.06em; text-transform: uppercase;
  color: var(--muted-foreground);
  padding-bottom: 8px; margin-bottom: 4px;
  border-bottom: 1px solid var(--border);
}
.cluecol ol { list-style: none; }
.cluecol button {
  width: 100%; text-align: left;
  padding: 6px 8px;
  font-size: 0.8125rem; line-height: 1.45;
  display: flex; gap: 8px;
  color: var(--muted-foreground);
  transition: color 150ms var(--ease), background 150ms var(--ease);
}
.cluecol button:hover { color: var(--foreground); background: var(--secondary); }
.cluecol button b {
  min-width: 1.6em; text-align: right;
  font-weight: 500; font-variant-numeric: tabular-nums;
}
.cluecol li.active button { background: var(--slot-hl); color: var(--foreground); }
.cluecol li.done .clue-t { text-decoration: line-through; text-decoration-thickness: 1px; }
.cluecol li { scroll-margin: 28px 0 8px; }

/* ---------- input fantasma (tastiera nativa) ---------- */
#ghost {
  position: fixed; left: 8px; top: 8px;   /* in alto: niente scroll di keyboard-avoidance iOS */
  width: 2px; height: 2px;
  opacity: 0.01;
  font-size: 16px;              /* niente auto-zoom su iOS */
  border: 0; padding: 0;
  background: transparent; color: transparent;
  caret-color: transparent;
  pointer-events: none;
}
#ghost:focus { outline: none; }

/* ---------- toast: in alto, mai coperto dalla tastiera nativa ---------- */
#toast {
  position: fixed; left: 50%; top: calc(16px + env(safe-area-inset-top));
  transform: translateX(-50%);
  background: var(--foreground); color: var(--background);
  padding: 10px 18px;
  font-size: 0.875rem;
  z-index: 40;
  max-width: 88vw; text-align: center;
  animation: toast-in 250ms var(--ease);
}
@keyframes toast-in { from { opacity: 0; transform: translate(-50%, -8px); } }

/* ---------- vittoria ---------- */
#win-overlay {
  position: fixed; inset: 0; z-index: 50;
  background: var(--overlay);
  display: flex; align-items: center; justify-content: center;
  padding: 24px;
}
#win-card {
  background: var(--card);
  border: 1px solid var(--border);
  box-shadow: 0 2px 24px -4px rgb(0 0 0 / 0.10), 0 0 8px -2px rgb(0 0 0 / 0.04);
  padding: 32px 28px;
  text-align: center;
  max-width: 360px;
  animation: card-in 250ms var(--ease-over);
}
@keyframes card-in { from { opacity: 0; transform: translateY(16px); } }
#win-card h2 { font-size: 1.125rem; font-weight: 600; letter-spacing: -0.025em; }
#win-card p { color: var(--muted-foreground); font-size: 0.875rem; line-height: 1.6; margin: 8px 0 20px; }
#win-close {
  height: 36px; padding: 0 20px;
  background: var(--primary); color: var(--primary-foreground);
  font-size: 0.875rem; font-weight: 500;
  transition: background 150ms var(--ease);
}
#win-close:hover { background: oklch(0.627 0.196 292 / 90%); }

/* ---------- scrollbar delle sezioni: visibili solo col mouse sopra ----------
   il canale resta sempre riservato (niente spostamenti di layout): e' il
   colore del cursore ad accendersi in hover. Sui touch restano i nativi. */
@media (hover: hover) {
  .cluecol, #boardwrap {
    scrollbar-width: thin;
    scrollbar-color: transparent transparent;
  }
  .cluecol:hover, #boardwrap:hover {
    scrollbar-color: var(--scrollbar-thumb) transparent;
  }
  .cluecol::-webkit-scrollbar, #boardwrap::-webkit-scrollbar { width: 8px; height: 8px; }
  .cluecol::-webkit-scrollbar-track, #boardwrap::-webkit-scrollbar-track { background: transparent; }
  .cluecol::-webkit-scrollbar-thumb, #boardwrap::-webkit-scrollbar-thumb { background: transparent; }
  .cluecol:hover::-webkit-scrollbar-thumb, #boardwrap:hover::-webkit-scrollbar-thumb {
    background: var(--scrollbar-thumb);
  }
  .cluecol:hover::-webkit-scrollbar-thumb:hover { background: var(--scrollbar-thumb-hover); }
}

[hidden] { display: none !important; }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}

/* ---------- schermi larghi: stessa disposizione, piu' respiro ---------- */
@media (min-width: 1080px) {
  /* la definizione attiva vive nell'elenco (evidenziata e auto-scrollata):
     la barra sopra la griglia serve solo su mobile */
  #cluebar { display: none; }
  #app { padding: 0 24px 48px; }
  #playarea { padding-top: 28px; }
  #clue-len { display: inline; }
}

/* ================= viste (bottone in alto a destra) =================
   stack (default): Orizzontali sopra, Verticali sotto, colonne fluide
   split: Orizzontali e Verticali affiancate, ognuna col proprio scroll
   flank (solo schermi larghi): Orizzontali | griglia | Verticali        */

body[data-view="split"] #cluepanel {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0 24px;
}
body[data-view="split"] .cluecol { margin-top: 0; }
body[data-view="split"] .cluecol,
body[data-view="flank"] .cluecol {
  overflow-y: auto;
  overscroll-behavior: contain;
  padding-right: 2px;
}
body[data-view="split"] .cluecol { max-height: var(--defs-h, 45dvh); }
body[data-view="split"] .cluecol ol,
body[data-view="flank"] .cluecol ol { columns: auto; }
body[data-view="split"] .cluecol h2,
body[data-view="flank"] .cluecol h2 {
  position: sticky; top: 0; z-index: 1;
  background: var(--background);
}

body[data-view="flank"] {
  --cell: min(calc((100vw - 560px) / var(--cols, 20)),
              32px,
              max(18px, calc((100dvh - 220px) / var(--rows, 10))));
}
body[data-view="flank"] #app {
  display: grid;
  grid-template-columns: minmax(220px, 340px) max-content minmax(220px, 340px);
  grid-template-areas: "ca play cd";
  justify-content: center;
  align-items: start;
  gap: 0 28px;
}
body[data-view="flank"] #playarea { grid-area: play; }
body[data-view="flank"] #cluepanel { display: contents; }
body[data-view="flank"] #col-A { grid-area: ca; }
body[data-view="flank"] #col-D { grid-area: cd; }
body[data-view="flank"] .cluecol {
  position: sticky; top: 76px;
  margin-top: 20px;
  max-height: calc(100dvh - 100px);
}
