:root {
  --bg: #f4efe3;
  --panel: #fffdfa;
  --ink: #222325;
  --muted: #6c6d72;
  --line: #ddd3c2;
  --shadow: 0 18px 42px rgba(24, 24, 22, 0.12);
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  padding: 0;
  font-family: "Segoe UI", "Noto Sans TC", sans-serif;
  background:
    radial-gradient(circle at top left, rgba(225, 198, 136, 0.2), transparent 28%),
    radial-gradient(circle at right 10%, rgba(127, 156, 135, 0.12), transparent 24%),
    var(--bg);
  color: var(--ink);
}

body.menu-open {
  overflow: hidden;
}

.page {
  max-width: 980px;
  margin: 0 auto;
  padding: 12px 10px 24px;
}

.main-stack {
  display: grid;
  gap: 12px;
}

.player-card,
.panel-card,
.drawer-card {
  background: var(--panel);
  border: 1px solid rgba(132, 120, 103, 0.14);
  border-radius: 24px;
  box-shadow: var(--shadow);
}

.player-card {
  padding: 10px;
}

.player-stage {
  position: relative;
  border-radius: 20px;
  overflow: hidden;
  background: #101010;
}

.player-shell {
  position: relative;
  width: 100%;
  aspect-ratio: 16 / 9;
}

#player,
#player iframe {
  width: 100%;
  height: 100%;
}

.fullscreen-btn,
.menu-toggle {
  border: 0;
  cursor: pointer;
  box-shadow: var(--shadow);
}

.fullscreen-btn {
  position: absolute;
  right: 10px;
  top: 10px;
  z-index: 4;
  width: 38px;
  height: 38px;
  border-radius: 999px;
  background: rgba(14, 14, 14, 0.72);
  color: white;
  font-size: 18px;
}

.subtitle-overlay {
  position: absolute;
  inset: 0;
  display: none;
  align-items: flex-end;
  justify-content: center;
  padding: 12px 12px calc(18px + env(safe-area-inset-bottom, 0px));
  pointer-events: none;
  z-index: 3;
}

.overlay-inner {
  width: min(82%, 980px);
  display: block;
}

.subtitle-strip {
  margin-top: 10px;
  padding: 4px 2px 0;
}

.subtitle-text {
  word-break: break-word;
}

.subtitle-text-strip {
  font-size: clamp(19px, 5.2vw, 28px);
  line-height: 1.52;
  font-weight: 780;
  color: #1d1d1f;
}

.subtitle-text-overlay {
  background: rgba(10, 10, 10, 0.74);
  color: #f6f3ec;
  border-radius: 18px;
  padding: 10px 12px;
  font-size: clamp(18px, 4.8vw, 28px);
  line-height: 1.56;
  font-weight: 760;
  text-align: center;
  text-shadow: 0 1px 2px rgba(0, 0, 0, 0.46);
  pointer-events: auto;
}

.subtitle-token {
  display: inline;
  padding: 0;
}

.subtitle-token.clickable {
  cursor: pointer;
}

.subtitle-token.clickable:hover {
  filter: brightness(1.08);
}

