:root {
  color-scheme: dark;
  --background: #2b2b2b;
  --key: #6b6b6b;
  --key-top: #4b4b4b;
  --key-pressed: #858585;
  --operator: #ff9f35;
  --operator-pressed: #ffb766;
  --text: #fff;
  --muted: #b8b8b8;
  --line: #3d3d3d;
  --fresh: #24b89a;
  --stale: #ffb24a;
  --danger: #ff715f;
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Display", "Segoe UI", sans-serif;
}

* { box-sizing: border-box; }
html, body { width: 100%; min-height: 100%; margin: 0; background: var(--background); }
body { min-height: 100svh; overflow: hidden; color: var(--text); -webkit-tap-highlight-color: transparent; }
button, input { font: inherit; }
button { border: 0; color: inherit; cursor: pointer; }

.app-shell {
  width: 100%;
  min-width: 0;
  max-width: 700px;
  height: 100svh;
  margin: 0 auto;
  padding-top: env(safe-area-inset-top, 0px);
  display: grid;
  grid-template-rows: minmax(220px, 34fr) minmax(330px, 55fr) minmax(88px, 11fr);
  background: var(--background);
}

.conversion-panel { min-width: 0; min-height: 0; display: grid; grid-template-columns: minmax(0, 1fr); grid-template-rows: 1fr 2px 1fr; }
.currency-row { min-width: 0; min-height: 0; padding: clamp(14px, 2.4vh, 24px) clamp(22px, 5vw, 42px); display: flex; align-items: center; justify-content: space-between; gap: 20px; }
.currency-divider { background: var(--line); }
.currency-identity { align-self: stretch; min-width: 82px; padding: 0; background: transparent; display: flex; flex-direction: column; align-items: flex-start; justify-content: center; gap: clamp(7px, 1vh, 12px); }
.currency-flag { flex: 0 0 auto; width: clamp(52px, 14vw, 70px); height: clamp(52px, 14vw, 70px); border: 1px solid rgba(255,255,255,.78); border-radius: 50%; display: block; overflow: hidden; background: #eee; box-shadow: 0 1px 2px rgba(0,0,0,.25); }
.currency-flag img { width: 100%; height: 100%; display: block; object-fit: cover; }
.currency-code { font-size: clamp(22px, 6vw, 32px); font-weight: 700; letter-spacing: .01em; }
.amount { flex: 1 1 auto; width: calc(100% - 105px); min-width: 0; max-width: calc(100% - 105px); color: var(--text); background: transparent; border: 0; padding: 0; text-align: right; font-size: clamp(47px, 13vw, 78px); font-weight: 400; line-height: 1; letter-spacing: -.04em; font-variant-numeric: tabular-nums; text-overflow: ellipsis; }
.amount-input { caret-color: transparent; }
.amount-output { overflow: hidden; white-space: nowrap; }

.calculator { min-width: 0; min-height: 0; background: var(--background); }
.keypad { width: 100%; height: 100%; display: grid; grid-template-columns: repeat(4, 1fr); grid-template-rows: repeat(5, 1fr); gap: 2px; background: var(--background); }
.key { min-width: 0; min-height: 0; padding: 0; border-radius: 0; background: var(--key); color: var(--text); font-size: clamp(36px, 10vw, 58px); font-weight: 400; line-height: 1; user-select: none; touch-action: manipulation; transition: filter .06s ease, transform .06s ease; }
.key-action { background: var(--key-top); }
.key-operator { background: var(--operator); font-size: clamp(42px, 11vw, 64px); }
.key:active { filter: brightness(1.2); transform: scale(.97); }
.key:focus-visible, .currency-identity:focus-visible, .footer-button:focus-visible, .dialog-close:focus-visible, .currency-option:focus-visible { outline: 4px solid #8bb7ff; outline-offset: -4px; }

.rate-footer { min-width: 0; min-height: 0; padding-bottom: env(safe-area-inset-bottom, 0px); display: grid; grid-template-columns: 22% minmax(0, 1fr) 22%; align-items: center; background: var(--background); }
.footer-button { width: 100%; height: 100%; padding: 0; background: transparent; color: var(--text); font-size: clamp(38px, 10vw, 56px); line-height: 1; touch-action: manipulation; }
.footer-button:disabled { opacity: .45; }
.info-button { font-size: clamp(32px, 8vw, 48px); }
.rate-status { min-width: 0; text-align: center; font-variant-numeric: tabular-nums; }
.rate-label { overflow: hidden; white-space: nowrap; text-overflow: ellipsis; font-size: clamp(16px, 4.5vw, 25px); font-weight: 650; }
.rate-age { margin-top: 5px; color: var(--fresh); font-size: clamp(15px, 4.2vw, 23px); font-weight: 650; }
.rate-age.is-stale { color: var(--stale); }
.rate-age.is-error { color: var(--danger); }

.sheet-dialog { width: min(100% - 24px, 520px); max-height: min(78svh, 720px); margin: auto auto max(12px, env(safe-area-inset-bottom, 0px)); padding: 0; border: 1px solid #555; border-radius: 24px; background: #303030; color: var(--text); box-shadow: 0 28px 80px rgba(0,0,0,.65); }
.sheet-dialog::backdrop { background: rgba(0,0,0,.7); backdrop-filter: blur(4px); }
.dialog-sheet { padding: 20px; }
.dialog-heading { display: flex; align-items: center; justify-content: space-between; gap: 16px; margin-bottom: 12px; }
.dialog-heading h2 { margin: 0; font-size: 23px; }
.dialog-close { flex: 0 0 auto; width: 40px; height: 40px; border-radius: 50%; background: #4b4b4b; font-size: 29px; line-height: 1; }
.currency-search { width: 100%; height: 54px; margin: 4px 0 12px; padding: 0 17px; border: 0; border-radius: 17px; outline: 0; background: #414141; color: var(--text); font-size: 19px; -webkit-appearance: none; appearance: none; }
.currency-search::placeholder { color: #999; }
.currency-search:focus { box-shadow: 0 0 0 3px #8bb7ff; }
.currency-options { max-height: min(54svh, 530px); overflow-y: auto; overscroll-behavior: contain; display: grid; gap: 3px; }
.currency-option { width: 100%; padding: 11px 12px; border-radius: 13px; display: flex; align-items: center; gap: 13px; background: transparent; text-align: left; }
.currency-option[hidden] { display: none; }
.currency-option:active { background: #4b4b4b; }
.option-flag { width: 39px; height: 39px; border: 1px solid rgba(255,255,255,.7); border-radius: 50%; display: block; object-fit: cover; background: #eee; overflow: hidden; }
.option-code { font-size: 17px; font-weight: 700; letter-spacing: .04em; }
.option-name { color: var(--muted); font-size: 13px; }
.info-dialog p { color: #e6e6e6; line-height: 1.45; }
.info-dialog #rate-details { white-space: pre-line; }
.info-dialog .dialog-note { color: var(--muted); font-size: 14px; }

.visually-hidden { position: absolute !important; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0,0,0,0); white-space: nowrap; border: 0; }

@media (max-height: 680px) {
  .app-shell { grid-template-rows: minmax(190px, 32fr) minmax(300px, 56fr) minmax(76px, 12fr); }
  .currency-row { padding-top: 12px; padding-bottom: 12px; }
  .currency-identity { gap: 6px; }
}

@media (min-width: 701px) {
  body { background: #151515; }
  .app-shell { box-shadow: 0 0 80px rgba(0,0,0,.65); }
}

@media (prefers-reduced-motion: reduce) { .key { transition: none; } }
