:root {
  --bg: #0b1115;
  --paper: rgba(18, 26, 32, 0.88);
  --paper-strong: rgba(12, 18, 23, 0.96);
  --ink: #edf3f7;
  --muted: #8ea1ad;
  --line: rgba(187, 212, 227, 0.12);
  --accent: #dd6b3c;
  --accent-dark: #b95329;
  --success: #54c17b;
  --danger: #ff6b6b;
  --shadow: 0 28px 90px rgba(0, 0, 0, 0.35);
}

* { box-sizing: border-box; }
body {
  margin: 0;
  color: var(--ink);
  background:
    radial-gradient(circle at top left, rgba(221, 107, 60, 0.14), transparent 24rem),
    radial-gradient(circle at top right, rgba(84, 193, 123, 0.1), transparent 26rem),
    radial-gradient(circle at bottom center, rgba(72, 108, 136, 0.12), transparent 30rem),
    linear-gradient(180deg, #0d1419, #070b0e 72%);
  font-family: "Segoe UI", sans-serif;
}

body.modal-open {
  overflow: hidden;
}

a {
  color: inherit;
}

.auth-shell {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 2rem;
}

.auth-card, .panel {
  background: var(--paper);
  backdrop-filter: blur(14px);
  border: 1px solid var(--line);
  border-radius: 24px;
  box-shadow: var(--shadow);
}

.auth-card {
  width: min(32rem, 100%);
  padding: 2rem;
}

.topbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 1.5rem 2rem 0.5rem;
  gap: 1rem;
}

.topbar-actions {
  display: flex;
  gap: 0.75rem;
  flex-wrap: wrap;
  align-items: center;
}

.layout {
  display: grid;
  grid-template-columns: repeat(12, minmax(0, 1fr));
  gap: 1rem;
  padding: 0.5rem 2rem 2rem;
  align-items: start;
}

.wide { grid-column: 1 / -1; }
.settings-column { grid-column: span 6; }
.panel { padding: 1.25rem; }
.panel-head {
  display: flex;
  justify-content: space-between;
  gap: 1rem;
  align-items: center;
  margin-bottom: 1rem;
}

.panel-head-actions {
  display: flex;
  gap: 0.75rem;
  align-items: center;
  flex-wrap: wrap;
}

.eyebrow {
  margin: 0 0 0.25rem;
  font-size: 0.75rem;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: var(--accent);
}

h1, h2, h3, p { margin-top: 0; }
h1 { font-size: clamp(2rem, 4vw, 3rem); margin-bottom: 0.5rem; }
h2 { font-size: 1.25rem; margin-bottom: 0; }
h3 { margin-bottom: 0.5rem; }
.lede, .muted { color: var(--muted); }

form { display: grid; gap: 1rem; }
.grid-form {
  grid-template-columns: repeat(auto-fit, minmax(14rem, 1fr));
  align-items: start;
}
.span-2 { grid-column: span 2; }

label {
  display: grid;
  gap: 0.35rem;
  font-size: 0.95rem;
}

input, select, button {
  font: inherit;
}

input, select {
  width: 100%;
  border-radius: 14px;
  color: var(--ink);
  border: 1px solid rgba(187, 212, 227, 0.16);
  padding: 0.85rem 0.95rem;
  background: rgba(10, 16, 21, 0.88);
}

input:focus, select:focus {
  outline: 2px solid rgba(221, 107, 60, 0.18);
  border-color: rgba(221, 107, 60, 0.45);
}

.checkbox {
  display: flex;
  align-items: center;
  gap: 0.65rem;
  margin-top: 1.6rem;
}
.checkbox input {
  width: 1.1rem;
  height: 1.1rem;
}

button, .button-link {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: none;
  text-decoration: none;
  border-radius: 999px;
  padding: 0.85rem 1.2rem;
  background: var(--accent);
  color: white;
  cursor: pointer;
  transition: transform 120ms ease, background 120ms ease;
}

button:hover, .button-link:hover {
  transform: translateY(-1px);
  background: var(--accent-dark);
}

.ghost, .ghost-link {
  background: transparent;
  color: var(--ink);
  border: 1px solid var(--line);
}

.danger {
  background: var(--danger);
}

.actions {
  display: flex;
  gap: 0.75rem;
  flex-wrap: wrap;
}

.flash {
  padding: 0.75rem 1rem;
  border-radius: 14px;
  background: rgba(84, 193, 123, 0.14);
  color: var(--success);
}

.flash-error {
  background: rgba(255, 107, 107, 0.14);
  color: var(--danger);
}

.runtime-grid {
  display: grid;
  grid-template-columns: 1.2fr 1fr;
  gap: 1rem;
  margin-bottom: 1rem;
}

.runtime-card {
  padding: 1rem;
  border: 1px solid var(--line);
  border-radius: 18px;
  background: rgba(8, 14, 18, 0.82);
}

.runtime-label {
  margin-bottom: 0.5rem;
  color: var(--muted);
}

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

.runtime-badge {
  display: inline-flex;
  padding: 0.5rem 0.9rem;
  border-radius: 999px;
  font-weight: 600;
}

