:root {
  color-scheme: light;
  --page: #f5f9f8;
  --surface: #ffffff;
  --surface-soft: #f6faf9;
  --surface-accent: #e9f7f4;
  --ink: #182b2d;
  --muted: #768687;
  --line: #e7edeb;
  --accent: #168c7c;
  --accent-dark: #117767;
  --accent-ink: #087364;
  --shadow: 0 18px 45px rgba(26, 55, 52, 0.07), 0 2px 8px rgba(26, 55, 52, 0.03);
  --small-shadow: 0 4px 14px rgba(26, 55, 52, 0.06);
  --danger: #bd4b53;
}

:root[data-theme="dark"] {
  color-scheme: dark;
  --page: #101a1b;
  --surface: #192526;
  --surface-soft: #202e2f;
  --surface-accent: #1c3936;
  --ink: #e8f1ef;
  --muted: #a0b0ae;
  --line: #2c3b3c;
  --accent: #56c5b1;
  --accent-dark: #6fd2c0;
  --accent-ink: #7be0cb;
  --shadow: 0 18px 45px rgba(0, 0, 0, 0.2), 0 2px 8px rgba(0, 0, 0, 0.1);
  --small-shadow: 0 4px 14px rgba(0, 0, 0, 0.16);
  --danger: #f09097;
}

* { box-sizing: border-box; }

