:root {
  --bg: #101418;
  --fg: #f2f4f6;
  --muted: #aab4bf;
  --accent: #f6c35a;
  --accent-fg: #1a1200;
  --card: rgba(16, 20, 24, 0.86);
  --btn: rgba(255, 255, 255, 0.12);
  --btn-border: rgba(255, 255, 255, 0.25);
  --ok: #7ad67a;
  --warn: #ffb347;
  --bad: #ff7a7a;
  --sat: env(safe-area-inset-top, 0px);
  --sab: env(safe-area-inset-bottom, 0px);
}
* { box-sizing: border-box; }
html, body {
  margin: 0; height: 100%; overflow: hidden; background: var(--bg); color: var(--fg);
  font: 16px/1.4 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-text-size-adjust: 100%; overscroll-behavior: none; touch-action: none;
}
#cam {
  position: fixed; inset: 0; width: 100%; height: 100%; object-fit: cover; z-index: 0;
  background: #000; display: none;
}
#gl { position: fixed; inset: 0; width: 100%; height: 100%; z-index: 1; display: block; }
#overlay { position: fixed; inset: 0; z-index: 2; pointer-events: auto; }
.hidden { display: none !important; }

#hud {
  position: absolute; left: 0; right: 0; top: 0; padding: calc(8px + var(--sat)) 12px 8px;
  background: linear-gradient(rgba(0,0,0,.65), rgba(0,0,0,0));
  font-size: 13px; line-height: 1.35; white-space: pre-line; text-shadow: 0 1px 2px #000;
  pointer-events: none;
}
#hint {
  text-align: center; font-size: 15px; padding: 8px 12px; margin: 0 2px 4px; border-radius: 10px;
  background: rgba(0,0,0,.6); text-shadow: 0 1px 2px #000; pointer-events: none;
}

#panel {
  position: absolute; left: 0; right: 0; bottom: 0; max-height: 100%; overflow-y: auto;
  padding: 16px 16px calc(16px + var(--sab)); background: var(--card);
  backdrop-filter: blur(8px); -webkit-backdrop-filter: blur(8px);
  border-radius: 16px 16px 0 0; touch-action: pan-y;
}
#panel h1 { margin: 0 0 10px; font-size: 22px; }
#panel .tag { font-size: 13px; color: var(--muted); font-weight: normal; margin-left: 8px; }
#panel .lead { margin: 0 0 10px; color: var(--muted); }
.caps { font-size: 14px; margin-bottom: 12px; white-space: pre-line; }
.caps .ok { color: var(--ok); } .caps .warn { color: var(--warn); } .caps .bad { color: var(--bad); }

button {
  font: inherit; color: var(--fg); background: var(--btn); border: 1px solid var(--btn-border);
  border-radius: 10px; padding: 12px 14px; min-height: 48px; cursor: pointer; touch-action: manipulation;
}
button.primary { background: var(--accent); color: var(--accent-fg); border-color: transparent; font-weight: 600; font-size: 18px; }
button.ghost { background: transparent; }
button:disabled { opacity: .5; }
.actions { display: flex; gap: 10px; margin-bottom: 12px; }
.actions button { flex: 1; }

details { margin-top: 4px; }
summary { cursor: pointer; padding: 8px 0; color: var(--muted); }
.grid { display: grid; grid-template-columns: 1fr 1fr; gap: 8px 10px; margin: 10px 0; }
label { display: flex; flex-direction: column; font-size: 12px; color: var(--muted); gap: 4px; }
input {
  font: inherit; font-size: 16px; color: var(--fg); background: rgba(255,255,255,.08);
  border: 1px solid var(--btn-border); border-radius: 8px; padding: 8px 10px; width: 100%;
}
.row { display: flex; gap: 8px; margin: 8px 0; flex-wrap: wrap; }
.row button { flex: 1; }
.msg { min-height: 1.4em; margin: 8px 0 0; color: var(--accent); font-size: 14px; }
.foot { margin: 10px 0 0; font-size: 12px; color: var(--muted); }

#controls {
  position: absolute; left: 0; right: 0; bottom: 0; padding: 8px 10px calc(10px + var(--sab));
  display: flex; flex-direction: column; gap: 8px;
  background: linear-gradient(rgba(0,0,0,0), rgba(0,0,0,.7));
}
.ctl-row { display: flex; gap: 8px; }
.ctl-row button { flex: 1; padding: 10px 6px; font-size: 14px; background: rgba(0,0,0,.55); }
.ctl-row[data-mode] { display: none; }
#controls[data-mode="xr"] .ctl-row[data-mode="xr"],
#controls[data-mode="compass"] .ctl-row[data-mode="compass"] { display: flex; }

@media (min-width: 700px) {
  #panel { left: 50%; transform: translateX(-50%); width: 560px; bottom: 16px; border-radius: 16px; }
}

#planWrap { margin: 4px 0 12px; }
#plan {
  display: block; width: 100%; aspect-ratio: 1 / 1; border-radius: 12px;
  background: #0b0e11; border: 1px solid var(--btn-border); touch-action: none;
}
.plan-row { margin: 8px 0 0; }
.plan-row button { padding: 10px 6px; font-size: 14px; min-height: 42px; }
.plan-row button.active { border-color: var(--ok); color: var(--ok); }

#preset, #tex, #quality {
  font: inherit; font-size: 15px; color: var(--fg); background: rgba(255,255,255,.08);
  border: 1px solid var(--btn-border); border-radius: 10px; padding: 10px 12px; width: 100%; margin-bottom: 8px;
}
.note { margin: 8px 2px 0; font-size: 13px; color: var(--muted); line-height: 1.4; }

#snap {
  position: absolute; inset: 0; z-index: 5; background: rgba(0,0,0,.92); display: flex; flex-direction: column;
  align-items: center; justify-content: center; padding: calc(12px + var(--sat)) 12px calc(12px + var(--sab)); gap: 10px;
}
#snap img { max-width: 100%; max-height: 72vh; border-radius: 10px; box-shadow: 0 4px 24px rgba(0,0,0,.6); }
#snap .row { width: 100%; max-width: 480px; }
#controls[data-mode="compass"] [data-xr-only] { display: none; }
