:root {
    --color-scheme: dark;
    --bg: #0b0c10;
    --text: #e9eef5;
    --muted: #94a3b8;
    --border: #1d2330;
    --surface: #0f1320;
    --surface-strong: #121621;
    --episode: #0b0f1c;
    --poster: #0b0c10;
    --accent: #5b7cff;
    --accent-veil: rgba(91, 124, 255, .15);
    --shadow: rgba(0, 0, 0, 0.15);
}

body[data-theme="light"] {
    --color-scheme: light;
    --bg: #f6f8fc;
    --text: #0f1a2e;
    --muted: #55657e;
    --border: #d8e0ed;
    --surface: #ffffff;
    --surface-strong: #eef3fc;
    --episode: #eef2fb;
    --poster: #dfe6f2;
    --shadow: rgba(15, 26, 46, 0.08);
}

body {
    margin: 0;
    font-family: system-ui, -apple-system, Segoe UI, Roboto, Ubuntu, Cantarell, "Helvetica Neue", Arial;
    background: var(--bg);
    color: var(--text);
    color-scheme: var(--color-scheme);
    transition: background .2s ease, color .2s ease;
}

header {
    padding: 18px 16px;
    border-bottom: 1px solid var(--border);
    display: flex;
    gap: 12px;
    align-items: center;
    justify-content: space-between;
    position: sticky;
    top: 0;
    z-index: 10;
    background: rgba(11, 12, 16, 0.9);
    backdrop-filter: blur(6px);
    box-shadow: 0 8px 22px -16px var(--shadow);
}

body[data-theme="light"] header {
    background: rgba(246, 248, 252, 0.9);
}

.header-left {
    display: flex;
    align-items: center;
    gap: 12px;
}

.header-actions {
    display: flex;
    gap: 8px;
    align-items: center;
}

.brand {
    font-weight: 700;
    letter-spacing: .2px;
    display: flex;
    align-items: center;
    gap: 10px;
}

.pill {
    font-size: 12px;
    padding: 6px 10px;
    border: 1px solid var(--border);
    border-radius: 999px;
    color: var(--text);
    background: var(--surface-strong);
    text-decoration: none;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 4px;
}

.pill svg {
    width: 18px;
    height: 18px;
    display: block;
    fill: currentColor;
}

main {
    padding: 16px;
    max-width: 1100px;
    margin: 0 auto;
}

.tabs {
    display: flex;
    gap: 8px;
    margin-bottom: 12px;
}

button {
    background: var(--surface-strong);
    color: var(--text);
    border: 1px solid var(--border);
    padding: 10px 12px;
    border-radius: 12px;
    cursor: pointer;
}

button.active {
    border-color: var(--accent);
    box-shadow: 0 0 0 3px var(--accent-veil);
}

.row {
    display: flex;
    gap: 10px;
    flex-wrap: wrap;
    align-items: center;
    margin-bottom: 12px;
}

input,
select {
    background: var(--surface);
    color: var(--text);
    border: 1px solid var(--border);
    padding: 10px 12px;
    border-radius: 12px;
}

input {
    width: min(520px, 100%);
}

.grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
    gap: 10px;
}

.section-block {
    width: 100%;
}

.card {
    border: 1px solid var(--border);
    border-radius: 16px;
    background: var(--surface);
    overflow: hidden;
    display: flex;
    gap: 12px;
}

.poster {
    width: 74px;
    height: 110px;
    background: var(--poster);
    flex: 0 0 auto;
    display: flex;
    align-items: center;
    justify-content: center;
}

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

.meta {
    padding: 10px 10px 10px 0;
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.title {
    font-weight: 700;
    line-height: 1.15;
}

.sub {
    color: var(--muted);
    font-size: 13px;
    min-height: 18px;
}

.ellipsis {
    display: inline-block;
    max-width: 140px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    vertical-align: bottom;
}

.muted {
    color: var(--muted);
    font-size: 12px;
}

.section-title {
    margin: 0 0 10px;
    padding-top: 18px;
    font-weight: 700;
    font-size: 18px;
}

.footer {
    margin-top: 14px;
    color: var(--muted);
    font-size: 12px;
}

.modal-backdrop {
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,.55);
    display: none;
    align-items: center;
    justify-content: center;
    padding: 20px;
    z-index: 10;
}

.modal-panel {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 16px;
    max-width: 900px;
    width: 100%;
    max-height: 90vh;
    overflow: hidden;
    display: flex;
    flex-direction: column;
}

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

.modal-body {
    padding: 14px;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 10px;
    flex: 1 1 auto;
    min-height: 200px;
    max-height: calc(90vh - 100px);
}

/* History detail */
h1 {
    margin: 0;
    font-size: 22px;
}

.card {
    padding: 12px;
}

.season-block {
    margin-bottom: 22px;
}

.episode-list {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(320px, 1fr));
    gap: 10px;
}

.episode {
    display: flex;
    gap: 12px;
    align-items: center;
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 10px;
    background: var(--episode);
}

.episode-cover {
    width: 60px;
    height: 90px;
    border-radius: 10px;
    overflow: hidden;
    background: var(--poster);
    flex: 0 0 auto;
    display: flex;
    align-items: center;
    justify-content: center;
}

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

.episode-viewed {
    color: var(--muted);
    font-size: 12px;
}

.lang-select {
    min-width: 70px;
    text-transform: uppercase;
    letter-spacing: .4px;
}

.icon-btn {
    font-size: 16px;
    line-height: 1;
    padding: 8px 12px;
}
