:root {
  color-scheme: dark;
  --bg: #091015;
  --panel: rgba(17, 27, 34, 0.9);
  --panel-strong: #111c23;
  --line: rgba(172, 212, 222, 0.12);
  --text: #f4f8f7;
  --muted: #91a3a8;
  --teal: #42e1bc;
  --teal-strong: #6cfbd7;
  --amber: #ffb86b;
  --red: #ff7f72;
  --blue: #84adff;
  --shadow: 0 28px 80px rgba(0, 0, 0, 0.32);
  --radius: 22px;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* { box-sizing: border-box; }

html { scroll-behavior: smooth; }

body {
  min-height: 100vh;
  margin: 0;
  color: var(--text);
  background:
    radial-gradient(circle at 15% -10%, rgba(48, 137, 122, 0.18), transparent 38%),
    radial-gradient(circle at 100% 24%, rgba(64, 93, 154, 0.12), transparent 30%),
    var(--bg);
}

button, input { font: inherit; }
button { color: inherit; }
.hidden { display: none !important; }

.ambient {
  position: fixed;
  width: 360px;
  height: 360px;
  border-radius: 50%;
  filter: blur(120px);
  opacity: 0.08;
  pointer-events: none;
}
.ambient-one { background: var(--teal); left: -180px; top: 24%; }
.ambient-two { background: var(--blue); right: -220px; top: 46%; }

.shell {
  width: min(1180px, calc(100% - 40px));
  margin: 0 auto;
  padding: 26px 0 80px;
  position: relative;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  min-height: 58px;
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: 12px;
  color: inherit;
  text-decoration: none;
  letter-spacing: 0.08em;
}

.brand-mark {
  display: grid;
  place-items: center;
  width: 40px;
  height: 40px;
  border: 1px solid rgba(108, 251, 215, 0.38);
  border-radius: 12px;
  color: var(--teal-strong);
  background: linear-gradient(145deg, rgba(66, 225, 188, 0.12), rgba(66, 225, 188, 0.02));
  font-family: Georgia, serif;
  font-size: 22px;
}

.brand strong { display: block; font-size: 14px; }
.brand small { display: block; margin-top: 2px; color: var(--muted); font-size: 9px; letter-spacing: 0.16em; text-transform: uppercase; }
.topbar-actions { display: flex; align-items: center; gap: 10px; }

.mode-badge,
.connection,
.status-pill {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.035);
}

.mode-badge {
  padding: 8px 11px;
  color: #b9c8cb;
  font-size: 10px;
  font-weight: 750;
  letter-spacing: 0.12em;
}
.mode-badge span, .connection span {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--amber);
  box-shadow: 0 0 16px rgba(255, 184, 107, 0.7);
}

.login-view {
  min-height: calc(100vh - 110px);
  display: grid;
  place-items: center;
}

.login-card {
  width: min(600px, 100%);
  padding: clamp(28px, 5vw, 58px);
  border: 1px solid var(--line);
  border-radius: 30px;
  background: linear-gradient(145deg, rgba(20, 32, 39, 0.96), rgba(11, 18, 23, 0.96));
  box-shadow: var(--shadow);
}

.eyebrow {
  margin: 0 0 9px;
  color: var(--teal);
  font-size: 10px;
  font-weight: 800;
  letter-spacing: 0.16em;
  text-transform: uppercase;
}

