/* CELLS — styles.css
   Retro-arcade chrome shared with The Lab; the working surface (toolbar,
   formula bar, grid) is a clean, dense spreadsheet UI. Dark only. */

/* ---------- fonts (self-hosted, shared with the lab root) ---------- */

@font-face { font-family: "Press Start 2P"; font-style: normal; font-weight: 400; font-display: swap; src: url("/press-start-2p.woff2") format("woff2"); }

/* ---------- tokens ---------- */

:root {
  --bg: #0a0a12;
  --surface: #12121d;
  --surface-2: #1a1a2a;
  --line: #28283c;
  --control-line: #5e5e80;
  --text: #e9e9f2;
  --dim: #9aa0b5;
  --cyan: #45f0ff;
  --magenta: #ff3d8b;
  --gold: #ffc857;
  --green: #41ff8b;
  --red: #ff5560;

  --pixel: "Press Start 2P", "Courier New", monospace;
  --body: -apple-system, "Segoe UI", system-ui, sans-serif;
  --mono: ui-monospace, "SF Mono", Menlo, monospace;

  --radius: 8px;
  --ease-out: cubic-bezier(0.16, 1, 0.3, 1);
  --glow-cyan: 0 0 14px rgba(69, 240, 255, 0.35);
  --space-gutter: clamp(14px, 4vw, 48px);

  --col-w: 104px;
  --row-h: 30px;
  --head-w: 48px;
}

/* ---------- base ---------- */

*, *::before, *::after { box-sizing: border-box; }
html { color-scheme: dark; }

body {
  margin: 0;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  background:
    radial-gradient(1200px 500px at 50% -10%, rgba(69, 240, 255, 0.05), transparent 70%),
    var(--bg);
  color: var(--text);
  font-family: var(--body);
  font-size: 15px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

::selection { background: rgba(69, 240, 255, 0.3); }
[hidden] { display: none !important; }

.visually-hidden {
  position: absolute !important;
  width: 1px; height: 1px;
  margin: -1px; padding: 0; border: 0;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
}

.skip-link {
  position: absolute;
  left: 12px; top: -48px;
  z-index: 200;
  background: var(--cyan);
  color: #05050d;
  padding: 10px 16px;
  border-radius: 6px;
  font-family: var(--mono);
  font-weight: 700;
  text-decoration: none;
  transition: transform 0.2s var(--ease-out);
}
.skip-link:focus-visible { transform: translateY(60px); }

:focus-visible {
  outline: 2px solid var(--cyan);
  outline-offset: 2px;
  box-shadow: 0 0 0 5px rgba(69, 240, 255, 0.15);
}

a { color: var(--cyan); }

/* ---------- header ---------- */

.site-header {
  padding: 24px var(--space-gutter) 8px;
  display: flex;
  flex-direction: column;
  gap: 18px;
}

.lab-link {
  align-self: flex-start;
  font-family: var(--pixel);
  font-size: 10px;
  color: var(--dim);
  text-decoration: none;
  padding: 6px 2px;
  transition: color 0.15s, text-shadow 0.15s;
}
.lab-link:hover { color: var(--cyan); text-shadow: var(--glow-cyan); }

.level {
  margin: 0;
  font-family: var(--pixel);
  font-size: 9px;
  letter-spacing: 3px;
  color: var(--gold);
}

.wordmark {
  margin: 6px 0 4px;
  font-family: var(--pixel);
  font-size: clamp(22px, 4.5vw, 34px);
  letter-spacing: 4px;
  color: var(--text);
  text-shadow: 0 0 16px rgba(69, 240, 255, 0.55), 3px 3px 0 var(--magenta);
}

.tagline {
  margin: 0;
  font-family: var(--mono);
  font-size: 12px;
  letter-spacing: 2px;
  text-transform: uppercase;
  color: var(--dim);
}

.cursor { color: var(--cyan); animation: blink 1.1s steps(1) infinite; }
@keyframes blink { 50% { opacity: 0; } }

/* ---------- layout ---------- */

main {
  flex: 1;
  width: 100%;
  max-width: 1200px;
  margin: 0 auto;
  padding: 14px var(--space-gutter) 60px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  min-width: 0;
}

/* ---------- toolbar ---------- */

.toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
  padding: 8px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 10px;
}

