* { box-sizing: border-box; }

:root {
    color-scheme: light;
    --bg: #f1efe9;
    --panel: #fffefa;
    --ink: #202a27;
    --muted: #6f766f;
    --line: #e3e0d7;
    --gold: #947340;
    --accent: #24473b;
    --soft: #eef1eb;
    --shadow: 0 18px 70px #302c2110;
    --scrollbar-thumb: #758073;
    --scrollbar-track: #eeece4;
}
:root[data-theme=dark] {
    color-scheme: dark;
    --bg: #141918;
    --panel: #202725;
    --ink: #f4f0e7;
    --muted: #a6aea5;
    --line: #363f3a;
    --gold: #d0b47e;
    --accent: #c1d7c8;
    --soft: #303d35;
    --shadow: 0 16px 60px #0002;
    --scrollbar-thumb: #828f83;
    --scrollbar-track: #242c27;
}

* {
    scrollbar-width: thin;
    scrollbar-color: var(--scrollbar-thumb) var(--scrollbar-track);
}
@supports selector(::-webkit-scrollbar) {
    * { scrollbar-width: auto; scrollbar-color: auto; }
}
::-webkit-scrollbar { width: 9px; height: 9px; }
::-webkit-scrollbar-track { background: var(--scrollbar-track); border-radius: 10px; }
::-webkit-scrollbar-thumb {
    border: 2px solid var(--scrollbar-track);
    border-radius: 10px;
    background: var(--scrollbar-thumb);
}
::-webkit-scrollbar-thumb:hover { background: var(--accent); }

body {
    margin: 0;
    background: var(--bg);
    color: var(--ink);
    font: 14px system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}
