:root {
  color-scheme: light;
  --bg: #f6f7f4;
  --surface: #ffffff;
  --surface-strong: #f0f3ef;
  --text: #18201d;
  --muted: #64706b;
  --line: #dfe5df;
  --accent: #d6422b;
  --accent-quiet: #fff0ec;
  --teal: #1d7f73;
  --shadow: 0 18px 40px rgba(24, 32, 29, 0.08);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--text);
  font-family:
    Inter,
    "Segoe UI",
    "Microsoft YaHei",
    "Noto Sans Thai",
    Arial,
    sans-serif;
}

button,
input,
select {
  font: inherit;
}

.mobile-only {
  display: none;
}

.hidden {
  display: none !important;
}

.app-shell {
  width: min(1860px, calc(100vw - 32px));
  margin: 0 auto;
  padding: 16px 0;
}

.learning-platform-nav {
  display: inline-flex;
  gap: 4px;
  margin-bottom: 12px;
  padding: 4px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--surface);
}

.learning-platform-nav a {
  padding: 8px 13px;
  border-radius: 9px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 750;
  text-decoration: none;
}

.learning-platform-nav a.active {
  background: #e5efe8;
  color: #235c45;
}

.topbar {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 20px;
  margin-bottom: 12px;
}

.topbar h1 {
  margin: 0;
  font-size: clamp(24px, 3vw, 36px);
  line-height: 1.15;
  letter-spacing: 0;
}

.topbar p {
  margin: 8px 0 0;
  color: var(--muted);
}

.status-pill {
  flex: 0 0 auto;
  padding: 8px 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  color: var(--teal);
  font-weight: 700;
}

.control-bar {
  display: grid;
  grid-template-columns: minmax(300px, 1fr) minmax(160px, 190px) repeat(4, minmax(118px, auto));
  gap: 12px;
  align-items: end;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: var(--shadow);
}

.control-actions {
  display: contents;
}

.hidden-file-input {
  display: none;
}

.youtube-browser {
  margin-top: 12px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: var(--shadow);
}

.youtube-browser-content {
  min-width: 0;
}

.browser-title {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 10px;
}

.browser-title h2 {
  margin: 0;
  font-size: 18px;
  line-height: 1.25;
}

.browser-title p,
.browser-title span {
  margin: 4px 0 0;
  color: var(--muted);
  font-size: 13px;
}

.browser-title span {
  flex: 0 0 auto;
  padding-top: 2px;
}

.youtube-account-actions,
.youtube-panel-actions {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 8px;
}

.youtube-tabs {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin: 10px 0;
}

.youtube-tab {
  min-height: 34px;
  padding: 0 12px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fbfcfb;
  color: var(--text);
  font-weight: 800;
  cursor: pointer;
}

.youtube-tab.is-active {
  border-color: #cbded8;
  background: #edf7f3;
  color: var(--teal);
}

.youtube-tab-panel {
  margin-top: 8px;
}

.browser-search {
  display: grid;
  grid-template-columns: minmax(240px, 1fr) minmax(108px, auto);
  gap: 10px;
}

.youtube-results {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(230px, 1fr));
  gap: 10px;
  max-height: 340px;
  overflow: auto;
  margin-top: 12px;
  padding-right: 2px;
}

.youtube-results.is-empty {
  display: block;
  max-height: none;
  overflow: visible;
}

.youtube-results-empty {
  padding: 12px;
  border: 1px dashed var(--line);
  border-radius: 6px;
  color: var(--muted);
  background: #fbfcfb;
}

.youtube-result {
  display: grid;
  grid-template-columns: 112px minmax(0, 1fr);
  gap: 10px;
  width: 100%;
  min-height: 88px;
  padding: 8px;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: #fbfcfb;
  color: var(--text);
  text-align: left;
  cursor: pointer;
}

.youtube-result.is-channel,
.youtube-result.is-playlist {
  cursor: pointer;
}