.login-card h1, .hero h1 {
  margin: 0;
  font-family: Georgia, "Times New Roman", serif;
  font-size: clamp(38px, 7vw, 64px);
  font-weight: 500;
  line-height: 0.98;
  letter-spacing: -0.045em;
}
.login-card > p { max-width: 500px; color: var(--muted); font-size: 16px; line-height: 1.65; }
.login-card form { margin-top: 32px; }
.login-card label, .field > span, .weekday-field legend { display: block; margin-bottom: 9px; color: #c5d1d3; font-size: 12px; font-weight: 700; }
.password-row { display: grid; grid-template-columns: 1fr auto; gap: 10px; }

input {
  width: 100%;
  min-height: 46px;
  border: 1px solid rgba(175, 211, 218, 0.18);
  border-radius: 12px;
  padding: 0 14px;
  color: var(--text);
  outline: none;
  background: rgba(4, 10, 13, 0.56);
  transition: border-color 160ms ease, box-shadow 160ms ease;
}
input:focus { border-color: rgba(66, 225, 188, 0.68); box-shadow: 0 0 0 3px rgba(66, 225, 188, 0.1); }
input::placeholder { color: #607177; }

.button {
  min-height: 43px;
  border: 1px solid transparent;
  border-radius: 12px;
  padding: 0 18px;
  cursor: pointer;
  font-weight: 760;
  transition: transform 120ms ease, filter 120ms ease, background 120ms ease;
}
.button:hover:not(:disabled) { transform: translateY(-1px); filter: brightness(1.07); }
.button:active:not(:disabled) { transform: translateY(0); }
.button:disabled { cursor: not-allowed; opacity: 0.42; }
.button-primary { color: #06110e; background: var(--teal); }
.button-quiet { color: #c0ced0; border-color: var(--line); background: rgba(255, 255, 255, 0.03); }

.security-note {
  display: flex;
  gap: 12px;
  margin-top: 30px;
  padding-top: 20px;
  border-top: 1px solid var(--line);
  color: var(--muted);
  font-size: 12px;
  line-height: 1.55;
}
.security-note span { color: var(--amber); font-size: 22px; }
.security-note p { margin: 0; }
.form-message { min-height: 18px; margin: 8px 0 0; color: var(--red); font-size: 12px; }

.app-view { padding-top: 78px; }
.hero { display: flex; align-items: end; justify-content: space-between; gap: 24px; margin-bottom: 38px; }
.hero-copy { margin: 14px 0 0; color: var(--muted); }
.connection { padding: 10px 14px; color: #b8c8ca; font-size: 12px; white-space: nowrap; }
.connection span { background: var(--teal); box-shadow: 0 0 16px rgba(66, 225, 188, 0.75); }
.connection[data-connected="false"] span { background: var(--amber); box-shadow: 0 0 16px rgba(255, 184, 107, 0.7); }
.mode-badge[data-mode="relay"] span { background: var(--teal); box-shadow: 0 0 16px rgba(66, 225, 188, 0.75); }

.panel { border: 1px solid var(--line); border-radius: var(--radius); background: var(--panel); box-shadow: var(--shadow); backdrop-filter: blur(12px); }
.gate-card { display: grid; grid-template-columns: minmax(280px, 0.8fr) minmax(380px, 1.2fr); min-height: 390px; overflow: hidden; }
.gate-visual { position: relative; display: grid; place-items: end center; min-height: 390px; overflow: hidden; background: linear-gradient(155deg, #14262b, #0b1318 72%); }
.gate-visual::before { content: ""; position: absolute; inset: 0; background: linear-gradient(rgba(255,255,255,.025) 1px, transparent 1px), linear-gradient(90deg, rgba(255,255,255,.018) 1px, transparent 1px); background-size: 36px 36px; mask-image: linear-gradient(to bottom, black, transparent 85%); }
.gate-frame { position: absolute; bottom: 52px; width: 68%; height: 61%; border: 12px solid #29383d; border-bottom: 0; box-shadow: inset 0 0 40px rgba(0,0,0,.7), 0 20px 60px rgba(0,0,0,.4); }
.gate-door { position: absolute; inset: 0; display: flex; gap: 7px; padding: 12px 10px 0; background: linear-gradient(#172126, #0f171b); transform-origin: top; transition: transform 900ms cubic-bezier(.4,0,.2,1), opacity 500ms ease; }
.gate-door i { flex: 1; border: 1px solid rgba(134, 166, 171, 0.15); background: linear-gradient(90deg, #26363b, #172328, #26363b); }
.gate-visual[data-state="open"] .gate-door { transform: translateY(-88%); opacity: .3; }
.gate-visual[data-state="opening"] .gate-door { transform: translateY(-42%); }
.gate-visual[data-state="closing"] .gate-door { transform: translateY(-20%); }
.gate-ground { width: 82%; height: 52px; border-top: 1px solid rgba(108, 251, 215, 0.25); background: radial-gradient(ellipse at top, rgba(66,225,188,.18), transparent 65%); }

.gate-content { display: flex; flex-direction: column; justify-content: center; padding: clamp(30px, 5vw, 64px); }
.section-heading { display: flex; align-items: end; justify-content: space-between; gap: 24px; margin: 72px 0 24px; }
.section-heading.compact { align-items: start; margin: 0 0 10px; }
.section-heading h2, .form-header h3, .secret-dialog h2 { margin: 0; font-family: Georgia, serif; font-weight: 500; letter-spacing: -0.025em; }
.section-heading h2 { font-size: clamp(28px, 4vw, 40px); }
.section-heading p:not(.eyebrow) { max-width: 650px; margin: 8px 0 0; color: var(--muted); line-height: 1.55; }
.status-pill { padding: 9px 13px; color: var(--teal-strong); border-color: rgba(66,225,188,.2); background: rgba(66,225,188,.08); font-size: 12px; font-weight: 760; }
.status-detail { margin: 12px 0 4px; color: #ced8da; }
.freshness { margin: 0; color: var(--muted); font-size: 11px; }
.gate-actions { display: grid; grid-template-columns: 1fr 0.8fr 1fr; gap: 10px; margin-top: 30px; }
.gate-actions .button { min-height: 54px; }
.button-open { color: #06110e; background: var(--teal); }
.button-stop { color: #ffd5a8; border-color: rgba(255,184,107,.25); background: rgba(255,184,107,.08); }
.button-close { color: #d9e2e4; border-color: var(--line); background: rgba(255,255,255,.04); }
.shadow-warning { margin: 18px 0 0; color: #809398; font-size: 11px; line-height: 1.5; }
.shadow-warning strong { color: var(--amber); }

.metrics { display: grid; grid-template-columns: repeat(3, 1fr); gap: 14px; margin-top: 14px; }
.metric { display: flex; align-items: center; gap: 14px; padding: 18px 20px; box-shadow: none; }
.metric-icon { display: grid; place-items: center; width: 38px; height: 38px; border-radius: 12px; color: var(--teal); background: rgba(66,225,188,.08); }
.metric strong, .metric span { display: block; }
.metric strong { font-size: 16px; }
.metric div span { margin-top: 3px; color: var(--muted); font-size: 11px; }

.code-form { padding: clamp(22px, 4vw, 38px); margin-bottom: 18px; box-shadow: none; }
.form-header { display: flex; justify-content: space-between; margin-bottom: 28px; }
.form-header h3 { font-size: 28px; }
.icon-button { width: 38px; height: 38px; border: 1px solid var(--line); border-radius: 11px; color: var(--muted); cursor: pointer; background: transparent; font-size: 24px; }
.form-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 16px; }
.field-wide { grid-column: span 2; }
.field small { color: var(--muted); font-weight: 400; }
.weekday-field { margin: 24px 0 0; padding: 0; border: 0; }
.weekday-options { display: flex; gap: 8px; flex-wrap: wrap; }
.weekday-options label input { position: absolute; opacity: 0; pointer-events: none; }
.weekday-options label span { display: grid; place-items: center; min-width: 48px; min-height: 38px; border: 1px solid var(--line); border-radius: 10px; color: var(--muted); cursor: pointer; font-size: 11px; font-weight: 750; }
.weekday-options input:checked + span { color: var(--teal-strong); border-color: rgba(66,225,188,.34); background: rgba(66,225,188,.1); }
.form-footer { display: flex; align-items: center; justify-content: space-between; gap: 20px; margin-top: 28px; padding-top: 22px; border-top: 1px solid var(--line); }

.code-list { display: grid; gap: 10px; }
.code-item { display: grid; grid-template-columns: minmax(220px, 1.3fr) minmax(260px, 1fr) auto; gap: 24px; align-items: center; padding: 20px 22px; border: 1px solid var(--line); border-radius: 16px; background: rgba(17,27,34,.72); }
.code-item h3 { margin: 0 0 6px; font-size: 15px; }
.code-item p { margin: 0; color: var(--muted); font-size: 11px; line-height: 1.5; }
.code-meta { display: flex; gap: 18px; }
.code-meta div span, .code-meta div strong { display: block; }
.code-meta span { color: var(--muted); font-size: 9px; font-weight: 750; letter-spacing: .08em; text-transform: uppercase; }
.code-meta strong { margin-top: 4px; font-size: 12px; }
.code-actions { display: flex; align-items: center; gap: 10px; }
.code-status { padding: 6px 9px; border-radius: 999px; color: var(--teal); background: rgba(66,225,188,.08); font-size: 9px; font-weight: 800; letter-spacing: .08em; text-transform: uppercase; }
.code-status[data-status="expired"], .code-status[data-status="exhausted"], .code-status[data-status="disabled"] { color: var(--muted); background: rgba(255,255,255,.05); }
.code-status[data-status="scheduled"], .code-status[data-status="outside_schedule"] { color: var(--amber); background: rgba(255,184,107,.08); }
.disable-code { min-height: 34px; padding: 0 11px; font-size: 10px; }

.empty-state { padding: 50px 24px; text-align: center; box-shadow: none; }
.empty-state > span { color: var(--teal); font-size: 32px; }
.empty-state h3 { margin: 12px 0 4px; }
.empty-state p, .empty-inline { margin: 0; color: var(--muted); font-size: 12px; }
.activity-list { overflow: hidden; box-shadow: none; }
.activity-item { display: grid; grid-template-columns: 42px 1fr auto; align-items: center; gap: 14px; padding: 15px 18px; border-bottom: 1px solid var(--line); }
.activity-item:last-child { border-bottom: 0; }
.activity-symbol { display: grid; place-items: center; width: 36px; height: 36px; border-radius: 11px; color: var(--teal); background: rgba(66,225,188,.08); }
.activity-item strong, .activity-item span { display: block; }
.activity-item strong { font-size: 12px; }
.activity-item span { margin-top: 3px; color: var(--muted); font-size: 10px; }
.activity-status { color: var(--teal) !important; font-weight: 750; text-transform: uppercase; }
.activity-list > .empty-inline { padding: 30px; text-align: center; }

.toast-region { position: fixed; right: 20px; bottom: 20px; z-index: 20; display: grid; gap: 8px; width: min(380px, calc(100vw - 40px)); }
.toast { padding: 14px 16px; border: 1px solid rgba(66,225,188,.2); border-radius: 13px; color: #dce8e6; background: #13221f; box-shadow: var(--shadow); font-size: 12px; animation: toast-in 180ms ease-out; }
.toast.error { border-color: rgba(255,127,114,.25); background: #291918; }
@keyframes toast-in { from { opacity: 0; transform: translateY(8px); } }

.secret-dialog { width: min(450px, calc(100% - 32px)); border: 1px solid var(--line); border-radius: 24px; padding: 34px; color: var(--text); text-align: center; background: #101b21; box-shadow: 0 40px 120px rgba(0,0,0,.65); }
.secret-dialog::backdrop { background: rgba(2,7,9,.76); backdrop-filter: blur(8px); }
.secret-dialog .dialog-icon { margin-bottom: 12px; color: var(--teal); font-size: 30px; }
.secret-dialog h2 { font-size: 30px; }
.secret-dialog output { display: block; margin: 24px 0 16px; color: var(--teal-strong); font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 46px; font-weight: 800; letter-spacing: .14em; }
.secret-dialog p:not(.eyebrow) { color: var(--muted); font-size: 12px; line-height: 1.55; }
.secret-dialog .button { width: 100%; margin-top: 8px; }

@media (max-width: 820px) {
  .app-view { padding-top: 46px; }
  .hero { align-items: start; flex-direction: column; }
  .gate-card { grid-template-columns: 1fr; }
  .gate-visual { min-height: 280px; }
  .gate-content { padding: 30px; }
  .metrics { grid-template-columns: 1fr; }
  .form-grid { grid-template-columns: 1fr 1fr; }
  .code-item { grid-template-columns: 1fr; gap: 14px; }
  .code-actions { justify-content: space-between; }
}

@media (max-width: 560px) {
  .shell { width: min(100% - 24px, 1180px); padding-top: 14px; }
  .brand small { display: none; }
  .password-row, .form-grid { grid-template-columns: 1fr; }
  .field-wide { grid-column: auto; }
  .password-row .button { min-height: 48px; }
  .mode-badge { padding: 7px 9px; font-size: 9px; }
  .hero h1 { font-size: 42px; }
  .gate-actions { grid-template-columns: 1fr 1fr; }
  .button-stop { grid-column: 1 / -1; grid-row: 2; }
  .section-heading { align-items: start; flex-direction: column; margin-top: 52px; }
  .section-heading > .button { width: 100%; }
  .form-footer { align-items: stretch; flex-direction: column; }
  .code-meta { flex-wrap: wrap; }
}

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