@import url('https://fonts.googleapis.com/css2?family=Noto+Sans+KR:wght@400;500;600;700;800&display=swap');

:root {
  color-scheme: light;
  --bg: #f5f6f3;
  --surface: #ffffff;
  --sidebar: #fbfcf9;
  --text: #25382f;
  --muted: #59685c;
  --line: #dce3d8;
  --green: #145e49;
  --green-soft: #eaf1e7;
  --lime: #dcf0bb;
  --key: #f1f4ee;
  --shadow: 0 12px 40px #243c2606;
  --rail-width: 224px;
  --app-height: 100vh;
  --mobile-nav-height: 72px;
  --answer-size: clamp(2.75rem, 4.5vw, 4rem);
  --result-size: clamp(1.75rem, 3vw, 2.5rem);
}
@supports (height: 100dvh) { :root { --app-height: 100dvh; } }
* { box-sizing: border-box; }
html { scroll-padding-block: 88px 110px; }
body { margin: 0; background: var(--bg); color: var(--text); font-family: 'Noto Sans KR', system-ui, sans-serif; font-size: 1rem; line-height: 1.5; letter-spacing: -.025em; }
button, input, select { font: inherit; }
button, a, input, select { -webkit-tap-highlight-color: transparent; }
button { cursor: pointer; color: inherit; border: 0; background: none; touch-action: manipulation; }
button:focus-visible, a:focus-visible, [tabindex]:focus-visible { outline: 3px solid #5b9471; outline-offset: 3px; }
button:disabled { opacity: .55; cursor: wait; }
a { color: inherit; text-decoration: none; }
[hidden] { display: none !important; }
svg { width: 22px; height: 22px; display: block; stroke: currentColor; fill: none; stroke-width: 1.7; stroke-linecap: round; stroke-linejoin: round; flex-shrink: 0; }
.sidebar { position: fixed; inset: 0 auto 0 0; width: var(--rail-width); background: var(--sidebar); border-right: 1px solid var(--line); padding: 30px 18px 20px; display: flex; flex-direction: column; z-index: 5; overflow-y: auto; }
.brand { display: flex; gap: 10px; align-items: center; font-size: 22px; font-weight: 800; letter-spacing: -1px; }
.brand-icon { display: grid; place-items: center; background: var(--green); color: var(--lime); width: 39px; height: 44px; border-radius: 12px; font-size: 27px; font-weight: 800; line-height: 1; flex-shrink: 0; }
.brand-light { font-weight: 500; }
.brand small { display: block; font-size: 10px; letter-spacing: .8px; color: var(--muted); font-weight: 500; margin-top: 4px; }
.side-caption { font-size: 12px; letter-spacing: 1.5px; color: var(--muted); margin: 42px 13px 14px; }
.side-nav { display: grid; gap: 7px; }
.nav-item { display: flex; align-items: center; gap: 10px; width: 100%; min-height: 50px; padding: 12px; border-radius: 10px; font-weight: 500; color: var(--muted); text-align: left; font-size: 15px; }
.nav-item.active { background: var(--green-soft); color: var(--green); font-weight: 700; }
.nav-item:hover { background: var(--green-soft); }
.nav-item svg { width: 20px; height: 20px; }
.nav-shortcut { font-size: 11px; margin-left: auto; }
.nav-count { font-size: 12px; background: var(--surface); padding: 2px 6px; border-radius: 4px; margin-left: auto; }
.side-note { margin-top: auto; background: var(--green-soft); padding: 20px 16px; border-radius: 13px; }
.note-icon { display: block; font-size: 28px; color: var(--green); margin-bottom: 12px; }
.side-note strong { font-size: 15px; }
.side-note p { font-size: 13px; line-height: 1.9; color: var(--muted); }
.mini-math { margin-top: 16px; font-size: 26px; font-weight: 500; color: var(--muted); letter-spacing: 2px; }
.mini-math span { color: var(--green); }
.sidebar-bottom { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-top: 24px; }
.quiet { display: inline-flex; align-items: center; gap: 7px; color: var(--muted); font-size: 13px; padding: 6px 0; min-height: 44px; }
.quiet svg { width: 18px; height: 18px; }
.version { font-size: 11px; color: var(--muted); white-space: nowrap; }
main { margin-left: var(--rail-width); min-width: 0; }
.topbar { min-height: 76px; border-bottom: 1px solid var(--line); padding: 12px clamp(20px, 3vw, 42px); display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.breadcrumb { font-size: 14px; color: var(--muted); min-width: 0; }
.breadcrumb span { margin: 0 12px; color: var(--muted); }
.breadcrumb b { font-weight: 600; color: var(--text); }
.top-actions { display: flex; align-items: center; gap: 12px; flex-shrink: 0; }
.local-badge { font-size: 13px; color: var(--muted); display: flex; align-items: center; gap: 7px; }
i { width: 6px; height: 6px; display: inline-block; border-radius: 50%; background: var(--green); }
.icon-button { width: 44px; height: 44px; display: inline-grid; place-items: center; border-radius: 9px; color: var(--muted); flex-shrink: 0; }
.icon-button:hover { background: var(--green-soft); }
.mobile-theme { display: none; }
.page-wrap { max-width: 1370px; margin: auto; padding: 30px clamp(20px, 3vw, 42px) 0; }
.page-heading { display: flex; justify-content: space-between; align-items: center; margin-bottom: 25px; gap: 12px; }
.eyebrow { font-size: 11px; font-weight: 600; letter-spacing: 1.5px; color: var(--muted); }
h1 { font-size: clamp(1.5rem, 2.4vw, 2rem); line-height: 1.4; letter-spacing: -.055em; margin: 8px 0; }
h1 span { color: var(--green); }
.page-heading p { font-size: 15px; color: var(--muted); margin: 7px 0 0; }
.heading-art { font-size: 72px; line-height: 1; color: #849f64; margin-right: 8px; transform: rotate(13deg); }
.workspace { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: clamp(20px, 2.5vw, 38px); align-items: start; }
.calculator-column, .library { min-width: 0; }
.calculator-card { background: var(--surface); border: 1px solid var(--line); border-radius: 21px; padding: clamp(18px, 1.8vw, 26px); box-shadow: var(--shadow); min-width: 0; }
.card-top { display: flex; justify-content: space-between; align-items: center; gap: 10px; min-height: 44px; }
.card-label { display: flex; align-items: center; gap: 8px; font-size: 16px; font-weight: 700; white-space: nowrap; }
.card-label svg { width: 20px; height: 20px; color: var(--green); }
.card-top-right { display: flex; gap: 6px; align-items: center; }
.keyboard-hint { font-size: 12px; color: var(--muted); }
.display { padding: 20px 3px; min-height: 140px; text-align: right; display: flex; flex-direction: column; justify-content: flex-end; gap: 4px; min-width: 0; }
.expression { font-size: clamp(1rem, 1.6vw, 1.125rem); color: var(--muted); min-height: 27px; white-space: nowrap; overflow-x: auto; overflow-y: hidden; scrollbar-width: thin; flex-shrink: 0; }
.answer { font-size: var(--answer-size); line-height: 1.3; letter-spacing: -.045em; font-weight: 600; white-space: nowrap; overflow-x: auto; overflow-y: hidden; scrollbar-width: thin; font-variant-numeric: tabular-nums; flex-shrink: 0; min-width: 0; }
.keypad { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: clamp(7px, .8vw, 11px); }
.key { min-width: 0; min-height: 48px; height: clamp(54px, 7.5vh, 76px); background: var(--key); border: 1px solid #00000003; border-radius: 12px; font-size: clamp(1.5rem, 2.3vw, 1.875rem); font-weight: 500; font-variant-numeric: tabular-nums; transition: background .12s, transform .08s; display: grid; place-items: center; padding: 0; }
.key:hover { filter: brightness(.97); }
.key:active { transform: scale(.95); }
.key.utility, .key.clear { font-size: clamp(1.125rem, 2vw, 1.5rem); background: #e9eee4; color: #465d36; }
.key.operator { background: var(--green-soft); color: var(--green); font-size: clamp(1.875rem, 2.8vw, 2.25rem); font-weight: 400; }
.key.equals { background: var(--green); color: #ffffff; font-size: 2.125rem; }
.key svg { width: 25px; height: 25px; color: var(--muted); }
.calc-bottom { display: flex; align-items: center; justify-content: space-between; gap: 6px; border-top: 1px solid var(--line); margin-top: 16px; padding-top: 13px; color: var(--muted); font-size: 12px; }
.calc-bottom span { display: flex; align-items: center; gap: 6px; }
.calc-bottom b { font-size: 15px; font-weight: 400; }
.recent-strip { display: flex; gap: 9px; align-items: center; padding: 16px 2px; color: var(--muted); }
.tip-circle { font-family: serif; border: 1px solid var(--muted); width: 18px; height: 18px; border-radius: 50%; font-size: 13px; text-align: center; flex-shrink: 0; line-height: 16px; }
.recent-strip p { font-size: 13px; line-height: 1.8; margin: 0; }
.recent-strip button { font-size: inherit; color: var(--green); padding: 0; font-weight: 600; text-decoration: underline; text-underline-offset: 3px; }
.library { padding-top: 4px; container-type: inline-size; }
.library-top { display: flex; justify-content: space-between; align-items: center; gap: 10px; margin: 0 0 18px; }
.small-eyebrow { font-size: 10px; letter-spacing: 1px; }
h2 { font-size: clamp(1.125rem, 1.8vw, 1.375rem); line-height: 1.5; letter-spacing: -.04em; margin: 6px 0 0; }
.tool-total { font-size: 12px; border: 1px solid var(--line); border-radius: 20px; padding: 5px 9px; color: var(--muted); white-space: nowrap; }
.search { display: flex; align-items: center; gap: 9px; border: 1px solid var(--line); border-radius: 11px; background: var(--surface); padding: 10px 13px; min-height: 52px; }
.search svg { width: 20px; height: 20px; color: var(--muted); }
.search input { background: transparent; border: 0; outline: 0; min-width: 0; width: 100%; font-size: 16px; color: var(--text); min-height: 30px; }
.search:focus-within { border-color: var(--green); box-shadow: 0 0 0 2px #86a67320; }
.search input::placeholder { color: var(--muted); }
.search kbd { font: 13px monospace; border: 1px solid var(--line); border-radius: 4px; padding: 2px 5px; color: var(--muted); }
.category-tabs { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 6px; margin: 14px 0 16px; }
.category-tabs button { min-height: 44px; font-size: 15px; color: var(--muted); padding: 8px 6px; border-radius: 9px; }
.category-tabs button.active { background: var(--green-soft); color: var(--green); font-weight: 700; }
.tool-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(100%, 155px), 1fr)); gap: 12px; max-height: max(360px, calc(var(--app-height) - 450px)); overflow-y: auto; padding: 2px 4px 4px 0; scrollbar-width: thin; scrollbar-color: #a5b39d transparent; }
.tool-tile { position: relative; background: var(--surface); border: 1px solid var(--line); border-radius: 13px; min-height: 135px; transition: border-color .15s; min-width: 0; }
.tool-tile:hover { border-color: #819e6e; }
.tool-tile.selected { border-color: #779c60; background: #f4f8ed; }
.tile-open { width: 100%; height: 100%; text-align: left; padding: 16px 13px; display: block; }
.tile-icon { width: 35px; height: 35px; display: grid; place-items: center; border-radius: 10px; background: #edf3e8; color: #527236; margin-bottom: 11px; }
.tile-icon svg { width: 21px; height: 21px; }
.tile-icon.blue { background: #edf2f8; color: #4c6c98; }
.tile-icon.amber { background: #f7f1e6; color: #8d6b2b; }
.tile-icon.rose { background: #f8eded; color: #9b5953; }
.tile-title { display: block; font-size: 16px; font-weight: 600; line-height: 1.5; word-break: keep-all; overflow-wrap: anywhere; }
.tile-desc { display: block; font-size: 13px; color: var(--muted); margin-top: 5px; line-height: 1.65; word-break: keep-all; overflow-wrap: anywhere; }
.star-button { position: absolute; right: 5px; top: 5px; color: #6d7c61; display: grid; place-items: center; width: 44px; height: 44px; border-radius: 10px; }
.star-button svg { width: 20px; height: 20px; }
.star-button.chosen { color: #776714; }
.star-button.chosen svg { fill: #ebe39a; }
.library-footer { display: flex; align-items: center; gap: 7px; color: var(--muted); font-size: 13px; line-height: 1.8; margin: 15px 0 0; }
.library-footer svg { width: 16px; height: 16px; }
.page-footer { display: flex; justify-content: space-between; align-items: center; gap: 12px; flex-wrap: wrap; border-top: 1px solid var(--line); margin-top: 24px; padding: 16px 0 22px; color: var(--muted); font-size: 13px; }
.page-footer b { color: var(--green); font-weight: 700; }
.footer-dot { padding: 0 6px; }
.mobile-nav { display: none; }
.tool-card { background: var(--surface); border: 1px solid var(--line); border-radius: 20px; padding: clamp(18px, 2vw, 26px); box-shadow: var(--shadow); min-width: 0; }
.tool-heading { display: flex; align-items: center; gap: 9px; margin-bottom: 20px; }
.tool-heading .back { width: 44px; height: 44px; background: var(--key); border-radius: 10px; font-size: 22px; flex-shrink: 0; }
.tool-heading h2 { font-size: 21px; margin: 0; min-width: 0; }
.tool-heading .star-button { position: static; margin-left: auto; flex-shrink: 0; }
.tool-intro { font-size: 15px; color: var(--muted); line-height: 1.8; margin: -4px 0 22px; word-break: keep-all; }
.tool-form { display: grid; gap: 17px; }
.field { min-width: 0; }
.field label { font-size: 15px; color: var(--text); display: block; margin-bottom: 7px; font-weight: 600; }
.input-wrap { display: flex; align-items: center; gap: 8px; border: 1px solid var(--line); background: var(--key); border-radius: 11px; padding: 0 14px; min-height: 56px; min-width: 0; }
.input-wrap:focus-within { border-color: var(--green); box-shadow: 0 0 0 2px #86a67320; }
.input-wrap input, .input-wrap select { width: 100%; min-width: 0; background: transparent; color: var(--text); font-size: 20px; border: 0; outline: 0; padding: 12px 0; font-variant-numeric: tabular-nums; }
.input-wrap input[type=date], .input-wrap select { font-size: 16px; min-height: 54px; }
.input-wrap input[type=date] { appearance: none; }
.input-wrap input::-webkit-inner-spin-button { -webkit-appearance: none; }
.input-wrap input { -moz-appearance: textfield; }
.input-wrap span { font-size: 15px; color: var(--muted); white-space: nowrap; flex-shrink: 0; }
.input-wrap input::placeholder { color: var(--muted); font-size: 16px; }
.row-fields { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 14px; }
.tool-result { margin-top: 24px; border-radius: 14px; padding: clamp(16px, 2vw, 22px); background: var(--green-soft); min-width: 0; }
.result-label { font-size: 15px; color: var(--muted); }
.result-main { font-size: var(--result-size); font-weight: 700; letter-spacing: -.035em; margin: 8px 0; line-height: 1.5; color: var(--green); white-space: nowrap; overflow-x: auto; overflow-y: hidden; scrollbar-width: thin; font-variant-numeric: tabular-nums; }
.result-detail { font-size: 14px; color: var(--muted); line-height: 1.9; }
.result-detail .result-row { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1.25fr); gap: 8px 14px; padding: 3px 0; }
.result-row b { font-weight: 500; color: var(--text); text-align: right; overflow-wrap: anywhere; }
.result-prompt { font-size: 15px; color: var(--muted); line-height: 1.8; margin: 0; }
.formula-note { font-size: 13px; color: var(--muted); line-height: 1.9; margin: 18px 0 0; word-break: keep-all; overflow-wrap: anywhere; }
.tool-bottom { display: flex; gap: 10px; margin-top: 16px; }
.button { background: var(--green); color: #ffffff; min-height: 48px; padding: 12px 16px; border-radius: 10px; font-size: 16px; font-weight: 600; }
.button.secondary { background: var(--key); color: var(--text); border: 1px solid var(--line); }
.button.full { width: 100%; margin-top: 16px; }
.tool-bottom .button { flex: 1; }
.empty-state { grid-column: 1/-1; text-align: center; font-size: 15px; color: var(--muted); padding: 60px 10px; line-height: 1.9; }
.tool-error { color: #a94436; font-size: 15px; line-height: 1.7; }
.rate-status { font-size: 13px; color: var(--muted); margin: 10px 0 0; line-height: 1.8; }
.rate-button { margin-top: 14px; width: 100%; }
.view-library .workspace { display: block; }
.view-library .calculator-column { display: none; }
.view-library .tool-grid { grid-template-columns: repeat(auto-fill, minmax(min(100%, 180px), 1fr)); max-height: none; overflow: visible; }
.view-library .library { max-width: none; }
.view-library .search { max-width: 520px; }
.view-library .heading-art { display: none; }
dialog { border: 1px solid var(--line); border-radius: 19px; padding: 24px; width: 520px; max-width: calc(100vw - 24px); max-height: calc(var(--app-height) - 24px); background: var(--surface); color: var(--text); box-shadow: 0 20px 100px #14281530; overflow-y: auto; }
dialog::backdrop { background: #16271b66; backdrop-filter: blur(5px); }
.dialog-heading { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 16px; }
.dialog-heading h2 { margin: 5px 0; }
.dialog-desc { font-size: 14px; color: var(--muted); margin-bottom: 20px; }
#history-list { max-height: 48vh; max-height: 48dvh; overflow: auto; }
.history-entry { width: 100%; padding: 14px 2px; border-bottom: 1px solid var(--line); display: block; text-align: right; }
.history-entry small { display: block; color: var(--muted); font-size: 16px; overflow-wrap: anywhere; }
.history-entry strong { display: block; font-size: 28px; font-weight: 600; margin-top: 4px; overflow-wrap: anywhere; }
.history-entry time { font-size: 12px; color: var(--muted); }
.about-text { font-size: 15px; line-height: 1.9; color: var(--muted); }
.about-text h3 { font-size: 17px; color: var(--text); margin: 22px 0 7px; }
.toast { position: fixed; left: calc(50% + var(--rail-width) / 2); bottom: 26px; transform: translate(-50%, 20px); opacity: 0; pointer-events: none; background: #263c2e; color: #ffffff; padding: 12px 18px; border-radius: 11px; font-size: 14px; transition: opacity .2s, transform .2s; z-index: 30; box-shadow: 0 8px 30px #0002; max-width: calc(100vw - 32px); width: max-content; text-align: center; }
.toast.visible { opacity: 1; transform: translate(-50%, 0); }

body.dark { color-scheme: dark; --bg: #171e1a; --surface: #222d25; --sidebar: #1c251f; --text: #e2e8dd; --muted: #b0bfa7; --line: #495846; --green: #b9df92; --green-soft: #31432e; --lime: #d6edbc; --key: #2b372d; --shadow: 0 12px 40px #0001; }
body.dark .brand-icon, body.dark .key.equals, body.dark .button:not(.secondary) { background: #badc9a; color: #223b26; }
body.dark .key.utility, body.dark .key.clear { background: #35462f; color: #c8ddba; }
body.dark .tool-tile.selected { background: #2c3d28; }
body.dark .tile-icon { background: #35472f; color: #bddc9a; }
body.dark .tile-icon.blue { background: #303e4a; color: #b1cbe1; }
body.dark .tile-icon.amber { background: #48412d; color: #e4ce8b; }
body.dark .tile-icon.rose { background: #493b37; color: #e8b4a7; }
body.dark .star-button { color: #b7c7ab; }
body.dark .star-button.chosen { color: #e5d37c; }
body.dark .star-button.chosen svg { fill: #655b24; }

/* Folded phones and tablets use all available width, without a narrow sidebar. */
@media (max-width: 1119px) {
  .sidebar { display: none; }
  main { margin-left: 0; }
  .topbar { min-height: calc(56px + env(safe-area-inset-top)); padding: calc(6px + env(safe-area-inset-top)) max(16px, env(safe-area-inset-right)) 6px max(16px, env(safe-area-inset-left)); position: sticky; top: 0; z-index: 6; background: var(--bg); }
  .breadcrumb { font-size: 13px; }
  .breadcrumb:before { content: '바로 계산기'; font-size: 17px; color: var(--green); font-weight: 800; margin-right: 12px; }
  .breadcrumb .breadcrumb-context { display: none; }
  .breadcrumb > span { margin: 0 6px; }
  .breadcrumb b { font-size: 13px; }
  .top-actions { gap: 4px; }
  .local-badge { display: none; }
  .mobile-theme { display: inline-grid; }
  .page-wrap { padding: 20px max(20px, env(safe-area-inset-right)) calc(var(--mobile-nav-height) + env(safe-area-inset-bottom) + 22px) max(20px, env(safe-area-inset-left)); }
  .page-heading { margin-bottom: 20px; }
  .page-heading .eyebrow { display: none; }
  .page-heading h1 { margin: 0; font-size: clamp(1.375rem, 3vw, 1.875rem); }
  .page-heading p { font-size: 14px; }
  .heading-art { font-size: 52px; }
  .keyboard-hint { display: none; }
  .mobile-nav { position: fixed; inset: auto 0 0; height: calc(var(--mobile-nav-height) + env(safe-area-inset-bottom)); background: var(--surface); border-top: 1px solid var(--line); z-index: 10; display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); padding: 6px max(8px, env(safe-area-inset-right)) calc(6px + env(safe-area-inset-bottom)) max(8px, env(safe-area-inset-left)); box-shadow: 0 -5px 30px #22332206; }
  .mobile-nav button { font-size: 12px; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 5px; color: var(--muted); padding: 2px; min-width: 0; min-height: 48px; white-space: nowrap; border-radius: 10px; }
  .mobile-nav button.active { color: var(--green); font-weight: 700; background: var(--green-soft); }
  .mobile-nav button svg { width: 23px; height: 23px; }
  .toast { left: 50%; bottom: calc(var(--mobile-nav-height) + env(safe-area-inset-bottom) + 14px); }
}

/* One column when the device needs more room for readable controls. */
@media (max-width: 879px) {
  :root { --answer-size: clamp(2.75rem, 9vw, 4rem); --result-size: clamp(1.75rem, 6vw, 2.5rem); }
  .workspace { grid-template-columns: minmax(0, 1fr); gap: 12px; }
  .calculator-column { width: 100%; max-width: 560px; margin-inline: auto; }
  .calculator-card { display: flex; flex-direction: column; gap: 8px; height: clamp(418px, calc(var(--app-height) - 226px - env(safe-area-inset-top) - env(safe-area-inset-bottom)), 710px); min-height: 418px; padding: clamp(14px, 3.5vw, 22px); }
  .card-top { flex: 0 0 44px; min-height: 44px; }
  .card-top .icon-button { height: 44px; width: 44px; }
  .display { flex: 1 0 86px; min-height: 86px; padding: 6px 2px 8px; }
  .keypad { flex: 3 0 252px; grid-template-rows: repeat(5, minmax(44px, 1fr)); gap: clamp(7px, 1.8vw, 11px); }
  .key { height: auto; min-height: 44px; font-size: clamp(1.5rem, 5.2vw, 2rem); }
  .key.utility, .key.clear { font-size: clamp(1.125rem, 4.6vw, 1.5rem); }
  .key.operator, .key.equals { font-size: clamp(1.875rem, 6vw, 2.5rem); }
  .calc-bottom { display: none; }
  .tool-grid { grid-template-columns: repeat(auto-fill, minmax(min(100%, 160px), 1fr)); max-height: none; overflow: visible; padding: 0; }
  .library { padding-top: 8px; }
  .library-top h2 { font-size: 21px; }
  .library-top .eyebrow { display: none; }
  .library-top { margin-bottom: 14px; }
  .view-library .tool-grid { grid-template-columns: repeat(auto-fill, minmax(min(100%, 160px), 1fr)); }
  .tool-card { padding: clamp(16px, 3.5vw, 24px); }
}
@media (max-width: 479px) {
  .page-wrap { padding-top: 12px; padding-left: max(12px, env(safe-area-inset-left)); padding-right: max(12px, env(safe-area-inset-right)); }
  .page-heading { margin-bottom: 12px; }
  .page-heading h1 { font-size: clamp(1.25rem, 5.8vw, 1.625rem); }
  .page-heading p { font-size: 14px; line-height: 1.7; margin-top: 5px; }
  .heading-art { display: none; }
  .breadcrumb:before { font-size: 16px; margin-right: 8px; }
  .breadcrumb b { font-size: 12px; }
  .topbar { gap: 2px; padding-left: max(12px, env(safe-area-inset-left)); padding-right: max(8px, env(safe-area-inset-right)); }
  .top-actions { gap: 0; }
  .calculator-card { border-radius: 17px; }
  .recent-strip { padding-block: 14px; }
  .tool-grid, .view-library .tool-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
  .tile-open { padding: 15px 12px; }
  .tile-title { font-size: 16px; }
  .tile-desc { font-size: 13px; }
  .tool-heading { gap: 7px; }
  .tool-heading h2 { font-size: 20px; }
  .result-detail .result-row { grid-template-columns: minmax(0, 1fr) minmax(0, 1.4fr); gap: 8px; }
  .tool-total { font-size: 12px; padding: 5px 7px; }
  .page-footer { font-size: 12px; margin-top: 20px; }
  dialog { padding: 18px; }
}
@media (max-width: 359px) {
  .breadcrumb b { display: none; }
  .breadcrumb > span { display: none; }
  .mobile-nav button { font-size: 11px; }
  .tile-open { padding: 14px 10px; }
  .tool-heading h2 { font-size: 18px; }
  .input-wrap { padding-inline: 10px; }
}
@media (max-width: 879px) and (max-height: 739px) {
  .page-heading p { display: none; }
  .page-heading h1 { font-size: 21px; }
  .page-heading { margin-bottom: 12px; }
  .page-wrap { padding-top: 10px; }
  .calculator-card { height: clamp(400px, calc(var(--app-height) - 186px - env(safe-area-inset-top) - env(safe-area-inset-bottom)), 600px); min-height: 400px; padding: 12px; gap: 6px; }
  .display { flex-basis: 80px; min-height: 80px; padding-block: 3px; }
  .keypad { flex-basis: 244px; gap: 6px; }
  .answer { line-height: 1.2; }
}
@media (max-width: 599px) and (max-height: 600px) {
  body:not(.view-library) .page-heading { display: none; }
  .calculator-card { height: max(400px, calc(var(--app-height) - 146px - env(safe-area-inset-top) - env(safe-area-inset-bottom))); }
}

/* Phone landscape: result on the left, keys on the right, navigation beside them. */
@media (min-width: 600px) and (max-width: 1119px) and (max-height: 500px) and (orientation: landscape) {
  :root { --landscape-nav: calc(76px + env(safe-area-inset-left)); }
  main { margin-left: var(--landscape-nav); }
  .topbar { min-height: 46px; height: auto; padding-block: 0; padding-left: 14px; }
  .topbar .icon-button { width: 40px; height: 40px; }
  .page-wrap { padding: 10px max(12px, env(safe-area-inset-right)) 18px 12px; }
  .page-heading { display: none; }
  .workspace { display: block; }
  .calculator-column { max-width: none; }
  .calculator-card { display: grid; grid-template-columns: minmax(140px, .75fr) minmax(240px, 1.25fr); grid-template-rows: 44px minmax(0, 1fr); gap: 8px 16px; height: max(278px, calc(var(--app-height) - 66px)); min-height: 278px; padding: 12px; }
  .card-top { grid-column: 1; grid-row: 1; min-width: 0; gap: 4px; }
  .card-label { font-size: 14px; gap: 5px; }
  .card-label svg { width: 17px; height: 17px; }
  .display { grid-column: 1; grid-row: 2; align-self: center; padding: 4px 0; min-width: 0; }
  .answer { --answer-size: 42px; }
  .keypad { grid-column: 2; grid-row: 1 / 3; gap: 6px; grid-template-rows: repeat(5, minmax(44px, 1fr)); }
  .key { min-height: 44px; height: auto; font-size: 24px; border-radius: 9px; }
  .key.operator, .key.equals { font-size: 29px; }
  .calc-bottom { display: none; }
  body:not(.view-library) .library, body:not(.view-library) .recent-strip { display: none; }
  .mobile-nav { inset: 0 auto 0 0; width: var(--landscape-nav); height: auto; grid-template-columns: 1fr; grid-template-rows: repeat(4, minmax(48px, 1fr)); padding: max(6px, env(safe-area-inset-top)) 6px max(6px, env(safe-area-inset-bottom)) max(6px, env(safe-area-inset-left)); border-top: 0; border-right: 1px solid var(--line); }
  .mobile-nav button { font-size: 11px; }
  .toast { bottom: 16px; left: calc(50% + var(--landscape-nav) / 2); }
}
@media (min-width: 1120px) and (max-width: 1280px) {
  :root { --rail-width: 200px; }
  .sidebar { padding-inline: 14px; }
  .brand { font-size: 19px; }
  .nav-shortcut, .keyboard-hint { display: none; }
  .side-note p { font-size: 12px; }
  .topbar { padding-inline: 24px; }
  .page-wrap { padding-inline: 24px; }
}
@media (min-width: 1120px) and (max-height: 720px) { .side-note { display: none; } .sidebar-bottom { margin-top: auto; } }
@media (prefers-reduced-motion: reduce) { *, *:before, *:after { scroll-behavior: auto !important; transition: none !important; animation: none !important; } }
.answer { font-size: var(--fit-font-size, var(--answer-size)); }
.result-main { font-size: var(--fit-font-size, var(--result-size)); }
.input-wrap input, .input-wrap select { scroll-margin-block: 90px 130px; }
