@import url('https://fonts.googleapis.com/css2?family=Noto+Serif+TC:wght@400;700;900&family=Newsreader:ital,wght@0,400;0,700;1,400&family=Public+Sans:wght@300;400;700&display=swap');

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

:root {
    --bg: #0d1228;
    --surface: #191e35;
    --surface-high: #242940;
    --surface-highest: #2f334b;
    --on-surface: #dde1ff;
    --on-surface-variant: #c7c5ce;
    --primary: #ffb4ac;
    --primary-container: #2e0001;
    --secondary: #e9c349;
    --secondary-container: #af8d11;
    --tertiary: #ffb5a0;
    --outline-variant: #46464d;
    --error: #ffb4ab;
    --shadow-sm: 0 1px 4px rgba(0,0,0,0.3);
    --shadow-md: 0 4px 16px rgba(0,0,0,0.4);
    --shadow-lg: 0 8px 32px rgba(0,0,0,0.5);
    --radius: 12px;
    --radius-lg: 16px;
}

/* ----------------------------------------------------------------
   Silk grain texture overlay
   ---------------------------------------------------------------- */
.silk-overlay {
    position: fixed;
    inset: 0;
    z-index: 9999;
    pointer-events: none;
    mix-blend-mode: soft-light;
    opacity: 0.2;
    background: url('https://lh3.googleusercontent.com/aida-public/AB6AXuAeBCLsrUMTFsGBHn_n_8tzDugoXfTTOVWkqjojj7VSLzqHvomxB1_ZMreVUvT-aaBeCuoSAeEwYhvFAARF2OYOszWF5Gqq5PwRJupzPzBGkYRt1WaTT3q5Z3cDOaeJ4TFh9AiBMGK00yh8jNd4wBsfjgSRtojYqnxabbm2VXPJfdit0jCBig0_HWUng4PIgqwO_3bytYdu35zpxtQKNo-noP0pdj1xZ33gd5d99ryjU842tO0VJl9t3dUj1nJdqPkQKAHIAUXkZQ') center/cover no-repeat;
}

/* ----------------------------------------------------------------
   Chinese fretwork border for cards
   ---------------------------------------------------------------- */
.fretwork-border {
    border-image: url("data:image/svg+xml,%3Csvg width='40' height='40' viewBox='0 0 40 40' xmlns='http://www.w3.org/2000/svg'%3E%3Cpath d='M0 0h10v2H2v8H0V0zm40 0v10h-2V2h-8V0h10zM0 40v-10h2v8h8v2H0zm40 0H30v-2h8v-8h2v10z' fill='%23af8d11' fill-opacity='0.4'/%3E%3C/svg%3E") 10 stretch;
    border-width: 2px;
    border-style: solid;
}

/* ----------------------------------------------------------------
   Base
   ---------------------------------------------------------------- */
body {
    font-family: 'Public Sans', system-ui, -apple-system, sans-serif;
    background: var(--bg);
    color: var(--on-surface);
    min-height: 100vh;
    line-height: 1.7;
    font-weight: 400;
    -webkit-font-smoothing: antialiased;
}

/* CJK font stacks */
html[lang^="zh"] body {
    font-family: 'Public Sans', 'PingFang HK', 'PingFang TC', 'Noto Sans HK', 'Noto Sans TC', 'Microsoft JhengHei', system-ui, sans-serif;
}

html[lang^="zh"] .app-title,
html[lang^="zh"] .form-header h1,
html[lang^="zh"] .form-section h2,
html[lang^="zh"] .hero-pillar,
html[lang^="zh"] .reading-section h2,
html[lang^="zh"] .loading-text,
html[lang^="zh"] #reading-content h1,
html[lang^="zh"] #reading-content h2,
html[lang^="zh"] #reading-content h3 {
    font-family: 'Noto Serif TC', 'PingFang HK', 'PingFang TC', 'Noto Serif HK', 'Noto Serif TC', Georgia, serif;
}

/* ----------------------------------------------------------------
   App shell
   ---------------------------------------------------------------- */
.app-shell {
    max-width: 960px;
    margin: 0 auto;
    padding: 0 1.5rem 4rem;
}

