:root {
  --bg: #111418;
  --panel: rgba(22, 26, 32, 0.94);
  --text: #eef1f4;
  --muted: #9aa3ad;
  --accent: #4f9dff;
  --good: #3ddc84;
  --gold: #ffcc00;
  --danger: #ff6b6b;
  --line: rgba(255, 255, 255, 0.12);
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-t: env(safe-area-inset-top, 0px);
  color-scheme: dark;
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--text);
  font: 15px/1.4 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif; overflow: hidden; }
button { font: inherit; color: inherit; }
[hidden] { display: none !important; }
.muted { color: var(--muted); }
.small { font-size: 13px; }

#app { position: fixed; inset: 0; }
/* Home-Screen app on iPhone: the layout viewport stopped ~48 pt short of the
   screen's bottom (reports: 848 of 896 pt), leaving a dark band under the tab
   bar. Size the app to the whole screen there (100lvh); the tab bar keeps its
   safe-area padding. Browser tabs keep inset: 0 (their toolbars come and go). */
@media (display-mode: standalone) {
  html, body { height: 100lvh; }
  #app { bottom: auto; height: 100lvh; }
}
#video, #overlay { position: absolute; inset: 0; width: 100%; height: 100%; }
#video { object-fit: cover; background: #000; }
#overlay { touch-action: none; }
/* Table view (Map mode): fills the screen above the camera layers. */
#tableMap { position: absolute; inset: 0; width: 100%; height: 100%; touch-action: none; background: #1a1f26; } /* after #video/#overlay in the DOM: paints above them, below the bars */
#mapCtrls { position: absolute; right: 10px; top: calc(var(--top-h, 52px) + 8px); /* below the top bar, which can wrap to 2-3 lines */ z-index: 6; display: flex; flex-direction: column; gap: 8px; }
#mapCtrls button { border: 1px solid var(--line); border-radius: 10px; padding: 8px 12px; background: rgba(0, 0, 0, 0.62); color: var(--text); font-size: 13px; }

#topbar { position: absolute; top: calc(var(--safe-t) + 8px); left: 50%; transform: translateX(-50%);
  display: flex; gap: 8px; align-items: center; padding: 6px 14px; border-radius: 999px;
  background: rgba(0, 0, 0, 0.55); backdrop-filter: blur(8px); -webkit-backdrop-filter: blur(8px);
  font-size: 14px; max-width: calc(100% - 24px); flex-wrap: wrap; justify-content: center; row-gap: 2px;
  border-radius: 18px; }
#topbar #stats { white-space: nowrap; }
#stats.warn { color: #ffb347; }
#modeHint { color: var(--muted); text-align: center; line-height: 1.3; } /* wraps instead of being cut off */
.dot { width: 10px; height: 10px; border-radius: 50%; background: var(--muted); flex: none; }
.dot.on { background: var(--good); box-shadow: 0 0 8px var(--good); }
.dot.lost { background: var(--danger); }

#banner { position: absolute; top: calc(var(--top-h, 52px) + 6px); left: 12px; right: 12px; text-align: center;
  padding: 8px 12px; border-radius: 10px; background: rgba(120, 30, 30, 0.75); font-size: 14px; }
#frameBar { position: absolute; top: calc(var(--top-h, 52px) + 6px); left: 10px; right: 10px; padding: 10px 12px;
  border-radius: 12px; background: rgba(20, 60, 110, 0.95); font-size: 14px; z-index: 8; }
.teach-actions { display: flex; gap: 8px; justify-content: flex-end; margin-top: 8px; }
.teach-actions button { border: 0; border-radius: 8px; padding: 6px 12px; background: rgba(255, 255, 255, 0.15); }
.teach-actions .strong { background: var(--accent); font-weight: 600; }
#toast { position: absolute; left: 50%; bottom: calc(var(--safe-b) + 96px); transform: translateX(-50%);
  background: rgba(0, 0, 0, 0.8); padding: 10px 16px; border-radius: 12px; max-width: 90%; text-align: center; }
#debug { position: absolute; top: calc(var(--top-h, 52px) + 54px); left: 8px; margin: 0; padding: 6px 8px;
  font: 11px/1.35 ui-monospace, Menlo, monospace; background: rgba(0, 0, 0, 0.6); border-radius: 6px; pointer-events: none; }

