:root {
  color-scheme: dark;
  --ink: #f4f7fb;
  --muted: #a9b7c9;
  --panel: rgba(7, 17, 31, 0.86);
  --line: rgba(255, 255, 255, 0.16);
  --signal: #ff5b35;
  --cyan: #70e1f5;
  --ok: #73e2a7;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* { box-sizing: border-box; }
html, body, #app { width: 100%; height: 100%; margin: 0; overflow: hidden; }
body { background: #07111f; color: var(--ink); }
button, select { font: inherit; }
button { color: inherit; }

.orientation-warning { display: none; }

#camera, #feature-overlay {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
}

#camera { background: radial-gradient(circle at 60% 35%, #18334c, #07111f 62%); }
#feature-overlay { pointer-events: none; }

#world-layer {
  position: fixed;
  z-index: 2;
  inset: 0;
  overflow: hidden;
  pointer-events: none;
}

#world-layer.interactive {
  cursor: crosshair;
  pointer-events: auto;
}

#world-layer.interactive::after {
  content: attr(data-prompt);
  position: absolute;
  left: 50%;
  top: 17%;
  padding: 9px 14px;
  transform: translateX(-50%);
  border: 1px solid rgba(255,255,255,.25);
  border-radius: 999px;
  background: rgba(7,17,31,.82);
  color: white;
  font-size: 12px;
  font-weight: 900;
  white-space: nowrap;
}

.world-canvas {
  display: block;
  width: 100%;
  height: 100%;
  pointer-events: none;
}

.topbar {
  position: fixed;
  z-index: 3;
  top: 0;
  left: 0;
  right: 0;
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  padding: max(18px, env(safe-area-inset-top)) 20px 20px;
  background: linear-gradient(to bottom, rgba(4, 12, 23, 0.92), transparent);
  pointer-events: none;
}

.eyebrow { margin: 0 0 5px; color: var(--cyan); font-size: 10px; font-weight: 800; letter-spacing: 0.18em; }
h1 { margin: 0; font-size: clamp(18px, 4vw, 26px); letter-spacing: -0.03em; }
h1 span { color: var(--muted); font-size: 0.58em; font-weight: 500; letter-spacing: 0.04em; }

