/* ───────────────────────────────────────
   Calendar Maker — Styles
   Editorial / Stationery aesthetic
   ─────────────────────────────────────── */

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

:root {
    --bg: #f5f3ee;
    --surface: #ffffff;
    --surface-alt: #f9f7f3;
    --border: #e4e0d8;
    --border-light: #edeae3;
    --text: #2c2825;
    --text-dim: #7a746b;
    --text-faint: #b0a99e;
    --accent: #c45d3e;
    --accent-hover: #a84d32;
    --accent-light: #fdf0ec;
    --toggle-bg: #d5d0c8;
    --toggle-active: #c45d3e;
    --shadow-sm: 0 1px 3px rgba(0,0,0,.06), 0 1px 2px rgba(0,0,0,.04);
    --shadow-md: 0 4px 16px rgba(0,0,0,.07), 0 2px 4px rgba(0,0,0,.04);
    --shadow-lg: 0 12px 40px rgba(0,0,0,.1), 0 4px 12px rgba(0,0,0,.05);
    --shadow-paper: 0 2px 8px rgba(0,0,0,.08), 0 12px 40px rgba(0,0,0,.06);
    --radius: 10px;
    --radius-sm: 7px;
    --panel-width: 340px;
    --header-h: 64px;
    --font: 'DM Sans', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
    --font-display: 'Fraunces', Georgia, serif;
}

html {
    font-size: 15px;
    -webkit-text-size-adjust: 100%;
}

body {
    font-family: var(--font);
    background: var(--bg);
    color: var(--text);
    line-height: 1.5;
    min-height: 100dvh;
    overflow-x: hidden;
    -webkit-font-smoothing: antialiased;
}

/* ─── HEADER ──────────────────────── */

.header {
    height: var(--header-h);
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    position: sticky;
    top: 0;
    z-index: 100;
}

.header-inner {
    width: 100%;
    max-width: 1600px;
    margin: 0 auto;
    padding: 0 24px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
}

.logo {
    display: flex;
    align-items: center;
    gap: 10px;
    flex-shrink: 0;
}

.logo-icon {
    width: 28px;
    height: 28px;
    color: var(--accent);
}

.logo-text {
    font-family: var(--font-display);
    font-weight: 500;
    font-size: 1.25rem;
    letter-spacing: -0.01em;
    color: var(--text);
}

/* ─── MAIN LAYOUT ─────────────────── */

.main {
    display: flex;
    height: calc(100dvh - var(--header-h));
}

/* ─── PANEL ───────────────────────── */

.panel {
    width: var(--panel-width);
    flex-shrink: 0;
    background: var(--surface);
    border-right: 1px solid var(--border);
    overflow: hidden;
    display: flex;
    flex-direction: column;
}

.panel-scroll {
    flex: 1;
    overflow-y: auto;
    overflow-x: hidden;
    padding: 20px;
    display: flex;
    flex-direction: column;
    gap: 18px;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: thin;
    scrollbar-color: var(--border) transparent;
}

.panel-scroll::-webkit-scrollbar {
    width: 5px;
}

.panel-scroll::-webkit-scrollbar-thumb {
    background: var(--border);
    border-radius: 10px;
}

/* ─── CUSTOM YEAR INPUT ───────────── */

.custom-year-input {
    width: 100%;
    padding: 9px 12px;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    background: var(--surface);
    font-family: var(--font);
    font-size: 0.88rem;
    color: var(--text);
    transition: border-color .2s, opacity .2s, max-height .25s ease;
    max-height: 44px;
    margin-top: 6px;
    -moz-appearance: textfield;
}

.custom-year-input::-webkit-inner-spin-button,
.custom-year-input::-webkit-outer-spin-button {
    -webkit-appearance: none;
    margin: 0;
}

.custom-year-input:focus {
    outline: none;
    border-color: var(--accent);
}

/* ─── LIFE EVENTS ─────────────────── */

.event-add-row {
    display: flex;
    gap: 6px;
    margin-top: 4px;
}

.event-age-input {
    width: 60px;
    padding: 7px 8px;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    background: var(--surface);
    font-family: var(--font);
    font-size: 0.82rem;
    color: var(--text);
    -moz-appearance: textfield;
}

