/* ---------- base ---------- */
:root {
  --bg: #f2f5f9;
  --fg: #1a1d23;
  --panel-bg: rgba(255, 255, 255, 0.92);
  --panel-bg-dark: rgba(20, 24, 32, 0.78);
  --panel-fg: #1a1d23;
  --border: rgba(0, 0, 0, 0.08);
  --shadow: 0 6px 24px rgba(0, 0, 0, 0.12);
  --accent: #2563eb;
  --danger: #dc2626;
  --radius: 10px;
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  color: var(--fg);
  background: var(--bg);
  overflow: hidden;
}

canvas.webgl {
  position: fixed;
  inset: 0;
  display: block;
  outline: none;
}

button {
  font: inherit;
  cursor: pointer;
  border: 1px solid var(--border);
  background: white;
  border-radius: 6px;
  padding: 6px 10px;
  transition: background 0.1s ease;
}
button:hover { background: #f3f4f6; }
button.primary { background: var(--accent); color: white; border-color: var(--accent); }
button.primary:hover { background: #1d4ed8; }
button.danger  { background: var(--danger); color: white; border-color: var(--danger); }
button.danger:hover { background: #b91c1c; }
input, select {
  font: inherit;
  padding: 6px 8px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: white;
}

/* ---------- top bar ---------- */
#topbar {
  position: fixed;
  top: 0; left: 0; right: 0;
  height: 44px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 14px;
  background: var(--panel-bg);
  backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--border);
  z-index: 30;
}
#brand { font-weight: 600; }
#user-area { display: flex; align-items: center; gap: 10px; }
#user-area a, #user-area button { font-size: 14px; }

/* ---------- legend (non-rotating UI panel) ---------- */
#legend {
  position: fixed;
  top: 58px;
  right: 14px;
  width: 230px;
  background: var(--panel-bg);
  backdrop-filter: blur(8px);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  z-index: 20;
  display: flex;
  flex-direction: column;
  max-height: calc(100vh - 80px);
}
#legend.collapsed ul, #legend.collapsed footer { display: none; }
#legend.collapsed { width: auto; }
#legend header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 8px 12px;
  border-bottom: 1px solid var(--border);
}
#legend h2 { margin: 0; font-size: 14px; font-weight: 600; }
#legend-collapse {
  border: none; background: transparent; font-size: 18px; line-height: 1;
  padding: 0 4px; cursor: pointer;
}
#legend-list {
  list-style: none; padding: 6px; margin: 0;
  overflow-y: auto;
}
#legend-list li {
  display: flex; align-items: center; gap: 8px;
  padding: 6px 8px;
  border-radius: 6px;
  cursor: pointer;
  user-select: none;
}
#legend-list li:hover { background: rgba(0,0,0,0.04); }
#legend-list li.hidden-status { opacity: 0.4; text-decoration: line-through; }
#legend-list li .swatch {
  width: 18px; height: 18px;
  border-radius: 4px;
  border: 1px solid rgba(0,0,0,0.15);
  flex-shrink: 0;
}
#legend-list li.multi .swatch {
  background: repeating-linear-gradient(45deg,
    var(--c1) 0 6px, var(--c2) 6px 12px);
}
#legend-list li .count {
  margin-left: auto;
  font-size: 11px;
  color: #6b7280;
}
#legend footer {
  padding: 6px 12px;
  border-top: 1px solid var(--border);
  color: #6b7280;
}

/* ---------- blind popup ---------- */
#blind-popup {
  position: fixed;
  z-index: 25;
  width: 280px;
  background: var(--panel-bg);
  backdrop-filter: blur(8px);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  font-size: 14px;
}
#blind-popup header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 8px 12px;
  border-bottom: 1px solid var(--border);
}
#popup-name { font-family: ui-monospace, "SF Mono", Consolas, monospace; }
#popup-close {
  border: none; background: transparent; font-size: 20px; line-height: 1;
  padding: 0 4px; cursor: pointer;
}
#blind-popup section { padding: 8px 12px; }
#popup-statuses .chip {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 3px 8px 3px 6px;
  border-radius: 999px;
  background: white;
  border: 1px solid var(--border);
  margin: 2px;
  font-size: 12px;
}
#popup-statuses .chip .dot {
  width: 10px; height: 10px; border-radius: 50%;
}
#popup-statuses .chip .x {
  border: none; background: transparent; padding: 0 2px; cursor: pointer;
  color: #6b7280; font-size: 14px;
}
#popup-statuses .chip .x:hover { color: var(--danger); }
#popup-add { display: flex; gap: 6px; align-items: center; border-top: 1px solid var(--border); }
#popup-add label { flex: 1; display: flex; gap: 4px; align-items: center; }
#popup-add select { flex: 1; }
#popup-history {
  border-top: 1px solid var(--border);
  font-size: 12px;
  color: #4b5563;
  max-height: 120px;
  overflow-y: auto;
}
#popup-history .entry { margin-bottom: 4px; }
#popup-history time { color: #9ca3af; }

