:root {
  --bg: #000;
  --panel: #14110d;
  --panel-deep: #0c0b09;
  --gold: #c9a86a;
  --gold-bright: #e8d1a6;
  --ivory: #f3ede2;
  --muted: #9b9387;
  --line: rgba(201, 168, 106, 0.18);
  --line-strong: rgba(201, 168, 106, 0.45);
  --ok: #8fb583;
  --err: #c96a5a;
  --serif: "Iowan Old Style", "Palatino Linotype", Palatino,
    "Book Antiqua", Georgia, serif;
  --sans: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  overflow: hidden;
  background: var(--bg);
  color: var(--ivory);
  font-family: var(--sans);
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
}

button {
  appearance: none;
  -webkit-appearance: none;
  margin: 0;
  font: inherit;
  color: inherit;
  background: none;
  border: 0;
  cursor: pointer;
}

.sprite {
  position: absolute;
  width: 0;
  height: 0;
  overflow: hidden;
}

.icon {
  display: block;
  width: 20px;
  height: 20px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.6;
  stroke-linecap: round;
  stroke-linejoin: round;
  flex: none;
}

#video {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  z-index: 1;
}

#overlay {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  z-index: 2;
  pointer-events: none;
}

#touchLayer {
  position: fixed;
  inset: 0;
  z-index: 5;
  touch-action: none;
}

#status {
  position: fixed;
  top: max(16px, env(safe-area-inset-top));
  left: 14px;
  z-index: 11;
  display: flex;
  align-items: center;
  gap: 8px;
  max-width: calc(100vw - 92px);
  padding: 8px 13px;
  background: rgba(12, 11, 9, 0.74);
  border: 1px solid var(--line);
  border-radius: 999px;
  color: var(--ivory);
  font-size: 11px;
  letter-spacing: 0.04em;
  backdrop-filter: blur(12px);
  box-shadow: 0 6px 22px rgba(0, 0, 0, 0.35);
  transition: opacity 0.4s ease, transform 0.4s ease;
}

#status.hidden {
  opacity: 0;
  transform: translateY(-6px);
  pointer-events: none;
}

#statusText {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.status-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  flex: none;
  background: var(--gold);
  box-shadow: 0 0 9px rgba(201, 168, 106, 0.8);
}

#status[data-state="ok"] .status-dot {
  background: var(--ok);
  box-shadow: 0 0 9px rgba(143, 181, 131, 0.85);
}

#status[data-state="error"] .status-dot {
  background: var(--err);
  box-shadow: 0 0 9px rgba(201, 106, 90, 0.85);
}

#status[data-state="idle"] .status-dot {
  background: var(--muted);
  box-shadow: none;
}

#toggleBtn {
  position: fixed;
  top: max(14px, env(safe-area-inset-top));
  right: 14px;
  z-index: 12;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 46px;
  height: 46px;
  border-radius: 50%;
  color: var(--gold);
  background: linear-gradient(
    180deg,
    rgba(32, 28, 22, 0.92),
    rgba(12, 11, 9, 0.94)
  );
  border: 1px solid var(--line-strong);
  backdrop-filter: blur(12px);
  box-shadow: 0 10px 26px rgba(0, 0, 0, 0.45),
    inset 0 1px 0 rgba(255, 255, 255, 0.06);
  transition: color 0.18s ease, border-color 0.18s ease,
    transform 0.18s ease;
}

#toggleBtn:hover {
  color: var(--gold-bright);
  border-color: var(--gold);
}

#toggleBtn:active { transform: scale(0.95); }

#toggleBtn[aria-expanded="false"] {
  color: var(--muted);
  border-color: var(--line);
}

#controls {
  position: fixed;
  left: 50%;
  bottom: 0;
  z-index: 10;
  width: min(560px, 100%);
  max-height: calc(100vh - 84px);
  overflow-y: auto;
  overscroll-behavior: contain;
  padding: 10px 18px calc(16px + env(safe-area-inset-bottom));
  background:
    radial-gradient(
      120% 80% at 50% 0%,
      rgba(201, 168, 106, 0.07),
      transparent 60%
    ),
    linear-gradient(180deg, rgba(26, 23, 18, 0.97), rgba(10, 9, 8, 0.99));
  border: 1px solid var(--line);
  border-bottom: none;
  border-radius: 22px 22px 0 0;
  backdrop-filter: blur(20px);
  box-shadow: 0 -24px 70px rgba(0, 0, 0, 0.6),
    inset 0 1px 0 rgba(255, 255, 255, 0.05);
  transform: translateX(-50%);
  transition: transform 0.3s cubic-bezier(0.22, 0.61, 0.36, 1),
    opacity 0.3s ease;
}

