:root {
  color-scheme: dark;
  --bg: #121212;
  --surface: #1e1e1e;
  --surface-2: #2a2a2a;
  --surface-3: #171717;
  --border: #2e2e2e;
  --text: #f0f0f0;
  --muted: #8d8d8d;
  --primary: #4f8ef7;
  --primary-soft: #1e2d4a;
  --primary-text: #ffffff;
  --danger: #ef6461;
  --warn: #f4b942;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--text);
  font-family: Ubuntu, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

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

button {
  cursor: pointer;
}

a {
  text-decoration: none;
}

button:disabled {
  cursor: not-allowed;
  opacity: 0.48;
}

h1,
h2,
h3,
p {
  margin: 0;
}

.authGate {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
  background: radial-gradient(circle at 50% 0%, rgba(79, 142, 247, 0.18), transparent 32%), var(--bg);
}

.authGate.hidden {
  display: none;
}

.authCard {
  width: min(420px, 100%);
  display: grid;
  gap: 12px;
  padding: 24px;
  border: 1px solid var(--border);
  border-radius: 14px;
  background: var(--surface);
  box-shadow: 0 24px 60px rgba(0, 0, 0, 0.32);
}

.authCard h1 {
  font-size: 28px;
}

.authCard p {
  color: var(--muted);
}

.authCard input {
  width: 100%;
  min-height: 46px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--surface-3);
  color: var(--text);
  padding: 0 12px;
  outline: none;
}

.authCard input:focus {
  border-color: var(--primary);
}

.authMessage {
  min-height: 20px;
  color: var(--muted);
  font-size: 13px;
}

.authMessage.error {
  color: var(--danger);
}

.appShell {
  min-height: 100vh;
  display: grid;
  grid-template-columns: 260px minmax(0, 1fr);
}

.sidebar {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  gap: 18px;
  padding: 18px;
  background: var(--surface);
  border-right: 1px solid var(--border);
}

.brandBlock {
  display: flex;
  align-items: center;
  gap: 12px;
}

.authLogo,
.sidebarLogo {
  object-fit: contain;
  display: block;
}

.logoHomeBtn {
  width: min(180px, 100%);
  display: block;
  border: 0;
  background: transparent;
  padding: 0;
  border-radius: 8px;
}

.logoHomeBtn:hover,
.logoHomeBtn:focus-visible {
  opacity: 0.82;
  outline: none;
}

.authLogo {
  width: min(220px, 72%);
  height: auto;
}

.sidebarLogo {
  width: 100%;
  height: auto;
}

.brandBlock p,
.sidebarFooter,
.eyebrow,
.heroCopy p,
.watchMeta,
.empty {
  color: var(--muted);
}

.brandBlock p {
  max-width: 170px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 12px;
}

.heroCopy p,
.sidebarFooter {
  display: none;
}

.historyList {
  min-height: 0;
  overflow: auto;
  display: grid;
  align-content: start;
  gap: 4px;
}

.historyItem {
  min-height: 42px;
  display: flex;
  align-items: center;
  padding: 7px 9px;
  border: 1px solid transparent;
  border-radius: 8px;
  background: transparent;
  color: var(--text);
  text-align: left;
}

.historyItem:hover,
.historyItem.active {
  border-color: var(--border);
  background: var(--surface-2);
}

.historySearch {
  display: block;
  padding: 4px 0 8px;
}

.historySearch input {
  width: 100%;
  min-height: 34px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface-2);
  color: var(--text);
  padding: 0 10px;
  font-size: 12px;
  outline: none;
}

.historySearch input::placeholder {
  color: var(--muted);
}

.historySearch input:focus {
  border-color: var(--primary);
}

.historyText {
  min-width: 0;
  width: 100%;
}

.historyItem strong,
.historyItem small {
  display: block;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.historyItem strong {
  font-size: 12px;
  font-weight: 650;
  line-height: 1.25;
}

.historyItem small {
  margin-top: 2px;
  color: var(--muted);
  font-size: 10.5px;
  line-height: 1.2;
}

.historyIcon {
  display: none;
}

.sidebarFooter {
  margin-top: auto;
  display: grid;
  gap: 10px;
  font-size: 13px;
  line-height: 1.45;
}

.userBlock {
  display: grid;
  gap: 8px;
  padding: 10px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--surface-3);
}

