/**
 * FILE: style.css
 * USAGE: Styles for BeadPix, arcade dark theme (tokens first, then layout)
 * SCOPE: tokens, controls, panels, canvas, palette, modals
 */
/* ============================================================
   BeadPix - Arcade dark theme
   Tokens first, then layout. External CSS only, no inline rules.
   ============================================================ */

/* ─── Local fonts (SIL OFL, files in src/fonts) ─── */
@font-face {
  font-family: 'VT323';
  font-style: normal;
  font-weight: 400;
  font-display: swap;
  src: url('fonts/vt323-latin.woff2') format('woff2');
}

@font-face {
  font-family: 'Press Start 2P';
  font-style: normal;
  font-weight: 400;
  font-display: swap;
  src: url('fonts/pressstart2p-latin.woff2') format('woff2');
}

/* ─── Design tokens ─── */
:root {
  color-scheme: dark;
  --bg: #070b12;
  --panel: #0d141e;
  --surface: #141f2c;
  --canvas: #131d29;
  --ink: #e8f1ff;
  --muted: #7f93ad;
  --line: #1e2b3d;
  --border: #2a3b55;
  --accent: #c6ff3d;
  --accent-2: #8b5cf6;
  --danger: #ff4d6d;
  --uncolored: #cfdcef;
  --focus: #c6ff3d;
  --shadow: #000000;
}

* { box-sizing: border-box; scrollbar-color: var(--border) var(--panel); }

html, body { margin: 0; height: 100%; }