#controls.hidden {
  transform: translate(-50%, calc(100% + 28px));
  opacity: 0;
  pointer-events: none;
}

#controls::-webkit-scrollbar { width: 0; }

.panel-grip {
  width: 44px;
  height: 3px;
  margin: 2px auto 12px;
  border-radius: 999px;
  background: linear-gradient(
    90deg,
    transparent,
    rgba(201, 168, 106, 0.45),
    transparent
  );
}

.panel-head {
  display: flex;
  align-items: center;
  gap: 14px;
  margin-bottom: 16px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  flex: none;
}

.brand-mark {
  width: 28px;
  height: 28px;
  color: var(--gold);
  stroke-width: 1.3;
}

.brand-text {
  display: flex;
  flex-direction: column;
  gap: 3px;
}

.brand-name {
  font-family: var(--serif);
  font-size: 20px;
  line-height: 1;
  letter-spacing: 0.02em;
  color: var(--ivory);
}

.brand-tag {
  font-size: 8.5px;
  line-height: 1;
  letter-spacing: 0.26em;
  text-transform: uppercase;
  color: var(--muted);
}

.head-rule {
  flex: 1;
  height: 1px;
  background: linear-gradient(90deg, var(--line), transparent);
}

.tool-section + .tool-section { margin-top: 15px; }

.section-label {
  margin: 0 0 8px;
  font-family: var(--serif);
  font-size: 11px;
  font-weight: 400;
  font-variant: small-caps;
  letter-spacing: 0.16em;
  color: var(--gold);
  opacity: 0.8;
}

.tool-grid {
  display: grid;
  gap: 8px;
}

.cols-3 { grid-template-columns: repeat(3, 1fr); }
.cols-4 { grid-template-columns: repeat(4, 1fr); }

.tool {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 7px;
  min-height: 58px;
  padding: 9px 5px 8px;
  border: 1px solid var(--line);
  border-radius: 12px;
  color: var(--ivory);
  background: linear-gradient(
    180deg,
    rgba(255, 255, 255, 0.035),
    rgba(255, 255, 255, 0.008)
  );
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.03);
  transition: border-color 0.18s ease, background 0.18s ease,
    color 0.18s ease, transform 0.08s ease;
}

.tool .icon {
  width: 20px;
  height: 20px;
  color: var(--gold);
  transition: color 0.18s ease;
}

.tool span {
  font-size: 9.5px;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: inherit;
  opacity: 0.82;
}

.tool:hover {
  border-color: var(--line-strong);
  background: rgba(201, 168, 106, 0.06);
}

.tool:active { transform: translateY(1px); }

.tool.active {
  border-color: rgba(201, 168, 106, 0.7);
  color: var(--gold-bright);
  background:
    radial-gradient(
      130% 120% at 50% 0%,
      rgba(201, 168, 106, 0.24),
      rgba(201, 168, 106, 0.05)
    );
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.09),
    0 0 0 1px rgba(201, 168, 106, 0.1);
}

.tool.active .icon { color: var(--gold-bright); }

#btnLock .icon-lock { display: none; }
#btnLock.active .icon-lock { display: block; }
#btnLock.active .icon-unlock { display: none; }

.slider-section {
  display: grid;
  gap: 9px;
  margin-top: 16px;
  padding-top: 14px;
  border-top: 1px solid var(--line);
}

.slider-row {
  display: grid;
  grid-template-columns: 72px minmax(0, 1fr) 44px;
  align-items: center;
  gap: 12px;
}

.slider-row label {
  font-family: var(--serif);
  font-size: 12px;
  font-variant: small-caps;
  letter-spacing: 0.08em;
  color: var(--muted);
}

.slider-row output {
  font-size: 11px;
  font-variant-numeric: tabular-nums;
  letter-spacing: 0.04em;
  text-align: right;
  color: var(--gold);
}

input[type="range"] {
  appearance: none;
  -webkit-appearance: none;
  width: 100%;
  height: 22px;
  margin: 0;
  background: transparent;
  cursor: pointer;
}