.youtube-result.is-video {
  border-color: #dde6df;
}

.youtube-result:hover,
.youtube-result:focus-visible {
  border-color: var(--teal);
  box-shadow: 0 0 0 3px rgba(29, 127, 115, 0.12);
  outline: none;
}

.youtube-thumb {
  position: relative;
  overflow: hidden;
  aspect-ratio: 16 / 9;
  border-radius: 5px;
  background: #dfe5df;
}

.youtube-thumb img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.youtube-duration {
  position: absolute;
  right: 4px;
  bottom: 4px;
  padding: 2px 5px;
  border-radius: 4px;
  background: rgba(0, 0, 0, 0.78);
  color: #fff;
  font-size: 12px;
  font-weight: 700;
}

.youtube-result-title {
  display: -webkit-box;
  overflow: hidden;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 2;
  font-weight: 800;
  line-height: 1.35;
}

.youtube-result-meta {
  margin-top: 5px;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.35;
}

.youtube-result-description {
  display: -webkit-box;
  overflow: hidden;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 2;
  margin-top: 6px;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.35;
}

.url-field,
.select-field {
  display: grid;
  gap: 7px;
}

.url-field > label,
.url-field span,
.select-field span {
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
}

.url-history-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 6px;
}

.url-history-row select,
.url-history-row .small-button {
  min-height: 32px;
  font-size: 12px;
}

.url-history-row select {
  min-width: 0;
  padding: 0 8px;
}

input,
select {
  width: 100%;
  min-height: 44px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fbfcfb;
  color: var(--text);
  outline: none;
}

input {
  padding: 0 13px;
}

select {
  padding: 0 10px;
}

input:focus,
select:focus {
  border-color: var(--teal);
  box-shadow: 0 0 0 3px rgba(29, 127, 115, 0.13);
}

.primary-button,
.ghost-button {
  min-height: 44px;
  border-radius: 6px;
  padding: 0 16px;
  border: 1px solid transparent;
  font-weight: 800;
  cursor: pointer;
}

.primary-button {
  background: var(--accent);
  color: #ffffff;
}

.primary-button:hover {
  background: #bd351f;
}

.ghost-button {
  border-color: var(--line);
  background: var(--surface-strong);
  color: var(--text);
}

.ghost-button:disabled {
  color: #9aa39f;
  cursor: not-allowed;
}

.workspace {
  display: grid;
  grid-template-columns: minmax(700px, 1.35fr) minmax(420px, 0.85fr);
  gap: 20px;
  margin-top: 16px;
  align-items: start;
}

.player-panel,
.subtitle-panel,
.ai-learning-panel {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: var(--shadow);
}

.player-panel {
  overflow: hidden;
}

.video-frame {
  position: relative;
  width: 100%;
  aspect-ratio: 16 / 9;
  background: #101615;
}

#player,
#player iframe {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
}

.html5-player {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  background: #101615;
}

.player-placeholder {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 24px;
  color: #d8e2df;
  text-align: center;
  background:
    linear-gradient(135deg, rgba(214, 66, 43, 0.2), transparent 38%),
    #101615;
}

.player-placeholder.hidden {
  display: none;
}

.meta-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  padding: 16px;
  border-top: 1px solid var(--line);
}

.meta-row strong,
.meta-row span {
  display: block;
}

.meta-row strong {
  line-height: 1.35;
}

.meta-row span {
  margin-top: 4px;
  color: var(--muted);
  font-size: 13px;
}

.player-actions {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 7px;
}

.time-readout {
  flex: 0 0 auto;
  min-width: 72px;
  padding: 8px 10px;
  border-radius: 6px;
  background: var(--surface-strong);
  color: var(--teal);
  text-align: center;
  font-variant-numeric: tabular-nums;
  font-weight: 800;
}

.subtitle-panel {
  min-height: 620px;
  max-height: calc(100vh - 132px);
  display: grid;
  grid-template-rows: auto auto auto auto auto auto minmax(0, 1fr);
  overflow: hidden;
}