body {
  font-family: 'VT323', 'Courier New', monospace;
  font-size: 19px;
  color: var(--ink);
  background: radial-gradient(circle at 50% 0%, #101b2a 0%, var(--bg) 58%);
  display: flex;
  flex-direction: column;
}

::selection { background: var(--accent); color: #08120a; }

/* ─── Controls ─── */
button {
  font-family: inherit;
  font-size: 18px;
  border: 2px solid var(--border);
  background: var(--surface);
  color: var(--ink);
  padding: 4px 10px;
  cursor: pointer;
  box-shadow: 2px 2px 0 var(--shadow);
  transition: border-color .12s ease, background-color .12s ease, color .12s ease;
}
button:hover:not(:disabled) { border-color: var(--accent); }
button:active { transform: translate(1px, 1px); box-shadow: none; }
button.primary { background: var(--accent); border-color: var(--accent); color: #08120a; }
button.danger { background: var(--danger); border-color: var(--danger); color: #20060d; }
button.neutral { background: var(--panel); }

button:focus-visible,
input:focus-visible,
select:focus-visible {
  outline: 2px solid var(--focus);
  outline-offset: 2px;
}

input[type="text"], input[type="number"], select {
  font-family: inherit;
  font-size: 19px;
  border: 2px solid var(--border);
  background: var(--surface);
  color: var(--ink);
  padding: 4px 8px;
}

/* ─── Top bar ─── */
.topbar {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 8px 14px;
  background: var(--panel);
  border-bottom: 3px solid var(--border);
}
.brand { font-family: 'Press Start 2P', 'Courier New', monospace; font-size: 14px; }
.brand .logo { color: var(--accent); text-shadow: 0 0 12px rgba(198, 255, 61, .45); }
.doc { display: flex; align-items: center; gap: 8px; flex: 1 1 auto; }
.doc .badge {
  font-size: 13px;
  letter-spacing: 1px;
  padding: 2px 8px;
  border: 2px solid var(--border);
  background: var(--surface);
}
.doc input { flex: 0 1 220px; }
.doc .dim { color: var(--muted); font-size: 16px; }
.actions { display: flex; gap: 6px; flex-wrap: wrap; justify-content: flex-end; }

/* ─── Layout ─── */
.layout { flex: 1 1 auto; display: flex; min-height: 0; }

.left {
  width: 230px;
  border-right: 3px solid var(--border);
  background: var(--panel);
  display: flex;
  flex-direction: column;
  min-height: 0;
}

.tools {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  padding: 10px;
  border-bottom: 2px solid var(--border);
}
.tool {
  flex: 1 1 calc(25% - 6px);
  aspect-ratio: 1;
  font-size: 15px;
  display: flex;
  align-items: center;
  justify-content: center;
  border: 2px solid var(--border);
  background: var(--surface);
  cursor: pointer;
  user-select: none;
}
.tool.active { background: var(--accent); border-color: var(--accent); color: #08120a; }
.tool svg { width: 20px; height: 20px; display: block; margin: 0 auto; }
.tool:disabled { opacity: .35; cursor: default; }

/* ─── Tracing ─── */
.trace-box {
  padding: 8px 10px;
  border-bottom: 2px solid var(--border);
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.trace-head { font-size: 14px; letter-spacing: 1px; color: var(--muted); }
.trace-box .row { display: flex; gap: 4px; }
.trace-box .row button { flex: 1 1 0; font-size: 14px; padding: 3px 4px; }
.trace-box button.on { background: var(--accent); border-color: var(--accent); color: #08120a; }
.trace-box label { font-size: 13px; color: var(--muted); display: flex; align-items: center; gap: 6px; }
.trace-box input[type="range"] { flex: 1 1 auto; accent-color: var(--accent); }
.trace-info { font-size: 13px; color: var(--muted); }

.palette-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 8px 10px 4px;
  font-size: 14px;
  letter-spacing: 1px;
  color: var(--muted);
}
.palette-head button { font-size: 18px; padding: 0 8px; }

.palette {
  flex: 1 1 auto;
  overflow-y: auto;
  overflow-x: hidden;
  padding: 4px 10px 12px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.mode-note {
  padding: 6px 10px;
  font-size: 14px;
  color: var(--accent);
  border-bottom: 2px solid var(--border);
  background: rgba(198, 255, 61, .08);
}
.palette.dim { opacity: .35; pointer-events: none; }
.hidden { display: none !important; }
.swatch {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 3px 5px;
  border: 2px solid transparent;
  cursor: pointer;
  user-select: none;
  min-width: 0;
}
.swatch .chip {
  width: 20px; height: 20px;
  border: 2px solid var(--border);
  border-radius: 4px;
  flex: 0 0 auto;
}
.swatch .nm { font-size: 15px; color: var(--muted); overflow-wrap: anywhere; min-width: 0; }
.swatch.selected { border-color: var(--accent); background: rgba(198, 255, 61, .08); }
.swatch.selected .nm { color: var(--ink); }
.swatch:hover { background: var(--surface); }

.center { flex: 1 1 auto; min-width: 0; display: flex; }
.canvas-wrap {
  position: relative;
  flex: 1 1 auto;
  min-width: 0;
  max-width: 100%;
  overflow: auto;
  padding: 16px;
  background: var(--canvas);
}
canvas { image-rendering: pixelated; }

/* ─── Empty canvas ─── */
.canvas-empty {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 4px;
  padding: 16px;
  pointer-events: none;
  text-align: center;
}
.canvas-empty p { margin: 0; color: var(--ink); font-size: 28px; letter-spacing: 1px; }
.canvas-empty .canvas-empty-hint { color: var(--muted); font-size: 20px; letter-spacing: 0; }

.right {
  width: 250px;
  border-left: 3px solid var(--border);
  background: var(--panel);
  display: flex;
  flex-direction: column;
  min-height: 0;
  overflow-y: auto;
}
.right section { padding: 8px 10px; border-bottom: 2px solid var(--border); }
.sec-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 14px;
  letter-spacing: 1px;
  color: var(--muted);
  margin-bottom: 6px;
}
.sec-head button { font-size: 16px; padding: 0 8px; }
.hint { font-size: 13px; color: var(--muted); margin: 0 0 6px; }

.list { display: flex; flex-direction: column; gap: 4px; }
.item {
  display: flex;
  align-items: center;
  gap: 6px;
  border: 2px solid var(--border);
  background: var(--surface);
  padding: 4px 6px;
}
.item .nm-wrap { flex: 1 1 auto; min-width: 0; }
.item .nm { display: block; cursor: pointer; overflow-wrap: anywhere; word-break: break-word; }
.item .nm:hover { text-decoration: underline; }
.item .src { display: block; font-size: 13px; color: var(--muted); }
.item .sz { font-size: 13px; color: var(--muted); }
.item button { font-size: 14px; padding: 0 6px; box-shadow: none; }
.item.active { background: rgba(139, 92, 246, .18); border-color: var(--accent-2); }

/* ─── Modals ─── */
.overlay {
  position: fixed; inset: 0;
  background: rgba(2, 5, 9, .72);
  display: flex; align-items: center; justify-content: center;
  z-index: 50;
  backdrop-filter: blur(3px);
}
.overlay.hidden { display: none; }
.modal {
  background: var(--panel);
  border: 3px solid var(--border);
  box-shadow: 0 0 0 1px rgba(198, 255, 61, .12), 0 18px 60px rgba(0, 0, 0, .6);
  padding: 16px;
  width: 320px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.modal-head { display: flex; justify-content: space-between; align-items: center; }
.modal-head h3 { margin: 0; font-size: 21px; letter-spacing: 1px; }
.modal-head .x { font-size: 16px; padding: 0 8px; }
.modal > p { margin: 0; }
.modal label { font-size: 15px; color: var(--muted); }
.modal input[type="color"] { width: 100%; height: 44px; border: 2px solid var(--border); padding: 2px; background: var(--surface); }
.modal-actions { display: flex; gap: 8px; justify-content: flex-end; margin-top: 6px; }
#new-dims { display: flex; gap: 8px; }
#new-dims input { width: 80px; }

.count-list { display: flex; flex-direction: column; gap: 4px; max-height: 60vh; overflow-y: auto; }
.count-row {
  display: flex; align-items: center; gap: 8px;
  border-bottom: 1px solid var(--line);
  padding: 3px 0;
}
.count-row .chip { width: 16px; height: 16px; border: 2px solid var(--border); border-radius: 3px; }
.count-row .n { flex: 1 1 auto; }
.count-row .q { font-family: 'Press Start 2P', monospace; font-size: 13px; color: var(--accent); }
.empty-note { color: var(--muted); }

/* ─── Desktop-only gate ─── */
.mobile-gate { display: none; }

@media (max-width: 999px), (hover: none) and (pointer: coarse) {
  body { overflow: hidden; }
  .topbar, .layout { visibility: hidden; }
  .mobile-gate {
    position: fixed;
    inset: 0;
    z-index: 200;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 12px;
    padding: 28px;
    overflow-y: auto;
    text-align: center;
    background: radial-gradient(circle at 50% 0%, #101b2a 0%, var(--bg) 58%);
  }
  .mobile-gate-icon { width: 80px; height: 80px; }
  .mobile-gate h1 {
    margin: 0;
    font-family: 'Press Start 2P', monospace;
    font-size: 20px;
    line-height: 1.6;
    color: var(--accent);
  }
  .mobile-gate p { margin: 0; max-width: 30ch; color: var(--ink); font-size: 23px; }
  .mobile-gate .mobile-gate-en { color: var(--muted); font-size: 19px; }
  .mobile-gate-link {
    margin-top: 10px;
    color: var(--accent);
    font-size: 21px;
    text-decoration: none;
    border-bottom: 2px solid var(--accent);
  }
}

@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; }
}
