:root {
  --bg: #08090b;
  --panel: #0d0e11;
  --panel-2: #141519;
  --line: rgba(255, 255, 255, 0.075);
  --line-2: rgba(255, 255, 255, 0.14);
  --ink: #eceef1;
  --dim: #8a8d95;
  --faint: #5b5e66;
  --ok: #7ee2a8;
  --warn: #e6c07b;
  --bad: #e58a8a;
  --u: 44px;
  --ease: cubic-bezier(0.22, 0.9, 0.24, 1);
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--ink);
  font: 400 14px/1.4 system-ui, -apple-system, "Segoe UI Variable", "Segoe UI", Roboto, sans-serif;
  overscroll-behavior: none;
  -webkit-user-select: none;
  user-select: none;
  touch-action: manipulation;
}

body {
  display: flex;
  flex-direction: column;
  height: 100dvh;
  min-height: 100dvh;
  overflow: hidden;
}

button {
  font: inherit;
  color: inherit;
  background: none;
  border: 0;
  padding: 0;
  cursor: pointer;
}

.micro {
  font-size: 10px;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--faint);
}

/* ------------------------------------------------------------------ stage */

#stage {
  position: relative;
  flex: 1 1 auto;
  min-height: 0;
  overflow: hidden;
  background: #000;
  touch-action: none;
  cursor: crosshair;
}

#viewport {
  position: absolute;
  left: 0;
  top: 0;
  transform-origin: 0 0;
  will-change: transform;
}

#screen {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: fill;
  background: #000;
  pointer-events: none;
}

#fx {
  position: absolute;
  inset: 0;
  pointer-events: none;
  overflow: hidden;
}

.ripple {
  position: absolute;
  width: 34px;
  height: 34px;
  margin: -17px 0 0 -17px;
  border-radius: 50%;
  border: 1.5px solid rgba(255, 255, 255, 0.85);
  animation: ripple 420ms var(--ease) forwards;
}

.ripple.right { border-color: rgba(230, 192, 123, 0.95); }
.ripple.middle { border-color: rgba(160, 190, 255, 0.95); }

@keyframes ripple {
  from { transform: scale(0.35); opacity: 0.9; }
  to { transform: scale(1.35); opacity: 0; }
}

.cursor-dot {
  position: absolute;
  width: 10px;
  height: 10px;
  margin: -5px 0 0 -5px;
  border-radius: 50%;
  background: #fff;
  box-shadow: 0 0 0 1.5px rgba(0, 0, 0, 0.55), 0 0 14px rgba(255, 255, 255, 0.5);
  pointer-events: none;
  transition: opacity 160ms linear;
  z-index: 5;
}

#hint {
  position: absolute;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  padding: 10px 16px;
  border-radius: 999px;
  background: rgba(10, 11, 13, 0.82);
  border: 1px solid var(--line);
  backdrop-filter: blur(18px);
  font-size: 12.5px;
  color: var(--dim);
  white-space: nowrap;
}

/* ----------------------------------------------------------------- chrome */

#chrome {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 20;
  transition: opacity 240ms var(--ease);
}

#chrome > * { pointer-events: auto; }

body.idle #chrome { opacity: 0; }
body.idle #chrome > * { pointer-events: none; }

#top {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: calc(env(safe-area-inset-top, 0px) + 10px) calc(env(safe-area-inset-right, 0px) + 12px) 10px
    calc(env(safe-area-inset-left, 0px) + 12px);
}

.pill {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  height: 34px;
  padding: 0 14px;
  border-radius: 999px;
  background: rgba(13, 14, 17, 0.72);
  border: 1px solid var(--line);
  backdrop-filter: blur(20px) saturate(120%);
  font-size: 12.5px;
  letter-spacing: 0.01em;
  color: var(--ink);
}

.pill #statusMeta { color: var(--faint); font-variant-numeric: tabular-nums; }

.dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--faint);
  box-shadow: 0 0 0 3px rgba(255, 255, 255, 0.045);
}

.dot.lan { background: var(--ok); }
.dot.wan { background: var(--warn); }
.dot.bad { background: var(--bad); }

.icon {
  display: grid;
  place-items: center;
  width: 40px;
  height: 40px;
  border-radius: 14px;
  background: rgba(13, 14, 17, 0.72);
  border: 1px solid var(--line);
  backdrop-filter: blur(20px) saturate(120%);
  color: var(--ink);
  transition: transform 140ms var(--ease), background 140ms;
}

.icon:active { transform: scale(0.94); background: rgba(30, 32, 38, 0.9); }

.icon svg { fill: none; stroke: currentColor; stroke-width: 1.5; stroke-linecap: round; stroke-linejoin: round; }
#more svg { fill: currentColor; stroke: none; }