.event-age-input::-webkit-inner-spin-button,
.event-age-input::-webkit-outer-spin-button {
    -webkit-appearance: none;
    margin: 0;
}

.event-text-input {
    flex: 1;
    min-width: 0;
    padding: 7px 8px;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    background: var(--surface);
    font-family: var(--font);
    font-size: 0.82rem;
    color: var(--text);
}

.event-age-input:focus,
.event-text-input:focus {
    outline: none;
    border-color: var(--accent);
}

.event-add-btn {
    width: 34px;
    height: 34px;
    flex-shrink: 0;
    border: 1px solid var(--accent);
    border-radius: var(--radius-sm);
    background: var(--accent);
    color: white;
    font-size: 1.1rem;
    font-weight: 600;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background .2s;
    -webkit-tap-highlight-color: transparent;
}

.event-add-btn:hover {
    background: var(--accent-hover);
}

.event-list {
    display: flex;
    flex-direction: column;
    gap: 4px;
    margin-top: 6px;
    max-height: 200px;
    overflow-y: auto;
}

.event-item {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 5px 8px;
    background: var(--surface-alt);
    border: 1px solid var(--border-light);
    border-radius: 5px;
    font-size: 0.78rem;
}

.event-item-marker {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--accent);
    flex-shrink: 0;
}

.event-item-age {
    font-weight: 600;
    color: var(--text);
    flex-shrink: 0;
    min-width: 28px;
}

