@import url('./themes.css');

*, *::before, *::after { margin: 0; padding: 0; box-sizing: border-box; }
*, *::before, *::after { transition: background-color 200ms ease, color 200ms ease, border-color 200ms ease; }
* { scrollbar-width: thin; scrollbar-color: var(--scrollbar-thumb) var(--scrollbar-track); }
::-webkit-scrollbar { width: 8px; height: 8px; }
::-webkit-scrollbar-track { background: var(--scrollbar-track); }
::-webkit-scrollbar-thumb { background: var(--scrollbar-thumb); border-radius: var(--radius-full); }
::-webkit-scrollbar-thumb:hover { background: var(--text-muted); }

html {
  font-family: var(--font-family);
  font-size: 16px;
  color: var(--text-primary);
  background: var(--bg-primary);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  overflow: hidden;
  height: 100%;
}
body { height: 100%; overflow: hidden; }
a { color: inherit; text-decoration: none; }
button { cursor: pointer; border: none; background: none; font: inherit; color: inherit; }
input, select { font: inherit; color: inherit; }
img { display: block; max-width: 100%; }

#app {
  display: flex;
  flex-direction: column;
  height: 100%;
}

/* Pages */
.page { display: none; flex: 1; overflow-y: auto; overflow-x: hidden; padding-bottom: 80px; }
.page.active { display: block; animation: fadeIn 0.2s ease; }
.page-header { padding: 16px 16px 8px; font-size: 1.5rem; font-weight: 800; }
.page-body { padding: 0 0 80px; }
.page-header--detail { display: flex; align-items: center; gap: 8px; padding: 12px 16px; font-size: 1.1rem; }
.page-header--detail .page-title { flex: 1; min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

@keyframes fadeIn { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: translateY(0); } }

/* Bottom Nav */
.bottom-nav {
  position: fixed; bottom: 0; left: 0; right: 0; z-index: 90;
  display: flex; background: var(--surface); border-top: 1px solid var(--border);
  height: 56px; padding-bottom: env(safe-area-inset-bottom, 0);
}
.nav-tab {
  flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
  font-size: 0.65rem; font-weight: 500; color: var(--text-secondary); transition: color 0.15s;
  -webkit-tap-highlight-color: transparent;
}
.nav-tab svg { width: 22px; height: 22px; stroke-width: 1.8; fill: none; stroke: currentColor; }
.nav-tab.active { color: var(--accent); }
.nav-tab.active svg { stroke: var(--accent); }

/* Mini Player */
.mini-player {
  position: fixed; left: 0; right: 0; z-index: 80; bottom: 56px; height: 56px;
  display: flex; align-items: center; gap: 12px; padding: 0 12px;
  background: var(--surface); border-top: 1px solid var(--border);
  transform: translateY(100%); transition: transform 0.25s ease;
}
.mini-player.visible { transform: translateY(0); }
.mini-player-progress { position: absolute; top: 0; left: 0; height: 3px; background: var(--accent); border-radius: 0 2px 2px 0; transition: width 0.3s linear; }
.mini-player-content { display: flex; align-items: center; gap: 12px; width: 100%; }
.mini-player-thumb { width: 40px; height: 40px; border-radius: 6px; object-fit: cover; background: var(--surface-alt); flex-shrink: 0; }
.mini-player-info { flex: 1; min-width: 0; }
.mini-player-title { font-size: 0.8rem; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; display: block; }
.mini-player-podcast { font-size: 0.7rem; color: var(--text-secondary); display: block; }
.mini-player-play { width: 36px; height: 36px; display: flex; align-items: center; justify-content: center; flex-shrink: 0; border-radius: 50%; background: var(--accent); color: var(--accent-contrast); }
.mini-player-play svg { width: 18px; height: 18px; fill: currentColor; }