/* ---------- toast ---------- */
#toast {
  position: fixed;
  bottom: 16px; left: 50%; transform: translateX(-50%);
  background: var(--panel-bg-dark);
  color: white;
  padding: 8px 14px;
  border-radius: 6px;
  font-size: 13px;
  z-index: 40;
  pointer-events: none;
}

/* ---------- auth pages ---------- */
body.auth-page {
  display: flex; align-items: center; justify-content: center;
  min-height: 100vh;
  background: linear-gradient(135deg, #e0e7ef 0%, #f2f5f9 100%);
}
.auth-card {
  background: white;
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 28px 32px;
  max-width: 360px;
  width: 90%;
}
.auth-card h1 { margin: 0 0 4px; font-size: 22px; }
.auth-sub { color: #6b7280; margin-top: 0; }
.auth-card form { display: flex; flex-direction: column; gap: 12px; }
.auth-card label { display: flex; flex-direction: column; gap: 4px; font-size: 13px; }
.auth-card button[type=submit] {
  background: var(--accent); color: white; border: none; padding: 10px;
  border-radius: 6px; font-size: 15px;
}
.auth-error { color: var(--danger); font-size: 13px; margin: 0; }
.auth-back { margin-top: 16px; font-size: 13px; }
.auth-back a { color: #6b7280; text-decoration: none; }

/* ---------- admin page ---------- */
body.admin-page { overflow: auto; }
.admin-wrap {
  max-width: 1100px; margin: 60px auto 40px; padding: 0 16px;
}
.admin-tabs {
  display: flex; gap: 4px; border-bottom: 1px solid var(--border);
  margin-bottom: 18px; flex-wrap: wrap;
}
.admin-tabs button {
  border: none; background: transparent; padding: 10px 14px;
  border-bottom: 2px solid transparent; border-radius: 0;
}
.admin-tabs button.active { border-bottom-color: var(--accent); color: var(--accent); }
.admin-section { display: none; }
.admin-section.active { display: block; }
.admin-section h2 { margin-top: 0; }

.list-table {
  width: 100%; border-collapse: collapse; font-size: 14px;
}
.list-table th, .list-table td {
  padding: 8px 10px; border-bottom: 1px solid var(--border); text-align: left;
}
.list-table th { font-weight: 600; color: #6b7280; font-size: 12px; text-transform: uppercase; letter-spacing: 0.04em; }
.list-table .swatch {
  display: inline-block; width: 18px; height: 18px; border-radius: 4px;
  border: 1px solid rgba(0,0,0,0.15); vertical-align: middle; margin-right: 8px;
}
.list-table .actions { display: flex; gap: 6px; }
.draggable { cursor: grab; }
.draggable.dragging { opacity: 0.5; }

.form-row { display: flex; gap: 8px; align-items: end; flex-wrap: wrap; }
.form-row label { display: flex; flex-direction: column; gap: 2px; font-size: 12px; color: #6b7280; }
.form-row input { min-width: 140px; }

.settings-grid { display: grid; gap: 12px; max-width: 540px; }
.settings-grid label { display: flex; flex-direction: column; gap: 4px; font-size: 13px; }
.settings-grid .row { display: flex; gap: 12px; align-items: center; }

/* ---------- mobile ---------- */
@media (max-width: 600px) {
  #legend { width: 200px; right: 8px; top: 50px; }
  #blind-popup { width: calc(100vw - 24px); max-width: 320px; }
  #topbar { padding: 0 10px; font-size: 14px; }
  .admin-wrap { margin-top: 50px; }
}
