/* LEDGER CALCULATOR v3.0.0 — ink & brass, not glass & neon. */
:root {
    --ink-950: #0f100c;
    --ink-900: #191a14;
    --ink-800: #23241d;
    --ink-700: #2f3027;
    --card-bg: rgba(35, 36, 29, .72);
    --rule: rgba(233, 224, 199, .10);
    --rule-strong: rgba(233, 224, 199, .18);
    --text-primary: #f2ead9;
    --text-secondary: #9c9686;
    --brass: #c98a3e;
    --brass-bright: #e3a75c;
    --stamp-green: #6fae82;
    --stamp-red: #c96a5c;
    --shadow: 0 25px 60px rgba(0, 0, 0, .55);
    --focus-ring: 0 0 0 3px var(--brass-bright);
    --font-display: "Fraunces", Georgia, serif;
    --font-body: "IBM Plex Sans", system-ui, sans-serif;
    --font-mono: "IBM Plex Mono", "Courier New", monospace;
}

.paper-theme {
    --ink-950: #e9e0c9;
    --ink-900: #f1e9d2;
    --ink-800: #f6f0dd;
    --ink-700: #ded3b2;
    --card-bg: rgba(246, 240, 221, .82);
    --rule: rgba(43, 39, 29, .12);
    --rule-strong: rgba(43, 39, 29, .22);
    --text-primary: #2b271d;
    --text-secondary: #6b5f47;
    --brass: #9c6423;
    --brass-bright: #b9782c;
    --stamp-green: #3f6b4c;
    --stamp-red: #a23b3b;
    --shadow: 0 20px 45px rgba(75, 62, 33, .18);
}

* { box-sizing: border-box; margin: 0; padding: 0; }
html { scroll-behavior: smooth; }
[id] { scroll-margin-top: 28px; }
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap; border: 0; }

body {
    min-width: 320px;
    min-height: 100vh;
    color: var(--text-primary);
    font-family: var(--font-body);
    background:
        radial-gradient(circle at 12% -10%, rgba(201, 138, 62, .10), transparent 40%),
        repeating-linear-gradient(180deg, transparent 0 39px, var(--rule) 39px 40px),
        var(--ink-950);
    transition: background-color .35s ease, color .35s ease;
}
.local-launch-notice {
    width: min(100% - 32px, 1200px);
    padding: 14px 18px;
    margin: 16px auto 0;
    border: 1px solid var(--brass);
    border-radius: 10px;
    background: var(--ink-800);
    color: var(--text-primary);
    font-family: var(--font-body);
    line-height: 1.5;
}
.local-launch-notice code { color: var(--brass-bright); font-family: var(--font-mono); }
::selection { background: var(--brass); color: var(--ink-950); }
:focus-visible { outline: 2px solid var(--brass-bright); outline-offset: 2px; }
button, select, input { font-family: inherit; color: inherit; background: none; border: none; cursor: pointer; }
input, select { cursor: text; }
h1, h2, h3 { font-family: var(--font-display); font-weight: 600; letter-spacing: -.01em; }

/* ---------- Header & tabs ---------- */
.app-header { display: flex; align-items: center; justify-content: space-between; gap: 20px; width: min(100%, 1200px); padding: 26px 8% 10px; margin: auto; }
.brand { display: flex; align-items: center; gap: 16px; }
.brand-mark { display: grid; width: 52px; height: 52px; place-items: center; border: 1px solid var(--rule-strong); border-radius: 12px; background: linear-gradient(155deg, var(--ink-800), var(--ink-900)); color: var(--brass-bright); font-family: var(--font-display); font-size: 1.6rem; font-weight: 700; }
.brand-text h1 { font-size: 1.5rem; }
.brand-text p { color: var(--text-secondary); font-size: .88rem; font-style: italic; }
.header-actions { display: flex; gap: 10px; }
.header-btn { height: 42px; padding: 0 16px; border: 1px solid var(--rule-strong); border-radius: 10px; background: var(--ink-800); color: var(--text-primary); font-family: var(--font-mono); font-size: .82rem; font-weight: 600; letter-spacing: .04em; transition: transform .2s, background .2s; }
.header-btn:hover { transform: translateY(-2px); background: var(--ink-700); }

