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

:root {
    --bg: #ffffff;
    --text: #000000;
    --dim: #888888;
    --link: #000000;
    --input-bg: #f5f5f5;
    --input-border: #ddd;
    --card-bg: #fafafa;
    --card-border: #eee;
}
html[data-theme="dark"] {
    --bg: #0a0a0c;
    --text: #e0ddd8;
    --dim: #4a4a52;
    --link: #e0ddd8;
    --input-bg: #141418;
    --input-border: #2a2a30;
    --card-bg: #111114;
    --card-border: #1e1e24;
}

html { font-size: 18px; }

body {
    background: var(--bg);
    color: var(--text);
    font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif;
    font-weight: 700;
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    line-height: 1.35;
    transition: background 0.6s ease, color 0.6s ease;
    position: relative;
    overflow-x: hidden;
}

/* ── Starfield canvas ── */
#stars {
    position: fixed; inset: 0; z-index: 0;
    opacity: 0; transition: opacity 1s ease; pointer-events: none;
}
html[data-theme="dark"] #stars { opacity: 1; }

/* ── Noise overlay ── */
body::before {
    content: ''; position: fixed; inset: 0; z-index: 1;
    pointer-events: none; opacity: 0; transition: opacity 0.6s ease;
    background-image: url("data:image/svg+xml,%3Csvg viewBox='0 0 512 512' xmlns='http://www.w3.org/2000/svg'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.75' numOctaves='4' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)' opacity='0.025'/%3E%3C/svg%3E");
}
html[data-theme="dark"] body::before { opacity: 1; }

/* ── Navigation ── */
.site-nav {
    position: fixed;
    top: clamp(48px, 6vw, 80px);
    right: clamp(48px, 6vw, 80px);
    z-index: 50;
}
.nav-inner {
    display: flex; align-items: center; gap: 20px;
}
.nav-links {
    display: flex; align-items: center; gap: 20px;
    list-style: none;
}
.nav-links a {
    color: var(--dim); text-decoration: none;
    font-weight: 400; font-size: 0.7rem;
    letter-spacing: 0.02em; text-transform: lowercase;
    transition: color 0.3s;
}
.nav-links a:hover, .nav-links a.active {
    color: var(--text);
}
.secondary-nav {
    display: none;
}

/* ── Theme toggle ── */
.toggle {
    width: 34px; height: 18px;
    border-radius: 9px; border: 1.5px solid var(--dim);
    background: transparent; cursor: pointer; padding: 0;
    transition: border-color 0.6s ease;
    -webkit-tap-highlight-color: transparent;
    position: relative; flex-shrink: 0;
}
.toggle::after {
    content: ''; position: absolute; top: 2px; left: 2.5px;
    width: 10px; height: 10px; border-radius: 50%;
    background: var(--text);
    transition: transform 0.35s cubic-bezier(0.4, 0, 0.2, 1), background 0.6s ease;
}
html[data-theme="dark"] .toggle::after {
    transform: translateX(15px);
    box-shadow: 0 0 6px rgba(224, 221, 216, 0.3);
}

/* ── Main content wrapper ── */
.page {
    position: relative; z-index: 2;
    max-width: 1100px; width: 100%;
    margin: 0;
    padding: clamp(48px, 6vw, 80px) clamp(48px, 6vw, 80px) 80px;
    flex: 1;
}

/* ── Home page ── */
.home-content { max-width: 620px; }
.block { margin-bottom: 1.8em; }

a {
    color: var(--link); text-decoration: underline;
    text-underline-offset: 3px; text-decoration-thickness: 2px;
    transition: color 0.3s, text-decoration-color 0.3s;
}
html[data-theme="dark"] a { text-decoration-color: #555; }
html[data-theme="dark"] a:hover { text-decoration-color: var(--text); }

.dim {
    color: var(--dim); font-weight: 400; font-size: 0.8rem;
    transition: color 0.6s ease;
}

/* ── Page headers ── */
.page-header {
    margin-bottom: 48px;
}
.page-header h1 {
    font-size: 1.6rem; font-weight: 700;
    letter-spacing: -0.03em; margin-bottom: 8px;
}
.page-header p {
    color: var(--dim); font-weight: 400; font-size: 0.85rem;
    max-width: 500px; line-height: 1.5;
}

/* ── Projects grid ── */
.projects-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(320px, 1fr));
    gap: 20px;
}
.project-card {
    border: 1px solid var(--card-border);
    background: var(--card-bg);
    padding: 28px; transition: border-color 0.3s, transform 0.3s;
    text-decoration: none; color: inherit; display: block;
}
.project-card:hover {
    border-color: var(--dim);
    transform: translateY(-2px);
    text-decoration: none;
}
html[data-theme="dark"] .project-card:hover {
    text-decoration: none;
}
.project-card .project-tag {
    display: inline-block;
    font-size: 0.6rem; font-weight: 400;
    color: var(--dim); letter-spacing: 0.06em;
    text-transform: uppercase; margin-bottom: 12px;
    border: 1px solid var(--card-border); padding: 3px 8px;
    transition: border-color 0.3s, color 0.3s;
}
.project-card h3 {
    font-size: 1rem; font-weight: 700;
    letter-spacing: -0.02em; margin-bottom: 8px;
}
.project-card p {
    font-weight: 400; font-size: 0.8rem;
    color: var(--dim); line-height: 1.5;
}
.project-card .project-year {
    margin-top: 16px; font-size: 0.65rem;
    font-weight: 400; color: var(--dim);
    letter-spacing: 0.04em;
}

