/* Definio: flat puzzle-game styling. One narrow column, square letter tiles, black pill buttons. */
:root {
  --bg: #ffffff;
  --fg: #121213;
  --muted: #787c7e;
  --line: #d3d6da;
  --tile-border: #878a8c;
  --panel: #f6f7f8;
  --btn: #121213;
  --btn-fg: #ffffff;
  --green: #6aaa64;
  --yellow: #c9b458;
  --red: #c4554d;
  --gray: #787c7e;
  --on-color: #ffffff;
  --font: "Libre Franklin", "Franklin Gothic Medium", "Helvetica Neue", Arial, sans-serif;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #121213; --fg: #f8f8f8; --muted: #818384; --line: #3a3a3c; --tile-border: #565758;
    --panel: #1d1d1f; --btn: #f8f8f8; --btn-fg: #121213;
    --green: #538d4e; --yellow: #b59f3b; --red: #b5534e; --gray: #3a3a3c; color-scheme: dark;
  }
}
* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg); color: var(--fg); font-family: var(--font); font-size: 16px; line-height: 1.45;
  min-height: 100vh; min-height: 100dvh;
  padding-top: env(safe-area-inset-top, 0px); padding-bottom: env(safe-area-inset-bottom, 0px);
}
button { font: inherit; color: inherit; cursor: pointer; }
:focus-visible { outline: 2px solid var(--green); outline-offset: 2px; }
[hidden] { display: none !important; }

/* Header */
.bar {
  height: 54px; display: grid; grid-template-columns: 1fr auto 1fr; align-items: center;
  border-bottom: 1px solid var(--line);
  padding-left: max(12px, env(safe-area-inset-left, 0px)); padding-right: max(12px, env(safe-area-inset-right, 0px));
}
.bar-side { display: flex; gap: 4px; }
.bar-side.right { justify-content: flex-end; }
.logo { margin: 0; font-weight: 800; font-size: 1.75rem; letter-spacing: 0.01em; position: relative; }
.beta { position: absolute; left: 100%; top: 6px; margin-left: 4px; font-size: 0.6rem; font-weight: 700; letter-spacing: 0.08em; text-transform: uppercase; color: var(--muted); }
.icon { background: none; border: 0; width: 40px; height: 40px; display: grid; place-items: center; border-radius: 4px; padding: 0; }
.icon svg { width: 24px; height: 24px; }

.loadbar { position: relative; height: 22px; background: var(--panel); border-bottom: 1px solid var(--line); overflow: hidden; }
.loadbar-fill { position: absolute; inset: 0 auto 0 0; width: 0; background: color-mix(in srgb, var(--green) 30%, transparent); transition: width 0.3s; }
.loadbar span { position: relative; display: block; text-align: center; font-size: 0.72rem; line-height: 22px; color: var(--muted); font-weight: 600; letter-spacing: 0.04em; text-transform: uppercase; }

main {
  max-width: 520px; margin: 0 auto;
  padding: 24px max(16px, env(safe-area-inset-right, 0px)) 48px max(16px, env(safe-area-inset-left, 0px));
  display: flex; flex-direction: column; gap: 22px;
}

/* Home */
.home { text-align: center; display: flex; flex-direction: column; gap: 22px; align-items: center; padding-top: 4vh; }
.home h2 { margin: 0; font-size: 2rem; font-weight: 800; text-wrap: balance; }
.home p.lede { margin: 0; color: var(--fg); font-size: 1.15rem; max-width: 30ch; text-wrap: balance; }
.levels { width: 100%; display: flex; flex-direction: column; gap: 10px; }
.level {
  width: 100%; display: grid; grid-template-columns: 1fr auto; align-items: center; gap: 4px 12px; text-align: left;
  border: 1px solid var(--line); border-radius: 8px; background: var(--bg); padding: 14px 16px;
}
.level:hover { border-color: var(--tile-border); }
.level b { font-size: 1.15rem; font-weight: 800; }
.level .ex { color: var(--muted); font-size: 0.9rem; text-align: right; }
.level .mine { grid-column: 1 / -1; font-size: 0.78rem; color: var(--muted); }
.level .dot { display: inline-block; width: 10px; height: 10px; border-radius: 2px; margin-right: 8px; vertical-align: 1px; }
.report { align-self: center; }
.linkbtn { background: none; border: 0; color: var(--muted); text-decoration: underline; text-underline-offset: 3px; font-size: 0.92rem; padding: 6px; }

