:root {
    --bg: #000000;
    --surface: #111113;
    --surface-2: #1c1c1e;
    --surface-3: #2c2c2e;
    --text: #ffffff;
    --muted: #9a9aa0;
    --dim: #6d6d72;
    --border: rgba(84, 84, 88, 0.65);
    --accent: #0a84ff;
    --danger: #ff453a;
    --success: #34c759;
    --warning: #ffd60a;
    --poster-w: 70px;
    --poster-h: 105px;
    color-scheme: dark;
}

* {
    box-sizing: border-box;
}

html,
body {
    width: 100%;
    min-height: 100%;
    margin: 0;
    background: var(--bg);
    color: var(--text);
    font-family: "JetBrains Mono", ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
    -webkit-font-smoothing: antialiased;
    text-size-adjust: 100%;
    overscroll-behavior: none;
}

body,
ion-app {
    background: var(--bg);
}

ion-content,
ion-toolbar,
ion-list,
ion-item {
    --background: var(--bg);
    --color: var(--text);
    font-family: inherit;
}

ion-toolbar {
    --border-color: var(--border);
}

ion-title {
    font-size: 18px;
    font-weight: 700;
    letter-spacing: 0;
}

ion-input,
ion-note,
ion-label,
ion-button,
ion-searchbar {
    font-family: inherit;
}

.app-container {
    min-height: 100vh;
    min-height: 100dvh;
    background: var(--bg);
}

.view {
    min-height: 100vh;
    min-height: 100dvh;
}

.view.hidden,
.hidden {
    display: none !important;
}

.header-icon-btn {
    --color: var(--accent);
}

.filter-toolbar {
    --min-height: auto;
}

.filter-section {
    display: grid;
    gap: 10px;
    width: 100%;
    padding: 8px 12px 12px;
}

.search-container {
    position: relative;
    display: flex;
    align-items: center;
    min-height: 40px;
    border: 1px solid transparent;
    border-radius: 10px;
    background: var(--surface-2);
}

.search-container:focus-within {
    background: var(--surface-3);
    border-color: rgba(10, 132, 255, 0.55);
}

.search-icon {
    width: 18px;
    height: 18px;
    margin-left: 12px;
    color: var(--dim);
    flex: 0 0 auto;
}

.search-container input {
    width: 100%;
    min-width: 0;
    height: 40px;
    padding: 0 40px 0 10px;
    border: 0;
    outline: 0;
    color: var(--text);
    background: transparent;
    font: inherit;
    font-size: 15px;
}

.search-container input::placeholder {
    color: var(--dim);
}

.clear-btn {
    position: absolute;
    right: 6px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 32px;
    height: 32px;
    border: 0;
    border-radius: 999px;
    color: var(--dim);
    background: transparent;
    padding: 0;
}

.clear-btn ion-icon {
    width: 19px;
    height: 19px;
}

.filter-chips-row {
    display: flex;
    gap: 8px;
    overflow-x: auto;
    padding-bottom: 2px;
    scrollbar-width: none;
}

.filter-chips-row::-webkit-scrollbar {
    display: none;
}

.filter-chip {
    display: inline-flex;
    align-items: center;
    gap: 7px;
    min-height: 34px;
    flex: 0 0 auto;
    padding: 0 12px;
    border: 1px solid var(--border);
    border-radius: 10px;
    background: rgba(28, 28, 30, 0.74);
    color: var(--muted);
    font: inherit;
    font-size: 13px;
    font-weight: 600;
}

.filter-chip.included {
    border-color: rgba(10, 132, 255, 0.8);
    color: var(--text);
    background: rgba(10, 132, 255, 0.16);
}

.filter-chip-icon,
.filter-chip-icon ion-icon {
    width: 16px;
    height: 16px;
}

.view-content {
    --background: var(--bg);
}

.screen-list,
.search-results-list {
    background: transparent;
}

.empty-state,
.inline-status {
    color: var(--muted);
    text-align: center;
    padding: 36px 18px;
    line-height: 1.5;
}

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

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

.inline-status.compact {
    min-height: 22px;
    padding: 0;
    text-align: left;
}

.screen-row,
.search-result-row {
    --background: transparent;
    --inner-border-width: 0 0 1px 0;
    --border-color: var(--border);
    --padding-start: 0;
    --inner-padding-end: 0;
    --min-height: auto;
    cursor: pointer;
}

.screen-row::part(native),
.search-result-row::part(native) {
    padding-top: 12px;
    padding-bottom: 12px;
}