.tb-group {
  display: flex;
  gap: 6px;
  padding: 0 6px;
  border-right: 1px solid var(--line);
}
.tb-group:last-child { border-right: 0; }
.tb-grow { margin-left: auto; }

.tb-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 40px;
  min-height: 40px;
  padding: 8px 10px;
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-radius: 6px;
  color: var(--text);
  font-family: var(--mono);
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.5px;
  cursor: pointer;
  transition: border-color 0.12s, color 0.12s, box-shadow 0.12s, background 0.12s, transform 0.1s;
}
.tb-btn:hover { border-color: var(--cyan); box-shadow: 0 0 10px rgba(69, 240, 255, 0.2); }
.tb-btn:active { transform: translateY(1px); }
.tb-btn.is-active {
  border-color: var(--cyan);
  color: var(--cyan);
  background: rgba(69, 240, 255, 0.1);
  box-shadow: inset 0 0 0 1px rgba(69, 240, 255, 0.4);
}
.tb-bold { font-family: var(--mono); font-weight: 900; font-size: 15px; }
.tb-text { font-size: 11px; }

/* ---------- formula bar ---------- */

.fx-bar {
  display: flex;
  align-items: stretch;
  gap: 0;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 10px;
  overflow: hidden;
}

.fx-cell {
  display: flex;
  align-items: center;
  justify-content: center;
  flex: 0 0 var(--head-w);
  min-width: 62px;
  padding: 0 10px;
  font-family: var(--mono);
  font-weight: 700;
  font-size: 13px;
  color: var(--gold);
  background: var(--surface-2);
  border-right: 1px solid var(--line);
  letter-spacing: 1px;
}

.fx-symbol {
  display: flex;
  align-items: center;
  padding: 0 12px;
  font-family: var(--mono);
  font-style: italic;
  color: var(--magenta);
  border-right: 1px solid var(--line);
  font-size: 15px;
}

.fx-input {
  flex: 1;
  min-width: 0;
  background: transparent;
  border: 0;
  color: var(--text);
  font-family: var(--mono);
  font-size: 14px;
  padding: 12px 14px;
}
.fx-input:focus { outline: none; box-shadow: none; }
.fx-bar:focus-within { border-color: var(--cyan); box-shadow: 0 0 0 3px rgba(69, 240, 255, 0.12); }

/* ---------- grid ---------- */

.grid-scroll {
  position: relative;
  overflow: auto;
  max-height: min(70vh, 640px);
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--surface);
  -webkit-overflow-scrolling: touch;
}

.grid {
  border-collapse: separate;
  border-spacing: 0;
  table-layout: fixed;
  font-family: var(--mono);
  font-size: 13px;
}

.grid th, .grid td {
  border-right: 1px solid var(--line);
  border-bottom: 1px solid var(--line);
  height: var(--row-h);
  padding: 0;
  margin: 0;
}

/* corner + column headers (sticky top) */
.grid thead th {
  position: sticky;
  top: 0;
  z-index: 3;
  background: var(--surface-2);
  color: var(--dim);
  font-family: var(--mono);
  font-weight: 700;
  font-size: 11px;
  letter-spacing: 1px;
  text-align: center;
  user-select: none;
  cursor: pointer;
}
.grid thead th.corner {
  left: 0;
  z-index: 4;
  width: var(--head-w);
  min-width: var(--head-w);
  background: var(--surface-2);
}
.grid th.col-head { width: var(--col-w); min-width: var(--col-w); }
.grid th.col-head.is-active { color: var(--cyan); background: rgba(69, 240, 255, 0.1); }