input[type="range"]:focus-visible { outline: none; }

input[type="range"]::-webkit-slider-runnable-track {
  height: 2px;
  border-radius: 2px;
  background: linear-gradient(
    90deg,
    rgba(201, 168, 106, 0.55),
    rgba(255, 255, 255, 0.12)
  );
}

input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 14px;
  height: 14px;
  margin-top: -6px;
  border-radius: 50%;
  border: 1px solid #0a0908;
  background: radial-gradient(circle at 35% 30%, #f2debb, var(--gold) 72%);
  box-shadow: 0 0 0 3px rgba(201, 168, 106, 0.13),
    0 2px 6px rgba(0, 0, 0, 0.55);
}

input[type="range"]:focus-visible::-webkit-slider-thumb {
  box-shadow: 0 0 0 5px rgba(201, 168, 106, 0.24);
}

input[type="range"]::-moz-range-track {
  height: 2px;
  border-radius: 2px;
  background: rgba(201, 168, 106, 0.35);
}

input[type="range"]::-moz-range-thumb {
  width: 13px;
  height: 13px;
  border-radius: 50%;
  border: 1px solid #0a0908;
  background: radial-gradient(circle at 35% 30%, #f2debb, var(--gold) 72%);
  box-shadow: 0 0 0 3px rgba(201, 168, 106, 0.13);
}

#cameraGate {
  position: fixed;
  inset: 0;
  z-index: 30;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  background:
    radial-gradient(
      90% 60% at 50% 20%,
      rgba(201, 168, 106, 0.08),
      transparent 65%
    ),
    rgba(0, 0, 0, 0.9);
  backdrop-filter: blur(10px);
}

#cameraGate[hidden] { display: none; }

.gate-card {
  width: min(430px, 100%);
  max-height: 90vh;
  overflow-y: auto;
  padding: 28px 24px 22px;
  text-align: center;
  border: 1px solid var(--line);
  border-radius: 18px;
  background: linear-gradient(180deg, #1b1712, #0e0d0b);
  box-shadow: 0 30px 80px rgba(0, 0, 0, 0.65),
    inset 0 1px 0 rgba(255, 255, 255, 0.05);
}

.gate-icon {
  width: 44px;
  height: 44px;
  margin: 0 auto 14px;
  color: var(--gold);
  stroke-width: 1.3;
}

.gate-card h1 {
  margin: 0 0 10px;
  font-family: var(--serif);
  font-size: 23px;
  font-weight: 400;
  letter-spacing: 0.01em;
  color: var(--ivory);
}

.gate-card p {
  margin: 0 0 18px;
  font-size: 13px;
  line-height: 1.65;
  color: var(--ivory);
  opacity: 0.8;
}

.gate-card code {
  font-size: 0.92em;
  color: var(--gold-bright);
}

.btn {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  width: 100%;
  margin-top: 8px;
  padding: 12px 14px;
  border-radius: 10px;
  font-size: 12px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  transition: filter 0.18s ease, border-color 0.18s ease,
    color 0.18s ease;
}

.btn[hidden] { display: none; }

.btn.primary {
  color: #17130d;
  font-weight: 700;
  background: linear-gradient(180deg, #e0c28c, #b9955b);
  border: 1px solid #e8d1a6;
  box-shadow: 0 8px 20px rgba(0, 0, 0, 0.35),
    inset 0 1px 0 rgba(255, 255, 255, 0.4);
}

.btn.primary:hover { filter: brightness(1.05); }
.btn.primary:disabled {
  cursor: wait;
  filter: grayscale(0.35) brightness(0.85);
}

.btn.ghost {
  color: var(--muted);
  border: 1px solid var(--line);
  background: transparent;
}

.btn.ghost:hover {
  color: var(--ivory);
  border-color: var(--line-strong);
}

#gateDiag {
  margin: 16px 0 0;
  font-size: 10px;
  letter-spacing: 0.03em;
  word-break: break-word;
  color: var(--muted);
  opacity: 0.6;
}

@media (max-width: 380px) {
  #controls { padding-inline: 14px; }
  .tool span { font-size: 9px; letter-spacing: 0.06em; }
  .slider-row { grid-template-columns: 64px minmax(0, 1fr) 40px; gap: 9px; }
}