/* ── Records grid ── */
.records-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
    gap: 24px;
}
.record-card {
    text-decoration: none; color: inherit; display: block;
    transition: transform 0.3s;
}
.record-card:hover {
    transform: translateY(-3px);
    text-decoration: none;
}
html[data-theme="dark"] .record-card:hover { text-decoration: none; }
.record-cover {
    width: 100%; aspect-ratio: 1;
    background: var(--card-bg); border: 1px solid var(--card-border);
    margin-bottom: 14px; overflow: hidden;
    transition: border-color 0.3s;
}
.record-card:hover .record-cover { border-color: var(--dim); }
.record-cover img {
    width: 100%; height: 100%; object-fit: cover;
    display: block;
}
.record-cover .cover-placeholder {
    width: 100%; height: 100%;
    display: flex; align-items: center; justify-content: center;
    color: var(--dim); font-size: 0.7rem; font-weight: 400;
}
.record-card h3 {
    font-size: 0.9rem; font-weight: 700;
    letter-spacing: -0.01em; margin-bottom: 2px;
}
.record-meta {
    font-size: 0.7rem; font-weight: 400; color: var(--dim);
}
.record-meta span + span::before {
    content: '·'; margin: 0 6px;
}

/* ── Writing / Blog ── */
.writing-list {
    max-width: 660px;
}
.writing-item {
    display: block; text-decoration: none; color: inherit;
    padding: 24px 0;
    border-bottom: 1px solid var(--card-border);
    transition: padding-left 0.3s;
}
.writing-item:first-child { border-top: 1px solid var(--card-border); }
.writing-item:hover {
    padding-left: 8px;
    text-decoration: none;
}
html[data-theme="dark"] .writing-item:hover { text-decoration: none; }
.writing-item h3 {
    font-size: 0.95rem; font-weight: 700;
    letter-spacing: -0.01em; margin-bottom: 6px;
}
.writing-item p {
    font-weight: 400; font-size: 0.8rem;
    color: var(--dim); line-height: 1.5;
    margin-bottom: 8px;
}
.writing-item .writing-date {
    font-size: 0.65rem; font-weight: 400;
    color: var(--dim); letter-spacing: 0.03em;
}

/* ── Contact form ── */
.contact {
    max-height: 0; overflow: hidden; opacity: 0;
    transition: max-height 0.5s ease, opacity 0.4s ease, margin 0.4s ease;
    margin-top: 0;
}
.contact.open {
    max-height: 500px; opacity: 1; margin-top: 2.5em;
}
.contact-inner { padding-top: 0.5em; }

.contact input, .contact textarea {
    display: block; width: 100%; max-width: 400px;
    background: var(--input-bg); color: var(--text);
    border: 1px solid var(--input-border);
    font-family: inherit; font-weight: 400; font-size: 0.85rem;
    padding: 10px 12px; margin-bottom: 10px;
    outline: none; transition: border-color 0.2s, background 0.3s;
}
.contact input:focus, .contact textarea:focus { border-color: var(--text); }
.contact input::placeholder, .contact textarea::placeholder { color: var(--dim); }
.contact textarea { resize: vertical; min-height: 80px; }

.contact-actions {
    display: flex; align-items: center; gap: 16px; margin-top: 4px;
}
.contact button {
    background: var(--text); color: var(--bg);
    border: none; font-family: inherit; font-weight: 700;
    font-size: 0.8rem; padding: 8px 20px; cursor: pointer;
    transition: opacity 0.2s;
}
.contact button:hover { opacity: 0.8; }
.contact button:disabled { opacity: 0.3; cursor: default; }

.contact .mail-fallback {
    font-size: 0.7rem; color: var(--dim); font-weight: 400;
}
.contact .mail-fallback a {
    color: var(--dim); text-decoration-thickness: 1px;
}

.contact .sent-msg {
    font-weight: 400; font-size: 0.85rem; color: var(--dim);
}

