:root {
  --marble: #f4efe4; --marble-2: #e9e1cf; --ink: #2b2620; --quiet: #6f6657; --line: #cfc4ab;
  --aegean: #1f4e79; --aegean-soft: #bcd3e6; --sky: #dfeaf1; --terra: #b4472c; --terra-soft: #e6b7a2;
  --gold: #b8892b; --tile: #f7e7bd; --tile-edge: #c9a96a; --ok: #2f7d4f; --bad: #b4472c;
  color-scheme: light;
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; }
body { background: var(--marble); color: var(--ink); font: 15px/1.4 system-ui, -apple-system, "Segoe UI", Roboto, Arial, sans-serif; }
h1, h2, h3, .score .p b, .game-score { font-family: Georgia, "Times New Roman", serif; }
button { font: inherit; color: inherit; cursor: pointer; border: 1px solid var(--line); background: #fffdf8; border-radius: 10px; padding: 9px 12px; min-height: 42px; }
button:active { transform: translateY(1px); }
button:disabled { opacity: .45; cursor: default; }
button.primary { background: var(--aegean); border-color: var(--aegean); color: #fff; font-weight: 600; }
button.link { border: 0; background: none; padding: 4px 0; min-height: 0; color: var(--aegean); text-decoration: underline; }
#app { max-width: 620px; margin: 0 auto; padding: 12px 12px calc(16px + env(safe-area-inset-bottom)); }
.top { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-bottom: 10px; }
.top h1 { font-size: 22px; margin: 0; letter-spacing: .02em; }
.frieze { height: 8px; margin: 0 -12px 10px; background: repeating-linear-gradient(90deg, var(--aegean) 0 10px, transparent 10px 14px, var(--aegean) 14px 18px, transparent 18px 22px); opacity: .85; }
.stats { display: flex; gap: 8px; color: var(--quiet); font-size: 14px; flex-wrap: wrap; }
.stats b { color: var(--ink); }
.card { background: #fbf8f0; border: 1px solid var(--line); border-radius: 12px; padding: 14px; margin-bottom: 12px; box-shadow: 0 1px 2px rgba(60,45,20,.06); }
.card h2 { margin: 0 0 8px; font-size: 17px; }
.levels { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.levels button { display: flex; flex-direction: column; gap: 2px; align-items: center; }
.levels small { color: var(--quiet); font-size: 12px; }
.game-row { display: flex; justify-content: space-between; gap: 8px; align-items: center; width: 100%; text-align: left; margin-bottom: 6px; }
.game-info { display: flex; flex-direction: column; gap: 1px; min-width: 0; }
.game-score { white-space: nowrap; font-size: 18px; }
.tag { font-size: 12px; color: var(--quiet); }
.tag.you { color: var(--terra); font-weight: 700; }
.nav { display: flex; gap: 8px; }
.nav button { flex: 1; padding: 9px 4px; font-size: 14px; }

.score { display: grid; grid-template-columns: 1fr auto 1fr; align-items: center; gap: 8px; margin-bottom: 8px; }
.score .p { padding: 6px 10px; border-radius: 8px; border: 1px solid var(--line); background: #fbf8f0; }
.score .p.active { border-color: var(--aegean); box-shadow: inset 0 0 0 1px var(--aegean); }
.score .p b { font-size: 20px; display: block; }
.score .p span { font-size: 12px; color: var(--quiet); }
.score .mid { text-align: center; font-size: 12px; color: var(--quiet); }

.board-wrap { overflow: hidden; box-sizing: border-box; width: min(100%, 62vh); margin: 0 auto; border: 2px solid var(--ink); border-radius: 4px; background: var(--ink); }
.board-wrap.zoomed { overflow: auto; width: 100%; max-height: 62vh; -webkit-overflow-scrolling: touch; }
.board { display: grid; grid-template-columns: repeat(15, 1fr); gap: 1px; aspect-ratio: 1; width: 100%; }
.board.zoom { width: 170%; }
.cell { background: var(--marble); display: flex; align-items: center; justify-content: center; padding: 0; border: 0; border-radius: 0; min-height: 0; font-size: 9px; color: rgba(0,0,0,.55); position: relative; aspect-ratio: 1; overflow: hidden; line-height: 1; }
.cell.w3 { background: var(--terra); color: #fff; }
.cell.w2 { background: var(--terra-soft); }
.cell.l3 { background: var(--aegean); color: #fff; }
.cell.l2 { background: var(--aegean-soft); }
.cell.center::after { content: "Ω"; font-size: 13px; color: var(--ink); }
.cell:active { transform: none; }
.tile { background: var(--tile); color: var(--ink); box-shadow: inset 0 -2px 0 var(--tile-edge); display: flex; align-items: center; justify-content: center; font-weight: 700; text-transform: uppercase; position: relative; }
.cell .tile { position: absolute; inset: 0; font-size: clamp(12px, 3.6vw, 20px); }
.board.zoom .cell .tile { font-size: clamp(18px, 5.6vw, 28px); }
.tile sub { position: absolute; right: 1px; bottom: 1px; font-size: .48em; font-weight: 400; line-height: 1; }
.cell .tile.new { background: #ffe58a; box-shadow: inset 0 0 0 2px var(--gold); }
.cell .tile.bad { background: #f3c2b4; box-shadow: inset 0 0 0 2px var(--bad); }
.cell .tile.last { box-shadow: inset 0 0 0 2px var(--aegean); }

button.word-ok { color: var(--ok); font-weight: 700; }
button.word-bad { color: var(--bad); font-weight: 700; }
input[type=search] { width: 100%; font: inherit; padding: 9px 10px; border: 1px solid var(--line); border-radius: 8px; background: #fff; }
.mod-row { display: flex; align-items: center; gap: 8px; padding: 6px 0; border-bottom: 1px solid var(--marble-2); flex-wrap: wrap; }
.mod-act { margin-left: auto; display: flex; gap: 6px; }
.rack { display: flex; gap: 5px; justify-content: center; margin: 10px 0 6px; min-height: 48px; }
.rack button { width: 44px; height: 46px; padding: 0; font-size: 22px; border-radius: 6px; border: 1px solid var(--tile-edge); background: var(--tile); box-shadow: inset 0 -3px 0 var(--tile-edge); font-weight: 700; text-transform: uppercase; position: relative; }
.rack button { touch-action: none; user-select: none; -webkit-user-select: none; }
.cell.target { outline: 3px solid var(--gold); outline-offset: -3px; z-index: 2; }
.ghost { position: fixed; z-index: 60; pointer-events: none; display: flex; align-items: center; justify-content: center; background: var(--tile); border: 1px solid var(--tile-edge); box-shadow: inset 0 -3px 0 var(--tile-edge); border-radius: 6px; font-weight: 700; font-size: 22px; text-transform: uppercase; transform-origin: top left; }
.ghost.drag { width: 52px; height: 54px; font-size: 26px; box-shadow: 0 8px 18px rgba(0,0,0,.35); }
.ghost[hidden] { display: none; }
.rack button sub { position: absolute; right: 3px; bottom: 3px; font-size: 10px; font-weight: 400; }
.rack button.sel { outline: 3px solid var(--aegean); }
.rack button.used { visibility: hidden; }
.preview:empty { display: none; }
.preview { min-height: 36px; font-size: 14px; padding: 6px 8px; border-radius: 8px; background: #fbf8f0; border: 1px solid var(--line); margin-bottom: 8px; }
.preview .ok { color: var(--ok); font-weight: 700; }
.preview .bad { color: var(--bad); font-weight: 700; }
.actions { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin-bottom: 6px; }
.actions button { padding: 8px 4px; font-size: 14px; }
.actions .main { grid-column: 1 / -1; min-height: 50px; font-size: 17px; }
.minor { display: flex; justify-content: center; gap: 22px; margin: 4px 0 12px; }
.minor button.link { font-size: 14px; color: var(--quiet); }
.brand { display: flex; align-items: center; gap: 12px; margin-bottom: 14px; }
.brand img { border-radius: 14px; flex: none; box-shadow: 0 2px 6px rgba(31,78,121,.3); }
.brand h1 { font-size: 24px; margin: 0 0 4px; }
.chip { background: var(--marble-2); border-radius: 999px; padding: 2px 10px; font-size: 13px; color: var(--quiet); }
.chip b { color: var(--ink); margin-left: 2px; }
.actions .wide { grid-column: span 2; }
.banner { padding: 8px 10px; border-radius: 8px; background: var(--sky); margin-bottom: 8px; font-size: 14px; }
.banner.end { background: var(--marble-2); }
.history { font-size: 14px; }
.history div { padding: 3px 0; border-bottom: 1px solid var(--marble-2); display: flex; gap: 6px; flex-wrap: wrap; align-items: baseline; }
.bonus { background: var(--gold); color: #fff; border-radius: 6px; padding: 1px 6px; font-size: 12px; font-weight: 700; white-space: nowrap; }
.history .pts { margin-left: auto; font-weight: 700; }
table.weights { border-collapse: collapse; width: 100%; font-size: 14px; }
table.weights td { border-bottom: 1px solid var(--marble-2); padding: 4px 6px; }
tr.me td { font-weight: 700; background: var(--sky); }
ul.rules { padding-left: 20px; margin: 6px 0; }
ul.rules li { margin-bottom: 5px; }
#toast { position: fixed; left: 50%; bottom: 20px; transform: translateX(-50%); background: var(--ink); color: #fff; padding: 10px 14px; border-radius: 8px; font-size: 14px; max-width: 90vw; z-index: 50; }
.modal { position: fixed; inset: 0; background: rgba(0,0,0,.45); display: flex; align-items: center; justify-content: center; padding: 16px; z-index: 40; }
.modal > div { background: var(--marble); border-radius: 12px; padding: 14px; max-width: 460px; width: 100%; max-height: 80vh; overflow: auto; white-space: pre-line; }
.modal h3 { margin: 0 0 8px; text-transform: capitalize; }
.modal .row { display: flex; gap: 8px; margin-top: 10px; flex-wrap: wrap; }
.swap { display: flex; gap: 6px; justify-content: center; flex-wrap: wrap; white-space: normal; }
.swap button { width: 42px; height: 44px; padding: 0; text-transform: uppercase; font-weight: 700; background: var(--tile); }
.swap button.sel { outline: 3px solid var(--terra); }
.quiet { color: var(--quiet); font-size: 13px; }
.mod-mean { flex-basis: 100%; font-size: 13px; line-height: 1.35; color: var(--ink); margin-top: 2px; }
.mod-mean.quiet { color: var(--quiet); }
