:root {
  --bg: #0b0e13;
  --bg-soft: #10141c;
  --panel: #141922;
  --panel-2: #1b2230;
  --border: #263041;
  --border-soft: #1f2837;
  --text: #e8edf5;
  --muted: #91a0b6;
  --muted-2: #66748a;
  --accent: #1f9ed9;
  --accent-hover: #35b3ec;
  --accent-soft: rgba(31, 158, 217, 0.14);
  --cyan: #5fd0ff;
  --danger: #ff5c63;
  --danger-soft: rgba(255, 92, 99, 0.14);
  --ok: #3dd68c;
  --ok-soft: rgba(61, 214, 140, 0.14);
  --warn: #ffcf70;
  --warn-soft: rgba(255, 207, 112, 0.12);
  --radius: 14px;
  --radius-sm: 10px;
  --shadow: 0 18px 48px rgba(0, 0, 0, 0.45);
  --tap: 48px;
  color-scheme: dark;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  padding: 0;
  min-height: 100%;
}

body {
  background: radial-gradient(1200px 600px at 15% -10%, #16202f 0%, var(--bg) 55%) fixed, var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
  font-size: 16px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

a {
  color: var(--cyan);
  text-decoration: none;
}

a:hover {
  text-decoration: underline;
}

h1,
h2,
h3 {
  margin: 0 0 10px 0;
  line-height: 1.2;
  font-weight: 700;
}

h1 {
  font-size: 28px;
}

h2 {
  font-size: 20px;
}

h3 {
  font-size: 17px;
}

p {
  margin: 0 0 12px 0;
}

.muted {
  color: var(--muted);
}

.small {
  font-size: 14px;
}

.mono {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 13px;
}

.hidden {
  display: none !important;
}

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

/* ---------------------------------------------------------------- topbar */

.topbar {
  display: flex;
  align-items: center;
  gap: 18px;
  min-height: 64px;
  padding: 8px 22px;
  background: rgba(15, 19, 27, 0.92);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 30;
  backdrop-filter: blur(10px);
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  font-weight: 800;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  font-size: 14px;
  color: var(--cyan);
  white-space: nowrap;
}

.brand::before {
  content: '';
  width: 8px;
  height: 22px;
  border-radius: 3px;
  background: linear-gradient(180deg, var(--cyan), var(--accent));
  box-shadow: 0 0 18px rgba(95, 208, 255, 0.5);
}

.topbar nav {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-left: 6px;
}

.topbar nav a {
  display: inline-flex;
  align-items: center;
  min-height: 40px;
  padding: 0 14px;
  border-radius: 999px;
  color: var(--muted);
  font-weight: 600;
  font-size: 14px;
}

.topbar nav a:hover,
.topbar nav a.active {
  background: var(--panel-2);
  color: var(--text);
  text-decoration: none;
}

.topbar .spacer {
  flex: 1;
}

.topbar .user {
  color: var(--muted);
  font-size: 14px;
  max-width: 280px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* -------------------------------------------------------------- controls */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: var(--tap);
  padding: 0 20px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--panel-2);
  color: var(--text);
  font: inherit;
  font-weight: 650;
  cursor: pointer;
  transition: background 0.15s ease, border-color 0.15s ease, transform 0.05s ease;
  user-select: none;
  touch-action: manipulation;
}

.btn:hover {
  background: #232c3d;
  border-color: #33415a;
}

.btn:active {
  transform: translateY(1px);
}

.btn:disabled {
  opacity: 0.45;
  cursor: not-allowed;
  transform: none;
}

.btn.primary {
  background: linear-gradient(180deg, #24a9e2, #1b8fc4);
  border-color: transparent;
  color: #04131c;
}

.btn.primary:hover {
  background: linear-gradient(180deg, #3bbcf2, #249ed6);
}

.btn.danger {
  background: var(--danger-soft);
  border-color: rgba(255, 92, 99, 0.4);
  color: #ff9ba0;
}

.btn.danger:hover {
  background: rgba(255, 92, 99, 0.24);
}

.btn.ghost {
  background: transparent;
}

.btn.small {
  min-height: 36px;
  padding: 0 12px;
  font-size: 13px;
  border-radius: 8px;
}

.btn.icon {
  width: var(--tap);
  padding: 0;
  font-size: 18px;
}

label.field {
  display: block;
  margin-bottom: 16px;
  font-size: 13px;
  font-weight: 700;
  letter-spacing: 0.02em;
  color: var(--muted);
}

label.field .hint {
  display: block;
  margin-top: 6px;
  font-weight: 500;
  color: var(--muted-2);
  letter-spacing: 0;
  font-size: 12.5px;
}

input[type='text'],
input[type='email'],
input[type='password'],
input[type='url'],
input[type='number'],
select,
textarea {
  display: block;
  width: 100%;
  min-height: var(--tap);
  margin-top: 7px;
  padding: 10px 14px;
  background: #0b1017;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text);
  font: inherit;
  font-weight: 500;
  outline: none;
}

input:focus,
select:focus,
textarea:focus {
  border-color: rgba(95, 208, 255, 0.65);
  box-shadow: 0 0 0 3px rgba(31, 158, 217, 0.18);
}

input[readonly] {
  background: #0e131b;
  color: var(--muted);
}

input[type='range'] {
  width: 100%;
  min-height: var(--tap);
  accent-color: var(--accent);
  cursor: pointer;
}

.check {
  display: flex;
  gap: 12px;
  align-items: flex-start;
  padding: 12px 14px;
  margin: 0 0 16px 0;
  background: var(--warn-soft);
  border: 1px solid rgba(255, 207, 112, 0.28);
  border-radius: var(--radius-sm);
  font-size: 13.5px;
  line-height: 1.5;
  color: #f2dcb0;
  cursor: pointer;
}

.check input {
  width: 20px;
  height: 20px;
  margin-top: 2px;
  accent-color: var(--accent);
  flex: 0 0 auto;
}

.row {
  display: flex;
  gap: 12px;
  flex-wrap: wrap;
}

.row > * {
  flex: 1 1 160px;
}

/* ----------------------------------------------------------------- cards */

.card {
  background: linear-gradient(180deg, rgba(27, 34, 48, 0.7), rgba(20, 25, 34, 0.95));
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  box-shadow: var(--shadow);
}

.card + .card {
  margin-top: 16px;
}

.card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 14px;
}

.card-header h2 {
  margin: 0;
}

/* ------------------------------------------------------------------ auth */

.auth-page {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 28px 18px;
  min-height: 100vh;
}

.auth-card {
  width: 100%;
  max-width: 460px;
  background: linear-gradient(180deg, #171d28, #12161e);
  border: 1px solid var(--border);
  border-radius: 20px;
  padding: 30px;
  box-shadow: var(--shadow);
}

.auth-card .brand {
  margin-bottom: 22px;
}

.auth-card h1 {
  font-size: 30px;
}

.auth-card .lead {
  color: var(--muted);
  margin-bottom: 22px;
}

.auth-card .btn {
  width: 100%;
  margin-top: 4px;
}

.auth-foot {
  margin-top: 20px;
  padding-top: 18px;
  border-top: 1px solid var(--border-soft);
  font-size: 14px;
  color: var(--muted);
  text-align: center;
}

.msg {
  display: none;
  margin-top: 16px;
  padding: 12px 14px;
  border-radius: var(--radius-sm);
  font-size: 14px;
  line-height: 1.5;
  background: var(--danger-soft);
  border: 1px solid rgba(255, 92, 99, 0.35);
  color: #ffb3b7;
}

.msg.show {
  display: block;
}

.msg.ok {
  background: var(--ok-soft);
  border-color: rgba(61, 214, 140, 0.35);
  color: #9df0c4;
}

.note {
  padding: 12px 14px;
  border-radius: var(--radius-sm);
  background: var(--accent-soft);
  border: 1px solid rgba(95, 208, 255, 0.28);
  color: #b9e7fb;
  font-size: 13.5px;
  line-height: 1.55;
  margin-bottom: 18px;
}

.note.warn {
  background: var(--warn-soft);
  border-color: rgba(255, 207, 112, 0.3);
  color: #f2dcb0;
}

/* -------------------------------------------------------------- disclaimer */

.disclaimer {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  padding: 10px 18px;
  background: linear-gradient(90deg, rgba(255, 207, 112, 0.14), rgba(255, 92, 99, 0.12));
  border-bottom: 1px solid rgba(255, 207, 112, 0.28);
  color: #ffd98a;
  font-size: 13px;
  font-weight: 700;
  letter-spacing: 0.02em;
  text-align: center;
  position: sticky;
  top: 64px;
  z-index: 25;
}

.disclaimer .dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--warn);
  box-shadow: 0 0 12px rgba(255, 207, 112, 0.8);
  flex: 0 0 auto;
}

/* ---------------------------------------------------------------- player */

.player-layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 360px;
  gap: 18px;
  padding: 18px 22px 28px;
  max-width: 1800px;
  margin: 0 auto;
  align-items: start;
}