button, input { font: inherit; color: inherit; }
button { cursor: pointer; }
button:disabled { cursor: default; }
button:focus-visible, input:focus-visible, a:focus-visible {
    outline: 2px solid var(--gold);
    outline-offset: 2px;
}
.sr-only {
    position: absolute;
    width: 1px;
    height: 1px;
    margin: -1px;
    overflow: hidden;
    clip-path: inset(50%);
    white-space: nowrap;
}
.shell { max-width: 700px; margin: auto; padding: 30px 24px 22px; }
header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    border-bottom: 1px solid var(--line);
    padding-bottom: 22px;
}
.brand {
    display: flex;
    gap: 11px;
    align-items: center;
    text-decoration: none;
    color: var(--ink);
    font-size: 22px;
    letter-spacing: -.9px;
}
.brand b { font-weight: 650; }
.mark {
    display: block;
    width: 43px;
    height: 43px;
    border-radius: 11px;
}
.header-actions { display: flex; align-items: center; gap: 8px; }
.language-control { position: relative; }
.flag { background-position: center; background-size: cover; background-repeat: no-repeat; }
.flag[data-flag=ru] { background-image: url("icons/flags/ru.png?v=9"); }
.flag[data-flag=en] { background-image: url("icons/flags/gb.png?v=9"); }
.flag[data-flag=be] { background-image: url("icons/flags/by.png?v=9"); background-position: left center; }
.flag[data-flag=ka] { background-image: url("icons/flags/ge.png?v=9"); }
#theme, #language {
    -webkit-appearance: none;
    appearance: none;
    width: 40px;
    height: 40px;
    min-width: 40px;
    min-height: 40px;
    padding: 0;
    border: 1px solid var(--line);
    border-radius: 50%;
    background-color: transparent;
}
#theme {
    position: relative;
    flex: 0 0 40px;
}
#theme::before {
    content: "";
    position: absolute;
    top: 50%;
    left: 50%;
    width: 18px;
    height: 18px;
    box-sizing: border-box;
    transform: translate(-50%, -50%);
    border: 1px solid currentColor;
    border-radius: 50%;
    background: linear-gradient(to right, currentColor 50%, transparent 50%);
}
#language { background-position: center; }
#language[data-flag=ru] { background-image: url("icons/languages/ru.png"); }
#language[data-flag=en] { background-image: url("icons/languages/en.png"); }
#language[data-flag=be] { background-image: url("icons/languages/be.png"); }
#language[data-flag=ka] { background-image: url("icons/languages/ka.png"); }
#language, .language-options button { -webkit-tap-highlight-color: transparent; }
.language-options:not([hidden]) {
    position: absolute;
    z-index: 4;
    top: calc(100% + 8px);
    right: 0;
    display: grid;
    min-width: 158px;
    padding: 4px;
    border: 1px solid var(--line);
    border-radius: 10px;
    background: var(--panel);
    box-shadow: 0 10px 24px #0002;
}
.language-options button {
    display: flex;
    align-items: center;
    gap: 8px;
    min-height: 38px;
    padding: 5px 8px;
    border: 0;
    border-radius: 6px;
    background: transparent;
    text-align: left;
}
.language-options button:hover, .language-options button[aria-pressed=true] { background: var(--soft); }
.language-options .flag { width: 23px; height: 17px; border-radius: 3px; border: 1px solid #0003; }
.intro { margin: 30px 0 24px; }
.intro h1 { margin: 0; font: 400 60px/1.05 Georgia, serif; letter-spacing: -3px; }
.intro h1 .title-period { color: var(--gold); }

.panel {
    --row-action-size: 44px;
    --row-action-gap: 8px;
    padding: 23px;
    background: var(--panel);
    border: 1px solid var(--line);
    border-radius: 19px;
    box-shadow: var(--shadow);
}
.head, .source, .tablehead {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 8px;
}
.label, .tablehead {
    color: var(--muted);
    font-size: 10px;
    font-weight: 650;
    letter-spacing: 1.6px;
}
#refresh { padding: 4px; border: 0; background: none; color: var(--accent); font-size: 12px; }
.banks {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 4px;
    padding: 4px;
    margin: 12px 0;
    background: var(--bg);
    border-radius: 10px;
}
.banks button {
    padding: 11px 6px;
    border: 0;
    border-radius: 7px;
    background: transparent;
    color: var(--muted);
    font-weight: 600;
}
.banks button[aria-pressed=true] { background: var(--panel); color: var(--ink); box-shadow: 0 1px 5px #0002; }
.source { margin: 12px 0 20px; color: var(--muted); font-size: 11px; }
.status { flex-shrink: 0; max-width: 52%; text-align: right; }
.tablehead {
    border-bottom: 1px solid var(--line);
    padding: 0 calc((var(--row-action-size) + var(--row-action-gap)) * 2) 10px 32px;
}
.currency {
    position: relative;
    display: grid;
    grid-template-columns: 24px minmax(84px, 1fr) minmax(0, 1.15fr) var(--row-action-size);
    gap: var(--row-action-gap);
    align-items: center;
    padding: 11px 0;
    border-bottom: 1px solid var(--line);
}
.currency.active {
    margin-inline: -8px -5px;
    padding-inline: 8px 5px;
    border-bottom-color: transparent;
    border-radius: 8px;
    background: var(--soft);
}
.currency.moving {
    z-index: 1;
    border-radius: 8px;
    background: var(--soft);
    box-shadow: 0 0 0 1px var(--gold);
}
.identity { display: flex; gap: 9px; align-items: center; min-width: 0; }
.identity-text { display: grid; gap: 3px; min-width: 0; }
.coin {
    display: grid;
    flex: none;
    place-items: center;
    width: 36px;
    height: 36px;
    border: 1px solid var(--line);
    border-radius: 50%;
    background: var(--panel);
    color: var(--gold);
    font: 19px Georgia, serif;
}
.coin-byn::before {
    content: "";
    width: 14px;
    height: 16px;
    background: currentColor;
    -webkit-mask: url("icons/byn.svg") center / contain no-repeat;
    mask: url("icons/byn.svg") center / contain no-repeat;
}
.identity b { font-size: 14px; letter-spacing: .7px; }
.amount-field {
    display: grid;
    grid-template-columns: minmax(0, 1fr) var(--row-action-size);
    align-items: center;
    gap: var(--row-action-gap);
    min-width: 0;
}
.amount {
    width: 100%;
    min-width: 0;
    padding: 6px 0;
    border: 0;
    background: transparent;
    text-align: right;
    font-size: clamp(19px, 4.5vw, 28px);
    font-weight: 500;
    font-variant-numeric: tabular-nums;
    letter-spacing: -.8px;
}
.amount:disabled { opacity: .65; }
.remove, .reorder, .clear-amount {
    min-height: 36px;
    padding: 0;
    border: 0;
    border-radius: 6px;
    background: transparent;
    color: var(--muted);
}
.remove, .clear-amount {
    -webkit-appearance: none;
    appearance: none;
    display: grid;
    place-items: center;
    width: var(--row-action-size);
    height: var(--row-action-size);
    min-height: 0;
    border-radius: 9px;
    line-height: 1;
    touch-action: manipulation;
    -webkit-tap-highlight-color: transparent;
}
.remove { font-size: 24px; }
.clear-amount {
    border: 1px solid var(--line);
    background: var(--bg);
    font-size: 20px;
}
.remove:disabled, .clear-amount:disabled { opacity: .3; }
.reorder {
    display: grid;
    place-items: center;
    touch-action: none;
    cursor: grab;
}
.reorder::before {
    content: "";
    width: 10px;
    height: 15px;
    background: radial-gradient(circle, currentColor 1px, transparent 1.35px) 0 0 / 5px 5px;
}
.currency.moving .reorder { cursor: grabbing; }
.reorder:hover, .reorder[aria-expanded=true], .remove:enabled:hover {
    color: var(--accent);
    background: var(--bg);
}
.clear-amount:enabled:hover, .clear-amount:enabled:active, .remove:enabled:active {
    color: var(--ink);
    background: var(--soft);
}
.move-actions:not([hidden]) {
    position: absolute;
    z-index: 2;
    top: calc(100% - 5px);
    left: 0;
    display: flex;
    gap: 3px;
    padding: 4px;
    border: 1px solid var(--line);
    border-radius: 9px;
    background: var(--panel);
    box-shadow: 0 6px 18px #0002;
}
.move-actions button {
    min-height: 36px;
    padding: 0 9px;
    border: 0;
    border-radius: 6px;
    background: none;
    color: var(--accent);
    font-size: 12px;
    white-space: nowrap;
}
.move-actions button:enabled:hover { background: var(--soft); }
.move-actions button:disabled { color: var(--muted); opacity: .65; }
#add {
    width: 100%;
    padding: 12px;
    margin-top: 14px;
    border: 1px dashed var(--line);
    border-radius: 9px;
    background: transparent;
    color: var(--accent);
    font-size: 12px;
    font-weight: 600;
}
.foot { display: grid; gap: 5px; margin-top: 16px; color: var(--muted); font-size: 10px; font-variant-numeric: tabular-nums; }
#monthly-rate:not([hidden]) { display: grid; gap: 3px; }
footer {
    display: flex;
    justify-content: space-between;
    gap: 10px;
    margin-top: 23px;
    padding-top: 16px;
    border-top: 1px solid var(--line);
    color: var(--muted);
    font-size: 9px;
    letter-spacing: .7px;
}
footer a { color: var(--accent); text-underline-offset: 2px; }

.dialog:not([open]) { display: none; }
.dialog {
    width: min(440px, calc(100% - 28px));
    padding: 23px;
    overflow: hidden;
    border: 1px solid var(--line);
    border-radius: 19px;
    background: var(--panel);
    color: var(--ink);
    box-shadow: 0 24px 90px #0004;
}
#picker { height: min(610px, 82vh); height: min(610px, 82dvh); }
#picker[open] { display: flex; flex-direction: column; gap: 17px; }
.dialog::backdrop { background: #151d19a0; }
.legacy-dialog-open { overflow: hidden; }
.legacy-dialog-open::before {
    content: "";
    position: fixed;
    top: 0;
    right: 0;
    bottom: 0;
    left: 0;
    z-index: 10;
    background: #151d19a0;
}
.legacy-dialog[open] {
    display: block;
    position: fixed;
    top: 50%;
    left: 50%;
    z-index: 11;
    max-height: 82vh;
    margin: 0;
    transform: translate(-50%, -50%);
}
.picker-header { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.dialog h2 { margin: 0; font: 400 29px/1.08 Georgia, serif; letter-spacing: -.6px; }
#remove-dialog { width: min(365px, calc(100% - 28px)); }
#remove-description { margin: 11px 0 23px; color: var(--muted); }
.confirm-actions { display: flex; flex-wrap: wrap; justify-content: flex-end; gap: 8px; }
.confirm-actions button {
    min-height: 44px;
    padding: 0 15px;
    border: 1px solid var(--line);
    border-radius: 8px;
    font-weight: 600;
}
.confirm-cancel { background: var(--bg); color: var(--ink); }
.confirm-cancel:hover { background: var(--soft); }
.confirm-actions .confirm-remove { border-color: transparent; background: #a73931; color: #fff; }
.confirm-actions .confirm-remove:hover { background: #8d2d27; }
.picker-close {
    display: grid;
    place-items: center;
    width: 38px;
    height: 38px;
    padding: 0;
    border: 1px solid var(--line);
    border-radius: 50%;
    background: var(--bg);
    color: var(--muted);
    font-size: 23px;
    line-height: 1;
}
.picker-close:hover { color: var(--ink); }
.picker-search {
    display: flex;
    align-items: center;
    flex: none;
    gap: 8px;
    min-height: 46px;
    padding: 0 11px;
    border: 1px solid var(--line);
    border-radius: 9px;
    background: var(--bg);
}
.picker-search:focus-within { border-color: var(--gold); outline: 1px solid var(--gold); }
.picker-search svg { flex: none; width: 20px; height: 20px; color: var(--accent); }
#search {
    width: 100%;
    min-width: 0;
    min-height: 44px;
    padding: 0;
    border: 0;
    outline: none;
    background: transparent;
    font-size: 16px;
}
#search::placeholder { color: var(--muted); }
#choices {
    flex: 1;
    min-height: 0;
    overflow: auto;
    overscroll-behavior: contain;
    scrollbar-gutter: stable;
    padding-right: 5px;
}
.choice {
    display: grid;
    grid-template-columns: auto minmax(0, 1fr) auto;
    gap: 10px;
    align-items: center;
    width: 100%;
    min-height: 52px;
    padding: 7px 9px;
    border: 0;
    border-bottom: 1px solid var(--line);
    border-radius: 7px;
    background: transparent;
    text-align: left;
}
.choice:last-child { border-bottom-color: transparent; }
.choice:hover, .choice:focus-visible { background: var(--soft); }
.choice:focus-visible { outline-offset: -2px; }
.choice b { letter-spacing: .65px; }
.choice small { color: var(--muted); font-size: 12px; }
.choice-add { padding-inline: 6px; color: var(--accent); font-size: 20px; }
.picker-empty { margin: 0; padding: 18px 8px; color: var(--muted); text-align: center; }

@media (prefers-reduced-motion: no-preference) {
    .dialog[open]:not(.legacy-dialog) { animation: picker-in .15s ease-out; }
    @keyframes picker-in {
        from { opacity: 0; transform: translateY(5px); }
        to { opacity: 1; transform: translateY(0); }
    }
}
@media (max-width: 500px) {
    .shell { padding: 22px 17px 17px; }
    header { padding-bottom: 17px; }
    .intro { margin: 24px 0 18px; }
    .intro h1 { font-size: 49px; }
    .panel { padding: 17px; border-radius: 16px; }
    .tablehead { padding-left: 31px; }
    .currency {
        grid-template-columns: 24px minmax(72px, .85fr) minmax(0, 1.45fr) var(--row-action-size);
        padding-block: 10px;
    }
    .coin { width: 32px; height: 32px; }
    .identity { gap: 7px; }
    .source { margin-bottom: 16px; font-size: 10px; }
    .foot { font-size: 10px; }
    footer { font-size: 8px; }
    .dialog { padding: 18px; border-radius: 16px; }
    #picker[open] { gap: 14px; }
    .dialog h2 { font-size: 26px; }
    .picker-close { width: 42px; height: 42px; }
}
@media (max-width: 370px) {
    .tablehead { padding-right: 0; }
    .currency {
        grid-template-columns: 24px minmax(0, 1fr) var(--row-action-size);
        grid-template-areas: "drag currency currency" ". amount remove";
        row-gap: 2px;
    }
    .currency > .reorder { grid-area: drag; }
    .currency > .identity { grid-area: currency; }
    .currency > .amount-field { grid-area: amount; }
    .currency > .remove { grid-area: remove; }
}
@media (max-width: 500px), (pointer: coarse) {
    .panel { --row-action-size: 48px; }
}
@media (pointer: coarse) {
    .reorder { min-height: 44px; }
    .move-actions button { min-height: 44px; }
    .language-options button { min-height: 44px; }
}
