html, body { overflow-x: hidden; }

.sequence-shell {
    max-width: 820px;
    margin: 0 auto;
    width: 100%;
}

/* ── Sections ── */
.section {
    margin-bottom: 3rem;
}

.page-title {
    font-size: 2.4rem;
    font-weight: 900;
    letter-spacing: -0.03em;
    line-height: 1.15;
    margin: 0 0 0.75rem;
    color: var(--text-primary);
}

.page-desc {
    color: var(--text-secondary);
    font-size: 1.1rem;
    line-height: 1.65;
    margin: 0 0 1.5rem;
}

.section-heading {
    font-size: 1.5rem;
    font-weight: 900;
    letter-spacing: -0.02em;
    color: var(--text-primary);
    margin: 0 0 0.5rem;
}

.section-desc {
    color: var(--text-secondary);
    font-size: 1rem;
    line-height: 1.6;
    margin: 0 0 1.25rem;
}

/* ── Answer context ── */
.answer-context {
    background: var(--card-background);
    border: 1px solid var(--border-color);
    border-radius: 14px;
    padding: 1rem 1.25rem;
    margin-bottom: 1.25rem;
    box-shadow: var(--shadow-sm);
}

.context-row {
    display: flex;
    justify-content: space-between;
    align-items: baseline;
    padding: 0.35rem 0;
    border-bottom: 1px solid rgba(148, 163, 184, 0.1);
}

.context-row:last-child { border-bottom: none; }

.context-label {
    font-weight: 700;
    font-size: 0.88rem;
    color: var(--text-secondary);
}

.context-value {
    font-weight: 800;
    font-size: 0.92rem;
    color: var(--text-primary);
    font-variant-numeric: tabular-nums;
}

/* ── Summary chips ── */
.summary-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
    gap: 0.75rem;
    margin-bottom: 1.25rem;
}

.summary-chip {
    border: 1px solid var(--border-color);
    border-radius: 14px;
    padding: 1rem;
    display: flex;
    gap: 0.85rem;
    align-items: flex-start;
    transition: border-color 0.15s ease, background 0.15s ease;
}

.summary-chip[data-tone="good"] { border-color: rgba(24, 166, 131, 0.35); background: rgba(24, 166, 131, 0.06); }
.summary-chip[data-tone="warn"] { border-color: rgba(245, 158, 11, 0.35); background: rgba(245, 158, 11, 0.06); }
.summary-chip[data-tone="bad"]  { border-color: rgba(239, 68, 68, 0.35); background: rgba(239, 68, 68, 0.06); }

.chip-icon {
    font-size: 1.4rem;
    font-weight: 900;
    flex: none;
    width: 28px;
    text-align: center;
    line-height: 1;
    margin-top: 2px;
}