html { min-width: 320px; min-height: 100%; background: var(--page); scrollbar-color: transparent transparent; scrollbar-width: thin; }
html.is-scrolling { scrollbar-color: var(--muted) transparent; }
::-webkit-scrollbar { width: 10px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { border: 3px solid transparent; border-radius: 8px; background: transparent; background-clip: content-box; }
html.is-scrolling::-webkit-scrollbar-thumb { background-color: var(--muted); }

body {
  min-width: 320px;
  min-height: 100vh;
  margin: 0;
  background: var(--page);
  color: var(--ink);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  font-size: 15px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  transition: background-color 180ms ease, color 180ms ease;
}

button, input, select { font: inherit; }
button { color: inherit; }
button:focus-visible, input:focus-visible, select:focus-visible, a:focus-visible {
  outline: 3px solid color-mix(in srgb, var(--accent) 50%, transparent);
  outline-offset: 3px;
}

.app-shell { width: min(100% - 40px, 1040px); margin: 0 auto; }
.topbar { display: flex; align-items: center; justify-content: space-between; min-height: 88px; }
.brand { display: inline-flex; align-items: center; gap: 12px; color: inherit; text-decoration: none; }
.brand-mark { display: grid; width: 42px; height: 42px; place-items: center; border-radius: 14px; background: var(--surface-accent); color: var(--accent-ink); }
.brand-mark svg { width: 24px; height: 24px; }
.brand-mark img { width: 100%; height: 100%; border-radius: inherit; object-fit: cover; }
.brand-copy { display: grid; gap: 1px; }
.brand-name { font-size: 15px; font-weight: 740; letter-spacing: -0.02em; }
.brand-caption { color: var(--muted); font-size: 12px; }
.primary-nav { display: flex; justify-content: center; gap: 6px; padding-top: 16px; border-top: 1px solid var(--line); }
.nav-link { display: inline-flex; align-items: center; justify-content: center; gap: 9px; min-height: 40px; padding: 0 15px; border: 0; border-radius: 10px; background: transparent; color: var(--muted); cursor: pointer; font-size: 13px; font-weight: 640; transition: color 150ms ease, background-color 150ms ease, transform 150ms ease; }
.nav-link svg { width: 19px; height: 19px; }
.nav-link:hover { background: var(--surface-soft); color: var(--ink); }
.nav-link:active { transform: scale(0.97); }
.nav-link.is-active { background: var(--surface-accent); color: var(--accent-ink); }
.mobile-nav { display: none; }

.main-content { min-height: 550px; padding: 44px 0 24px; }
.page-section { display: none; animation: reveal 220ms ease both; }
.page-section.is-visible { display: block; }
.page-section[hidden] { display: none; }
@keyframes reveal { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: translateY(0); } }
.page-intro { margin: 0 auto 28px; text-align: center; }
.eyebrow { margin: 0 0 11px; color: var(--accent-ink); font-size: 10px; font-weight: 750; letter-spacing: 0.16em; }
h1, h2, p { margin-top: 0; }
.page-intro h1 { margin-bottom: 8px; font-size: clamp(29px, 4vw, 38px); font-weight: 680; letter-spacing: -0.055em; line-height: 1.15; }
.intro-copy { margin-bottom: 0; color: var(--muted); font-size: 14px; }
.converter-card, .content-card { border: 1px solid color-mix(in srgb, var(--line) 85%, transparent); border-radius: 20px; background: var(--surface); box-shadow: var(--shadow); }
.converter-card { width: min(100%, 650px); margin: 0 auto; padding: 27px 30px 21px; }
.calculator-card { width: min(100%, 390px); margin: 0 auto; padding: 18px; border: 1px solid color-mix(in srgb, var(--line) 85%, transparent); border-radius: 20px; background: var(--surface); box-shadow: var(--shadow); }
.calculator-display { display: grid; min-height: 112px; align-content: end; justify-items: end; gap: 7px; padding: 14px 12px 18px; overflow: hidden; }
.calculator-expression { min-height: 18px; width: 100%; overflow: hidden; color: var(--muted); font-size: 13px; text-align: right; text-overflow: ellipsis; white-space: nowrap; }
.calculator-result { width: 100%; overflow: hidden; color: var(--ink); font-size: clamp(36px, 10vw, 48px); font-weight: 630; letter-spacing: -0.055em; line-height: 1.15; text-align: right; text-overflow: ellipsis; white-space: nowrap; }
.calculator-keypad { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 9px; }
.calculator-key { min-height: 58px; border: 1px solid var(--line); border-radius: 13px; background: var(--surface-soft); color: var(--ink); cursor: pointer; font-size: 20px; font-weight: 600; transition: background-color 140ms ease, transform 140ms ease; }
.calculator-key:hover { background: var(--surface-accent); }
.calculator-key:active { transform: scale(0.96); }
.calculator-key-function { color: var(--muted); font-size: 16px; }
.calculator-key-operator { background: var(--surface-accent); color: var(--accent-ink); font-size: 23px; }
.calculator-key-operator:hover { background: color-mix(in srgb, var(--accent) 18%, var(--surface)); }
.calculator-key-zero { grid-column: span 2; }
.calculator-history-card { width: min(100%, 426px); margin: 14px auto 0; }
.calculator-history-list { display: grid; gap: 8px; margin: 0; padding: 0; list-style: none; }
.calculator-history-entry { display: grid; gap: 4px; padding: 12px 14px; border: 1px solid var(--line); border-radius: 11px; background: var(--surface); }
.calculator-history-summary { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; }
.calculator-history-expression { color: var(--muted); font-size: 12px; }
.calculator-history-result { color: var(--ink); font-size: 13px; font-weight: 670; }
.calculator-history-time { color: var(--muted); font-size: 10px; }
.card-heading { display: flex; align-items: flex-start; justify-content: space-between; gap: 16px; margin-bottom: 24px; }
.card-heading h2, .list-heading h2, .settings-heading h2 { margin-bottom: 4px; font-size: 16px; font-weight: 700; letter-spacing: -0.025em; }
.card-heading p, .list-heading p, .settings-heading p { margin-bottom: 0; color: var(--muted); font-size: 12px; }
.accuracy-badge { display: inline-flex; align-items: center; gap: 5px; margin-top: 2px; color: var(--accent-ink); font-size: 11px; font-weight: 700; }
.accuracy-badge svg { width: 16px; height: 16px; }
.converter-controls { display: grid; gap: 19px; }
.value-field, .unit-field { display: grid; gap: 7px; }
.value-field label, .unit-field label { color: var(--muted); font-size: 11px; font-weight: 690; letter-spacing: 0.015em; }
.input-wrap { display: flex; align-items: center; min-height: 53px; border: 1px solid var(--line); border-radius: 11px; background: var(--surface); transition: border-color 150ms ease, box-shadow 150ms ease; }
.input-wrap:focus-within { border-color: var(--accent); box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 13%, transparent); }
.input-wrap input { width: 100%; min-width: 0; height: 51px; padding: 0 14px; border: 0; outline: 0; background: transparent; color: var(--ink); font-size: 17px; font-weight: 550; }
.input-wrap input::placeholder { color: color-mix(in srgb, var(--muted) 76%, transparent); font-size: 14px; font-weight: 440; }
.icon-button { display: grid; width: 38px; height: 38px; flex: 0 0 38px; margin-right: 7px; place-items: center; border: 0; border-radius: 9px; background: transparent; color: var(--muted); cursor: pointer; transition: color 150ms ease, background-color 150ms ease; }
.icon-button:hover { background: var(--surface-soft); color: var(--ink); }
.icon-button svg { width: 19px; height: 19px; }
.unit-row { display: grid; grid-template-columns: minmax(0, 1fr) 42px minmax(0, 1fr); align-items: end; gap: 11px; }
.print-dimensions { grid-template-columns: minmax(0,1fr) 28px minmax(0,1fr); align-items: end; }
.dimension-sep { display: flex; align-items: center; justify-content: center; padding-bottom: 18px; color: var(--muted); font-size: 22px; font-weight: 700; }
select { width: 100%; min-height: 47px; padding: 0 36px 0 12px; border: 1px solid var(--line); border-radius: 10px; appearance: none; background-color: var(--surface); background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='14' height='14' viewBox='0 0 14 14' fill='none'%3E%3Cpath d='m3 5 4 4 4-4' stroke='%23768687' stroke-width='1.5' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E"); background-position: right 12px center; background-repeat: no-repeat; color: var(--ink); cursor: pointer; font-size: 13px; font-weight: 570; }
select:hover { border-color: color-mix(in srgb, var(--accent) 45%, var(--line)); }
.swap-button { display: grid; width: 42px; height: 42px; margin-bottom: 2px; place-items: center; border: 1px solid var(--line); border-radius: 12px; background: var(--surface); color: var(--accent-ink); cursor: pointer; transition: background-color 150ms ease, transform 220ms ease, border-color 150ms ease; }
.swap-button:hover { border-color: color-mix(in srgb, var(--accent) 45%, var(--line)); background: var(--surface-accent); }
.swap-button svg { width: 19px; height: 19px; }
.swap-button.is-swapping { transform: rotate(180deg); }
.field-feedback { min-height: 16px; color: var(--danger); font-size: 11px; }
.result-panel { position: relative; overflow: hidden; margin-top: 9px; padding: 19px 20px 15px; border: 1px solid color-mix(in srgb, var(--accent) 11%, var(--line)); border-radius: 14px; background: var(--surface-accent); }
.result-label { margin-bottom: 4px; color: var(--accent-ink); font-size: 9px; font-weight: 780; letter-spacing: 0.16em; }
.result-line { display: flex; align-items: baseline; flex-wrap: wrap; gap: 8px; }
.result-line output { overflow-wrap: anywhere; color: var(--ink); font-size: clamp(28px, 6vw, 38px); font-weight: 680; letter-spacing: -0.055em; line-height: 1.22; }
.result-unit { color: var(--accent-ink); font-size: 14px; font-weight: 650; }
.currency-symbol { color: var(--accent-ink); font-size: 18px; font-weight: 700; }
.result-detail { margin: 5px 0 0; color: var(--muted); font-size: 11px; }
.copy-button { display: inline-flex; align-items: center; justify-content: center; gap: 7px; min-height: 34px; margin-top: 12px; padding: 0 10px; border: 1px solid color-mix(in srgb, var(--accent) 22%, var(--line)); border-radius: 8px; background: var(--surface); color: var(--accent-ink); cursor: pointer; font-size: 11px; font-weight: 680; transition: background-color 150ms ease, opacity 150ms ease; }
.copy-button:hover:not(:disabled) { background: var(--surface-soft); }
.copy-button:disabled { cursor: not-allowed; opacity: 0.48; }
.copy-button svg { width: 16px; height: 16px; }
.conversion-note { margin: 13px 0 0; color: var(--muted); font-size: 10px; text-align: center; }
.offline-note { display: flex; align-items: center; justify-content: center; gap: 7px; margin: 16px auto 0; color: var(--muted); font-size: 11px; }
.offline-note svg { width: 16px; height: 16px; color: var(--accent-ink); }
.compact-intro { margin-bottom: 27px; }
.compact-intro h1 { font-size: clamp(27px, 4vw, 34px); }
.content-card { padding: 22px 24px; }
.list-heading { display: flex; align-items: center; justify-content: space-between; gap: 16px; padding-bottom: 18px; }
.text-button { padding: 7px 9px; border: 0; border-radius: 7px; background: transparent; color: var(--accent-ink); cursor: pointer; font-size: 11px; font-weight: 690; }
.text-button:hover { background: var(--surface-accent); }
.history-list { display: grid; gap: 8px; margin: 0; padding: 0; list-style: none; }
.history-item { display: flex; align-items: center; justify-content: space-between; gap: 14px; width: 100%; padding: 14px 15px; border: 1px solid var(--line); border-radius: 11px; background: var(--surface); color: inherit; cursor: pointer; text-align: left; transition: border-color 150ms ease, background-color 150ms ease, transform 150ms ease; }
.history-item:hover { transform: translateY(-1px); border-color: color-mix(in srgb, var(--accent) 38%, var(--line)); background: var(--surface-soft); }
.history-conversion { display: flex; align-items: baseline; flex-wrap: wrap; gap: 5px; min-width: 0; }
.history-source, .history-target { overflow-wrap: anywhere; font-size: 13px; font-weight: 660; }
.history-arrow { margin: 0 4px; color: var(--accent-ink); }
.history-time { flex: 0 0 auto; color: var(--muted); font-size: 10px; }
.empty-state { display: grid; justify-items: center; gap: 7px; padding: 36px 16px 29px; color: var(--muted); text-align: center; }
.empty-state[hidden] { display: none; }
.empty-state strong { color: var(--ink); font-size: 13px; font-weight: 670; }
.empty-state > span:last-child { font-size: 11px; }
.empty-icon { display: grid; width: 42px; height: 42px; margin-bottom: 3px; place-items: center; border-radius: 14px; background: var(--surface-accent); color: var(--accent-ink); }
.empty-icon svg { width: 23px; height: 23px; }
.settings-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 14px; }
.settings-card { padding: 21px; box-shadow: var(--small-shadow); }
.settings-heading { display: flex; align-items: center; gap: 12px; margin-bottom: 19px; }
.settings-heading h2 { font-size: 14px; }
.settings-heading p { font-size: 11px; }
.settings-icon { display: grid; width: 38px; height: 38px; flex: 0 0 38px; place-items: center; border-radius: 12px; background: var(--surface-accent); color: var(--accent-ink); }
.settings-icon svg { width: 21px; height: 21px; }
.units-icon { background: #edf3fb; color: #5781b5; }
:root[data-theme="dark"] .units-icon { background: #273548; color: #92b7e4; }
.data-icon { background: #f9f0e9; color: #ad7447; }
:root[data-theme="dark"] .data-icon { background: #3b3027; color: #d8a879; }
.about-icon { background: #f1eefb; color: #8170b4; }
:root[data-theme="dark"] .about-icon { background: #322c41; color: #b2a3e5; }
.setting-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 12px 0; border-top: 1px solid var(--line); color: var(--ink); font-size: 12px; font-weight: 560; }
.setting-row select { width: min(58%, 220px); min-height: 39px; padding-left: 10px; font-size: 11px; }
.setting-input { width: min(58%, 220px); min-width: 0; min-height: 39px; padding: 0 10px; border: 1px solid var(--line); border-radius: 9px; background: var(--surface); color: var(--ink); font-size: 11px; }
.profile-photo-row input { font-size: 10px; }
.remove-photo-button { margin-top: 4px; }
.setting-row.data-row { min-height: 47px; }
.about-version { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding-top: 13px; border-top: 1px solid var(--line); font-size: 12px; font-weight: 600; }
.version-tag { color: var(--muted); font-size: 10px; font-weight: 550; }
.site-footer { display: flex; justify-content: space-between; gap: 12px; padding: 17px 0 22px; border-top: 1px solid var(--line); color: var(--muted); font-size: 10px; }
.toast { position: fixed; z-index: 5; right: 22px; bottom: 22px; max-width: min(360px, calc(100vw - 32px)); padding: 12px 16px; border: 1px solid var(--line); border-radius: 11px; background: var(--surface); box-shadow: var(--shadow); color: var(--ink); font-size: 12px; font-weight: 600; opacity: 0; pointer-events: none; transform: translateY(8px); transition: opacity 160ms ease, transform 160ms ease; }
.toast.is-visible { opacity: 1; transform: translateY(0); }

@media (max-width: 600px) {
  .app-shell { width: min(100% - 32px, 460px); }
  .topbar { min-height: 72px; }
  .brand-mark { width: 38px; height: 38px; border-radius: 12px; }
  .brand-name { font-size: 14px; }
  .brand-caption { font-size: 11px; }
  .primary-nav { display: none; }
  .main-content { min-height: auto; padding: 35px 0 100px; }
  .page-intro { margin-bottom: 22px; }
  .page-intro h1 { font-size: 31px; }
  .intro-copy { font-size: 13px; }
  .converter-card { padding: 21px 17px 17px; border-radius: 17px; }
  .card-heading { margin-bottom: 20px; }
  .card-heading h2 { font-size: 15px; }
  .card-heading p { max-width: 230px; font-size: 11px; }
  .accuracy-badge { gap: 3px; font-size: 10px; }
  .unit-row { grid-template-columns: minmax(0, 1fr) 38px minmax(0, 1fr); gap: 7px; }
  .swap-button { width: 38px; height: 38px; }
  .unit-field select { padding-left: 9px; padding-right: 26px; background-position: right 8px center; font-size: 12px; }
  .result-panel { padding: 16px 15px 13px; }
  .result-line output { font-size: clamp(27px, 8vw, 35px); }
  .offline-note { font-size: 10px; }
  .content-card { padding: 18px 15px; border-radius: 16px; }
  .settings-grid { grid-template-columns: 1fr; gap: 11px; }
  .settings-card { padding: 18px; }
  .history-item { padding: 12px 11px; }
  .history-source, .history-target { font-size: 12px; }
  .history-time { font-size: 9px; }
  .site-footer { display: grid; justify-content: center; gap: 5px; padding-bottom: 18px; text-align: center; }
  .calculator-card { padding: 14px; }
  .calculator-keypad { gap: 7px; }
  .calculator-key { min-height: 56px; border-radius: 11px; }
  .mobile-nav { position: fixed; z-index: 4; right: 0; bottom: 0; left: 0; display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); padding: 8px 8px max(8px, env(safe-area-inset-bottom)); border-top: 1px solid var(--line); background: color-mix(in srgb, var(--surface) 94%, transparent); backdrop-filter: blur(16px); }
  .mobile-nav .nav-link { display: grid; gap: 2px; min-height: 51px; padding: 4px 6px; border-radius: 10px; font-size: 10px; }
  .mobile-nav .nav-link svg { width: 20px; height: 20px; }
  .toast { right: 16px; bottom: calc(78px + env(safe-area-inset-bottom)); left: 16px; max-width: none; text-align: center; }
}

@media (min-width: 900px) {
  .main-content { padding-top: 51px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { scroll-behavior: auto !important; animation-duration: 0.01ms !important; animation-iteration-count: 1 !important; transition-duration: 0.01ms !important; }
}
