:root {
  --ink: #1d2433;
  --muted: #667085;
  --line: #e4e7ec;
  --bg: #f5f7fa;
  --panel: #ffffff;
  --accent: #1f6feb;
  --accent-soft: #e8f0fe;
  --input: #1f6feb;
  --ok: #12805c;
  --warn: #b54708;
  --err: #c01048;
  font-family: "Inter", "Segoe UI", system-ui, -apple-system, Roboto, Arial, sans-serif;
  color: var(--ink);
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; background: var(--bg); }
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
button, select, input, textarea { font: inherit; }
button {
  border: 1px solid var(--line); background: var(--panel); color: var(--ink);
  padding: 6px 12px; border-radius: 8px; cursor: pointer;
}
button:hover { border-color: #c7ccd4; }
button.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
button.danger { color: var(--err); }
button:disabled { opacity: .5; cursor: default; }

/* ------------------------------------------------------------ gallery */
.page { max-width: 1040px; margin: 0 auto; padding: 48px 24px; }
.page h1 { font-size: 30px; margin: 0 0 6px; letter-spacing: -.01em; }
.page .lead { color: var(--muted); margin: 0 0 32px; }
.cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); gap: 16px; }
.card {
  display: block; background: var(--panel); border: 1px solid var(--line); border-radius: 14px;
  padding: 20px; color: inherit; transition: box-shadow .15s, transform .15s;
}
.card:hover { text-decoration: none; box-shadow: 0 8px 24px rgba(16,24,40,.08); transform: translateY(-1px); }
.card h2 { font-size: 17px; margin: 0 0 8px; }
.card p { margin: 0; color: var(--muted); font-size: 14px; line-height: 1.5; }
.card .go { margin-top: 14px; font-size: 13px; color: var(--accent); font-weight: 600; }
.empty { color: var(--muted); padding: 40px; text-align: center; border: 1px dashed var(--line); border-radius: 14px; }