.view-tabs { display: flex; gap: 4px; width: min(100%, 1200px); padding: 0 8%; margin: 8px auto 26px; border-bottom: 1px solid var(--rule); }
.view-tab { padding: 12px 22px; border-bottom: 2px solid transparent; color: var(--text-secondary); font-family: var(--font-mono); font-size: .88rem; font-weight: 600; letter-spacing: .03em; text-transform: uppercase; transition: color .2s, border-color .2s; }
.view-tab:hover { color: var(--text-primary); }
.view-tab.active { border-color: var(--brass); color: var(--brass-bright); }

/* ---------- Layout ---------- */
.app-container { width: min(100%, 1200px); padding: 0 8% 40px; margin: auto; }
.calculator-layout { display: flex; align-items: flex-start; gap: 30px; }
.calculator-card { position: relative; flex: 1; width: 100%; max-width: 760px; padding: 32px; overflow: hidden; border: 1px solid var(--rule-strong); border-radius: 18px; background: var(--card-bg); backdrop-filter: blur(14px); box-shadow: var(--shadow); }
.view-panel[hidden] { display: none; }

/* ---------- Display ---------- */
.display-panel { padding: 22px 24px; margin-bottom: 22px; border: 1px solid var(--rule); border-radius: 14px; background: var(--ink-950); }
.display-header, .panel-header, .history-header, .modal-header { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.display-header { margin-bottom: 14px; }
.mode-status { padding: 6px 14px; border: 1px solid var(--rule-strong); border-radius: 20px; color: var(--brass-bright); font-family: var(--font-mono); font-size: .76rem; font-weight: 700; letter-spacing: .06em; }
.memory-status { color: var(--text-secondary); font-family: var(--font-mono); font-size: .82rem; font-weight: 600; }
.expression-line { min-height: 24px; overflow: hidden; color: var(--text-secondary); text-align: right; white-space: nowrap; font-family: var(--font-mono); font-size: 1.05rem; }
.main-display { margin-top: 6px; text-align: right; }
.main-display span#display { display: inline-block; max-width: 100%; overflow: hidden; color: var(--text-primary); font-family: var(--font-mono); font-variant-numeric: tabular-nums; font-size: 2.9rem; font-weight: 600; letter-spacing: -.01em; text-overflow: ellipsis; white-space: nowrap; }
.calculation-info { display: grid; grid-template-columns: repeat(3, 1fr); gap: 14px; margin-top: 20px; }
.info-box { padding: 14px; border: 1px solid var(--rule); border-radius: 12px; text-align: center; transition: transform .25s, background .25s; }
.info-box:hover { transform: translateY(-3px); background: var(--ink-800); }
.info-box span { display: block; margin-bottom: 8px; color: var(--brass-bright); font-family: var(--font-display); font-size: 1.4rem; }
.info-box p { color: var(--text-secondary); font-size: .8rem; }

/* ---------- Memory & scientific ---------- */
.quick-actions { display: grid; grid-template-columns: repeat(4, 1fr); gap: 10px; margin-bottom: 20px; }
.quick-btn, .science-btn { border: 1px solid var(--rule-strong); border-radius: 10px; color: var(--text-primary); font-family: var(--font-mono); font-weight: 700; transition: transform .18s, background .18s; }
.quick-btn { height: 44px; background: var(--ink-800); }
.quick-btn:hover { transform: translateY(-2px); background: var(--ink-700); }
.scientific-panel { padding: 20px; margin-bottom: 22px; border: 1px solid var(--rule); border-radius: 14px; }
.panel-header { margin-bottom: 16px; }
.panel-header h3 { font-size: 1rem; }
.mode-switch { padding: 8px 16px; border: 1px solid var(--rule-strong); border-radius: 20px; background: var(--ink-800); color: var(--brass-bright); font-family: var(--font-mono); font-size: .78rem; font-weight: 700; }
.mode-switch:hover { background: var(--ink-700); }
.scientific-buttons { display: grid; grid-template-columns: repeat(6, 1fr); gap: 10px; }
.scientific-panel.is-collapsed .scientific-buttons { display: none; }
.scientific-panel.is-collapsed .panel-header { margin-bottom: 0; }
.science-btn { height: 46px; background: var(--ink-800); font-size: .92rem; }
.science-btn:hover { transform: translateY(-3px); background: var(--ink-700); border-color: var(--brass); }

/* ---------- Keypad ---------- */
.calculator-buttons { display: grid; grid-template-columns: repeat(4, 1fr); gap: 12px; }
.calc-btn { height: 62px; border: 1px solid var(--rule-strong); border-radius: 12px; background: var(--ink-800); color: var(--text-primary); font-family: var(--font-mono); font-size: 1.2rem; font-weight: 600; transition: transform .15s, background .15s, border-color .15s; }
.calc-btn:hover { transform: translateY(-3px); background: var(--ink-700); border-color: var(--brass); }
.calc-btn.operator { color: var(--brass-bright); }
.calc-btn.function, .calc-btn.secondary { color: var(--stamp-green); }
.calc-btn.warning { color: #d3a24c; }
.calc-btn.danger { color: var(--stamp-red); }
.calc-btn.equals {
    position: relative;
    border-color: var(--brass);
    background: linear-gradient(155deg, var(--brass), #8a5a26);
    color: var(--ink-950);
    font-weight: 700;
    box-shadow: 0 10px 22px rgba(201, 138, 62, .28);
}
.calc-btn.equals:active { transform: translateY(1px) scale(.97) rotate(-1deg); box-shadow: 0 4px 10px rgba(201, 138, 62, .35); }

/* ---------- Converter ---------- */
.converter-body { display: flex; flex-direction: column; gap: 18px; padding: 6px; }
.converter-label { color: var(--text-secondary); font-family: var(--font-mono); font-size: .8rem; font-weight: 600; letter-spacing: .04em; text-transform: uppercase; }
.converter-select, .converter-field select { width: 100%; padding: 12px 14px; border: 1px solid var(--rule-strong); border-radius: 10px; background: var(--ink-800); color: var(--text-primary); font-family: var(--font-body); font-size: .95rem; }
.converter-row { display: grid; grid-template-columns: 1fr auto 1fr; align-items: end; gap: 16px; }
.converter-field { display: flex; flex-direction: column; gap: 8px; }
.converter-field label { color: var(--text-secondary); font-family: var(--font-mono); font-size: .76rem; font-weight: 600; letter-spacing: .05em; text-transform: uppercase; }
.converter-field input, .converter-field output { display: block; padding: 16px 14px; border: 1px solid var(--rule); border-radius: 12px; background: var(--ink-950); font-family: var(--font-mono); font-size: 1.4rem; font-variant-numeric: tabular-nums; }
.converter-field output { color: var(--brass-bright); font-weight: 700; overflow-wrap: anywhere; }
.converter-swap { display: grid; width: 44px; height: 44px; place-items: center; align-self: center; margin-bottom: 4px; border: 1px solid var(--rule-strong); border-radius: 50%; background: var(--ink-800); font-size: 1.1rem; transition: transform .3s, background .2s; }
.converter-swap:hover { transform: rotate(180deg); background: var(--ink-700); }
.converter-note { color: var(--text-secondary); font-size: .84rem; }

/* ---------- The Tape (history) ---------- */
.history-panel {
    position: sticky;
    top: 30px;
    display: none;
    flex: 0 0 320px;
    width: 320px;
    padding: 26px 22px 34px;
    background: var(--card-bg);
    border: 1px solid var(--rule-strong);
    border-left: none;
    box-shadow: var(--shadow);
    backdrop-filter: blur(14px);
    background-image: repeating-radial-gradient(circle at 10px center, transparent 0 4px, var(--ink-950) 4px 5px);
    background-size: 100% 32px;
    background-repeat: repeat-y;
    background-position: left top;
    clip-path: polygon(
        0 0, 100% 0, 100% 100%,
        96% 96%, 92% 100%, 88% 96%, 84% 100%, 80% 96%, 76% 100%, 72% 96%, 68% 100%,
        64% 96%, 60% 100%, 56% 96%, 52% 100%, 48% 96%, 44% 100%, 40% 96%, 36% 100%,
        32% 96%, 28% 100%, 24% 96%, 20% 100%, 16% 96%, 12% 100%, 8% 96%, 4% 100%, 0 96%
    );
}
.history-panel.active { display: block; }
.history-header { padding-left: 12px; margin-bottom: 20px; }
.history-header h2 { font-size: 1.15rem; }
.close-history { display: grid; width: 36px; height: 36px; place-items: center; border-radius: 50%; background: var(--ink-800); color: var(--text-primary); transition: transform .25s, background .2s; }
.close-history:hover { transform: rotate(90deg); background: var(--stamp-red); color: #fff; }
.history-content { max-height: 400px; padding: 0 4px 0 12px; overflow-y: auto; }
.empty-history { display: flex; min-height: 220px; flex-direction: column; align-items: center; justify-content: center; color: var(--text-secondary); text-align: center; }
.empty-history span { margin-bottom: 12px; font-family: var(--font-display); font-size: 2.4rem; }
.empty-history p { margin-bottom: 6px; color: var(--text-primary); font-size: 1rem; }
.history-item { display: block; width: 100%; padding: 12px 0; margin-bottom: 4px; border-bottom: 1px dashed var(--rule-strong); color: var(--text-primary); text-align: left; transition: transform .18s; }
.history-item:hover { transform: translateX(4px); }
.history-item .history-stamp { display: inline-block; margin-bottom: 4px; padding: 2px 8px; border: 1px solid var(--stamp-green); border-radius: 4px; color: var(--stamp-green); font-family: var(--font-mono); font-size: .68rem; letter-spacing: .04em; text-transform: uppercase; transform: rotate(-2deg); }
.history-item p { overflow-wrap: anywhere; color: var(--text-secondary); font-family: var(--font-mono); font-size: .86rem; }
.history-item strong { display: block; margin-top: 2px; color: var(--brass-bright); font-family: var(--font-mono); font-size: 1.05rem; }
.history-actions { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; padding-left: 12px; margin-top: 18px; }
.tape-btn { height: 42px; border: 1px solid var(--rule-strong); border-radius: 10px; background: var(--ink-800); color: var(--text-primary); font-family: var(--font-mono); font-size: .76rem; font-weight: 700; letter-spacing: .03em; text-transform: uppercase; transition: background .2s, transform .18s; }
.tape-btn:hover { transform: translateY(-2px); background: var(--ink-700); }
.tape-btn.danger { color: var(--stamp-red); }
.history-content::-webkit-scrollbar { width: 6px; }
.history-content::-webkit-scrollbar-thumb { border-radius: 20px; background: var(--brass); }
.history-content { scrollbar-color: var(--brass) transparent; scrollbar-width: thin; }

/* ---------- Feature / shortcut / about sections ---------- */
.feature-section { display: grid; grid-template-columns: repeat(4, 1fr); gap: 20px; margin-block: 60px; }
.feature-card { padding: 26px; border: 1px solid var(--rule); border-radius: 16px; transition: transform .3s, background .3s; }
.feature-card:hover, .info-card:hover, .version-card:hover { transform: translateY(-6px); background: var(--ink-800); }
.feature-icon { display: block; margin-bottom: 12px; color: var(--brass-bright); font-family: var(--font-display); font-size: 1.9rem; }
.feature-card h3 { margin-bottom: 10px; font-size: 1.05rem; }
.feature-card p { color: var(--text-secondary); font-size: .9rem; line-height: 1.6; }

.shortcut-section { margin-bottom: 60px; }
.shortcut-card { padding: 32px; border: 1px solid var(--rule); border-radius: 18px; }
.shortcut-card h2 { margin-bottom: 22px; font-size: 1.3rem; }
.shortcuts { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 18px; }
.shortcuts div { display: flex; flex-direction: column; align-items: center; gap: 8px; color: var(--text-secondary); font-size: .82rem; }
kbd { padding: 8px 14px; border: 1px solid var(--rule-strong); border-radius: 6px; background: var(--ink-950); color: var(--brass-bright); font-family: var(--font-mono); font-weight: 700; }

.project-info { display: grid; grid-template-columns: 2fr 1fr; gap: 26px; margin-bottom: 60px; }
.info-card, .version-card { padding: 32px; border: 1px solid var(--rule); border-radius: 18px; transition: transform .3s, background .3s; }
.info-card h2, .version-card h2 { margin-bottom: 16px; font-size: 1.25rem; }
.info-card p { margin-bottom: 14px; color: var(--text-secondary); line-height: 1.75; }
.version-card { display: flex; flex-direction: column; align-items: center; justify-content: center; text-align: center; }
.version-card span { margin: 16px 0; color: var(--brass-bright); font-family: var(--font-display); font-size: 2.6rem; font-weight: 700; }
.version-card p { color: var(--text-secondary); font-family: var(--font-mono); font-size: .82rem; text-transform: uppercase; letter-spacing: .05em; }

/* ---------- Footer ---------- */
.app-footer { padding: 50px 8% 40px; border-top: 1px solid var(--rule); background: var(--ink-900); }
.footer-content { display: grid; grid-template-columns: 2fr 1fr 1fr; gap: 36px; width: min(100%, 1200px); margin: auto; }
.footer-brand h2 { margin-bottom: 12px; font-size: 1.2rem; }
.footer-brand p { max-width: 400px; color: var(--text-secondary); line-height: 1.7; }
.footer-links { display: flex; flex-direction: column; gap: 10px; }
.footer-links h3 { margin-bottom: 12px; font-size: .95rem; }
.footer-links a { width: fit-content; color: var(--text-secondary); text-decoration: none; transition: transform .2s, color .2s; }
.footer-links a:hover { transform: translateX(5px); color: var(--brass-bright); }
.footer-bottom { width: min(100%, 1200px); padding-top: 22px; margin: 40px auto 0; border-top: 1px solid var(--rule); color: var(--text-secondary); text-align: center; font-size: .86rem; line-height: 2; }
.footer-bottom strong { color: var(--brass-bright); }

/* ---------- Modal ---------- */
.modal-backdrop { position: fixed; inset: 0; z-index: 50; display: grid; place-items: center; padding: 20px; background: rgba(15, 16, 12, .72); backdrop-filter: blur(4px); }
.modal-backdrop[hidden] { display: none; }
.modal-card { width: min(100%, 460px); max-height: 80vh; padding: 28px; overflow-y: auto; border: 1px solid var(--rule-strong); border-radius: 18px; background: var(--ink-900); box-shadow: var(--shadow); }
.modal-header { margin-bottom: 18px; }
.modal-shortcut-list { display: flex; flex-direction: column; gap: 12px; list-style: none; }
.modal-shortcut-list li { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; color: var(--text-secondary); font-size: .9rem; }
.modal-shortcut-list kbd { padding: 5px 10px; font-size: .78rem; }

/* ---------- Utility states ---------- */
.error { color: var(--stamp-red) !important; animation: shake .35s ease; }
.copied { color: var(--stamp-green) !important; }
@keyframes shake { 25% { transform: translateX(-6px); } 75% { transform: translateX(6px); } }
::-webkit-scrollbar { width: 10px; }
::-webkit-scrollbar-track { background: var(--ink-950); }
::-webkit-scrollbar-thumb { border-radius: 20px; background: var(--brass); }

/* ---------- Responsive ---------- */
@media (max-width: 1100px) {
    .calculator-layout { flex-direction: column; }
    .calculator-card { max-width: none; }
    .history-panel { position: relative; top: 0; flex-basis: auto; width: 100%; margin-top: 24px; clip-path: none; border-left: 1px solid var(--rule-strong); border-radius: 18px; }
    .feature-section { grid-template-columns: repeat(2, 1fr); }
}
@media (max-width: 850px) {
    .app-header { flex-direction: column; text-align: center; }
    .project-info, .footer-content { grid-template-columns: 1fr; }
    .footer-content { text-align: center; }
    .footer-brand p { margin-inline: auto; }
    .footer-links { align-items: center; }
}
@media (max-width: 700px) {
    .calculation-info { grid-template-columns: 1fr; }
    .quick-actions { grid-template-columns: repeat(2, 1fr); }
    .scientific-buttons { grid-template-columns: repeat(3, 1fr); }
    .main-display span#display { font-size: 2.2rem; }
    .converter-row { grid-template-columns: 1fr; }
    .converter-swap { justify-self: center; transform: rotate(90deg); }
    .converter-swap:hover { transform: rotate(270deg); }
}
@media (max-width: 600px) {
    .app-header, .app-container, .feature-section, .shortcut-section, .project-info, .view-tabs { width: 95%; }
    .calculator-card { padding: 20px; }
    .display-panel, .scientific-panel { padding: 16px; }
    .main-display span#display { font-size: 2rem; }
    .scientific-buttons { grid-template-columns: repeat(2, 1fr); }
    .calculator-buttons { gap: 8px; }
    .calc-btn { height: 56px; font-size: 1.05rem; }
    .feature-section { grid-template-columns: 1fr; }
    .shortcut-card, .info-card, .version-card { padding: 22px; }
}
@media (prefers-reduced-motion: reduce) { *, *::before, *::after { scroll-behavior: auto !important; animation-duration: .01ms !important; animation-iteration-count: 1 !important; transition: none !important; } }
@media print { body { background: #fff; color: #000; } .header-actions, .quick-actions, .scientific-panel, .history-panel, .app-footer, .view-tabs { display: none !important; } .calculator-card { max-width: none; border-color: #000; box-shadow: none; } }
