:root {
    --bg: #0c0c10;
    --surface: #141418;
    --surface-2: #1c1c22;
    --border: rgba(255,255,255,.07);
    --text: #ddd9e3;
    --text-soft: #b8b3c0;
    --muted: #8a8494;
    --accent: #6e6878;
    --accent-hover: #827c8c;
    --accent-soft: rgba(130, 124, 140, .14);
    --accent-border: rgba(130, 124, 140, .28);
    --success: #7a9e8e;
    --radius: 14px;
    --shadow: 0 16px 40px rgba(0,0,0,.35);
    --font: "Segoe UI", system-ui, -apple-system, sans-serif;
}

*, *::before, *::after { box-sizing: border-box; }

html {
    scroll-behavior: smooth;
    overflow-x: clip;
}

body {
    margin: 0;
    font-family: var(--font);
    background: var(--bg);
    color: var(--text);
    line-height: 1.6;
    min-height: 100vh;
    overflow-x: clip;
    max-width: 100%;
}

a { color: inherit; text-decoration: none; }

img { max-width: 100%; display: block; }

.container {
    width: min(1120px, calc(100% - 2rem));
    margin: 0 auto;
    max-width: 100%;
    min-width: 0;
}

main {
    max-width: 100%;
    min-width: 0;
    overflow-x: clip;
}

/* Header */
.site-header {
    position: sticky;
    top: 0;
    z-index: 100;
    backdrop-filter: blur(16px);
    background: rgba(10,10,15,.85);
    border-bottom: 1px solid var(--border);
}

.header-inner {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
    padding: .9rem 0;
}

.logo {
    display: flex;
    align-items: center;
    gap: .6rem;
    font-weight: 700;
    font-size: 1.15rem;
}

.logo-icon {
    width: 36px;
    height: 36px;
    border-radius: 10px;
    background: var(--surface-2);
    border: 1px solid var(--border);
    display: grid;
    place-items: center;
    font-size: 1rem;
}

.nav {
    display: flex;
    align-items: center;
    gap: .5rem;
    flex-wrap: wrap;
}

.nav a, .btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: .4rem;
    padding: .55rem 1rem;
    border-radius: 10px;
    font-size: .92rem;
    font-weight: 500;
    transition: background .2s ease, border-color .2s ease, color .2s ease;
    border: 1px solid transparent;
    cursor: pointer;
}

.nav a:hover { background: var(--surface-2); color: var(--text); }

.btn-primary {
    background: var(--surface-2);
    color: var(--text);
    border-color: var(--accent-border);
    box-shadow: none;
}

.btn-primary:hover {
    background: #24242c;
    border-color: rgba(130, 124, 140, .4);
    color: #ebe8ef;
}

.btn-outline {
    border-color: var(--border);
    background: transparent;
    color: var(--text-soft);
}

.btn-outline:hover {
    background: var(--surface-2);
    color: var(--text);
    border-color: rgba(255,255,255,.12);
}

.btn-danger {
    background: rgba(120, 90, 90, .12);
    color: #c4a8a8;
    border-color: rgba(120, 90, 90, .22);
}

.btn-danger:hover {
    background: rgba(120, 90, 90, .18);
    color: #d4bcbc;
}

/* Hero */
.hero {
    padding: 3.5rem 0 2rem;
    text-align: center;
}

.hero-badge {
    display: inline-block;
    padding: .35rem .85rem;
    border-radius: 8px;
    background: var(--accent-soft);
    color: var(--text-soft);
    font-size: .82rem;
    font-weight: 500;
    margin-bottom: 1rem;
    border: 1px solid var(--border);
}

.hero h1 {
    font-size: clamp(2rem, 5vw, 3.2rem);
    line-height: 1.15;
    margin: 0 0 1rem;
    letter-spacing: -.02em;
}

.hero p {
    color: var(--muted);
    font-size: clamp(1rem, 2.5vw, 1.15rem);
    max-width: 620px;
    margin: 0 auto 1.5rem;
}