/* row headers (sticky left) */
.grid th.row-head {
  position: sticky;
  left: 0;
  z-index: 2;
  width: var(--head-w);
  min-width: var(--head-w);
  background: var(--surface-2);
  color: var(--dim);
  font-family: var(--mono);
  font-weight: 700;
  font-size: 11px;
  text-align: center;
  user-select: none;
  cursor: pointer;
}
.grid th.row-head.is-active { color: var(--cyan); background: rgba(69, 240, 255, 0.1); }

/* data cells */
.grid td.cell {
  width: var(--col-w);
  min-width: var(--col-w);
  max-width: var(--col-w);
  padding: 0 8px;
  color: var(--text);
  background: var(--surface);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  cursor: cell;
  vertical-align: middle;
}
.grid tbody tr:nth-child(even) td.cell { background: #14141f; }

.grid td.cell.is-num, .grid td.cell.align-right { text-align: right; }
.grid td.cell.align-left { text-align: left; }
.grid td.cell.align-center { text-align: center; }
.grid td.cell.is-bold { font-weight: 800; color: #fff; }
.grid td.cell.is-error { color: var(--red); font-weight: 700; }

.grid td.cell.is-selected { background: rgba(69, 240, 255, 0.08); }
.grid tbody tr:nth-child(even) td.cell.is-selected { background: rgba(69, 240, 255, 0.11); }

.grid td.cell.is-active-cell {
  outline: 2px solid var(--cyan);
  outline-offset: -2px;
  box-shadow: inset 0 0 12px rgba(69, 240, 255, 0.2);
  background: rgba(69, 240, 255, 0.06);
  z-index: 1;
  position: relative;
}

.grid td.cell.is-clip-src {
  outline: 2px dashed var(--gold);
  outline-offset: -2px;
}

.grid:focus { outline: none; }
.grid:focus-visible { outline: none; box-shadow: none; }

/* in-cell editor */
.grid td.cell.is-editing {
  padding: 0;
  overflow: visible;
}
.cell-editor {
  width: 100%;
  min-width: var(--col-w);
  height: calc(var(--row-h) - 0px);
  background: var(--bg);
  border: 2px solid var(--cyan);
  border-radius: 0;
  color: var(--text);
  font-family: var(--mono);
  font-size: 13px;
  padding: 0 6px;
  box-shadow: 0 4px 18px rgba(0, 0, 0, 0.5), 0 0 0 1px var(--cyan);
}
.cell-editor:focus { outline: none; }

/* ---------- status ---------- */

.status {
  margin: 2px 2px 0;
  min-height: 18px;
  font-family: var(--mono);
  font-size: 12px;
  color: var(--dim);
}

/* ---------- buttons (dialogs) ---------- */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  background: var(--surface-2);
  border: 1px solid var(--line);
  color: var(--text);
  font-family: var(--mono);
  font-size: 12.5px;
  font-weight: 600;
  letter-spacing: 0.5px;
  padding: 11px 16px;
  min-height: 42px;
  border-radius: 6px;
  cursor: pointer;
  text-decoration: none;
  transition: transform 0.12s var(--ease-out), border-color 0.12s, box-shadow 0.12s;
}
.btn:hover { border-color: var(--cyan); box-shadow: 0 0 12px rgba(69, 240, 255, 0.22); transform: translateY(-1px); }
.btn:active { transform: translateY(1px); }
.btn-primary { background: var(--cyan); border-color: var(--cyan); color: #05050d; }
.btn-primary:hover { box-shadow: 0 0 18px rgba(69, 240, 255, 0.5); }
.btn-danger { background: var(--red); border-color: var(--red); color: #1a0306; }
.btn-danger:hover { box-shadow: 0 0 18px rgba(255, 85, 96, 0.5); border-color: var(--red); }
.btn-ghost { background: transparent; }

/* ---------- toasts ---------- */

.toasts {
  position: fixed;
  bottom: 18px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 100;
  display: flex;
  flex-direction: column;
  gap: 8px;
  width: min(440px, calc(100vw - 32px));
  pointer-events: none;
}

.toast {
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-left: 3px solid var(--red);
  color: var(--text);
  padding: 12px 14px;
  border-radius: 8px;
  font-size: 13.5px;
  box-shadow: 0 8px 30px rgba(0, 0, 0, 0.5);
  animation: toast-in 0.22s var(--ease-out) both;
}
.toast-info { border-left-color: var(--cyan); }
.toast-success { border-left-color: var(--green); }
.toast.out { opacity: 0; transform: translateY(6px); transition: opacity 0.25s, transform 0.25s; }
@keyframes toast-in { from { opacity: 0; transform: translateY(10px); } }

/* ---------- dialogs ---------- */

.dialog {
  background: var(--surface);
  color: var(--text);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 24px;
  max-width: min(440px, calc(100vw - 32px));
}
.dialog-wide { max-width: min(560px, calc(100vw - 32px)); width: 100%; }
.dialog::backdrop { background: rgba(5, 5, 12, 0.72); }
.dialog-title { margin: 0 0 12px; font-family: var(--pixel); font-size: 12px; color: var(--gold); }
.dialog p { margin: 0 0 18px; color: var(--dim); line-height: 1.55; }
.dialog-actions { display: flex; flex-wrap: wrap; gap: 10px; margin-top: 8px; }

.import-controls {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 14px;
  margin-bottom: 12px;
}
.import-file-label { cursor: pointer; }
.toggle-line {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  min-height: 40px;
  font-family: var(--mono);
  font-size: 12.5px;
  color: var(--text);
  cursor: pointer;
}
.toggle-line input { accent-color: var(--cyan); width: 16px; height: 16px; }

.import-text {
  width: 100%;
  background: var(--bg);
  border: 1px solid var(--control-line);
  border-radius: 8px;
  color: var(--text);
  font-family: var(--mono);
  font-size: 13px;
  padding: 10px 12px;
  resize: vertical;
  margin-bottom: 6px;
}
.import-text:focus { outline: none; border-color: var(--cyan); box-shadow: 0 0 0 3px rgba(69, 240, 255, 0.12); }

.help-list {
  display: grid;
  grid-template-columns: minmax(78px, max-content) 1fr;
  gap: 8px 16px;
  margin: 0 0 8px;
  font-size: 13px;
  line-height: 1.5;
}
.help-list dt {
  font-family: var(--pixel);
  font-size: 9px;
  color: var(--cyan);
  align-self: center;
  letter-spacing: 1px;
}
.help-list dd { margin: 0; color: var(--text); }
.help-fns { font-family: var(--mono); color: var(--gold); font-size: 12px; word-spacing: 2px; }

/* ---------- footer ---------- */

.site-footer {
  border-top: 1px solid var(--line);
  padding: 22px var(--space-gutter);
  text-align: center;
  color: var(--dim);
  font-size: 13px;
}
.site-footer a { color: var(--cyan); text-decoration: none; }
.site-footer a:hover { text-decoration: underline; text-shadow: var(--glow-cyan); }

/* ---------- responsive / mobile ---------- */

@media (max-width: 640px) {
  :root { --col-w: 84px; --head-w: 40px; --row-h: 34px; }
  .grid-scroll { max-height: 56vh; }
  .tb-grow { margin-left: 0; }
  .tb-group { border-right: 0; padding: 0 2px; }
  .toolbar { gap: 6px; }
}

@media (pointer: coarse) {
  /* Grow the row height so each cell (the primary tap target for select +
     double-tap to edit) meets the >=40px touch-target minimum. */
  :root { --row-h: 44px; }
  .tb-btn { min-height: 44px; }
  .grid td.cell { cursor: pointer; }
}

@media (max-width: 380px) {
  :root { --col-w: 76px; }
  .wordmark { letter-spacing: 2px; }
}

/* ---------- reduced motion ---------- */

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
    scroll-behavior: auto !important;
  }
  .cursor { animation: none; }
}