/* Today's Five */
.daily { width: 100%; text-align: left; border: 2px solid var(--fg); border-radius: 10px; padding: 16px; display: flex; flex-direction: column; gap: 10px; }
.daily-top { display: flex; justify-content: space-between; align-items: baseline; gap: 8px; flex-wrap: wrap; }
.daily-top b { font-size: 1.2rem; font-weight: 800; }
.daily-top span, .daily .mine { color: var(--muted); font-size: 0.85rem; }
.daily-score { display: flex; justify-content: space-between; align-items: center; gap: 10px; }
.daily-score b { font-size: 1.3rem; font-weight: 800; font-variant-numeric: tabular-nums; }
.sq { letter-spacing: 2px; font-size: 1.3rem; }
.sq.big { text-align: center; font-size: 1.8rem; }
.big-stats.three { grid-template-columns: repeat(3, 1fr); }

/* Tiles */
.tiles { display: flex; justify-content: center; gap: var(--gap, 5px); flex-wrap: wrap; }
.tile {
  width: var(--ts, 52px); height: var(--ts, 52px); border: 2px solid var(--tile-border); display: grid; place-items: center;
  font-weight: 800; font-size: calc(var(--ts, 52px) * 0.55); text-transform: uppercase; line-height: 1;
}
.tiles.revealed .tile { background: var(--fg); color: var(--bg); border-color: var(--fg); }
.tiles.scored .tile { color: var(--on-color); }
.tile.flip { animation: flip 0.42s ease both; }
@keyframes flip { 0% { transform: rotateX(0); } 50% { transform: rotateX(90deg); } 100% { transform: rotateX(0); } }
@media (prefers-reduced-motion: reduce) { .tile.flip { animation: none; } }
.logo-tiles .tile { --ts: 44px; }
.tiles.brand .tile { color: var(--on-color); border-color: transparent; background: var(--green); }
.tiles.brand .tile:nth-child(4) { background: var(--yellow); }
.tiles.brand .tile:nth-child(7) { background: var(--fg); color: var(--bg); }

/* Game */
.statline { display: flex; justify-content: center; gap: 28px; font-variant-numeric: tabular-nums; }
.statline div { text-align: center; }
.statline b { display: block; font-size: 1.4rem; font-weight: 800; line-height: 1.1; }
.statline span { font-size: 0.68rem; letter-spacing: 0.08em; text-transform: uppercase; color: var(--muted); font-weight: 600; }
.levtag { align-self: center; font-size: 0.72rem; letter-spacing: 0.1em; text-transform: uppercase; font-weight: 700; color: var(--muted); }
.sense { text-align: center; display: flex; flex-direction: column; gap: 6px; }
.pos { font-style: italic; color: var(--muted); }
.sentence { margin: 0; font-size: 1.1rem; text-wrap: pretty; }
.sentence strong { font-weight: 800; }

.answer { display: flex; flex-direction: column; gap: 10px; }
textarea {
  width: 100%; min-height: 104px; resize: none; font: inherit; font-size: 1.08rem; color: var(--fg); background: var(--bg);
  border: 2px solid var(--line); border-radius: 8px; padding: 12px 14px;
}
textarea:focus { outline: none; border-color: var(--tile-border); }
.field { position: relative; }
.field.has-lead { border: 2px solid var(--line); border-radius: 8px; padding: 12px 14px 4px; display: block; }
.field.has-lead:focus-within { border-color: var(--tile-border); }
.field.has-lead textarea { border: 0; padding: 4px 0 8px; min-height: 76px; border-radius: 0; }
.lead { display: block; font-weight: 700; font-size: 1.08rem; color: var(--fg); }
.lead::after { content: " …"; color: var(--muted); font-weight: 400; }
.lead-q { color: var(--muted); }
.btn {
  width: 100%; height: 52px; border: 0; border-radius: 26px; background: var(--btn); color: var(--btn-fg);
  font-weight: 700; font-size: 1rem; letter-spacing: 0.02em;
}
.btn:disabled { opacity: 0.35; cursor: default; }
.btn.secondary { background: transparent; color: var(--fg); border: 1px solid var(--fg); }
.row { display: flex; gap: 10px; }
.row .btn { flex: 1; }
.hint { text-align: center; font-size: 0.8rem; color: var(--muted); margin: 0; }

