:root {
    --bg-color: #0a0d10;
    --card-bg: #12161c;
    --panel-bg: #0d1117;
    --text-primary: #e6edf3;
    --text-secondary: #7d8590;
    --accent-color: #58a6ff;
    --accent-glow: rgba(88, 166, 255, 0.15);
    --chart-grid: #21262d;
    --dayun-color: #a371f7;
    --k-up: #f85149;
    --k-down: #3fb950;
    --border-color: rgba(255, 255, 255, 0.06);
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

html,
body {
    height: 100%;
    overflow: hidden;
}

body {
    font-family: 'Outfit', -apple-system, BlinkMacSystemFont, sans-serif;
    background: linear-gradient(180deg, var(--bg-color) 0%, #0d1117 100%);
    color: var(--text-primary);
}

/* App Container */
.app-container {
    display: flex;
    flex-direction: column;
    height: 100vh;
    padding: 16px 24px;
    max-width: 1800px;
    margin: 0 auto;
}

/* Header */
.header {
    text-align: center;
    padding: 12px 0 16px;
    flex-shrink: 0;
}

.header h1 {
    font-family: 'Noto Serif SC', serif;
    font-size: 1.75rem;
    font-weight: 700;
    letter-spacing: 4px;
    background: linear-gradient(135deg, #fff 0%, #8b949e 100%);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
}

.subtitle {
    font-size: 0.75rem;
    color: var(--text-secondary);
    letter-spacing: 3px;
    margin-top: 4px;
    text-transform: uppercase;
}

/* Main Chart Container */
.chart-container {
    flex: 1;
    display: flex;
    flex-direction: column;
    background: var(--card-bg);
    border-radius: 16px;
    border: 1px solid var(--border-color);
    box-shadow:
        0 0 0 1px rgba(255, 255, 255, 0.03),
        0 16px 48px rgba(0, 0, 0, 0.5);
    overflow: hidden;
    min-height: 0;
}

/* Canvas Wrapper */
.canvas-wrapper {
    flex: 1;
    position: relative;
    min-height: 300px;
}

canvas {
    display: block;
    width: 100%;
    height: 100%;
}

/* BaZi Display (Top Left Overlay) */
.bazi-display {
    position: absolute;
    top: 12px;
    left: 12px;
    z-index: 10;
    background: rgba(13, 17, 23, 0.85);
    backdrop-filter: blur(10px);
    border: 1px solid var(--border-color);
    border-radius: 10px;
    padding: 10px 14px;
}

.bazi-pillars {
    display: flex;
    gap: 12px;
}

.bazi-pillar {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 2px;
}

.pillar-label {
    font-size: 0.6rem;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 1px;
}

.pillar-gan {
    font-family: 'Noto Serif SC', serif;
    font-size: 1.1rem;
    font-weight: 700;
    color: var(--dayun-color);
}

.pillar-zhi {
    font-family: 'Noto Serif SC', serif;
    font-size: 1.1rem;
    font-weight: 700;
    color: var(--accent-color);
}


/* Bottom Info Panel */
.controls-panel {
    display: flex;
    gap: 12px;
    padding: 16px 24px;
    background: var(--panel-bg);
    border-top: 1px solid var(--border-color);
    flex-shrink: 0;
}

.info-card {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 16px;
    background: rgba(255, 255, 255, 0.02);
    border-radius: 8px;
    border: 1px solid var(--border-color);
    white-space: nowrap;
}

.info-card .info-label {
    font-size: 0.7rem;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 1px;
}

.info-card .info-value {
    font-size: 1.1rem;
    font-weight: 600;
    font-family: 'Noto Serif SC', serif;
    color: var(--text-primary);
}

.info-card .info-value.score {
    font-family: 'Outfit', sans-serif;
    font-size: 1.25rem;
    font-weight: 700;
    background: linear-gradient(135deg, var(--k-up), #ff7b72);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
}

.reason-card {
    flex: 1;
}

.info-card .info-value.reason {
    font-family: 'Outfit', sans-serif;
    font-size: 0.9rem;
    font-weight: 400;
    color: var(--text-secondary);
    white-space: normal;
    line-height: 1.4;
}

/* Tooltip */
.chart-tooltip {
    position: fixed;
    display: none;
    background: rgba(13, 17, 23, 0.95);
    border: 1px solid var(--border-color);
    padding: 12px 16px;
    border-radius: 10px;
    pointer-events: none;
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.5);
    z-index: 100;
    font-size: 0.85rem;
    backdrop-filter: blur(10px);
    max-width: 280px;
}

.chart-tooltip strong {
    color: var(--text-primary);
    display: block;
    margin-bottom: 6px;
    font-size: 0.95rem;
}

/* Modal Overlay */
.modal-overlay {
    position: fixed;
    inset: 0;
    display: flex;
    justify-content: center;
    align-items: center;
    background: rgba(0, 0, 0, 0.8);
    backdrop-filter: blur(8px);
    z-index: 1000;
}

.modal-overlay.hidden {
    display: none;
}

.modal-content {
    background: linear-gradient(180deg, rgba(22, 27, 34, 0.95) 0%, rgba(13, 17, 23, 0.98) 100%);
    border: 1px solid var(--border-color);
    padding: 32px 40px;
    border-radius: 20px;
    width: 90%;
    max-width: 480px;
    box-shadow: 0 32px 64px rgba(0, 0, 0, 0.6);
    animation: modalIn 0.3s ease-out;
}

@keyframes modalIn {
    from {
        opacity: 0;
        transform: scale(0.95) translateY(10px);
    }

    to {
        opacity: 1;
        transform: scale(1) translateY(0);
    }
}

.modal-header {
    text-align: center;
    margin-bottom: 28px;
}

.modal-header h2 {
    font-family: 'Noto Serif SC', serif;
    font-size: 1.5rem;
    font-weight: 700;
    color: var(--text-primary);
    margin-bottom: 8px;
}

.modal-subtitle {
    font-size: 0.85rem;
    color: var(--text-secondary);
}

/* Radio Group */
.radio-group {
    display: flex;
    gap: 12px;
    margin-bottom: 24px;
    background: rgba(255, 255, 255, 0.02);
    padding: 6px;
    border-radius: 12px;
    border: 1px solid var(--border-color);
}

.radio-label {
    flex: 1;
    position: relative;
    cursor: pointer;
    text-align: center;
}

.radio-label input {
    position: absolute;
    opacity: 0;
    width: 0;
    height: 0;
}

.radio-label span {
    display: block;
    padding: 12px;
    border-radius: 8px;
    color: var(--text-secondary);
    font-weight: 600;
    font-size: 0.95rem;
    transition: all 0.2s ease;
}

.radio-label input:checked+span {
    background: var(--accent-glow);
    color: var(--accent-color);
}

/* Input Grid */
.input-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 16px;
    margin-bottom: 24px;
}

.input-wrapper {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.input-wrapper label {
    font-size: 0.75rem;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.input-wrapper select {
    appearance: none;
    -webkit-appearance: none;
    padding: 12px 40px 12px 14px;
    background: rgba(13, 17, 23, 0.6);
    border: 1px solid var(--border-color);
    border-radius: 10px;
    color: var(--text-primary);
    font-family: 'Outfit', sans-serif;
    font-size: 1rem;
    cursor: pointer;
    transition: all 0.2s ease;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' fill='%237d8590' viewBox='0 0 16 16'%3E%3Cpath d='M7.247 11.14 2.451 5.658C1.885 5.013 2.345 4 3.204 4h9.592a1 1 0 0 1 .753 1.659l-4.796 5.48a1 1 0 0 1-1.506 0z'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 14px center;
}

.input-wrapper select:hover {
    border-color: var(--accent-color);
}

.input-wrapper select:focus {
    outline: none;
    border-color: var(--accent-color);
    box-shadow: 0 0 0 3px var(--accent-glow);
}

/* Start Button */
.start-btn {
    width: 100%;
    padding: 16px;
    background: linear-gradient(135deg, #238636 0%, #2ea043 100%);
    border: none;
    border-radius: 12px;
    color: white;
    font-weight: 700;
    font-size: 1rem;
    cursor: pointer;
    transition: all 0.2s ease;
    text-shadow: 0 1px 2px rgba(0, 0, 0, 0.2);
}

.start-btn:hover {
    transform: translateY(-2px);
    box-shadow: 0 8px 24px rgba(46, 160, 67, 0.4);
    filter: brightness(1.1);
}

.start-btn:active {
    transform: translateY(0);
}

/* ========================================
   RESPONSIVE DESIGN - Tablet & Mobile
   ======================================== */

/* Tablet (768px and below) */
@media (max-width: 768px) {
    .app-container {
        padding: 12px 16px;
    }

    .header {
        padding: 8px 0 12px;
    }

    .header h1 {
        font-size: 1.4rem;
        letter-spacing: 2px;
    }

    .subtitle {
        font-size: 0.65rem;
        letter-spacing: 2px;
    }

    .chart-container {
        border-radius: 12px;
    }

    .canvas-wrapper {
        min-height: 250px;
    }

    /* Info Panel - Wrap to 2x2 grid */
    .controls-panel {
        flex-wrap: wrap;
        gap: 8px;
        padding: 12px 16px;
    }

    .info-card {
        flex: 1 1 calc(50% - 4px);
        padding: 8px 12px;
        gap: 6px;
    }

    .info-card .info-label {
        font-size: 0.6rem;
    }

    .info-card .info-value {
        font-size: 0.95rem;
    }

    .info-card .info-value.score {
        font-size: 1.1rem;
    }

    .reason-card {
        flex: 1 1 100%;
        order: 4;
    }

    .info-card .info-value.reason {
        font-size: 0.8rem;
    }

    /* Modal Adjustments */
    .modal-content {
        padding: 24px 20px;
        border-radius: 16px;
        width: 95%;
        max-height: 90vh;
        overflow-y: auto;
    }

    .modal-header {
        margin-bottom: 20px;
    }

    .modal-header h2 {
        font-size: 1.3rem;
    }

    .input-grid {
        gap: 12px;
    }

    .input-wrapper select {
        padding: 14px 40px 14px 14px;
        font-size: 16px;
        /* Prevents iOS zoom on focus */
    }

    .start-btn {
        padding: 16px;
        font-size: 1rem;
    }
}

/* Mobile Phone (480px and below) */
@media (max-width: 480px) {
    .app-container {
        padding: 8px 12px;
    }

    .header {
        padding: 6px 0 10px;
    }

    .header h1 {
        font-size: 1.2rem;
        letter-spacing: 1px;
    }

    .subtitle {
        font-size: 0.55rem;
        letter-spacing: 1px;
    }

    .chart-container {
        border-radius: 10px;
    }

    .canvas-wrapper {
        min-height: 200px;
    }

    /* Info Panel - Stack Vertically */
    .controls-panel {
        flex-direction: column;
        gap: 6px;
        padding: 10px 12px;
    }

    .info-card {
        flex: none;
        width: 100%;
        justify-content: space-between;
        padding: 10px 14px;
    }

    .info-card .info-label {
        font-size: 0.65rem;
        min-width: 45px;
    }

    .info-card .info-value {
        font-size: 1rem;
        text-align: right;
    }

    .info-card .info-value.score {
        font-size: 1.15rem;
    }

    .reason-card {
        flex-direction: column;
        align-items: flex-start;
        gap: 4px;
    }

    .info-card .info-value.reason {
        font-size: 0.8rem;
        text-align: left;
        line-height: 1.5;
    }

    /* Modal - Full Width */
    .modal-content {
        padding: 20px 16px;
        border-radius: 14px;
        width: 100%;
        max-width: none;
        margin: 10px;
    }

    .modal-header {
        margin-bottom: 16px;
    }

    .modal-header h2 {
        font-size: 1.2rem;
    }

    .modal-subtitle {
        font-size: 0.75rem;
    }

    /* Radio Group */
    .radio-group {
        gap: 8px;
        padding: 4px;
        margin-bottom: 16px;
    }

    .radio-label span {
        padding: 10px 8px;
        font-size: 0.9rem;
    }

    /* Input Grid - Stack */
    .input-grid {
        grid-template-columns: 1fr;
        gap: 12px;
        margin-bottom: 16px;
    }

    .input-wrapper select {
        padding: 14px 40px 14px 14px;
        font-size: 16px;
        /* Prevents iOS zoom */
    }

    .start-btn {
        padding: 14px;
        font-size: 0.95rem;
        border-radius: 10px;
    }

    /* Tooltip - Bottom of screen on mobile */
    .chart-tooltip {
        font-size: 0.8rem;
        padding: 10px 12px;
        max-width: 90vw;
    }
}

/* Landscape Mode on Mobile */
@media (max-height: 500px) and (orientation: landscape) {
    .header {
        padding: 4px 0 8px;
    }

    .header h1 {
        font-size: 1rem;
    }

    .subtitle {
        display: none;
    }

    .controls-panel {
        flex-direction: row;
        flex-wrap: nowrap;
        padding: 8px 12px;
        gap: 8px;
    }

    .info-card {
        flex: 1;
        padding: 6px 10px;
    }

    .reason-card {
        flex: 2;
    }

    .info-card .info-label {
        font-size: 0.55rem;
    }

    .info-card .info-value {
        font-size: 0.85rem;
    }

    .canvas-wrapper {
        min-height: 150px;
    }
}

/* Touch Device Optimizations */
@media (hover: none) and (pointer: coarse) {
    .start-btn:hover {
        transform: none;
        box-shadow: none;
    }

    .start-btn:active {
        transform: scale(0.98);
        filter: brightness(0.9);
    }

    .input-wrapper select:hover {
        border-color: var(--border-color);
    }

    /* Larger touch targets */
    .radio-label span {
        min-height: 44px;
        display: flex;
        align-items: center;
        justify-content: center;
    }

    .input-wrapper select {
        min-height: 48px;
    }

    .start-btn {
        min-height: 50px;
    }
}

/* Safe Area for notched phones (iPhone X+) */
@supports (padding: max(0px)) {
    .app-container {
        padding-left: max(12px, env(safe-area-inset-left));
        padding-right: max(12px, env(safe-area-inset-right));
        padding-bottom: max(8px, env(safe-area-inset-bottom));
    }
}

/* ========================================
   LANDSCAPE ROTATION PROMPT
   ======================================== */

.rotate-prompt {
    display: none;
    position: fixed;
    inset: 0;
    background: linear-gradient(135deg, var(--bg-color) 0%, #0d1117 100%);
    z-index: 2000;
    justify-content: center;
    align-items: center;
    flex-direction: column;
}

.rotate-content {
    text-align: center;
    padding: 40px;
}

.rotate-icon {
    color: var(--accent-color);
    margin-bottom: 24px;
    animation: rotateHint 2s ease-in-out infinite;
}

.rotate-icon svg {
    transform: rotate(-90deg);
}

@keyframes rotateHint {

    0%,
    100% {
        transform: rotate(0deg);
    }

    25% {
        transform: rotate(15deg);
    }

    75% {
        transform: rotate(-15deg);
    }
}

.rotate-text {
    font-family: 'Noto Serif SC', serif;
    font-size: 1.5rem;
    font-weight: 700;
    color: var(--text-primary);
    margin-bottom: 12px;
}

.rotate-subtext {
    font-size: 0.9rem;
    color: var(--text-secondary);
}

/* Show rotate prompt on mobile portrait when chart is active */
@media (max-width: 768px) and (orientation: portrait) {
    body.chart-active .rotate-prompt {
        display: flex;
    }

    body.chart-active .app-container {
        display: none;
    }
}

/* Hide rotate prompt when in landscape or on desktop */
@media (orientation: landscape),
(min-width: 769px) {
    .rotate-prompt {
        display: none !important;
    }

    body.chart-active .app-container {
        display: flex;
    }
}