.runtime-badge.ok {
  background: rgba(84, 193, 123, 0.14);
  color: var(--success);
}

.runtime-badge.idle {
  background: rgba(187, 212, 227, 0.08);
  color: var(--muted);
}

.runtime-actions {
  display: flex;
  gap: 0.75rem;
  flex-wrap: wrap;
  align-items: start;
}

.mono {
  font-family: "Cascadia Mono", "SFMono-Regular", monospace;
}

.console {
  min-height: 22rem;
  width: 100%;
  resize: vertical;
  font-family: "Cascadia Mono", "SFMono-Regular", monospace;
  background: #05080b;
  color: #d5e4ee;
  border-radius: 18px;
  border: 1px solid rgba(89, 118, 138, 0.28);
}

.panel-fold {
  display: grid;
  gap: 1rem;
}

.panel-fold[hidden] {
  display: none;
}

.collapse-button {
  width: 2.75rem;
  height: 2.75rem;
  padding: 0;
}

.collapse-chevron {
  font-size: 1.1rem;
  line-height: 1;
  color: var(--accent);
  transition: transform 160ms ease;
}

.collapse-button[aria-expanded="false"] .collapse-chevron {
  transform: rotate(-90deg);
}

.fold-body {
  margin-top: 1rem;
}

.spectacle-list {
  display: grid;
  gap: 0.85rem;
  grid-template-columns: repeat(4, minmax(0, 1fr));
}

.spectacle-card {
  display: grid;
  gap: 1rem;
  padding: 1rem;
  border-radius: 18px;
  border: 1px solid var(--line);
  background: rgba(8, 14, 18, 0.72);
  min-height: 100%;
}

.card-actions {
  display: flex;
  flex-direction: row;
  flex-wrap: wrap;
  gap: 0.6rem;
  align-items: stretch;
  margin-top: auto;
}

.card-actions form {
  display: flex;
}

.settings-column .grid-form,
.security-card .grid-form {
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.security-stack {
  display: grid;
  gap: 1rem;
}

.security-card {
  padding: 1rem;
  border: 1px solid var(--line);
  border-radius: 18px;
  background: rgba(8, 14, 18, 0.72);
}

.security-head {
  display: flex;
  justify-content: space-between;
  gap: 1rem;
  align-items: start;
  margin-bottom: 1rem;
}

.totp-box {
  display: grid;
  gap: 1rem;
}

.totp-secret,
.totp-uri {
  padding: 0.9rem 1rem;
  border-radius: 16px;
  background: rgba(5, 8, 11, 0.88);
  border: 1px solid rgba(89, 118, 138, 0.28);
  overflow-wrap: anywhere;
}

.runtime-panel {
  overflow: hidden;
}

.icon-button {
  width: 2.75rem;
  height: 2.75rem;
  padding: 0;
  font-size: 1.4rem;
}

.modal-shell {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: grid;
  place-items: center;
  padding: 1.5rem;
}

.modal-shell[hidden] {
  display: none;
}

.modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(2, 6, 9, 0.78);
  backdrop-filter: blur(10px);
}

.modal-card {
  position: relative;
  z-index: 1;
  width: min(62rem, 100%);
  max-height: calc(100vh - 3rem);
  overflow: auto;
  padding: 1.25rem;
  border-radius: 24px;
  border: 1px solid var(--line);
  background: rgba(10, 16, 21, 0.96);
  box-shadow: var(--shadow);
}

.modal-head {
  position: sticky;
  top: 0;
  padding-bottom: 0.5rem;
  background: linear-gradient(180deg, rgba(10, 16, 21, 0.98), rgba(10, 16, 21, 0.8));
  backdrop-filter: blur(6px);
}

@media (max-width: 800px) {
  .topbar {
    flex-direction: column;
    align-items: stretch;
    padding: 1rem 1rem 0.25rem;
  }
  .topbar-actions {
    width: 100%;
  }
  .layout {
    grid-template-columns: 1fr;
    padding: 0.5rem 1rem 1.25rem;
  }
  .grid-form,
  .settings-column .grid-form,
  .security-card .grid-form {
    grid-template-columns: 1fr;
  }
  .settings-column,
  .wide,
  .span-2 { grid-column: span 1; }
  .runtime-grid {
    grid-template-columns: 1fr;
  }
  .runtime-actions form,
  .runtime-actions button,
  .card-actions button,
  .card-actions .button-link,
  .panel-head-actions .button-link {
    width: 100%;
  }
  .panel-head,
  .panel-head-actions {
    align-items: stretch;
  }
  .spectacle-list {
    grid-template-columns: 1fr;
  }
  .spectacle-card {
    grid-template-columns: 1fr;
  }
  .card-actions {
    flex-direction: column;
  }
  .modal-shell {
    padding: 0.75rem;
  }
  .modal-card {
    max-height: calc(100vh - 1.5rem);
    border-radius: 20px;
  }
  .auth-card {
    padding: 1.25rem;
  }
}

@media (min-width: 801px) and (max-width: 1180px) {
  .settings-column {
    grid-column: span 12;
  }
  .spectacle-list {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

@media (min-width: 1181px) and (max-width: 1480px) {
  .spectacle-list {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }
}
