:root {
  --bg: #0d1117;
  --bg-soft: #131a23;
  --panel: #161d27;
  --line: #253041;
  --text: #e8eef7;
  --muted: #94a3b6;
  --accent: #4c97ff;
  --accent-2: #ff8c1a;
  --good: #3ecf8e;
  --bad: #ff6b6b;
  --radius: 12px;
  --shadow: 0 10px 30px rgba(0, 0, 0, 0.35);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.45 ui-sans-serif, system-ui, "Segoe UI", Roboto, sans-serif;
}

button, input, select, textarea { font: inherit; color: inherit; }

#app {
  height: 100%;
  display: grid;
  grid-template-rows: auto 1fr;
}

/* ------------------------------------------------------------------ top bar */

.topbar {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 14px;
  border-bottom: 1px solid var(--line);
  background: var(--bg-soft);
  flex-wrap: wrap;
}

.brand { display: flex; align-items: baseline; gap: 8px; }
.brand .logo { font-size: 22px; }
.brand .name { font-weight: 750; letter-spacing: -0.2px; }
.brand .tagline { color: var(--muted); font-size: 12px; }
.spacer { flex: 1 1 auto; }

.modes { display: flex; gap: 6px; }

.chip {
  display: inline-flex;
  flex-direction: column;
  gap: 1px;
  padding: 6px 12px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: #1b232e;
  color: var(--text);
  cursor: pointer;
  line-height: 1.15;
  transition: border-color 0.15s, background 0.15s, transform 0.1s;
}
.chip strong { font-size: 13px; font-weight: 650; }
.chip span { font-size: 11px; color: var(--muted); }
.chip:hover { border-color: #3b4a60; }
.chip:active { transform: translateY(1px); }
.chip.active {
  background: rgba(76, 151, 255, 0.16);
  border-color: rgba(76, 151, 255, 0.65);
}
.chip.active span { color: #a9c8ff; }

.badge {
  font-size: 12px;
  color: var(--muted);
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 5px 10px;
  max-width: 260px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.badge.ready { color: var(--good); border-color: rgba(62, 207, 142, 0.45); }
.badge.error { color: var(--bad); border-color: rgba(255, 107, 107, 0.45); }

button.primary {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 8px 16px;
  border: 1px solid rgba(76, 151, 255, 0.6);
  border-radius: 999px;
  background: linear-gradient(180deg, #5aa2ff, #3d84ec);
  color: #06101f;
  font-weight: 700;
  cursor: pointer;
}
button.primary .dot {
  width: 9px; height: 9px; border-radius: 50%;
  background: #06101f; opacity: 0.45;
}
button.primary.live {
  background: linear-gradient(180deg, #ff8f6b, #f0603a);
  border-color: rgba(255, 140, 26, 0.7);
}
button.primary.live .dot { background: #fff; opacity: 1; animation: pulse 1.1s infinite; }

@keyframes pulse {
  0%, 100% { transform: scale(1); opacity: 1; }
  50% { transform: scale(1.6); opacity: 0.5; }
}

button.icon {
  width: 36px; height: 36px;
  display: grid; place-items: center;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: #1b232e;
  cursor: pointer;
}
button.icon:hover { border-color: #3b4a60; }

/* -------------------------------------------------------------------- layout */

main {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 340px;
  min-height: 0;
}

.stagewrap {
  display: grid;
  grid-template-rows: minmax(0, 1fr) auto auto auto;
  gap: 10px;
  padding: 14px;
  min-height: 0;
}

.stagebox {
  position: relative;
  min-height: 0;
  display: grid;
  place-items: center;
  background: #05070a;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  overflow: hidden;
  box-shadow: var(--shadow);
}

#stage {
  width: 100%;
  height: 100%;
  display: block;
  touch-action: none;
}

.hint {
  position: absolute;
  inset: auto 0 14%;
  text-align: center;
  color: #cfe0f5;
  pointer-events: none;
  text-shadow: 0 2px 12px rgba(0, 0, 0, 0.6);
  transition: opacity 0.3s;
}
.hint p { margin: 4px 0; }
.hint .muted { color: #8ea3bb; font-size: 13px; }
.hint.hidden { opacity: 0; }

.rec {
  position: absolute;
  top: 12px; right: 12px;
  padding: 4px 10px;
  border-radius: 999px;
  background: rgba(255, 60, 60, 0.9);
  color: #fff;
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.08em;
}
.rec[hidden] { display: none; }

.statusbar {
  display: flex;
  align-items: center;
  gap: 12px;
  min-height: 22px;
  font-size: 13px;
  color: var(--muted);
}
.statusbar .heard {
  flex: 1 1 auto;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  color: #b9c9dc;
}
.statusbar .timing { color: var(--good); font-variant-numeric: tabular-nums; }
.statusbar .timing.slow { color: var(--accent-2); }
.statusbar .count { white-space: nowrap; }

.typeform { display: flex; gap: 8px; }
.typeform input {
  flex: 1 1 auto;
  padding: 10px 14px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: #131a23;
}
.typeform input:focus { outline: 2px solid rgba(76, 151, 255, 0.5); border-color: transparent; }

.stageactions {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
}
.stageactions button {
  padding: 7px 12px;
  border: 1px solid var(--line);
  border-radius: 9px;
  background: #1b232e;
  cursor: pointer;
  font-size: 13px;
}
.stageactions button:hover { border-color: #3b4a60; }
.stageactions button.on { border-color: rgba(255, 140, 26, 0.7); color: #ffd7ad; }

.toggle {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 13px;
  color: var(--muted);
  user-select: none;
}

/* --------------------------------------------------------------------- panel */

.panel {
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  border-left: 1px solid var(--line);
  background: var(--panel);
  min-height: 0;
}

.tabs { display: flex; border-bottom: 1px solid var(--line); }
.tab {
  flex: 1 1 0;
  padding: 12px 8px;
  border: 0;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  font-weight: 600;
  border-bottom: 2px solid transparent;
}
.tab.active { color: var(--text); border-bottom-color: var(--accent); }

.tabbody { overflow-y: auto; min-height: 0; }
.tabpane { display: none; padding: 14px; }
.tabpane.active { display: block; }

.panel h3 {
  margin: 18px 0 8px;
  font-size: 12px;
  letter-spacing: 0.09em;
  text-transform: uppercase;
  color: var(--muted);
}

.field { display: grid; gap: 5px; margin-bottom: 10px; font-size: 13px; }
.field > span { color: var(--muted); }
.field em { font-style: normal; opacity: 0.7; }
.field input, .field select, .field textarea {
  padding: 8px 10px;
  border: 1px solid var(--line);
  border-radius: 9px;
  background: #111823;
  width: 100%;
}
.field textarea { resize: vertical; }
.field input:focus, .field select:focus, .field textarea:focus {
  outline: 2px solid rgba(76, 151, 255, 0.45);
  border-color: transparent;
}

.hint-sm { color: var(--muted); font-size: 12px; margin: 8px 0 0; }

/* ------------------------------------------------------------------- assets */

.packs { display: grid; gap: 12px; }
.pack h4 {
  margin: 0 0 6px;
  font-size: 11px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--muted);
}
.pack .grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(38px, 1fr));
  gap: 4px;
}
.asset {
  aspect-ratio: 1;
  display: grid;
  place-items: center;
  border: 1px solid transparent;
  border-radius: 8px;
  background: #1b232e;
  font-size: 20px;
  cursor: pointer;
  transition: transform 0.1s, border-color 0.15s, background 0.15s;
}
.asset:hover { background: #22303f; border-color: #3b4a60; transform: translateY(-1px); }
.asset:active { transform: scale(0.94); }
.asset.empty { grid-column: 1 / -1; background: none; border: 0; color: var(--muted); font-size: 13px; cursor: default; }

.shapes { display: flex; flex-wrap: wrap; gap: 6px; }
.shapes .asset { width: 42px; aspect-ratio: 1; font-size: 18px; color: #cfe0f5; padding: 0; }

.swatches { display: grid; grid-template-columns: repeat(auto-fill, minmax(78px, 1fr)); gap: 6px; }
.swatch {
  padding: 12px 6px 6px;
  border: 1px solid var(--line);
  border-radius: 9px;
  background: linear-gradient(to bottom, var(--a), var(--b));
  color: #10151c;
  font-size: 11px;
  font-weight: 700;
  text-shadow: 0 1px 0 rgba(255, 255, 255, 0.35);
  cursor: pointer;
  text-align: center;
}
.swatch:hover { border-color: #4b6280; }
.swatch.dark { color: #f4f8ff; text-shadow: 0 1px 3px rgba(0, 0, 0, 0.6); }

.fxrow { display: flex; flex-wrap: wrap; gap: 6px; }
.fxrow button {
  padding: 7px 10px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: #1b232e;
  font-size: 12px;
  cursor: pointer;
}
.fxrow button:hover { border-color: #4b6280; background: #22303f; }

/* ----------------------------------------------------------------- sprites */

.sprites { list-style: none; margin: 0; padding: 0; display: grid; gap: 6px; }
.sprite {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 7px 10px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: #111823;
  cursor: pointer;
}
.sprite:hover { border-color: #3b4a60; }
.sprite.selected { border-color: rgba(76, 151, 255, 0.8); background: rgba(76, 151, 255, 0.12); }
.sprite .glyph { font-size: 19px; width: 24px; text-align: center; }
.sprite .meta { flex: 1 1 auto; font-size: 12px; color: var(--muted); overflow: hidden; }
.sprite .meta b { color: var(--text); font-weight: 650; }
.sprite .kill {
  border: 0; background: none; color: var(--muted);
  font-size: 16px; cursor: pointer; line-height: 1;
}
.sprite .kill:hover { color: var(--bad); }
.empty-list { color: var(--muted); font-size: 13px; padding: 6px 0; }

/* -------------------------------------------------------------------- log */

.log {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  gap: 4px;
  max-height: 260px;
  overflow-y: auto;
  font-size: 12.5px;
}
.log li { display: flex; gap: 8px; align-items: baseline; }
.log time { color: #64748b; font-variant-numeric: tabular-nums; }
.log .bad { color: var(--bad); }
.log .meta { color: var(--muted); font-style: italic; }

.progress {
  display: flex;
  align-items: center;
  gap: 10px;
  margin: 8px 0;
  font-size: 12px;
  color: var(--muted);
}
.progress.hidden { display: none; }
.progress .track {
  flex: 1 1 auto;
  height: 6px;
  border-radius: 999px;
  background: #1b232e;
  overflow: hidden;
}
.progress .bar {
  height: 100%;
  width: 0;
  border-radius: 999px;
  background: linear-gradient(90deg, var(--accent), var(--accent-2));
  transition: width 0.25s;
}

/* ----------------------------------------------------------------- dialog */

dialog {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--panel);
  color: var(--text);
  padding: 0;
  max-width: 460px;
  width: min(92vw, 460px);
  box-shadow: var(--shadow);
}
dialog::backdrop { background: rgba(4, 7, 11, 0.7); }
.dialog { padding: 18px; display: grid; gap: 6px; }
.dialog h2 { margin: 0 0 2px; font-size: 17px; }
.dialog fieldset {
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 10px 12px 4px;
  margin: 10px 0 0;
}
.dialog legend { padding: 0 6px; font-size: 11px; color: var(--muted); text-transform: uppercase; letter-spacing: 0.08em; }
.dialog-actions { display: flex; justify-content: flex-end; margin-top: 12px; }

/* ------------------------------------------------------- presenting / full */

body.presenting .topbar,
body.presenting .panel,
body.presenting .statusbar,
body.presenting .typeform,
body.presenting .stageactions,
body.presenting .hint { display: none; }
body.presenting main { grid-template-columns: 1fr; }
body.presenting .stagewrap { padding: 0; gap: 0; grid-template-rows: 1fr; }
body.presenting .stagebox { border: 0; border-radius: 0; }

@media (max-width: 900px) {
  main { grid-template-columns: 1fr; grid-template-rows: minmax(0, 1fr) auto; }
  .panel { border-left: 0; border-top: 1px solid var(--line); max-height: 46vh; }
  .brand .tagline { display: none; }
}

@media (prefers-reduced-motion: reduce) {
  * { animation-duration: 0.001ms !important; transition-duration: 0.001ms !important; }
}