.ai-learning-panel {
  position: fixed;
  z-index: 70;
  top: 16px;
  right: 16px;
  bottom: 16px;
  width: min(440px, calc(100vw - 32px));
  min-height: 0;
  max-height: none;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  visibility: hidden;
  transform: translateX(calc(100% + 32px));
  transition: transform 180ms ease, visibility 180ms ease;
}

body.learning-panel-open {
  overflow: hidden;
}

body.learning-panel-open .ai-learning-panel {
  visibility: visible;
  transform: translateX(0);
}

.ai-learning-backdrop {
  position: fixed;
  z-index: 60;
  inset: 0;
  border: 0;
  padding: 0;
  background: rgba(24, 32, 29, 0.34);
  opacity: 0;
  visibility: hidden;
  cursor: default;
  transition: opacity 180ms ease, visibility 180ms ease;
}

body.learning-panel-open .ai-learning-backdrop {
  opacity: 1;
  visibility: visible;
}

.learning-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 16px;
  border-bottom: 1px solid var(--line);
}

.learning-header h2 {
  margin: 0;
  font-size: 20px;
}

.learning-header p {
  margin: 4px 0 0;
  color: var(--muted);
  font-size: 13px;
}

.learning-header-actions,
.subtitle-view-actions {
  display: flex;
  align-items: center;
  gap: 7px;
}

.learning-open-button {
  border-color: #c8ddd6;
  color: var(--teal);
}

.learning-open-button.has-results::after {
  content: attr(data-count);
  min-width: 18px;
  margin-left: 5px;
  padding: 1px 5px;
  border-radius: 8px;
  background: var(--teal);
  color: #ffffff;
  font-size: 10px;
}

.learning-progress-wrap {
  padding: 8px 16px 0;
}

.learning-progress-wrap progress {
  width: 100%;
  height: 7px;
  accent-color: var(--teal);
}

.learning-summary {
  padding: 14px 16px;
  border-bottom: 1px solid var(--line);
}

.learning-summary h3 {
  margin: 0 0 7px;
  font-size: 16px;
}

.learning-summary p {
  margin: 5px 0;
  color: #34403c;
  font-size: 13px;
  line-height: 1.55;
}

.learning-stars {
  color: #c57a00;
  font-weight: 800;
  letter-spacing: 0;
}

.learning-empty {
  padding: 12px;
  color: var(--muted);
  font-size: 13px;
  text-align: center;
}

.learning-stats {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  border-bottom: 1px solid var(--line);
}

.learning-stats div {
  min-width: 0;
  padding: 10px 5px;
  text-align: center;
}

.learning-stats div + div {
  border-left: 1px solid var(--line);
}

.learning-stats strong,
.learning-stats span {
  display: block;
}

.learning-stats strong {
  color: var(--teal);
  font-size: 19px;
}

.learning-stats span {
  margin-top: 2px;
  color: var(--muted);
  font-size: 11px;
}

.learning-toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 7px;
  padding: 10px 12px;
  border-bottom: 1px solid var(--line);
}

.learning-categories {
  flex: 1 1 auto;
  min-height: 0;
  padding: 8px;
  overflow-y: auto;
  scrollbar-gutter: stable;
}

.learning-category {
  border-bottom: 1px solid var(--line);
}

.learning-category summary {
  display: flex;
  align-items: center;
  gap: 7px;
  padding: 10px 6px;
  cursor: pointer;
  font-weight: 750;
  list-style: none;
}

.learning-category summary::-webkit-details-marker {
  display: none;
}

.learning-category summary::before {
  content: "+";
  width: 18px;
  color: var(--teal);
  text-align: center;
}

.learning-category[open] summary::before {
  content: "−";
}

.learning-category-count {
  margin-left: auto;
  color: var(--muted);
  font-size: 12px;
  font-weight: 600;
}