/* Camera paused (menu open, or the phone was left sitting still). */
#resume { position: absolute; inset: 0; z-index: 7; display: flex; flex-direction: column; gap: 6px;
  align-items: center; justify-content: center; border: 0; background: rgba(10, 13, 17, 0.88); color: var(--text); }
#resume strong { font-size: 19px; }
#resume span { color: var(--muted); }

/* Find-mode chips: piece classes to light up, match cycling, map toggle. */
/* The gaps between chips stay click-through, so the chip row never steals a
   tap meant for a piece underneath it. */
/* One row that scrolls sideways (v0.20; two wrapped rows plus the tab bar
   left the camera ~60% of the screen). */
#findBar { position: absolute; left: 0; right: 0; bottom: calc(var(--safe-b) + 68px); z-index: 6;
  display: flex; flex-wrap: nowrap; overflow-x: auto; justify-content: flex-start; gap: 6px; padding: 6px 10px;
  scrollbar-width: none; -webkit-overflow-scrolling: touch; }
#findBar::-webkit-scrollbar { display: none; }
body.panel-open #findBar, body.panel-open #matchBar { display: none; }
#findBar button { pointer-events: auto; flex: none; border: 1px solid var(--line); border-radius: 999px; padding: 7px 12px;
  background: rgba(0, 0, 0, 0.62); backdrop-filter: blur(8px); -webkit-backdrop-filter: blur(8px);
  color: var(--text); font-size: 13px; }
#findBar button.on { background: var(--accent); border-color: transparent; font-weight: 600; }
#findBar button[data-filter=corner].on { background: #ff8c3a; color: #111418; }
#findBar button[data-filter=border].on { background: #35e0d8; color: #111418; }
#findBar button:disabled { opacity: 0.45; }

#matchBar { position: absolute; left: 8px; right: 8px; bottom: calc(var(--safe-b) + 120px); z-index: 6;
  display: flex; align-items: center; gap: 6px; padding: 8px 10px; border-radius: 14px;
  background: rgba(22, 26, 32, 0.94); box-shadow: 0 4px 18px rgba(0, 0, 0, 0.5); }
#matchBar > button { border: 0; background: rgba(255, 255, 255, 0.1); border-radius: 10px;
  width: 36px; height: 48px; font-size: 24px; line-height: 1; flex: none; }
#matchBar > button:disabled { opacity: 0.35; }
.match-acts { display: flex; justify-content: center; gap: 8px; margin-top: 6px; }
.match-acts button { border: 0; border-radius: 8px; padding: 5px 16px; background: rgba(255, 255, 255, 0.12); color: var(--text); font-size: 13px; }
.match-acts button.yes { background: rgba(61, 220, 132, 0.28); }
.cand.unconfirmed canvas { border-style: dashed; }
.cand.weak { opacity: 0.55; }
.cand .verdict { font-weight: 600; color: var(--text); }
.cand.gold .verdict { color: var(--gold); }
.sel-acts { display: flex; align-items: center; gap: 10px; margin: 0 0 8px; flex-wrap: wrap; }
#inPuzzleBtn { border: 1px solid var(--line); border-radius: 8px; padding: 6px 10px; background: rgba(255, 255, 255, 0.08); font-size: 13px; }
#inPuzzleBtn.on { background: rgba(61, 220, 132, 0.25); border-color: #3ddc84; }
#uprightBox { display: flex; align-items: center; gap: 8px; flex: 1 1 220px; }
#uprightBox[hidden] { display: none; }
#selUpright { width: 56px; height: 56px; border-radius: 8px; background: #000; flex: none; }
#coach { position: absolute; left: 12px; right: 12px; top: calc(var(--top-h, 52px) + 44px); z-index: 7; display: flex; gap: 10px; align-items: center;
  padding: 10px 12px; border-radius: 12px; background: rgba(20, 24, 30, 0.92); border: 1px solid #ffcc00; font-size: 13px; }
