:root {
  color-scheme: light;
  --bg: #f5f7fb;
  --surface: #ffffff;
  --surface-strong: #eef3f8;
  --ink: #16202e;
  --muted: #687385;
  --line: #dbe3ec;
  --primary: #0d7c86;
  --primary-strong: #095f66;
  --accent: #e5b736;
  --danger: #c04747;
  --success: #2e8b57;
  --shadow: 0 20px 60px rgba(34, 47, 70, 0.12);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  color: var(--ink);
  background:
    radial-gradient(circle at top left, rgba(13, 124, 134, 0.14), transparent 30rem),
    linear-gradient(135deg, #f8fafc 0%, var(--bg) 48%, #edf4f1 100%);
}

button,
input,
select {
  font: inherit;
}

button,
a {
  -webkit-tap-highlight-color: transparent;
}

a {
  color: inherit;
  text-decoration: none;
}

.app-shell {
  min-height: 100vh;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  width: min(1180px, calc(100vw - 2rem));
  margin: 0 auto;
  padding: 1.1rem 0;
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: 0.75rem;
}

.brand-mark {
  display: grid;
  place-items: center;
  width: 2.75rem;
  height: 2.75rem;
  border-radius: 0.55rem;
  color: #ffffff;
  background: linear-gradient(135deg, var(--primary), #183b59);
  font-weight: 800;
}

.brand strong,
.brand small {
  display: block;
  line-height: 1.1;
}

.brand small {
  color: var(--muted);
  margin-top: 0.15rem;
}

.top-actions {
  display: flex;
  align-items: center;
  gap: 0.55rem;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.top-actions a,
.ghost,
.primary,
.danger-button,
.download-link,
.icon-button {
  border: 1px solid transparent;
  border-radius: 0.5rem;
  cursor: pointer;
  min-height: 2.55rem;
  transition: transform 160ms ease, border-color 160ms ease, background 160ms ease, color 160ms ease;
}

.top-actions a {
  display: inline-flex;
  align-items: center;
  padding: 0 0.85rem;
  color: var(--muted);
}

.top-actions a.active {
  color: var(--ink);
  background: var(--surface);
  box-shadow: 0 8px 24px rgba(34, 47, 70, 0.08);
}

.ghost,
.download-link {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0 0.9rem;
  color: var(--ink);
  background: var(--surface);
  border-color: var(--line);
}

.primary {
  padding: 0 1.05rem;
  color: #ffffff;
  background: var(--primary);
  border-color: var(--primary);
  font-weight: 700;
}

.danger-button {
  padding: 0 0.9rem;
  color: #ffffff;
  background: var(--danger);
  border-color: var(--danger);
  font-weight: 700;
}

.icon-button {
  display: grid;
  place-items: center;
  width: 2.45rem;
  height: 2.45rem;
  padding: 0;
  color: var(--muted);
  background: var(--surface);
  border-color: var(--line);
  font-size: 1.4rem;
  line-height: 1;
}

.primary:hover,
.ghost:hover,
.danger-button:hover,
.download-link:hover,
.icon-button:hover {
  transform: translateY(-1px);
}

.primary:disabled,
.danger-button:disabled {
  cursor: not-allowed;
  opacity: 0.45;
  transform: none;
}

.small-button {
  min-height: 2.15rem;
  padding: 0 0.65rem;
  font-size: 0.9rem;
}

.view-root {
  width: min(1180px, calc(100vw - 2rem));
  margin: 0 auto;
  padding: 1rem 0 4rem;
}

.split-view {
  display: grid;
  grid-template-columns: minmax(18rem, 0.85fr) minmax(18rem, 1.15fr);
  gap: 1rem;
  min-height: calc(100vh - 7.5rem);
}

.login-panel,
.stage-panel,
.tool-panel,
.side-panel,
.main-panel,
.stat-card {
  background: rgba(255, 255, 255, 0.88);
  border: 1px solid rgba(219, 227, 236, 0.9);
  box-shadow: var(--shadow);
  backdrop-filter: blur(18px);
}

.login-panel {
  align-self: center;
  padding: clamp(1.4rem, 3vw, 2.6rem);
  border-radius: 0.7rem;
}

.login-panel.compact {
  width: min(28rem, 100%);
}

.login-panel h1,
.section-heading h1,
.tool-panel h2,
.side-panel h2 {
  margin: 0;
  letter-spacing: 0;
}

.login-panel h1 {
  font-size: clamp(2.4rem, 6vw, 4.8rem);
  line-height: 0.95;
}

.eyebrow {
  margin: 0 0 0.5rem;
  color: var(--primary-strong);
  font-size: 0.78rem;
  font-weight: 800;
  letter-spacing: 0.12em;
  text-transform: uppercase;
}

.form-grid {
  display: grid;
  gap: 1rem;
  margin-top: 2rem;
}

label {
  display: grid;
  gap: 0.45rem;
  color: var(--muted);
  font-weight: 700;
}

input,
select {
  width: 100%;
  min-height: 2.9rem;
  padding: 0 0.85rem;
  color: var(--ink);
  background: #ffffff;
  border: 1px solid var(--line);
  border-radius: 0.5rem;
  outline: none;
}

input:focus,
select:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(13, 124, 134, 0.14);
}

.stage-panel {
  position: relative;
  display: grid;
  align-content: end;
  min-height: 35rem;
  overflow: hidden;
  padding: 2rem;
  border-radius: 0.7rem;
  background:
    linear-gradient(160deg, rgba(15, 32, 46, 0.88), rgba(13, 124, 134, 0.62)),
    url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='900' height='700' viewBox='0 0 900 700'%3E%3Cg fill='none' stroke='%23ffffff' stroke-opacity='.16'%3E%3Cpath d='M80 530c80-120 162-194 286-194 154 0 203-160 360-160 55 0 93 16 124 38'/%3E%3Cpath d='M20 390c126-78 196-90 313-34 142 68 249-60 364-92 62-17 111-9 160 18'/%3E%3Cpath d='M114 172c89 27 150 85 262 71 121-16 177-104 296-99 73 3 129 41 172 88'/%3E%3C/g%3E%3C/svg%3E");
  background-size: cover;
}

.pulse-disc {
  position: absolute;
  top: 10%;
  left: 13%;
  width: min(32rem, 70vw);
  aspect-ratio: 1;
  border-radius: 50%;
  background:
    radial-gradient(circle, rgba(255, 255, 255, 0.22) 0 14%, transparent 15%),
    repeating-radial-gradient(circle, rgba(255,255,255,.18) 0 2px, transparent 3px 22px);
  opacity: 0.9;
}

.pulse-disc span {
  position: absolute;
  inset: 30%;
  border-radius: 50%;
  border: 2px solid rgba(255,255,255,.42);
}

.pulse-disc span:nth-child(2) {
  inset: 20%;
}

.pulse-disc span:nth-child(3) {
  inset: 10%;
}

.stage-copy {
  position: relative;
  display: grid;
  gap: 0.35rem;
  color: #ffffff;
  font-size: 1.1rem;
}

.stage-copy strong {
  font-size: clamp(1.8rem, 5vw, 3.6rem);
  line-height: 1;
}

.workspace,
.admin-grid {
  display: grid;
  grid-template-columns: 22rem minmax(0, 1fr);
  gap: 1rem;
  align-items: start;
}

.side-panel,
.main-panel,
.tool-panel {
  border-radius: 0.7rem;
  padding: 1.25rem;
}

.side-panel {
  position: sticky;
  top: 1rem;
  display: grid;
  gap: 1.2rem;
}

.section-heading,
.panel-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  margin-bottom: 1rem;
}

.section-heading h1 {
  font-size: clamp(2rem, 5vw, 3.3rem);
  line-height: 1;
}

.search-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 0.65rem;
}