#dock {
  position: absolute;
  left: 50%;
  bottom: calc(env(safe-area-inset-bottom, 0px) + 16px);
  transform: translateX(-50%);
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px;
  border-radius: 999px;
  background: rgba(11, 12, 15, 0.66);
  border: 1px solid var(--line);
  backdrop-filter: blur(24px) saturate(130%);
}

.seg {
  display: flex;
  padding: 3px;
  gap: 2px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.045);
}

.seg button {
  width: 38px;
  height: 32px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.04em;
  color: var(--dim);
  transition: color 140ms, background 180ms var(--ease);
}

.seg button.on {
  background: var(--ink);
  color: #08090b;
}

#dock .icon {
  width: 44px;
  height: 34px;
  border-radius: 999px;
  background: transparent;
  border: 0;
  backdrop-filter: none;
}

#dock .icon.on {
  background: var(--ink);
  color: #08090b;
}

/* --------------------------------------------------------------- keyboard */

#keyboard {
  flex: 0 0 auto;
  background: var(--panel);
  border-top: 1px solid var(--line);
  padding-bottom: env(safe-area-inset-bottom, 0px);
  z-index: 30;
  animation: slide-up 240ms var(--ease);
  max-height: 62dvh;
  display: flex;
  flex-direction: column;
}

@keyframes slide-up {
  from { transform: translateY(14px); opacity: 0; }
  to { transform: translateY(0); opacity: 1; }
}

.kb-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 12px 4px;
  flex: 0 0 auto;
}

.kb-tools { display: flex; align-items: center; gap: 4px; }

.kb-tools button {
  height: 26px;
  padding: 0 10px;
  border-radius: 8px;
  border: 1px solid var(--line);
  color: var(--dim);
  font-size: 11px;
  letter-spacing: 0.02em;
}