.userBlock span {
  overflow: hidden;
  color: var(--muted);
  font-size: 12px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.userBlock button {
  min-height: 30px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface-2);
  color: var(--text);
}

.status.error,
.error {
  color: var(--danger);
}

.sidebarFooter .status {
  display: none;
}

.mainPane {
  min-width: 0;
}

.homeView {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 28px;
  padding: 48px 24px;
}

.heroCopy {
  max-width: 720px;
  text-align: center;
}

.heroCopy h2 {
  font-size: clamp(34px, 5vw, 58px);
  line-height: 1.05;
  font-weight: 760;
  letter-spacing: 0;
}

.heroCopy p {
  margin-top: 14px;
  font-size: 16px;
  line-height: 1.6;
}

.promptComposer {
  width: min(760px, 100%);
  overflow: hidden;
  border: 1px solid var(--border);
  border-radius: 18px;
  background: var(--surface);
  box-shadow: 0 24px 80px rgba(0, 0, 0, 0.28);
}

#topicInput {
  width: 100%;
  min-height: 112px;
  resize: vertical;
  border: 0;
  outline: none;
  padding: 18px;
  background: transparent;
  color: var(--text);
  font-size: 18px;
  line-height: 1.55;
}

.composerBar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px;
  border-top: 1px solid var(--border);
}

.uploadBar {
  min-height: 48px;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 0 12px 12px;
}

.fileInput {
  display: none;
}

.uploadButton,
.iconTextButton {
  min-height: 34px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--surface-2);
  color: var(--text);
  padding: 0 12px;
  font-size: 13px;
  font-weight: 650;
  cursor: pointer;
}

.uploadButton:hover,
.iconTextButton:hover {
  border-color: #555555;
  background: #303030;
}

.uploadName {
  min-width: 0;
  flex: 1;
  overflow: hidden;
  color: var(--muted);
  font-size: 13px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.segmented {
  display: flex;
  align-items: center;
  overflow: hidden;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--surface-2);
}

.chip {
  min-height: 34px;
  border: 0;
  border-right: 1px solid var(--border);
  background: transparent;
  color: var(--muted);
  padding: 0 12px;
  font-size: 13px;
  font-weight: 650;
}

.chip:last-child {
  border-right: 0;
}

.chip.active {
  background: var(--primary-soft);
  color: var(--primary);
}

.primaryAction,
.secondaryAction,
.sectionHead button {
  min-height: 38px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 0 14px;
  color: var(--text);
  background: var(--surface-2);
}

.primaryAction {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  border-color: var(--primary);
  background: var(--primary);
  color: var(--primary-text);
  font-weight: 750;
}

.secondaryAction:hover,
.sectionHead button:hover:not(:disabled),
.chip:hover,
.suggestions button:hover {
  border-color: #555555;
  background: #303030;
}

.suggestions {
  width: min(760px, 100%);
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 12px;
}

.suggestions button {
  min-height: 42px;
  border: 1px solid var(--border);
  border-radius: 14px;
  background: var(--surface);
  color: var(--muted);
  padding: 0 14px;
}

.hiddenControls,
.hidden {
  display: none !important;
}

.studioView {
  min-height: 100vh;
  padding: 24px;
  display: flex;
  flex-direction: column;
  justify-content: center;
}

.studioHeader {
  width: min(1180px, 100%);
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 18px;
  margin: 0 auto 18px;
}

.studioHeader h2 {
  margin-top: 3px;
  font-size: 28px;
  font-weight: 760;
}

.eyebrow {
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
}

.studioActions,
.buttonGroup {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 8px;
}

.watchPanel,
.panel,
.developerDetails {
  border: 1px solid var(--border);
  border-radius: 14px;
  background: var(--surface);
}

.watchPanel {
  width: min(1180px, 100%);
  overflow: hidden;
  margin: 0 auto;
}

.videoShell {
  position: relative;
  width: 100%;
  background: #050505;
}

.preparingPanel {
  position: relative;
  z-index: 1;
  width: 100%;
  min-height: clamp(360px, 58vh, 680px);
  aspect-ratio: 16 / 9;
  display: grid;
  place-items: center;
  padding: 28px;
  background: #050505;
}

.preparingContent {
  width: min(560px, 100%);
  display: grid;
  gap: 14px;
  justify-items: center;
  text-align: center;
}