.song-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(18rem, 1fr));
  gap: 0.75rem;
  margin-top: 1rem;
}

.compact-grid {
  grid-template-columns: repeat(auto-fill, minmax(16rem, 1fr));
}

.song-card,
.selected-song,
.table-row {
  display: grid;
  align-items: center;
  gap: 0.75rem;
  padding: 0.75rem;
  border: 1px solid var(--line);
  border-radius: 0.55rem;
  background: #ffffff;
}

.song-card {
  grid-template-columns: 4rem minmax(0, 1fr) auto;
}

.song-card img,
.selected-song img,
.fallback-cover {
  width: 4rem;
  height: 4rem;
  border-radius: 0.45rem;
  object-fit: cover;
}

.fallback-cover {
  display: grid;
  place-items: center;
  color: #ffffff;
  background: linear-gradient(135deg, #183b59, var(--primary));
  font-weight: 900;
}

.song-meta,
.selected-song div {
  min-width: 0;
  display: grid;
  gap: 0.18rem;
}

.song-meta strong,
.song-meta span,
.song-meta small,
.selected-song strong,
.selected-song span,
.selected-song small {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.song-meta span,
.selected-song span,
.muted {
  color: var(--muted);
}

.song-meta small,
.selected-song small {
  color: #8a94a3;
}

.pill-row {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem;
  margin-top: 0.25rem;
}

.pill,
.status-badge {
  display: inline-flex;
  align-items: center;
  min-height: 1.45rem;
  padding: 0 0.45rem;
  border-radius: 99rem;
  color: var(--primary-strong);
  background: rgba(13, 124, 134, 0.1);
  font-size: 0.75rem;
  font-weight: 800;
}

.status-badge {
  border-radius: 0.5rem;
  line-height: 1.25;
  padding: 0.35rem 0.6rem;
}

.explicit-mark {
  display: inline-flex;
  align-items: center;
  color: var(--ink);
  font-size: 0.9em;
  line-height: 1;
  vertical-align: -0.06em;
}

.danger,
.danger[data-tone],
.message[data-tone="error"] {
  color: var(--danger);
}

.pill.danger {
  color: #8d2929;
  background: rgba(192, 71, 71, 0.12);
}

.muted-pill {
  color: var(--muted);
  background: var(--surface-strong);
}

.message {
  min-height: 1.3rem;
  margin: 0.8rem 0 0;
  color: var(--danger);
  font-weight: 700;
}

.message[data-tone="success"] {
  color: var(--success);
}

.message[data-tone="info"] {
  color: var(--muted);
}

.meter {
  display: grid;
  gap: 0.45rem;
  color: var(--muted);
  font-weight: 800;
}

.meter div {
  height: 0.55rem;
  overflow: hidden;
  border-radius: 99rem;
  background: var(--surface-strong);
}

.meter i {
  display: block;
  width: 0;
  height: 100%;
  border-radius: inherit;
  background: linear-gradient(90deg, var(--primary), var(--accent));
}

.selected-list {
  display: grid;
  gap: 0.65rem;
}

.top-panel {
  display: grid;
  gap: 0.7rem;
  padding-top: 0.4rem;
  border-top: 1px solid var(--line);
}

.mini-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.6rem;
}

.top-list {
  display: grid;
  gap: 0.45rem;
}

.top-song {
  display: grid;
  grid-template-columns: 2rem minmax(0, 1fr) auto;
  align-items: center;
  gap: 0.55rem;
  padding: 0.55rem;
  border: 1px solid var(--line);
  border-radius: 0.5rem;
  background: #ffffff;
}

.top-song div {
  min-width: 0;
  display: grid;
  gap: 0.12rem;
}

.top-song strong,
.top-song small {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.top-song small {
  color: var(--muted);
}

.selected-song {
  grid-template-columns: 3.4rem minmax(0, 1fr) auto;
}

.selected-song img,
.selected-song .fallback-cover {
  width: 3.4rem;
  height: 3.4rem;
}

.admin-login {
  display: grid;
  place-items: center;
  min-height: calc(100vh - 8rem);
}

.admin-workspace {
  display: grid;
  gap: 1rem;
}

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

.stat-card {
  display: grid;
  gap: 0.25rem;
  padding: 1rem;
  border-radius: 0.7rem;
}

.stat-card span {
  color: var(--muted);
  font-weight: 800;
}

.stat-card strong {
  font-size: 2rem;
}

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

.class-generator {
  display: grid;
  gap: 0.75rem;
}

#classRows {
  display: grid;
  gap: 0.55rem;
}

.class-row {
  display: grid;
  grid-template-columns: minmax(8rem, 1fr) 7rem 6rem auto;
  gap: 0.5rem;
}

.button-row {
  display: flex;
  gap: 0.6rem;
  align-items: center;
  flex-wrap: wrap;
}

.table-list {
  display: grid;
  gap: 0.55rem;
  margin-top: 1rem;
}

.table-row {
  grid-template-columns: minmax(8rem, 1fr) auto auto auto auto auto;
}

.class-admin-card {
  display: grid;
  grid-template-columns: minmax(8rem, 1fr) 7rem auto;
  align-items: center;
  gap: 0.75rem;
  padding: 0.75rem;
  border: 1px solid var(--line);
  border-radius: 0.55rem;
  background: #ffffff;
}

.class-summary {
  min-width: 0;
  display: grid;
  gap: 0.2rem;
}

.class-summary strong,
.class-summary span {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.class-summary span {
  color: var(--muted);
}

.inline-number {
  display: grid;
  grid-template-columns: auto minmax(3.5rem, 4.5rem);
  align-items: center;
  gap: 0.45rem;
}

.inline-number span {
  font-size: 0.85rem;
}

.inline-number input {
  min-height: 2.15rem;
}

.class-actions,
.card-actions {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 0.45rem;
  flex-wrap: wrap;
}

.card-actions {
  flex-direction: column;
  align-items: stretch;
}

.table-row input {
  width: 5rem;
  min-height: 2.35rem;
}

.rank {
  display: grid;
  place-items: center;
  width: 2rem;
  height: 2rem;
  border-radius: 0.45rem;
  color: #ffffff;
  background: var(--primary);
  font-weight: 900;
}

.switch {
  display: inline-flex;
  grid-template-columns: none;
  align-items: center;
  gap: 0.45rem;
  color: var(--ink);
}

.switch input {
  width: 1.15rem;
  height: 1.15rem;
  min-height: auto;
  accent-color: var(--primary);
}

.warning {
  padding: 0.85rem 1rem;
  border: 1px solid rgba(192, 71, 71, 0.28);
  border-radius: 0.55rem;
  color: #8d2929;
  background: rgba(192, 71, 71, 0.1);
  font-weight: 800;
}

.empty {
  margin: 0;
  padding: 0.5rem 0;
}

.hidden {
  display: none !important;
}

@media (max-width: 920px) {
  .split-view,
  .workspace,
  .admin-grid {
    grid-template-columns: 1fr;
  }

  .side-panel {
    position: static;
  }

  .stat-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .stage-panel {
    min-height: 22rem;
  }
}

@media (max-width: 640px) {
  .topbar,
  .section-heading,
  .panel-heading {
    align-items: stretch;
    flex-direction: column;
  }

  .top-actions {
    justify-content: flex-start;
  }

  .search-row,
  .class-row,
  .class-admin-card,
  .song-card,
  .table-row {
    grid-template-columns: 1fr;
  }

  .class-actions,
  .card-actions {
    justify-content: flex-start;
  }

  .song-card {
    align-items: stretch;
  }

  .song-card img,
  .song-card .fallback-cover {
    width: 100%;
    height: auto;
    aspect-ratio: 1.8;
  }

  .stat-grid {
    grid-template-columns: 1fr;
  }

  .view-root {
    width: min(100vw - 1rem, 1180px);
  }
}