.summary-chip[data-tone="good"] .chip-icon { color: #18A683; }
.summary-chip[data-tone="warn"] .chip-icon { color: #F59E0B; }
.summary-chip[data-tone="bad"]  .chip-icon { color: #EF4444; }

.chip-body { display: grid; gap: 0.2rem; }
.chip-title { font-weight: 800; font-size: 0.88rem; color: var(--text-primary); }
.chip-value { font-weight: 900; font-size: 1rem; color: var(--text-primary); }
.chip-sub { color: var(--text-muted); font-size: 0.82rem; }

/* ── Callout ── */
.callout {
    border-radius: 14px;
    padding: 1rem 1.25rem;
    border: 1px solid var(--border-color);
    background: linear-gradient(135deg, rgba(239, 68, 68, 0.06), rgba(118, 75, 162, 0.05));
    margin-bottom: 0.75rem;
}

.callout-copy {
    color: var(--text-primary);
    margin: 0;
    font-weight: 700;
    line-height: 1.6;
    font-size: 0.95rem;
}

/* ── Withdrawal note ── */
.withdrawal-note {
    color: var(--text-muted);
    font-size: 0.88rem;
    font-weight: 600;
    line-height: 1.5;
}

/* ── Chart ── */
.chart-card {
    border: 1px solid var(--border-color);
    border-radius: 16px;
    padding: 1rem;
    background: var(--card-background);
    box-shadow: var(--shadow-sm);
}

.chart-shell {
    position: relative;
    width: 100%;
    height: 360px;
    border-radius: 14px;
    border: 1px solid var(--border-color);
    background: var(--card-background);
}

.chart-canvas { width: 100%; height: 100%; display: block; }

.chart-legend {
    display: flex;
    flex-wrap: wrap;
    gap: 0.75rem 1.25rem;
    margin-top: 0.85rem;
    color: var(--text-secondary);
    font-size: 0.9rem;
}

.legend-item { display: inline-flex; align-items: center; gap: 0.4rem; font-weight: 700; }
.legend-dot { width: 10px; height: 10px; border-radius: 999px; display: inline-block; }

/* ── Sequence table ── */
.table-wrap {
    border: 1px solid var(--border-color);
    border-radius: 16px;
    overflow-x: auto;
    overflow-y: hidden;
    background: var(--card-background);
    -webkit-overflow-scrolling: touch;
    box-shadow: var(--shadow-sm);
    max-height: 520px;
    overflow-y: auto;
}

.sequence-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.88rem;
    font-variant-numeric: tabular-nums;
}

.sequence-table thead {
    position: sticky;
    top: 0;
    z-index: 2;
}

.sequence-table th {
    text-align: left;
    padding: 0.7rem 0.85rem;
    background: var(--card-background);
    color: var(--text-primary);
    font-weight: 900;
    border-bottom: 2px solid rgba(148, 163, 184, 0.3);
    white-space: nowrap;
}

.sequence-table td {
    padding: 0.45rem 0.85rem;
    border-bottom: 1px solid rgba(148, 163, 184, 0.1);
    white-space: nowrap;
}

.sequence-table tbody tr:last-child td { border-bottom: none; }

.year-col {
    color: var(--text-muted);
    font-weight: 800;
    font-size: 0.82rem;
}

.return-pos { color: #18A683; font-weight: 700; }
.return-neg { color: #EF4444; font-weight: 700; }

.avg-row {
    border-top: 2px solid var(--border-color);
    position: sticky;
    bottom: 0;
    background: var(--card-background);
}

.avg-row td {
    padding: 0.65rem 0.85rem;
    border-bottom: none;
}

.avg-cell {
    font-weight: 900;
    color: var(--text-primary);
}

.sequence-note {
    color: var(--text-muted);
    font-size: 0.85rem;
    margin: 0.75rem 0 0;
    line-height: 1.55;
}

/* ── Card / Inputs ── */
.card {
    background: var(--card-background);
    border: 1px solid var(--border-color);
    border-radius: 16px;
    box-shadow: var(--shadow-sm);
}

.card-head {
    padding: 1.25rem 1.25rem 0.75rem;
    border-bottom: 1px solid var(--border-color);
}

.card-head h2 {
    font-size: 1.15rem;
    font-weight: 800;
    letter-spacing: -0.01em;
    margin: 0 0 0.35rem;
    color: var(--text-primary);
}

.card-head p {
    color: var(--text-secondary);
    margin: 0 0 0.5rem;
    font-size: 0.95rem;
}

.input-grid {
    padding: 1.25rem;
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 1rem;
    align-items: start;
}

.field { display: grid; gap: 0.4rem; }
.field-full { grid-column: 1 / -1; }

.field-label {
    font-size: 0.85rem;
    font-weight: 700;
    color: var(--text-primary);
}

.field-help {
    font-size: 0.82rem;
    color: var(--text-muted);
    line-height: 1.4;
}

.field-control {
    display: flex;
    align-items: center;
    gap: 0.4rem;
    border: 1px solid rgba(148, 163, 184, 0.3);
    border-radius: 12px;
    padding: 0.75rem 0.85rem;
    background: rgba(0, 0, 0, 0.15);
    box-shadow: inset 0 2px 4px rgba(0,0,0,0.1);
}

.field-control input, .field-control select {
    width: 100%;
    border: none;
    outline: none;
    background: transparent;
    font-size: 1.05rem;
    font-weight: 700;
    color: var(--text-primary);
    font-family: inherit;
}

.field-control:focus-within {
    border-color: var(--primary);
    background: rgba(0, 0, 0, 0.25);
    box-shadow: 0 0 0 3px rgba(102, 126, 234, 0.2), inset 0 2px 4px rgba(0,0,0,0.1);
}

.field-prefix, .field-suffix { color: var(--text-muted); font-weight: 700; flex: none; }
.field-control-money input, .field-control-percent input, .field-control-years input { font-variant-numeric: tabular-nums; }

.field-readonly .readonly-pill {
    border: 1px solid var(--border-color);
    border-radius: 12px;
    padding: 0.75rem;
    background: rgba(118, 75, 162, 0.06);
}

#withdrawalRateText {
    font-size: 1.2rem;
    font-weight: 900;
    letter-spacing: -0.02em;
    color: var(--text-primary);
    display: block;
    font-variant-numeric: tabular-nums;
}

.readonly-sub {
    font-size: 0.82rem;
    color: var(--text-muted);
    display: block;
    margin-top: 0.2rem;
}

textarea {
    width: 100%;
    border: 1px solid var(--border-color);
    border-radius: 12px;
    padding: 0.75rem;
    font-family: inherit;
    font-size: 0.95rem;
    resize: vertical;
    background: rgba(102, 126, 234, 0.03);
    color: var(--text-primary);
}

textarea:focus {
    outline: none;
    border-color: rgba(102, 126, 234, 0.6);
    box-shadow: 0 0 0 3px rgba(102, 126, 234, 0.12);
}

.field-actions { display: grid; gap: 0.5rem; }

.primary-btn {
    border: none;
    border-radius: 12px;
    padding: 0.85rem 1rem;
    font-weight: 900;
    font-size: 0.95rem;
    cursor: pointer;
    color: #ffffff;
    background: var(--gradient);
    box-shadow: var(--shadow-md);
    transition: transform 0.15s ease, box-shadow 0.2s ease;
}

.primary-btn:hover { transform: translateY(-1px); box-shadow: var(--shadow-lg); }
.primary-btn:active { transform: translateY(0); }

.toggle-custom-btn {
    background: none;
    border: 1px dashed var(--border-color);
    border-radius: 12px;
    padding: 0.65rem 0.75rem;
    color: var(--text-muted);
    font-weight: 700;
    font-size: 0.85rem;
    cursor: pointer;
    transition: color 0.15s ease, border-color 0.15s ease;
    text-align: left;
    font-family: inherit;
}

.toggle-custom-btn:hover { color: var(--text-primary); border-color: rgba(102, 126, 234, 0.4); }

/* ── Explainer ── */
.prose {
    padding: 1.25rem;
    display: grid;
    gap: 0.75rem;
    color: var(--text-secondary);
}

.prose p { margin: 0; line-height: 1.65; }

.fine-print {
    color: var(--text-muted);
    font-size: 0.82rem;
    margin: 0 0 2rem;
    line-height: 1.55;
}

/* ── Title Row & Modal ── */
.title-row {
    display: flex;
    align-items: baseline;
    gap: 1rem;
    flex-wrap: wrap;
    margin-bottom: 0.75rem;
}

.title-row .page-title {
    margin-bottom: 0;
}

.info-link {
    background: rgba(118, 75, 162, 0.1);
    color: var(--primary);
    border: 1px solid rgba(118, 75, 162, 0.3);
    padding: 0.35rem 0.75rem;
    border-radius: 999px;
    font-size: 0.85rem;
    font-weight: 700;
    cursor: pointer;
    transition: all 0.2s ease;
}
.info-link:hover {
    background: rgba(118, 75, 162, 0.2);
}

.modal-overlay {
    position: fixed;
    top: 0; left: 0; right: 0; bottom: 0;
    background: rgba(15, 23, 42, 0.75);
    backdrop-filter: blur(4px);
    z-index: 100;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 1rem;
}
.modal-content {
    background: var(--card-background);
    border: 1px solid var(--border-color);
    border-radius: 16px;
    padding: 2rem;
    max-width: 600px;
    width: 100%;
    box-shadow: var(--shadow-xl);
    position: relative;
}
.modal-close {
    position: absolute;
    top: 1rem; right: 1rem;
    background: none; border: none;
    font-size: 1.5rem; color: var(--text-muted);
    cursor: pointer; padding: 0.5rem; line-height: 1;
}
.modal-close:hover { color: var(--text-primary); }

/* ── Presets ── */
.presets-section {
    padding: 0 1.25rem 1.25rem;
}
.presets-section h3 {
    font-size: 0.95rem;
    color: var(--text-secondary);
    margin-bottom: 0.75rem;
    font-weight: 700;
}
.presets-grid {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
}
.preset-btn {
    background: rgba(102, 126, 234, 0.05);
    border: 1px solid var(--border-color);
    color: var(--text-secondary);
    padding: 0.65rem 1rem;
    border-radius: 12px;
    font-size: 0.85rem;
    font-weight: 700;
    cursor: pointer;
    transition: all 0.2s ease;
}
.preset-btn:hover {
    background: rgba(102, 126, 234, 0.1);
    border-color: rgba(102, 126, 234, 0.3);
}
.preset-btn.active {
    background: rgba(102, 126, 234, 0.15);
    border-color: var(--primary);
    color: var(--primary);
}

.scenario-preview {
    margin-top: 1rem;
    padding: 1rem;
    background: rgba(0,0,0,0.15);
    border: 1px solid rgba(148, 163, 184, 0.2);
    border-radius: 12px;
}
.preview-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 0.5rem;
}
.preview-header h4 {
    margin: 0;
    color: var(--text-primary);
    font-size: 1.05rem;
}
.preview-header span {
    font-size: 0.85rem;
    color: var(--text-muted);
}
.preview-data {
    font-size: 0.9rem;
    color: var(--text-muted);
}
.preview-data strong {
    color: var(--text-primary);
}

/* ── Result Summary Panel ── */
.summary-panel {
    background: var(--card-background);
    border: 1px solid var(--border-color);
    border-radius: 16px;
    padding: 1.5rem;
    box-shadow: var(--shadow-sm);
    display: flex;
    flex-direction: column;
    gap: 1rem;
    border-left: 4px solid var(--border-color);
}
.summary-panel.tone-good { border-left-color: #18A683; }
.summary-panel.tone-warn { border-left-color: #F59E0B; }
.summary-panel.tone-bad { border-left-color: #EF4444; }

.summary-title {
    font-size: 1.2rem;
    font-weight: 800;
    color: var(--text-primary);
    margin: 0;
}
.summary-desc {
    font-size: 1rem;
    line-height: 1.6;
    color: var(--text-secondary);
    margin: 0;
}
.summary-stats {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
    gap: 1rem;
    margin-top: 0.5rem;
    padding-top: 1rem;
    border-top: 1px solid rgba(148, 163, 184, 0.1);
}
.stat-box {
    display: flex;
    flex-direction: column;
}
.stat-label {
    font-size: 0.82rem;
    color: var(--text-muted);
    font-weight: 700;
    margin-bottom: 0.2rem;
}
.stat-value {
    font-size: 1.1rem;
    font-weight: 800;
    color: var(--text-primary);
}

/* ── Hover Tooltip ── */
.chart-hover-tooltip {
    position: absolute;
    background: rgba(15, 23, 42, 0.9);
    border: 1px solid rgba(148, 163, 184, 0.3);
    border-radius: 8px;
    padding: 0.6rem 0.85rem;
    color: #fff;
    font-size: 0.85rem;
    pointer-events: none;
    transform: translate(-50%, -120%);
    box-shadow: 0 4px 12px rgba(0,0,0,0.2);
    z-index: 5;
    white-space: nowrap;
}
.chart-hover-tooltip strong {
    color: var(--primary);
    font-size: 1rem;
}
.chart-hover-tooltip span {
    display: block;
    color: var(--text-muted);
    font-size: 0.75rem;
    margin-top: 0.2rem;
}

/* ── Interactive Chart Popup ── */
.chart-popup {
    position: absolute;
    background: var(--card-background);
    border: 1px solid var(--border-color);
    border-radius: 12px;
    padding: 1rem;
    box-shadow: var(--shadow-lg);
    z-index: 10;
    min-width: 180px;
    transform: translate(-50%, -110%);
    pointer-events: auto;
}
.chart-popup h4 {
    margin: 0 0 0.75rem;
    font-size: 0.95rem;
    color: var(--text-primary);
}
.chart-popup label {
    display: flex;
    flex-direction: column;
    font-size: 0.85rem;
    color: var(--text-secondary);
    gap: 0.4rem;
}
.chart-popup input {
    background: rgba(148, 163, 184, 0.05);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    padding: 0.5rem;
    color: var(--text-primary);
    width: 100%;
}
.popup-actions {
    display: flex;
    gap: 0.5rem;
    margin-top: 0.85rem;
}
.btn-sm {
    padding: 0.4rem 0.75rem;
    font-size: 0.8rem;
    border-radius: 8px;
    cursor: pointer;
    font-weight: 700;
}
.btn-sm:not(.primary-btn) {
    background: transparent;
    border: 1px solid var(--border-color);
    color: var(--text-secondary);
}

/* ── Responsive ── */
@media (max-width: 640px) {
    .page-title { font-size: 1.8rem; }
    .summary-grid { grid-template-columns: 1fr; }
    .input-grid { grid-template-columns: 1fr; }
    .chart-shell { height: 280px; }
}

/* ── Loader ── */
.loader {
    width: 24px;
    height: 24px;
    border: 3px solid rgba(255,255,255,0.2);
    border-radius: 50%;
    border-top-color: #fff;
    animation: spin 1s linear infinite;
    position: absolute;
    left: 50%;
    top: 50%;
    margin-top: -12px;
    margin-left: -12px;
}

.primary-btn.loading {
    opacity: 0.8;
    cursor: not-allowed;
}

@keyframes spin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}