.phase-container {
    animation: fadeIn 0.4s ease-out;
}

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

/* ----------------------------------------------------------------
   Top bar (persistent across phases)
   ---------------------------------------------------------------- */
.top-bar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 1.25rem 0;
    margin-bottom: 1rem;
    border-bottom: 1px solid var(--outline-variant);
}

.app-title {
    font-family: 'Noto Serif TC', Georgia, serif;
    font-size: 1.4rem;
    font-weight: 700;
    color: var(--secondary);
    letter-spacing: 0.02em;
}

/* Language toggle */
.lang-toggle {
    display: flex;
    gap: 0;
    padding: 0.2rem;
    background: var(--surface);
    border: 1px solid var(--outline-variant);
    border-radius: 999px;
    box-shadow: var(--shadow-sm);
}

.lang-btn {
    background: transparent;
    border: none;
    padding: 0.35rem 0.85rem;
    font-family: 'Public Sans', system-ui, sans-serif;
    font-size: 0.75rem;
    font-weight: 500;
    letter-spacing: 0.05em;
    color: var(--on-surface-variant);
    cursor: pointer;
    border-radius: 999px;
    transition: background 0.2s, color 0.2s;
}

.lang-btn:hover:not(.active) {
    color: var(--on-surface);
}

.lang-btn.active {
    background: var(--surface-high);
    color: var(--secondary);
    box-shadow: var(--shadow-sm);
}

/* ----------------------------------------------------------------
   PHASE 1: Form
   ---------------------------------------------------------------- */
.form-header {
    text-align: center;
    margin-bottom: 2.5rem;
    padding: 1rem 0 1.5rem;
}

.subtitle {
    color: var(--on-surface-variant);
    font-size: 0.8rem;
    font-weight: 300;
    letter-spacing: 0.18em;
    text-transform: uppercase;
}

#reading-form {
    max-width: 640px;
    margin: 0 auto;
}

.form-section {
    margin-bottom: 2rem;
}

.form-section h2 {
    font-family: 'Noto Serif TC', Georgia, serif;
    font-size: 1.05rem;
    font-weight: 400;
    color: var(--on-surface);
    margin-bottom: 1rem;
    padding-bottom: 0.6rem;
    border-bottom: 1px solid var(--outline-variant);
}

.form-group {
    margin-bottom: 0.9rem;
}

.form-row {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
    gap: 0.9rem;
}

label {
    display: block;
    font-size: 0.75rem;
    font-weight: 500;
    color: var(--on-surface-variant);
    margin-bottom: 0.35rem;
    letter-spacing: 0.04em;
    text-transform: uppercase;
    font-family: 'Public Sans', sans-serif;
}

.required { color: var(--primary); font-weight: 400; }
.optional { color: var(--on-surface-variant); font-size: 0.7rem; text-transform: none; font-weight: 300; }

/* Info popover */
.info-trigger {
    position: relative;
    display: inline-block;
    vertical-align: middle;
    margin-left: 0.2rem;
    cursor: pointer;
    font-size: 0.85rem;
    color: var(--on-surface-variant);
    transition: color 0.2s;
    text-transform: none;
    letter-spacing: normal;
}

.info-trigger:hover,
.info-trigger:focus {
    color: var(--secondary);
}

.info-popover {
    display: none;
    position: absolute;
    left: 50%;
    top: calc(100% + 8px);
    transform: translateX(-50%);
    width: 300px;
    padding: 1rem 1.1rem;
    background: var(--surface-highest);
    border: 1px solid var(--outline-variant);
    border-radius: var(--radius);
    box-shadow: var(--shadow-lg);
    font-size: 0.8rem;
    font-weight: 300;
    line-height: 1.6;
    color: var(--on-surface);
    text-transform: none;
    letter-spacing: normal;
    z-index: 100;
}

.info-popover::before {
    content: '';
    position: absolute;
    top: -6px;
    left: 50%;
    transform: translateX(-50%) rotate(45deg);
    width: 10px;
    height: 10px;
    background: var(--surface-highest);
    border-top: 1px solid var(--outline-variant);
    border-left: 1px solid var(--outline-variant);
}