.kb-tools button.on { background: var(--ink); color: #08090b; border-color: transparent; }

.kb-scale {
  position: relative;
  overflow: hidden;
  padding: 4px 8px 10px;
  flex: 1 1 auto;
  min-height: 0;
}

.kb-keys {
  display: flex;
  flex-direction: column;
  gap: 4px;
  transform-origin: top left;
}

.kb-row { display: flex; gap: 4px; }

.key {
  height: calc(var(--u) * 0.92);
  flex: 0 0 auto;
  display: grid;
  place-items: center;
  border-radius: 7px;
  border: 1px solid var(--line);
  background: var(--panel-2);
  color: var(--ink);
  font-size: calc(var(--u) * 0.27);
  font-weight: 500;
  line-height: 1;
  transition: background 90ms, transform 90ms;
  position: relative;
}

.key.mod { background: #1b1d22; color: var(--dim); font-size: calc(var(--u) * 0.22); }
.key.mod.sticky { background: var(--ink); color: #08090b; border-color: transparent; }
.key.mod.locked::after {
  content: "";
  position: absolute;
  right: 4px;
  top: 4px;
  width: 4px;
  height: 4px;
  border-radius: 50%;
  background: #08090b;
}
.key.down { transform: translateY(1px) scale(0.985); background: #2a2d34; }
.key.mod.down { background: #33363e; }

.key.gap { visibility: hidden; pointer-events: none; }

/* ------------------------------------------------------------------ sheet */

.sheet {
  position: fixed;
  inset: 0;
  z-index: 40;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  background: rgba(0, 0, 0, 0.45);
  backdrop-filter: blur(3px);
  animation: fade 160ms linear;
}

@keyframes fade { from { opacity: 0; } to { opacity: 1; } }

.sheet-grip {
  position: absolute;
  top: 8px;
  left: 50%;
  transform: translateX(-50%);
  width: 36px;
  height: 4px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.16);
}

.sheet-body {
  width: min(520px, 100%);
  max-height: 78dvh;
  overflow: auto;
  background: var(--panel);
  border-top-left-radius: 20px;
  border-top-right-radius: 20px;
  border-top: 1px solid var(--line);
  padding: 26px 18px calc(env(safe-area-inset-bottom, 0px) + 18px);
  animation: sheet-up 240ms var(--ease);
}

@keyframes sheet-up { from { transform: translateY(24px); } to { transform: translateY(0); } }

.row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  padding: 12px 2px;
  border-bottom: 1px solid var(--line);
}

.row:last-child { border-bottom: 0; }
.row .label { font-size: 13.5px; }
.row .label small { display: block; color: var(--faint); font-size: 11.5px; margin-top: 2px; }

.stat-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
  margin: 2px 0 14px;
}

.stat {
  padding: 12px 14px;
  border-radius: 14px;
  background: #101116;
  border: 1px solid var(--line);
}

.stat b { display: block; font-size: 19px; font-weight: 600; font-variant-numeric: tabular-nums; letter-spacing: -0.01em; }
.stat span { font-size: 10px; letter-spacing: 0.13em; text-transform: uppercase; color: var(--faint); }

.switch {
  position: relative;
  width: 46px;
  height: 28px;
  border-radius: 999px;
  background: #23252b;
  border: 1px solid var(--line);
  flex: 0 0 auto;
  transition: background 180ms var(--ease);
}

.switch::after {
  content: "";
  position: absolute;
  top: 3px;
  left: 3px;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  background: #cfd2d8;
  transition: transform 200ms var(--ease), background 180ms;
}

.switch.on { background: var(--ink); }
.switch.on::after { transform: translateX(18px); background: #08090b; }

.choice { display: flex; gap: 4px; padding: 3px; border-radius: 10px; background: rgba(255, 255, 255, 0.05); }
.choice button { padding: 6px 12px; border-radius: 8px; font-size: 12px; color: var(--dim); }
.choice button.on { background: var(--ink); color: #08090b; }

.btn {
  height: 38px;
  padding: 0 16px;
  border-radius: 10px;
  border: 1px solid var(--line-2);
  font-size: 12.5px;
  color: var(--ink);
}

.btn.primary { background: var(--ink); color: #08090b; border-color: transparent; font-weight: 600; }
.btn.danger { color: var(--bad); border-color: rgba(229, 138, 138, 0.3); }

/* ------------------------------------------------------------------- gate */

[hidden] { display: none !important; }

.gate {
  position: fixed;
  inset: 0;
  z-index: 60;
  display: grid;
  place-items: center;
  padding: 20px;
  background: var(--bg);
}

.gate-card { width: min(360px, 100%); text-align: center; }

.brand {
  font-size: 10px;
  letter-spacing: 0.34em;
  color: var(--faint);
  margin-bottom: 26px;
}

.gate h1 { font-size: 20px; font-weight: 550; margin: 0 0 6px; letter-spacing: -0.01em; }
.gate .sub { margin: 0 0 24px; color: var(--dim); font-size: 13px; }
.gate .err { min-height: 18px; margin: 14px 0 0; color: var(--bad); font-size: 12.5px; }

.pins { display: flex; justify-content: center; gap: 10px; margin-bottom: 26px; }

.pins i {
  width: 11px;
  height: 11px;
  border-radius: 50%;
  border: 1px solid rgba(255, 255, 255, 0.24);
  transition: background 120ms, border-color 120ms, transform 120ms var(--ease);
}

.pins i.on { background: var(--ink); border-color: transparent; transform: scale(1.08); }
.pins.shake { animation: shake 320ms var(--ease); }

@keyframes shake {
  0%, 100% { transform: translateX(0); }
  25% { transform: translateX(-7px); }
  75% { transform: translateX(7px); }
}

.pad { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }

.pad button {
  height: 54px;
  border-radius: 14px;
  border: 1px solid var(--line);
  background: #0f1014;
  font-size: 18px;
  font-variant-numeric: tabular-nums;
  transition: background 120ms, transform 100ms;
}

.pad button:active { background: #1b1d22; transform: scale(0.97); }
.pad button.blank { visibility: hidden; }
.pad button.del { border-color: transparent; background: transparent; color: var(--dim); }
.pad button.go { background: var(--ink); color: #08090b; font-weight: 600; }

/* ------------------------------------------------------------------ toast */

#toast {
  position: fixed;
  left: 50%;
  bottom: calc(env(safe-area-inset-bottom, 0px) + 84px);
  transform: translate(-50%, 8px);
  z-index: 70;
  padding: 9px 15px;
  border-radius: 999px;
  background: rgba(18, 19, 23, 0.92);
  border: 1px solid var(--line);
  color: var(--ink);
  font-size: 12.5px;
  opacity: 0;
  pointer-events: none;
  transition: opacity 180ms, transform 220ms var(--ease);
  max-width: 82vw;
  text-align: center;
}

#toast.show { opacity: 1; transform: translate(-50%, 0); }

/* ------------------------------------------------------------- responsive */

@media (max-width: 420px) {
  #dock { gap: 4px; padding: 5px; }
  .seg button { width: 34px; }
}

@media (pointer: fine) {
  #stage { cursor: none; }
  #dock { opacity: 0.9; }
}

@media (prefers-reduced-motion: reduce) {
  * { animation-duration: 0.01ms !important; transition-duration: 0.01ms !important; }
}