.learning-item {
  display: grid;
  grid-template-columns: 22px minmax(0, 1fr) auto;
  gap: 7px;
  padding: 9px 6px 10px;
  border-top: 1px dashed var(--line);
}

.learning-item input {
  margin-top: 3px;
}

.learning-item-text {
  display: block;
  font-size: 15px;
  line-height: 1.45;
}

.learning-item-translation,
.learning-item-meta {
  display: block;
  margin-top: 3px;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.45;
}

.learning-seek {
  align-self: start;
  min-width: 48px;
  min-height: 28px;
  padding: 0 5px;
  color: var(--teal);
  font-size: 11px;
}

.subtitle-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 16px;
  border-bottom: 1px solid var(--line);
}

.subtitle-header h2 {
  margin: 0;
  font-size: 20px;
  letter-spacing: 0;
}

.subtitle-header p {
  margin: 4px 0 0;
  color: var(--muted);
  font-size: 13px;
}

.subtitle-toggles {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 10px;
}

.compact-toggle {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
}

.compact-toggle input {
  width: 16px;
  min-height: 16px;
  accent-color: var(--teal);
}

.study-strip {
  display: grid;
  grid-template-columns: minmax(180px, 0.65fr) minmax(0, 1fr);
  gap: 10px;
  padding: 10px 14px 0;
}

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

.study-metrics div,
.focus-line {
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fbfcfb;
}

.study-metrics div {
  min-height: 54px;
  padding: 8px;
}

.study-metrics strong {
  display: block;
  color: var(--teal);
  font-size: 18px;
  line-height: 1;
}

.study-metrics span,
.focus-line span {
  display: block;
  margin-top: 5px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
}

.focus-line {
  min-width: 0;
  padding: 8px 10px;
}

.focus-line strong {
  display: block;
  overflow: hidden;
  margin-top: 4px;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 15px;
  line-height: 1.35;
}

.focus-line em {
  display: block;
  overflow: hidden;
  margin-top: 2px;
  color: #58635f;
  font-size: 13px;
  font-style: normal;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.subtitle-tools {
  display: grid;
  grid-template-columns: minmax(170px, 1fr) auto auto;
  gap: 8px;
  align-items: center;
  padding: 10px 14px 0;
}

.subtitle-tools input {
  min-height: 36px;
}

.subtitle-filter-buttons {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 6px;
}

.filter-chip {
  min-height: 32px;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 0 9px;
  background: #ffffff;
  color: var(--muted);
  font-size: 12px;
  font-weight: 900;
  cursor: pointer;
}

.filter-chip.is-active {
  border-color: #cbded8;
  background: #edf7f3;
  color: var(--teal);
}

.message {
  margin: 10px 14px 0;
  padding: 9px 11px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--surface-strong);
  color: var(--muted);
  font-size: 14px;
  line-height: 1.55;
}

.subtitle-item.is-filtered-out {
  display: none;
}

.message.hidden {
  display: none;
}

.message.error {
  border-color: #efb3a5;
  background: #fff1ee;
  color: #9d2a18;
}

.message.success {
  border-color: #b8d8cc;
  background: #eef8f4;
  color: #17695f;
}

.word-lookup {
  margin: 8px 14px 0;
  padding: 10px 12px;
  border: 1px solid #b8d8cc;
  border-radius: 6px;
  background: #eef8f4;
}

.word-lookup.hidden {
  display: none;
}

.lookup-topline {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.lookup-kicker {
  color: var(--teal);
  font-size: 12px;
  font-weight: 800;
}

.icon-button {
  width: 28px;
  height: 28px;
  border: 1px solid #b8d8cc;
  border-radius: 6px;
  background: #ffffff;
  color: #36514b;
  font-size: 18px;
  line-height: 1;
  font-weight: 800;
  cursor: pointer;
}

.icon-button:hover {
  background: #f4faf7;
  color: var(--teal);
}

.lookup-word {
  margin-top: 3px;
  color: var(--text);
  font-size: 17px;
  font-weight: 800;
  line-height: 1.35;
}

.lookup-phonetic {
  margin-top: 2px;
  color: var(--teal);
  font-size: 14px;
  font-weight: 800;
}

.lookup-phonetic.hidden {
  display: none;
}

.lookup-translation {
  margin-top: 4px;
  color: #36514b;
  font-size: 14px;
  line-height: 1.55;
}

.lookup-actions,
.sentence-actions,
.favorite-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 7px;
  margin-top: 8px;
}

