:root {
  color-scheme: light;
  --ground: #fff;
  --surface: #f4f5f7;
  --selected: #e7e9ed;
  --rule: #dedfe3;
  --ink: #121316;
  --muted: #62656c;
  --accent: #2353cf;
  --focus: #5076db;
  --danger: #d52232;
  --radius: 24px;
  --gutter: clamp(16px, 5vw, 24px);
  --keyboard-offset: 0px;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  -webkit-text-size-adjust: 100%;
}

*, *::before, *::after { box-sizing: border-box; }
[hidden], .symbols { display: none !important; }
.visually-hidden { position: absolute; width: 1px; height: 1px; padding: 0; overflow: hidden; clip-path: inset(50%); white-space: nowrap; }
html { scroll-padding-block: calc(110px + env(safe-area-inset-top)) calc(var(--keyboard-offset) + 60px); }
body { margin: 0; padding-bottom: var(--keyboard-offset); color: var(--ink); background: var(--ground); }
button, input { color: inherit; font: inherit; }
button { cursor: pointer; -webkit-tap-highlight-color: transparent; }
button:disabled { cursor: default; }
button:focus-visible, a:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; }
.icon { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 1.9; stroke-linecap: round; stroke-linejoin: round; flex: none; }

.app {
  width: min(100%, 560px);
  margin-inline: auto;
  padding: calc(16px + env(safe-area-inset-top)) max(var(--gutter), env(safe-area-inset-right))
    calc(18px + env(safe-area-inset-bottom)) max(var(--gutter), env(safe-area-inset-left));
}

.round-button {
  border: 1px solid var(--rule);
  border-radius: 999px;
  background: var(--surface);
  min-height: 44px;
}
.round-button, .icon-button { display: grid; place-items: center; padding: 0; }
.round-button { min-width: 44px; }
.icon-button { min-width: 44px; min-height: 44px; border: 0; border-radius: 50%; background: transparent; }

.base-area {
  position: sticky;
  top: env(safe-area-inset-top);
  z-index: 1;
  background: var(--ground);
  padding: 6px 0 12px;
  margin-top: -6px;
  margin-bottom: 12px;
  border-bottom: 1px solid var(--rule);
}
.base-area::before { content: ''; position: absolute; inset: -10px 0 auto; height: 10px; background: var(--ground); }
.quotes { display: grid; gap: 12px; padding: 0; margin: 0; list-style: none; }
.quote-item { --delete-width: 92px; --swipe-duration: 180ms; position: relative; isolation: isolate; min-width: 0; overflow: hidden; border-radius: var(--radius); }
.quote-item, .quote-item .amount { touch-action: pan-y pinch-zoom; }
.quote-item.is-open { --swipe-rest: calc(-1 * var(--delete-width)); }
.quote-item .currency-row {
  position: relative;
  z-index: 1;
  border-radius: 0;
  transform: translateX(var(--swipe-offset, var(--swipe-rest, 0px)));
  transition: transform var(--swipe-duration) ease;
  -webkit-touch-callout: none;
  user-select: none;
}
.quote-item .amount { -webkit-touch-callout: default; user-select: text; }
.quote-item.is-reordering { opacity: 0; }
.reorder-preview {
  position: fixed;
  z-index: 3;
  inset: 0 auto auto 0;
  pointer-events: none;
  border-radius: var(--radius);
  box-shadow: 0 12px 32px rgb(0 0 0 / 17%);
}
.quote-item.is-dragging .currency-row { transition: none; user-select: none; }
.quote-item .currency-row.is-focused { outline-color: transparent; }
.quote-item .currency-row.is-focused::after {
  content: '';
  position: absolute;
  inset: 0;
  border: 2px solid var(--focus);
  border-radius: var(--radius);
  pointer-events: none;
}
.delete-action {
  position: absolute;
  inset: 0 0 0 auto;
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  gap: 4px;
  width: var(--delete-width);
  padding: 0;
  border: 0;
  color: white;
  background: var(--danger);
  font-size: 13px;
  font-weight: 620;
  opacity: 0;
  transition: opacity 0s var(--swipe-duration);
}
.quote-item:is(.is-open, .is-dragging) .delete-action { opacity: 1; transition: none; }
.delete-action:focus-visible { outline-color: white; outline-offset: -5px; }

