
:root {
  color-scheme: dark;
  --bg: #0a0d12;
  --panel: rgba(17, 22, 31, .78);
  --panel-solid: #151a24;
  --text: #f6f8fb;
  --muted: #a9b1bf;
  --accent: #6fa8ff;
  --good: #63d99a;
  --warn: #ffc56f;
  --danger: #ff7f87;
  --border: rgba(255,255,255,.11);
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

* { box-sizing: border-box; }
html, body {
  width: 100%; height: 100%; margin: 0; overflow: hidden;
  background: var(--bg); color: var(--text);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  -webkit-tap-highlight-color: transparent;
  touch-action: none;
}
button, input { font: inherit; }
#viewer { position: fixed; inset: 0; }
#viewer canvas { display: block; width: 100%; height: 100%; touch-action: none; }

.glass {
  background: var(--panel);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  border: 1px solid var(--border);
}

.topbar {
  position: fixed; z-index: 20; top: 0; left: 0; right: 0;
  display: flex; align-items: flex-start; justify-content: space-between; gap: 8px;
  padding: calc(9px + var(--safe-top)) 9px 8px;
  background: linear-gradient(to bottom, rgba(4,6,10,.84), rgba(4,6,10,.24), transparent);
  pointer-events: none;
}
.brand {
  border-radius: 14px; padding: 8px 10px; min-width: 150px; max-width: 40vw;
  pointer-events: auto;
}
.brand-title { font-weight: 780; font-size: 14px; letter-spacing: .01em; }
.brand-sub {
  margin-top: 3px; color: var(--muted); font-size: 10px;
  display: flex; align-items: center; gap: 6px;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.status-dot { width: 7px; height: 7px; border-radius: 50%; background: var(--warn); flex: 0 0 auto; }

.toolbar { display: flex; gap: 5px; flex-wrap: wrap; justify-content: flex-end; pointer-events: auto; max-width: 470px; }
.tool-btn {
  min-width: 40px; height: 40px; border: 1px solid var(--border); border-radius: 12px;
  padding: 0 9px; color: var(--text); background: var(--panel); backdrop-filter: blur(14px);
  cursor: pointer; font-weight: 760; font-size: 17px;
}
.tool-btn:active { transform: scale(.96); }
.tool-btn.active { border-color: rgba(111,168,255,.8); background: rgba(61,113,190,.50); }
.label-btn { min-width: 47px; font-size: 11px; }
.quality-btn { min-width: 62px; font-size: 10px; letter-spacing: .04em; }
.quality-btn.ultra { border-color: rgba(111,168,255,.82); background: rgba(48,101,180,.56); }

.stats {
  position: fixed; z-index: 16; left: 9px; bottom: calc(42px + var(--safe-bottom));
  min-width: 195px; padding: 9px 10px; border-radius: 12px; pointer-events: none;
  font-size: 10px;
}
.stats div { display: flex; justify-content: space-between; gap: 18px; padding: 2px 0; }
.stats span { color: var(--muted); }
.stats b { font-weight: 650; color: var(--text); text-align: right; }

.loading {
  position: fixed; z-index: 30; left: 50%; top: 50%; transform: translate(-50%,-50%);
  width: min(82vw, 360px); border-radius: 18px; padding: 21px; text-align: center;
}
.spinner {
  width: 38px; height: 38px; margin: 0 auto 12px; border-radius: 50%;
  border: 4px solid rgba(255,255,255,.13); border-top-color: var(--accent);
  animation: spin .8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
.loading-title { font-size: 13px; color: var(--text); }
.progress-track {
  height: 5px; margin-top: 13px; border-radius: 999px; overflow: hidden;
  background: rgba(255,255,255,.10);
}
.progress-bar { width: 0; height: 100%; background: var(--accent); transition: width .15s ease; }

.perf-hint {
  position: fixed; z-index: 25; left: 50%; bottom: calc(12px + var(--safe-bottom));
  transform: translateX(-50%);
  width: min(88vw, 420px); padding: 10px 38px 10px 12px; border-radius: 13px;
  font-size: 10px; line-height: 1.35;
}
.perf-hint b { display: block; margin-bottom: 2px; }
.perf-hint span { color: var(--muted); }
.perf-hint button {
  position: absolute; right: 8px; top: 7px; width: 27px; height: 27px;
  border-radius: 9px; border: 1px solid var(--border); color: var(--text);
  background: rgba(255,255,255,.06);
}

.error-box {
  position: fixed; z-index: 40; left: 50%; top: 50%; transform: translate(-50%,-50%);
  width: min(90vw, 410px); padding: 20px; border-radius: 18px;
  background: var(--panel-solid); border: 1px solid rgba(255,127,135,.42);
}
.error-title { color: #ffadb2; font-weight: 800; font-size: 16px; margin-bottom: 8px; }
.error-text { color: var(--muted); white-space: pre-wrap; overflow-wrap: anywhere; font-size: 11px; line-height: 1.5; margin-bottom: 14px; }

.modal-backdrop {
  position: fixed; z-index: 50; inset: 0; display: grid; place-items: center; padding: 15px;
  background: rgba(0,0,0,.62); backdrop-filter: blur(9px);
}
.modal {
  width: min(94vw, 500px); max-height: 91vh; overflow: auto; padding: 20px;
  border-radius: 20px; background: #151a24; border: 1px solid var(--border);
}
.modal h2 { margin: 0 0 7px; font-size: 20px; }
.modal p { margin: 0 0 16px; color: var(--muted); font-size: 12px; line-height: 1.5; }

.mode-table {
  display: grid; gap: 6px; margin: 12px 0 15px;
}
.mode-table div {
  display: grid; grid-template-columns: 60px 1fr; align-items: center;
  gap: 8px; padding: 9px 10px; border-radius: 11px;
  border: 1px solid var(--border); background: rgba(255,255,255,.025);
  font-size: 10px;
}
.mode-table span { color: var(--muted); }

.settings-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin-top: 15px; }
.check-row {
  display: flex; align-items: center; gap: 7px; padding: 9px; border: 1px solid var(--border);
  border-radius: 11px; background: rgba(255,255,255,.025); font-size: 11px;
}
.modal-actions, .row { display: flex; justify-content: flex-end; gap: 8px; margin-top: 18px; }
.primary-btn, .secondary-btn {
  min-height: 42px; padding: 0 14px; border-radius: 12px; cursor: pointer; font-weight: 750;
  border: 1px solid var(--border);
}
.primary-btn { color: white; background: #347eea; border-color: #5897f2; }
.secondary-btn { color: var(--text); background: #242b37; }

.source-info {
  margin-top: 13px; padding: 10px 11px; border: 1px solid var(--border);
  border-radius: 12px; background: rgba(255,255,255,.025);
  color: var(--muted); font-size: 10px; line-height: 1.5; overflow-wrap: anywhere;
}
.source-info b { color: var(--text); font-weight: 650; }

.gesture-hint {
  position: fixed; z-index: 12; left: 50%; bottom: calc(7px + var(--safe-bottom)); transform: translateX(-50%);
  white-space: nowrap; padding: 5px 9px; border-radius: 999px; background: rgba(0,0,0,.37);
  color: rgba(255,255,255,.72); font-size: 9px; pointer-events: none; transition: opacity .5s ease;
}

.walk-hud { position: fixed; z-index: 35; inset: 0; pointer-events: none; }
.joystick-base {
  position: absolute; left: 24px; bottom: calc(28px + var(--safe-bottom)); width: 120px; height: 120px;
  border-radius: 50%; background: rgba(15,18,25,.48); border: 1px solid rgba(255,255,255,.16);
  pointer-events: auto; touch-action: none;
}
.joystick-knob {
  position: absolute; left: 35px; top: 35px; width: 50px; height: 50px; border-radius: 50%;
  background: rgba(111,168,255,.62); border: 1px solid rgba(255,255,255,.28);
  transform: translate(0,0);
}
.walk-help {
  position: absolute; left: 50%; bottom: calc(12px + var(--safe-bottom)); transform: translateX(-50%);
  padding: 6px 9px; border-radius: 10px; color: var(--muted); font-size: 9px;
}
.exit-walk {
  position: absolute; right: 16px; bottom: calc(18px + var(--safe-bottom));
  min-height: 40px; padding: 0 13px; border-radius: 12px; color: var(--text); pointer-events: auto;
}

.hidden { display: none !important; }

@media (max-width: 700px) {
  .brand { max-width: 35vw; }
  .toolbar { max-width: 260px; }
  .tool-btn { min-width: 37px; height: 37px; border-radius: 11px; padding: 0 7px; }
  .label-btn { min-width: 42px; font-size: 10px; }
  .quality-btn { min-width: 56px; }
  .settings-grid { grid-template-columns: 1fr; }
  .walk-help { display: none; }
}
