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

html {
    line-height: 1.5;
    -webkit-text-size-adjust: 100%;
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
}

body {
    margin: 0;
    min-height: 100vh;
    min-height: 100dvh;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: space-between;
    padding: 1.5rem;
    background-color: #ffffff;
    color: #0f172a;
    -webkit-font-smoothing: antialiased;
    overscroll-behavior: none;
    transition: background-color 0.25s ease, color 0.25s ease;
}

@media (min-width: 768px) {
    body { padding: 3rem; }
}

html.dark body {
    background-color: #020617;
    color: #f1f5f9;
}

button, input, a {
    font: inherit;
    color: inherit;
}

button {
    background: transparent;
    cursor: pointer;
    padding: 0;
}

a { text-decoration: none; }

.serif {
    font-family: 'Lora', Georgia, Cambria, 'Times New Roman', serif;
}

.hidden { display: none !important; }

/* Loading Overlay */
#loading-overlay {
    position: fixed;
    inset: 0;
    background: #ffffff;
    z-index: 100;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    transition: opacity 0.35s ease;
}
html.dark #loading-overlay { background: #020617; }

.spinner {
    width: 1.5rem;
    height: 1.5rem;
    border-radius: 9999px;
    border: 2px solid #e2e8f0;
    border-top-color: #1e293b;
    animation: spin 0.75s linear infinite;
    margin-bottom: 1rem;
}
html.dark .spinner {
    border-color: #1e293b;
    border-top-color: #e2e8f0;
}
@keyframes spin {
    to { transform: rotate(360deg); }
}
.loading-text {
    font-size: 9px;
    text-transform: uppercase;
    letter-spacing: 0.2em;
    color: #94a3b8;
}

/* Top Bar */
.top-bar {
    width: 100%;
    max-width: 28rem;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 0.5rem;
    margin-bottom: 2.5rem;
}

.stats-wrap {
    display: flex;
    align-items: center;
    gap: 0.75rem;
}

