:root {
  color-scheme: dark;
  --bg: #070a0d;
  --panel: rgba(17, 23, 29, 0.94);
  --panel-strong: #11171d;
  --line: rgba(255, 255, 255, 0.09);
  --line-strong: rgba(255, 255, 255, 0.15);
  --text: #eef3f5;
  --muted: #93a1aa;
  --accent: #5be0a1;
  --accent-dark: #123d2b;
  --danger: #ff7b78;
  --warning: #f6bf5b;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* { box-sizing: border-box; }

html,
body {
  width: 100%;
  min-height: 100%;
  margin: 0;
  background: var(--bg);
  color: var(--text);
}

button,
input { font: inherit; }

button,
a { -webkit-tap-highlight-color: transparent; }

[hidden] { display: none !important; }

.gate-page {
  min-height: 100dvh;
  background:
    radial-gradient(circle at 18% 14%, rgba(43, 145, 104, 0.2), transparent 34rem),
    radial-gradient(circle at 84% 82%, rgba(39, 92, 111, 0.16), transparent 32rem),
    var(--bg);
}

.gate-shell {
  min-height: 100dvh;
  display: grid;
  place-items: center;
  padding: 28px 18px;
}

.gate-card {
  width: min(100%, 400px);
  padding: 34px;
  border: 1px solid var(--line);
  border-radius: 22px;
  background: var(--panel);
  box-shadow: 0 28px 90px rgba(0, 0, 0, 0.45);
  backdrop-filter: blur(20px);
}

.gate-card.wide { width: min(100%, 460px); }

.brand-mark {
  position: relative;
  width: 46px;
  height: 46px;
  margin-bottom: 25px;
  border: 1px solid rgba(91, 224, 161, 0.28);
  border-radius: 15px;
  background: linear-gradient(145deg, rgba(91, 224, 161, 0.19), rgba(91, 224, 161, 0.04));
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.08), 0 14px 34px rgba(40, 180, 120, 0.12);
}

.brand-mark::before,
.brand-mark::after,
.brand-mark span {
  content: "";
  position: absolute;
  left: 11px;
  right: 11px;
  height: 2px;
  border-radius: 2px;
  background: var(--accent);
}

.brand-mark::before { top: 13px; }
.brand-mark span { top: 21px; left: 16px; }
.brand-mark::after { top: 29px; right: 16px; }

.eyebrow {
  margin: 0 0 8px;
  color: var(--accent);
  font-size: 11px;
  font-weight: 750;
  letter-spacing: 0.13em;
  text-transform: uppercase;
}

.gate-card h1 {
  margin: 0;
  font-size: clamp(27px, 7vw, 34px);
  line-height: 1.08;
  letter-spacing: -0.035em;
}

.gate-copy {
  margin: 13px 0 27px;
  color: var(--muted);
  font-size: 14px;
  line-height: 1.6;
}

.stacked-form { display: grid; gap: 10px; }

.stacked-form label {
  margin-top: 5px;
  color: #c9d1d6;
  font-size: 12px;
  font-weight: 650;
}

.stacked-form input,
.text-panel input {
  width: 100%;
  min-height: 46px;
  padding: 10px 13px;
  border: 1px solid var(--line-strong);
  border-radius: 11px;
  outline: none;
  background: rgba(3, 7, 9, 0.66);
  color: var(--text);
  transition: border-color 150ms ease, box-shadow 150ms ease;
}

.stacked-form input:focus,
.text-panel input:focus {
  border-color: rgba(91, 224, 161, 0.72);
  box-shadow: 0 0 0 3px rgba(91, 224, 161, 0.1);
}

.primary-button,
.tool-button {
  min-height: 40px;
  border: 1px solid transparent;
  border-radius: 10px;
  color: var(--text);
  cursor: pointer;
  transition: background-color 150ms ease, border-color 150ms ease, transform 100ms ease;
}

.primary-button {
  display: flex;
  align-items: center;
  justify-content: space-between;
  min-height: 46px;
  margin-top: 7px;
  padding: 10px 15px;
  background: var(--accent);
  color: #06130d;
  font-weight: 750;
}