/* ── Footer ── */
.site-footer {
    position: relative; z-index: 2;
    max-width: 1100px; width: 100%; margin: 0;
    padding: 60px clamp(48px, 6vw, 80px) 60px;
}
.site-footer p {
    color: var(--dim); font-weight: 400; font-size: 0.7rem;
    transition: color 0.6s ease;
}
.site-footer p + p { margin-top: 0.8em; }

/* ── Admin panel (same as before) ── */
.admin-overlay {
    display: none; position: fixed; inset: 0; z-index: 200;
    background: var(--bg); overflow-y: auto;
    padding: clamp(24px, 5vw, 60px);
    transition: background 0.6s ease;
}
.admin-overlay.open { display: block; }

.admin-header {
    display: flex; align-items: center; justify-content: space-between;
    margin-bottom: 32px;
}
.admin-header h2 {
    font-size: 1rem; font-weight: 700; letter-spacing: -0.01em;
}
.admin-close {
    background: none; border: 1px solid var(--input-border);
    color: var(--text); font-family: inherit; font-weight: 400;
    font-size: 0.75rem; padding: 6px 14px; cursor: pointer;
    transition: border-color 0.2s;
}
.admin-close:hover { border-color: var(--text); }

.admin-login input {
    background: var(--input-bg); color: var(--text);
    border: 1px solid var(--input-border);
    font-family: inherit; font-size: 0.85rem; font-weight: 400;
    padding: 10px 12px; width: 240px; outline: none;
}
.admin-login input:focus { border-color: var(--text); }
.admin-login button {
    background: var(--text); color: var(--bg);
    border: none; font-family: inherit; font-weight: 700;
    font-size: 0.8rem; padding: 10px 20px; cursor: pointer;
    margin-left: 8px;
}
.admin-login .err { color: #c44; font-size: 0.75rem; margin-top: 8px; font-weight: 400; }

.admin-nav {
    display: flex; gap: 24px; margin-bottom: 32px;
    border-bottom: 1px solid var(--input-border); padding-bottom: 12px;
}
.admin-nav button {
    background: none; border: none; color: var(--dim);
    font-family: inherit; font-weight: 700; font-size: 0.8rem;
    cursor: pointer; padding: 0; transition: color 0.2s;
}
.admin-nav button.active { color: var(--text); }
.admin-nav button:hover { color: var(--text); }

.msg-card {
    border: 1px solid var(--input-border); padding: 16px;
    margin-bottom: 12px; transition: border-color 0.2s;
}
.msg-card:hover { border-color: var(--dim); }
.msg-meta {
    display: flex; gap: 16px; align-items: baseline;
    margin-bottom: 8px; flex-wrap: wrap;
}
.msg-name { font-weight: 700; font-size: 0.85rem; }
.msg-contact { font-weight: 400; font-size: 0.75rem; color: var(--dim); }
.msg-time { font-weight: 400; font-size: 0.65rem; color: var(--dim); margin-left: auto; }
.msg-body { font-weight: 400; font-size: 0.85rem; line-height: 1.5; margin-bottom: 10px; }
.msg-delete {
    background: none; border: none; color: var(--dim);
    font-family: inherit; font-size: 0.7rem; cursor: pointer;
    padding: 0; font-weight: 400;
}
.msg-delete:hover { color: #c44; }

.msg-empty {
    color: var(--dim); font-weight: 400; font-size: 0.85rem;
}

.admin-section { display: none; }
.admin-section.active { display: block; }

.admin-placeholder {
    color: var(--dim); font-weight: 400; font-size: 0.85rem;
    font-style: italic;
}

/* ── Billing panel layout ── */
.billing-container {
    display: grid;
    grid-template-columns: 1fr 1.2fr;
    gap: 40px;
    align-items: start;
}

@media (max-width: 800px) {
    .billing-container {
        grid-template-columns: 1fr;
        gap: 32px;
    }
}

/* ── Apple Pay & Invoice styles ── */
.invoice-sheet {
    border: 1px solid var(--card-border);
    background: var(--card-bg);
    padding: clamp(24px, 6vw, 60px);
    max-width: 700px;
    margin: 0 auto;
    position: relative;
}

.invoice-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    border-bottom: 1px solid var(--card-border);
    padding-bottom: 24px;
    margin-bottom: 32px;
}

.invoice-status {
    padding: 6px 14px;
    font-size: 0.65rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.status-unpaid {
    background: rgba(200, 68, 68, 0.1);
    color: #c44;
    border: 1px solid rgba(200, 68, 68, 0.2);
}

.status-paid {
    background: rgba(68, 200, 68, 0.1);
    color: #4c4;
    border: 1px solid rgba(68, 200, 68, 0.2);
}

.invoice-row {
    display: flex;
    justify-content: space-between;
    padding: 16px 0;
    border-bottom: 1px solid var(--card-border);
    font-weight: 400;
    font-size: 0.85rem;
}

.invoice-row.total {
    font-weight: 700;
    font-size: 1.1rem;
    border-bottom: 2px solid var(--text);
    margin-top: 24px;
}

.invoice-notes {
    margin-top: 32px;
    font-weight: 400;
    font-size: 0.75rem;
    color: var(--dim);
    line-height: 1.5;
}

.payment-area {
    margin-top: 40px;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 16px;
}

/* Apple Pay Button */
.apple-pay-btn {
    background: var(--text);
    color: var(--bg);
    border: none;
    border-radius: 4px;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    font-weight: 500;
    font-size: 0.95rem;
    height: 48px;
    padding: 0 24px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    gap: 6px;
    width: 100%;
    max-width: 320px;
    transition: opacity 0.2s, transform 0.2s;
    -webkit-tap-highlight-color: transparent;
}
.apple-pay-btn:hover {
    opacity: 0.9;
}
.apple-pay-btn:active {
    transform: scale(0.98);
}
.apple-pay-btn svg {
    height: 20px;
    fill: currentColor;
}

/* Custom Sliding sheet modal simulation */
.payment-sheet-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.6);
    z-index: 1000;
    display: flex;
    align-items: flex-end;
    justify-content: center;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.3s ease;
}