.info-popover strong {
    font-weight: 600;
    color: var(--on-surface);
}

.info-popover em {
    color: var(--secondary);
    font-style: italic;
}

.info-trigger:hover .info-popover,
.info-trigger:focus .info-popover,
.info-trigger.active .info-popover {
    display: block;
}

@media (max-width: 600px) {
    .info-popover {
        left: 0;
        transform: none;
        width: 260px;
    }
    .info-popover::before {
        left: 12px;
        transform: rotate(45deg);
    }
}

.field-hint {
    display: block;
    color: var(--on-surface-variant);
    font-size: 0.72rem;
    font-weight: 300;
    margin-top: 0.3rem;
    line-height: 1.4;
}
.field-hint:empty { display: none; }

input, select {
    width: 100%;
    padding: 0.6rem 0.75rem;
    background: var(--surface);
    border: 1px solid var(--outline-variant);
    border-radius: 8px;
    color: var(--on-surface);
    font-family: 'Public Sans', system-ui, sans-serif;
    font-size: 0.88rem;
    font-weight: 400;
    transition: border-color 0.2s, box-shadow 0.2s;
    box-shadow: var(--shadow-sm);
}

input:focus, select:focus {
    outline: none;
    border-color: var(--secondary);
    box-shadow: 0 0 0 3px rgba(233, 195, 73, 0.15);
}

input::placeholder {
    color: var(--on-surface-variant);
    opacity: 0.5;
}

select option {
    background: var(--surface);
    color: var(--on-surface);
}