/* One full-width row, with shared inset edges for flags and amounts. */
.currency-row {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr);
  align-items: center;
  gap: clamp(7px, 2vw, 12px);
  min-height: 78px;
  padding: 8px clamp(12px, 4vw, 20px);
  border-radius: var(--radius);
  background: var(--surface);
  outline: 2px solid transparent;
  outline-offset: -2px;
  transition: outline-color 140ms ease;
  --amount-size: 22px;
}
.currency-row.is-focused { outline-color: var(--focus); }
.currency-row.is-base { --amount-size: 25px; align-items: end; }
.currency-row.is-base .money { padding-bottom: 2px; }
.base-label { margin: 0; color: var(--muted); font-size: 13px; font-weight: 400; line-height: 1.25; }
.currency-button {
  display: flex;
  align-items: center;
  min-height: 44px;
  gap: 8px;
  padding: 0;
  border: 0;
  border-radius: 10px;
  background: transparent;
  font-size: 16px;
  font-weight: 650;
}
.currency-button:active, .option:active { opacity: 0.65; }
.currency-button .chevron { width: 14px; height: 14px; }
.flag {
  width: 24px;
  height: 24px;
  display: grid;
  place-items: center;
  flex: none;
  border-radius: 50%;
  background-color: var(--selected);
  overflow: hidden;
}
.flag[data-flag] { background-image: url("./assets/flags.webp"); background-size: 1200% var(--flag-height); }
.flag .icon { width: 75%; height: 75%; color: var(--muted); }
.money, .amount-control { min-width: 0; }
.amount-control { display: flex; align-items: center; }
.amount {
  flex: 1 1 0;
  width: 100%;
  min-width: 0;
  height: 35px;
  padding: 0;
  border: 0;
  outline: 0;
  background: transparent;
  text-align: right;
  letter-spacing: -0.035em;
  font-size: clamp(16px, calc(var(--amount-size) - var(--shrink, 0px)), var(--amount-size));
  font-weight: 620;
  font-variant-numeric: tabular-nums lining-nums;
  caret-color: var(--accent);
}
.is-base .amount { height: 40px; }
.amount:disabled { color: var(--muted); opacity: 1; -webkit-text-fill-color: currentColor; }
.unit-rate { display: block; text-align: right; color: var(--muted); font-size: 13px; line-height: 1.25; font-variant-numeric: tabular-nums; }
.clear-amount {
  display: grid;
  place-items: center;
  flex: none;
  padding: 0;
  width: 44px;
  height: 44px;
  border: 0;
  border-radius: 50%;
  background: transparent;
}
.clear-amount { margin: -4.5px -12px -4.5px -6px; }
.is-base .clear-amount { margin-block: -2px; }
.clear-amount span { display: grid; place-items: center; width: 19px; height: 19px; color: white; background: var(--muted); border-radius: 50%; }
.clear-amount .icon { width: 12px; height: 12px; stroke-width: 2.8; }