.stage-panel {
  display: flex;
  flex-direction: column;
  gap: 12px;
  min-width: 0;
}

.stage {
  position: relative;
  width: 100%;
  aspect-ratio: 16 / 9;
  max-height: calc(100vh - 250px);
  min-height: 260px;
  background: #000;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  box-shadow: var(--shadow);
}

.stage canvas {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: contain;
  background: #000;
}

.overlay {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 10px;
  padding: 24px;
  text-align: center;
  color: var(--muted);
  background: radial-gradient(circle at center, rgba(20, 25, 34, 0.55), rgba(0, 0, 0, 0.82));
  pointer-events: none;
}

.overlay.hidden {
  display: none !important;
}

.overlay strong {
  color: var(--text);
  font-size: 20px;
}

.spinner {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  border: 3px solid rgba(95, 208, 255, 0.2);
  border-top-color: var(--cyan);
  animation: spin 0.9s linear infinite;
}

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

.stage-bar {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  padding: 10px 14px;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
}

.stats {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  flex: 1;
}

.stat {
  display: inline-flex;
  align-items: baseline;
  gap: 6px;
  padding: 6px 10px;
  background: #0c1118;
  border: 1px solid var(--border-soft);
  border-radius: 8px;
  font-size: 12px;
  color: var(--muted);
}