#coach[hidden] { display: none; }
.lib { margin: 12px 0 4px; }
#libList .lib-row { display: flex; align-items: center; gap: 8px; padding: 6px 0; border-bottom: 1px solid var(--line); }
#libList .lib-row span { flex: 1; }
#libList .lib-row button { border: 1px solid var(--line); border-radius: 8px; padding: 4px 10px; background: rgba(255, 255, 255, 0.08); font-size: 12px; }
#coach button { flex: none; border: 0; border-radius: 8px; padding: 6px 10px; background: #ffcc00; color: #111; font-weight: 600; }
#matchBar .icon-btn { height: 32px; width: 32px; font-size: 15px; }
.match-mid { flex: 1; min-width: 0; text-align: center; }
.match-pics { display: flex; gap: 8px; justify-content: center; align-items: center; }
.match-pics canvas { width: 56px; height: 56px; border-radius: 8px; background: #000; border: 2px solid transparent; }
#matchA { border-color: #ffffff; }
#matchB { border-color: var(--gold); }
#matchLabel { margin-top: 4px; color: var(--muted); }
.warn-note { color: #ffb347; }

/* A corner thumbnail (owner's screenshots: at 42% of the width it covered a
   quarter of the camera view); tap to enlarge. */
#minimap { position: absolute; left: 10px; bottom: calc(var(--safe-b) + 78px); width: 28vw; max-width: 220px;
  border-radius: 8px; border: 1px solid var(--line); box-shadow: 0 4px 16px rgba(0, 0, 0, 0.5); touch-action: none; }
#minimap.big { width: calc(100vw - 20px); max-width: 720px; }
#minimap.right:not(.big) { left: auto; right: 10px; }
/* Keep the box picture clear of the chip bar / match cycler stacked above the toolbar. */
body.findbar #minimap { bottom: calc(var(--safe-b) + 116px); } /* above the one-row find bar */
body.findbar.matchbar #minimap { bottom: calc(var(--safe-b) + 226px); }

#toolbar { position: absolute; left: 0; right: 0; bottom: 0; display: flex; justify-content: space-around;
  padding: 8px 6px calc(var(--safe-b) + 8px); background: linear-gradient(transparent, rgba(0, 0, 0, 0.75) 35%); }
#toolbar button { flex: 1; background: none; border: 0; padding: 6px 0; display: flex; flex-direction: column;
  align-items: center; gap: 2px; font-size: 12px; color: var(--muted); }
#toolbar button .ico { font-size: 22px; line-height: 1; }
#toolbar button.active { color: var(--text); }
#toolbar button.active .ico { color: var(--accent); }
/* Border toggle (not a mode): lit in the corner-piece orange while on. */
#toolbar button.on { color: var(--text); }
#toolbar button.on .ico { color: #ff8c3a; }

.sheet { position: absolute; left: 0; right: 0; bottom: 0; max-height: 62vh; overflow-y: auto;
  background: var(--panel); border-radius: 16px 16px 0 0; padding: 12px 14px calc(var(--safe-b) + 14px);
  box-shadow: 0 -6px 24px rgba(0, 0, 0, 0.5); z-index: 5; }
.sheet-head { display: flex; align-items: center; gap: 10px; margin-bottom: 8px; }
.sheet-head strong { flex: 1; }
/* Folded to its header so the camera view (and the piece's spot inside the
   marked border) can be seen while the piece stays selected. */
#findPanel.peek > :not(.sheet-head) { display: none; }
#findPanel.peek .sheet-head { margin-bottom: 0; }
.sel-info { flex: 1; display: flex; flex-direction: column; }
.sel-info span { color: var(--muted); font-size: 13px; }
.icon-btn { background: rgba(255, 255, 255, 0.08); border: 0; border-radius: 50%; width: 32px; height: 32px; }
#selThumb { width: 56px; height: 56px; border-radius: 8px; background: #000; }

