:root {
  --bg-image: url("assets/background-custom.jpg");
  --page: #030a21;
  --panel: rgba(6, 20, 58, 0.9);
  --panel-solid: #0a1d50;
  --soft: rgba(11, 31, 82, 0.78);
  --line: rgba(96, 165, 250, 0.26);
  --line-strong: rgba(147, 197, 253, 0.42);
  --ink: #ecf4ff;
  --muted: #9eb8df;
  --accent: #3b82f6;
  --accent-dark: #82b4ff;
  --success: #22a768;
  --danger: #ef5b5b;
  --warn: #f0b429;
  --shadow: 0 22px 54px rgba(0, 4, 20, 0.38);
}

* { box-sizing: border-box; }
html { min-height: 100%; }

body {
  min-height: 100vh;
  margin: 0;
  color: var(--ink);
  font-family: Inter, Segoe UI, Roboto, Arial, sans-serif;
  background:
    linear-gradient(90deg, rgba(3, 10, 33, 0.96), rgba(3, 14, 46, 0.9) 56%, rgba(5, 22, 65, 0.74)),
    var(--bg-image),
    var(--page);
  background-attachment: fixed;
  background-position: center;
  background-size: cover;
}

button, input, select, textarea { font: inherit; }

button {
  min-height: 40px;
  border: 1px solid var(--line-strong);
  border-radius: 8px;
  padding: 9px 13px;
  background: var(--panel-solid);
  color: var(--ink);
  font-weight: 800;
  cursor: pointer;
  transition: border-color 0.16s ease, box-shadow 0.16s ease, transform 0.16s ease, background 0.16s ease;
}

button:hover {
  border-color: rgba(191, 219, 254, 0.72);
  box-shadow: 0 8px 18px rgba(0, 4, 20, 0.24);
  transform: translateY(-1px);
}

