:root {
  --bg: #0f1a2e;
  --bg-2: #16243d;
  --tile: #e9dcc0;
  --tile-ink: #13203a;
  --paper: #efe4cb;
  --paper-2: #e6d8b8;
  --ink: #1d1b16;
  --muted: #6d6250;
  --line: #cdbb94;
  --cream: #f3ead6;
  --radius: 10px;
  --f1: #c0392b; --f2: #1f6fb2; --f3: #2e7d4f; --f4: #8e44ad;
  --f5: #d35400; --f6: #0e7c86; --mine: #c2185b; --line-o: #8a6d12;
  --safe-b: env(safe-area-inset-bottom, 0px);
}
body.theme-burgundy { --bg: #3d0c11; --bg-2: #521419; --tile-ink: #4a1016; }
body.theme-navy { --bg: #0f1a2e; --bg-2: #16243d; --tile-ink: #13203a; }

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  background: var(--bg);
  background-image: radial-gradient(ellipse at top, rgba(255,255,255,.06), transparent 60%);
  background-attachment: fixed;
  color: var(--cream);
  font-family: "Source Serif 4", Georgia, serif;
  font-size: 16px;
  min-height: 100vh;
  -webkit-tap-highlight-color: transparent;
}
button { font: inherit; color: inherit; cursor: pointer; }
a { color: inherit; }
.wrap { max-width: 980px; margin: 0 auto; padding: 16px 14px 120px; }
.hidden { display: none !important; }

/* ---------- tile wordmark ---------- */
.mark { display: flex; flex-direction: column; align-items: center; gap: 6px; margin: 18px 0 8px; }
.mark .row { display: flex; gap: 5px; }
.tile {
  font-family: "Roboto Slab", serif; font-weight: 700;
  display: inline-grid; place-items: center;
  background: var(--tile); color: var(--tile-ink);
  border-radius: 5px; box-shadow: 0 3px 0 rgba(0,0,0,.35), inset 0 0 0 1px rgba(0,0,0,.08);
  width: 1.55em; height: 1.75em; font-size: 22px;
}
.tile.dark { background: var(--bg-2); color: var(--tile); box-shadow: 0 3px 0 rgba(0,0,0,.45), inset 0 0 0 1px rgba(255,255,255,.08); }
.tile.sm { font-size: 13px; }
.mark .sub { font-family: "Roboto Slab", serif; letter-spacing: .35em; font-size: 12px; opacity: .8; margin-top: 6px; text-transform: uppercase; }

/* ---------- top bar ---------- */
.topbar { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 10px 14px; position: sticky; top: 0; z-index: 20; background: color-mix(in srgb, var(--bg) 92%, transparent); backdrop-filter: blur(6px); border-bottom: 1px solid rgba(255,255,255,.08); }
.topbar .title { font-family: "Roboto Slab", serif; font-weight: 700; letter-spacing: .08em; text-transform: uppercase; font-size: 14px; text-align: center; flex: 1; line-height: 1.2; }
.topbar .title small { display: block; font-weight: 500; letter-spacing: .14em; opacity: .7; font-size: 11px; }
.iconbtn { background: transparent; border: 1px solid rgba(255,255,255,.18); border-radius: 8px; padding: 7px 10px; min-width: 40px; font-size: 14px; }
.iconbtn:disabled { opacity: .3; cursor: default; }
.linkbtn { background: none; border: none; text-decoration: underline; padding: 4px; opacity: .85; }

/* ---------- forms ---------- */
.card { background: var(--paper); color: var(--ink); border-radius: var(--radius); padding: 20px; box-shadow: 0 8px 30px rgba(0,0,0,.35); }
.auth { max-width: 400px; margin: 10px auto; }
.tabs { display: flex; gap: 6px; margin-bottom: 14px; }
.tabs button { flex: 1; padding: 9px; border-radius: 8px; border: 1px solid var(--line); background: transparent; color: var(--ink); }
.tabs button.on { background: var(--tile-ink); color: var(--cream); border-color: var(--tile-ink); }
label { display: block; font-size: 13px; color: var(--muted); margin: 10px 0 4px; }
input[type=email], input[type=password], input[type=text], input[type=search] {
  width: 100%; padding: 11px 12px; border-radius: 8px; border: 1px solid var(--line); background: #fbf6ea; font: inherit; color: var(--ink);
}
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 8px; padding: 11px 16px; border-radius: 9px; border: none; background: var(--tile-ink); color: var(--cream); font-weight: 600; }
.btn.block { width: 100%; margin-top: 16px; }
.btn.light { background: var(--tile); color: var(--tile-ink); }
.btn.ghost { background: transparent; border: 1px solid rgba(255,255,255,.25); color: var(--cream); }
.btn:disabled { opacity: .45; cursor: default; }
.msg { font-size: 14px; margin-top: 12px; color: var(--muted); }
.msg.err { color: #a12a1e; }
.note { text-align: center; opacity: .75; font-size: 14px; margin: 18px auto; max-width: 520px; line-height: 1.5; }

/* ---------- library ---------- */
.shelf { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 22px; margin-top: 18px; }
.book { background: none; border: none; padding: 0; text-align: left; }
.book img { width: 100%; aspect-ratio: 2/3; object-fit: cover; border-radius: 4px 8px 8px 4px; box-shadow: 0 12px 30px rgba(0,0,0,.5); display: block; }
.book .meta { margin-top: 10px; font-family: "Roboto Slab", serif; }
.book .meta b { display: block; }
.book .meta span { opacity: .7; font-size: 13px; }
.book.locked img { filter: grayscale(.85) brightness(.55); }
.badge { display: inline-block; font-size: 11px; letter-spacing: .08em; text-transform: uppercase; padding: 3px 8px; border-radius: 20px; background: rgba(255,255,255,.12); margin-top: 6px; }
.pending { border: 1px dashed rgba(255,255,255,.3); border-radius: var(--radius); padding: 16px; text-align: center; margin-top: 14px; line-height: 1.5; }

/* ---------- volume ---------- */
.progressbar { height: 6px; background: rgba(255,255,255,.12); border-radius: 6px; overflow: hidden; margin: 6px 0 4px; }
.progressbar > i { display: block; height: 100%; background: var(--tile); }
.mm-card { display: flex; align-items: center; justify-content: space-between; gap: 14px; padding: 16px; border-radius: var(--radius); background: var(--bg-2); border: 1px solid rgba(255,255,255,.1); margin: 16px 0; }
.mm-card h3 { margin: 0 0 4px; font-family: "Roboto Slab", serif; font-size: 16px; letter-spacing: .05em; }
.mm-card p { margin: 0; opacity: .75; font-size: 14px; }
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(86px, 1fr)); gap: 8px; }
a.cell, a.btn { text-decoration: none; color: inherit; }
a.btn { color: var(--cream); }
a.btn.light { color: var(--tile-ink); }
.cell { background: var(--bg-2); border: 1px solid rgba(255,255,255,.1); border-radius: 8px; padding: 8px 6px; text-align: center; min-height: 62px; display: flex; flex-direction: column; justify-content: center; gap: 2px; }
.cell .no { font-family: "Roboto Slab", serif; font-weight: 700; font-size: 15px; }
.cell .nm { font-family: "Patrick Hand", cursive; font-size: 15px; color: var(--tile); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.cell .st { font-size: 11px; opacity: .6; }
.cell.solved { background: var(--tile); color: var(--tile-ink); }
.cell.solved .nm { color: var(--tile-ink); }
.cell.revealed { outline: 2px dashed rgba(233,220,192,.5); }
.cell.started { border-color: rgba(233,220,192,.55); }
.filters { display: flex; gap: 6px; margin: 4px 0 12px; flex-wrap: wrap; }
.filters button { padding: 6px 12px; border-radius: 20px; border: 1px solid rgba(255,255,255,.2); background: transparent; font-size: 13px; }
.filters button.on { background: var(--tile); color: var(--tile-ink); border-color: var(--tile); }

/* ---------- puzzle ---------- */
.facts { position: sticky; top: 53px; z-index: 15; background: color-mix(in srgb, var(--bg) 94%, transparent); backdrop-filter: blur(6px); padding: 10px 0 10px; margin: 0 -14px; padding-left: 14px; padding-right: 14px; border-bottom: 1px solid rgba(255,255,255,.06); }
.chips { display: flex; gap: 6px; overflow-x: auto; scrollbar-width: none; padding-bottom: 2px; }
.chips::-webkit-scrollbar { display: none; }
.chip { flex: 0 0 auto; min-width: 38px; height: 38px; padding: 0 10px; border-radius: 9px; border: 2px solid var(--c); background: transparent; color: var(--cream); font-family: "Roboto Slab", serif; font-weight: 700; font-size: 14px; position: relative; }
.chip.on { background: var(--c); color: #fff; box-shadow: 0 0 0 3px rgba(255,255,255,.18); }
.chip .ct { position: absolute; top: -7px; right: -7px; background: var(--cream); color: var(--ink); font-size: 10px; border-radius: 10px; padding: 1px 5px; font-family: "Source Serif 4", serif; font-weight: 600; }
.chip.std { letter-spacing: .06em; font-size: 12px; }
.pinned { margin-top: 10px; background: var(--paper); color: var(--ink); border-radius: 9px; padding: 10px 12px; border-left: 6px solid var(--c); display: flex; gap: 10px; align-items: flex-start; }
.pinned .k { font-family: "Roboto Slab", serif; font-weight: 700; color: var(--c); white-space: nowrap; }
.pinned .t { flex: 1; line-height: 1.35; }
.pinned .x { background: none; border: none; color: var(--muted); font-size: 13px; text-decoration: underline; white-space: nowrap; padding: 0; }
.allfacts { margin-top: 10px; background: var(--paper); color: var(--ink); border-radius: 9px; padding: 6px; }
.allfacts button { display: flex; gap: 10px; width: 100%; text-align: left; background: none; border: none; border-radius: 6px; padding: 8px; color: var(--ink); align-items: baseline; }
.allfacts button.on { background: var(--paper-2); }
.allfacts .k { font-family: "Roboto Slab", serif; font-weight: 700; min-width: 42px; }
.hint { font-size: 12px; opacity: .65; margin-top: 8px; }

.sheet { background: var(--paper); color: var(--ink); border-radius: var(--radius); padding: 10px 10px 14px 4px; margin-top: 14px; box-shadow: 0 10px 30px rgba(0,0,0,.4); background-image: repeating-linear-gradient(transparent 0 calc(100% - 1px), transparent 0); }
.prow { display: flex; align-items: flex-start; border-bottom: 1px solid var(--line); padding: 3px 0; }
.prow:last-child { border-bottom: none; }
.prow.even { background: rgba(0,0,0,.025); }
.ln { flex: 0 0 auto; width: 38px; margin-right: 4px; background: none; border: none; color: var(--muted); font-family: "Roboto Slab", serif; font-size: 12px; padding: 7px 0; text-align: right; padding-right: 8px; border-right: 2px solid var(--line); align-self: stretch; }
.ln:active { color: var(--ink); }
.names { flex: 1; display: flex; flex-wrap: wrap; align-items: baseline; padding-left: 4px; }
.nm-b { background: none; border: none; padding: 5px 3px; font-family: "Patrick Hand", cursive; font-size: 19px; line-height: 1.15; color: var(--ink); position: relative; border-radius: 5px; }
.nm-b:hover { background: rgba(0,0,0,.05); }
.nm-b .sep { color: var(--muted); }
.nm-b.x .w { text-decoration: line-through; text-decoration-color: var(--c); text-decoration-thickness: 2.5px; color: color-mix(in srgb, var(--ink) 38%, transparent); }
.nm-b.x sup { color: var(--c); font-family: "Roboto Slab", serif; font-weight: 700; font-size: 10px; margin-left: 1px; }
.nm-b.last .w { background: #fff3b0; border-radius: 4px; padding: 0 3px; box-shadow: 0 0 0 2px #e4c75a; }
.nm-b.answer .w { background: var(--tile-ink); color: var(--cream); border-radius: 4px; padding: 0 4px; }
.sheet.done .nm-b { cursor: default; }
.reg-row .names { font-size: 19px; }

.bottom { position: fixed; left: 0; right: 0; bottom: 0; z-index: 25; background: color-mix(in srgb, var(--bg) 95%, transparent); backdrop-filter: blur(8px); border-top: 1px solid rgba(255,255,255,.1); padding: 10px 14px calc(10px + var(--safe-b)); }
.bottom .in { max-width: 980px; margin: 0 auto; display: flex; gap: 8px; align-items: center; }
.bottom .count { font-family: "Roboto Slab", serif; font-size: 13px; line-height: 1.15; min-width: 74px; }
.bottom .count b { font-size: 20px; display: block; }
.bottom .sp { flex: 1; }
.accuse { background: #b3261e; color: #fff; }
.solvedbar { background: var(--tile); color: var(--tile-ink); border-radius: 9px; padding: 10px 14px; flex: 1; font-family: "Roboto Slab", serif; }
.solvedbar b { font-family: "Patrick Hand", cursive; font-size: 22px; font-weight: 400; }

.menu { position: absolute; right: 14px; top: 52px; background: var(--paper); color: var(--ink); border-radius: 10px; box-shadow: 0 10px 30px rgba(0,0,0,.4); padding: 6px; z-index: 40; min-width: 200px; }
.menu button { display: block; width: 100%; text-align: left; background: none; border: none; padding: 10px 12px; border-radius: 6px; color: var(--ink); }
.menu button:hover { background: var(--paper-2); }
.menu button.danger { color: #a12a1e; }

/* ---------- modal & toast ---------- */
.modal-bg { position: fixed; inset: 0; background: rgba(0,0,0,.6); z-index: 50; display: grid; place-items: center; padding: 20px; }
.modal { max-width: 380px; width: 100%; text-align: center; }
.modal h2 { font-family: "Roboto Slab", serif; margin: 4px 0 8px; letter-spacing: .04em; }
.modal .big { font-family: "Patrick Hand", cursive; font-size: 40px; margin: 10px 0; color: var(--tile-ink); }
.modal p { line-height: 1.45; }
.modal .row { display: flex; gap: 8px; margin-top: 16px; }
.modal .row .btn { flex: 1; }
.modal .btn.light { background: var(--paper-2); }
#toast { position: fixed; left: 50%; bottom: 90px; transform: translateX(-50%) translateY(20px); background: #111; color: #fff; padding: 10px 16px; border-radius: 9px; font-size: 14px; opacity: 0; transition: .25s; z-index: 60; pointer-events: none; max-width: 90vw; text-align: center; }
#toast.on { opacity: 1; transform: translateX(-50%) translateY(0); }

/* ---------- admin ---------- */
.admin-table { width: 100%; border-collapse: collapse; color: var(--ink); }
.admin-table td, .admin-table th { padding: 10px 8px; border-bottom: 1px solid var(--line); text-align: left; font-size: 14px; }
.admin-table th { font-size: 12px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); }
.admin-table .em { word-break: break-all; }
.toggle { display: inline-flex; align-items: center; gap: 6px; padding: 6px 10px; border-radius: 20px; border: 1px solid var(--line); background: transparent; color: var(--ink); font-size: 13px; }
.toggle.on { background: #2e7d4f; border-color: #2e7d4f; color: #fff; }
.preview-flag { position: fixed; left: 8px; bottom: calc(80px + var(--safe-b)); background: #b3261e; color: #fff; font-size: 11px; padding: 3px 8px; border-radius: 6px; z-index: 30; opacity: .85; letter-spacing: .05em; }

@media (max-width: 560px) {
  .tile { font-size: 17px; }
  .tile.sm { font-size: 11px; }
  .nm-b { font-size: 18px; padding: 5px 2px; }
  .ln { width: 30px; padding-right: 6px; }
  .bottom .count { min-width: 60px; }
  .btn { padding: 10px 12px; }
}

.chips { padding-top: 9px; margin-top: -9px; padding-right: 8px; }
@media (max-width: 560px) {
  .chips { display: grid; grid-template-columns: repeat(6, minmax(0, 1fr)) 1.55fr 1.45fr 1.25fr; gap: 5px; overflow: visible; padding-right: 0; }
  .chip { min-width: 0; padding: 0; height: 36px; }
  .chip.std { font-size: 10.5px; letter-spacing: .02em; }
}

/* ---------- desktop: facts column + sheet ---------- */
@media (min-width: 1000px) {
  .wrap.puzzle { max-width: 1320px; display: grid; grid-template-columns: 380px 1fr; gap: 28px; align-items: start; padding-top: 22px; }
  .wrap.puzzle .facts { position: sticky; top: 76px; margin: 0; padding: 0; border: none; background: none; backdrop-filter: none; max-height: calc(100vh - 170px); overflow-y: auto; }
  .wrap.puzzle .sheet { margin-top: 0; padding: 14px 16px 18px 6px; }
  .wrap.puzzle .allfacts { display: block !important; }
  .wrap.puzzle .chip.allbtn { display: none; }
  .wrap.puzzle .allfacts button { padding: 9px 10px; font-size: 15px; }
  .nm-b { font-size: 21px; padding: 5px 4px; }
  .ln { width: 44px; font-size: 13px; }
  .bottom .in { max-width: 1320px; }
  .wrap { max-width: 1100px; }
  .grid { grid-template-columns: repeat(auto-fill, minmax(104px, 1fr)); }
  .tile { font-size: 26px; }
  .tile.sm { font-size: 15px; }
}
@media (hover: hover) {
  .nm-b:hover .w { text-decoration: underline; text-decoration-color: var(--c, #0003); text-decoration-thickness: 1px; }
  .nm-b.x:hover .w { text-decoration: line-through; text-decoration-color: var(--c); text-decoration-thickness: 2.5px; }
  .cell:hover { border-color: rgba(233,220,192,.6); }
}
/* phones: larger touch targets, no zoom on input focus */
@media (max-width: 560px) {
  input[type=email], input[type=password], input[type=text], input[type=search] { font-size: 16px; }
  .nm-b { min-height: 34px; }
}
@media (display-mode: standalone) { .topbar { padding-top: max(10px, env(safe-area-inset-top)); } }
