/* Crossword Studio */
:root {
  --bg: #f5f3ee;
  --surface: #ffffff;
  --surface-2: #faf9f6;
  --ink: #1b1d24;
  --ink-2: #3a3e4a;
  --muted: #6b6f7a;
  --line: #e2dfd7;
  --line-2: #cfcbc1;
  --accent: #2f55d4;
  --accent-ink: #ffffff;
  --accent-soft: #e6ecff;
  --accent-2: #1d3db0;
  --good: #1f8a5b;
  --good-soft: #def5e9;
  --warn: #b86e00;
  --warn-soft: #fff2d6;
  --bad: #d13b3b;
  --bad-soft: #fde3e3;
  --cell: 32px;
  --cell-bg: #ffffff;
  --cell-block: #1b1d24;
  --cell-line: #1b1d24;
  --cell-sel: #ffd84d;
  --cell-word: #cfe0ff;
  --cell-cross: #eef3ff;
  --cell-shade: #e4e2dc;
  --cell-auto: #2f55d4;
  --heat-0: #ffc2c2;
  --heat-1: #ffd9b0;
  --heat-2: #fff0bd;
  --heat-3: transparent;
  --radius: 12px;
  --shadow: 0 1px 2px rgba(20, 20, 30, .06), 0 4px 16px rgba(20, 20, 30, .06);
  --shadow-lg: 0 12px 48px rgba(20, 20, 30, .22);
  --font: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --mono: ui-monospace, "SF Mono", "Cascadia Mono", Menlo, Consolas, monospace;
  --grid-font: "Helvetica Neue", Helvetica, Arial, var(--font);
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #121317;
    --surface: #1b1d23;
    --surface-2: #20232a;
    --ink: #eceef3;
    --ink-2: #c9ccd6;
    --muted: #9095a3;
    --line: #2d3039;
    --line-2: #3b3f4a;
    --accent: #6f8cff;
    --accent-ink: #0d1020;
    --accent-soft: #232c4d;
    --accent-2: #9cb0ff;
    --good: #4cc38a;
    --good-soft: #17352a;
    --warn: #f0b23e;
    --warn-soft: #3a2e14;
    --bad: #ff6b6b;
    --bad-soft: #3d1c1f;
    --cell-bg: #2a2d35;
    --cell-block: #07080a;
    --cell-line: #07080a;
    --cell-sel: #e3b62b;
    --cell-word: #33466f;
    --cell-cross: #2f3544;
    --cell-shade: #3a3d46;
    --cell-auto: #93a9ff;
    --heat-0: #6b2a2e;
    --heat-1: #5e4020;
    --heat-2: #4d4520;
    --shadow: 0 1px 2px rgba(0, 0, 0, .3), 0 4px 16px rgba(0, 0, 0, .25);
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 15px/1.45 var(--font);
  -webkit-font-smoothing: antialiased;
  min-height: 100dvh;
}
button, input, select, textarea { font: inherit; color: inherit; }
input, select, textarea { font-size: 16px; } /* iOS zooms on focus below 16px */
a { color: var(--accent); }
h1, h2, h3, h4 { line-height: 1.2; margin: 0; }
p { margin: 0; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.mono { font-family: var(--mono); }
kbd {
  font: 12px/1 var(--mono); padding: 2px 5px; border-radius: 5px;
  border: 1px solid var(--line-2); border-bottom-width: 2px; background: var(--surface-2); white-space: nowrap;
}
.ic { width: 18px; height: 18px; flex: none; }
.spacer { flex: 1; }
[hidden] { display: none !important; }

/* ------------------------------------------------------------ buttons */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 7px;
  height: 38px; padding: 0 14px; border-radius: 10px;
  border: 1px solid var(--line-2); background: var(--surface); color: var(--ink);
  font-weight: 600; font-size: 14px; cursor: pointer; text-decoration: none; white-space: nowrap;
  transition: background .12s, border-color .12s, transform .06s;
}
.btn:hover { background: var(--surface-2); border-color: var(--muted); }
.btn:active { transform: translateY(1px); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn.primary:hover { background: var(--accent-2); border-color: var(--accent-2); }
.btn.danger { background: var(--bad); border-color: var(--bad); color: #fff; }
.btn.ghost { border-color: transparent; background: transparent; }
.btn.ghost:hover { background: var(--surface-2); }
.btn.small { height: 32px; padding: 0 10px; font-size: 13px; border-radius: 8px; }
.btn.big { height: 46px; padding: 0 20px; font-size: 15px; border-radius: 12px; }
.btn.block { width: 100%; }
.btn:disabled { opacity: .45; pointer-events: none; }
.icon-btn {
  display: inline-grid; place-items: center; width: 38px; height: 38px; border-radius: 10px;
  border: 0; background: transparent; color: var(--ink-2); cursor: pointer; flex: none; text-decoration: none;
}
@media (hover: hover) { .icon-btn:hover { background: var(--surface-2); color: var(--ink); } }
.linkish {
  border: 0; background: none; padding: 0; color: var(--accent); font-weight: 600; cursor: pointer;
  display: inline-flex; align-items: center; gap: 4px; font-size: inherit;
}
.linkish:hover { text-decoration: underline; }
.linkish .ic { width: 15px; height: 15px; }

/* ------------------------------------------------------------ top bar & toolbar */
.topbar {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; gap: 8px;
  height: 58px; padding: 0 12px; padding-top: env(safe-area-inset-top);
  background: color-mix(in srgb, var(--surface) 92%, transparent);
  backdrop-filter: blur(10px); -webkit-backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--line);
}
.title-wrap { min-width: 0; flex: 0 1 360px; }
.title-input {
  width: 100%; height: 38px; border: 1px solid transparent; border-radius: 8px; background: transparent;
  padding: 0 8px; font-weight: 700; font-size: 18px; text-overflow: ellipsis;
}
.title-input:hover { border-color: var(--line); }
.title-input:focus { outline: none; border-color: var(--accent); background: var(--surface); }
.save-state { font-size: 12px; color: var(--muted); white-space: nowrap; }

.toolbar {
  display: flex; align-items: center; gap: 2px; padding: 6px 12px;
  background: var(--surface); border-bottom: 1px solid var(--line);
  overflow-x: auto; scrollbar-width: none;
  position: sticky; top: 58px; z-index: 19;
}
.toolbar::-webkit-scrollbar { display: none; }
.tool {
  display: inline-flex; align-items: center; gap: 6px; height: 36px; padding: 0 10px;
  border: 0; border-radius: 8px; background: transparent; color: var(--ink-2);
  font-size: 13.5px; font-weight: 600; cursor: pointer; white-space: nowrap; flex: none;
}
@media (hover: hover) { .tool:hover { background: var(--surface-2); color: var(--ink); } }
.tool[aria-pressed="true"] { background: var(--accent-soft); color: var(--accent); }
.tool:disabled { opacity: .35; pointer-events: none; }
.tool.accent { color: var(--accent); }
.tool.running, .btn.running { background: var(--bad-soft); color: var(--bad); border-color: var(--bad); }
.tgroup { display: inline-flex; gap: 2px; flex: none; }
.tgroup.pin { position: sticky; left: -12px; z-index: 1; background: var(--surface); padding-left: 12px; margin-left: -12px; box-shadow: 8px 0 8px -8px rgba(0,0,0,.15); }
.tsep { width: 1px; height: 22px; background: var(--line); margin: 0 6px; flex: none; }
.seg { display: inline-flex; background: var(--surface-2); border: 1px solid var(--line); border-radius: 10px; padding: 2px; gap: 2px; }
.seg .tool { height: 30px; }
.seg .tool[aria-pressed="true"] { background: var(--surface); color: var(--ink); box-shadow: var(--shadow); }
.show-sm, .show-sm-block { display: none !important; }

/* ------------------------------------------------------------ grid */
.grid-wrap { position: relative; }
.grid {
  --w: 15; --h: 15;
  display: grid;
  grid-template-columns: repeat(var(--w), minmax(0, 1fr));
  grid-template-rows: repeat(var(--h), minmax(0, 1fr));
  gap: 1px;
  width: 100%;
  aspect-ratio: var(--w) / var(--h);
  margin: 0 auto;
  background: var(--cell-line);
  border: 2px solid var(--cell-line);
  border-radius: 3px;
  user-select: none; -webkit-user-select: none;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
  cursor: pointer;
}
.cell {
  position: relative; background: var(--cell-bg); overflow: hidden; min-width: 0; min-height: 0;
  display: grid; place-items: center;
  font-family: var(--grid-font);
}
.cell .n {
  position: absolute; top: 1px; left: 2px; font-size: clamp(7px, calc(var(--cell) * .28), 17px); line-height: 1;
  font-weight: 500; color: var(--ink-2); pointer-events: none;
}
.cell .l {
  font-size: min(calc(var(--cell) * .6), 60px); line-height: 1; font-weight: 600; text-transform: uppercase;
  transform: translateY(calc(var(--cell) * .07)); pointer-events: none;
}
.cell.rb .l { font-size: calc(var(--cell) * .34); letter-spacing: -.02em; }
.cell.rb4 .l { font-size: calc(var(--cell) * .24); }
.cell.s { background: var(--cell-shade); }
.cell.h1 { background: var(--heat-1); }
.cell.h2 { background: var(--heat-2); }
.cell.x { background: var(--cell-cross); }
.cell.w { background: var(--cell-word); }
.cell.w.h1 { background: linear-gradient(var(--heat-1), var(--heat-1)) padding-box, var(--cell-word); box-shadow: inset 0 0 0 3px var(--cell-word); }
.cell.h0 { background: var(--heat-0); }
.cell.w.h0 { box-shadow: inset 0 0 0 3px var(--cell-word); }
.cell.sel { background: var(--cell-sel); }
.cell.sel.h0 { box-shadow: inset 0 0 0 3px var(--bad); }
.cell.b { background: var(--cell-block); }
.cell.b.sel { background: var(--cell-block); box-shadow: inset 0 0 0 3px var(--cell-sel); }
.cell.c::after {
  content: ''; position: absolute; inset: 1px; border-radius: 50%;
  border: 1px solid var(--ink-2); pointer-events: none;
}
.cell.auto .l { color: var(--cell-auto); }
.cell.mir { outline: 2px dashed var(--accent); outline-offset: -3px; }
.cell.mir.b { outline-color: var(--cell-sel); }
.cell.ghost .l { color: var(--muted); opacity: .6; }
.cell.pencil .l { color: var(--muted); font-weight: 400; }
.cell.bad::before {
  content: ''; position: absolute; left: -10%; right: -10%; top: 50%; height: 2px;
  background: var(--bad); transform: rotate(-45deg); opacity: .85;
}
.cell.bad .l { color: var(--bad); }
.cell.rev::before {
  content: ''; position: absolute; right: 0; top: 0; border-style: solid;
  border-width: 0 calc(var(--cell) * .28) calc(var(--cell) * .28) 0;
  border-color: transparent var(--bad) transparent transparent;
}
.cell.flash { animation: flash 1s ease-in-out 3; }
@keyframes flash { 50% { box-shadow: inset 0 0 0 3px var(--bad); } }
.cell.solved { animation: solvedWave .9s ease both; animation-delay: calc(var(--d, 0) * 1ms); }
@keyframes solvedWave { 40% { background: var(--good-soft); } }
.bld[data-mode="blocks"] .grid { cursor: crosshair; touch-action: none; }
.filling .grid { cursor: progress; }

/* ------------------------------------------------------------ builder layout */
.bld-main {
  display: grid; grid-template-columns: minmax(0, 1fr) minmax(340px, 400px);
  gap: 20px; padding: 16px 20px 24px; max-width: 1440px; margin: 0 auto; align-items: start;
}
.bld-gridcol { display: flex; flex-direction: column; gap: 12px; min-width: 0; }
.tips {
  display: flex; align-items: center; gap: 10px; padding: 10px 16px; margin: 12px 20px 0;
  background: var(--accent-soft); border-radius: var(--radius); color: var(--ink-2); font-size: 14px;
}
.tips > .ic { color: var(--accent); }
.tips p { flex: 1; }

.entry-bar {
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 10px 12px; display: grid; gap: 8px; box-shadow: var(--shadow);
  width: min(100%, max(var(--gw, 100%), 460px)); margin: 0 auto;
}
.eb-top { display: flex; align-items: center; gap: 10px; min-width: 0; }
.eb-label {
  display: inline-flex; align-items: center; gap: 6px; border: 0; cursor: pointer;
  background: var(--accent-soft); color: var(--accent); font-weight: 600; font-size: 14px;
  padding: 4px 10px; border-radius: 999px; white-space: nowrap;
}
.eb-label .ic { width: 14px; height: 14px; }
.eb-pattern { display: flex; gap: 2px; overflow: hidden; min-width: 0; }
.eb-pattern i {
  font-style: normal; font-family: var(--mono); font-weight: 700; font-size: 13px;
  flex: 0 1 18px; min-width: 9px; height: 22px; display: grid; place-items: center; border-radius: 4px; overflow: hidden;
  background: var(--surface-2); border: 1px solid var(--line); color: var(--ink-2);
}
.eb-pattern i.cur { background: var(--cell-sel); border-color: var(--cell-sel); color: #1b1d24; }
.eb-count { margin-left: auto; font-size: 12.5px; color: var(--muted); white-space: nowrap; }
.eb-count.warn { color: var(--warn); font-weight: 600; }
.eb-count.bad { color: var(--bad); font-weight: 700; }
.eb-clue {
  width: 100%; height: 42px; border: 1px solid var(--line-2); border-radius: 9px; padding: 0 12px;
  background: var(--surface-2);
}
.eb-clue:focus { outline: none; border-color: var(--accent); background: var(--surface); box-shadow: 0 0 0 3px var(--accent-soft); }
.eb-clue:disabled { opacity: .5; }
.eb-chips { display: flex; gap: 6px; overflow-x: auto; scrollbar-width: none; min-height: 30px; }
.eb-chips::-webkit-scrollbar { display: none; }
.chip {
  display: inline-flex; align-items: center; gap: 5px; height: 30px; padding: 0 10px; flex: none;
  border-radius: 999px; border: 1px solid var(--line-2); background: var(--surface);
  font: 600 13px/1 var(--mono); letter-spacing: .04em; cursor: pointer; color: var(--ink); text-decoration: none;
}
.chip:hover { border-color: var(--accent); color: var(--accent); }
.chip .ic { width: 14px; height: 14px; }
.chip.mem, .chip.add, .chip.ghosty { font-family: var(--font); letter-spacing: 0; font-weight: 500; }
.chip.add { border-color: var(--warn); color: var(--warn); }
.chip.ghosty { color: var(--muted); border-style: dashed; }
.chip-note { font-size: 13px; align-self: center; }
.bad { color: var(--bad); }
.entry-bar.none .eb-label { background: var(--surface-2); color: var(--muted); }

.fillbar {
  display: flex; align-items: center; gap: 10px; justify-content: center;
  padding: 8px 12px; border-radius: var(--radius); background: var(--accent-soft); color: var(--accent); font-weight: 600;
}
.spin {
  width: 16px; height: 16px; border-radius: 50%; border: 2px solid currentColor; border-right-color: transparent;
  animation: spin .7s linear infinite; display: inline-block; vertical-align: -3px;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ------------------------------------------------------------ side panel */
.panel {
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow);
  position: sticky; top: 124px; max-height: calc(100dvh - 140px); display: flex; flex-direction: column; overflow: hidden;
}
.tabs { display: flex; border-bottom: 1px solid var(--line); padding: 4px; gap: 2px; flex: none; }
.tabs button {
  flex: 1; display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  height: 40px; border: 0; background: transparent; border-radius: 8px; cursor: pointer;
  font-weight: 600; font-size: 14px; color: var(--muted); position: relative;
}
.tabs button:hover { color: var(--ink); background: var(--surface-2); }
.tabs button[aria-selected="true"] { color: var(--ink); background: var(--surface-2); }
.tabs button[aria-selected="true"]::after {
  content: ''; position: absolute; left: 20%; right: 20%; bottom: -5px; height: 2px; background: var(--accent); border-radius: 2px;
}
.tabs .ic { width: 16px; height: 16px; }
.badge { font-style: normal; font-size: 11px; min-width: 18px; height: 18px; padding: 0 5px; border-radius: 9px; background: var(--surface-2); border: 1px solid var(--line); display: inline-grid; place-items: center; color: var(--muted); }
.badge:empty { display: none; }
.badge.bad { background: var(--bad); border-color: var(--bad); color: #fff; }
.badge.good { background: var(--good-soft); border-color: transparent; color: var(--good); }
.tabpane { overflow-y: auto; padding: 14px; flex: 1; min-height: 0; overscroll-behavior: contain; }

.pane-actions { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 14px; }
.pane-actions .btn.ghost { margin-left: auto; color: var(--muted); font-weight: 500; }
.sugg-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-bottom: 8px; }
.sugg-filter { width: 120px; height: 34px; border: 1px solid var(--line-2); border-radius: 8px; padding: 0 10px; background: var(--surface-2); font-size: 16px; transform-origin: right center; }
.sugg-list, .finder-list, .clue-list, .pl-list, .issues { list-style: none; margin: 0; padding: 0; }
.sugg-list li { display: flex; align-items: center; border-radius: 8px; }
.sugg-list li:hover { background: var(--surface-2); }
.sugg-list li.empty { display: block; }
.sugg-list li.more-row { justify-content: center; padding: 8px 0; }
.sugg-list li.more-row:hover { background: none; }
.sg-row {
  flex: 1; display: grid; grid-template-columns: 1fr auto 56px; align-items: center; gap: 10px;
  height: 36px; padding: 0 8px; border: 0; background: none; cursor: pointer; text-align: left; min-width: 0;
}
.sg-w { font: 600 15px var(--mono); letter-spacing: .06em; overflow: hidden; text-overflow: ellipsis; }
.sg-meta { font-size: 12px; color: var(--bad); white-space: nowrap; }
.meter { height: 5px; border-radius: 3px; background: var(--line); overflow: hidden; display: block; }
.meter i { display: block; height: 100%; background: var(--good); border-radius: 3px; }
.sugg-list li.dead .sg-w { color: var(--muted); text-decoration: line-through; text-decoration-color: var(--bad); }
.sugg-list li.dead .meter i { background: var(--muted); }
.sg-ban { width: 30px; height: 30px; opacity: 0; color: var(--muted); }
.sg-ban .ic { width: 15px; height: 15px; }
.sugg-list li:hover .sg-ban, .sg-ban:focus { opacity: 1; }
.empty { padding: 14px 8px; color: var(--muted); font-size: 14px; }
.empty.bad { color: var(--bad); }
.finder { margin-top: 16px; border-top: 1px solid var(--line); padding-top: 10px; }
.finder summary { cursor: pointer; font-weight: 600; display: flex; flex-wrap: wrap; align-items: center; gap: 6px; list-style: none; padding: 4px 0; }
.finder summary::-webkit-details-marker { display: none; }
.finder summary .muted { font-weight: 400; }
.finder-q { width: 100%; height: 40px; margin: 8px 0 4px; border: 1px solid var(--line-2); border-radius: 8px; padding: 0 10px; background: var(--surface-2); font-family: var(--mono); }
.finder-list li { display: grid; grid-template-columns: 1fr auto 50px; gap: 10px; align-items: center; padding: 5px 8px; font: 600 14px var(--mono); letter-spacing: .05em; }
.finder-list li:nth-child(odd) { background: var(--surface-2); border-radius: 6px; }
.wl-foot { margin-top: 16px; }

/* clues tab */
.clue-cols { display: grid; gap: 18px; }
.clue-cols h3 { font-size: 13px; text-transform: uppercase; letter-spacing: .08em; color: var(--muted); margin: 0 0 6px; }
.clue-list li { display: flex; gap: 8px; align-items: flex-start; padding: 6px; border-radius: 8px; }
.clue-list li.cur { background: var(--accent-soft); }
.cl-num {
  width: 30px; height: 30px; flex: none; border: 0; border-radius: 6px; background: var(--surface-2); font-weight: 700; cursor: pointer; font-size: 13px;
}
.clue-list li.cur .cl-num { background: var(--accent); color: var(--accent-ink); }
.cl-body { flex: 1; min-width: 0; display: grid; gap: 3px; }
.cl-ans { font: 600 12px var(--mono); letter-spacing: .12em; color: var(--muted); cursor: pointer; }
.cl-in { width: 100%; height: 36px; border: 1px solid var(--line); border-radius: 7px; padding: 0 9px; background: var(--surface); }
.cl-in:focus { outline: none; border-color: var(--accent); }
.clue-list li.missing .cl-in { border-color: var(--line-2); border-style: dashed; }

/* check tab */
.ready {
  display: flex; gap: 12px; align-items: center; padding: 14px; border-radius: var(--radius);
  background: var(--good-soft); color: var(--good); margin-bottom: 14px;
}
.ready > .ic { width: 28px; height: 28px; }
.ready p { color: var(--ink-2); font-size: 13px; }
.ready div { flex: 1; }
.progress-sum { display: grid; gap: 6px; margin-bottom: 14px; font-size: 13px; color: var(--muted); }
.bar { height: 8px; background: var(--line); border-radius: 4px; overflow: hidden; }
.bar i { display: block; height: 100%; background: var(--accent); border-radius: 4px; transition: width .3s; }
.quality { background: var(--surface-2); border-radius: var(--radius); padding: 12px; margin-bottom: 12px; display: grid; gap: 8px; }
.q-head { display: flex; gap: 12px; align-items: center; }
.q-head div { display: grid; }
.q-score { width: 44px; height: 44px; border-radius: 50%; display: grid; place-items: center; font: 700 17px var(--mono); flex: none; }
.q-score.good { background: var(--good-soft); color: var(--good); }
.q-score.warn { background: var(--warn-soft); color: var(--warn); }
.q-score.bad { background: var(--bad-soft); color: var(--bad); }
.weak { display: flex; flex-wrap: wrap; gap: 6px; }
.weak-chip small { font: 600 10px var(--font); color: var(--warn); margin-left: 2px; }
.issues li button {
  width: 100%; display: grid; grid-template-columns: 10px 1fr auto; gap: 10px; align-items: start;
  text-align: left; padding: 10px; border: 0; background: none; border-radius: 9px; cursor: pointer;
}
.issues li button:hover { background: var(--surface-2); }
.issues li button:disabled { cursor: default; background: none; }
.issues .dot { width: 10px; height: 10px; border-radius: 50%; margin-top: 5px; background: var(--muted); }
.issues .lv-error .dot { background: var(--bad); }
.issues .lv-warn .dot { background: var(--warn); }
.issues .lv-todo .dot { background: var(--accent); }
.iss-text { display: grid; gap: 2px; }
.iss-text small { color: var(--muted); font-size: 12.5px; }
.issues em { font-style: normal; font-size: 11px; color: var(--muted); white-space: nowrap; margin-top: 3px; }
.rules { margin-top: 12px; font-size: 13.5px; color: var(--ink-2); }
.rules summary { cursor: pointer; font-weight: 600; padding: 6px 0; }
.rules ul { margin: 6px 0 0; padding-left: 20px; display: grid; gap: 4px; }

/* details tab */
.form { display: grid; gap: 12px; }
.field { display: grid; gap: 5px; font-size: 13px; font-weight: 600; color: var(--ink-2); }
.field small { font-weight: 400; }
.field input, .field textarea, .field select {
  width: 100%; border: 1px solid var(--line-2); border-radius: 9px; padding: 9px 11px; background: var(--surface); font-weight: 400;
}
.field input, .field select { height: 42px; padding: 0 11px; }
.field textarea { resize: vertical; min-height: 60px; font-family: var(--mono); font-size: 16px; }
.field input:focus, .field textarea:focus, .field select:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.info-body h3 { font-size: 15px; margin: 22px 0 10px; }
.info-body h4 { font-size: 13px; margin: 16px 0 8px; color: var(--muted); font-weight: 600; }
.statgrid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 8px; }
.statgrid div { background: var(--surface-2); border-radius: 9px; padding: 9px 11px; display: grid; gap: 2px; }
.statgrid b { font-size: 18px; }
.statgrid span { font-size: 12px; color: var(--muted); }
.statgrid .warn b { color: var(--warn); }
.hist { display: flex; align-items: flex-end; gap: 4px; margin-bottom: 4px; }
.hist div { flex: 1; display: flex; flex-direction: column; align-items: stretch; gap: 2px; text-align: center; font-size: 11px; color: var(--muted); }
.hist i { display: block; background: var(--accent); border-radius: 3px 3px 0 0; opacity: .8; }
.hist b { font-size: 10px; color: var(--ink-2); font-weight: 600; }
.hist span { border-top: 1px solid var(--line-2); padding-top: 2px; }
.share-grid { display: flex; flex-wrap: wrap; gap: 8px; }
.row2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }

/* ------------------------------------------------------------ keyboard */
.kb-host, .kb { display: none; }
/* .touch is set on <html> by app.js (coarse pointer, or ?touch for testing). */
.touch .kb-host { display: block; position: sticky; bottom: 0; z-index: 15; }
.touch .typing .kb-host { display: none; }
@media all {
  .touch .kb {
    display: grid; gap: 6px;
    padding: 8px 4px calc(8px + env(safe-area-inset-bottom));
    background: color-mix(in srgb, var(--surface-2) 94%, transparent);
    backdrop-filter: blur(10px); -webkit-backdrop-filter: blur(10px);
    border-top: 1px solid var(--line);
  }
}
.kb-row { display: flex; gap: 5px; justify-content: center; }
.key {
  flex: 1; max-width: 44px; height: 46px; border: 0; border-radius: 7px;
  background: var(--surface); color: var(--ink); font: 600 19px var(--grid-font);
  box-shadow: 0 1px 0 var(--line-2); touch-action: manipulation; padding: 0;
  display: grid; place-items: center; cursor: pointer;
}
.key.wide { flex: 1.5; max-width: 66px; background: var(--line); }
.key small { font-size: 11px; font-weight: 700; }
.key.down { background: var(--accent-soft); transform: scale(.96); }
.key .ic { width: 20px; height: 20px; }