.edge-row { border-top: 1px solid var(--line); padding: 8px 0; }
.edge-row h4 { margin: 0 0 6px; font-size: 13px; font-weight: 600; display: flex; align-items: center; gap: 8px; }
.edge-row h4 .sw { width: 12px; height: 12px; border-radius: 3px; }
.cands { display: flex; gap: 10px; overflow-x: auto; padding-bottom: 2px; }
.cand { flex: none; width: 84px; text-align: center; font-size: 11px; color: var(--muted); }
.cand canvas { width: 72px; height: 72px; border-radius: 8px; background: #000; border: 2px solid transparent; }
.cand.gold canvas { border-color: var(--gold); }
.cand.silver canvas { border-color: #c0c0c0; }
.cand .acts { display: flex; justify-content: center; gap: 6px; margin-top: 3px; }
.cand .acts button { border: 0; border-radius: 6px; padding: 3px 8px; background: rgba(255, 255, 255, 0.1); font-size: 12px; }
.cand .acts button.yes { background: rgba(61, 220, 132, 0.25); }
.empty { color: var(--muted); font-size: 13px; }

#menu label.row { display: flex; align-items: center; gap: 10px; margin: 10px 0; }
#menu input[type=range] { flex: 1; }
.menu-actions { display: flex; flex-direction: column; gap: 8px; margin: 14px 0; }
.menu-actions button { padding: 10px; border-radius: 10px; border: 1px solid var(--line); background: rgba(255, 255, 255, 0.06); }
.menu-actions .danger { color: var(--danger); }
details summary { cursor: pointer; color: var(--accent); }
details ul { padding-left: 18px; }
#colorKeyList h4 { margin: 10px 0 4px; font-size: 13px; color: var(--muted); font-weight: 600; }
#colorKeyList .key-row { display: flex; align-items: center; gap: 10px; padding: 3px 0; }
#colorKeyList canvas { width: 28px; height: 28px; flex: none; }

.screen { position: fixed; inset: 0; background: var(--bg); z-index: 10; display: flex; flex-direction: column; }
#start { align-items: center; justify-content: center; padding: 24px; }
.start-card { max-width: 420px; text-align: center; }
.start-card h1 { margin: 0 0 8px; font-size: 30px; }
.primary { background: var(--accent); color: #fff; border: 0; border-radius: 12px; padding: 14px 28px; font-size: 17px; font-weight: 600; margin: 14px 0 6px; }
.primary:disabled { opacity: 0.5; }
a { color: var(--accent); }

.box-head { display: flex; align-items: center; justify-content: space-between; padding: calc(var(--safe-t) + 10px) 14px 10px;
  border-bottom: 1px solid var(--line); }
.link { background: none; border: 0; color: var(--accent); padding: 6px; font-size: 16px; }
.link.strong { font-weight: 700; }
.link:disabled { color: var(--muted); }
#boxBody { flex: 1; position: relative; display: flex; flex-direction: column; align-items: center; justify-content: center; min-height: 0; padding: 10px; }
#boxEmpty { text-align: center; max-width: 340px; }
#boxCanvas { touch-action: none; flex: none; }
#frameBody { flex: 1; display: flex; align-items: center; justify-content: center; min-height: 0; padding: 10px; }
#frameCanvas { touch-action: none; flex: none; }
.frame-controls { display: flex; gap: 12px; align-items: center; padding: 10px 14px calc(var(--safe-b) + 14px); border-top: 1px solid var(--line); }
.frame-controls p { margin: 0; flex: 1; }
#frameBox { flex: none; }
.box-controls { display: flex; flex-wrap: wrap; gap: 12px 18px; align-items: center; justify-content: center;
  padding: 10px 14px calc(var(--safe-b) + 14px); border-top: 1px solid var(--line); }
.box-controls input { width: 64px; padding: 6px; border-radius: 8px; border: 1px solid var(--line); background: #1b2027; color: var(--text); font-size: 15px; }
#boxPieces { width: 76px; }

/* Piece view: a tapped piece's picture and outline geometry */
#pieceBody { flex: 1; overflow-y: auto; display: flex; flex-direction: column; align-items: center; gap: 12px; padding: 12px 14px calc(var(--safe-b) + 16px); }
#pieceBody canvas { width: 100%; max-width: 460px; aspect-ratio: 1; background: #111; border-radius: 10px; flex: none; }
#pieceFacts { width: 100%; max-width: 460px; line-height: 1.5; }
#pieceFacts b { font-weight: 600; }

/* Build view: groups of joined pieces */
#buildBody { flex: 1; overflow-y: auto; padding: 12px 14px calc(var(--safe-b) + 16px); }
#buildGroups { display: flex; flex-direction: column; gap: 14px; align-items: flex-start; margin: 8px 0 16px; }
#buildGroups .grp { overflow-x: auto; max-width: 100%; }
#buildGroups .grp p { margin: 4px 0 0; }
#buildGroups canvas { border-radius: 8px; display: block; }
#buildJoins { padding-left: 22px; line-height: 1.6; }

/* Settings: full screen - the camera is off while it is open (owner, 2026-10-11) */
#menu { position: fixed; top: 0; bottom: 0; max-height: none; border-radius: 0; box-shadow: none;
  padding-top: calc(var(--safe-t) + 12px); z-index: 10; }
