:root {
  color-scheme: light;
  --bg: #ffffff;
  --panel: #ffffff;
  --panel-muted: #f6f6f6;
  --text: #111111;
  --muted: #666666;
  --border: #dddddd;
  --border-strong: #b8b8b8;
  --accent: #111111;
  --danger: #b42318;
  --success: #16703c;
  --mark: #fff1a8;
  --radius: 4px;
  --tap: 44px;
  --page-max: 1180px;
}

body.dark {
  color-scheme: dark;
  --bg: #111111;
  --panel: #151515;
  --panel-muted: #1f1f1f;
  --text: #f2f2f2;
  --muted: #aaaaaa;
  --border: #333333;
  --border-strong: #555555;
  --accent: #ffffff;
  --danger: #ff8a80;
  --success: #8ee6ad;
  --mark: #5b4b00;
}

* {
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
}

html {
  min-height: 100%;
  text-size-adjust: 100%;
  -webkit-text-size-adjust: 100%;
}

body {
  min-height: 100%;
  margin: 0;
  overflow-x: hidden;
  background: var(--bg);
  color: var(--text);
  font-family: ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", "Microsoft YaHei", "PingFang SC", sans-serif;
  line-height: 1.4;
}

button,
input,
select {
  font: inherit;
}

button,
select {
  cursor: pointer;
}

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

input,
select,
textarea {
  font-size: 16px;
}

svg {
  display: block;
}

.hidden {
  display: none !important;
}

.app-header {
  position: sticky;
  top: 0;
  z-index: 20;
  max-width: var(--page-max);
  margin: 0 auto;
  padding: max(12px, env(safe-area-inset-top)) 18px 12px;
  border-bottom: 1px solid var(--border);
  background: color-mix(in srgb, var(--bg) 94%, transparent);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
}

.plain-button {
  min-height: 38px;
  border: 0;
  background: transparent;
  color: var(--muted);
  padding: 7px 9px;
  border-radius: var(--radius);
  touch-action: manipulation;
}

.plain-button:hover,
.plain-button.active {
  color: var(--text);
  background: var(--panel-muted);
}

.brand-button {
  color: var(--text);
  font-weight: 700;
  font-size: 1.15rem;
  letter-spacing: -0.02em;
  white-space: nowrap;
}

.top-nav {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 6px;
  min-width: 0;
}

.icon-nav-button {
  width: 38px;
  height: 38px;
  display: grid;
  place-items: center;
}

.icon-nav-button svg {
  width: 20px;
  height: 20px;
  fill: currentColor;
}

.app-shell {
  max-width: var(--page-max);
  margin: 0 auto;
  padding: 18px 18px calc(36px + env(safe-area-inset-bottom));
}

.page {
  display: none;
}

.page.active {
  display: block;
}

.toolbar {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 160px auto;
  gap: 12px;
  align-items: end;
  margin-bottom: 16px;
}

.search,
.select {
  display: grid;
  gap: 6px;
  min-width: 0;
}

.search span,
.select span {
  color: var(--muted);
  font-size: 0.86rem;
}

.search input,
.select select {
  width: 100%;
  min-height: var(--tap);
  border: 1px solid var(--border);
  background: var(--panel);
  color: var(--text);
  border-radius: var(--radius);
  padding: 10px 11px;
  outline: none;
}

.search input:focus,
.select select:focus {
  border-color: var(--accent);
}

.simple-status {
  min-height: var(--tap);
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 12px;
  color: var(--muted);
  white-space: nowrap;
  font-size: 0.92rem;
}

.content {
  display: grid;
  grid-template-columns: minmax(260px, 360px) minmax(0, 1fr);
  gap: 16px;
  align-items: start;
}

.list-panel,
.player-card,
.settings-card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}

.list-panel {
  min-height: 520px;
  max-height: calc(100vh - 160px);
  overflow: auto;
  padding: 6px;
  overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
}

.empty {
  min-height: 280px;
  display: grid;
  place-content: center;
  text-align: center;
  color: var(--muted);
  gap: 6px;
  padding: 24px;
}

.empty strong {
  color: var(--text);
  font-weight: 650;
}

.result-list {
  display: grid;
  gap: 2px;
}

.result-item {
  width: 100%;
  min-height: var(--tap);
  text-align: left;
  background: transparent;
  color: var(--text);
  border: 1px solid transparent;
  border-radius: var(--radius);
  padding: 12px 11px;
  display: grid;
  gap: 4px;
  touch-action: manipulation;
}

.result-item:hover {
  background: var(--panel-muted);
}

.result-item.active {
  border-color: var(--border-strong);
  background: var(--panel-muted);
}

