:root {
  --bg: #050b14;
  --panel: #0a1624;
  --panel-2: #0d1d2d;
  --line: rgba(41, 157, 255, 0.24);
  --line-strong: rgba(69, 177, 255, 0.52);
  --blue: #1f9bff;
  --blue-deep: #0068b5;
  --cyan: #5ed7ff;
  --violet: #8aa8ff;
  --text: #edf8ff;
  --soft: #c6dfef;
  --muted: #7894a8;
  --amber: #e8bd62;
  --red: #ff7388;
  --mono: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", monospace;
  --shadow: 0 22px 65px rgba(0, 0, 0, 0.48);
  color-scheme: dark;
}

* {
  box-sizing: border-box;
  min-width: 0;
}

html,
body {
  width: 100%;
  min-height: 100%;
  margin: 0;
  overflow-x: clip;
  background: var(--bg);
  -webkit-text-size-adjust: 100%;
}

body {
  min-height: 100svh;
  color: var(--text);
  font-family: var(--mono);
  background:
    radial-gradient(circle at 12% -8%, rgba(0, 104, 181, 0.30), transparent 25rem),
    radial-gradient(circle at 110% 5%, rgba(31, 155, 255, 0.16), transparent 22rem),
    linear-gradient(180deg, #061423 0, var(--bg) 42%, #02060b 100%);
}

body::before {
  content: "";
  position: fixed;
  inset: 0;
  z-index: 90;
  pointer-events: none;
  opacity: 0.045;
  background: repeating-linear-gradient(
    to bottom,
    rgba(255, 255, 255, 0.05) 0,
    rgba(255, 255, 255, 0.05) 1px,
    transparent 1px,
    transparent 5px
  );
}

button,
input {
  font: inherit;
}

.hidden {
  display: none !important;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

.success,
.ok { color: var(--cyan) !important; }
.info { color: var(--blue) !important; }
.warning,
.warn { color: var(--amber) !important; }
.error,
.bad { color: var(--red) !important; }
.dim,
.muted { color: var(--muted) !important; }

.window-bar {
  height: 40px;
  display: flex;
  align-items: center;
  gap: 7px;
  padding: 0 12px;
  border-bottom: 1px solid var(--line);
  background: linear-gradient(180deg, rgba(18, 43, 67, 0.78), rgba(7, 20, 34, 0.86));
  color: var(--muted);
  font-size: 10px;
}

.dot {
  width: 9px;
  height: 9px;
  flex: 0 0 9px;
  border-radius: 50%;
}

.dot.red { background: #ff5f57; }
.dot.amber { background: #f0b34a; }
.dot.blue { background: #2e9cff; }

.window-title {
  margin-left: 4px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

#boot {
  position: fixed;
  inset: 0;
  z-index: 300;
  display: grid;
  place-items: center;
  padding: 12px;
  background: #02070d;
  transition: opacity 0.3s, visibility 0.3s;
}

#boot.done {
  opacity: 0;
  visibility: hidden;
}

.boot-window {
  width: 100%;
  max-width: 640px;
  min-height: 52svh;
  overflow: hidden;
  border: 1px solid var(--line-strong);
  border-radius: 14px;
  background: #040b13;
  box-shadow: var(--shadow);
}

.boot-body {
  padding: 18px 14px;
  color: #a9d9f5;
  font-size: 11px;
  line-height: 1.65;
  white-space: pre-wrap;
}

.boot-line {
  opacity: 0;
  animation: bootIn 0.16s forwards;
}

@keyframes bootIn {
  to { opacity: 1; }
}

#gate {
  min-height: 100svh;
  display: grid;
  place-items: center;
  padding: max(12px, env(safe-area-inset-top)) 12px max(12px, env(safe-area-inset-bottom));
}

.gate-shell {
  width: 100%;
  max-width: 470px;
  overflow: hidden;
  border: 1px solid var(--line-strong);
  border-radius: 16px;
  background: rgba(5, 14, 24, 0.97);
  box-shadow: var(--shadow), 0 0 55px rgba(31, 155, 255, 0.08);
}

.gate-body {
  padding: 20px 16px;
}

.gate-brand {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 20px;
}

.gate-emblem {
  width: 54px;
  height: 54px;
  flex: 0 0 54px;
  display: grid;
  place-items: center;
  border: 1px solid var(--line-strong);
  border-radius: 14px;
  color: #fff;
  background: linear-gradient(145deg, var(--blue-deep), var(--blue));
  box-shadow: 0 12px 28px rgba(0, 104, 181, 0.25);
  font-weight: 900;
  letter-spacing: 0.04em;
}

.gate-kicker {
  color: var(--cyan);
  font-size: 9px;
  letter-spacing: 0.12em;
  text-transform: uppercase;
}

.gate-host {
  margin-top: 5px;
  color: var(--soft);
  font-size: 12px;
}

.gate-title {
  margin: 0 0 7px;
  font-size: clamp(24px, 8vw, 34px);
  line-height: 1.08;
  letter-spacing: -0.04em;
}

.gate-copy {
  margin: 0 0 20px;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.55;
}

.field {
  margin-top: 14px;
}

.field label {
  display: block;
  margin-bottom: 7px;
  color: #a9cfe6;
  font-size: 10px;
}

.input-shell {
  display: flex;
  align-items: center;
  gap: 9px;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: #030a12;
  padding: 0 11px;
}

.input-shell:focus-within {
  border-color: var(--blue);
  box-shadow: 0 0 0 3px rgba(31, 155, 255, 0.10);
}

.input-prefix {
  flex: 0 0 auto;
  color: var(--blue);
  font-size: 9px;
  text-transform: uppercase;
}

.input-shell input {
  width: 100%;
  min-height: 50px;
  border: 0;
  outline: 0;
  padding: 10px 0;
  color: var(--text);
  background: transparent;
  font-size: 16px;
}

.gate-actions {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 8px;
  margin-top: 18px;
}

.gate-actions.single {
  grid-template-columns: 1fr;
}

.btn {
  min-height: 48px;
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 10px 13px;
  color: var(--text);
  background: rgba(13, 35, 55, 0.9);
  cursor: pointer;
  font-size: 11px;
}

.btn.primary {
  border-color: var(--blue);
  color: #fff;
  background: linear-gradient(145deg, var(--blue-deep), var(--blue));
  font-weight: 900;
}

.btn.ghost {
  color: var(--muted);
  background: transparent;
}

.gate-output {
  min-height: 20px;
  margin-top: 13px;
  font-size: 10px;
  line-height: 1.5;
}

.security-note {
  margin-top: 18px;
  padding-top: 14px;
  border-top: 1px solid var(--line);
  color: var(--muted);
  font-size: 9px;
  line-height: 1.55;
}

.security-note summary {
  cursor: pointer;
  color: #98b8cc;
}

.security-note p {
  margin: 9px 0 0;
}

#app,
.app-shell,
.main-grid,
.terminal-pane {
  width: 100%;
  height: 100svh;
  min-height: 100svh;
  overflow: hidden;
}

.app-shell,
.main-grid {
  display: block;
}

.terminal-pane {
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto;
  border: 0;
  border-radius: 0;
  background:
    radial-gradient(circle at 100% 0, rgba(31, 155, 255, 0.08), transparent 24rem),
    rgba(1, 7, 13, 0.98);
}

.pane-head {
  min-height: 46px;
  display: flex;
  align-items: center;
  gap: 6px;
  padding: max(7px, env(safe-area-inset-top)) 10px 7px;
  overflow: hidden;
  border-bottom: 1px solid var(--line);
  color: var(--muted);
  background: rgba(7, 24, 39, 0.96);
  font-size: 8px;
}

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

.pane-head .right {
  margin-left: auto;
  display: flex;
  gap: 5px;
}

.mini-action {
  min-height: 28px;
  border: 1px solid var(--line);
  border-radius: 7px;
  padding: 4px 7px;
  color: var(--muted);
  background: rgba(3, 14, 25, 0.7);
  cursor: pointer;
  font-size: 7px;
}

#terminalOutput {
  width: 100%;
  min-height: 0;
  overflow-x: hidden;
  overflow-y: auto;
  padding: 15px 12px 24px;
  scroll-behavior: smooth;
  scrollbar-color: rgba(94, 215, 255, 0.34) transparent;
  scrollbar-width: thin;
}

.terminal-line {
  max-width: 100%;
  margin: 0 0 7px;
  color: #c4deef;
  font-size: 11px;
  line-height: 1.55;
  overflow-wrap: anywhere;
  word-break: break-word;
  white-space: pre-wrap;
}

.terminal-line.command {
  color: var(--text);
}

.prompt-user,
.prompt .u { color: var(--blue); }
.prompt-host,
.prompt .h { color: var(--cyan); }
.prompt-path,
.prompt .p { color: var(--violet); }

.terminal-table {
  width: 100%;
  min-width: 0;
  margin: 8px 0 14px;
  border-collapse: collapse;
  table-layout: fixed;
  font-size: 9px;
}

.terminal-table th,
.terminal-table td {
  padding: 6px;
  border: 1px solid var(--line);
  text-align: left;
  vertical-align: top;
  overflow-wrap: anywhere;
  word-break: break-word;
}

.terminal-table th {
  color: var(--cyan);
  background: rgba(31, 155, 255, 0.08);
}

.terminal-input-row {
  min-height: 58px;
  display: flex;
  align-items: center;
  gap: 7px;
  padding: 7px 11px max(8px, env(safe-area-inset-bottom));
  overflow: hidden;
  border-top: 1px solid var(--line);
  background: rgba(2, 12, 23, 0.99);
}

.prompt {
  flex: 0 0 auto;
  color: var(--cyan);
  font-size: 12px;
  white-space: nowrap;
}

.prompt-full {
  display: none;
}

#commandInput {
  width: 100%;
  min-height: 40px;
  border: 0;
  outline: 0;
  padding: 8px 0;
  color: var(--text);
  caret-color: var(--cyan);
  background: transparent;
  font-size: 16px;
}

#commandInput::placeholder {
  color: #506f86;
}