.event-item-text {
    flex: 1;
    min-width: 0;
    color: var(--text-dim);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.event-item-del {
    width: 20px;
    height: 20px;
    border: none;
    background: transparent;
    color: var(--text-faint);
    font-size: 0.9rem;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    flex-shrink: 0;
    transition: all .15s;
    -webkit-tap-highlight-color: transparent;
}

.event-item-del:hover {
    background: var(--border-light);
    color: var(--accent);
}

.custom-year-input.hidden {
    display: none;
}

/* ─── CONTROL GROUP ───────────────── */

.control-group {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.control-label {
    font-size: 0.72rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: var(--text-dim);
}

.divider {
    border: none;
    height: 1px;
    background: var(--border-light);
    margin: 2px 0;
}

/* ─── SEGMENTED BUTTONS ───────────── */

.seg-group {
    display: flex;
    gap: 0;
    background: var(--surface-alt);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    padding: 3px;
}

.seg-group.seg-wrap {
    flex-wrap: wrap;
}

.seg-btn {
    flex: 1;
    padding: 7px 10px;
    border: none;
    background: transparent;
    border-radius: 5px;
    font-family: var(--font);
    font-size: 0.82rem;
    font-weight: 500;
    color: var(--text-dim);
    cursor: pointer;
    transition: all .2s ease;
    white-space: nowrap;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 5px;
    -webkit-tap-highlight-color: transparent;
    user-select: none;
}

.seg-btn:hover {
    color: var(--text);
}

.seg-btn.active {
    background: var(--surface);
    color: var(--text);
    box-shadow: var(--shadow-sm);
}

.seg-wrap .seg-btn {
    min-width: calc(33.333% - 4px);
}

.orient-icon {
    width: 16px;
    height: 16px;
    flex-shrink: 0;
}

.color-dot {
    width: 10px;
    height: 10px;
    border-radius: 50%;
    display: inline-block;
    border: 1px solid rgba(0,0,0,.1);
}

/* ─── SELECT ──────────────────────── */

.select-wrap {
    position: relative;
}

.select-wrap select {
    width: 100%;
    padding: 9px 32px 9px 12px;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    background: var(--surface);
    font-family: var(--font);
    font-size: 0.88rem;
    color: var(--text);
    cursor: pointer;
    appearance: none;
    -webkit-appearance: none;
    transition: border-color .2s;
}

.select-wrap select:focus {
    outline: none;
    border-color: var(--accent);
}

.select-arrow {
    position: absolute;
    right: 10px;
    top: 50%;
    transform: translateY(-50%);
    width: 12px;
    height: 12px;
    color: var(--text-dim);
    pointer-events: none;
}

/* ─── TOGGLES ─────────────────────── */

.toggle-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 6px 0;
}

.toggle-row + .toggle-row {
    border-top: 1px solid var(--border-light);
}

.toggle-label {
    font-size: 0.88rem;
    color: var(--text);
}

.toggle {
    width: 44px;
    height: 26px;
    border-radius: 13px;
    background: var(--toggle-bg);
    border: none;
    padding: 3px;
    cursor: pointer;
    transition: background .25s ease;
    flex-shrink: 0;
    -webkit-tap-highlight-color: transparent;
}

.toggle.active {
    background: var(--toggle-active);
}

.toggle-knob {
    display: block;
    width: 20px;
    height: 20px;
    border-radius: 50%;
    background: white;
    box-shadow: 0 1px 3px rgba(0,0,0,.2);
    transition: transform .25s cubic-bezier(.4, .0, .2, 1);
}

.toggle.active .toggle-knob {
    transform: translateX(18px);
}

/* ─── FEATURE REQUEST FORM ────────── */

.prompt-input,
.prompt-textarea {
    width: 100%;
    padding: 8px 10px;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    background: var(--surface);
    font-family: var(--font);
    font-size: 0.85rem;
    color: var(--text);
    transition: border-color .2s;
    margin-bottom: 6px;
}

.prompt-textarea {
    resize: vertical;
    min-height: 60px;
}

.prompt-input:focus,
.prompt-textarea:focus {
    outline: none;
    border-color: var(--accent);
}

.btn-sm {
    padding: 8px 14px;
    font-size: 0.82rem;
    width: 100%;
}

.prompt-feedback {
    font-size: 0.78rem;
    margin-top: 6px;
    min-height: 18px;
}

.prompt-feedback.success {
    color: #30a46c;
}

.prompt-feedback.error {
    color: var(--accent);
}

/* ─── VERSION ROW ─────────────────── */

.version-row {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
    padding: 4px 0 0;
}

.version-tag {
    font-size: 10px;
    color: var(--text-faint);
    letter-spacing: 0.06em;
    opacity: 0.6;
    white-space: nowrap;
}

.btn-update {
    padding: 4px 10px;
    background: transparent;
    border: 1px solid var(--border);
    border-radius: 5px;
    color: var(--text-faint);
    font-family: var(--font);
    font-size: 10px;
    font-weight: 500;
    cursor: pointer;
    -webkit-appearance: none;
    transition: all 0.2s ease;
}

.btn-update:active {
    background: var(--surface-alt);
    color: var(--accent);
    border-color: var(--accent);
}

/* ─── BUTTONS ─────────────────────── */

.panel-footer {
    flex-shrink: 0;
    padding: 14px 20px max(14px, env(safe-area-inset-bottom));
    border-top: 1px solid var(--border-light);
    background: var(--surface);
}

.actions {
    display: flex;
    gap: 8px;
}

.btn {
    flex: 1;
    padding: 11px 16px;
    border: none;
    border-radius: var(--radius-sm);
    font-family: var(--font);
    font-size: 0.88rem;
    font-weight: 600;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 7px;
    transition: all .2s ease;
    -webkit-tap-highlight-color: transparent;
    user-select: none;
}

.btn-icon {
    width: 18px;
    height: 18px;
    flex-shrink: 0;
}

.btn-secondary {
    background: var(--surface-alt);
    color: var(--text);
    border: 1px solid var(--border);
}

.btn-secondary:hover {
    background: var(--border-light);
}

.btn-primary {
    background: var(--accent);
    color: white;
}

.btn-primary:hover {
    background: var(--accent-hover);
}

.btn:active {
    transform: scale(.97);
}

/* ─── PREVIEW AREA ────────────────── */

.preview-area {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 12px;
    gap: 10px;
    min-width: 0;
    overflow: hidden;
}

.preview-container {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    width: 100%;
    min-height: 0;
}

#previewCanvas {
    box-shadow: var(--shadow-paper);
    border-radius: 2px;
    max-width: 100%;
    max-height: 100%;
    object-fit: contain;
    transition: box-shadow .3s;
}

/* ─── PAGE NAV ────────────────────── */

.page-nav {
    display: flex;
    align-items: center;
    gap: 12px;
    flex-shrink: 0;
    margin-top: -8px;
}

.page-nav.hidden {
    display: none;
}

.page-btn {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    border: 1px solid var(--border);
    background: var(--surface);
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: all .2s;
    -webkit-tap-highlight-color: transparent;
}

