/* Stage Manager — backstage theme
   House lights down: deep velvet background, tungsten-white type,
   amber standby / red tally / green done, borrowed from the wings. */

:root {
  --bg: #1c1a2a;
  --surface: #262437;
  --surface-2: #302d45;
  --line: #3d3a55;
  --text: #f4efe4;
  --muted: #a9a3bd;
  --standby: #f2b544;
  --live: #ff4d3d;
  --done: #6fcf97;
  --danger: #e8604f;
  --focus: #8fb8ff;

  --font-body: "Barlow", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --font-display: "Barlow Semi Condensed", "Barlow", system-ui, sans-serif;

  --radius: 6px;
  --measure: 880px;
}

* { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-body);
  font-size: 1rem;
  line-height: 1.45;
  min-height: 100dvh;
}

body.centered {
  display: grid;
  place-items: center;
  padding: 1.5rem;
}

a { color: inherit; }

h1, h2, h3 { font-family: var(--font-display); margin: 0; line-height: 1.1; }

:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; }

/* ---------- header ---------- */

.top {
  position: sticky;
  top: 0;
  z-index: 10;
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--line);
}

.top-inner {
  max-width: var(--measure);
  margin: 0 auto;
  padding: 0.6rem 1rem;
  display: flex;
  align-items: center;
  gap: 1rem;
  flex-wrap: wrap;
}

.brand {
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 1.15rem;
  text-decoration: none;
  letter-spacing: 0.01em;
}

.nav {
  display: flex;
  gap: 0.15rem;
  flex-wrap: wrap;
  margin-right: auto;
}

.nav a {
  text-decoration: none;
  color: var(--muted);
  padding: 0.35rem 0.6rem;
  border-radius: var(--radius);
  font-weight: 500;
}

.nav a:hover { color: var(--text); background: var(--surface); }
.nav a[aria-current="page"] { color: var(--text); background: var(--surface-2); }

.logout { margin: 0; }

.progress {
  height: 3px;
  background: var(--surface-2);
}

.progress span {
  display: block;
  height: 100%;
  width: 0;
  background: var(--done);
  transition: width 0.4s ease;
}

/* ---------- board ---------- */

.board {
  max-width: var(--measure);
  margin: 0 auto;
  padding: 1rem 1rem 6rem;
}

.board-bar {
  display: flex;
  align-items: baseline;
  gap: 0.75rem 1rem;
  flex-wrap: wrap;
  margin: 0.5rem 0 1rem;
}

.board-title { font-size: 1.75rem; font-weight: 600; }
.board-count { margin: 0; color: var(--muted); }
.board-actions { margin-left: auto; display: flex; gap: 0.5rem; flex-wrap: wrap; }

.acts {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  gap: 0.5rem;
}

.act {
  display: grid;
  grid-template-columns: auto 1fr auto;
  gap: 0.25rem 1rem;
  align-items: center;
  padding: 0.85rem 1rem 0.85rem 0.9rem;
  background: var(--surface);
  border: 1px solid var(--line);
  border-left: 5px solid var(--line);
  border-radius: var(--radius);
  transition: opacity 0.25s ease, border-color 0.25s ease, box-shadow 0.25s ease;
}

.act-num {
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 1.6rem;
  font-variant-numeric: tabular-nums;
  color: var(--muted);
  min-width: 2ch;
  text-align: right;
  line-height: 1;
}

.act-body { min-width: 0; }

.act-title {
  font-size: 1.25rem;
  font-weight: 600;
  overflow-wrap: anywhere;
}

.act-desc {
  margin: 0.1rem 0 0;
  color: var(--muted);
}

.act-cast {
  margin: 0.3rem 0 0;
  font-size: 0.95rem;
  color: var(--muted);
}

.act-cast strong { color: var(--text); font-weight: 500; }

.act-side {
  display: grid;
  gap: 0.4rem;
  justify-items: end;
  align-content: center;
}

.status {
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--muted);
  white-space: nowrap;
}