.poster {
    width: var(--poster-w);
    height: var(--poster-h);
    object-fit: cover;
    border-radius: 6px;
    background: var(--surface-2);
    border: 1px solid rgba(255, 255, 255, 0.06);
    flex: 0 0 auto;
}

.poster.placeholder {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    color: var(--dim);
}

.poster.placeholder ion-icon {
    width: 30px;
    height: 30px;
}

.screen-row-content,
.result-content {
    display: flex;
    align-items: flex-start;
    gap: 12px;
    width: 100%;
}

.screen-summary,
.result-summary {
    min-width: 0;
    flex: 1;
}

.screen-title {
    margin: 0 0 5px;
    font-size: 16px;
    line-height: 1.3;
    font-weight: 700;
    color: var(--text);
}

.screen-subtitle,
.screen-overview,
.result-overview {
    margin: 0;
    color: var(--muted);
    font-size: 13px;
    line-height: 1.45;
}

.screen-overview,
.result-overview {
    display: -webkit-box;
    overflow: hidden;
    -webkit-box-orient: vertical;
    -webkit-line-clamp: 2;
    margin-top: 7px;
}

.meta-row,
.tag-row {
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: 6px;
    margin-top: 8px;
}

.meta-chip,
.tag-chip {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    max-width: 100%;
    min-height: 24px;
    padding: 2px 8px;
    border: 1px solid rgba(255, 255, 255, 0.08);
    border-radius: 7px;
    color: var(--muted);
    background: rgba(255, 255, 255, 0.04);
    font-size: 11px;
    font-weight: 600;
}

.meta-chip.primary {
    color: var(--accent);
}

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

.meta-chip.warning {
    color: var(--warning);
}

.meta-chip ion-icon,
.tag-chip ion-icon {
    width: 13px;
    height: 13px;
}

.result-actions {
    flex: 0 0 auto;
    align-self: center;
}

.add-body,
.settings-body {
    max-width: 820px;
    margin: 0 auto;
}

.settings-section-title {
    margin: 0;
    color: var(--text);
    font-size: 15px;
    font-weight: 700;
}

.settings-description,
.setting-hint,
.debug-log-summary {
    color: var(--muted);
    font-size: 12px;
    line-height: 1.5;
}

.sync-buttons {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    margin: 12px 0 22px;
}

.sync-buttons ion-button {
    min-height: 40px;
}

.config-json-panel {
    margin: -8px 0 24px;
}

.config-json-label {
    display: block;
    color: var(--muted);
    font-size: 11px;
    font-weight: 700;
    letter-spacing: 0;
    margin: 0 0 8px;
    text-transform: uppercase;
}

.config-json-text {
    width: 100%;
    min-height: 172px;
    resize: vertical;
    border: 1px solid var(--border);
    border-radius: 8px;
    background: rgba(255, 255, 255, 0.04);
    color: var(--text);
    font-family: inherit;
    font-size: 12px;
    line-height: 1.5;
    outline: none;
    padding: 12px;
}

.config-json-text:focus {
    border-color: var(--accent);
    box-shadow: 0 0 0 2px rgba(125, 176, 255, 0.2);
}

.clipboard-copy-target {
    position: fixed;
    top: 0;
    left: 0;
    width: 1px;
    height: 1px;
    opacity: 0;
    pointer-events: none;
    z-index: -1;
}

.form-actions {
    display: flex;
    justify-content: flex-end;
    gap: 10px;
    width: 100%;
    padding: 8px 12px;
}

.screen-form {
    display: grid;
    gap: 14px;
    max-width: 680px;
    margin: 0 auto;
}

.form-type-segment {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 8px;
}

.form-type-segment button {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    min-height: 40px;
    border: 1px solid var(--border);
    border-radius: 9px;
    background: var(--surface-2);
    color: var(--muted);
    font: inherit;
    font-size: 13px;
    font-weight: 700;
}

.form-type-segment button.included {
    border-color: rgba(10, 132, 255, 0.8);
    background: rgba(10, 132, 255, 0.16);
    color: var(--text);
}

.form-type-segment ion-icon {
    width: 16px;
    height: 16px;
}

.form-field {
    display: grid;
    gap: 6px;
}

.form-field span {
    color: var(--muted);
    font-size: 12px;
    font-weight: 700;
}

.sync-status {
    min-height: 22px;
    margin: 0 0 22px;
    color: var(--muted);
    font-size: 13px;
    line-height: 1.5;
}

