* { box-sizing: border-box; }
[hidden] { display: none !important; }
body {
    margin: 0;
    min-height: 100vh;
    min-height: 100dvh;
    display: flex;
    flex-direction: column;
    background: #f4f7fc;
    color: #0b1a33;
    font-family: system-ui, -apple-system, 'Segoe UI', Roboto, 'Helvetica Neue', sans-serif;
}
button, input { font: inherit; }
:where(a, button, input):focus-visible { outline: 3px solid #8ec7ff; outline-offset: 3px; }
.calculator-header {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto minmax(0, 1fr);
    align-items: center;
    gap: 16px;
    min-height: 66px;
    padding: 10px 28px;
    background: #fff;
    border-bottom: 1px solid #e7edf5;
}
.calculator-plan { justify-self: start; display: inline-flex; align-items: center; gap: 7px; padding: 6px 12px; border-radius: 8px; background: #eaf8ef; color: #16803d; font-size: .8rem; font-weight: 500; }
.calculator-plan strong { font-size: .85rem; font-style: italic; font-weight: 800; }
.calculator-title { display: flex; align-items: center; justify-content: center; gap: 10px; margin: 0; font-size: 1.325rem; font-weight: 700; line-height: 1.4; }
.calculator-title-icon { display: grid; place-items: center; width: 36px; height: 36px; color: #006acd; }
.dynasty-book-icon { position: relative; width: 22px; height: 18px; border: 2px solid currentColor; border-radius: 4px 4px 3px 3px; }
.dynasty-book-icon::before { position: absolute; inset: 0 auto 0 50%; width: 2px; transform: translateX(-50%); background: currentColor; content: ""; }
.dynasty-book-icon::after { position: absolute; top: 4px; left: 2px; width: 4px; height: 1px; background: currentColor; box-shadow: 0 4px currentColor, 10px 0 currentColor, 10px 4px currentColor; content: ""; }
.calculator-open-link { align-items: center; gap: 6px; justify-self: end; color: #69798d; font-size: .9rem; text-decoration: none; white-space: nowrap; }
.calculator-open-link:hover { color: #006acd; }
.calculator-main { flex: 1; display: flex; flex-direction: column; gap: 24px; width: 100%; max-width: 1008px; margin: 0 auto; padding: 32px 24px 16px; }
.calculator-card { padding: 20px 22px; border: 1px solid #e5ebf3; border-radius: 24px; background: #fff; box-shadow: 0 12px 40px rgba(18, 61, 107, .06); }
.dynasty-search-card, .dynasty-search-controls { display: flex; align-items: center; gap: 12px; }
.dynasty-search-label { flex: none; color: #315d8d; font-weight: 600; }
.dynasty-search-controls { flex: 1; min-width: 0; }
.dynasty-search-controls input { flex: 1; min-width: 0; min-height: 44px; padding: 8px 12px; border: 1px solid #e5ebf3; border-radius: 12px; background: #f8faff; color: #0b1a33; }
.dynasty-search-controls input::placeholder { color: #69798d; }
.dynasty-search-controls button { padding: 8px 10px; border: 0; border-radius: 8px; background: #eef4fe; color: #006acd; white-space: nowrap; cursor: pointer; }
.dynasty-search-controls button:hover { background: #dce8fa; }
.dynasty-results-header { display: flex; flex-wrap: wrap; align-items: baseline; justify-content: space-between; gap: 6px 16px; margin: 0 2px 14px; }
.dynasty-results-header h2 { margin: 0; font-size: 1.125rem; }
.dynasty-results-header p { margin: 0; color: #52637a; font-size: .875rem; }
.dynasty-results { display: grid; gap: 16px; }
.dynasty-period h3 { margin: 0 0 12px; color: #315d8d; font-size: 1rem; }
.dynasty-list { margin: 0; padding: 0; list-style: none; }
.dynasty-row { display: grid; grid-template-columns: minmax(0, 1.15fr) minmax(0, 1fr) minmax(0, 1.2fr); align-items: start; gap: 6px 18px; padding: 12px 0; border-top: 1px solid #eef2f8; line-height: 1.55; overflow-wrap: anywhere; }
.dynasty-row:last-child { padding-bottom: 0; }
.dynasty-identity h4 { margin: 0 0 2px; font-size: 1rem; }
.dynasty-detail { display: grid; gap: 2px; font-size: .9rem; }
.dynasty-label, .dynasty-dates, .dynasty-note { color: #52637a; font-size: .8rem; }
.dynasty-dates { font-variant-numeric: tabular-nums; }
.dynasty-note { grid-column: 1 / -1; margin: 0; }
.dynasty-empty { margin: 0; color: #52637a; text-align: center; }
.calculator-tips { margin-top: auto; padding: 18px 12px 0; border-top: 1px solid #e7edf5; color: #66758a; font-size: .9rem; line-height: 1.8; text-align: center; }
.calculator-tips p { margin: 0; }
.calculator-tips a { display: inline-block; margin-inline: 5px; color: #006acd; }

@media (max-width: 767.98px) {
    .calculator-header { padding: 8px 16px; gap: 10px; }
    .calculator-title { gap: 7px; font-size: 1.175rem; }
    .calculator-title-icon { width: 32px; height: 32px; }
    .calculator-open-link { font-size: .8rem; }
    .calculator-main { padding: 24px 16px 16px; gap: 20px; }
}
@media (max-width: 575.98px) {
    .calculator-header { grid-template-columns: minmax(0, 1fr) auto; }
    .calculator-title { grid-column: 1 / -1; grid-row: 1; }
    .calculator-plan { grid-column: 1; grid-row: 2; padding: 5px 8px; font-size: .72rem; }
    .calculator-open-link { grid-column: 2; grid-row: 2; }
    .calculator-card { padding: 16px 14px; border-radius: 22px; }
    .dynasty-search-card { flex-direction: column; align-items: stretch; gap: 8px; }
    .dynasty-search-controls input { font-size: .9rem; }
    .dynasty-row { grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 8px 12px; }
    .dynasty-identity { grid-column: 1 / -1; }
    .calculator-tips { font-size: .8rem; }
}
