/* GhostBoard — haunted harbor theme. Functional first: high contrast,
   big touch targets for cheap Android phones, no heavy assets. */

:root {
  --bg: #0b1c2c;
  --bg2: #0e2536;
  --panel: #122c40;
  --panel2: #16405c;
  --ink: #eef6f8;
  --muted: #a9c3cf;
  --line: #2a4a61;
  --lantern: #ffd166;
  --lantern-off: #8a7a4d;
  --ok: #7ee2a0;
  --warn: #ffb454;
  --warn-bg: #3a2a12;
  --accent: #6fd3e7;
  --radius: 12px;
}

* { box-sizing: border-box; }

/* The hidden attribute must win over display rules below (e.g. the QR
 * canvas sets display:block when drawn — without this, a fresh page
 * would show an empty white box where the canvas hides). */
[hidden] { display: none !important; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  font-size: 17px;
  line-height: 1.55;
}

h1, h2, h3 { line-height: 1.25; margin: 0 0 0.5em; }
h1 { font-size: 1.9rem; letter-spacing: 0.02em; }
h2 { font-size: 1.25rem; }
h3 { font-size: 1.1rem; }
p { margin: 0 0 0.75em; }
.muted { color: var(--muted); font-size: 0.92rem; }

/* Header + lantern (the online/offline signal) */
.site-header {
  display: flex;
  flex-wrap: wrap;
  gap: 16px;
  align-items: center;
  justify-content: space-between;
  padding: 18px 20px;
  background: linear-gradient(180deg, #103049, var(--bg2));
  border-bottom: 2px solid var(--line);
}
.brand { display: flex; gap: 12px; align-items: flex-start; }
.ghost { font-size: 2.4rem; line-height: 1; }
.tagline { color: var(--muted); margin: 0; max-width: 560px; }
.header-right { display: flex; gap: 14px; align-items: center; flex-wrap: wrap; }

.net-status {
  display: flex;
  gap: 10px;
  align-items: center;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 8px 14px;
  font-weight: 600;
}
.lantern {
  width: 18px; height: 18px; border-radius: 50%;
  background: var(--lantern-off);
  flex: none;
}
.lantern.on {
  background: var(--lantern);
  box-shadow: 0 0 14px 4px rgba(255, 209, 102, 0.55);
}
.lantern.off { background: var(--lantern-off); box-shadow: none; }
.lantern.syncing { animation: flicker 0.7s infinite alternate; }
@keyframes flicker {
  from { box-shadow: 0 0 4px 1px rgba(255, 209, 102, 0.3); }
  to { box-shadow: 0 0 16px 5px rgba(255, 209, 102, 0.65); }
}

.lang-toggle button {
  min-height: 44px; min-width: 52px;
  background: var(--panel); color: var(--ink);
  border: 1px solid var(--line); border-radius: 8px;
  font-size: 1rem; font-weight: 700; cursor: pointer;
}
.lang-toggle button.active { background: var(--accent); color: #08222f; border-color: var(--accent); }

/* Fog = syncing */
.fog-bar {
  display: none;
  text-align: center;
  letter-spacing: 0.5em;
  color: var(--muted);
  background: linear-gradient(90deg, transparent, #1d4258, transparent);
  padding: 4px 0;
}
.fog-bar.visible { display: block; }
.queue-banner {
  margin: 0;
  padding: 10px 20px;
  background: var(--warn-bg);
  color: var(--warn);
  font-weight: 600;
  text-align: center;
}

/* Layout */
.layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 360px;
  gap: 20px;
  max-width: 1180px;
  margin: 0 auto;
  padding: 20px;
  align-items: start;
}
@media (max-width: 900px) {
  .layout { grid-template-columns: 1fr; }
}

.board-head { display: flex; flex-wrap: wrap; gap: 8px; align-items: baseline; justify-content: space-between; }
.board-head h2 { margin: 0; }
.count { color: var(--muted); margin: 0; }

.filter-bar { display: flex; flex-wrap: wrap; gap: 8px; margin: 14px 0 10px; }
.chip {
  min-height: 44px;
  padding: 8px 14px;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: var(--panel);
  color: var(--ink);
  font-size: 0.98rem;
  cursor: pointer;
}
.chip.active { background: var(--accent); color: #08222f; border-color: var(--accent); font-weight: 700; }

.search {
  width: 100%;
  min-height: 48px;
  padding: 10px 14px;
  border-radius: 10px;
  border: 1px solid var(--line);
  background: var(--panel);
  color: var(--ink);
  font-size: 1rem;
  margin-bottom: 16px;
}
.search::placeholder { color: var(--muted); }

/* Listing cards */
.board { display: grid; gap: 14px; }
.card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 16px 18px;
}
.card.is-queued { border-style: dashed; border-color: var(--warn); }
.card-top { display: flex; justify-content: space-between; gap: 8px; align-items: center; margin-bottom: 6px; }
.cat {
  font-size: 0.85rem; font-weight: 700; letter-spacing: 0.04em;
  text-transform: uppercase; color: var(--accent);
}
.price-line { font-size: 1.05rem; margin: 0 0 0.5em; }
.warning {
  background: var(--warn-bg);
  border: 1px solid var(--warn);
  color: var(--warn);
  border-radius: 8px;
  padding: 8px 10px;
  font-weight: 600;
}
.meta { color: var(--muted); font-size: 0.92rem; margin-bottom: 10px; }
.badges { display: flex; flex-wrap: wrap; gap: 6px; }
.badge {
  display: inline-block;
  font-size: 0.85rem;
  border-radius: 999px;
  padding: 3px 10px;
  border: 1px solid var(--line);
}
.badge-ok { background: #123524; color: var(--ok); border-color: #2c6b45; }
.badge-warn { background: var(--warn-bg); color: var(--warn); border-color: var(--warn); }
.badge-muted { background: var(--bg2); color: var(--muted); }
.empty { color: var(--muted); padding: 20px 0; }

/* Side panels + form */
.side { display: grid; gap: 16px; }
.panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 16px 18px;
}
.panel h2 { margin-top: 0; }
.crew-list { padding-left: 0; list-style: none; margin: 0 0 10px; }
.crew-list li { margin-bottom: 12px; }
.crew-stats { color: var(--muted); font-size: 0.92rem; margin: 0; }

form label { display: block; margin-bottom: 12px; font-weight: 600; }
form label span { display: block; margin-bottom: 4px; }
input, select, textarea {
  width: 100%;
  min-height: 48px;
  padding: 10px 12px;
  border-radius: 10px;
  border: 1px solid var(--line);
  background: var(--bg2);
  color: var(--ink);
  font-size: 1rem;
  font-family: inherit;
}
textarea { min-height: 96px; resize: vertical; }
input:focus, select:focus, textarea:focus, button:focus-visible {
  outline: 3px solid var(--accent);
  outline-offset: 2px;
}
.row { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
button.primary, button.secondary {
  width: 100%;
  min-height: 52px;
  border-radius: 10px;
  font-size: 1.05rem;
  font-weight: 700;
  cursor: pointer;
  border: none;
}
button.primary { background: var(--lantern); color: #231a05; margin-top: 4px; }
button.secondary {
  background: transparent;
  color: var(--ink);
  border: 1px solid var(--line);
  margin-top: 10px;
}
.check-line { display: flex; gap: 10px; align-items: center; font-weight: 600; margin-top: 12px; }
.check-line input { width: auto; min-height: 24px; accent-color: var(--lantern); }
.form-msg { margin: 10px 0 0; color: var(--ok); font-weight: 600; }
.form-msg.error { color: var(--warn); }

.price-table { width: 100%; border-collapse: collapse; font-size: 0.95rem; }
.price-table th, .price-table td { text-align: left; padding: 6px 4px; border-bottom: 1px solid var(--line); }
.price-table th { color: var(--muted); }

.site-footer {
  border-top: 2px solid var(--line);
  padding: 18px 20px 28px;
  color: var(--muted);
  text-align: center;
  font-size: 0.92rem;
}
.site-footer p { margin: 0; }

/* ---- Display themes: CRT (default) + High-Contrast Modern ---- */
.theme-toggle button {
  min-height: 44px; min-width: 52px;
  background: var(--panel); color: var(--ink);
  border: 1px solid var(--line); border-radius: 8px;
  font-size: 1rem; font-weight: 700; cursor: pointer;
}
.theme-toggle button.active { background: var(--accent); color: #08222f; border-color: var(--accent); }

.crt-overlay {
  display: none;
  position: fixed; inset: 0;
  pointer-events: none;
  z-index: 40;
  background: repeating-linear-gradient(0deg, rgba(0, 0, 0, 0.16) 0 1px, transparent 1px 3px);
}
body[data-theme="crt"] .crt-overlay { display: block; }
body[data-theme="crt"] h1 { text-shadow: 0 0 14px rgba(111, 211, 231, 0.5); }

body[data-theme="modern"] {
  --bg: #f2f2ee; --bg2: #ffffff; --panel: #ffffff; --panel2: #e9eef2;
  --ink: #101418; --muted: #3c4750; --line: #6b7883;
  --lantern: #8a6d00; --lantern-off: #6b7280;
  --ok: #0b6e2f; --warn: #7a3e00; --warn-bg: #ffefd0;
  --accent: #0057b8;
}
body[data-theme="modern"] .site-header { background: #ffffff; }
body[data-theme="modern"] .crt-overlay { display: none; }
body[data-theme="modern"] h1 { text-shadow: none; }
body[data-theme="modern"] .badge-ok { background: #d9f2e2; color: #0b6e2f; border-color: #0b6e2f; }
body[data-theme="modern"] .badge-warn { background: #ffefd0; color: #7a3e00; border-color: #7a3e00; }
body[data-theme="modern"] .badge-muted { background: #e9eef2; color: #3c4750; }
body[data-theme="modern"] .warning { background: #ffefd0; border-color: #7a3e00; color: #7a3e00; }
body[data-theme="modern"] .fog-bar { background: #dfe7ec; }
body[data-theme="modern"] .queue-banner { background: #ffefd0; color: #7a3e00; }
body[data-theme="modern"] .lang-toggle button.active,
body[data-theme="modern"] .chip.active,
body[data-theme="modern"] .theme-toggle button.active { background: var(--accent); color: #ffffff; border-color: var(--accent); }
body[data-theme="modern"] button.primary { background: #0057b8; color: #ffffff; }
body[data-theme="modern"] .lantern.on { box-shadow: 0 0 10px 3px rgba(138, 109, 0, 0.45); }
body[data-theme="modern"] .form-msg { color: var(--ok); }

/* ---- Board picker ---- */
.board-picker { display: flex; gap: 10px; align-items: center; margin: 12px 0 4px; font-weight: 600; }
.board-picker select { width: auto; flex: 1; }
.board-desc { margin: 0 0 4px; }

/* ---- Sync packets panel ---- */
.btn-row { display: flex; flex-wrap: wrap; gap: 8px; margin: 10px 0; }
.btn-row button.secondary { width: auto; flex: 1 1 auto; min-width: 140px; margin-top: 0; }
.sync-result { color: var(--ok); font-weight: 600; margin: 10px 0 0; min-height: 1.4em; }
.qr-box { margin-top: 14px; border-top: 1px solid var(--line); padding-top: 12px; }
.qr-box label span { display: block; margin-bottom: 4px; font-weight: 600; }
.qr-box .secondary { width: auto; min-width: 140px; margin-top: 10px; }
.qr-canvas { display: block; margin: 12px auto; border: 1px solid var(--line); border-radius: 8px; background: #ffffff; max-width: 100%; }

/* ---- Persistent BBS command bar ---- */
body { padding-bottom: 64px; }
.cmd-bar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 50;
  display: flex; gap: 8px; align-items: center;
  padding: 8px 12px;
  background: var(--panel);
  border-top: 2px solid var(--line);
  font-family: ui-monospace, "Cascadia Mono", Consolas, monospace;
  overflow-x: auto;
}
.cmd-prompt { color: var(--lantern); font-weight: 700; flex: none; }
.cmd-bar button {
  flex: none;
  min-height: 40px; padding: 6px 10px;
  background: transparent; color: var(--ink);
  border: 1px solid var(--line); border-radius: 6px;
  font: inherit; font-size: 0.95rem; cursor: pointer;
}
.cmd-bar button:hover, .cmd-bar button:focus-visible { border-color: var(--accent); outline: 3px solid var(--accent); outline-offset: 1px; }
.cmd-help { color: var(--muted); font-size: 0.9rem; white-space: nowrap; }

@media (prefers-reduced-motion: reduce) {
  .lantern.syncing { animation: none; }
}