.sync-status.success,
.pwa-update-ready {
    color: var(--success);
}

.sync-status.error,
.pwa-update-error {
    color: var(--danger);
}

.sync-status.info,
.pwa-update-checking {
    color: var(--accent);
}

.pwa-update-current {
    color: var(--muted);
}

.screen-detail-modal {
    --height: 100%;
    --width: 100%;
    --border-radius: 0;
}

.screen-form-modal {
    --height: 100%;
    --width: 100%;
    --border-radius: 0;
}

.modal-sheet {
    display: flex;
    flex-direction: column;
    width: 100%;
    height: 100%;
    min-height: 0;
    overflow: hidden;
    background: var(--bg);
}

.modal-sheet > ion-header,
.modal-sheet > ion-footer {
    flex: 0 0 auto;
}

.modal-sheet > ion-content {
    flex: 1 1 0;
    min-height: 0;
}

.detail-hero {
    display: grid;
    grid-template-columns: 110px minmax(0, 1fr);
    gap: 16px;
    align-items: start;
    margin-bottom: 18px;
}

.detail-hero .poster {
    width: 110px;
    height: 165px;
}

.detail-title {
    margin: 0 0 6px;
    font-size: 21px;
    line-height: 1.25;
    font-weight: 800;
}

.detail-description {
    color: var(--muted);
    font-size: 14px;
    line-height: 1.6;
    white-space: pre-wrap;
}

.detail-section {
    margin: 18px 0;
    padding-top: 16px;
    border-top: 1px solid var(--border);
}

.detail-section h3 {
    margin: 0 0 10px;
    font-size: 14px;
    font-weight: 700;
}

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

.status-segment ion-button {
    min-height: 38px;
}

.tag-editor {
    display: flex;
    gap: 8px;
    align-items: center;
}

.tag-editor input,
.rating-input,
.edit-field,
.edit-textarea {
    width: 100%;
    min-height: 38px;
    border: 1px solid var(--border);
    border-radius: 9px;
    outline: none;
    background: var(--surface-2);
    color: var(--text);
    padding: 8px 10px;
    font: inherit;
}

.edit-textarea {
    min-height: 120px;
    resize: vertical;
    line-height: 1.5;
}

.tag-pill {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    border: 1px solid var(--border);
    border-radius: 8px;
    background: var(--surface-2);
    padding: 4px 8px;
    color: var(--text);
    font-size: 12px;
}

.tag-pill button {
    width: 18px;
    height: 18px;
    border: 0;
    border-radius: 999px;
    background: transparent;
    color: var(--muted);
    padding: 0;
}

.episode-season {
    border: 1px solid var(--border);
    border-radius: 10px;
    overflow: hidden;
    margin-bottom: 10px;
}

.episode-season summary {
    cursor: pointer;
    padding: 12px;
    color: var(--text);
    background: var(--surface-2);
    font-weight: 700;
}

.episode-row {
    display: grid;
    grid-template-columns: 34px minmax(0, 1fr) 38px;
    gap: 10px;
    padding: 10px 12px;
    border-top: 1px solid rgba(255, 255, 255, 0.06);
}

.episode-row.watched {
    opacity: 0.62;
}

.episode-number {
    color: var(--accent);
    font-size: 12px;
    font-weight: 700;
}

.episode-title {
    margin: 0;
    color: var(--text);
    font-size: 13px;
    line-height: 1.35;
    font-weight: 700;
}

.episode-meta {
    color: var(--dim);
    font-size: 11px;
}

.episode-overview {
    color: var(--muted);
    font-size: 12px;
    line-height: 1.45;
    margin-top: 5px;
}

.episode-watch-btn {
    width: 34px;
    height: 34px;
    border: 1px solid var(--border);
    border-radius: 999px;
    background: var(--surface-2);
    color: transparent;
}

.episode-watch-btn.watched {
    border-color: var(--accent);
    background: var(--accent);
    color: #ffffff;
}

@media (max-width: 520px) {
    :root {
        --poster-w: 62px;
        --poster-h: 93px;
    }

    .screen-row-content,
    .result-content {
        gap: 10px;
    }

    .result-actions ion-button {
        --padding-start: 10px;
        --padding-end: 10px;
    }

    .detail-hero {
        grid-template-columns: 92px minmax(0, 1fr);
    }

    .detail-hero .poster {
        width: 92px;
        height: 138px;
    }

    .status-segment {
        grid-template-columns: 1fr;
    }
}