.primary-button:hover { background: #72edb3; }
.primary-button:active, .tool-button:active { transform: translateY(1px); }
button:disabled { cursor: wait; opacity: 0.62; }
.primary-button.compact { min-height: 40px; margin: 0; justify-content: center; }

.notice {
  display: grid;
  gap: 4px;
  margin: 20px 0 2px;
  padding: 13px 14px;
  border: 1px solid var(--line);
  border-radius: 12px;
  font-size: 13px;
  line-height: 1.45;
}

.notice.warning { background: rgba(246, 191, 91, 0.08); color: #f8d998; }
.notice.success { background: rgba(91, 224, 161, 0.08); color: #a7f2ce; }
.notice a, .back-link { color: inherit; }

.form-message {
  margin: 2px 0 0;
  font-size: 13px;
  line-height: 1.45;
}

.form-message.error { color: var(--danger); }

.privacy-note {
  margin: 25px 0 0;
  color: #66747d;
  font-size: 11px;
  text-align: center;
}

.back-link {
  display: inline-block;
  margin-top: 22px;
  color: var(--muted);
  font-size: 13px;
  text-decoration: none;
}

.back-link:hover { color: var(--text); }

.app-page {
  height: 100dvh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

#toolbar {
  z-index: 5;
  display: flex;
  flex: 0 0 auto;
  align-items: center;
  gap: 8px;
  min-height: 56px;
  padding: max(8px, env(safe-area-inset-top)) max(10px, env(safe-area-inset-right)) 8px max(10px, env(safe-area-inset-left));
  border-bottom: 1px solid var(--line);
  background: rgba(12, 17, 21, 0.95);
  backdrop-filter: blur(18px);
}

.toolbar-brand {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-right: 7px;
  letter-spacing: -0.01em;
}

.mini-mark {
  width: 10px;
  height: 10px;
  border: 2px solid var(--accent);
  border-radius: 3px;
  transform: rotate(45deg);
}

.toolbar-spacer { flex: 1; }

.status {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  min-height: 30px;
  padding: 5px 10px;
  border: 1px solid var(--line);
  border-radius: 999px;
  color: var(--muted);
  font-size: 12px;
  white-space: nowrap;
}

.status-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: #71808a;
}

.status.online { color: #a7f2ce; background: rgba(91, 224, 161, 0.07); }
.status.online .status-dot { background: var(--accent); box-shadow: 0 0 0 4px rgba(91, 224, 161, 0.1); }
.status.offline { color: #ffaaa7; background: rgba(255, 123, 120, 0.07); }
.status.offline .status-dot { background: var(--danger); }
.status.warning { color: #f8d998; background: rgba(246, 191, 91, 0.07); }
.status.warning .status-dot { background: var(--warning); }
#statusDetail { color: #7d8c95; }

.fit-toggle {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  min-height: 40px;
  padding: 0 6px;
  color: var(--muted);
  font-size: 12px;
  cursor: pointer;
  user-select: none;
}

.fit-toggle input { accent-color: var(--accent); }

.tool-button {
  padding: 7px 11px;
  border-color: var(--line);
  background: rgba(255, 255, 255, 0.045);
  font-size: 12px;
}

.tool-button:hover { border-color: var(--line-strong); background: rgba(255, 255, 255, 0.08); }
.tool-button.danger-soft { color: #ffc1bf; }

#stage {
  position: relative;
  min-height: 0;
  flex: 1;
  display: grid;
  place-items: center;
  overflow: auto;
  background-color: #020304;
  background-image: radial-gradient(rgba(255, 255, 255, 0.035) 1px, transparent 1px);
  background-size: 22px 22px;
}

#screen {
  display: none;
  max-width: 100%;
  max-height: 100%;
  user-select: none;
  -webkit-user-drag: none;
}

#screen.visible { display: block; }
#screen.native-size { max-width: none; max-height: none; }

#overlay {
  position: absolute;
  inset: 0;
  z-index: 2;
  cursor: crosshair;
  outline: none;
  touch-action: none;
}

.empty-state {
  display: grid;
  place-items: center;
  gap: 7px;
  padding: 30px;
  color: var(--muted);
  text-align: center;
}

.empty-state strong { color: #c8d0d5; font-size: 14px; }
.empty-state span:last-child { font-size: 12px; }

.loader {
  width: 25px;
  height: 25px;
  margin-bottom: 8px;
  border: 2px solid rgba(255, 255, 255, 0.1);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

@keyframes spin { to { transform: rotate(360deg); } }

.text-panel {
  z-index: 8;
  display: grid;
  gap: 8px;
  padding: 12px max(12px, env(safe-area-inset-right)) max(12px, env(safe-area-inset-bottom)) max(12px, env(safe-area-inset-left));
  border-top: 1px solid var(--line);
  background: var(--panel-strong);
}

.text-panel label { color: var(--muted); font-size: 12px; }
.text-panel > div { display: grid; grid-template-columns: minmax(0, 1fr) auto auto; gap: 8px; }

.toast {
  position: fixed;
  z-index: 20;
  right: 16px;
  bottom: max(16px, env(safe-area-inset-bottom));
  max-width: min(360px, calc(100vw - 32px));
  padding: 10px 13px;
  border: 1px solid var(--line-strong);
  border-radius: 10px;
  background: #1b2329;
  box-shadow: 0 15px 45px rgba(0, 0, 0, 0.45);
  color: #dce4e8;
  font-size: 12px;
}

@media (max-width: 760px) {
  #toolbar { min-height: 50px; gap: 5px; overflow-x: auto; }
  .toolbar-brand strong, .fit-toggle span, #statusDetail { display: none; }
  .toolbar-brand { margin-right: 0; }
  .status { padding-inline: 8px; }
  .tool-button { min-height: 36px; padding: 6px 9px; }
  .fit-toggle { min-height: 36px; }
}

@media (max-width: 460px) {
  .gate-card { padding: 27px 22px; border-radius: 18px; }
  .text-panel > div { grid-template-columns: 1fr auto; }
  .text-panel #closeTextPanel { grid-column: 1 / -1; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { scroll-behavior: auto !important; animation-duration: 0.01ms !important; }
}