.small-button {
  min-height: 28px;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 0 9px;
  background: #ffffff;
  color: #33413c;
  font-size: 12px;
  font-weight: 800;
  cursor: pointer;
}

.small-button:hover {
  border-color: #b8d8cc;
  background: #f4faf7;
  color: var(--teal);
}

.listen-button {
  border-color: #b8d8cc;
  background: #edf7f3;
  color: var(--teal);
}

.listen-button.is-active {
  border-color: var(--teal);
  background: var(--teal);
  color: #ffffff;
}

.next-episode-button:not(:disabled) {
  border-color: #f0b7a8;
  background: #fff2ed;
  color: var(--accent);
}

.previous-episode-button:not(:disabled) {
  border-color: #b8d8cc;
  background: #f0f8f5;
  color: var(--teal);
}

.queue-mode-toggle {
  min-height: 34px;
  padding: 0 9px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fbfcfb;
  white-space: nowrap;
}

.queue-mode-toggle span {
  margin: 0;
  color: inherit;
  font-size: 12px;
}

.favorites-panel {
  margin: 8px 14px 0;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fbfcfb;
  overflow: hidden;
}

.favorites-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
  padding: 8px 10px;
  border-bottom: 0;
}

.favorites-header h3 {
  margin: 0;
  font-size: 15px;
  letter-spacing: 0;
}

.favorites-header span {
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
}

.favorites-controls {
  display: inline-flex;
  align-items: center;
  gap: 8px;
}

.favorites-list {
  max-height: 190px;
  overflow: auto;
  border-top: 1px solid var(--line);
}

.favorites-panel.is-collapsed .favorites-list {
  display: none;
}

.favorites-empty {
  padding: 12px;
  color: var(--muted);
  font-size: 13px;
}

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

.favorite-item:last-child {
  border-bottom: 0;
}

.favorite-text {
  color: var(--text);
  font-size: 14px;
  line-height: 1.45;
  font-weight: 800;
}

.favorite-translation {
  margin-top: 3px;
  color: #58635f;
  font-size: 13px;
  line-height: 1.45;
}

.favorite-meta {
  margin-top: 5px;
  color: var(--muted);
  font-size: 12px;
}

.subtitle-list {
  overflow: auto;
  overscroll-behavior: contain;
  scrollbar-gutter: stable;
  -webkit-overflow-scrolling: touch;
  padding: 10px 10px 18px;
}

.subtitle-item {
  width: 100%;
  display: grid;
  grid-template-columns: 56px minmax(0, 1fr) auto;
  gap: 10px;
  padding: 10px 12px;
  border: 0;
  border-left: 4px solid transparent;
  border-radius: 6px;
  background: transparent;
  color: inherit;
  text-align: left;
  cursor: pointer;
}

.subtitle-item.is-saved {
  border-left-color: var(--teal);
}

.subtitle-item:hover {
  background: #f6f8f6;
}

.subtitle-item:focus-visible {
  outline: 3px solid rgba(29, 127, 115, 0.18);
  outline-offset: 2px;
}

.subtitle-item.active {
  border-left-color: var(--accent);
  background: var(--accent-quiet);
}

.subtitle-time {
  color: var(--teal);
  font-size: 13px;
  font-variant-numeric: tabular-nums;
  font-weight: 800;
  padding-top: 3px;
}

.subtitle-original {
  display: block;
  color: var(--text);
  font-size: 17px;
  line-height: 1.5;
}

