: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;
}

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

.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);
}

.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);
}

.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 span,
.select-field span {
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
}

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 {
  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;
}

.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);
}

.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;
  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) {
  .app-shell {
    width: min(100vw - 20px, 1480px);
    padding: 14px 0;
  }

  .topbar {
    display: grid;
  }

  .control-bar {
    grid-template-columns: 1fr;
  }

  .browser-title {
    display: grid;
  }

  .browser-title span {
    padding-top: 0;
  }

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

  .youtube-results {
    grid-template-columns: 1fr;
    max-height: 320px;
  }

  .youtube-result {
    grid-template-columns: 104px minmax(0, 1fr);
  }

  .study-strip,
  .subtitle-tools {
    grid-template-columns: 1fr;
  }

  .subtitle-filter-buttons {
    justify-content: flex-start;
  }

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

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

  .subtitle-item {
    grid-template-columns: 54px minmax(0, 1fr);
    gap: 5px;
  }

  .sentence-actions {
    grid-column: 2;
    justify-content: flex-start;
    max-width: none;
  }
}