.preparingContent h3 {
  max-width: 100%;
  font-size: clamp(24px, 4vw, 42px);
  line-height: 1.12;
  font-weight: 760;
}

.preparingContent p {
  min-height: 22px;
  color: var(--muted);
  font-size: 14px;
}

.preparingTrack {
  width: min(460px, 100%);
  height: 5px;
  overflow: hidden;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.1);
}

.preparingBar {
  width: 0%;
  height: 100%;
  border-radius: inherit;
  background: var(--primary);
  transition: width 850ms ease;
}

#videoOutput {
  display: none;
  width: 100%;
  aspect-ratio: 16 / 9;
  background: #050505;
}

#videoOutput.visible {
  display: block;
}

#preloadVideo {
  display: none;
}

.playerControls {
  position: absolute;
  z-index: 3;
  left: 16px;
  right: 16px;
  bottom: 14px;
  min-height: 46px;
  display: grid;
  grid-template-columns: auto auto minmax(0, 1fr) auto auto;
  align-items: center;
  gap: 12px;
  padding: 8px 10px;
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: 10px;
  background: rgba(18, 18, 18, 0.82);
  backdrop-filter: blur(14px);
  box-shadow: 0 14px 34px rgba(0, 0, 0, 0.28);
  opacity: 1;
  transform: translateY(0);
  transition: opacity 180ms ease, transform 180ms ease;
}

.playerControls.autoHidden {
  opacity: 0;
  pointer-events: none;
  transform: translateY(12px);
}

.playerButton {
  min-width: 78px;
  min-height: 30px;
  border: 1px solid rgba(255, 255, 255, 0.16);
  border-radius: 8px;
  background: var(--primary);
  color: var(--primary-text);
  font-weight: 750;
}

.playerIconButton {
  width: 34px;
  min-height: 30px;
  display: grid;
  place-items: center;
  border: 1px solid rgba(255, 255, 255, 0.16);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.08);
  color: var(--text);
  font-size: 16px;
  font-weight: 800;
}

.timeText {
  min-width: 44px;
  color: var(--text);
  font-size: 12px;
  font-variant-numeric: tabular-nums;
  text-align: center;
}

.seekBar {
  width: 100%;
  accent-color: var(--primary);
}

.videoOverlay {
  display: none;
  position: absolute;
  z-index: 2;
  inset: 0;
  align-items: center;
  justify-content: center;
  background: rgba(5, 5, 5, 0.72);
  color: var(--text);
  font-size: 15px;
  text-align: center;
  padding: 16px;
  pointer-events: none;
}

.videoOverlay.visible {
  display: flex;
}

.karaAskForm {
  position: relative;
  width: min(720px, calc(100% - 32px));
  min-height: 52px;
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto;
  align-items: center;
  gap: 8px;
  margin: 14px auto 0;
  padding: 6px 6px 6px 18px;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--surface);
  box-shadow: 0 16px 34px rgba(0, 0, 0, 0.18);
}

.karaAskForm.hidden {
  display: none;
}

.karaAskForm input {
  min-width: 0;
  border: 0;
  outline: 0;
  background: transparent;
  color: var(--text);
  font-size: 15px;
}

.karaAskForm input::placeholder {
  color: rgba(240, 240, 240, 0.54);
}

.karaTimestamp {
  min-width: 42px;
  color: var(--primary);
  font-size: 13px;
  font-weight: 750;
  font-variant-numeric: tabular-nums;
  text-align: right;
}

.karaTimestamp:empty {
  display: none;
}

.karaSendBtn {
  width: 40px;
  height: 40px;
  display: grid;
  place-items: center;
  border: 0;
  border-radius: 999px;
  background: var(--primary);
  color: var(--primary-text);
}