button:active { box-shadow: none; transform: translateY(0); }
button:disabled { cursor: wait; opacity: 0.62; transform: none; }
button.primary { border-color: var(--accent); background: var(--accent); color: #ffffff; }
button.primary:hover { background: #2563eb; }
button.success { border-color: var(--success); background: var(--success); color: #ffffff; }
button.danger { border-color: var(--danger); background: var(--danger); color: #ffffff; }
button.ghost { background: transparent; }
.danger-text { color: var(--danger); }

input, select, textarea {
  width: 100%;
  border: 1px solid var(--line-strong);
  border-radius: 8px;
  padding: 10px 11px;
  background: rgba(4, 16, 47, 0.88);
  color: var(--ink);
}

select option {
  background: #071740;
  color: var(--ink);
}

input:focus, select:focus, textarea:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(36, 87, 197, 0.16);
}

textarea { line-height: 1.55; resize: vertical; }

label {
  display: grid;
  gap: 7px;
  color: #cfe0ff;
  font-size: 12px;
  font-weight: 900;
}

.app-shell {
  width: min(1560px, 100%);
  min-height: 100vh;
  margin: 0 auto;
  display: grid;
  grid-template-columns: 318px minmax(0, 1fr);
  gap: 16px;
  padding: 16px;
}

.sidebar, .main-panel, .bucket-panel, .editor-card, .review-card, .review-lists article {
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--panel);
  box-shadow: var(--shadow);
}

.sidebar {
  position: sticky;
  top: 16px;
  align-self: start;
  max-height: calc(100vh - 32px);
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto;
  gap: 12px;
  padding: 12px;
}

.brand {
  display: grid;
  grid-template-columns: 54px minmax(0, 1fr);
  align-items: center;
  gap: 11px;
  padding: 4px 4px 10px;
  border-bottom: 1px solid var(--line);
}

.brand img {
  width: 54px;
  height: 54px;
  border-radius: 8px;
  object-fit: contain;
  background: #ffffff;
}

.brand strong { display: block; font-size: 1.02rem; }
.brand span { display: block; margin-top: 2px; color: var(--muted); font-size: 0.82rem; }

.side-card {
  min-height: 0;
  display: grid;
  gap: 10px;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--soft);
}

.side-card.compact { align-self: end; }

.side-card-head, .list-head, .section-title {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.side-card-head h2, .list-head h2, .section-title h2 {
  margin: 0;
  font-size: 0.98rem;
}

.side-card-head span {
  color: var(--accent-dark);
  font-size: 0.9rem;
  font-weight: 900;
}

.queue-tools { display: grid; gap: 9px; }

.filter-tabs {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 6px;
}

.filter-tabs button {
  min-height: 34px;
  padding: 7px 8px;
  border-color: rgba(147, 197, 253, 0.25);
  background: rgba(4, 16, 47, 0.6);
  color: var(--muted);
  font-size: 0.78rem;
}

.filter-tabs button.active {
  border-color: rgba(130, 180, 255, 0.82);
  background: rgba(37, 99, 235, 0.32);
  color: var(--ink);
}

.inline-control {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 8px;
}

.queue-list {
  min-height: 240px;
  overflow: auto;
  display: grid;
  align-content: start;
  gap: 6px;
  padding-right: 2px;
}

.queue-empty {
  align-self: start;
}

.queue-item {
  width: 100%;
  display: grid;
  grid-template-columns: 52px minmax(0, 1fr) 10px;
  gap: 8px;
  align-items: center;
  border: 1px solid transparent;
  border-radius: 8px;
  padding: 8px;
  background: rgba(6, 24, 66, 0.9);
  text-align: left;
}

.queue-item:hover, .queue-item.active {
  border-color: #aac0f2;
  box-shadow: none;
  transform: none;
}

.queue-item.active { background: rgba(37, 99, 235, 0.22); }
.queue-id { color: var(--accent-dark); font-size: 0.76rem; font-weight: 900; }
.queue-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 0.86rem; font-weight: 800; }
.queue-dot { width: 10px; height: 10px; border-radius: 50%; background: #cbd5e1; }
.queue-dot.done { background: var(--success); }
.queue-dot.rejected { background: var(--danger); }

.main-panel {
  min-width: 0;
  display: grid;
  gap: 12px;
  padding: 14px;
}

.topbar {
  display: flex;
  align-items: end;
  justify-content: space-between;
  gap: 16px;
  padding: 4px 2px 2px;
}

.topbar-actions {
  display: flex;
  align-items: center;
  justify-content: end;
  gap: 10px;
  flex-wrap: wrap;
}

.connection-pill {
  display: inline-flex;
  align-items: center;
  min-height: 34px;
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 7px 11px;
  background: rgba(4, 16, 47, 0.62);
  color: var(--muted);
  font-size: 0.8rem;
  font-weight: 900;
}

.connection-pill.online {
  border-color: rgba(134, 239, 172, 0.62);
  background: rgba(20, 83, 45, 0.32);
  color: #dcfce7;
}

.connection-pill.loading {
  border-color: rgba(147, 197, 253, 0.62);
  background: rgba(30, 64, 175, 0.28);
  color: #dbeafe;
}

.connection-pill.offline {
  border-color: rgba(252, 165, 165, 0.62);
  background: rgba(127, 29, 29, 0.3);
  color: #fee2e2;
}

.eyebrow {
  margin: 0 0 4px;
  color: var(--accent-dark);
  font-size: 0.76rem;
  font-weight: 900;
  text-transform: uppercase;
}

.topbar h1 {
  margin: 0;
  font-size: clamp(1.8rem, 2.6vw, 2.65rem);
  line-height: 1.05;
}

.bucket-panel {
  display: grid;
  grid-template-columns: minmax(220px, 0.72fr) minmax(260px, 1fr) auto;
  gap: 14px;
  align-items: center;
  padding: 14px;
  box-shadow: 0 12px 28px rgba(0, 4, 20, 0.24);
}

.bucket-copy { display: grid; gap: 3px; }
.bucket-label { color: var(--muted); font-size: 0.76rem; font-weight: 900; text-transform: uppercase; }
.bucket-copy strong { font-size: 1.08rem; }
.bucket-copy p { margin: 0; color: var(--muted); font-size: 0.88rem; }

.progress-meter {
  height: 14px;
  overflow: hidden;
  border-radius: 999px;
  background: rgba(148, 163, 184, 0.28);
}

.progress-meter > div {
  width: 0%;
  height: 100%;
  border-radius: inherit;
  background: linear-gradient(90deg, var(--accent), var(--success));
  transition: width 0.35s ease;
}

.bucket-stats {
  display: grid;
  grid-auto-flow: column;
  gap: 8px;
}

.bucket-stats span {
  min-width: 92px;
  padding: 8px 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--soft);
  color: var(--muted);
  font-size: 0.8rem;
  font-weight: 800;
  text-align: center;
}

.bucket-stats strong { display: block; color: var(--ink); font-size: 1.1rem; }

.status-bar {
  display: none;
  align-items: center;
  min-height: 42px;
  padding: 9px 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(30, 64, 175, 0.18);
  color: #dbeafe;
  font-weight: 850;
}

.status-info { border-color: rgba(147, 197, 253, 0.62); background: rgba(30, 64, 175, 0.2); color: #dbeafe; }
.status-success { border-color: rgba(134, 239, 172, 0.62); background: rgba(20, 83, 45, 0.34); color: #dcfce7; }
.status-warn { border-color: rgba(250, 204, 21, 0.62); background: rgba(113, 63, 18, 0.32); color: #fef3c7; }
.status-error { border-color: rgba(252, 165, 165, 0.66); background: rgba(127, 29, 29, 0.34); color: #fee2e2; }

.work-grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 390px;
  gap: 12px;
  align-items: start;
}

.editor-card, .review-card {
  display: grid;
  gap: 14px;
  padding: 14px;
  box-shadow: 0 14px 32px rgba(0, 4, 20, 0.24);
}

.review-card {
  position: sticky;
  top: 16px;
  max-height: calc(100vh - 32px);
  overflow: auto;
  background: rgba(8, 24, 65, 0.9);
}

.exercise-header {
  display: flex;
  align-items: start;
  justify-content: space-between;
  gap: 12px;
}

.exercise-header h2 {
  margin: 7px 0 0;
  font-size: clamp(1.35rem, 2vw, 2rem);
  line-height: 1.18;
}

.id-pill, .state-pill {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 999px;
  padding: 5px 10px;
  font-size: 0.78rem;
  font-weight: 900;
}

.id-pill {
  border: 1px solid rgba(147, 197, 253, 0.5);
  background: rgba(37, 99, 235, 0.22);
  color: var(--accent-dark);
}

.state-pill {
  flex: 0 0 auto;
  border: 1px solid var(--line);
  background: var(--soft);
  color: var(--muted);
}

.state-pill.done { border-color: rgba(167, 243, 208, 0.62); background: rgba(6, 78, 59, 0.38); color: #bbf7d0; }
.state-pill.rejected { border-color: rgba(254, 202, 202, 0.62); background: rgba(127, 29, 29, 0.38); color: #fecaca; }

.meta { margin: 0; color: var(--muted); line-height: 1.45; }
.tts-label textarea {
  min-height: 250px;
  max-height: 34vh;
  font-size: 1rem;
}

.editor-actions, .review-actions {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px;
}

.review-actions { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.voice-box, .audio-box, .decision-box { display: grid; gap: 10px; }
.section-title { align-items: start; }

.section-title span {
  max-width: 190px;
  color: var(--muted);
  font-size: 0.82rem;
  font-weight: 800;
  text-align: right;
}

.players { display: grid; gap: 9px; }

.empty-state {
  margin: 0;
  padding: 14px;
  border: 1px dashed var(--line-strong);
  border-radius: 8px;
  color: var(--muted);
  background: rgba(6, 24, 66, 0.9);
  font-size: 0.9rem;
}

.player-card {
  display: grid;
  gap: 8px;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(6, 24, 66, 0.9);
}

.player-header {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr);
  align-items: center;
  gap: 8px;
}

.player-header input { width: 18px; height: 18px; padding: 0; }

.player-header label {
  min-width: 0;
  display: grid;
  gap: 2px;
  color: var(--ink);
  font-size: 0.9rem;
}

.voice-name, .voice-style {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.voice-name { font-weight: 900; }
.voice-style { color: var(--muted); font-size: 0.78rem; font-weight: 750; }
.audio-player { width: 100%; height: 36px; }

.review-lists {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
}

.review-lists article {
  min-width: 0;
  overflow: hidden;
  box-shadow: 0 12px 28px rgba(0, 4, 20, 0.24);
}

.list-head {
  padding: 10px 12px;
  border-bottom: 1px solid var(--line);
}

.list-head button { min-height: 34px; padding: 7px 10px; font-size: 0.82rem; }

.review-lists ul {
  max-height: 260px;
  margin: 0;
  padding: 10px 14px 10px 30px;
  overflow: auto;
  color: #d7e5ff;
  line-height: 1.45;
}

.review-lists li + li { margin-top: 6px; }
.hidden { display: none; }

@media (max-width: 1220px) {
  .app-shell { grid-template-columns: 1fr; }
  .sidebar { position: static; max-height: none; grid-template-rows: auto; }
  .queue-list { max-height: 260px; }
  .work-grid { grid-template-columns: 1fr; }
  .review-card { position: static; max-height: none; }
}

@media (max-width: 820px) {
  body { background: #030a21; }
  .app-shell { gap: 10px; padding: 10px; }
  .main-panel, .sidebar { padding: 10px; }
  .topbar, .exercise-header, .section-title { display: grid; }
  .bucket-panel { grid-template-columns: 1fr; }
  .bucket-stats { grid-auto-flow: row; grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .editor-actions, .review-actions, .review-lists { grid-template-columns: 1fr; }
  .tts-label textarea { min-height: 240px; max-height: none; }
}