.badge { padding: 8px 12px; border: 1px solid var(--line); border-radius: 999px; background: rgba(7,17,31,.72); font-size: 12px; font-weight: 800; }
.badge.tracking { color: #03140c; background: var(--ok); border-color: var(--ok); }
.badge.limited { color: #1d1300; background: #ffd166; border-color: #ffd166; }
.badge.lost { color: white; background: #db3a34; border-color: #db3a34; }

.card {
  position: fixed;
  z-index: 4;
  left: 50%;
  top: 50%;
  width: min(88vw, 430px);
  transform: translate(-50%, -50%);
  padding: 28px;
  border: 1px solid var(--line);
  border-radius: 22px;
  background: var(--panel);
  box-shadow: 0 24px 80px rgba(0,0,0,.42);
  backdrop-filter: blur(18px);
}

.phase-mark { color: var(--signal); font-size: 12px; font-weight: 900; letter-spacing: .22em; }
.card h2 { margin: 10px 0 8px; font-size: 25px; letter-spacing: -.03em; }
.card p { color: var(--muted); line-height: 1.65; }
.privacy { margin-bottom: 0; font-size: 11px; }

.primary, .secondary, select {
  border: 1px solid var(--line);
  border-radius: 12px;
}
.primary { width: 100%; padding: 15px 18px; border: 0; background: var(--signal); font-weight: 900; box-shadow: 0 10px 28px rgba(255, 91, 53, .3); }
.primary:disabled { opacity: .55; }
.secondary, select { min-height: 42px; padding: 9px 12px; background: rgba(7, 17, 31, .82); }
.place-button { min-height: 42px; padding: 9px 16px; border: 0; border-radius: 12px; background: #f05a2a; font-weight: 900; white-space: nowrap; }
.place-button[aria-pressed="true"] { color: #251100; background: #ffd166; box-shadow: 0 0 0 3px rgba(255,209,102,.25); }
.place-button:disabled, .secondary:disabled { opacity: .4; }
.drill-button { min-height: 42px; padding: 9px 16px; border: 0; border-radius: 12px; background: #d92f3f; font-weight: 900; white-space: nowrap; }
.drill-button:disabled { opacity: .4; }
.return-button { position: fixed; z-index: 7; top: max(18px, env(safe-area-inset-top)); right: 18px; width: 58px; height: 58px; border: 2px solid rgba(255,255,255,.58); border-radius: 50%; background: rgba(7,17,31,.42); color: white; font-size: 11px; font-weight: 900; backdrop-filter: blur(8px); }

.scan-guide { position: fixed; z-index: 2; inset: 20% 8% auto; text-align: center; pointer-events: none; }
.scan-guide p { display: inline-block; padding: 9px 14px; border-radius: 999px; background: rgba(7,17,31,.78); font-size: 13px; font-weight: 800; }
.progress { width: min(320px, 75vw); height: 4px; margin: 8px auto; overflow: hidden; border-radius: 4px; background: rgba(255,255,255,.2); }
.progress span { display: block; width: 0; height: 100%; background: var(--cyan); transition: width .2s; }

.controls {
  position: fixed;
  z-index: 5;
  left: 14px;
  right: 14px;
  bottom: max(14px, env(safe-area-inset-bottom));
  display: flex;
  align-items: end;
  gap: 8px;
  padding: 10px;
  overflow-x: auto;
  border: 1px solid var(--line);
  border-radius: 16px;
  background: rgba(7,17,31,.84);
  backdrop-filter: blur(14px);
}
.controls label { display: grid; min-width: 150px; gap: 4px; }
.controls label span { padding-left: 3px; color: var(--muted); font-size: 10px; font-weight: 800; letter-spacing: .08em; text-transform: uppercase; }
.controls select { width: 100%; }

.debug-hud {
  position: fixed;
  z-index: 5;
  top: 88px;
  left: 14px;
  width: min(330px, calc(100vw - 28px));
  padding: 14px;
  border: 1px solid rgba(112,225,245,.35);
  border-radius: 14px;
  background: rgba(2, 10, 18, .86);
  font: 11px/1.35 ui-monospace, SFMono-Regular, Menlo, monospace;
  backdrop-filter: blur(12px);
}
.hud-title { margin-bottom: 9px; color: var(--cyan); font-weight: 900; letter-spacing: .1em; }
.debug-hud dl { display: grid; gap: 3px; margin: 0; }
.debug-hud dl div { display: grid; grid-template-columns: 118px 1fr; }
.debug-hud dt { color: #75879c; }
.debug-hud dd { margin: 0; overflow: hidden; color: #dbe7f2; text-overflow: ellipsis; white-space: nowrap; }

.log-panel {
  position: fixed;
  z-index: 8;
  inset: 9% 5% max(86px, 12%);
  max-width: 720px;
  margin: auto;
  padding: 18px;
  border: 1px solid var(--line);
  border-radius: 18px;
  background: rgba(3,10,18,.96);
  box-shadow: 0 30px 100px rgba(0,0,0,.55);
}
.panel-heading, .log-actions { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.panel-heading h2 { margin: 0; font-size: 18px; }
.panel-heading button { border: 0; background: none; font-size: 28px; }
.log-panel pre { height: calc(100% - 96px); overflow: auto; white-space: pre-wrap; color: #b9c8d8; font-size: 11px; }
.log-actions { justify-content: flex-start; }

#toast { position: fixed; z-index: 10; left: 50%; bottom: 100px; transform: translateX(-50%); padding: 10px 14px; border-radius: 10px; background: rgba(0,0,0,.82); opacity: 0; transition: opacity .2s; pointer-events: none; }
#toast.visible { opacity: 1; }

[hidden] { display: none !important; }

@media (max-width: 620px) {
  .controls { gap: 6px; }
  .controls label { min-width: 128px; }
  .controls .secondary { padding-inline: 10px; }
  .debug-hud { top: 78px; }
}

@media (orientation: portrait) {
  .orientation-warning {
    position: fixed;
    z-index: 100;
    inset: 0;
    display: grid;
    place-items: center;
    padding: 28px;
    background: #07111f;
    text-align: center;
  }
  .orientation-warning div { display: grid; gap: 12px; }
  .orientation-warning strong { color: var(--cyan); font-size: 22px; }
  .orientation-warning span { color: var(--muted); font-size: 13px; line-height: 1.6; }
}

@media (prefers-reduced-motion: reduce) {
  * { scroll-behavior: auto !important; transition: none !important; }
}