.karaSendBtn svg {
  width: 19px;
  height: 19px;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.karaChat {
  display: grid;
  gap: 12px;
  padding: 16px 0 0;
  font-family: Georgia, "Times New Roman", serif;
}

.karaChat.hidden {
  display: none;
}

.chatMessage {
  max-width: min(820px, 100%);
  padding: 12px 14px;
  border: 1px solid var(--border);
  border-radius: 14px;
  background: var(--surface);
  line-height: 1.55;
  font-size: 15px;
}

.chatMessage.user {
  justify-self: end;
  background: var(--primary-soft);
  border-color: rgba(79, 142, 247, 0.34);
}

.chatMessage.assistant {
  justify-self: start;
}

.chatMeta {
  margin-bottom: 6px;
  color: var(--muted);
  font-family: Ubuntu, ui-sans-serif, system-ui, sans-serif;
  font-size: 12px;
  font-weight: 700;
}

.chatContent p {
  margin: 0 0 8px;
}

.chatContent p:last-child {
  margin-bottom: 0;
}

.watchMeta {
  min-height: 44px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 10px 14px;
  border-top: 1px solid var(--border);
  font-size: 13px;
}

#logOutput {
  min-height: 96px;
  max-height: 180px;
  margin: 0;
  padding: 12px 14px;
  overflow: auto;
  color: var(--muted);
  background: var(--surface-3);
  border-top: 1px solid var(--border);
  font-family: "Cascadia Code", "Consolas", monospace;
  font-size: 12px;
  line-height: 1.45;
  white-space: pre-wrap;
}

.lessonGrid,
.devGrid {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(420px, 1fr);
  gap: 18px;
}

.sectionHead {
  min-height: 52px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px 14px;
  border-bottom: 1px solid var(--border);
}

.sectionHead h3 {
  font-size: 15px;
  font-weight: 750;
}

#planOutput,
#speechOutput,
.segmentDetail {
  padding: 14px;
  line-height: 1.55;
}

#planOutput strong,
.segmentDetail strong {
  color: var(--warn);
}

.segmentList {
  display: flex;
  gap: 8px;
  overflow-x: auto;
  padding: 10px 14px 0;
}

.segmentTab {
  flex: 0 0 auto;
  min-width: 78px;
  height: 34px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--surface-2);
  color: var(--muted);
}

.segmentTab.active {
  border-color: var(--primary);
  color: var(--primary);
}

.developerDetails {
  margin-top: 18px;
  padding: 0;
}

.developerDetails summary {
  cursor: pointer;
  padding: 14px;
  color: var(--muted);
}

.devGrid {
  padding: 0 14px 14px;
}

#audioOutput {
  display: none;
  width: calc(100% - 28px);
  margin: 0 14px 14px;
}

#audioOutput.visible {
  display: block;
}

#codeOutput {
  display: block;
  width: 100%;
  height: 360px;
  border: 0;
  border-radius: 0 0 14px 14px;
  background: #0d0d0d;
  color: #e9f5ef;
  padding: 12px;
  font-family: "Cascadia Code", "Consolas", monospace;
  font-size: 13px;
  line-height: 1.48;
  outline: none;
}

.row {
  display: grid;
  gap: 8px;
  margin-bottom: 12px;
}

.row:last-child {
  margin-bottom: 0;
}

.pill {
  display: inline-flex;
  align-items: center;
  min-height: 24px;
  margin: 4px 6px 0 0;
  padding: 2px 8px;
  border: 1px solid var(--border);
  border-radius: 999px;
  color: var(--muted);
  font-size: 12px;
}

@media (max-width: 1180px) {
  .appShell {
    grid-template-columns: 1fr;
  }

  .sidebar {
    min-height: auto;
    flex-direction: row;
    align-items: center;
  }

  .historyList {
    display: none;
  }

  .sidebarFooter {
    margin-left: auto;
    margin-top: 0;
  }

  .lessonGrid,
  .devGrid {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 760px) {
  .homeView,
  .studioView {
    padding: 16px;
  }

  .composerBar,
  .studioHeader {
    align-items: stretch;
    flex-direction: column;
  }

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

  .uploadButton,
  .iconTextButton {
    width: 100%;
  }

  .segmented {
    width: 100%;
  }

  .chip {
    flex: 1;
  }

  .primaryAction,
  .secondaryAction {
    width: 100%;
    justify-content: center;
  }

  .sidebar {
    align-items: flex-start;
    flex-direction: column;
  }

  .sidebarFooter {
    margin-left: 0;
  }

  .playerControls {
    left: 10px;
    right: 10px;
    bottom: 10px;
    grid-template-columns: auto minmax(0, 1fr) auto auto;
    gap: 8px;
  }

  .playerButton {
    min-width: 64px;
  }

  .karaAskForm {
    width: calc(100% - 20px);
    min-height: 48px;
    padding-left: 14px;
  }

  .karaAskForm input {
    font-size: 14px;
  }

  .karaSendBtn {
    width: 36px;
    height: 36px;
  }

  .timeText:first-of-type {
    display: none;
  }
}
