:root {
  --bg: #0f1115;
  --panel: #181b22;
  --panel-2: #20242d;
  --line: #2c313c;
  --text: #e8eaef;
  --muted: #9aa1ae;
  --accent: #4f8cff;
  --accent-2: #3a74e0;
  --danger: #ef5b5b;
  --ok: #3ecf8e;
  --warn: #f0b44c;
  --radius: 12px;
  color-scheme: dark;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  background: var(--bg);
  color: var(--text);
  font-family: "Assistant", "Segoe UI", Arial, sans-serif;
  font-size: 16px;
  line-height: 1.5;
}
a { color: var(--accent); }
h1, h2, h3 { margin: 0 0 .5em; line-height: 1.25; }
.muted { color: var(--muted); }
.small { font-size: .875rem; }
.hidden { display: none !important; }

.center {
  min-height: 100%;
  display: grid;
  place-items: center;
  padding: 24px 16px;
}
.card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 28px;
  width: 100%;
  max-width: 420px;
}
.card h1 { font-size: 1.5rem; }

label { display: block; font-size: .9rem; color: var(--muted); margin: 14px 0 6px; }
input, select, textarea {
  width: 100%;
  background: var(--panel-2);
  color: var(--text);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px 12px;
  font: inherit;
}
input:focus, select:focus, textarea:focus { outline: 2px solid var(--accent); outline-offset: 0; border-color: transparent; }
input.code-input {
  text-align: center;
  letter-spacing: .2em;
  font-size: 1.4rem;
  font-family: ui-monospace, Consolas, monospace;
  text-transform: uppercase;
  direction: ltr;
}
button, .btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  background: var(--accent);
  color: #fff;
  border: 0;
  border-radius: 8px;
  padding: 10px 16px;
  font: inherit;
  font-weight: 600;
  cursor: pointer;
  text-decoration: none;
}
button:hover { background: var(--accent-2); }
button:disabled { opacity: .5; cursor: default; }
button.ghost { background: transparent; color: var(--text); border: 1px solid var(--line); }
button.ghost:hover { background: var(--panel-2); }
button.danger { background: transparent; color: var(--danger); border: 1px solid #5a2a2a; }
button.danger:hover { background: #2a1717; }
.btn.small, button.small { padding: 5px 10px; font-size: .85rem; font-weight: 500; }
.full { width: 100%; margin-top: 18px; }
.error { color: var(--danger); min-height: 1.5em; margin-top: 10px; font-size: .95rem; }

/* ---------- player ---------- */
.player-page { max-width: 1200px; margin: 0 auto; padding: 16px; }
.topbar { display: flex; justify-content: space-between; align-items: center; gap: 12px; margin-bottom: 12px; flex-wrap: wrap; }
.stage {
  position: relative;
  background: #000;
  border-radius: var(--radius);
  overflow: hidden;
  aspect-ratio: 16 / 9;
  user-select: none;
  -webkit-user-select: none;
}
.stage video { width: 100%; height: 100%; display: block; background: #000; object-fit: contain; }
.stage:fullscreen { border-radius: 0; aspect-ratio: auto; width: 100vw; height: 100vh; }
.stage:-webkit-full-screen { border-radius: 0; aspect-ratio: auto; width: 100vw; height: 100vh; }
.stage.pseudo-fs { position: fixed; inset: 0; z-index: 1000; border-radius: 0; aspect-ratio: auto; width: 100vw; height: 100dvh; }
.stage:focus { outline: none; }
.stage.idle { cursor: none; }
.watermark {
  position: absolute;
  pointer-events: none;
  color: rgba(255, 255, 255, .38);
  text-shadow: 0 0 3px rgba(0, 0, 0, .6);
  font-size: clamp(12px, 1.6vw, 20px);
  font-weight: 600;
  white-space: nowrap;
  transition: top 1.2s ease, left 1.2s ease;
  z-index: 5;
  direction: rtl;
}
.watermark.faint { color: rgba(255, 255, 255, .12); font-size: clamp(10px, 1.1vw, 14px); transition: none; }
/* custom controls: shown on mouse move, hidden after 2.5s of stillness while playing */
.controls {
  position: absolute; left: 0; right: 0; bottom: 0; z-index: 6;
  padding: 40px 12px 6px;
  background: linear-gradient(transparent, rgba(0, 0, 0, .75));
  transition: opacity .25s;
}
.stage.idle .controls, .stage.idle .big-play { opacity: 0; pointer-events: none; }
.ctl-bar { display: flex; align-items: center; gap: 4px; color: #fff; }
.ctl-bar .grow { flex: 1; }
.stage button.ctl {
  background: transparent; color: #fff; padding: 6px; border-radius: 6px; border: 0;
}
.stage button.ctl:hover { background: rgba(255, 255, 255, .15); }
.ctl svg { width: 26px; height: 26px; fill: currentColor; display: block; }
.time { font-size: .9rem; font-variant-numeric: tabular-nums; margin: 0 8px; white-space: nowrap; }

.seek { position: relative; height: 18px; cursor: pointer; touch-action: none; margin: 0 6px; }
.seek .track {
  position: absolute; left: 0; right: 0; top: 7px; height: 4px; border-radius: 2px;
  background: rgba(255, 255, 255, .25); overflow: hidden; transition: height .1s, top .1s;
}
.seek:hover .track { top: 6px; height: 6px; }
.seek .buf, .seek .played { position: absolute; left: 0; top: 0; bottom: 0; width: 0; }
.seek .buf { background: rgba(255, 255, 255, .4); }
.seek .played { background: var(--accent); }
.seek .knob {
  position: absolute; top: 3px; width: 13px; height: 13px; margin-left: -6.5px; border-radius: 50%;
  background: var(--accent); transform: scale(0); transition: transform .1s;
}
.seek:hover .knob { transform: scale(1); }

.vol {
  --v: 100%;
  -webkit-appearance: none; appearance: none; width: 80px; height: 4px; padding: 0; margin: 0 4px;
  border: 0; border-radius: 2px; background: linear-gradient(to right, #fff var(--v), rgba(255, 255, 255, .3) var(--v));
  cursor: pointer;
}
.vol:focus { outline: none; }
.vol::-webkit-slider-thumb { -webkit-appearance: none; width: 12px; height: 12px; border-radius: 50%; background: #fff; }
.vol::-moz-range-thumb { width: 12px; height: 12px; border: 0; border-radius: 50%; background: #fff; }

.stage button.big-play {
  position: absolute; top: 50%; left: 50%; transform: translate(-50%, -50%); z-index: 6;
  width: 76px; height: 76px; border-radius: 50%; padding: 0;
  background: rgba(0, 0, 0, .55); color: #fff; border: 0; transition: opacity .2s, background .15s;
}
.stage button.big-play:hover { background: var(--accent); }
.big-play svg { width: 38px; height: 38px; fill: currentColor; margin-left: 4px; }
.stage:not(.paused) .big-play { opacity: 0; pointer-events: none; }

.spinner {
  position: absolute; top: 50%; left: 50%; width: 48px; height: 48px; margin: -24px 0 0 -24px; z-index: 6;
  border: 4px solid rgba(255, 255, 255, .25); border-top-color: #fff; border-radius: 50%;
  animation: spin .8s linear infinite; pointer-events: none;
}
@keyframes spin { to { transform: rotate(360deg); } }

@media (max-width: 560px) {
  .vol { display: none; }
  .ctl svg { width: 24px; height: 24px; }
  .time { font-size: .8rem; margin: 0 4px; }
}
.notice { margin-top: 12px; }

/* ---------- admin ---------- */
.admin { max-width: 1100px; margin: 0 auto; padding: 20px 16px 60px; }
.tabs { display: flex; gap: 8px; margin: 16px 0; flex-wrap: wrap; }
.tabs button { background: transparent; color: var(--muted); border: 1px solid var(--line); }
.tabs button.active { background: var(--panel-2); color: var(--text); border-color: var(--accent); }
.panel { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 20px; margin-bottom: 16px; }
.grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 0 16px; }
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: .92rem; }
th, td { text-align: right; padding: 10px 8px; border-bottom: 1px solid var(--line); vertical-align: middle; }
th { color: var(--muted); font-weight: 500; white-space: nowrap; }
td.code { font-family: ui-monospace, Consolas, monospace; direction: ltr; text-align: right; white-space: nowrap; }
.actions { display: flex; gap: 6px; flex-wrap: wrap; }
.badge { display: inline-block; padding: 2px 8px; border-radius: 999px; font-size: .78rem; font-weight: 600; white-space: nowrap; }
.badge.ok { background: #143327; color: var(--ok); }
.badge.bad { background: #3a1a1a; color: var(--danger); }
.badge.warn { background: #3a2d13; color: var(--warn); }
.progress { height: 10px; background: var(--panel-2); border-radius: 999px; overflow: hidden; margin-top: 12px; }
.progress > div { height: 100%; width: 0; background: var(--accent); transition: width .2s; }
.row { display: flex; gap: 10px; align-items: end; flex-wrap: wrap; }
.row > * { flex: 1 1 200px; }
.row > button { flex: 0 0 auto; }
.usage-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(250px, 1fr)); gap: 12px; margin-top: 12px; }
.ucard { background: var(--panel-2); border-radius: 10px; padding: 14px; display: flex; flex-direction: column; gap: 6px; }
.ucard-head { display: flex; justify-content: space-between; align-items: center; gap: 8px; flex-wrap: wrap; }
.ucard-num { font-size: 1.15rem; font-weight: 600; font-variant-numeric: tabular-nums; }
.ucard-num .muted { font-size: .85rem; font-weight: 400; }
.ubar { height: 8px; background: var(--bg); border-radius: 999px; overflow: hidden; }
.ubar > i { display: block; height: 100%; border-radius: 999px; }
.ubar.ok > i { background: var(--ok); }
.ubar.warn > i { background: var(--warn); }
.ubar.bad > i { background: var(--danger); }
.usage-more { margin-top: 16px; }
.usage-more summary { cursor: pointer; color: var(--muted); }
.usage-banner { border-color: var(--warn); color: var(--warn); }
.pw-wrap { display: flex; gap: 8px; }
.pw-wrap input { flex: 1; }
.stats { display: flex; gap: 12px; margin-top: 16px; flex-wrap: wrap; }
.stats > div { background: var(--panel-2); border-radius: 8px; padding: 10px 16px; min-width: 120px; }
.stats b { display: block; font-size: 1.4rem; }
.stats span { color: var(--muted); font-size: .85rem; }
.bar { display: inline-block; width: 60px; height: 6px; background: var(--panel-2); border-radius: 999px; overflow: hidden; vertical-align: middle; }
.bar > i { display: block; height: 100%; background: var(--ok); }
code.k { background: var(--panel-2); padding: 1px 6px; border-radius: 4px; }
.toast {
  position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%);
  background: var(--panel-2); border: 1px solid var(--line); padding: 10px 18px; border-radius: 8px; z-index: 2000;
}