.payment-sheet-overlay.open {
    opacity: 1;
    pointer-events: auto;
}

.payment-sheet {
    background: #111115;
    color: #ffffff;
    border-top-left-radius: 16px;
    border-top-right-radius: 16px;
    width: 100%;
    max-width: 500px;
    padding: 24px;
    transform: translateY(100%);
    transition: transform 0.4s cubic-bezier(0.25, 1, 0.5, 1);
    box-shadow: 0 -10px 30px rgba(0, 0, 0, 0.5);
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
}

.payment-sheet-overlay.open .payment-sheet {
    transform: translateY(0);
}

.payment-sheet-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    border-bottom: 1px solid #22222a;
    padding-bottom: 16px;
    margin-bottom: 20px;
}

.payment-sheet-row {
    display: flex;
    justify-content: space-between;
    font-size: 0.85rem;
    padding: 12px 0;
    color: #888890;
    border-bottom: 1px solid #22222a;
}
.payment-sheet-row span.val {
    color: #ffffff;
}

.payment-sheet-row.total {
    font-size: 1.05rem;
    color: #ffffff;
    font-weight: 700;
    border-bottom: none;
    margin-top: 10px;
}

.apple-pay-auth {
    display: flex;
    flex-direction: column;
    align-items: center;
    margin-top: 24px;
    gap: 12px;
}

.auth-circle {
    width: 60px;
    height: 60px;
    border-radius: 50%;
    border: 2px solid #007aff;
    display: flex;
    align-items: center;
    justify-content: center;
    position: relative;
    cursor: pointer;
    background: rgba(0, 122, 255, 0.05);
}

.auth-circle svg {
    width: 28px;
    height: 28px;
    fill: #007aff;
}

.auth-circle.authenticating::before {
    content: '';
    position: absolute;
    inset: -6px;
    border-radius: 50%;
    border: 2px solid transparent;
    border-top-color: #007aff;
    animation: rotate 1s linear infinite;
}

.auth-circle.success {
    border-color: #4cd964;
    background: rgba(76, 217, 100, 0.05);
}
.auth-circle.success svg {
    fill: #4cd964;
}

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

/* ── Print Styles ── */
@media print {
    body {
        background: #ffffff !important;
        color: #000000 !important;
    }
    body::before, #stars, .site-nav, .site-footer, button, .apple-pay-btn, .payment-area, .back-btn {
        display: none !important;
    }
    .page {
        padding: 0 !important;
        margin: 0 !important;
        max-width: 100% !important;
    }
    .invoice-sheet {
        border: none !important;
        background: transparent !important;
        padding: 0 !important;
        max-width: 100% !important;
    }
    .invoice-status {
        border: 1px solid #000000 !important;
        color: #000000 !important;
        background: transparent !important;
    }
    a {
        text-decoration: none !important;
        color: #000000 !important;
    }
}

/* ── Responsive ── */
@media (max-width: 560px) {
    .page {
        padding-top: 110px !important;
    }
    .projects-grid { grid-template-columns: 1fr; }
    .records-grid { grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); }
    .nav-links { gap: 18px; }
    .nav-links a { font-size: 0.7rem; }
    br { display: none; }
    br.keep { display: inline; }
    .msg-time { margin-left: 0; }
}