.page-btn:hover {
    border-color: var(--accent);
    color: var(--accent);
}

.page-btn:disabled {
    opacity: .3;
    pointer-events: none;
}

.page-btn svg {
    width: 14px;
    height: 14px;
}

.page-info {
    font-size: 0.82rem;
    color: var(--text-dim);
    min-width: 100px;
    text-align: center;
    font-variant-numeric: tabular-nums;
}

/* ─── RESPONSIVE ──────────────────── */


@media (max-width: 860px) {
    :root {
        --panel-width: 100%;
        --header-h: 56px;
    }

    .main {
        flex-direction: column;
        height: auto;
        min-height: calc(100dvh - var(--header-h));
    }

    .panel {
        width: 100%;
        border-right: none;
        border-bottom: 1px solid var(--border);
        overflow: visible;
    }

    .panel-scroll {
        padding: 16px;
        gap: 14px;
        max-height: none;
        overflow: visible;
    }

    .preview-area {
        padding: 16px;
        min-height: 50vh;
    }

    .panel-footer {
        position: fixed;
        bottom: 0;
        left: 0;
        right: 0;
        padding: 12px 16px max(12px, env(safe-area-inset-bottom));
        z-index: 100;
        border-top: 1px solid var(--border);
        box-shadow: 0 -2px 8px rgba(0,0,0,.06);
    }

    .preview-area {
        padding-bottom: 120px;
    }
}

@media (max-width: 480px) {
    html {
        font-size: 14px;
    }

    .seg-wrap .seg-btn {
        min-width: calc(33.333% - 4px);
        padding: 7px 6px;
        font-size: 0.78rem;
    }

    .header-inner {
        padding: 0 16px;
    }
}

/* ─── PRINT ───────────────────────── */

@media print {
    .header, .panel, .page-nav { display: none !important; }
    .preview-area { padding: 0; }
    body { background: white; }
}

/* ─── LOADING STATE ───────────────── */

.btn.loading {
    pointer-events: none;
    opacity: .7;
}

.btn.loading::after {
    content: '';
    width: 16px;
    height: 16px;
    border: 2px solid currentColor;
    border-top-color: transparent;
    border-radius: 50%;
    animation: spin .6s linear infinite;
    margin-left: 4px;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

/* ─── About Button ─────────────────── */

.about-btn {
    background: none;
    border: none;
    color: var(--text-dim);
    cursor: pointer;
    padding: 2px;
    opacity: 0.5;
    transition: opacity .2s, color .2s;
    vertical-align: middle;
    display: inline-flex;
    align-items: center;
}
.about-btn:hover { opacity: 1; color: var(--accent); }

/* ─── Modal ────────────────────────── */

.modal-overlay {
    display: none;
    position: fixed;
    inset: 0;
    z-index: 1000;
    background: rgba(44, 40, 37, .45);
    backdrop-filter: blur(4px);
    align-items: center;
    justify-content: center;
}
.modal-overlay.active {
    display: flex;
}
.modal {
    background: var(--surface);
    border-radius: var(--radius);
    box-shadow: var(--shadow-lg);
    max-width: 480px;
    width: 90%;
    padding: 28px 32px;
    position: relative;
    animation: modalIn .2s ease-out;
}
@keyframes modalIn {
    from { opacity: 0; transform: translateY(12px) scale(.97); }
    to { opacity: 1; transform: none; }
}
.modal-close {
    position: absolute;
    top: 12px;
    right: 16px;
    background: none;
    border: none;
    font-size: 1.4rem;
    color: var(--text-dim);
    cursor: pointer;
    line-height: 1;
    padding: 4px;
}
.modal-close:hover { color: var(--text); }
.modal-title {
    font-family: var(--font-display);
    font-size: 1.25rem;
    font-weight: 600;
    color: var(--text);
    margin-bottom: 16px;
}
.modal-body p {
    font-size: 0.88rem;
    color: var(--text-dim);
    line-height: 1.6;
    margin-bottom: 12px;
}
.modal-body p:last-child { margin-bottom: 0; }
.modal-copyright {
    margin-top: 16px;
    padding-top: 12px;
    border-top: 1px solid var(--border-light);
    font-size: 0.75rem;
    color: var(--text-faint);
    text-align: center;
}