/* Result */
.result { display: flex; flex-direction: column; gap: 16px; }
.scorebox { display: flex; flex-direction: column; gap: 8px; }
.score-top { display: flex; justify-content: space-between; align-items: baseline; gap: 12px; }
.pct { font-size: 2.8rem; font-weight: 800; line-height: 1; font-variant-numeric: tabular-nums; }
.pts { text-align: right; font-variant-numeric: tabular-nums; }
.pts b { font-size: 1.3rem; font-weight: 800; }
.pts span { display: block; font-size: 0.78rem; color: var(--muted); }
.meter { height: 34px; border-radius: 6px; background: var(--panel); position: relative; overflow: hidden; }
.meter i { position: absolute; inset: 0 auto 0 0; width: 0; border-radius: 6px; transition: width 0.6s cubic-bezier(.2,.8,.2,1); }
.meter em { position: absolute; left: 12px; top: 0; line-height: 34px; font-style: normal; font-weight: 700; color: var(--on-color); font-size: 0.9rem; letter-spacing: 0.02em; mix-blend-mode: normal; }
.meter.low em { color: var(--fg); }
@media (prefers-reduced-motion: reduce) { .meter i { transition: none; } }
.note { margin: 0; font-weight: 600; }
.block { display: flex; flex-direction: column; gap: 6px; }
.label { font-size: 0.7rem; letter-spacing: 0.1em; text-transform: uppercase; color: var(--muted); font-weight: 700; }
.quote { margin: 0; font-size: 1.02rem; padding: 12px 14px; border-radius: 8px; background: var(--panel); text-wrap: pretty; overflow-wrap: anywhere; }
.k { border-radius: 3px; padding: 0 3px; color: var(--on-color); }
.k.hit { background: var(--green); }
.k.rel { background: var(--yellow); }
.k.miss { background: transparent; color: inherit; box-shadow: inset 0 -2px 0 var(--tile-border); padding: 0 1px; border-radius: 0; }
.legend { display: flex; gap: 14px; flex-wrap: wrap; font-size: 0.78rem; color: var(--muted); }
.legend i { display: inline-block; width: 10px; height: 10px; border-radius: 2px; margin-right: 6px; vertical-align: 0; }

/* Modal */
dialog {
  border: 0; border-radius: 10px; padding: 0; width: min(440px, calc(100vw - 32px)); max-height: calc(100dvh - 48px);
  background: var(--bg); color: var(--fg); box-shadow: 0 10px 40px rgba(0,0,0,.25);
}
dialog::backdrop { background: color-mix(in srgb, var(--bg) 60%, transparent); }
.modal-body { padding: 22px 22px 24px; display: flex; flex-direction: column; gap: 14px; }
.modal-body h3 { margin: 0; font-size: 1.4rem; font-weight: 800; }
.modal-body p, .modal-body ul { margin: 0; }
.modal-body ul { padding-left: 1.1em; display: flex; flex-direction: column; gap: 6px; }
.modal-head { display: flex; justify-content: space-between; align-items: center; }
.big-stats { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; text-align: center; font-variant-numeric: tabular-nums; }
.big-stats b { display: block; font-size: 1.8rem; font-weight: 800; line-height: 1.1; }
.big-stats span { font-size: 0.68rem; color: var(--muted); text-transform: uppercase; letter-spacing: 0.04em; }
table { width: 100%; border-collapse: collapse; font-variant-numeric: tabular-nums; font-size: 0.92rem; }
th, td { padding: 7px 4px; border-bottom: 1px solid var(--line); text-align: right; }
th:first-child, td:first-child { text-align: left; }
th { font-size: 0.68rem; letter-spacing: 0.06em; text-transform: uppercase; color: var(--muted); font-weight: 700; }

.toast {
  position: fixed; left: 50%; top: calc(64px + env(safe-area-inset-top, 0px)); transform: translateX(-50%);
  background: var(--fg); color: var(--bg); padding: 10px 14px; border-radius: 6px; font-weight: 600; font-size: 0.9rem;
  opacity: 0; pointer-events: none; transition: opacity 0.2s; max-width: calc(100vw - 32px); text-align: center;
}
.toast.show { opacity: 1; }
.spin { display: inline-block; width: 14px; height: 14px; border: 2px solid currentColor; border-right-color: transparent; border-radius: 50%; animation: spin 0.8s linear infinite; vertical-align: -2px; margin-right: 8px; }
@keyframes spin { to { transform: rotate(360deg); } }