.result-title {
  font-weight: 650;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.result-meta {
  min-height: 1em;
  color: var(--muted);
  font-size: 0.84rem;
}

.result-meta:empty {
  display: none;
}

.cache-badge {
  color: var(--success);
  font-weight: 650;
}

.player-panel {
  position: sticky;
  top: 72px;
}

.player-card {
  overflow: hidden;
}

.mobile-close-button {
  display: none;
}

.video-wrap {
  position: relative;
  aspect-ratio: 16 / 9;
  background: #000;
}

.video-wrap video {
  width: 100%;
  height: 100%;
  display: block;
  object-fit: contain;
  background: #000;
}

.video-wrap video:not([src]) {
  display: none;
}

.player-placeholder {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  color: #fff;
  text-align: center;
  padding: 20px;
  background: #111;
}

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

.player-placeholder span {
  border: 1px solid rgba(255, 255, 255, 0.28);
  border-radius: var(--radius);
  padding: 9px 12px;
  background: rgba(255, 255, 255, 0.08);
}

.player-info {
  padding: 16px;
}

.player-info h1 {
  margin: 0;
  font-size: clamp(1.25rem, 3vw, 2rem);
  letter-spacing: -0.03em;
  word-break: break-word;
}

.player-info p {
  margin: 8px 0 0;
  color: var(--muted);
  word-break: break-word;
  overflow-wrap: anywhere;
  font-size: 0.92rem;
}

.player-actions,
.speed-controls,
.button-row {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  margin-top: 14px;
  align-items: center;
}

.speed-controls {
  overflow-x: auto;
  flex-wrap: nowrap;
  padding-bottom: 2px;
  scrollbar-width: none;
  -webkit-overflow-scrolling: touch;
}

.speed-controls::-webkit-scrollbar {
  display: none;
}

.speed-controls span {
  flex: 0 0 auto;
  color: var(--muted);
  font-size: 0.9rem;
  margin-right: 2px;
}

.player-actions button,
.speed-controls button,
.secondary-button {
  min-height: var(--tap);
  background: var(--panel);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 8px 12px;
  touch-action: manipulation;
}

.speed-controls button {
  flex: 0 0 auto;
  min-width: 64px;
}

.icon-control-button {
  width: 56px;
  display: inline-grid;
  place-items: center;
}

.icon-control-button svg {
  width: 24px;
  height: 24px;
  fill: currentColor;
}

.player-actions button:hover,
.speed-controls button:hover,
.secondary-button:hover:not(:disabled) {
  border-color: var(--accent);
}

.speed-controls button.active {
  color: var(--bg);
  background: var(--accent);
  border-color: var(--accent);
}

.danger-button {
  color: var(--danger);
}

.danger-button:hover:not(:disabled) {
  border-color: var(--danger);
}

mark {
  background: var(--mark);
  color: var(--text);
  border-radius: 2px;
  padding: 0 1px;
}

.settings-header {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 18px;
}

.settings-header h1 {
  margin: 0;
  font-size: clamp(1.6rem, 6vw, 2rem);
  letter-spacing: -0.04em;
}

.settings-grid {
  display: grid;
  gap: 14px;
  grid-template-columns: minmax(0, 620px);
}

.settings-card {
  padding: 16px;
}

.settings-card h2 {
  margin: 0 0 14px;
  font-size: 1.05rem;
}

.language-select {
  max-width: 240px;
  margin-bottom: 12px;
}

.settings-card dl {
  margin: 14px 0 0;
  display: grid;
  gap: 12px;
}

.settings-card dl div {
  display: grid;
  gap: 4px;
}

.settings-card dt {
  color: var(--muted);
  font-size: 0.86rem;
}

.settings-card dd {
  margin: 0;
  word-break: break-word;
  overflow-wrap: anywhere;
}

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

.success {
  color: var(--success);
}

@supports (height: 100dvh) {
  .list-panel {
    max-height: calc(100dvh - 160px);
  }
}

@media (hover: none) {
  .plain-button:hover,
  .result-item:hover,
  .player-actions button:hover,
  .speed-controls button:hover,
  .secondary-button:hover:not(:disabled) {
    border-color: var(--border);
    background: inherit;
  }

  .plain-button.active,
  .result-item.active {
    background: var(--panel-muted);
  }

  .speed-controls button.active {
    background: var(--accent);
  }
}

@media (max-width: 900px) {
  .app-header {
    max-width: none;
  }

  .app-shell {
    padding-top: 14px;
  }

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

  .simple-status {
    justify-content: flex-start;
    min-height: auto;
    flex-wrap: wrap;
  }

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

  .player-panel {
    display: none;
  }

  .list-panel {
    max-height: none;
    min-height: calc(100dvh - 230px);
  }

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

  body.mobile-player-open {
    overflow: hidden;
    position: fixed;
    inset: 0;
    width: 100%;
  }

  body.mobile-player-open .player-panel {
    position: fixed;
    inset: 0;
    z-index: 100;
    display: block;
    overflow-y: auto;
    overscroll-behavior: contain;
    -webkit-overflow-scrolling: touch;
    padding: max(10px, env(safe-area-inset-top)) 10px max(16px, env(safe-area-inset-bottom));
    background: var(--bg);
  }

  body.mobile-player-open .player-card {
    min-height: calc(100dvh - max(10px, env(safe-area-inset-top)) - max(16px, env(safe-area-inset-bottom)));
    display: flex;
    flex-direction: column;
    position: relative;
  }

  body.mobile-player-open .video-wrap {
    flex: 0 0 auto;
  }

  body.mobile-player-open .player-info {
    flex: 1 1 auto;
  }

  .mobile-close-button {
    position: sticky;
    top: 0;
    z-index: 2;
    align-self: flex-end;
    width: 44px;
    height: 44px;
    margin: 8px 8px -52px 0;
    display: grid;
    place-items: center;
    border: 1px solid rgba(255, 255, 255, 0.35);
    background: rgba(0, 0, 0, 0.65);
    color: #fff;
    border-radius: 999px;
    touch-action: manipulation;
  }

  .mobile-close-button svg {
    width: 22px;
    height: 22px;
    fill: currentColor;
  }
}

@media (max-width: 640px) {
  :root {
    --tap: 46px;
  }

  .app-header {
    padding: max(10px, env(safe-area-inset-top)) 12px 10px;
    gap: 8px;
  }

  .brand-button {
    max-width: 52vw;
    overflow: hidden;
    text-overflow: ellipsis;
  }

  .top-nav {
    gap: 2px;
  }

  .plain-button {
    min-height: 40px;
    padding: 7px 8px;
  }

  .icon-nav-button {
    width: 40px;
    height: 40px;
  }

  .app-shell {
    padding: 12px 12px calc(24px + env(safe-area-inset-bottom));
  }

  .toolbar {
    margin-bottom: 12px;
  }

  .search input,
  .select select {
    padding: 10px;
  }

  .content {
    gap: 12px;
  }

  .player-info {
    padding: 12px;
  }

  .player-info h1 {
    font-size: 1.35rem;
  }

  .player-info p {
    font-size: 0.88rem;
  }

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

  .player-actions button {
    width: 100%;
  }

  .icon-control-button {
    width: auto;
  }

  .speed-controls {
    margin-left: -12px;
    margin-right: -12px;
    padding-left: 12px;
    padding-right: 12px;
  }

  .list-panel {
    padding: 4px;
  }

  .result-item {
    padding: 13px 10px;
  }

  .settings-card {
    padding: 14px;
  }

  .button-row {
    display: grid;
    grid-template-columns: 1fr;
    gap: 8px;
  }

  .button-row .secondary-button {
    width: 100%;
  }

  .language-select {
    max-width: none;
  }

  body.mobile-player-open .player-panel {
    padding-left: 0;
    padding-right: 0;
    padding-bottom: 0;
  }

  body.mobile-player-open .player-card {
    border-left: 0;
    border-right: 0;
    border-bottom: 0;
    min-height: calc(100dvh - max(10px, env(safe-area-inset-top)));
  }
}

@media (max-width: 420px) {
  .app-header {
    align-items: stretch;
    flex-direction: column;
  }

  .brand-button {
    max-width: 100%;
    align-self: flex-start;
  }

  .top-nav {
    width: 100%;
    justify-content: space-between;
  }

  .simple-status {
    gap: 8px;
    font-size: 0.86rem;
  }

  .video-wrap {
    aspect-ratio: 4 / 3;
  }

  .result-title,
  .result-meta {
    white-space: normal;
    display: -webkit-box;
    -webkit-box-orient: vertical;
  }

  .result-title {
    -webkit-line-clamp: 2;
  }

  .result-meta {
    -webkit-line-clamp: 1;
  }
}

@media (max-width: 900px) {
  html,
  body {
    min-height: 100%;
    height: auto;
    overflow-x: hidden;
  }

  body:not(.mobile-player-open) {
    position: static !important;
    inset: auto !important;
    top: auto !important;
    width: auto !important;
    height: auto !important;
    overflow-y: auto !important;
  }

  #dictionaryPage.active {
    display: flex;
    flex-direction: column;
    min-height: calc(100dvh - 86px);
  }

  #dictionaryPage.active .toolbar {
    flex: 0 0 auto;
  }

  #dictionaryPage.active .content {
    flex: 1 1 auto;
    min-height: 0;
    display: flex;
    flex-direction: column;
  }

  #dictionaryPage.active .list-panel {
    flex: 1 1 auto;
    height: calc(100dvh - 230px);
    min-height: 260px;
    max-height: none;
    overflow-y: auto;
    overflow-x: hidden;
    overscroll-behavior-y: auto;
    touch-action: pan-y;
    -webkit-overflow-scrolling: touch;
  }

  body.mobile-player-open {
    overflow: hidden !important;
    position: fixed !important;
    inset: 0 !important;
    width: 100% !important;
    height: 100dvh !important;
  }

  body.mobile-player-open .player-panel {
    height: 100dvh;
    max-height: 100dvh;
    overflow-y: auto;
    overflow-x: hidden;
    touch-action: pan-y;
  }
}

@media (max-width: 640px) {
  #dictionaryPage.active {
    min-height: calc(100dvh - 132px);
  }

  #dictionaryPage.active .list-panel {
    height: calc(100dvh - 276px);
    min-height: 240px;
  }
}

@media (max-width: 420px) {
  #dictionaryPage.active {
    min-height: calc(100dvh - 172px);
  }

  #dictionaryPage.active .list-panel {
    height: calc(100dvh - 316px);
    min-height: 220px;
  }
}