/* Full Player */
.full-player {
  position: fixed; inset: 0; z-index: 200; background: var(--bg-primary);
  display: flex; flex-direction: column; align-items: center;
  padding: 24px 24px calc(24px + env(safe-area-inset-bottom, 0));
  transform: translateY(100%); transition: transform 0.3s ease; overflow-y: auto;
}
.full-player.open { transform: translateY(0); }
.full-player-content { width: 100%; max-width: 480px; display: flex; flex-direction: column; align-items: center; }
.full-player-close { align-self: flex-end; width: 32px; height: 32px; display: flex; align-items: center; justify-content: center; border-radius: 50%; color: var(--text-secondary); }
.full-player-close:hover { background: var(--surface-alt); }
.full-player-close svg { width: 20px; height: 20px; stroke: currentColor; fill: none; stroke-width: 2; }
.full-player-art { width: min(280px, 70vw); height: min(280px, 70vw); border-radius: 16px; object-fit: cover; background: var(--surface-alt); margin: 16px 0 28px; box-shadow: 0 12px 40px rgba(0,0,0,0.25); }
.full-player-meta { text-align: center; margin-bottom: 8px; width: 100%; }
.full-player-title { font-size: 1.15rem; font-weight: 700; line-height: 1.3; max-width: 100%; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.full-player-podcast { font-size: 0.85rem; color: var(--accent); margin-top: 4px; }
.full-player-progress { width: 100%; max-width: 480px; margin-top: 16px; }
.progress-slider {
  -webkit-appearance: none; width: 100%; height: 4px; background: var(--border); border-radius: 2px; outline: none; cursor: pointer;
}
.progress-slider::-webkit-slider-thumb {
  -webkit-appearance: none; width: 14px; height: 14px; border-radius: 50%; background: var(--accent); cursor: pointer;
  box-shadow: 0 1px 4px rgba(0,0,0,0.2);
}
.progress-slider::-moz-range-thumb { width: 14px; height: 14px; border-radius: 50%; background: var(--accent); cursor: pointer; border: none; }
.progress-times { display: flex; justify-content: space-between; margin-top: 8px; font-size: 0.72rem; color: var(--text-secondary); font-variant-numeric: tabular-nums; }
.full-player-controls { display: flex; align-items: center; justify-content: center; gap: 28px; margin-top: 24px; width: 100%; max-width: 320px; }
.btn--lg { width: 48px; height: 48px; display: flex; align-items: center; justify-content: center; border-radius: 50%; color: var(--text-primary); }
.btn--lg:active { transform: scale(0.92); }
.btn--lg svg { width: 28px; height: 28px; stroke: currentColor; fill: none; stroke-width: 2; }
.btn--play-main { width: 64px; height: 64px; background: var(--accent); color: var(--accent-contrast); border-radius: 50%; display: flex; align-items: center; justify-content: center; }
.btn--play-main:active { transform: scale(0.92); }
.btn--play-main svg { width: 28px; height: 28px; fill: currentColor; stroke: none; }
.full-player-speed { font-size: 0.75rem; font-weight: 700; color: var(--text-secondary); padding: 6px 12px; border-radius: var(--radius-full); margin-top: 16px; }
.full-player-speed:hover { background: var(--surface-alt); }

/* Podcast Grid */
.podcast-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; padding: 8px 16px; }
.podcast-card { display: flex; flex-direction: column; transition: transform 0.15s ease; -webkit-tap-highlight-color: transparent; }
.podcast-card:active { transform: scale(0.97); }
@media (hover: hover) { .podcast-card:hover { transform: scale(1.03); } }
.podcast-card__cover { width: 100%; aspect-ratio: 1; border-radius: 10px; object-fit: cover; background: var(--surface-alt); }
.podcast-card__title { font-size: 0.78rem; font-weight: 600; margin-top: 6px; line-height: 1.3; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.podcast-card__author { font-size: 0.68rem; color: var(--text-secondary); margin-top: 1px; }
@media (min-width: 600px) { .podcast-grid { grid-template-columns: repeat(4, 1fr); } }
@media (min-width: 860px) { .podcast-grid { grid-template-columns: repeat(5, 1fr); } }

/* Podcast Detail */
.podcast-detail__header { display: flex; gap: 16px; padding: 16px; align-items: flex-start; }
.podcast-detail__cover { width: 120px; height: 120px; border-radius: 14px; object-fit: cover; background: var(--surface-alt); flex-shrink: 0; box-shadow: 0 4px 16px rgba(0,0,0,0.12); }
.podcast-detail__info { flex: 1; min-width: 0; }
.podcast-detail__title { font-size: 1.1rem; font-weight: 800; line-height: 1.3; }
.podcast-detail__author { font-size: 0.85rem; color: var(--text-secondary); margin-top: 4px; }
.podcast-detail__actions { display: flex; gap: 8px; margin-top: 12px; }
.podcast-detail__desc { font-size: 0.82rem; color: var(--text-secondary); line-height: 1.5; padding: 0 16px 12px; display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical; overflow: hidden; }

/* Episode List */
.episode-list { display: flex; flex-direction: column; }
.episode-row { display: flex; align-items: center; gap: 12px; padding: 12px 16px; border-top: 1px solid var(--border); transition: background 0.12s; -webkit-tap-highlight-color: transparent; position: relative; }
.episode-row:hover { background: var(--bg-secondary); }
.episode-row.playing { background: var(--accent-subtle); }
.episode-row__play { width: 36px; height: 36px; display: flex; align-items: center; justify-content: center; border-radius: 50%; background: var(--accent); color: var(--accent-contrast); flex-shrink: 0; transition: transform 0.1s; }
.episode-row__play:active { transform: scale(0.9); }
.episode-row__play svg { width: 16px; height: 16px; fill: currentColor; stroke: none; }
.episode-row__body { flex: 1; min-width: 0; }
.episode-row__title { font-size: 0.85rem; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.episode-row__meta { display: flex; gap: 10px; font-size: 0.72rem; color: var(--text-secondary); margin-top: 3px; }
.episode-row__progress { width: 100%; height: 3px; background: var(--border); border-radius: 2px; margin-top: 6px; overflow: hidden; }
.episode-row__progress-fill { height: 100%; background: var(--accent); border-radius: 2px; }
.episode-row__download { width: 32px; height: 32px; display: flex; align-items: center; justify-content: center; border-radius: 50%; color: var(--text-secondary); flex-shrink: 0; transition: color 0.15s, background 0.15s; }
.episode-row__download:active { background: var(--surface-alt); }
.episode-row__download svg { width: 18px; height: 18px; stroke: currentColor; fill: none; stroke-width: 1.8; }
.episode-row__download.downloaded { color: var(--accent); }

/* Search */
.search-bar { padding: 12px 16px; position: sticky; top: 0; z-index: 10; background: var(--bg-primary); }
.search-input-wrapper { display: flex; align-items: center; gap: 8px; background: var(--surface); border: 1px solid var(--border); border-radius: 12px; padding: 0 14px; height: 44px; transition: border-color 0.15s; }
.search-input-wrapper:focus-within { border-color: var(--accent); }
.search-icon { width: 18px; height: 18px; stroke: var(--text-secondary); fill: none; stroke-width: 2; flex-shrink: 0; }
.search-input { flex: 1; border: none; background: none; outline: none; font-size: 0.9rem; min-width: 0; height: 100%; padding: 0; }
.search-input::placeholder { color: var(--text-secondary); }
.search-results { padding: 0 16px; }
.search-empty { padding: 32px 16px; text-align: center; color: var(--text-secondary); font-size: 0.85rem; }
.search-result-card { display: flex; align-items: center; gap: 12px; padding: 10px 0; border-bottom: 1px solid var(--border); }
.search-result-card__cover { width: 56px; height: 56px; border-radius: 8px; object-fit: cover; background: var(--surface-alt); flex-shrink: 0; }
.search-result-card__info { flex: 1; min-width: 0; }
.search-result-card__title { font-size: 0.88rem; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.search-result-card__author { font-size: 0.75rem; color: var(--text-secondary); }
.add-by-url-section { padding: 20px 16px 0; }
.label { font-size: 0.78rem; font-weight: 600; color: var(--text-secondary); text-transform: uppercase; letter-spacing: 0.04em; margin-bottom: 8px; display: block; }
.input-group { display: flex; gap: 8px; }
.input-group .input { flex: 1; }

/* Settings */
.settings-section { margin: 16px; }
.settings-section-title { font-size: 0.72rem; font-weight: 700; text-transform: uppercase; letter-spacing: 0.06em; color: var(--text-secondary); margin-bottom: 8px; }
.settings-row { display: flex; align-items: center; justify-content: space-between; padding: 12px 16px; background: var(--surface); gap: 12px; }
.settings-row:first-of-type { border-radius: var(--radius-md) var(--radius-md) 0 0; }
.settings-row:last-child { border-radius: 0 0 var(--radius-md) var(--radius-md); }
.settings-row + .settings-row { border-top: 1px solid var(--border); }
.settings-row--column { flex-direction: column; align-items: stretch; gap: 8px; }
.settings-label { font-size: 0.88rem; font-weight: 500; }
.settings-value { font-size: 0.85rem; color: var(--text-secondary); }
.tint-picker { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.tint-swatch { width: 28px; height: 28px; border-radius: 50%; border: 2px solid transparent; background: var(--tint); transition: border-color 0.15s, transform 0.1s; flex-shrink: 0; }
.tint-swatch.active { border-color: var(--text-primary); }
.tint-swatch:active { transform: scale(0.88); }

/* Toggle */
.toggle { position: relative; width: 46px; height: 28px; flex-shrink: 0; cursor: pointer; }
.toggle input { position: absolute; opacity: 0; width: 0; height: 0; }
.toggle-slider { position: absolute; inset: 0; background: var(--border); border-radius: 14px; transition: background 0.2s; }
.toggle input:checked + .toggle-slider { background: var(--accent); }
.toggle-slider::before { content: ''; position: absolute; top: 3px; left: 3px; width: 22px; height: 22px; background: #fff; border-radius: 50%; box-shadow: 0 1px 3px rgba(0,0,0,0.2); transition: transform 0.2s; pointer-events: none; }
.toggle input:checked + .toggle-slider::before { transform: translateX(18px); }

/* Inputs */
.input { height: 40px; padding: 0 14px; border: 1px solid var(--border); border-radius: 10px; background: var(--surface); font-size: 0.85rem; outline: none; width: 100%; transition: border-color 0.15s; color: var(--text-primary); }
.input:focus { border-color: var(--accent); }
.input--number { width: 72px; text-align: center; }
.input--select { cursor: pointer; -webkit-appearance: none; appearance: none; background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%2394a3b8' stroke-width='2'%3E%3Cpolyline points='6 9 12 15 18 9'/%3E%3C/svg%3E"); background-repeat: no-repeat; background-position: right 12px center; padding-right: 32px; }

/* Buttons */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; height: 38px; padding: 0 18px; border-radius: 10px; font-size: 0.82rem; font-weight: 600; transition: background 0.15s, transform 0.1s, filter 0.15s; white-space: nowrap; }
.btn:active { transform: scale(0.96); }
.btn--primary { background: var(--accent); color: var(--accent-contrast); }
.btn--primary:hover { filter: brightness(1.08); }
.btn--secondary { border: 1.5px solid var(--accent); color: var(--accent); background: transparent; }
.btn--secondary:hover { background: var(--accent); color: var(--accent-contrast); }
.btn--danger { background: var(--error); color: #ffffff; }
.btn--danger:hover { filter: brightness(1.1); }
.btn--icon { width: 38px; padding: 0; }
.btn--icon svg { width: 18px; height: 18px; stroke: currentColor; fill: none; stroke-width: 2; }
.btn--sm { height: 32px; padding: 0 12px; font-size: 0.75rem; border-radius: 8px; }
.btn:disabled { opacity: 0.5; cursor: not-allowed; pointer-events: none; }

/* FAB */
.fab { position: fixed; bottom: 140px; right: 20px; z-index: 50; width: 52px; height: 52px; border-radius: 50%; background: var(--accent); color: var(--accent-contrast); display: flex; align-items: center; justify-content: center; box-shadow: 0 4px 16px rgba(0,0,0,0.2); transition: transform 0.15s, box-shadow 0.15s; }
.fab:active { transform: scale(0.92); }
.fab:hover { box-shadow: 0 6px 24px rgba(0,0,0,0.3); }
.fab svg { width: 24px; height: 24px; stroke: currentColor; fill: none; stroke-width: 2; }

/* Toast */
.toast-container { position: fixed; bottom: 130px; left: 50%; transform: translateX(-50%); z-index: 300; display: flex; flex-direction: column; align-items: center; gap: 8px; pointer-events: none; }
.toast { background: var(--text-primary); color: var(--bg-primary); padding: 10px 20px; border-radius: 10px; font-size: 0.82rem; font-weight: 500; box-shadow: 0 4px 20px rgba(0,0,0,0.2); animation: toastIn 0.25s ease, toastOut 0.2s ease 2.5s forwards; pointer-events: auto; }
@keyframes toastIn { from { opacity: 0; transform: translateY(12px) scale(0.95); } to { opacity: 1; transform: translateY(0) scale(1); } }
@keyframes toastOut { from { opacity: 1; } to { opacity: 0; transform: translateY(-8px); } }

/* Modal */
.modal-overlay { position: fixed; inset: 0; z-index: 250; background: rgba(0,0,0,0.45); display: flex; align-items: center; justify-content: center; padding: 24px; }
.modal { background: var(--surface); border-radius: 16px; padding: 24px; max-width: 340px; width: 100%; animation: modalIn 0.2s ease; }
@keyframes modalIn { from { opacity: 0; transform: scale(0.94); } to { opacity: 1; transform: scale(1); } }
.modal-title { font-size: 1rem; font-weight: 700; margin-bottom: 8px; }
.modal-message { font-size: 0.85rem; color: var(--text-secondary); line-height: 1.5; margin-bottom: 20px; }
.modal-actions { display: flex; justify-content: flex-end; gap: 8px; }

/* Spinner */
.spinner { width: 28px; height: 28px; border: 3px solid var(--border); border-top-color: var(--accent); border-radius: 50%; animation: spin 0.6s linear infinite; }
.loading-center { display: flex; justify-content: center; padding: 48px 0; }
@keyframes spin { to { transform: rotate(360deg); } }

/* Empty State */
.empty-state { display: flex; flex-direction: column; align-items: center; justify-content: center; padding: 64px 24px; text-align: center; color: var(--text-secondary); }
.empty-icon { margin-bottom: 12px; opacity: 0.5; color: var(--text-muted); }
.empty-icon svg { width: 64px; height: 64px; stroke: currentColor; fill: none; stroke-width: 1.5; }
.empty-state h3 { font-size: 1rem; font-weight: 600; color: var(--text-primary); margin-bottom: 4px; }
.empty-state p { font-size: 0.82rem; line-height: 1.4; }

/* Desktop */
@media (min-width: 960px) {
  .page { max-width: 900px; margin: 0 auto; }
  .bottom-nav { max-width: 960px; left: 50%; transform: translateX(-50%); border-radius: 16px 16px 0 0; }
  .mini-player { max-width: 960px; left: 50%; transform: translateX(-50%); }
  .mini-player.visible { transform: translateX(-50%) translateY(0); }
}

::selection { background: var(--accent); color: var(--accent-contrast); }