.progress-ring { flex-shrink: 0; }
.progress-ring__track { color: #f1f5f9; }
html.dark .progress-ring__track { color: #1e293b; }
.progress-ring__circle {
    color: #10b981;
    transition: stroke-dashoffset 0.6s ease;
    transform: rotate(-90deg);
    transform-origin: 50% 50%;
}

.stats-row {
    display: flex;
    align-items: baseline;
    gap: 0.3rem;
}
.stats-percent {
    font-size: 0.75rem;
    font-weight: 700;
    color: #334155;
    letter-spacing: -0.02em;
}
html.dark .stats-percent { color: #cbd5e1; }

.stats-count {
    font-size: 9px;
    font-weight: 500;
    color: #94a3b8;
}
html.dark .stats-count { color: #64748b; }

.sync-row {
    display: flex;
    align-items: center;
    gap: 0.35rem;
    flex-wrap: wrap;
}
.status-dot {
    width: 6px;
    height: 6px;
    border-radius: 50%;
    display: inline-block;
    flex-shrink: 0;
}
.status-online { background-color: #10b981; box-shadow: 0 0 8px #10b981; }
.status-offline { background-color: #94a3b8; }
.status-error { background-color: #ef4444; box-shadow: 0 0 8px #ef4444; }

.sync-label {
    font-size: 9px;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    color: #94a3b8;
    font-weight: 500;
}
html.dark .sync-label { color: #64748b; }

.streak-badge {
    font-size: 9px;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    color: #10b981;
    font-weight: 700;
}

.pill-btn {
    display: inline-flex;
    align-items: center;
    gap: 0.3rem;
    padding: 0.375rem 0.75rem;
    background: #f8fafc;
    border: 1px solid #e2e8f0;
    border-radius: 9999px;
    color: #64748b;
    font-size: 10px;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    font-weight: 600;
    transition: background-color 0.2s, color 0.2s;
}
.pill-btn:hover { background: #f1f5f9; color: #0f172a; }
html.dark .pill-btn {
    background: #0f172a;
    border-color: #1e293b;
    color: #94a3b8;
}
html.dark .pill-btn:hover { background: #1e293b; color: #f8fafc; }

/* Main Reading Area */
.main-wrap {
    width: 100%;
    max-width: 28rem;
    position: relative;
    touch-action: pan-y;
}

.reading-main { text-align: center; }

.reading-label {
    margin-bottom: 2rem;
    font-size: 10px;
    letter-spacing: 0.3em;
    text-transform: uppercase;
    color: #cbd5e1;
    font-weight: 600;
}
html.dark .reading-label { color: #334155; }

.portion-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 2.75rem;
    width: 100%;
}

.nav-btn {
    opacity: 0.35;
    transition: opacity 0.2s, transform 0.15s;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0.9rem;
    -webkit-tap-highlight-color: transparent;
}
.nav-btn:hover { opacity: 1; }
.nav-btn:active { transform: scale(0.92); }
.nav-btn:disabled { opacity: 0.06; cursor: default; }

.reading-portion {
    flex: 1;
    margin: 0;
    padding: 0 0.75rem;
    min-height: 4rem;
    display: flex;
    align-items: center;
    justify-content: center;
    text-align: center;
    font-size: 1.875rem;
    font-weight: 400;
    line-height: 1.3;
    color: #0f172a;
}
@media (min-width: 768px) {
    .reading-portion { font-size: 2.25rem; }
}
html.dark .reading-portion { color: #f1f5f9; }

.actions-col {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 1.35rem;
}

.action-button {
    transition: transform 0.12s ease, background-color 0.2s ease, border-color 0.2s ease, color 0.2s ease;
    -webkit-tap-highlight-color: transparent;
}
.action-button:active { transform: scale(0.96); }

.check-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    width: 100%;
    padding: 1rem 2.5rem;
    border: 2px solid #f1f5f9;
    border-radius: 0.375rem;
    color: #94a3b8;
    font-size: 0.75rem;
    letter-spacing: 0.2em;
    text-transform: uppercase;
    font-weight: 600;
}
@media (min-width: 640px) {
    .check-btn { width: auto; }
}
html.dark .check-btn {
    border-color: #1e293b;
    color: #64748b;
}

.check-btn.completed {
    background-color: #10b981;
    color: #ffffff !important;
    border-color: #10b981;
}

@keyframes celebratePop {
    0% { transform: scale(1); }
    45% { transform: scale(1.05); }
    100% { transform: scale(1); }
}
.check-btn.pop {
    animation: celebratePop 0.35s cubic-bezier(0.22, 1, 0.36, 1);
}

.read-link-wrap {
    width: 100%;
    display: flex;
    flex-direction: column;
    align-items: center;
}

.read-link {
    display: inline-block;
    width: 100%;
    padding: 1.2rem 3.5rem;
    background-color: #0f172a;
    color: #ffffff;
    font-size: 0.75rem;
    letter-spacing: 0.2em;
    text-transform: uppercase;
    border-radius: 0.375rem;
    font-weight: 700;
    box-shadow: 0 10px 25px -5px rgba(15, 23, 42, 0.15);
}
@media (min-width: 640px) {
    .read-link { width: auto; }
}
html.dark .read-link {
    background-color: #f1f5f9;
    color: #0f172a;
    box-shadow: none;
}

.sub-actions {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 1.5rem;
}

.text-action {
    display: inline-flex;
    align-items: center;
    gap: 0.45rem;
    font-size: 10px;
    letter-spacing: 0.15em;
    text-transform: uppercase;
    color: #94a3b8;
    font-weight: 500;
    transition: color 0.2s;
}
.text-action:hover { color: #475569; }
html.dark .text-action { color: #64748b; }
html.dark .text-action:hover { color: #cbd5e1; }

.complete-banner {
    margin-top: 1.25rem;
    padding: 0.85rem 1.25rem;
    border-radius: 0.75rem;
    background: #ecfdf5;
    border: 1px solid #a7f3d0;
    color: #065f46;
    font-size: 0.75rem;
    font-weight: 600;
    letter-spacing: 0.04em;
}
html.dark .complete-banner {
    background: #064e3b;
    border-color: #065f46;
    color: #d1fae5;
}

/* Footer */
.footer-bar {
    width: 100%;
    max-width: 28rem;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 1.25rem;
    padding: 1.5rem 0 1rem;
}

.settings-bar {
    display: flex;
    align-items: center;
    gap: 0.75rem;
}

.settings-divider {
    width: 1px;
    height: 0.75rem;
    background: #e2e8f0;
}
html.dark .settings-divider { background: #1e293b; }

.settings-row {
    display: flex;
    background: #f1f5f9;
    padding: 2px;
    border-radius: 6px;
    gap: 2px;
}
html.dark .settings-row { background: #1e293b; }

.settings-row button {
    padding: 4px 10px;
    font-size: 9px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    border-radius: 4px;
    transition: all 0.2s;
    white-space: nowrap;
}
.settings-row button.active {
    background: #ffffff;
    color: #0f172a;
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.1);
}
html.dark .settings-row button.active {
    background: #334155;
    color: #f8fafc;
}
.settings-row button:not(.active) { color: #94a3b8; }

.disclaimer {
    text-align: center;
    padding: 0 1rem;
    font-size: 9px;
    text-transform: uppercase;
    letter-spacing: 0.15em;
    color: #94a3b8;
    opacity: 0.65;
    line-height: 1.6;
    max-width: 280px;
    margin: 0 auto;
}
html.dark .disclaimer { color: #475569; }

/* Toast with Undo */
.toast {
    position: fixed;
    bottom: 2rem;
    left: 50%;
    transform: translateX(-50%) translateY(8px);
    display: inline-flex;
    align-items: center;
    gap: 0.75rem;
    background: #0f172a;
    color: #ffffff;
    font-size: 10px;
    letter-spacing: 0.12em;
    text-transform: uppercase;
    font-weight: 700;
    padding: 0.65rem 1.1rem;
    border-radius: 9999px;
    box-shadow: 0 10px 25px rgba(0, 0, 0, 0.2);
    z-index: 60;
    visibility: hidden;
    opacity: 0;
    transition: opacity 0.25s ease, transform 0.25s ease, visibility 0.25s ease;
}
html.dark .toast {
    background: #f1f5f9;
    color: #0f172a;
}
.toast.show {
    visibility: visible;
    opacity: 1;
    transform: translateX(-50%) translateY(0);
}
.toast-undo {
    padding: 0.22rem 0.6rem;
    border-radius: 9999px;
    background: rgba(16, 185, 129, 0.22);
    color: #34d399;
    font-weight: 700;
    letter-spacing: 0.12em;
}
html.dark .toast-undo {
    background: rgba(16, 185, 129, 0.18);
    color: #059669;
}

/* Modals */
.modal-backdrop {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(2, 6, 23, 0.55);
    backdrop-filter: blur(8px);
    z-index: 50;
    align-items: center;
    justify-content: center;
    padding: 1.25rem;
}
.modal-backdrop.show { display: flex; }

.modal-card {
    background: #ffffff;
    width: 100%;
    max-width: 25rem;
    border-radius: 1.25rem;
    overflow: hidden;
    display: flex;
    flex-direction: column;
    box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.25);
}
html.dark .modal-card {
    background: #0f172a;
    border: 1px solid #1e293b;
}

.modal-pad {
    padding: 2rem;
    display: flex;
    flex-direction: column;
    gap: 1.35rem;
}

.modal-header {
    padding: 1rem 1.25rem;
    border-bottom: 1px solid #f1f5f9;
    display: flex;
    justify-content: space-between;
    align-items: center;
}
html.dark .modal-header { border-bottom-color: #1e293b; }

.modal-title {
    font-size: 0.75rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.14em;
    color: #94a3b8;
    margin: 0;
}

.modal-close {
    padding: 0.35rem;
    color: #94a3b8;
    display: inline-flex;
}
.modal-close:hover { color: #0f172a; }
html.dark .modal-close:hover { color: #f8fafc; }

.modal-tools {
    padding: 0.75rem 1rem;
    border-bottom: 1px solid #f1f5f9;
    display: flex;
    flex-direction: column;
    gap: 0.6rem;
}
html.dark .modal-tools { border-bottom-color: #1e293b; }

.search-input, .id-input {
    width: 100%;
    padding: 0.65rem 0.85rem;
    font-size: 0.85rem;
    border-radius: 0.5rem;
    border: 1px solid #e2e8f0;
    background: #f8fafc;
    color: #0f172a;
    outline: none;
}
.search-input:focus, .id-input:focus { border-color: #94a3b8; }
html.dark .search-input, html.dark .id-input {
    background: #020617;
    border-color: #1e293b;
    color: #f1f5f9;
}

.filter-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.5rem;
}

.jump-btn {
    font-size: 9px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: #10b981;
    padding: 4px 8px;
    border-radius: 4px;
}
.jump-btn:hover { background: rgba(16, 185, 129, 0.1); }

.schedule-list {
    flex: 1;
    overflow-y: auto;
    padding: 0.5rem;
    max-height: 62vh;
}

.schedule-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0.7rem 0.75rem;
    border-radius: 0.5rem;
    margin-bottom: 2px;
    cursor: pointer;
    transition: background-color 0.15s;
}
.schedule-item:hover { background: #f8fafc; }
html.dark .schedule-item:hover { background: #1e293b; }
.schedule-item.is-current { background: #f1f5f9; }
html.dark .schedule-item.is-current { background: #1e293b; }

.schedule-item-left {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    min-width: 0;
}
.schedule-idx {
    font-size: 10px;
    font-weight: 700;
    color: #94a3b8;
    min-width: 1.75rem;
}
.schedule-name {
    font-size: 0.8rem;
    color: #0f172a;
}
html.dark .schedule-name { color: #f1f5f9; }
.schedule-name.is-done {
    color: #94a3b8;
    text-decoration: line-through;
}
.schedule-name.is-current { font-weight: 700; }

.schedule-empty {
    text-align: center;
    padding: 2rem 1rem;
    font-size: 0.75rem;
    color: #94a3b8;
}

/* Onboarding & Confirm helpers */
.onboard-head { text-align: center; }
.onboard-icon {
    display: inline-flex;
    padding: 0.75rem;
    background: #ecfdf5;
    border-radius: 9999px;
    margin-bottom: 0.5rem;
}
html.dark .onboard-icon { background: #022c22; }
.onboard-title { font-size: 1.5rem; margin: 0 0 0.25rem; font-weight: 400; }
.onboard-sub {
    font-size: 10px;
    text-transform: uppercase;
    letter-spacing: 0.2em;
    color: #94a3b8;
    font-weight: 700;
    margin: 0;
}
.onboard-list { display: flex; flex-direction: column; gap: 1rem; }
.onboard-item { display: flex; align-items: flex-start; gap: 0.85rem; }
.onboard-item svg { color: #10b981; margin-top: 2px; flex-shrink: 0; }
.onboard-item-title {
    font-size: 10px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.14em;
    color: #64748b;
    margin: 0 0 0.2rem;
}
.onboard-item-desc {
    font-size: 0.75rem;
    color: #94a3b8;
    line-height: 1.5;
    margin: 0;
}

.btn-primary {
    width: 100%;
    padding: 1rem;
    background: #0f172a;
    color: #ffffff;
    border-radius: 0.375rem;
    font-size: 10px;
    text-transform: uppercase;
    letter-spacing: 0.2em;
    font-weight: 700;
}
html.dark .btn-primary {
    background: #f1f5f9;
    color: #0f172a;
}

.btn-secondary {
    width: 100%;
    padding: 0.85rem;
    border: 1px solid #e2e8f0;
    border-radius: 0.375rem;
    font-size: 10px;
    text-transform: uppercase;
    letter-spacing: 0.2em;
    font-weight: 700;
    color: #64748b;
}
html.dark .btn-secondary {
    border-color: #1e293b;
    color: #94a3b8;
}

.confirm-box { text-align: center; }
.confirm-msg { font-size: 1.2rem; line-height: 1.5; margin: 0; }
.confirm-btns { display: flex; gap: 0.75rem; }
.confirm-btns button { flex: 1; }