.hero-actions {
    display: flex;
    gap: .75rem;
    justify-content: center;
    flex-wrap: wrap;
}

/* Cards grid */
.section-title {
    font-size: 1.35rem;
    margin: 2.5rem 0 1.25rem;
}

.novel-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
    gap: 1.25rem;
    padding-bottom: 3rem;
}

.novel-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    overflow: hidden;
    transition: .25s ease;
    display: flex;
    flex-direction: column;
}

.novel-card:hover {
    transform: translateY(-2px);
    border-color: rgba(255,255,255,.12);
    box-shadow: var(--shadow);
}

.novel-cover {
    height: 160px;
    position: relative;
    overflow: hidden;
}

.novel-cover::after {
    content: "";
    position: absolute;
    inset: 0;
    background: linear-gradient(to top, rgba(0,0,0,.6), transparent);
}

.cover-night-city { background: linear-gradient(135deg, #1e1b4b, #312e81); }
.cover-old-library { background: linear-gradient(135deg, #78350f, #451a03); }
.cover-forest-path { background: linear-gradient(135deg, #14532d, #052e16); }
.cover-sunset-beach { background: linear-gradient(135deg, #9a3412, #7c2d12); }
.cover-mystery-room { background: linear-gradient(135deg, #581c87, #3b0764); }
.cover-rain-street { background: linear-gradient(135deg, #0f172a, #1e293b); }
.cover-from-amber-700-to-indigo-900 { background: linear-gradient(135deg, #b45309, #312e81); }
.cover-from-indigo-600-to-purple-800 { background: linear-gradient(135deg, #4f46e5, #6b21a8); }
.cover-from-slate-700-to-slate-900 { background: linear-gradient(135deg, #334155, #0f172a); }
.cover-from-rose-900-to-purple-900 { background: linear-gradient(135deg, #881337, #581c87); }

.novel-cover--custom {
    background-size: cover;
    background-position: center;
    background-repeat: no-repeat;
}

.novel-body { padding: 1.1rem 1.2rem 1.3rem; flex: 1; display: flex; flex-direction: column; }

.novel-body h3 { margin: 0 0 .4rem; font-size: 1.08rem; }

.novel-meta {
    color: var(--muted);
    font-size: .85rem;
    margin-bottom: .65rem;
}

.novel-desc {
    color: var(--text-soft);
    font-size: .92rem;
    flex: 1;
    margin-bottom: 1rem;
}

.novel-actions { display: flex; gap: .5rem; flex-wrap: wrap; }

.featured-badge {
    position: absolute;
    top: .75rem;
    left: .75rem;
    z-index: 2;
    background: rgba(20, 20, 26, .82);
    color: var(--text-soft);
    font-size: .72rem;
    font-weight: 500;
    padding: .25rem .55rem;
    border-radius: 6px;
    border: 1px solid var(--border);
    text-transform: uppercase;
    letter-spacing: .04em;
}

/* Forms */
.page-panel {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 1.5rem;
    margin-bottom: 1.25rem;
    max-width: 100%;
    min-width: 0;
    overflow: hidden;
}

.form-grid {
    display: grid;
    gap: 1rem;
    min-width: 0;
}

.form-grid > * {
    min-width: 0;
}

.form-grid-2 {
    grid-template-columns: repeat(auto-fit, minmax(min(100%, 220px), 1fr));
}

label {
    display: block;
    font-size: .88rem;
    font-weight: 500;
    margin-bottom: .35rem;
    color: var(--text-soft);
}

input, textarea, select {
    width: 100%;
    padding: .7rem .85rem;
    border-radius: 10px;
    border: 1px solid var(--border);
    background: var(--surface-2);
    color: var(--text);
    font: inherit;
}

input:focus, textarea:focus, select:focus {
    outline: none;
    border-color: var(--accent-border);
    box-shadow: 0 0 0 2px rgba(130, 124, 140, .1);
}

textarea { min-height: 110px; resize: vertical; }

.alert {
    padding: .85rem 1rem;
    border-radius: 10px;
    margin-bottom: 1rem;
    font-size: .92rem;
}

.alert-success {
    background: rgba(122, 158, 142, .1);
    border: 1px solid rgba(122, 158, 142, .22);
    color: #a8c4b8;
}

/* Builder */
.builder-layout {
    display: grid;
    grid-template-columns: 1fr;
    gap: 1.25rem;
    padding: 1.5rem 0 3rem;
}

@media (min-width: 900px) {
    .builder-layout { grid-template-columns: 280px 1fr; }
}

.builder-sidebar {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 1rem;
    height: fit-content;
}

.chapter-list { list-style: none; padding: 0; margin: 0; }

.chapter-list li {
    padding: .65rem .75rem;
    border-radius: 8px;
    margin-bottom: .35rem;
    font-size: .9rem;
    background: var(--surface-2);
}

.scene-list { margin-top: 1rem; }

.scene-item {
    background: var(--surface-2);
    border: 1px solid var(--border);
    border-radius: 10px;
    padding: .85rem;
    margin-bottom: .65rem;
}

.scene-item-header {
    display: flex;
    justify-content: space-between;
    align-items: start;
    gap: .5rem;
    flex-wrap: wrap;
}

.scene-type {
    font-size: .72rem;
    text-transform: uppercase;
    font-weight: 500;
    padding: .2rem .45rem;
    border-radius: 6px;
    background: var(--accent-soft);
    color: var(--text-soft);
    border: 1px solid var(--border);
}

.scene-type.end {
    background: rgba(100, 90, 90, .12);
    color: #b8aaaa;
}

.choice-tag {
    display: inline-block;
    font-size: .78rem;
    color: var(--muted);
    margin-top: .35rem;
}

.tag-start {
    color: var(--success);
    font-size: .78rem;
    font-weight: 500;
}

.empty-state {
    text-align: center;
    padding: 3rem 1rem;
    color: var(--muted);
}

/* Player */
.player-page {
    min-height: 100vh;
    display: flex;
    flex-direction: column;
}

.player-topbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: .75rem;
    padding: .75rem 1rem;
    background: rgba(0,0,0,.5);
    backdrop-filter: blur(10px);
    border-bottom: 1px solid var(--border);
    position: relative;
    z-index: 10;
    flex-wrap: wrap;
}

.player-topbar-actions {
    display: flex;
    align-items: center;
    gap: .5rem;
    flex-wrap: wrap;
}

.player-music-btn {
    display: inline-flex;
    align-items: center;
    gap: .35rem;
    min-width: 4.75rem;
    justify-content: center;
    transition: background .2s, border-color .2s, color .2s, opacity .2s;
}

.player-music-btn.is-on {
    background: var(--accent-soft);
    border-color: var(--accent-border);
    color: var(--text);
}

.player-music-btn.is-on .player-music-icon {
    animation: player-music-pulse 1.6s ease-in-out infinite;
}

.player-music-btn.is-off {
    opacity: .65;
    color: var(--muted);
}

.player-music-btn.is-off .player-music-icon {
    text-decoration: line-through;
    opacity: .55;
}

.player-music-btn.is-unavailable {
    opacity: .45;
    cursor: not-allowed;
}

.player-music-icon {
    font-size: 1rem;
    line-height: 1;
}

.player-music-label {
    font-size: .78rem;
    font-weight: 600;
    letter-spacing: .02em;
    text-transform: uppercase;
}

@keyframes player-music-pulse {
    0%, 100% { opacity: 1; transform: scale(1); }
    50% { opacity: .45; transform: scale(.92); }
}

.music-upload-block {
    margin-top: .5rem;
    padding-top: .75rem;
    border-top: 1px solid var(--border);
}

.audio-preview-wrap {
    margin-bottom: .75rem;
}

.audio-preview-label {
    display: block;
    font-size: .82rem;
    color: var(--text-soft);
    margin-bottom: .4rem;
}

.audio-preview {
    width: 100%;
    max-width: 100%;
    height: 36px;
    filter: sepia(.15) saturate(.7);
}

.video-upload-block,
.chapter-video-item {
    margin-top: .5rem;
}

.chapter-video-item {
    padding: 1rem 0;
    border-bottom: 1px solid var(--border);
}

.chapter-video-item:last-child {
    border-bottom: none;
    padding-bottom: 0;
}

.chapter-video-form {
    margin-top: .65rem;
}

.video-preview-wrap {
    margin-bottom: .75rem;
}

.video-preview-label {
    display: block;
    font-size: .82rem;
    color: var(--text-soft);
    margin-bottom: .4rem;
}

.video-preview,
.intro-video-player {
    width: 100%;
    max-width: 100%;
    border-radius: 10px;
    background: #000;
}

.video-preview {
    max-height: 220px;
}

.video-overlay {
    position: fixed;
    inset: 0;
    z-index: 1000;
    background: rgba(0, 0, 0, .92);
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 1rem;
}

.video-overlay[hidden] {
    display: none !important;
}

.video-overlay-inner {
    width: min(960px, 100%);
    display: flex;
    flex-direction: column;
    gap: .85rem;
    align-items: center;
}

.video-overlay-title {
    margin: 0;
    font-size: 1rem;
    color: var(--text-soft);
    text-align: center;
}

.intro-video-player {
    max-height: min(70vh, 540px);
    object-fit: contain;
}

#video-skip-btn {
    min-width: 140px;
}

.player-stage {
    flex: 1;
    position: relative;
    min-height: calc(100vh - 120px);
    display: flex;
    align-items: flex-end;
    overflow: hidden;
    background: #050810;
}

.player-bg {
    position: absolute;
    inset: 0;
    background-size: cover;
    background-position: center;
    background-repeat: no-repeat;
    transform: scale(1.05);
    animation: bgKenBurns 24s ease-in-out infinite alternate;
    transition: opacity .5s ease;
}

@keyframes bgKenBurns {
    from { transform: scale(1.05) translate(0, 0); }
    to { transform: scale(1.12) translate(-1%, -1%); }
}

.bg-night-city { background-image: url('/images/backgrounds/night-city.svg'); }
.bg-old-library { background-image: url('/images/backgrounds/old-library.svg'); }
.bg-forest-path { background-image: url('/images/backgrounds/forest-path.svg'); }
.bg-sunset-beach { background-image: url('/images/backgrounds/sunset-beach.svg'); }
.bg-mystery-room { background-image: url('/images/backgrounds/mystery-room.svg'); }
.bg-rain-street { background-image: url('/images/backgrounds/rain-street.svg'); }

.player-overlay {
    position: absolute;
    inset: 0;
    background:
        linear-gradient(to top, rgba(0,0,0,.82) 0%, rgba(0,0,0,.15) 55%, rgba(0,0,0,.35) 100%),
        linear-gradient(to right, rgba(0,0,0,.25), transparent 30%, transparent 70%, rgba(0,0,0,.25));
    pointer-events: none;
}

.dialogue-box {
    position: relative;
    z-index: 5;
    width: min(900px, calc(100% - 2rem));
    margin: 0 auto 1.5rem;
    background: rgba(14, 14, 18, .88);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 1.25rem 1.35rem;
    backdrop-filter: blur(12px);
    animation: fadeUp .35s ease;
}

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

.character-name {
    color: var(--text-soft);
    font-weight: 500;
    font-size: .9rem;
    margin-bottom: .45rem;
    letter-spacing: .02em;
}

.dialogue-text {
    font-size: clamp(1rem, 2.5vw, 1.1rem);
    line-height: 1.75;
    margin-bottom: 1rem;
    color: var(--text);
    font-weight: 400;
}

.choices-list {
    display: grid;
    gap: .55rem;
}

.choice-btn {
    width: 100%;
    text-align: left;
    padding: .8rem 1rem;
    border-radius: 10px;
    border: 1px solid var(--border);
    background: rgba(255, 255, 255, .03);
    color: var(--text-soft);
    font: inherit;
    font-weight: 400;
    line-height: 1.5;
    cursor: pointer;
    transition: background .2s ease, border-color .2s ease, color .2s ease;
}

.choice-btn:hover {
    background: rgba(255, 255, 255, .06);
    border-color: var(--accent-border);
    color: var(--text);
}

.chapter-indicator {
    font-size: .82rem;
    color: var(--muted);
}

.player-resume-hint {
    color: var(--accent);
    font-size: .78rem;
}

.end-actions {
    display: flex;
    gap: .5rem;
    flex-wrap: wrap;
    margin-top: .5rem;
}

.site-footer {
    border-top: 1px solid var(--border);
    padding: 1.5rem 0;
    color: var(--muted);
    font-size: .88rem;
    text-align: center;
}

.inline-form { display: inline; }

.novel-cover-preview-block {
    margin-bottom: 1rem;
}

.novel-cover-preview-block .novel-cover {
    margin-top: .6rem;
    border-radius: 12px;
}

/* Cover picker */
.cover-picker {
    margin-top: .25rem;
    min-width: 0;
    max-width: 100%;
}

.cover-presets {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(min(100%, 6.5rem), 1fr));
    gap: .65rem;
    margin: .65rem 0 1rem;
    max-width: 100%;
}

.cover-preset-option {
    display: flex;
    flex-direction: column;
    gap: .35rem;
    cursor: pointer;
    position: relative;
    min-width: 0;
}

.cover-preset-option input {
    position: absolute;
    opacity: 0;
    pointer-events: none;
}

.cover-preset-thumb {
    display: block;
    height: 88px;
    border-radius: 8px;
    border: 2px solid transparent;
    background-size: cover;
    background-position: center;
    transition: border-color .2s ease;
}

.cover-preset-option input:checked + .cover-preset-thumb {
    border-color: var(--accent-border);
    box-shadow: 0 0 0 2px rgba(130, 124, 140, .15);
}

.cover-preset-label {
    font-size: .75rem;
    color: var(--text-soft);
    line-height: 1.3;
    word-break: break-word;
}

.cover-upload,
.background-upload {
    padding-top: .75rem;
    border-top: 1px solid var(--border);
}

/* File upload */
.file-upload {
    margin-top: .25rem;
    max-width: 100%;
    min-width: 0;
}

.file-upload-title {
    margin: 0 0 .65rem;
    font-size: .88rem;
    font-weight: 500;
    color: var(--text-soft);
}

.file-upload-control {
    display: flex;
    align-items: center;
    gap: .75rem;
    flex-wrap: wrap;
    max-width: 100%;
    min-width: 0;
}

.file-upload-input {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
}

.file-upload-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: .5rem;
    padding: .6rem 1rem;
    border-radius: 10px;
    border: 1px dashed var(--accent-border);
    background: var(--surface-2);
    color: var(--text-soft);
    font-size: .9rem;
    font-weight: 500;
    cursor: pointer;
    transition: background .2s ease, border-color .2s ease, color .2s ease;
    user-select: none;
    max-width: 100%;
}

.file-upload-btn:hover {
    background: #24242c;
    border-color: rgba(130, 124, 140, .45);
    color: var(--text);
}

.file-upload-control:focus-within .file-upload-btn {
    border-color: var(--accent-border);
    box-shadow: 0 0 0 2px rgba(130, 124, 140, .12);
}

.file-upload-input:focus-visible + .file-upload-btn {
    border-color: var(--accent-border);
    box-shadow: 0 0 0 2px rgba(130, 124, 140, .12);
}

.file-upload-icon {
    width: 18px;
    height: 18px;
    flex-shrink: 0;
    opacity: .85;
}

.file-upload-name {
    font-size: .85rem;
    color: var(--muted);
    flex: 1 1 auto;
    min-width: 0;
    max-width: 100%;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.file-upload-name.is-selected {
    color: var(--text-soft);
}

.file-upload-hint {
    margin: .55rem 0 0;
    font-size: .8rem;
    color: var(--muted);
    line-height: 1.45;
}

/* Background picker */
.background-picker {
    margin-top: .25rem;
    min-width: 0;
    max-width: 100%;
}

.background-presets {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(min(100%, 7rem), 1fr));
    gap: .65rem;
    margin: .65rem 0 1rem;
    max-width: 100%;
}

.background-preset-option {
    display: flex;
    flex-direction: column;
    gap: .35rem;
    cursor: pointer;
    position: relative;
    min-width: 0;
}

.background-preset-option input {
    position: absolute;
    opacity: 0;
    pointer-events: none;
}

.background-preset-thumb {
    display: block;
    height: 72px;
    border-radius: 8px;
    border: 2px solid transparent;
    background-size: cover;
    background-position: center;
    transition: border-color .2s ease;
}

.background-preset-option input:checked + .background-preset-thumb {
    border-color: var(--accent-border);
    box-shadow: 0 0 0 2px rgba(130, 124, 140, .15);
}

.background-preset-label {
    font-size: .78rem;
    color: var(--text-soft);
    line-height: 1.3;
    word-break: break-word;
}

.scene-background-block {
    margin-top: .85rem;
    padding-top: .85rem;
    border-top: 1px solid var(--border);
}

.scene-background-preview {
    position: relative;
    margin: .6rem 0;
    border-radius: 10px;
    overflow: hidden;
    border: 1px solid var(--border);
    height: 120px;
    background: var(--surface-2);
}

.scene-background-preview img,
.scene-background-preview-preset {
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
}

.scene-background-preview-preset {
    background-size: cover;
    background-position: center;
}

.scene-background-badge {
    position: absolute;
    left: .6rem;
    bottom: .6rem;
    padding: .2rem .5rem;
    border-radius: 6px;
    background: rgba(10, 10, 14, .75);
    color: var(--text-soft);
    font-size: .75rem;
    border: 1px solid var(--border);
}

.scene-background-form {
    margin-top: .5rem;
}

.background-remove-check {
    display: flex;
    align-items: center;
    gap: .45rem;
    margin-top: .65rem;
    font-size: .88rem;
    color: var(--text-soft);
    cursor: pointer;
}

.background-remove-check input {
    width: auto;
}

.container-narrow {
    max-width: 720px;
}

@media (max-width: 768px) {
    .container {
        width: min(1120px, calc(100% - 1.25rem));
    }

    .container-narrow {
        padding-left: 0;
        padding-right: 0;
    }

    .header-inner {
        flex-direction: column;
        align-items: stretch;
        padding: .75rem 0;
    }

    .nav {
        justify-content: stretch;
        flex-direction: column;
        width: 100%;
    }

    .nav a,
    .nav .btn {
        width: 100%;
        justify-content: center;
    }

    .logo {
        justify-content: center;
    }

    .page-panel {
        padding: 1rem;
    }

    .cover-presets,
    .background-presets {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }

    .cover-preset-thumb {
        height: 76px;
    }

    .form-grid-2 {
        grid-template-columns: 1fr;
    }

    .file-upload-control {
        flex-direction: column;
        align-items: stretch;
    }

    .file-upload-btn {
        width: 100%;
    }

    .file-upload-name {
        white-space: normal;
        word-break: break-word;
        text-align: center;
    }

    .hero {
        padding: 2rem 0 1.5rem;
    }

    .hero h1 {
        font-size: 1.75rem;
    }

    .builder-layout {
        padding: 1rem 0 2rem;
    }

    .scene-item-header {
        flex-direction: column;
    }

    .novel-actions {
        flex-direction: column;
    }

    .novel-actions .btn {
        width: 100%;
    }
}

@media (max-width: 640px) {
    .player-topbar {
        flex-direction: column;
        align-items: stretch;
        text-align: center;
    }

    .player-topbar-actions {
        justify-content: center;
        width: 100%;
    }

    .player-music-btn,
    .player-topbar-actions .btn {
        flex: 1 1 auto;
    }

    .dialogue-box {
        margin-bottom: 1rem;
        width: calc(100% - 1rem);
    }
}