.subtitle-text-strip .subtitle-token.token-new-high { color: #b26b00; }
.subtitle-text-strip .subtitle-token.token-new-mid { color: #18724f; }
.subtitle-text-strip .subtitle-token.token-new-low { color: #245eb8; }
.subtitle-text-strip .subtitle-token.token-review1-high { color: #c18718; }
.subtitle-text-strip .subtitle-token.token-review1-mid { color: #2f8a66; }
.subtitle-text-strip .subtitle-token.token-review1-low { color: #4f78c7; }
.subtitle-text-strip .subtitle-token.token-normal { color: #202124; }
.subtitle-text-strip .subtitle-token.token-missing { color: #8a6f63; }
.subtitle-text-strip .subtitle-token.token-important { color: #b44747; }

.subtitle-text-overlay .subtitle-token.token-new-high { color: #ffd66f; }
.subtitle-text-overlay .subtitle-token.token-new-mid { color: #97ebb8; }
.subtitle-text-overlay .subtitle-token.token-new-low { color: #9ecdff; }
.subtitle-text-overlay .subtitle-token.token-review1-high { color: #ffe2a0; }
.subtitle-text-overlay .subtitle-token.token-review1-mid { color: #c0efd1; }
.subtitle-text-overlay .subtitle-token.token-review1-low { color: #c5d9ff; }
.subtitle-text-overlay .subtitle-token.token-normal { color: #f7f5ef; }
.subtitle-text-overlay .subtitle-token.token-missing { color: #d3c0b6; }
.subtitle-text-overlay .subtitle-token.token-important { color: #ff8a8a; }

.status-bar {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  margin-top: 10px;
  color: var(--muted);
  font-size: 12px;
}

.panel-card {
  padding: 14px;
}

.panel-card h2 {
  margin: 0 0 10px;
  font-size: 16px;
}

.popup-card {
  min-height: 120px;
  border-radius: 18px;
  background: #fbf8f1;
  border: 1px solid var(--line);
  padding: 12px;
}

.popup-card.empty {
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--muted);
}

.popup-stack {
  display: grid;
  gap: 10px;
}

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

.popup-action-group {
  display: flex;
  align-items: center;
  gap: 8px;
}

.word-main {
  font-size: 26px;
  font-weight: 800;
  line-height: 1.08;
}

.word-pinyin {
  color: #47664f;
  font-size: 18px;
  font-weight: 700;
}

.popup-meaning {
  font-size: 18px;
  line-height: 1.45;
  color: #1f2325;
}

.popup-more-btn {
  flex: 0 0 auto;
  width: 30px;
  height: 30px;
  border: 0;
  border-radius: 999px;
  background: #ece5d6;
  color: #47514c;
  font-size: 18px;
  line-height: 1;
  cursor: pointer;
}

.popup-important-btn {
  flex: 0 0 auto;
  width: 30px;
  height: 30px;
  border: 0;
  border-radius: 999px;
  background: #ede4d2;
  color: #9a5656;
  font-size: 18px;
  line-height: 1;
  font-weight: 800;
  cursor: pointer;
}

.popup-important-btn.active {
  background: #b44747;
  color: #fff8f8;
}

.popup-extra {
  display: none;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px 14px;
  padding-top: 2px;
}

.popup-card.expanded .popup-extra {
  display: grid;
}

.popup-extra .meta-row:last-child {
  grid-column: 1 / -1;
}

.meta-row {
  display: grid;
  gap: 4px;
}

.meta-label {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--muted);
}

.compact-popup {
  display: none;
  position: absolute;
  top: 12px;
  right: 12px;
  z-index: 5;
  width: min(36vw, 220px);
  min-height: 72px;
  border-radius: 16px;
  padding: 9px 11px;
  background: rgba(12, 12, 12, 0.82);
  color: white;
  backdrop-filter: blur(10px);
  box-shadow: 0 16px 34px rgba(0, 0, 0, 0.28);
}

.compact-popup.empty {
  display: none;
}

.compact-title {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: rgba(255, 255, 255, 0.68);
}

.compact-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.compact-word {
  margin-top: 4px;
  font-size: 18px;
  font-weight: 800;
}

.compact-pinyin {
  margin-top: 2px;
  color: #bfead2;
  font-size: 12px;
  font-weight: 700;
}

.compact-meaning {
  margin-top: 6px;
  font-size: 12px;
  line-height: 1.35;
}

.compact-important-btn {
  flex: 0 0 auto;
  width: 24px;
  height: 24px;
  border: 0;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.14);
  color: #ffd6d6;
  font-size: 15px;
  line-height: 1;
  font-weight: 800;
  cursor: pointer;
}

.compact-important-btn.active {
  background: #b44747;
  color: #fff8f8;
}

.menu-toggle {
  position: fixed;
  left: 12px;
  top: 12px;
  z-index: 10001;
  width: 48px;
  height: 48px;
  border-radius: 16px;
  background: rgba(18, 18, 18, 0.84);
  display: grid;
  place-content: center;
  gap: 5px;
}

.menu-toggle span {
  width: 18px;
  height: 2px;
  border-radius: 999px;
  background: white;
  display: block;
}

.star-toggle {
  position: fixed;
  right: 12px;
  top: 12px;
  z-index: 10001;
  width: 48px;
  height: 48px;
  border: 0;
  border-radius: 16px;
  background: rgba(18, 18, 18, 0.84);
  color: #fff5c2;
  font-size: 24px;
  box-shadow: var(--shadow);
  cursor: pointer;
}

.menu-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.32);
  backdrop-filter: blur(4px);
  opacity: 0;
  pointer-events: none;
  transition: opacity 160ms ease;
  z-index: 9998;
}

.important-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.24);
  backdrop-filter: blur(4px);
  opacity: 0;
  pointer-events: none;
  transition: opacity 160ms ease;
  z-index: 9996;
}

.setup-drawer {
  position: fixed;
  inset: 0 0 0 auto;
  width: min(88vw, 380px);
  background: #fffdf8;
  box-shadow: -18px 0 36px rgba(0, 0, 0, 0.18);
  padding: 68px 16px 20px;
  overflow-y: auto;
  transform: translateX(104%);
  transition: transform 180ms ease;
  z-index: 9999;
}

body.menu-open .menu-backdrop {
  opacity: 1;
  pointer-events: auto;
}

body.menu-open .setup-drawer {
  transform: translateX(0);
}

body.important-open .important-backdrop {
  opacity: 1;
  pointer-events: auto;
}

.drawer-head h1 {
  margin: 0;
  font-size: 26px;
  line-height: 1.06;
}

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

.controls {
  display: grid;
  gap: 12px;
  margin-top: 18px;
}

.control {
  display: grid;
  gap: 8px;
}

.control span {
  font-size: 13px;
  color: var(--muted);
  font-weight: 700;
}

.control input {
  width: 100%;
  padding: 12px 13px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: white;
  font-size: 16px;
}

.actions {
  display: grid;
  gap: 10px;
}

.actions button {
  width: 100%;
  border: 0;
  border-radius: 14px;
  padding: 12px 15px;
  cursor: pointer;
  font-size: 16px;
  font-weight: 800;
  color: white;
  background: #305453;
}

.actions button.secondary {
  background: #7d8f59;
}

.drawer-card {
  margin-top: 16px;
  padding: 14px;
}

.drawer-card h2 {
  margin: 0 0 10px;
  font-size: 16px;
}

.legend {
  display: grid;
  gap: 10px;
}

.legend-item {
  display: flex;
  gap: 10px;
  align-items: center;
  font-size: 13px;
}

.swatch {
  width: 16px;
  height: 16px;
  border-radius: 6px;
  display: inline-block;
}

.swatch.token-new-high { background: #b26b00; }
.swatch.token-new-mid { background: #18724f; }
.swatch.token-new-low { background: #245eb8; }
.swatch.token-review1-high { background: #c18718; }
.swatch.token-review1-mid { background: #2f8a66; }
.swatch.token-review1-low { background: #4f78c7; }
.swatch.token-normal { background: #5e6166; }
.swatch.token-missing { background: #8a6f63; }
.swatch.token-important { background: #b44747; }

body.fullscreen-active .subtitle-overlay {
  display: flex;
  align-items: flex-end;
  padding: 12px 12px calc(18px + env(safe-area-inset-bottom, 0px));
}

body.fullscreen-active .subtitle-strip,
body.fullscreen-active .status-bar,
body.fullscreen-active .popup-section,
body.fullscreen-active .menu-toggle,
body.fullscreen-active .menu-backdrop,
body.fullscreen-active .setup-drawer {
  display: none !important;
}

body.fullscreen-active .compact-popup:not(.empty) {
  display: block;
}

#playerStage:fullscreen,
#playerStage:-webkit-full-screen {
  width: 100vw;
  height: 100vh;
  max-width: none;
  background: #000;
}

#playerStage:fullscreen .player-shell,
#playerStage:-webkit-full-screen .player-shell {
  width: 100%;
  height: 100%;
  aspect-ratio: auto;
}

body.fullscreen-active .overlay-inner {
  width: min(78%, 1180px);
}

body.fullscreen-active .subtitle-text-overlay {
  padding: 8px 12px;
  font-size: clamp(14px, 2.6vw, 21px);
  line-height: 1.42;
}

@media (min-width: 900px) {
  .page {
    padding: 18px 16px 30px;
  }

  .main-stack {
    gap: 16px;
  }

  .subtitle-text-strip {
    font-size: 28px;
  }

  .subtitle-text-overlay {
    font-size: 28px;
  }

  .compact-popup {
    width: 240px;
  }
}

.link-btn {
  width: 100%;
  border-radius: 14px;
  padding: 12px 15px;
  display: inline-flex;
  justify-content: center;
  align-items: center;
  background: #efe7d4;
  color: #2f3b33;
  text-decoration: none;
  font-size: 15px;
  font-weight: 800;
  border: 1px solid var(--line);
}

.reading-page {
  max-width: 920px;
}

.reading-stack {
  gap: 14px;
}

.reading-hero {
  padding: 16px;
}

.reading-hero-head {
  display: grid;
  gap: 10px;
}

.reading-hero h1 {
  margin: 0;
  font-size: 28px;
  line-height: 1.04;
}

.reading-hero p {
  margin: 8px 0 0;
  color: var(--muted);
  line-height: 1.45;
}

.reading-stats {
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
}

.reading-panel {
  padding: 12px;
}

.reading-blocks {
  display: grid;
  gap: 14px;
}

.reading-blocks.empty {
  min-height: 180px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--muted);
}

.reading-block {
  background: #fbf8f1;
  border: 1px solid var(--line);
  border-radius: 20px;
  padding: 14px 14px 16px;
}

.reading-block-meta {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
  margin-bottom: 10px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}

.reading-block-meta-left {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.reading-speaker-badge {
  display: inline-flex;
  align-items: center;
  padding: 4px 9px;
  border-radius: 999px;
  background: #2d3434;
  color: #f5f1e8;
  font-size: 11px;
  letter-spacing: 0.04em;
}

.reading-block-text {
  font-size: clamp(20px, 6vw, 31px);
  line-height: 1.9;
  font-weight: 770;
  color: #1d1d1f;
  word-break: break-word;
}

.reading-token {
  display: inline;
  padding: 0;
}

.reading-token.clickable {
  cursor: pointer;
}

.reading-token.clickable:hover {
  filter: brightness(1.08);
}

.reading-block-text .reading-token.token-new-high { color: #b26b00; }
.reading-block-text .reading-token.token-new-mid { color: #18724f; }
.reading-block-text .reading-token.token-new-low { color: #245eb8; }
.reading-block-text .reading-token.token-review1-high { color: #c18718; }
.reading-block-text .reading-token.token-review1-mid { color: #2f8a66; }
.reading-block-text .reading-token.token-review1-low { color: #4f78c7; }
.reading-block-text .reading-token.token-normal { color: #202124; }
.reading-block-text .reading-token.token-missing { color: #8a6f63; }
.reading-block-text .reading-token.token-important { color: #b44747; }

.reading-popup-section {
  position: sticky;
  bottom: 0;
  z-index: 20;
  backdrop-filter: blur(8px);
}

.important-drawer {
  position: fixed;
  inset: 0 0 0 auto;
  width: min(82vw, 360px);
  background: #fffdf8;
  box-shadow: -18px 0 36px rgba(0, 0, 0, 0.18);
  padding: 72px 16px 20px;
  overflow-y: auto;
  transform: translateX(104%);
  transition: transform 180ms ease;
  z-index: 9997;
}

body.important-open .important-drawer {
  transform: translateX(0);
}

.important-drawer-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 14px;
}

.important-drawer-head h2 {
  margin: 0;
  font-size: 20px;
}

.important-count {
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}

.important-list {
  display: grid;
  gap: 10px;
}

.important-list.empty {
  color: var(--muted);
}

.important-item {
  width: 100%;
  text-align: left;
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 12px;
  background: #fbf8f1;
  cursor: pointer;
}

.important-item-head {
  display: flex;
  justify-content: space-between;
  gap: 8px;
  align-items: baseline;
}

.important-item-word {
  font-size: 20px;
  font-weight: 800;
  color: #1e2023;
}

.important-item-pinyin {
  font-size: 14px;
  font-weight: 700;
  color: #47664f;
}

.important-item-meta {
  margin-top: 6px;
  color: var(--muted);
  font-size: 12px;
}

.important-item-snippet {
  margin-top: 6px;
  color: #4f5358;
  font-size: 13px;
  line-height: 1.4;
}

.auth-control {
  gap: 10px;
}

.auth-inline {
  display: grid;
  grid-template-columns: 1fr;
  gap: 10px;
}

.cloud-status {
  font-size: 0.95rem;
  color: #6d6558;
}

.cloud-status.is-on {
  color: #2f6f61;
}

.cloud-status.is-error {
  color: #b44747;
}

.reading-block.important-target {
  box-shadow: 0 0 0 3px rgba(180, 71, 71, 0.22);
  border-color: rgba(180, 71, 71, 0.5);
}

@media (min-width: 720px) {
  .auth-inline {
    grid-template-columns: minmax(0, 1fr) auto auto;
    align-items: center;
  }
}

@media (min-width: 900px) {
  .reading-hero-head {
    grid-template-columns: 1fr auto;
    align-items: end;
  }

  .reading-panel {
    padding: 16px;
  }

  .reading-block {
    padding: 18px 18px 20px;
  }

  .reading-popup-section {
    bottom: 0;
  }
}

@media (max-width: 560px) {
  .word-main {
    font-size: 24px;
  }

  .word-pinyin {
    font-size: 16px;
  }

  .popup-meaning {
    font-size: 16px;
  }

  .popup-extra {
    grid-template-columns: 1fr;
    gap: 10px;
  }

  .popup-extra .meta-row:last-child {
    grid-column: auto;
  }
}
