:root {
    --bg: #f5f7f2;
    --text: #000000;
    --accent: #4ade80;
    --surface: color-mix(in srgb, var(--bg) 70%, white 30%);
    --surface2: color-mix(in srgb, var(--bg) 85%, white 15%);
    --border: color-mix(in srgb, var(--text) 15%, transparent 85%);
    --font-size: 16px;
    --line-height: 1.5;
    --indent: 1em;
    --font-family: sans-serif;
    --font-weight: 400;
    --side-padding: 24px;
    --para-spacing: 8px;
}

* { box-sizing: border-box; margin: 0; padding: 0; }
[hidden] { display: none !important; }
html { font-size: 16px; -webkit-text-size-adjust: 100%; }

body {
    font-family: var(--font-family), 'Pretendard', 'Apple SD Gothic Neo', 'Noto Sans KR', 'Malgun Gothic', sans-serif;
    font-weight: var(--font-weight);
    background: var(--bg);
    color: var(--text);
    min-height: 100vh;
    -webkit-font-smoothing: antialiased;
}

a { color: var(--accent); text-decoration: none; }

/* Header */
.header {
    position: sticky;
    top: 0;
    z-index: 100;
    background: var(--bg);
    border-bottom: 1px solid var(--border);
    padding: 0 16px;
    padding-top: env(safe-area-inset-top);
    min-height: 56px;
    display: flex;
    align-items: center;
    gap: 12px;
}
.header-back, .header-action {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 40px;
    height: 40px;
    border-radius: 50%;
    color: var(--text);
    font-size: 20px;
    flex-shrink: 0;
    opacity: 0.8;
    background: none;
    border: none;
    cursor: pointer;
}
.header-title {
    font-size: 17px;
    font-weight: 600;
    flex: 1;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.header-text-btn {
    background: none;
    border: none;
    cursor: pointer;
    color: var(--text);
    font-size: 13px;
    font-weight: 600;
    opacity: 0.4;
    padding: 8px;
    -webkit-tap-highlight-color: transparent;
}

/* Main */
.main {
    padding: 16px var(--side-padding);
    max-width: 680px;
    margin: 0 auto;
    padding-bottom: calc(90px + env(safe-area-inset-bottom));
}

/* Cards */
.card {
    background: var(--surface);
    border-radius: 12px;
    padding: 16px;
    margin-bottom: 12px;
    border: 1px solid var(--border);
}
.card.warn { border-color: #fbbf24; background: rgba(251,191,36,0.12); font-size: 14px; }
.card.error { border-color: #f87171; background: rgba(248,113,113,0.1); color: #dc2626; font-size: 14px; }

/* Buttons */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    padding: 12px 20px;
    border-radius: 10px;
    font-size: 15px;
    font-weight: 600;
    cursor: pointer;
    border: none;
    font-family: inherit;
    -webkit-tap-highlight-color: transparent;
}
.btn:active { transform: scale(0.97); }
.btn-primary { background: var(--accent); color: #000; }
.btn-secondary { background: var(--surface2); color: var(--text); border: 1px solid var(--border); }
.btn-danger { background: transparent; color: #dc2626; border: 1px solid #f87171; }
.btn-full { width: 100%; }
.btn:disabled { opacity: 0.5; cursor: not-allowed; transform: none; }

/* Forms */
input[type="text"], input[type="password"], input[type="number"], input[type="file"], textarea {
    width: 100%;
    background: var(--surface2);
    color: var(--text);
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 10px 12px;
    font-size: 16px;
    font-family: inherit;
    outline: none;
}
input[type="color"] {
    width: 48px;
    height: 40px;
    padding: 2px;
    border: 1px solid var(--border);
    border-radius: 8px;
    background: var(--surface2);
    flex-shrink: 0;
}
input:focus, textarea:focus { border-color: var(--accent); }
textarea { resize: vertical; min-height: 100px; }
textarea.mono { font-family: ui-monospace, Menlo, monospace; font-size: 13px; line-height: 1.6; }
label { display: block; font-size: 13px; opacity: 0.7; margin-bottom: 6px; font-weight: 500; }
.form-group { margin-bottom: 16px; }
.color-row { display: flex; gap: 8px; align-items: center; }
.color-row input[type="text"] { font-family: ui-monospace, Menlo, monospace; }

/* Collapsible */
details {
    background: var(--surface);
    border-radius: 12px;
    border: 1px solid var(--border);
    margin-bottom: 12px;
    overflow: hidden;
}
summary {
    padding: 16px;
    cursor: pointer;
    font-weight: 600;
    font-size: 16px;
    list-style: none;
    display: flex;
    align-items: center;
    gap: 8px;
    user-select: none;
    -webkit-tap-highlight-color: transparent;
}
summary::-webkit-details-marker { display: none; }
summary::after { content: '▶'; margin-left: auto; font-size: 12px; opacity: 0.6; transition: transform 0.2s; }
details[open] summary::after { transform: rotate(90deg); }
.details-body { padding: 0 16px 16px; }

.text-muted { opacity: 0.55; font-size: 13px; }
.hint { display: block; margin-top: 8px; }
.row { display: flex; gap: 10px; }
.row > * { flex: 1; min-width: 0; }

/* Toast */
.toast {
    position: fixed;
    bottom: calc(90px + env(safe-area-inset-bottom));
    left: 50%;
    transform: translateX(-50%);
    background: var(--accent);
    color: #000;
    padding: 10px 20px;
    border-radius: 20px;
    font-size: 14px;
    font-weight: 600;
    z-index: 999;
    animation: fadeInOut 2.5s ease forwards;
    white-space: nowrap;
}
@keyframes fadeInOut {
    0% { opacity: 0; transform: translateX(-50%) translateY(10px); }
    20% { opacity: 1; transform: translateX(-50%) translateY(0); }
    80% { opacity: 1; }
    100% { opacity: 0; }
}

/* Library / book list */
.list-item {
    display: flex;
    align-items: center;
    gap: 14px;
    padding: 14px 16px;
    color: inherit;
}
.list-item .grow { flex: 1; min-width: 0; }
.list-item .name { font-weight: 600; font-size: 16px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.list-item .chev { opacity: 0.4; font-size: 18px; flex-shrink: 0; }
.ch-num {
    width: 32px; height: 32px; border-radius: 50%;
    display: flex; align-items: center; justify-content: center;
    font-size: 13px; font-weight: 600; flex-shrink: 0;
    background: var(--surface2); border: 1px solid var(--border);
}
.ch-num.done { background: var(--accent); border-color: var(--accent); color: #000; }
.ch-num.partial { border-color: var(--accent); }

/* Reading */
.reading-content {
    font-size: var(--font-size);
    line-height: var(--line-height);
}
.chapter-title {
    font-size: calc(var(--font-size) * 1.1);
    font-weight: 700;
    margin-bottom: 28px;
    text-align: center;
    padding-bottom: 16px;
    border-bottom: 1px solid var(--border);
}
.section-label {
    font-size: 11px;
    font-weight: 700;
    letter-spacing: 0.1em;
    opacity: 0.4;
    margin-bottom: 12px;
    margin-top: 28px;
}
.para-block {
    margin-bottom: var(--para-spacing);
    cursor: pointer;
    border-radius: 6px;
    padding: 3px 6px;
    margin-left: -6px;
    margin-right: -6px;
    -webkit-tap-highlight-color: transparent;
}
.para-block:active { background: color-mix(in srgb, var(--text) 5%, transparent); }
.trans-para { text-indent: var(--indent); }
.orig-para {
    display: none;
    margin-top: 6px;
    padding: 6px 10px;
    border-left: 2px solid var(--accent);
    font-size: 0.82em;
    opacity: 0.45;
    line-height: 1.65;
}
.para-block.open .orig-para { display: block; }
.empty-note { opacity: 0.5; font-size: 15px; text-align: center; padding: 40px 0; }

.status {
    margin-bottom: 16px;
    padding: 10px 12px;
    border-radius: 8px;
    font-size: 13px;
    line-height: 1.5;
    background: rgba(251,191,36,0.14);
}
.status.error { background: rgba(248,113,113,0.14); color: #dc2626; }

/* Bottom nav */
.nav-bar {
    position: fixed;
    bottom: 0; left: 0; right: 0;
    background: var(--bg);
    border-top: 1px solid var(--border);
    padding: 10px 16px calc(10px + env(safe-area-inset-bottom));
    display: flex;
    gap: 8px;
    align-items: center;
    z-index: 100;
}
.nav-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    height: 44px;
    border-radius: 10px;
    font-size: 14px;
    font-weight: 600;
    font-family: inherit;
    cursor: pointer;
    border: 1px solid var(--border);
    background: var(--surface);
    color: var(--text);
    -webkit-tap-highlight-color: transparent;
    flex-shrink: 0;
    padding: 0 16px;
}
.nav-btn.primary { background: var(--accent); color: #000; border-color: var(--accent); flex: 1; }
.nav-btn:disabled { opacity: 0.28; cursor: not-allowed; }
.nav-spacer { flex: 1; }
#progress {
    position: absolute;
    top: -1px; left: 0; right: 0;
    height: 3px;
    background: var(--border);
}
#progress-fill { height: 100%; width: 0; background: var(--accent); transition: width 0.3s; }