.word-token {
  display: inline;
  min-height: 0;
  margin: 0 1px;
  padding: 0 2px;
  border: 0;
  border-bottom: 1px dotted rgba(29, 127, 115, 0.55);
  border-radius: 3px;
  background: transparent;
  color: inherit;
  line-height: inherit;
  cursor: pointer;
}

.word-token:hover,
.word-token:focus-visible {
  background: rgba(29, 127, 115, 0.11);
  outline: none;
}

.word-token.selected {
  background: #d9efe8;
  border-bottom-color: var(--teal);
  color: #0f5149;
}

.highlight-term {
  border-radius: 4px;
  padding: 0 3px;
  font-weight: 900;
}

.highlight-term.business {
  background: #fff0d8;
  color: #9a3f08;
  box-shadow: inset 0 -2px 0 rgba(214, 66, 43, 0.24);
}

.highlight-term.thai {
  background: #e6f5ef;
  color: #0f6b5d;
  box-shadow: inset 0 -2px 0 rgba(29, 127, 115, 0.22);
}

.word-token.highlight-term {
  border-bottom-color: transparent;
}

.subtitle-translation {
  margin-top: 5px;
  color: #58635f;
  font-size: 14px;
  line-height: 1.55;
}

.subtitle-translation.empty {
  color: #9aa39f;
  font-style: italic;
}

.keyword-list {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 8px;
}

.keyword-label {
  color: var(--teal);
  font-size: 12px;
  font-weight: 900;
  padding: 4px 0;
}

.keyword-chip {
  padding: 4px 7px;
  border: 1px solid #d7e8e2;
  border-radius: 6px;
  background: #f5fbf8;
  color: #36514b;
  font-size: 12px;
  line-height: 1.35;
}

body.focus-mode .topbar,
body.focus-mode .control-bar,
body.focus-mode .youtube-browser,
body.focus-mode .favorites-panel {
  display: none;
}

body.focus-mode .app-shell {
  width: min(1900px, calc(100vw - 20px));
  padding-top: 10px;
}

body.focus-mode .workspace {
  margin-top: 0;
  grid-template-columns: minmax(760px, 1.2fr) minmax(500px, 0.8fr);
}

body.focus-mode .subtitle-panel {
  max-height: calc(100vh - 20px);
}

.sentence-actions {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  align-content: flex-start;
  gap: 6px;
  max-width: 154px;
  opacity: 0.78;
}

.sentence-action {
  min-height: 28px;
  padding: 0 8px;
  white-space: nowrap;
}

.sentence-action.is-saved {
  border-color: #c8ddd6;
  background: #edf7f3;
  color: var(--teal);
  cursor: default;
}

