:root {
  --bg: #0f1216;
  --panel: rgba(18, 21, 26, 0.94);
  --fg: #e8e6e1;
  --muted: #9a9890;
  --accent: #e0a458;
  --line: rgba(255, 255, 255, 0.08);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--fg); overflow: hidden; }
canvas#c { position: fixed; inset: 0; width: 100%; height: 100%; display: block; }

#hud { cursor: pointer; position: fixed; left: 16px; top: 14px; background: var(--panel); border: 1px solid var(--line); border-radius: 10px; padding: 10px 14px; max-width: 420px; font-size: 13px; z-index: 2; }
#hud-room { font-weight: 600; font-size: 15px; }
#hud-detail { color: var(--muted); margin-top: 2px; line-height: 1.4; }
#hud-detail b { color: var(--fg); }
#hud.mini #hud-detail, #hud.mini #hud-mode { display: none; }
#hud.mini { padding: 6px 12px; opacity: 0.85; }

#crosshair { position: fixed; left: 50%; top: 50%; width: 10px; height: 10px; margin: -5px 0 0 -5px; border: 1.5px solid rgba(255,255,255,0.7); border-radius: 50%; pointer-events: none; }

#overlay { position: fixed; inset: 0; display: flex; align-items: center; justify-content: center; background: rgba(0,0,0,0.45); cursor: pointer; z-index: 5; }
#overlay[hidden] { display: none; }
#overlay .card { background: var(--panel); border: 1px solid var(--line); border-radius: 14px; padding: 16px 20px; max-width: 560px; margin: 16px; font-size: 14px; line-height: 1.55; }
#overlay h1 { margin: 0 0 8px; font-size: 20px; }
#overlay h1 span { display: block; font-size: 13px; color: var(--muted); font-weight: 400; }
kbd { display: inline-block; padding: 1px 6px; border: 1px solid #555; border-bottom-width: 2px; border-radius: 4px; background: #23272e; font-size: 12px; margin: 0 1px; }
.muted { color: var(--muted); }
.legend i.sw { display: inline-block; width: 14px; height: 14px; border: 1px solid #777; vertical-align: -2px; margin: 0 4px 0 10px; }
.sw.full { background: #f3efe7; } .sw.cut { background: #f2c9a3; } .sw.L { background: #d9c3ef; } .sw.tk { background: #eceef0; background-image: radial-gradient(#2f5da8 1px, transparent 1.2px), radial-gradient(#7fa3d8 0.8px, transparent 1px); background-size: 5px 5px, 7px 7px; } .sw.pt { background: #f7f7f4; }

#toggle-panel { position: fixed; right: 16px; top: 14px; z-index: 4; background: var(--accent); color: #1a1408; border: 0; border-radius: 8px; padding: 8px 12px; font-weight: 600; cursor: pointer; }

#panel { position: fixed; right: 0; top: 0; height: 100%; width: min(560px, 100%); background: var(--panel); border-left: 1px solid var(--line); transform: translateX(100%); transition: transform 0.25s ease; z-index: 3; display: flex; flex-direction: column; padding-top: 56px; }
#panel.open { transform: none; }
#tabs { display: flex; gap: 4px; padding: 0 12px 8px; flex-wrap: wrap; border-bottom: 1px solid var(--line); }
#tabs button { background: transparent; color: var(--muted); border: 1px solid var(--line); border-radius: 6px; padding: 6px 10px; cursor: pointer; font-size: 13px; }
#tabs button.active { color: var(--fg); border-color: var(--accent); background: rgba(224,164,88,0.12); }
.tab { display: none; overflow: auto; padding: 12px 16px 40px; font-size: 13px; line-height: 1.5; }
.tab.active { display: block; }
.tab h2 { font-size: 16px; margin: 6px 0 8px; }
.tab h3 { font-size: 14px; margin: 16px 0 6px; color: var(--accent); }
table { width: 100%; border-collapse: collapse; margin: 6px 0 12px; font-size: 12.5px; }
th, td { padding: 5px 6px; border-bottom: 1px solid var(--line); text-align: left; vertical-align: top; }
th { color: var(--muted); font-weight: 500; }
td.num, th.num { text-align: right; white-space: nowrap; }
tr.total td { font-weight: 600; border-top: 1px solid rgba(255,255,255,0.2); }
.cuts { color: var(--muted); font-size: 11.5px; }
.badge { display: inline-block; padding: 1px 6px; border-radius: 10px; font-size: 11px; background: rgba(224,164,88,0.18); color: var(--accent); }
.warn { background: rgba(224, 120, 88, 0.12); border-left: 3px solid #e07858; padding: 8px 10px; border-radius: 6px; margin: 8px 0; }
.ok { background: rgba(120, 200, 120, 0.1); border-left: 3px solid #7ac87a; padding: 8px 10px; border-radius: 6px; margin: 8px 0; }
.row-click { cursor: pointer; }
.row-click:hover td { background: rgba(255,255,255,0.04); }

.gallery { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 8px; margin: 8px 0 14px; }
.gallery.small { grid-template-columns: repeat(3, 1fr); }
.gallery img { width: 100%; aspect-ratio: 1 / 1.2; object-fit: cover; border-radius: 6px; border: 1px solid var(--line); cursor: zoom-in; background: #fff; }
.gallery.small img { aspect-ratio: 1; }
.gallery figure { margin: 0; }
.gallery figcaption { font-size: 11px; color: var(--muted); margin-top: 3px; }
.btn { display: inline-block; background: var(--accent); color: #1a1408; border: 0; border-radius: 8px; padding: 8px 12px; font-weight: 600; text-decoration: none; cursor: pointer; }
.form label { display: block; margin: 8px 0; }
.form input[type=number], .form select { background: #1c2027; color: var(--fg); border: 1px solid #444; border-radius: 6px; padding: 5px 8px; width: 90px; }
.form select { width: 100%; max-width: 420px; }
.form small { color: var(--muted); margin-left: 6px; }
.form .row { display: inline-flex; gap: 6px; }
.form .row input { width: 70px; }
code { background: #1c2027; padding: 1px 5px; border-radius: 4px; font-size: 12px; }

#lightbox { position: fixed; inset: 0; background: rgba(0,0,0,0.9); z-index: 10; display: flex; align-items: center; justify-content: center; }
#lightbox[hidden] { display: none; }
#lightbox img { max-width: 96vw; max-height: 92vh; background: #fff; border-radius: 4px; }
#lightbox button { position: absolute; top: 50%; transform: translateY(-50%); background: rgba(255,255,255,0.15); color: #fff; border: 0; font-size: 34px; width: 48px; height: 64px; border-radius: 8px; cursor: pointer; }
#lb-prev { left: 12px; } #lb-next { right: 12px; }
#lb-close { top: 20px; right: 12px; transform: none; height: 40px; width: 40px; font-size: 20px; }
#lb-cap { position: absolute; bottom: 14px; left: 0; right: 0; text-align: center; color: #ddd; font-size: 13px; }

@media (max-width: 700px) {
  #hud { max-width: calc(100% - 32px); font-size: 12px; }
  #panel { width: 100%; }
}

#viewbar { position: fixed; right: 16px; bottom: 16px; z-index: 2; display: flex; flex-direction: column; gap: 6px; align-items: flex-end; }
#viewbar .grp { display: flex; gap: 4px; background: var(--panel); border: 1px solid var(--line); border-radius: 10px; padding: 4px; align-items: center; }
#viewbar button { background: transparent; color: var(--muted); border: 0; border-radius: 7px; padding: 6px 10px; cursor: pointer; font-size: 13px; white-space: nowrap; }
#viewbar button:hover { color: var(--fg); background: rgba(255,255,255,0.06); }
#viewbar button.active { color: #1a1408; background: var(--accent); font-weight: 600; }
#viewbar .lbl { color: var(--muted); font-size: 12px; padding: 0 6px 0 8px; }
#panel.open ~ #viewbar { right: min(576px, calc(100% - 16px)); }
@media (max-width: 700px) { #viewbar { left: 8px; right: 8px; align-items: stretch; } #viewbar .grp { justify-content: space-between; } }