.act-tools {
  display: flex;
  gap: 0.35rem;
  align-items: center;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.act-tools form { margin: 0; }

/* elapsed / run time next to the status */
.timer {
  font-family: var(--font-display);
  font-variant-numeric: tabular-nums;
  font-weight: 600;
  padding: 0.05rem 0.4rem;
  border-radius: 999px;
  background: color-mix(in srgb, currentColor 14%, transparent);
}
.board-count .timer { color: var(--live); font-size: 1rem; }

/* status styling: the left rule carries the state, like a cue light */

.act[data-status="Ready"] {
  border-left-color: var(--standby);
}
.act[data-status="Ready"] .status,
.act[data-status="Ready"] .act-num { color: var(--standby); }

.act[data-status="On Stage"] {
  border-left-color: var(--live);
  border-color: color-mix(in srgb, var(--live) 45%, var(--line));
  background: color-mix(in srgb, var(--live) 9%, var(--surface));
  box-shadow: 0 0 0 1px color-mix(in srgb, var(--live) 30%, transparent),
              0 0 28px color-mix(in srgb, var(--live) 28%, transparent);
  animation: tally 2.4s ease-in-out infinite;
}
.act[data-status="On Stage"] .status,
.act[data-status="On Stage"] .act-num { color: var(--live); }

@keyframes tally {
  0%, 100% { box-shadow: 0 0 0 1px color-mix(in srgb, var(--live) 30%, transparent), 0 0 18px color-mix(in srgb, var(--live) 22%, transparent); }
  50%      { box-shadow: 0 0 0 1px color-mix(in srgb, var(--live) 50%, transparent), 0 0 40px color-mix(in srgb, var(--live) 40%, transparent); }
}

.act[data-status="Complete"] {
  opacity: 0.45;
  border-left-color: var(--done);
}
.act[data-status="Complete"] .status { color: var(--done); }
.act[data-status="Complete"] .act-title { text-decoration: line-through; text-decoration-color: var(--muted); }

.board:not([data-show-complete]) .act[data-status="Complete"] { display: none; }

/* costumes view: cast becomes a two-column sheet */

.cast-sheet {
  margin: 0.5rem 0 0;
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  gap: 0.15rem 1rem;
  font-size: 0.95rem;
}
.cast-sheet dt { margin: 0; color: var(--text); }
.cast-sheet dd { margin: 0; color: var(--muted); }
.cast-sheet dd:empty::before { content: "—"; color: var(--line); }

/* ---------- buttons ---------- */

.btn {
  font: inherit;
  font-weight: 600;
  font-family: var(--font-display);
  letter-spacing: 0.01em;
  color: var(--text);
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 0.55rem 1rem;
  cursor: pointer;
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.4rem;
  line-height: 1.1;
  min-height: 2.5rem;
  transition: background 0.15s ease, transform 0.05s ease;
}

.btn:hover { background: var(--line); }
.btn:active { transform: translateY(1px); }
.btn[disabled] { opacity: 0.5; cursor: default; }

.btn-sm { padding: 0.35rem 0.7rem; min-height: 2rem; font-size: 0.9rem; }
.btn-lg { padding: 0.75rem 1.4rem; font-size: 1.1rem; min-height: 3rem; }
.btn-icon { width: 2rem; padding: 0; min-height: 2rem; font-size: 1rem; }

.btn-quiet { background: transparent; }
.btn-quiet:hover { background: var(--surface-2); }

.btn-primary { background: var(--text); color: var(--bg); border-color: var(--text); }
.btn-primary:hover { background: #fff; }

.btn-danger { background: transparent; color: var(--danger); border-color: color-mix(in srgb, var(--danger) 45%, var(--line)); }
.btn-danger:hover { background: color-mix(in srgb, var(--danger) 15%, transparent); }

/* the advance button is coloured by the state it will set */
.btn-advance { min-width: 7.5rem; min-height: 2.75rem; font-size: 1.05rem; }
.btn-advance[data-next="Ready"]    { background: var(--standby); color: #2a1e00; border-color: var(--standby); }
.btn-advance[data-next="On Stage"] { background: var(--live);    color: #fff;    border-color: var(--live); }
.btn-advance[data-next="Complete"] { background: var(--done);    color: #06301a; border-color: var(--done); }
.btn-advance:hover { filter: brightness(1.08); }

/* ---------- manage ---------- */

.acts-manage .act { grid-template-columns: auto auto 1fr auto; cursor: grab; }
.acts-manage .act:active { cursor: grabbing; }
.acts-manage .act.dragging { opacity: 0.4; }
.acts-manage .act.drop-before { box-shadow: 0 -3px 0 0 var(--standby); }
.acts-manage .act.drop-after  { box-shadow: 0  3px 0 0 var(--standby); }

.act-handle {
  color: var(--muted);
  letter-spacing: -0.15em;
  font-size: 1.1rem;
  user-select: none;
}

/* ---------- forms ---------- */

label, legend {
  display: block;
  font-weight: 600;
  font-family: var(--font-display);
  margin: 1rem 0 0.35rem;
}

.hint { color: var(--muted); font-weight: 400; font-family: var(--font-body); font-size: 0.9rem; }

input[type="text"], input[type="password"], input[type="date"], select, textarea {
  font: inherit;
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 0.6rem 0.75rem;
  width: 100%;
  min-height: 2.75rem;
}

input:focus { border-color: var(--focus); outline: none; box-shadow: 0 0 0 3px color-mix(in srgb, var(--focus) 30%, transparent); }

.act-form { max-width: 640px; }

.cast-fieldset { border: 0; padding: 0; margin: 0.5rem 0 0; }
.cast-fieldset legend { padding: 0; }

.cast-rows { display: grid; gap: 0.5rem; margin-bottom: 0.6rem; }

.cast-head, .cast-row {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr 2rem;
  gap: 0.5rem;
  align-items: center;
}
.cast-head { color: var(--muted); font-size: 0.85rem; margin-bottom: 0.25rem; }

textarea { resize: vertical; line-height: 1.4; }
select { appearance: auto; }

.check { display: flex; gap: 0.6rem; align-items: center; font-weight: 400; font-family: var(--font-body); margin: 0.5rem 0; }
.check input { width: 1.1rem; height: 1.1rem; accent-color: var(--standby); }

.act-notes {
  margin: 0.4rem 0 0;
  font-size: 0.95rem;
  color: var(--text);
  padding-left: 0.6rem;
  border-left: 2px solid var(--standby);
  white-space: pre-wrap;
}

.form-actions { display: flex; gap: 0.75rem; margin-top: 1.5rem; flex-wrap: wrap; }

.form-error {
  margin: 0.75rem 0 0;
  padding: 0.6rem 0.8rem;
  border-radius: var(--radius);
  background: color-mix(in srgb, var(--danger) 18%, transparent);
  border: 1px solid color-mix(in srgb, var(--danger) 50%, transparent);
}

/* ---------- login ---------- */

.login {
  width: min(100%, 360px);
  text-align: center;
}

.login-lamp {
  width: 14px;
  height: 14px;
  border-radius: 50%;
  margin: 0 auto 1.25rem;
  background: var(--live);
  box-shadow: 0 0 24px var(--live), 0 0 60px color-mix(in srgb, var(--live) 40%, transparent);
  animation: tally-dot 2.4s ease-in-out infinite;
}

@keyframes tally-dot {
  0%, 100% { box-shadow: 0 0 18px var(--live), 0 0 40px color-mix(in srgb, var(--live) 30%, transparent); }
  50%      { box-shadow: 0 0 30px var(--live), 0 0 80px color-mix(in srgb, var(--live) 50%, transparent); }
}

.login-title { font-size: 2.25rem; font-weight: 700; }
.login-sub { color: var(--muted); margin: 0.35rem 0 1.75rem; }
.login-form { text-align: left; display: grid; }
.login-form label { margin-top: 0; }
.login-form .btn { margin-top: 1rem; }

/* ---------- misc ---------- */

.empty {
  color: var(--muted);
  text-align: center;
  padding: 3rem 1rem;
}

.toast {
  position: fixed;
  left: 50%;
  bottom: 1.25rem;
  transform: translateX(-50%);
  background: var(--text);
  color: var(--bg);
  padding: 0.6rem 1rem;
  border-radius: var(--radius);
  font-weight: 600;
  z-index: 20;
  max-width: calc(100vw - 2rem);
}

.toast[data-kind="error"] { background: var(--danger); color: #fff; }

/* ---------- small screens ---------- */

/* ---------- dashboard ---------- */

.crumb { color: var(--line); font-size: 1.2rem; }
.show-name { font-family: var(--font-display); font-weight: 600; color: var(--muted); }

.shows { list-style: none; margin: 0; padding: 0; display: grid; gap: 0.5rem; }

.show-card {
  display: flex;
  align-items: center;
  gap: 1rem;
  flex-wrap: wrap;
  padding: 0.9rem 1rem;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
}
.shows-archived .show-card { opacity: 0.7; }
.show-main { flex: 1 1 14rem; min-width: 0; }
.show-title { font-size: 1.3rem; font-weight: 600; }
.show-title a { text-decoration: none; }
.show-title a:hover { text-decoration: underline; }
.show-meta { margin: 0.15rem 0 0; color: var(--muted); font-size: 0.95rem; }
.show-tools { display: flex; gap: 0.35rem; flex-wrap: wrap; }
.show-tools form { margin: 0; }
.section-title { font-size: 1.2rem; color: var(--muted); font-weight: 600; margin: 2rem 0 0.75rem; }

/* ---------- import picker ---------- */

.import-form { margin-top: 1rem; }
.import-hint { margin: 0 0 0.75rem; }
.select-all { margin-bottom: 0.5rem; }
.acts-pick .act { padding: 0; }
.pick {
  display: grid;
  grid-template-columns: auto auto 1fr;
  gap: 0.25rem 1rem;
  align-items: center;
  padding: 0.75rem 1rem;
  margin: 0;
  cursor: pointer;
  font-weight: 400;
  font-family: var(--font-body);
}
.pick input { width: 1.2rem; height: 1.2rem; accent-color: var(--standby); }
.pick .act-body { display: grid; }
.pick .act-title { font-family: var(--font-display); font-size: 1.15rem; font-weight: 600; }

/* ---------- display screen ---------- */

.display-body { overflow: hidden; }

.display {
  height: 100dvh;
  display: grid;
  grid-template-rows: auto 1fr;
  padding: 1.25rem 1.5rem 1.5rem;
  gap: 1rem;
}

.display-top { display: flex; align-items: baseline; gap: 1rem; flex-wrap: wrap; }
.display-show { font-size: clamp(1.5rem, 2.5vw, 2.5rem); font-weight: 700; }
.display-count { margin: 0; color: var(--muted); font-size: clamp(1rem, 1.4vw, 1.4rem); }
.display-tools { margin-left: auto; display: flex; gap: 0.35rem; opacity: 0.35; transition: opacity 0.2s; }
.display-tools:hover, .display-tools:focus-within { opacity: 1; }
.display-tools .is-on { background: var(--surface-2); }

.display-grid {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  gap: clamp(0.6rem, 1.2vw, 1.25rem);
  min-height: 0;
}
.display-grid[data-cards="4"] { grid-template-columns: repeat(4, 1fr); grid-template-rows: 1fr; }
.display-grid[data-cards="6"] { grid-template-columns: repeat(3, 1fr); grid-template-rows: repeat(2, 1fr); }
.display-grid[data-cards="8"] { grid-template-columns: repeat(4, 1fr); grid-template-rows: repeat(2, 1fr); }

.dcard {
  display: flex;
  flex-direction: column;
  min-height: 0;
  padding: clamp(0.8rem, 1.6vw, 1.6rem);
  background: var(--surface);
  border: 1px solid var(--line);
  border-top: 6px solid var(--line);
  border-radius: 10px;
  overflow: hidden;
  --fs: clamp(1rem, 1.6vw, 1.7rem);
  font-size: var(--fs);
}
.dcard-blank { background: transparent; border-style: dashed; border-top-width: 1px; color: var(--muted); align-items: center; justify-content: center; font-family: var(--font-display); }

.dcard-head { display: flex; justify-content: space-between; align-items: baseline; gap: 0.5rem; color: var(--muted); }
.dcard-num { font-family: var(--font-display); font-weight: 700; font-size: 1.6em; line-height: 1; font-variant-numeric: tabular-nums; }
.dcard-status { font-family: var(--font-display); font-weight: 600; font-size: 0.9em; }

.dcard-title {
  font-size: 1.7em;
  font-weight: 700;
  line-height: 1.05;
  margin-top: 0.4em;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
  overflow-wrap: anywhere;
}
.dcard-desc, .dcard-cast {
  margin: 0.35em 0 0;
  color: var(--muted);
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}
.dcard-desc { font-size: 1em; }
.dcard-cast { font-size: 0.9em; margin-top: auto; padding-top: 0.5em; }
.dcard-timer {
  margin-top: 0.4em;
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 1.6em;
  font-variant-numeric: tabular-nums;
  color: var(--live);
}

.dcard[data-status="Ready"] { border-top-color: var(--standby); }
.dcard[data-status="Ready"] .dcard-status, .dcard[data-status="Ready"] .dcard-num { color: var(--standby); }

.dcard[data-status="On Stage"] {
  border-top-color: var(--live);
  border-color: color-mix(in srgb, var(--live) 45%, var(--line));
  border-top-color: var(--live);
  background: color-mix(in srgb, var(--live) 9%, var(--surface));
  animation: tally 2.4s ease-in-out infinite;
}
.dcard[data-status="On Stage"] .dcard-status, .dcard[data-status="On Stage"] .dcard-num { color: var(--live); }

/* cheer card shown when an act finishes */
.cheer {
  position: fixed;
  inset: auto 0 6vh 0;
  margin: 0 auto;
  width: min(80vw, 60rem);
  padding: 2rem 2.5rem;
  background: var(--text);
  color: var(--bg);
  border-radius: 14px;
  text-align: center;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.5);
  z-index: 30;
  cursor: pointer;
  animation: cheer-in 0.35s ease-out;
}
.cheer-title { margin: 0; font-family: var(--font-display); font-weight: 700; font-size: clamp(1.8rem, 3.5vw, 3.2rem); line-height: 1.1; }
.cheer-line { margin: 0.6rem 0 0; font-size: clamp(1.1rem, 1.8vw, 1.7rem); color: #4a4661; }
.cheer-line:empty { display: none; }
@keyframes cheer-in { from { transform: translateY(30px); opacity: 0; } to { transform: none; opacity: 1; } }

@media (max-width: 900px) {
  .display-grid[data-cards="4"], .display-grid[data-cards="8"] { grid-template-columns: repeat(2, 1fr); grid-template-rows: none; grid-auto-rows: 1fr; }
  .display-grid[data-cards="6"] { grid-template-columns: repeat(2, 1fr); grid-template-rows: none; grid-auto-rows: 1fr; }
}

@media (max-width: 600px) {
  .cast-head { display: none; }
  .crumb, .show-name { display: none; }
  .act { grid-template-columns: auto 1fr; }
  .act-side {
    grid-column: 1 / -1;
    grid-auto-flow: column;
    justify-content: space-between;
    align-items: center;
    width: 100%;
    margin-top: 0.4rem;
  }
  .act-tools { justify-content: flex-start; }
  .acts-manage .act { grid-template-columns: auto auto 1fr; }
  .acts-manage .act-tools { grid-column: 1 / -1; margin-top: 0.4rem; }
  .board-actions { margin-left: 0; width: 100%; }
  .cast-row { grid-template-columns: 1fr; padding-bottom: 0.5rem; border-bottom: 1px solid var(--line); }
  .cast-row .btn-icon { justify-self: end; }
}

@media (prefers-reduced-motion: reduce) {
  * { animation: none !important; transition: none !important; }
}

/* Quick-add cast buttons, driven by the show's castTags setting. */
.cast-tags {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.4rem;
  margin: 0.5rem 0 0.75rem;
}
.cast-tags-label {
  color: var(--muted);
  font-size: 0.85rem;
  margin-right: 0.15rem;
}
.cast-tag {
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 0.25rem 0.7rem;
  color: var(--text);
  font-family: var(--font-body);
  white-space: nowrap;
}
.cast-tag:hover { background: var(--surface-2); border-color: var(--muted); }

/* The hidden attribute is applied by the user-agent stylesheet, which any class
   setting `display` outranks - .btn's inline-flex silently defeated it. Restore
   it globally so `hidden` means hidden on every element, whatever its classes. */
[hidden] { display: none !important; }

/* "Install app" button: revealed by public/js/pwa.js when installable. */
.install-btn { margin-left: auto; white-space: nowrap; }
.install-hint {
  margin: 0;
  padding: 0.5rem 1rem 0.75rem;
  color: var(--muted);
  font-size: 0.9rem;
  border-top: 1px solid var(--line);
  background: var(--surface);
}
.install-hint strong { color: var(--text); }