.subtitle-item:hover .sentence-actions,
.subtitle-item.active .sentence-actions {
  opacity: 1;
}

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

  .primary-button,
  .ghost-button {
    width: 100%;
  }

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

  .subtitle-panel {
    min-height: 520px;
    max-height: none;
  }

  body.focus-mode .workspace {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 640px),
  (max-width: 950px) and (max-height: 520px) and (orientation: landscape) {
  body {
    min-height: 100dvh;
    overscroll-behavior-y: none;
  }

  .app-shell {
    width: 100%;
    padding: max(10px, env(safe-area-inset-top)) 0 env(safe-area-inset-bottom);
  }

  .topbar {
    display: flex;
    align-items: center;
    margin: 0 12px 10px;
    gap: 10px;
  }

  .topbar h1 {
    font-size: 20px;
    line-height: 1.2;
  }

  .topbar p {
    display: none;
  }

  .status-pill {
    padding: 6px 8px;
    font-size: 12px;
  }

  .control-bar {
    grid-template-columns: minmax(0, 1fr) minmax(118px, 0.42fr);
    gap: 8px;
    margin: 0 10px;
    padding: 10px;
  }

  .url-field {
    grid-column: 1 / -1;
  }

  .url-field > label,
  .url-field span,
  .select-field span {
    font-size: 12px;
  }

  input,
  select,
  .primary-button,
  .ghost-button {
    min-height: 42px;
  }

  .mobile-only {
    display: inline-flex;
    align-items: center;
    justify-content: center;
  }

  .control-actions {
    display: none;
    grid-column: 1 / -1;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 8px;
    padding-top: 2px;
  }

  .control-actions.is-open {
    display: grid;
  }

  .control-actions .ghost-button {
    width: 100%;
  }

  .youtube-browser {
    margin: 10px 10px 0;
    padding: 10px;
  }

  .browser-title {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    align-items: center;
    margin-bottom: 8px;
  }

  .browser-title p {
    display: -webkit-box;
    overflow: hidden;
    -webkit-box-orient: vertical;
    -webkit-line-clamp: 2;
  }

  .youtube-account-actions {
    justify-content: flex-end;
  }

  .youtube-browser.is-collapsed .youtube-browser-content {
    display: none;
  }

  .youtube-tabs {
    flex-wrap: nowrap;
    overflow-x: auto;
    padding-bottom: 2px;
    scrollbar-width: none;
  }

  .youtube-tabs::-webkit-scrollbar,
  .subtitle-filter-buttons::-webkit-scrollbar {
    display: none;
  }

  .youtube-tab {
    flex: 0 0 auto;
  }

  .browser-search {
    grid-template-columns: 1fr;
  }

  .youtube-results {
    grid-template-columns: 1fr;
    max-height: min(46dvh, 420px);
  }

  .youtube-result {
    grid-template-columns: 112px minmax(0, 1fr);
    min-height: 82px;
  }

  .workspace {
    gap: 8px;
    margin-top: 10px;
  }

  .player-panel {
    position: sticky;
    z-index: 20;
    top: 0;
    border-right: 0;
    border-left: 0;
    border-radius: 0;
    box-shadow: 0 8px 24px rgba(24, 32, 29, 0.16);
  }

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

  .meta-row > div:first-child {
    min-width: 0;
  }

  .meta-row strong {
    overflow: hidden;
    font-size: 13px;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  .meta-row span {
    display: none;
  }

  .player-actions {
    display: flex;
    grid-column: 1 / -1;
    grid-row: 2;
    flex-wrap: nowrap;
    justify-content: center;
  }

  .player-actions #youtubeLoginButton,
  .player-actions #openYoutubeButton {
    display: none;
  }

  #backgroundPlayButton,
  #previousEpisodeButton,
  #nextEpisodeButton {
    min-height: 32px;
    padding: 0 8px;
    white-space: nowrap;
  }

  .queue-mode-toggle {
    min-height: 32px;
    padding: 0 7px;
  }

  .queue-mode-toggle span {
    display: block;
  }

  .time-readout {
    min-width: 64px;
    padding: 6px 8px;
    font-size: 13px;
  }

  .subtitle-panel {
    height: calc(100dvh - 56.25vw - 96px - env(safe-area-inset-top));
    min-height: 410px;
    max-height: calc(100dvh - 56.25vw - 96px - env(safe-area-inset-top));
    border-right: 0;
    border-left: 0;
    border-radius: 0;
  }

  .ai-learning-panel {
    top: 0;
    right: 0;
    bottom: 0;
    width: min(100%, 480px);
    min-height: 100dvh;
    max-height: 100dvh;
    border-radius: 0;
  }

  .learning-header {
    padding: 11px 12px;
  }

  .learning-summary {
    padding: 10px 12px;
  }

  .learning-toolbar {
    padding: 8px 10px;
  }

  .learning-toolbar .small-button {
    flex: 1 1 auto;
  }

  .learning-categories {
    padding: 6px 8px calc(16px + env(safe-area-inset-bottom));
  }

  .subtitle-header {
    align-items: flex-start;
    padding: 10px 12px;
  }

  .subtitle-header h2 {
    font-size: 18px;
  }

  .subtitle-toggles {
    gap: 8px;
  }

  .compact-toggle {
    min-height: 32px;
    gap: 5px;
    font-size: 12px;
  }

  .compact-toggle input {
    width: 18px;
    min-height: 18px;
  }

  .study-strip {
    grid-template-columns: 1fr;
    padding: 8px 10px 0;
  }

  .study-metrics {
    display: none;
  }

  .focus-line {
    min-height: 54px;
    padding: 7px 9px;
  }

  .subtitle-tools {
    grid-template-columns: minmax(0, 1fr) auto;
    padding: 8px 10px 0;
  }

  .subtitle-tools input {
    grid-column: 1 / -1;
    min-height: 40px;
  }

  .subtitle-filter-buttons {
    min-width: 0;
    flex-wrap: nowrap;
    justify-content: flex-start;
    overflow-x: auto;
    scrollbar-width: none;
  }

  .filter-chip {
    flex: 0 0 auto;
    min-height: 34px;
  }

  #focusModeButton {
    min-height: 34px;
    white-space: nowrap;
  }

  .message,
  .word-lookup,
  .favorites-panel {
    margin-right: 10px;
    margin-left: 10px;
  }

  .message {
    padding: 8px 10px;
    font-size: 13px;
  }

  .word-lookup {
    max-height: 180px;
    overflow: auto;
  }

  .icon-button,
  .small-button {
    min-height: 36px;
  }

  .icon-button {
    width: 36px;
    height: 36px;
  }

  .favorites-list {
    max-height: 140px;
  }

  .subtitle-list {
    padding: 6px 6px calc(18px + env(safe-area-inset-bottom));
  }

  .subtitle-item {
    grid-template-columns: 46px minmax(0, 1fr) 70px;
    gap: 6px;
    padding: 9px 7px;
  }

  .subtitle-time {
    font-size: 12px;
  }

  .subtitle-original {
    font-size: 16px;
    line-height: 1.55;
  }

  .subtitle-translation {
    font-size: 14px;
  }

  .sentence-actions {
    display: grid;
    grid-template-columns: repeat(2, 32px);
    align-content: start;
    justify-content: end;
    gap: 5px;
    width: 69px;
    max-width: 69px;
    margin-top: 0;
    opacity: 1;
  }

  .sentence-action {
    width: 32px;
    min-height: 32px;
    padding: 0;
    overflow: hidden;
    font-size: 0;
  }

  .sentence-action::after {
    content: attr(data-mobile-label);
    font-size: 12px;
  }

  body.focus-mode .app-shell {
    width: 100%;
    padding-top: 0;
  }

  body.focus-mode .workspace {
    gap: 8px;
  }

  body.focus-mode .subtitle-panel {
    max-height: calc(100dvh - 56.25vw - 96px);
  }
}

@media (max-width: 950px) and (max-height: 520px) and (orientation: landscape) {
  .app-shell {
    padding-top: 0;
  }

  .topbar {
    display: none;
  }

  .workspace {
    grid-template-columns: minmax(0, 1.25fr) minmax(330px, 0.95fr);
    gap: 0;
  }

  .player-panel {
    position: sticky;
    top: 0;
  }

  .subtitle-panel,
  body.focus-mode .subtitle-panel {
    height: 100dvh;
    min-height: 100dvh;
    max-height: 100dvh;
  }

  .subtitle-header {
    min-height: 46px;
    align-items: center;
    padding: 6px 10px;
  }

  .subtitle-header p,
  .subtitle-toggles,
  .study-strip,
  .message,
  .favorites-panel {
    display: none;
  }

  .subtitle-tools {
    grid-template-columns: minmax(0, 1fr) auto;
    padding: 6px 8px;
  }

  .subtitle-tools input {
    grid-column: 1 / -1;
    min-height: 36px;
  }

  .filter-chip,
  #focusModeButton {
    min-height: 30px;
  }

  .subtitle-list {
    padding-top: 4px;
  }
}