/* Submit button */
button[type="submit"] {
    display: block;
    width: 100%;
    padding: 0.9rem 1.5rem;
    background: linear-gradient(135deg, var(--primary-container) 0%, #4a0e0e 100%);
    border: 1px solid var(--primary);
    border-radius: 8px;
    color: var(--primary);
    font-family: 'Public Sans', system-ui, sans-serif;
    font-size: 0.9rem;
    font-weight: 600;
    letter-spacing: 0.06em;
    text-transform: uppercase;
    cursor: pointer;
    transition: all 0.25s;
    margin-top: 1.5rem;
    box-shadow: 0 0 20px rgba(255, 180, 172, 0.1);
}

button[type="submit"]:hover:not(:disabled) {
    background: linear-gradient(135deg, #4a0e0e 0%, #6a1a1a 100%);
    box-shadow: 0 0 30px rgba(255, 180, 172, 0.2);
    transform: translateY(-1px);
}

button[type="submit"]:active:not(:disabled) {
    transform: translateY(0);
}

button[type="submit"]:disabled {
    opacity: 0.4;
    cursor: not-allowed;
}

/* ----------------------------------------------------------------
   PHASE 2: Dashboard
   ---------------------------------------------------------------- */

/* Hero section */
.hero-section {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 2rem;
    align-items: center;
    margin-bottom: 2.5rem;
    padding: 2rem 0;
    min-height: 280px;
}

.hero-text {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.hero-year-label {
    font-family: 'Noto Serif TC', Georgia, serif;
    font-size: 5rem;
    font-weight: 900;
    line-height: 1;
    color: var(--secondary);
    opacity: 0.35;
    letter-spacing: -0.02em;
}

.hero-pillar {
    font-family: 'Noto Serif TC', Georgia, serif;
    font-size: 2.2rem;
    font-weight: 700;
    color: var(--on-surface);
    line-height: 1.2;
}

.hero-tagline {
    font-family: 'Newsreader', Georgia, serif;
    font-size: 1rem;
    font-style: italic;
    color: var(--on-surface-variant);
    margin-top: 0.25rem;
    line-height: 1.5;
}

.new-reading-btn {
    display: inline-flex;
    align-items: center;
    gap: 0.4rem;
    margin-top: 1rem;
    padding: 0.5rem 1.2rem;
    background: var(--surface);
    border: 1px solid var(--outline-variant);
    border-radius: 8px;
    color: var(--on-surface-variant);
    font-family: 'Public Sans', sans-serif;
    font-size: 0.8rem;
    font-weight: 500;
    letter-spacing: 0.04em;
    cursor: pointer;
    transition: all 0.2s;
    width: fit-content;
}

.new-reading-btn:hover {
    background: var(--surface-high);
    color: var(--on-surface);
    border-color: var(--secondary);
}

.new-reading-btn .material-symbols-outlined {
    font-size: 1rem;
}

.hero-image {
    position: relative;
    display: flex;
    justify-content: center;
    align-items: center;
}

.hero-image img {
    width: 100%;
    max-width: 380px;
    height: auto;
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-lg);
    object-fit: cover;
    /* Warm tint overlay via filter */
    filter: saturate(1.1) contrast(1.05);
}

/* Dashboard card grid */
.dashboard-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 1rem;
    margin-bottom: 1rem;
}

.current-year-section {
    margin-bottom: 2rem;
}

.dash-card {
    background: var(--surface);
    border-radius: var(--radius);
    padding: 1.25rem 1.3rem;
    box-shadow: var(--shadow-sm);
    transition: box-shadow 0.25s, transform 0.25s;
    position: relative;
    overflow: hidden;
}

.dash-card:hover {
    box-shadow: var(--shadow-md);
    transform: translateY(-2px);
}

.dash-card-header {
    display: flex;
    align-items: center;
    gap: 0.6rem;
    margin-bottom: 0.6rem;
}

.dash-card-icon {
    font-size: 1.3rem;
    color: var(--secondary);
    opacity: 0.8;
}

.dash-card-titles {
    display: flex;
    flex-direction: column;
    gap: 0;
}

.dash-card-title-zh {
    font-family: 'Noto Serif TC', serif;
    font-size: 0.95rem;
    font-weight: 700;
    color: var(--on-surface);
    line-height: 1.2;
}

.dash-card-title-en {
    font-family: 'Public Sans', sans-serif;
    font-size: 0.6rem;
    font-weight: 700;
    color: var(--on-surface-variant);
    letter-spacing: 0.12em;
    text-transform: uppercase;
    line-height: 1.3;
}

.dash-card-divider {
    height: 1px;
    background: linear-gradient(to right, var(--secondary-container), transparent);
    margin-bottom: 0.8rem;
}

/* Watermark number behind numerology card */
.dash-card-watermark {
    position: absolute;
    right: 0.5rem;
    bottom: 0.25rem;
    font-family: 'Noto Serif TC', serif;
    font-size: 4.5rem;
    font-weight: 900;
    color: var(--secondary);
    opacity: 0.06;
    line-height: 1;
    pointer-events: none;
    user-select: none;
}

/* Chart values (shared between numerology, zodiac, western) */
.chart-values {
    position: relative;
    z-index: 1;
}

.chart-value {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0.2rem 0;
    font-size: 0.82rem;
}

.chart-value .label {
    color: var(--on-surface-variant);
    font-weight: 300;
    font-family: 'Public Sans', sans-serif;
}

.chart-value .value {
    color: var(--secondary);
    font-weight: 600;
    font-family: 'Public Sans', sans-serif;
}

/* Zodiac year badge */
.zodiac-year-badge[hidden] {
    display: none;
}

.zodiac-year-badge {
    display: inline-block;
    margin-top: 0.6rem;
    padding: 0.3rem 0.8rem;
    background: linear-gradient(135deg, var(--primary-container), #3a0a0a);
    border: 1px solid var(--primary);
    border-radius: 999px;
    font-family: 'Noto Serif TC', serif;
    font-size: 0.72rem;
    font-weight: 700;
    color: var(--primary);
    letter-spacing: 0.04em;
}

/* Western sign icon display */
.western-sign-display {
    text-align: center;
    padding: 0.5rem 0;
}

.western-sign-symbol {
    font-size: 2.2rem;
    display: block;
    margin-bottom: 0.3rem;
}

.western-sign-name {
    font-family: 'Noto Serif TC', serif;
    font-size: 1.1rem;
    font-weight: 700;
    color: var(--on-surface);
}

/* ----------------------------------------------------------------
   Reading section
   ---------------------------------------------------------------- */
.reading-section {
    background: var(--surface);
    border: 1px solid var(--outline-variant);
    border-radius: var(--radius-lg);
    padding: 2rem 2.2rem;
    box-shadow: var(--shadow-sm);
}

.reading-section-header {
    display: flex;
    align-items: center;
    gap: 0.6rem;
    margin-bottom: 1.5rem;
    padding-bottom: 0.8rem;
    border-bottom: 1px solid var(--outline-variant);
}

.reading-section-header .material-symbols-outlined {
    font-size: 1.4rem;
    color: var(--secondary);
}

.reading-section-header h2 {
    font-family: 'Noto Serif TC', Georgia, serif;
    font-size: 1.25rem;
    font-weight: 700;
    color: var(--on-surface);
}

#reading-content {
    font-family: 'Newsreader', Georgia, serif;
    font-size: 1.1rem;
    font-weight: 400;
    line-height: 1.9;
    min-height: 80px;
    color: var(--on-surface);
}

#reading-content h1,
#reading-content h2,
#reading-content h3 {
    font-family: 'Noto Serif TC', Georgia, serif;
    color: var(--on-surface);
    font-weight: 700;
    margin: 2rem 0 0.6rem;
}