.toast {
  position: fixed;
  left: 50%;
  bottom: max(18px, env(safe-area-inset-bottom));
  z-index: 400;
  width: calc(100% - 24px);
  max-width: 430px;
  padding: 12px 14px;
  border: 1px solid var(--line-strong);
  border-radius: 11px;
  color: var(--text);
  background: rgba(4, 20, 37, 0.97);
  box-shadow: 0 20px 55px rgba(0, 0, 0, 0.46);
  font-size: 11px;
  line-height: 1.45;
  opacity: 0;
  pointer-events: none;
  transform: translate(-50%, 16px);
  transition: opacity 0.2s, transform 0.2s;
}

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

body.matrix-mode::before {
  opacity: 0.12;
}

@media (min-width: 760px) {
  .pane-head {
    padding: 9px 14px;
    font-size: 10px;
  }

  #terminalOutput {
    padding: 20px;
  }

  .terminal-line {
    font-size: 13px;
  }

  .prompt-mobile {
    display: none;
  }

  .prompt-full {
    display: inline;
  }

  .mini-action {
    min-height: 32px;
    font-size: 9px;
  }
}


/* Backend authentication trace: visual progress only; Python decides access. */
.gate-output.gate-trace {
  max-height: 172px;
  overflow-y: auto;
  padding: 10px;
  border: 1px solid rgba(97, 181, 232, 0.18);
  border-radius: 9px;
  background: #02070d;
  font-family: var(--mono);
}

.gate-trace-line {
  display: grid;
  grid-template-columns: 64px minmax(0, 1fr);
  gap: 8px;
  opacity: 0;
  animation: bootIn 0.16s forwards;
}

.gate-trace-marker {
  color: currentColor;
  font-weight: 800;
  white-space: pre;
}

#unlockBtn:disabled,
#loginPassword:disabled {
  cursor: wait;
  opacity: 0.65;
}

@media (max-width: 420px) {
  .gate-trace-line {
    grid-template-columns: 58px minmax(0, 1fr);
  }
}