.stat b {
  color: var(--text);
  font-size: 14px;
  font-variant-numeric: tabular-nums;
}

.side {
  display: flex;
  flex-direction: column;
  gap: 16px;
  min-width: 0;
}

.side .card + .card {
  margin-top: 0;
}

.form-actions {
  display: flex;
  gap: 10px;
  margin-top: 4px;
}

.form-actions .btn {
  flex: 1;
}

.mode-help {
  margin-top: 10px;
  font-size: 12.5px;
  line-height: 1.55;
  color: var(--muted-2);
}

.session-line {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  padding: 8px 0;
  border-bottom: 1px solid var(--border-soft);
  font-size: 13px;
}

.session-line:last-child {
  border-bottom: none;
}

.session-line span {
  color: var(--muted);
}

.session-line b {
  text-align: right;
  word-break: break-all;
}

.volume-row {
  display: flex;
  align-items: center;
  gap: 12px;
}

.volume-row input {
  flex: 1;
}

audio {
  display: none;
}

/* ----------------------------------------------------------------- admin */

.admin-layout {
  display: grid;
  grid-template-columns: 380px minmax(0, 1fr);
  gap: 18px;
  padding: 22px;
  max-width: 1600px;
  margin: 0 auto;
  align-items: start;
}

.admin-main {
  display: flex;
  flex-direction: column;
  gap: 16px;
  min-width: 0;
}

.table-wrap {
  width: 100%;
  overflow-x: auto;
  border: 1px solid var(--border-soft);
  border-radius: var(--radius-sm);
}

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 14px;
  min-width: 640px;
}

th,
td {
  padding: 12px 14px;
  text-align: left;
  border-bottom: 1px solid var(--border-soft);
  vertical-align: middle;
}

th {
  background: #0e131b;
  color: var(--muted);
  font-size: 11.5px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  font-weight: 700;
  white-space: nowrap;
}

tbody tr:last-child td {
  border-bottom: none;
}

tbody tr:hover {
  background: rgba(255, 255, 255, 0.02);
}

td.actions {
  white-space: nowrap;
}

td.actions .btn {
  margin: 2px 6px 2px 0;
}

.empty {
  padding: 22px;
  text-align: center;
  color: var(--muted-2);
  font-size: 14px;
}

.badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 10px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.02em;
  white-space: nowrap;
}

.badge.pending {
  background: var(--accent-soft);
  color: var(--cyan);
}

.badge.used {
  background: var(--ok-soft);
  color: var(--ok);
}

.badge.expired {
  background: rgba(145, 160, 182, 0.14);
  color: var(--muted);
}

.badge.revoked {
  background: var(--danger-soft);
  color: #ff9ba0;
}

.badge.owner {
  background: var(--warn-soft);
  color: var(--warn);
}

.badge.viewer {
  background: rgba(145, 160, 182, 0.14);
  color: var(--muted);
}

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

@media (max-width: 1100px) {
  .player-layout {
    grid-template-columns: minmax(0, 1fr);
  }

  .admin-layout {
    grid-template-columns: minmax(0, 1fr);
  }

  .stage {
    max-height: none;
  }
}

@media (max-width: 700px) {
  .topbar {
    flex-wrap: wrap;
    gap: 8px;
    padding: 10px 14px;
  }

  .topbar .user {
    max-width: 150px;
  }

  .topbar nav a {
    padding: 0 10px;
  }

  .disclaimer {
    position: static;
    font-size: 12px;
    padding: 8px 12px;
  }

  .player-layout,
  .admin-layout {
    padding: 14px;
  }

  .auth-card {
    padding: 22px;
  }

  h1 {
    font-size: 24px;
  }
}

.mt-10 {
  margin-top: 10px;
}

.mt-16 {
  margin-top: 16px;
}