/* ------------------------------------------------------------ viewer layout */
body.viewer { display: flex; flex-direction: column; overflow: hidden; }
.topbar {
  display: flex; align-items: center; gap: 12px; padding: 10px 16px;
  background: var(--panel); border-bottom: 1px solid var(--line); flex: none;
}
.topbar .back { color: var(--muted); font-size: 20px; line-height: 1; padding: 0 4px; }
.topbar .titles { min-width: 0; flex: 1; }
.topbar h1 { font-size: 16px; margin: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.topbar .desc { font-size: 12.5px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.preview-badge {
  display: inline-block; margin-left: 8px; padding: 1px 8px; border-radius: 999px; font-size: 11.5px;
  font-weight: 600; background: #fff4e5; color: var(--warn); vertical-align: 2px;
}
.preview-badge.live { background: #ecfdf3; color: var(--ok); }
.status { font-size: 12.5px; color: var(--muted); white-space: nowrap; display: flex; align-items: center; gap: 6px; }
.status .dot { width: 8px; height: 8px; border-radius: 50%; background: var(--ok); }
.status.busy .dot { background: var(--accent); animation: pulse 1s infinite; }
.status.error .dot { background: var(--err); }
@keyframes pulse { 50% { opacity: .3; } }
.main { flex: 1; display: flex; min-height: 0; }
/* name box + formula bar */
.fbar { display: flex; align-items: center; gap: 6px; padding: 4px 8px; background: #fff; border-bottom: 1px solid var(--line); flex: none; }
.fbar input { border: 1px solid var(--line); border-radius: 4px; padding: 3px 6px; font: 13px Calibri, Carlito, "Segoe UI", Arial, sans-serif; }
.fbar .namebox { width: 110px; text-align: center; }
.fbar .fx { color: var(--muted); font-style: italic; font-size: 13px; padding: 0 2px; }
.fbar .fxinput { flex: 1; min-width: 0; }
.fbar .fxinput[readonly] { background: #f8f9fb; color: #475467; }
.sheet-area { flex: 1; display: flex; flex-direction: column; min-width: 0; }
.scroller { flex: 1; overflow: auto; position: relative; background: #fff; }
.tabs { display: flex; gap: 2px; background: #eef0f3; border-top: 1px solid var(--line); padding: 0 8px; flex: none; overflow-x: auto; }
.tabs button {
  border: none; border-radius: 0 0 6px 6px; background: transparent; padding: 7px 16px; font-size: 13px; color: var(--muted);
}
.tabs button.active { background: #fff; color: var(--ink); font-weight: 600; box-shadow: inset 0 2px 0 var(--accent); }
.loading { padding: 40px; color: var(--muted); }

/* ------------------------------------------------------------ the grid */
table.grid {
  border-collapse: separate; border-spacing: 0; table-layout: fixed;
  font-family: Calibri, Carlito, "Segoe UI", Arial, sans-serif; font-size: 11pt; color: #000;
}
table.grid td {
  padding: 0 3px; white-space: nowrap; overflow: hidden; vertical-align: bottom;
  border-right: 1px solid transparent; border-bottom: 1px solid transparent; line-height: 1.15;
}
table.grid.gridlines td { border-right-color: #e6e6e6; border-bottom-color: #e6e6e6; }
table.grid td.ovf { overflow: visible; }
/* row numbers and column letters (sticky, above frozen cells and drawings) */
table.grid th.hdr {
  position: sticky; background: #f3f4f6; color: #5f6673; font: 500 11px "Segoe UI", system-ui, Arial, sans-serif;
  text-align: center; padding: 0 2px; border-right: 1px solid #d5d9df; border-bottom: 1px solid #d5d9df;
  overflow: hidden; white-space: nowrap; user-select: none;
}
table.grid th.colhdr { top: 0; z-index: 9; }
table.grid th.rowhdr { left: 0; z-index: 9; }
table.grid th.rowhdr.frozen, table.grid th.colhdr.frozen { z-index: 10; }
table.grid th.corner { top: 0; left: 0; z-index: 11; }
table.grid td.wrap { white-space: pre-wrap; word-break: break-word; }
table.grid td.sticky { position: sticky; background-color: #fff; }
table.grid { user-select: none; -webkit-user-select: none; }
table.grid td.sel { background-image: linear-gradient(rgba(26,115,232,.14), rgba(26,115,232,.14)); }
table.grid td.cur { box-shadow: inset 0 0 0 2px #1a73e8 !important; }
table.grid th.hdr.on { background: #d3e3fd; color: #0b57d0; font-weight: 700; }
table.grid th.hdr.colhdr, table.grid th.hdr.rowhdr, table.grid th.corner { cursor: pointer; }
table.grid td.changed { box-shadow: inset 0 0 0 2px var(--input); font-weight: 700; }
table.grid td.dd:not(.sticky) { position: relative; }
table.grid td.dd::after {
  content: "▾"; position: absolute; right: 2px; top: 50%; transform: translateY(-50%);
  font-size: 10px; color: #667085; pointer-events: none;
}
table.grid td.flash { animation: flash 1.2s ease-out; }
@keyframes flash { 0% { box-shadow: inset 0 0 0 3px #f79009; } 100% { box-shadow: none; } }
table.grid td.updated { transition: none; animation: upd 0.9s ease-out; }
@keyframes upd { 0% { background-image: linear-gradient(rgba(255,214,0,.45), rgba(255,214,0,.45)); } 100% { background-image: none; } }
.chart {
  position: absolute; z-index: 7; border-radius: 4px; overflow: hidden;
  box-shadow: 0 1px 3px rgba(0,0,0,.15);
}
.picture { position: absolute; z-index: 6; object-fit: fill; pointer-events: none; }
.sheet-button {
  position: absolute; z-index: 8; border: none; border-radius: 2px; font: 600 14px "Segoe UI", Calibri, Arial, sans-serif;
  box-shadow: 0 2px 4px rgba(0,0,0,.25); cursor: pointer; padding: 2px 6px;
}
.sheet-button.rounded { border-radius: 10px; }
.sheet-button:hover:not(:disabled) { filter: brightness(1.08); }
.sheet-button:disabled { cursor: not-allowed; opacity: .55; }
.solver-panel {
  position: fixed; right: 20px; bottom: 56px; z-index: 60; width: min(420px, calc(100vw - 40px));
  background: #fff; border: 1px solid var(--line); border-radius: 12px; padding: 16px 18px;
  box-shadow: 0 12px 32px rgba(16,24,40,.18);
}
.solver-panel h3 { margin: 0 0 6px; font-size: 15px; }
.solver-panel p { margin: 0 0 10px; font-size: 13px; color: var(--muted); line-height: 1.45; }
.solver-panel .progress { height: 6px; background: #eef0f3; border-radius: 99px; overflow: hidden; margin-bottom: 12px; }
.solver-panel .progress div { height: 100%; width: 0; background: var(--accent); transition: width .9s linear; }
.solver-panel .actions { display: flex; gap: 8px; justify-content: flex-end; flex-wrap: wrap; }
.macro-dialog-back {
  position: fixed; inset: 0; z-index: 80; background: rgba(16,24,40,.28); display: flex; align-items: center; justify-content: center;
}
.macro-dialog {
  background: #fff; border-radius: 10px; padding: 16px 18px; width: min(420px, calc(100vw - 40px));
  box-shadow: 0 16px 40px rgba(16,24,40,.28);
}
.macro-dialog h3 { margin: 0 0 8px; font-size: 15px; }
.macro-dialog p { margin: 0 0 12px; font-size: 14px; white-space: pre-wrap; line-height: 1.45; }
.macro-dialog input { width: 100%; box-sizing: border-box; padding: 6px 8px; margin-bottom: 12px; font-size: 14px; }
.macro-dialog .actions { display: flex; gap: 8px; justify-content: flex-end; }
.editor {
  position: absolute; z-index: 12; border: 2px solid var(--input); border-radius: 2px;
  font-family: Calibri, Carlito, Arial, sans-serif; font-size: 11pt; padding: 0 3px; background: #fff;
  box-shadow: 0 4px 14px rgba(0,0,0,.18); outline: none;
}
.toast {
  position: fixed; left: 50%; bottom: 52px; transform: translateX(-50%); background: #1d2433; color: #fff;
  padding: 8px 14px; border-radius: 8px; font-size: 13px; z-index: 50; opacity: 0; transition: opacity .2s; pointer-events: none;
}
.toast.show { opacity: 1; }
/* Turnstile: invisible unless Cloudflare wants a click; then the page fades and the
   check sits in the middle. The overlay is always laid out (never display:none),
   since the widget can't run inside a hidden element. */
#ts-overlay {
  position: fixed; inset: 0; z-index: 200; display: flex; align-items: center; justify-content: center;
  background: rgba(245, 247, 250, .72); backdrop-filter: blur(2px);
  opacity: 0; pointer-events: none; transition: opacity .2s;
}
#ts-overlay.show { opacity: 1; pointer-events: auto; }
#ts-overlay .ts-card {
  background: #fff; border: 1px solid var(--line); border-radius: 12px; box-shadow: 0 10px 40px rgba(0,0,0,.18);
  padding: 20px 22px; text-align: center; max-width: calc(100vw - 32px);
}
#ts-overlay .ts-card p { margin: 0 0 14px; font-size: 14px; color: var(--ink); }
@media (max-width: 760px) {
  .topbar .desc { display: none; }
}

/* ------------------------------------------------------------ admin */
.admin table.list { width: 100%; border-collapse: collapse; background: var(--panel); border: 1px solid var(--line); border-radius: 12px; overflow: hidden; }
.admin table.list th, .admin table.list td { text-align: left; padding: 10px 12px; border-bottom: 1px solid var(--line); font-size: 14px; vertical-align: top; }
.admin table.list th { font-size: 12px; text-transform: uppercase; color: var(--muted); letter-spacing: .05em; background: #fafbfc; }
.admin .box { background: var(--panel); border: 1px solid var(--line); border-radius: 12px; padding: 20px; margin-bottom: 24px; }
.admin .box h2 { margin: 0 0 12px; font-size: 16px; }
.admin .form { display: grid; grid-template-columns: 140px 1fr; gap: 10px 14px; align-items: center; }
.admin .form input[type=text], .admin .form textarea { padding: 7px 10px; border: 1px solid var(--line); border-radius: 8px; width: 100%; }
.admin .badge { display: inline-block; padding: 2px 8px; border-radius: 999px; font-size: 12px; font-weight: 600; }
.admin .badge.ready { background: #ecfdf3; color: var(--ok); }
.admin .badge.processing { background: var(--accent-soft); color: var(--accent); }
.admin .badge.error { background: #fff1f3; color: var(--err); }
.admin .small { font-size: 12.5px; color: var(--muted); }
.admin details { margin-top: 6px; }
.admin details pre { font-size: 12px; background: #f8f9fb; padding: 10px; border-radius: 8px; overflow: auto; max-height: 300px; }
.admin .slug-row { display: flex; align-items: center; gap: 2px; margin-top: 6px; }
.admin input.slug { padding: 3px 6px; border: 1px solid var(--line); border-radius: 6px; font-size: 12.5px; width: 180px; }
.admin input.slug:invalid { border-color: var(--err); }
a.button { display: inline-block; padding: 6px 12px; border-radius: 8px; border: 1px solid var(--line); font-size: inherit; }
a.button.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
a.button:hover { text-decoration: none; filter: brightness(1.05); }
a.button.disabled { opacity: .45; pointer-events: none; }
.admin .verdict { font-weight: 600; }
.admin .verdict.ok { color: var(--ok); }
.admin .verdict.warn { color: var(--warn); }
.admin .verdict.bad { color: var(--err); }
.admin .whoami { text-align: right; margin-bottom: 8px; }
button.link { border: none; background: none; padding: 0; color: var(--accent); cursor: pointer; font-size: inherit; }
.signin { max-width: 560px; }
.admin .actions { display: flex; gap: 6px; flex-wrap: wrap; }

.site-label {
  position: fixed; left: 50%; top: 0; transform: translateX(-50%); z-index: 100;
  background: #b54708; color: #fff; font: 700 11px system-ui, sans-serif; letter-spacing: .08em;
  text-transform: uppercase; padding: 2px 10px; border-radius: 0 0 6px 6px; pointer-events: none;
}