#reading-content h1 { font-size: 1.4rem; }
#reading-content h2 { font-size: 1.15rem; }
#reading-content h3 { font-size: 1rem; }

#reading-content p {
    margin-bottom: 1rem;
}

#reading-content strong {
    color: var(--primary);
    font-weight: 700;
}

#reading-content em {
    color: var(--secondary);
    font-style: italic;
}

#reading-content hr {
    border: none;
    height: 1px;
    background: var(--outline-variant);
    margin: 2rem 0;
}

#reading-content ul, #reading-content ol {
    margin: 0.5rem 0 1rem 1.2rem;
}

#reading-content li {
    margin-bottom: 0.25rem;
}

/* Loading indicator */
#reading-loading {
    text-align: center;
    padding: 3rem 1rem;
}

.loading-spinner {
    width: 32px;
    height: 32px;
    border: 2px solid var(--outline-variant);
    border-top-color: var(--secondary);
    border-radius: 50%;
    margin: 0 auto 1.2rem;
    animation: spin 1s linear infinite;
}

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

.loading-text {
    font-family: 'Noto Serif TC', Georgia, serif;
    color: var(--on-surface);
    font-size: 1.05rem;
    margin-bottom: 0.4rem;
}

.loading-subtext {
    color: var(--on-surface-variant);
    font-size: 0.8rem;
    font-weight: 300;
}

/* Streaming cursor */
.cursor {
    display: inline-block;
    width: 2px;
    height: 1em;
    background: var(--secondary);
    margin-left: 2px;
    vertical-align: text-bottom;
    animation: blink 1s step-end infinite;
}

@keyframes blink {
    50% { opacity: 0; }
}

/* Error */
.error-message {
    color: var(--error);
    background: rgba(255, 180, 171, 0.08);
    border: 1px solid rgba(255, 180, 171, 0.25);
    border-radius: 8px;
    padding: 1rem;
    font-size: 0.9rem;
    margin-top: 1rem;
}

/* ----------------------------------------------------------------
   Responsive
   ---------------------------------------------------------------- */
@media (max-width: 768px) {
    .hero-section {
        grid-template-columns: 1fr;
        text-align: center;
    }

    .hero-text {
        align-items: center;
    }

    .hero-year-label {
        font-size: 3.5rem;
    }

    .hero-pillar {
        font-size: 1.6rem;
    }

    .hero-image img {
        max-width: 280px;
    }

    .dashboard-grid {
        grid-template-columns: 1fr;
    }

    .new-reading-btn {
        margin-left: auto;
        margin-right: auto;
    }
}

@media (max-width: 600px) {
    .app-shell {
        padding: 0 1rem 3rem;
    }

    .app-title {
        font-size: 1.1rem;
    }

    .hero-year-label {
        font-size: 2.8rem;
    }

    .hero-pillar {
        font-size: 1.3rem;
    }

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

    .reading-section {
        padding: 1.3rem;
    }

    .dash-card-watermark {
        font-size: 3rem;
    }
}