.add-button {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  min-height: 48px;
  width: 100%;
  margin-top: 8px;
  border: 0;
  border-radius: var(--radius);
  background: transparent;
  font-size: 16px;
  font-weight: 620;
}
.add-button:disabled { color: var(--muted); }
.add-button .icon { width: 18px; height: 18px; }
.rates-info { display: flex; align-items: center; justify-content: center; flex-wrap: wrap; gap: 0 8px; min-height: 44px; color: var(--muted); font-size: 12px; text-align: center; }
.rates-info p { margin: 0; }
.rates-info a { color: inherit; text-underline-offset: 3px; }
.rates-info .icon-button { margin-left: -6px; }
.rates-info .icon { width: 16px; height: 16px; }
.rates-info .icon-button[aria-busy="true"] .icon { animation: spin 1s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

.picker {
  position: fixed;
  inset: auto 0 var(--keyboard-offset);
  width: min(100%, 560px);
  max-width: none;
  max-height: none;
  height: min(760px, calc(90dvh - var(--keyboard-offset)));
  margin: 0 auto;
  padding: 0;
  border: 0;
  border-radius: 16px 16px 0 0;
  color: var(--ink);
  background: var(--surface);
  overflow: hidden;
}
.picker[open], .delete-confirm[open] { animation: open-sheet 200ms ease-out; }
.picker::backdrop, .delete-confirm::backdrop { background: rgb(0 0 0 / 47%); }
@keyframes open-sheet { from { transform: translateY(35px); } }
body:has(dialog[open]) { overflow: hidden; }
.sheet { height: 100%; display: flex; flex-direction: column; padding-inline: max(var(--gutter), env(safe-area-inset-left)) max(var(--gutter), env(safe-area-inset-right)); }
.sheet-header { position: relative; padding-top: 66px; }
.close-picker { position: absolute; right: -8px; top: 15px; }
.close-picker .icon { width: 18px; height: 18px; }
.sheet h2 { margin: 0 0 16px; font-size: clamp(26px, 7.7vw, 32px); line-height: 1.12; letter-spacing: -0.045em; }
.search-field { min-height: 48px; display: flex; align-items: center; gap: 10px; padding: 0 13px; border: 1px solid #d6d8df; border-radius: 10px; color: var(--muted); }
.search-field:focus-within { border-color: var(--focus); outline: 1px solid var(--focus); }
.search-field input { width: 100%; min-height: 44px; padding: 0; font-size: 16px; border: 0; outline: 0; background: transparent; color: var(--ink); }
.search-field input::placeholder { color: var(--muted); opacity: 1; }
.currency-options { flex: 1; overflow: auto; overscroll-behavior: contain; margin: 4px -8px 0; padding: 0 0 max(12px, env(safe-area-inset-bottom)); }
.currency-options h3 { margin: 20px 8px 5px; font-size: 16px; font-weight: 650; letter-spacing: -0.015em; }
.option { display: flex; align-items: center; gap: 12px; width: 100%; min-height: 57px; padding: 8px; text-align: left; font-weight: 560; border: 0; border-radius: 10px; background: transparent; }
.option[aria-current="true"] { background: var(--selected); }
.option:focus-visible { outline-offset: -2px; }
.option .flag { width: 28px; height: 28px; }
.option .option-name { flex: 1; }
.option .check { width: 18px; height: 18px; }
.option-empty { margin: 24px 8px; color: var(--muted); }

.delete-confirm {
  position: fixed;
  inset: auto 0 calc(var(--keyboard-offset) + max(10px, env(safe-area-inset-bottom)));
  width: min(calc(100% - 20px), 430px);
  margin: 0 auto;
  padding: 0;
  border: 0;
  background: transparent;
}
.delete-confirm form { display: grid; gap: 8px; }
.delete-group, .confirm-cancel { border-radius: 16px; background: var(--surface); }
.delete-group { overflow: hidden; }
.delete-group h2 { margin: 0; padding: 17px 12px; color: var(--muted); font-size: 14px; font-weight: 550; text-align: center; }
.delete-confirm button { width: 100%; min-height: 54px; border: 0; font-size: 18px; }
.delete-confirm button:focus-visible { outline-offset: -4px; }
.delete-confirm .confirm-remove { border-top: 1px solid var(--rule); color: var(--danger); background: transparent; }
.confirm-cancel { color: var(--accent); font-weight: 650; }

.keyboard-tools {
  position: fixed;
  z-index: 2;
  left: 50%;
  bottom: calc(var(--keyboard-offset) + 8px);
  display: flex;
  justify-content: flex-end;
  width: min(100%, 560px);
  padding-inline: var(--gutter);
  transform: translateX(-50%);
  pointer-events: none;
}
.done-button { pointer-events: auto; padding: 0 16px; background: var(--ground); color: var(--accent); font-weight: 650; box-shadow: 0 3px 12px rgb(0 0 0 / 11%); }

@media (hover: hover) {
  .icon-button:hover, .add-button:hover { background: var(--surface); }
  .option:hover, .round-button:hover { background: var(--selected); }
}
@media (min-width: 900px) {
  .app { width: min(100%, 900px); padding-top: calc(48px + env(safe-area-inset-top)); }
  .quotes { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .quotes li:last-child:nth-child(odd) { grid-column: 1 / -1; }
}
@media (max-width: 350px) {
  .currency-row { --amount-size: 20px; }
  .currency-row.is-base { --amount-size: 23px; }
  .base-label { font-size: 12px; }
  .unit-rate { font-size: 12px; }
}
@media (max-height: 500px) {
  .sheet-header { padding-top: 45px; }
  .close-picker { top: 5px; }
}
@media (prefers-reduced-motion: reduce) {
  .quote-item { --swipe-duration: 0s; }
  *, *::before, *::after { animation-duration: 0.01ms !important; animation-iteration-count: 1 !important; transition-duration: 0.01ms !important; }
}