/* ------------------------------------------------------------ player */
.ply-title { display: grid; min-width: 0; line-height: 1.2; }
.ply-title b { font-size: 16px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.ply-title small { color: var(--muted); font-size: 12px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.timer {
  display: inline-flex; align-items: center; gap: 6px; height: 34px; padding: 0 10px; border-radius: 999px;
  border: 1px solid var(--line); background: var(--surface-2); font: 600 14px var(--mono); cursor: pointer; color: var(--ink-2);
}
.timer .ic { width: 14px; height: 14px; }
.test-banner {
  display: flex; align-items: center; gap: 10px; padding: 8px 16px; background: var(--warn-soft); color: var(--ink-2); font-size: 13.5px;
}
.test-banner > .ic { color: var(--warn); }
.test-banner span { flex: 1; }
.ply-main {
  display: grid; grid-template-columns: minmax(0, 1.3fr) minmax(300px, 1fr); gap: 24px; padding: 16px 20px 24px;
  max-width: 1300px; margin: 0 auto; align-items: start;
}
.ply-gridcol { display: flex; flex-direction: column; gap: 12px; min-width: 0; }
.cluebar {
  display: flex; align-items: center; gap: 4px; background: var(--accent-soft); border-radius: var(--radius);
  min-height: 56px; padding: 4px;
  width: min(100%, max(var(--gw, 100%), 360px)); margin: 0 auto;
}
.cb-text { flex: 1; display: flex; gap: 10px; align-items: baseline; padding: 6px 4px; cursor: pointer; min-width: 0; font-size: 16px; }
.cb-text b { color: var(--accent); flex: none; }
.ply-clues { display: grid; grid-template-columns: 1fr 1fr; gap: 20px; min-width: 0; }
.ply-clues h3 { font-size: 13px; text-transform: uppercase; letter-spacing: .08em; color: var(--muted); margin: 4px 0 8px; padding-bottom: 6px; border-bottom: 1px solid var(--line); }
.pl-list { max-height: calc(100dvh - 190px); overflow-y: auto; overscroll-behavior: contain; position: relative; }
.pl-list li {
  display: grid; grid-template-columns: 28px 1fr; gap: 6px; padding: 6px 8px; border-radius: 8px; cursor: pointer;
  border-left: 3px solid transparent;
}
.pl-list li:hover { background: var(--surface); }
.pl-list li b { text-align: right; }
.pl-list li.cur { background: var(--cell-word); }
.pl-list li.crs { border-left-color: var(--accent); }
.pl-list li.done span { color: var(--muted); }
.cover {
  position: absolute; inset: 0; display: grid; place-items: center; z-index: 5;
  background: color-mix(in srgb, var(--bg) 70%, transparent); backdrop-filter: blur(9px); -webkit-backdrop-filter: blur(9px);
  border-radius: 4px;
}
.cover-card {
  background: var(--surface); border-radius: 16px; padding: 24px; box-shadow: var(--shadow-lg);
  display: grid; gap: 8px; text-align: center; justify-items: center; max-width: min(92%, 380px);
}
.cover-card .btn { margin-top: 8px; }
.cover-card .note { display: flex; gap: 8px; text-align: left; background: var(--surface-2); padding: 10px; border-radius: 10px; font-size: 14px; }
.paused .ply-clues span { filter: blur(5px); }
.pencil-on .tool[data-act="pencil"] { background: var(--accent-soft); color: var(--accent); }

/* ------------------------------------------------------------ library */
.lib { max-width: 1120px; margin: 0 auto; padding: 0 20px 40px; }
.lib-head { display: flex; align-items: center; justify-content: space-between; padding: 18px 0; padding-top: calc(18px + env(safe-area-inset-top)); }
.brand { display: flex; align-items: center; gap: 10px; }
.brand h1 { font-size: 20px; letter-spacing: -.01em; }
.home-link { color: var(--muted); text-decoration: none; font-size: 14px; }
.home-link:hover { color: var(--ink); }
.hero {
  display: grid; grid-template-columns: 1fr auto; gap: 32px; align-items: center;
  background: var(--surface); border: 1px solid var(--line); border-radius: 20px; padding: 32px; box-shadow: var(--shadow);
}
.hero h2 { font-size: clamp(26px, 4vw, 38px); letter-spacing: -.02em; margin-bottom: 10px; }
.hero p { color: var(--ink-2); max-width: 540px; font-size: 16px; }
.hero-actions { display: flex; gap: 10px; flex-wrap: wrap; margin-top: 22px; }
.art {
  display: grid; grid-template-columns: repeat(5, 36px); grid-auto-rows: 36px; gap: 2px;
  background: var(--cell-line); border: 2px solid var(--cell-line); border-radius: 4px; transform: rotate(3deg);
}
.art i {
  background: var(--cell-bg); display: grid; place-items: center; font: 700 18px var(--grid-font); font-style: normal;
  animation: artIn .5s both; animation-delay: calc(var(--k) * 35ms);
}
.art i.b { background: var(--cell-block); }
.art i:nth-child(7), .art i:nth-child(8), .art i:nth-child(9) { background: var(--cell-word); }
.art i:nth-child(7) { background: var(--cell-sel); }
@keyframes artIn { from { opacity: 0; transform: scale(.6); } }
.shelf { margin-top: 30px; }
.shelf-head { display: flex; align-items: baseline; gap: 8px; margin-bottom: 12px; }
.shelf-head h3 { font-size: 17px; }
.cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 14px; }
.card {
  background: var(--surface); border: 1px solid var(--line); border-radius: 16px; overflow: hidden;
  display: flex; flex-direction: column; box-shadow: var(--shadow); transition: transform .12s, box-shadow .12s;
}
.card:hover { transform: translateY(-2px); box-shadow: var(--shadow-lg); }
.card-main { display: flex; gap: 14px; padding: 14px; text-decoration: none; color: inherit; flex: 1; }
.thumb { width: 84px; height: 84px; flex: none; display: grid; place-items: center; }
.thumb svg { width: 100%; height: 100%; }
.thumb .tw { fill: var(--cell-bg); stroke: var(--cell-line); stroke-width: .12; }
.thumb .tb { fill: var(--cell-block); }
.thumb .tf { fill: var(--cell-word); }
.card-text { display: grid; gap: 4px; align-content: start; min-width: 0; }
.card-text b { font-size: 16px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.status { font-size: 12px; font-weight: 600; color: var(--muted); background: var(--surface-2); border-radius: 999px; padding: 3px 9px; justify-self: start; margin-top: 4px; }
.status.good { background: var(--good-soft); color: var(--good); }
.status.prog { background: var(--accent-soft); color: var(--accent); }
.card-actions { display: flex; gap: 6px; align-items: center; padding: 10px 14px; border-top: 1px solid var(--line); background: var(--surface-2); }
.card-actions .icon-btn { margin-left: auto; width: 32px; height: 32px; }
.empty-card { border: 2px dashed var(--line-2); border-radius: 16px; padding: 24px; display: grid; gap: 14px; justify-items: start; color: var(--ink-2); }
.empty-line { padding: 4px 0; }
.lib-foot { margin-top: 40px; padding-top: 18px; border-top: 1px solid var(--line); display: flex; gap: 18px; flex-wrap: wrap; align-items: center; }

/* ------------------------------------------------------------ dialogs, menus, toast */
.dlg {
  border: 0; padding: 0; border-radius: 18px; background: var(--surface); color: var(--ink);
  width: min(560px, calc(100vw - 24px)); max-height: calc(100dvh - 32px); box-shadow: var(--shadow-lg);
}
.dlg.small { width: min(430px, calc(100vw - 24px)); }
.dlg.wide { width: min(720px, calc(100vw - 24px)); }
.dlg::backdrop { background: rgba(10, 12, 20, .45); backdrop-filter: blur(3px); }
.dlg[open] { animation: dlgIn .18s ease-out; }
@keyframes dlgIn { from { opacity: 0; transform: translateY(10px) scale(.98); } }
.dlg-inner { padding: 22px; display: grid; gap: 14px; }
.dlg h2 { font-size: 20px; display: flex; align-items: center; gap: 8px; }
.dlg h2 .ic { width: 22px; height: 22px; color: var(--accent); }
.dlg h3 { font-size: 15px; margin-top: 4px; }
.dlg-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 6px; flex-wrap: wrap; }
.dlg-actions.center { justify-content: center; }
.note { display: flex; gap: 10px; padding: 10px 12px; border-radius: 10px; font-size: 14px; align-items: flex-start; }
.note.warn { background: var(--warn-soft); }
.note .ic { margin-top: 2px; color: var(--warn); }
.linkbox { display: flex; gap: 8px; }
.linkbox input { flex: 1; min-width: 0; height: 42px; border: 1px solid var(--line-2); border-radius: 9px; padding: 0 10px; background: var(--surface-2); font-family: var(--mono); font-size: 16px; }
.dlg p.small .ic { width: 14px; height: 14px; vertical-align: -2px; }
.steps { margin: 0; padding-left: 22px; display: grid; gap: 8px; }
.keys { border-collapse: collapse; width: 100%; font-size: 14px; }
.keys td { padding: 6px 4px; border-bottom: 1px solid var(--line); }
.keys td:first-child { white-space: nowrap; width: 1%; padding-right: 16px; }
.rebus-in { height: 52px; font: 700 24px var(--mono); text-transform: uppercase; letter-spacing: .1em; text-align: center; border: 1px solid var(--line-2); border-radius: 10px; background: var(--surface-2); }
.sizes { display: grid; grid-template-columns: repeat(auto-fill, minmax(92px, 1fr)); gap: 8px; }
.size {
  display: grid; justify-items: center; gap: 4px; padding: 12px 6px 10px; border-radius: 12px;
  border: 1.5px solid var(--line); background: var(--surface); cursor: pointer;
}
.size small { color: var(--muted); font-size: 12px; }
.size[aria-pressed="true"] { border-color: var(--accent); background: var(--accent-soft); }
.size-grid {
  width: 36px; height: 36px; border: 1.5px solid var(--ink-2); border-radius: 3px;
  background-image: linear-gradient(var(--line-2) 1px, transparent 1px), linear-gradient(90deg, var(--line-2) 1px, transparent 1px);
  background-size: calc(100% / var(--n)) calc(100% / var(--n));
}
.size-grid.custom { display: grid; place-items: center; font-weight: 700; color: var(--muted); background: none; border-style: dashed; }
.start { border: 0; padding: 0; margin: 0; display: grid; gap: 8px; }
.start legend { font-size: 13px; font-weight: 600; color: var(--ink-2); margin-bottom: 6px; }
.radio { display: flex; gap: 10px; align-items: flex-start; padding: 10px 12px; border: 1.5px solid var(--line); border-radius: 12px; cursor: pointer; }
.radio:has(input:checked) { border-color: var(--accent); background: var(--accent-soft); }
.radio input { margin-top: 3px; accent-color: var(--accent); }
.radio span { display: grid; gap: 2px; }
.radio small { color: var(--muted); }
.or { display: flex; align-items: center; gap: 10px; color: var(--muted); font-size: 13px; }
.or::before, .or::after { content: ''; flex: 1; height: 1px; background: var(--line); }

.menu {
  position: fixed; z-index: 100; min-width: 220px; max-width: min(340px, calc(100vw - 16px));
  background: var(--surface); border: 1px solid var(--line); border-radius: 12px; padding: 6px;
  box-shadow: var(--shadow-lg); animation: dlgIn .12s ease-out;
}
.menu-item {
  width: 100%; display: flex; align-items: center; gap: 10px; min-height: 40px; padding: 6px 10px; border: 0;
  background: none; border-radius: 8px; cursor: pointer; text-align: left; font-size: 14px;
}
.menu-item:hover, .menu-item:focus-visible { background: var(--surface-2); outline: none; }
.menu-item:disabled { opacity: .55; cursor: default; background: none; font-size: 12.5px; }
.menu-item.danger { color: var(--bad); }
.menu-item .ic { color: var(--muted); }
.menu-item.danger .ic { color: var(--bad); }
.menu-check { width: 18px; display: grid; place-items: center; color: var(--accent); flex: none; }
.menu-check .ic { color: var(--accent); }
.menu-label { display: grid; gap: 1px; }
.menu-label small { color: var(--muted); font-size: 12px; }
.menu-sep { height: 1px; background: var(--line); margin: 5px 4px; }
.menu-h { font-size: 11px; font-weight: 700; text-transform: uppercase; letter-spacing: .08em; color: var(--muted); padding: 8px 10px 4px; }

.toast {
  position: fixed; left: 12px; right: 12px; margin: 0 auto; width: fit-content; bottom: calc(24px + env(safe-area-inset-bottom)); z-index: 200;
  transform: translateY(20px); opacity: 0; pointer-events: none;
  display: flex; align-items: center; gap: 14px; max-width: 560px;
  background: #1f2128; color: #f2f3f6; padding: 11px 16px; border-radius: 12px; box-shadow: var(--shadow-lg);
  font-size: 14px; transition: opacity .18s, transform .18s;
}
.toast.show { opacity: 1; transform: none; pointer-events: auto; }
.toast.bad { background: #8f2424; }
.toast button { border: 0; background: none; color: #9fb4ff; font-weight: 700; cursor: pointer; padding: 4px; white-space: nowrap; }
.touch body[data-view="edit"] .toast, .touch body[data-view="play"] .toast, .touch body[data-view="test"] .toast { bottom: calc(210px + env(safe-area-inset-bottom)); }

/* celebration */
.solved-dlg { overflow: hidden; }
.celebrate { text-align: center; display: grid; gap: 6px; justify-items: center; position: relative; }
.trophy { width: 64px; height: 64px; border-radius: 50%; background: var(--good); color: #fff; display: grid; place-items: center; animation: pop .5s cubic-bezier(.3, 1.6, .5, 1) both; }
.trophy .ic { width: 34px; height: 34px; stroke-width: 3; }
.celebrate h2 { font-size: 28px; justify-content: center; }
.big-time { font: 700 34px var(--mono); }
@keyframes pop { from { transform: scale(0); } }
.confetti { position: absolute; inset: 0; pointer-events: none; overflow: hidden; }
.confetti i {
  position: absolute; top: -12px; left: var(--x); width: 8px; height: 14px; border-radius: 2px;
  background: hsl(var(--h) 85% 60%); animation: fall 1.8s ease-in var(--d) both;
}
@keyframes fall { to { transform: translateY(460px) rotate(540deg); opacity: 0; } }

/* ------------------------------------------------------------ responsive */
@media (max-width: 1100px) {
  .ply-main { grid-template-columns: 1fr; }
  .ply-clues { max-width: 720px; margin: 0 auto; width: 100%; }
  .pl-list { max-height: 360px; }
}
@media (max-width: 900px) {
  .bld-main { grid-template-columns: 1fr; padding: 10px 10px 16px; gap: 12px; }
  .panel { position: static; max-height: none; }
  .tabpane { max-height: none; }
  .entry-bar { order: 2; }
  .grid-wrap { order: 1; }
  .fillbar { order: 3; }
  .tips { margin: 10px 10px 0; }
  .hide-sm { display: none !important; }
  .show-sm { display: inline-flex !important; }
  .show-sm-block { display: block !important; }
  .tips { padding: 8px 12px; font-size: 13.5px; }
  .toolbar { padding: 4px 6px; gap: 0; }
  .tgroup.pin { left: -6px; padding-left: 6px; margin-left: -6px; }
  .toolbar .tool { flex-direction: column; gap: 2px; height: 50px; min-width: 56px; padding: 4px 6px; font-size: 11px; font-weight: 600; }
  .seg .tool { height: 46px; }
  .tsep { height: 34px; margin: 0 3px; }
  .topbar .btn { padding: 0 11px; }
  .toolbar { top: 58px; }
  .panel .tabs { position: sticky; top: 0; }
  .ply-main { padding: 8px 8px 16px; gap: 14px; }
  .ply .topbar .tool { flex-direction: column; gap: 1px; height: 46px; min-width: 44px; padding: 3px 4px; font-size: 10.5px; }
  .hero { grid-template-columns: 1fr; padding: 22px; }
  .hero-art { display: none; }
}
@media (max-width: 520px) {
  .topbar { padding: 0 6px; gap: 4px; }
  .title-input { font-size: 16px; }
  .save-state { display: none; }
  .lib { padding: 0 14px 30px; }
  .timer { padding: 0 8px; }
  .cards { grid-template-columns: 1fr; }
  .ply .topbar .tool { min-width: 38px; }
  .ply .topbar .tool .lbl { display: none; }
  .ply-title small { display: none; }
  .ply .topbar { gap: 0; }
  .test-banner { padding: 6px 10px; }
  .ply-clues { grid-template-columns: 1fr; }
  .sg-row { grid-template-columns: 1fr auto 40px; }
}

/* ------------------------------------------------------------ print */
#print-root { display: none; }
@media print {
  body.printing > *:not(#print-root) { display: none !important; }
  body.printing { background: #fff; }
  body.printing #print-root { display: block; color: #000; font: 11pt/1.35 Georgia, serif; }
  #print-root header h1 { font: 700 20pt var(--font); }
  #print-root header p { margin: 2px 0 8px; }
  #print-root .pn { font-style: italic; }
  .pgrid {
    display: grid; grid-template-columns: repeat(var(--w), 1fr); width: min(100%, 6.5in);
    border: 1.5pt solid #000; margin: 10px 0 14px; aspect-ratio: var(--w) / var(--h);
  }
  .pc { position: relative; border: .5pt solid #000; display: grid; place-items: center; font: 700 14pt Helvetica, Arial, sans-serif; }
  .pc span { position: absolute; top: 1px; left: 2px; font: 7pt Helvetica, Arial, sans-serif; }
  .pc.b { background: #000; }
  .pc.s { background: #ddd; }
  .pc.c::after { content: ''; position: absolute; inset: 1px; border: .5pt solid #000; border-radius: 50%; }
  .pclues { columns: 2; column-gap: 24px; }
  .pclues h3 { font: 700 12pt var(--font); margin: 6px 0; }
  .pclues ol { list-style: none; padding: 0; margin: 0 0 10px; }
  .pclues li { break-inside: avoid; margin-bottom: 3px; }
  .pclues li b { display: inline-block; min-width: 22px; }
}
