
/* Design tokens and base */
:root {
  color-scheme: light;
  --bg: #f8f9fb; --paper: #fff; --ink: #20242b; --muted: #626c79;
  --line: #e2e5e9; --accent: #2563eb; --soft: #f3f5f7;
  --radius: 12px; --control-radius: 8px; --tap: 44px;
  font: 14px Inter, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
body { margin: 0; background: var(--bg); color: var(--ink); min-height: 100vh; min-height: 100dvh; display: grid; place-items: center; padding: 24px 16px; }
main { width: min(100%, 460px); min-width: 0; }
.card { background: var(--paper); border: 1px solid var(--line); border-radius: 20px; padding: 24px; box-shadow: 0 8px 32px #17243b08; }
button, input { font: inherit; color: inherit; }
button { cursor: pointer; display: inline-flex; align-items: center; justify-content: center; gap: 6px; background: none; border: 0; border-radius: var(--control-radius); padding: 0; transition: color .15s, background-color .15s, border-color .15s; }
button:focus-visible, input:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
button:disabled { cursor: default; opacity: .5; }
.material-icon { display: inline-block; width: 18px; height: 18px; flex: none; background-color: currentColor; mask: center / contain no-repeat; -webkit-mask: center / contain no-repeat; }
.iconbtn { flex: none; width: var(--tap); height: var(--tap); color: var(--muted); }
.iconbtn .material-icon { width: 20px; height: 20px; }
.iconbtn:hover:not(:disabled), .iconbtn[aria-expanded="true"], .source-info:hover { color: var(--ink); }
.iconbtn:focus-visible, .source-info:focus-visible { outline-offset: -5px; }
/* Header */
.card > header { position: relative; display: flex; align-items: center; justify-content: space-between; gap: 4px; margin-bottom: 16px; }
h1 { font-size: 23px; font-weight: 650; letter-spacing: -.65px; line-height: 1.2; margin: 0; }
.header-actions { display: flex; align-items: center; flex: none; }
.header-actions .iconbtn .material-icon { width: 21px; height: 21px; }
/* Currency panels */
.currency { background: var(--soft); border-radius: var(--radius); padding: 14px; min-width: 0; }
.role { display: block; color: var(--muted); font-size: 12px; font-weight: 550; line-height: 1.3; }
.rowtop { display: flex; align-items: center; gap: 4px; }
.choice { flex: 1; min-width: 0; width: 100%; min-height: var(--tap); justify-content: flex-start; text-align: left; gap: 10px; padding: 5px 8px; }
.choice:hover { background: #e8ecf0; }
.option:hover:not(:disabled), .option:focus-visible, .history-entry:hover { background: var(--soft); }
.choice-text { display: flex; flex: 1; flex-direction: column; gap: 2px; min-width: 0; }
.currency-identity { display: flex; align-items: baseline; gap: 6px; min-width: 0; }
.currency-identity .code { flex: none; }
.currency-identity .name::before { content: "·"; margin-right: 6px; }
.code { font-size: 14px; font-weight: 650; line-height: 1.2; }
.name { font-size: 12px; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; line-height: 1.3; }
.choice > .material-icon { width: 22px; height: 22px; color: var(--muted); }
.flagbadge { width: 34px; height: 24px; flex: none; display: grid; place-items: center; color: var(--muted); }
.flagbadge img { display: block; max-width: 100%; max-height: 100%; width: auto; height: auto; border-radius: 2px; box-shadow: 0 0 0 1px #20242b12; }
.flagbadge .material-icon { width: 21px; height: 21px; }
.amountline { display: flex; align-items: center; gap: 4px; min-width: 0; min-height: 58px; margin-top: 4px; padding: 5px 4px 5px 8px; border: 1px solid transparent; border-radius: var(--control-radius); background: transparent; cursor: text; transition: border-color .15s, background-color .15s; }
.amountline:hover { border-color: #d8dde4; }
.amountline:has(.amount:focus) { border-color: var(--accent); box-shadow: 0 0 0 2px #2563eb16; }
.amountline:has(.amount[readonly]), .amount[readonly] { cursor: default; }
.symbol, .amount { color: var(--ink); font-size: clamp(30px, 9vw, 44px); line-height: 1.18; font-weight: 620; letter-spacing: -1.6px; font-variant-numeric: tabular-nums; }
.symbol { flex: none; max-width: 30%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.symbol.long { font-size: clamp(19px, 5vw, 26px); letter-spacing: -.5px; }
.amount { flex: 1; width: 0; min-width: 0; border: 0; background: transparent; padding: 0; outline: none; cursor: text; }
.amount:focus-visible { outline: none; }
.amount::placeholder { color: var(--ink); opacity: 1; }
.amount[readonly], .amount[readonly]::placeholder { color: var(--muted); }
.amountline .copy { margin-left: auto; cursor: pointer; }
.amountline .copy:disabled { cursor: default; }
/* Connected primary currency pair */
.currency-pair { background: var(--soft); border-radius: var(--radius); min-width: 0; }
.currency-pair .currency { background: transparent; border-radius: 0; }
.currency-pair #primary .currency { padding-bottom: 0; }
.currency-pair #secondary .currency { padding-top: 0; }
.swapwrap { display: flex; align-items: center; gap: 8px; padding: 0 22px; height: var(--tap); }
.swapwrap::before, .swapwrap::after { content: ""; flex: 1; height: 1px; background: #dce1e6; }
.swap { width: var(--tap); height: var(--tap); flex: none; color: var(--muted); }
.swap .material-icon { width: 22px; height: 22px; }
.swap:hover { color: var(--ink); }
.swap:focus-visible { outline-offset: -5px; }
.add { width: 100%; min-height: var(--tap); margin-top: 4px; padding: 8px; font-weight: 550; color: var(--muted); }
.add:hover:not(:disabled), .history-clear:hover:not(:disabled) { color: var(--ink); }
.extras { display: grid; gap: 10px; margin-top: 10px; }
.extras:empty { display: none; }
/* Rate information */
.ratebox { border-top: 1px solid var(--line); margin-top: 4px; padding-top: 5px; text-align: center; }
.rateheading { display: flex; justify-content: center; align-items: center; gap: 0; min-height: var(--tap); }
.rate { min-width: 0; font-size: 14px; font-weight: 600; font-variant-numeric: tabular-nums; overflow-wrap: anywhere; }
.refresh { margin-right: -8px; }
.refresh.is-loading .material-icon { animation: refresh-spin .8s linear infinite; }
@keyframes refresh-spin { to { transform: rotate(360deg); } }
.source-line, .freshness { display: flex; justify-content: center; align-items: center; flex-wrap: wrap; gap: 3px 5px; font-size: 11px; line-height: 1.6; color: var(--muted); }
.source-line { position: relative; min-height: 24px; }
.source-line a { color: inherit; text-decoration: underline; text-underline-offset: 2px; }
.source-line a:hover, footer a:hover { color: var(--ink); }
.source-info-wrap { display: inline-flex; align-items: center; }
.source-info { width: var(--tap); height: var(--tap); margin: -10px -10px -10px -9px; color: var(--muted); }
.source-info .material-icon { width: 15px; height: 15px; }
/* Shared floating tooltip: same surface as the original rate explanation. */
.tooltip { position: fixed; z-index: 30; width: max-content; max-width: min(268px, calc(100vw - 16px)); text-align: left; font-size: 12px; line-height: 1.5; color: var(--muted); padding: 10px 12px; background: var(--paper); border: 1px solid var(--line); border-radius: var(--control-radius); box-shadow: 0 4px 14px #17243b12; overflow-wrap: anywhere; }
.tooltip[data-long] { width: min(268px, calc(100vw - 16px)); }

.freshness { margin-top: 3px; font-variant-numeric: tabular-nums; }
.notice { color: #996321; font-size: 11px; line-height: 1.5; margin-top: 5px; }
.notice:empty { display: none; }
footer { text-align: center; margin-top: 12px; font-size: 12px; }
footer a { color: #737b87; text-decoration: none; }
/* Picker and history */
dialog { width: min(420px, calc(100% - 24px)); max-height: min(540px, 80dvh); padding: 0; border: 1px solid var(--line); border-radius: var(--radius); box-shadow: 0 18px 60px #11182725; color: var(--ink); background: var(--paper); }
dialog::backdrop { background: #18202e40; }
#picker[open] { display: flex; flex-direction: column; overflow: hidden; }
html:has(#picker[open]) { overflow: hidden; }
.dialoghead { display: flex; align-items: center; justify-content: space-between; padding: 10px 12px 8px 18px; flex: none; }
.dialoghead h2 { font-size: 16px; margin: 0; }
.search { flex: none; margin: 0 16px 10px; display: flex; align-items: center; gap: 9px; background: var(--soft); border: 1px solid var(--line); border-radius: var(--control-radius); padding: 10px; color: var(--muted); }
.search > span { display: flex; }
.search input { min-width: 0; width: 100%; background: none; border: 0; outline: 0; font-size: 16px; }
.search input:focus-visible { outline: 0; }
.search:focus-within { border-color: var(--accent); }
.options { flex: 0 1 auto; min-height: 0; overflow-y: auto; overflow-x: hidden; overscroll-behavior: contain; padding: 0 8px 8px; }
.option { display: flex; width: 100%; min-height: 48px; padding: 9px 10px; text-align: left; justify-content: flex-start; gap: 10px; }
.option:disabled { opacity: 1; color: var(--muted); }
.option:disabled .flagbadge { opacity: .55; }
.option-note { flex: none; font-size: 10px; color: var(--muted); text-align: right; max-width: 76px; }
.option-heading { padding: 10px 10px 5px; color: var(--muted); font-size: 11px; font-weight: 600; }
.option-heading:not(:first-child) { border-top: 1px solid var(--line); margin-top: 6px; padding-top: 12px; }
.empty, .history-empty { padding: 22px 10px; color: var(--muted); text-align: center; font-size: 12px; line-height: 1.6; }
.history-panel { position: absolute; top: calc(100% + 5px); right: 0; z-index: 8; width: min(340px, 100%); max-height: var(--history-height, 380px); display: flex; flex-direction: column; background: var(--paper); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: 0 8px 28px #17243b1a; text-align: left; overflow: hidden; }
.history-head { display: flex; align-items: center; justify-content: space-between; padding: 7px 10px 7px 14px; gap: 8px; border-bottom: 1px solid var(--line); flex: none; }
.history-head h2 { margin: 0; font-size: 13px; font-weight: 650; }
.history-clear { padding: 0 8px; min-height: var(--tap); color: var(--muted); font-size: 12px; }
.history-list { min-height: 0; overflow: auto; overscroll-behavior: contain; padding: 4px; }
.history-entry { display: block; width: 100%; text-align: left; padding: 10px; border-radius: var(--control-radius); min-height: 60px; }
.history-entry:focus-visible { outline-offset: -2px; }
.history-entry + .history-entry { border-top: 1px solid var(--line); }
.history-meta { display: flex; justify-content: space-between; align-items: baseline; gap: 8px; font-size: 11px; color: var(--muted); margin-bottom: 5px; }
.history-meta time { white-space: nowrap; font-size: 10px; }
.history-amounts { display: flex; align-items: center; flex-wrap: wrap; gap: 5px; font-size: 13px; font-weight: 600; font-variant-numeric: tabular-nums; overflow-wrap: anywhere; }
.history-amounts span { min-width: 0; }
.history-amounts .material-icon { width: 15px; height: 15px; color: var(--muted); }
.history-foot { border-top: 1px solid var(--line); padding: 9px 12px; font-size: 10px; color: var(--muted); line-height: 1.5; flex: none; }
/* Feedback and responsive behavior */
html, .options, .history-list { scrollbar-width: thin; scrollbar-color: #cbd1d8 transparent; }
:is(html, .options, .history-list)::-webkit-scrollbar { width: 6px; height: 6px; }
:is(html, .options, .history-list)::-webkit-scrollbar-track { background: transparent; }
:is(html, .options, .history-list)::-webkit-scrollbar-thumb { background: #cbd1d8; border-radius: 10px; }
:is(html, .options, .history-list)::-webkit-scrollbar-thumb:hover { background: #a8b1bc; }
:is(html, .options, .history-list)::-webkit-scrollbar-button { display: none; }
.toast { position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%); background: #252a32; color: #fff; padding: 10px 16px; border-radius: var(--control-radius); box-shadow: 0 5px 20px #0002; opacity: 0; pointer-events: none; transition: opacity .15s; z-index: 10; max-width: calc(100% - 24px); text-align: center; }
.toast.show { opacity: 1; }
@media (max-width: 420px) {
  body { padding: 12px; }
  .card { padding: 16px 12px; border-radius: 16px; }
  .card > header { margin-bottom: 12px; }
  h1 { font-size: clamp(18px, 5.2vw, 23px); }
  .currency { padding: 10px; }
  .amountline { min-height: 52px; }
  .symbol, .amount { font-size: clamp(30px, 10vw, 40px); }
  footer { margin-top: 9px; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { transition: none !important; }
  .refresh.is-loading .material-icon { animation: none; }
}
