:root {
  color-scheme: dark;
  --bg: #131313;
  --surface: #1c1c1c;
  --card: #242424;
  --line: #383835;
  --control-line: #5a5a54;
  --text: #f5f5f5;
  --muted: #b5b5b0;
  --gold: #d4af37;
  --display: "Unbounded", Arial, sans-serif;
  --sans: "Inter", Arial, sans-serif;
}

*, *::before, *::after { box-sizing: border-box; }

html { scroll-padding-top: 1rem; }

body {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 1rem/1.5 var(--sans);
}

[hidden] { display: none !important; }

h1, h2, h3, p { margin: 0; }
h1, h2 { font-family: var(--display); font-weight: 500; }
a { color: inherit; text-decoration: none; }
button, input, select { font: inherit; }
button, select, input[type="date"]::-webkit-calendar-picker-indicator { cursor: pointer; }

:focus-visible { outline: 2px solid var(--gold); outline-offset: 3px; }
:disabled { opacity: .55; cursor: default; }

.sr-only, .skip:not(:focus) {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
}

.skip:focus {
  z-index: 1;
  position: absolute;
  left: 1rem;
  top: 1rem;
  padding: .5rem 1rem;
  background: var(--gold);
  color: var(--bg);
  border-radius: 9px;
}

.wrap { width: min(1120px, calc(100% - 64px)); margin-inline: auto; }

.site-header { border-bottom: 1px solid var(--line); }

.header-inner, .footer-inner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
}

.header-inner { min-height: 72px; }

.brand {
  display: inline-flex;
  align-items: center;
  gap: .75rem;
  font: 500 .8125rem/1.25 var(--display);
  letter-spacing: -.045em;
}

.brand-mark {
  display: grid;
  place-items: center;
  width: 34px;
  height: 34px;
  color: var(--gold);
  border: 1px solid #685824;
  border-radius: 50%;
  font-weight: 600;
}

nav { display: flex; gap: 1.75rem; }
nav a, .footer-inner a { color: var(--muted); font-size: .875rem; }
nav a:hover, .footer-inner a:hover, .brand:hover { color: var(--gold); }

main { flex: 1; padding-bottom: 3.5rem; }

.intro {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 202px;
  align-items: end;
  gap: 1.5rem;
  padding-block: 3.625rem 2.25rem;
}

h1 {
  font-size: clamp(1.75rem, 4.2vw, 3.5rem);
  line-height: 1.15;
  letter-spacing: -.075em;
  overflow-wrap: anywhere;
}

h1 span { color: var(--gold); }
.intro p { margin-top: .875rem; color: var(--muted); }

label, .result-label {
  display: block;
  color: var(--muted);
  font-size: .875rem;
  font-weight: 500;
}

label > span, .date-control label { display: block; margin-bottom: .5rem; }

input:not([type="checkbox"]), select {
  width: 100%;
  min-width: 0;
  min-height: 46px;
  padding: .625rem .75rem;
  color: var(--text);
  background: var(--bg);
  border: 1px solid var(--control-line);
  border-radius: 10px;
  font-variant-numeric: tabular-nums;
}

select {
  appearance: none;
  padding-right: 2rem;
  text-overflow: ellipsis;
  background: var(--bg) url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8' viewBox='0 0 12 8'%3E%3Cpath d='m1 1 5 5 5-5' fill='none' stroke='%23b5b5b0' stroke-width='1.5' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E") no-repeat right .75rem center;
}

input[aria-invalid="true"] { border-color: #efad94; }

.panel {
  padding: 1.625rem;
  border: 1px solid var(--line);
  border-radius: 18px;
  background: var(--surface);
}

.panel + .panel { margin-top: 1rem; }

.panel-heading, .dialog-heading {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 1rem;
  margin-bottom: 1.25rem;
}

h2 { font-size: clamp(1.1rem, 2.25vw, 1.5rem); line-height: 1.35; letter-spacing: -.055em; }
.status { margin-top: .35rem; color: var(--muted); font-size: .875rem; }
.status[data-error], .error { color: #efad94; }

.button {
  display: inline-flex;
  justify-content: center;
  align-items: center;
  gap: .5rem;
  min-height: 44px;
  padding: .5rem .875rem;
  color: var(--text);
  background: var(--bg);
  border: 1px solid var(--control-line);
  border-radius: 9px;
  font-size: .875rem;
  font-weight: 600;
  white-space: nowrap;
}

.button:hover:enabled { border-color: var(--gold); color: var(--gold); }
.choose-button svg { color: var(--gold); }
.retry { margin-top: 1rem; }

.rates-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: .75rem;
}

.rate-card {
  min-width: 0;
  padding: 1rem;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 12px;
}

.rate-name {
  display: flex;
  align-items: center;
  gap: .625rem;
  min-height: 2rem;
  color: var(--muted);
  font-size: .875rem;
  line-height: 1.3;
}

.rate-code {
  flex: none;
  display: grid;
  place-items: center;
  min-width: 2.625rem;
  min-height: 1.875rem;
  padding-inline: .3rem;
  border: 1px solid #685824;
  border-radius: 7px;
  color: var(--gold);
  background: #2d281c;
  font-weight: 600;
}

.rate-value {
  margin-top: .875rem;
  font-size: clamp(1.25rem, 2.5vw, 1.875rem);
  line-height: 1.15;
  letter-spacing: -.04em;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  overflow-wrap: anywhere;
}

.rate-value small { color: var(--muted); font-size: .65em; }
.rate-unit { margin-top: .35rem; color: var(--muted); font-size: .875rem; }

.converter-layout {
  display: grid;
  grid-template-columns: minmax(0, 3fr) minmax(0, 2fr);
  align-items: stretch;
  gap: 1.25rem;
}

.amount-field { margin-bottom: .9rem; }

.currency-fields {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto minmax(0, 1fr);
  align-items: end;
  gap: .625rem;
}

.swap { width: 46px; height: 46px; padding: 0; }
.error { margin-top: .625rem; font-size: .875rem; }

.result {
  display: grid;
  align-content: center;
  gap: .45rem;
  min-height: 147px;
  padding: 1.125rem 1.25rem;
  border: 1px solid #685824;
  border-radius: 12px;
  background: linear-gradient(120deg, #302919, #28251e 70%);
}

.result-value { display: flex; flex-wrap: wrap; align-items: baseline; gap: .2rem .6rem; color: var(--gold); }
#result-amount {
  min-width: 0;
  overflow-wrap: anywhere;
  font: 500 clamp(1.5rem, 3.1vw, 2.375rem)/1.25 var(--display);
  letter-spacing: -.06em;
  font-variant-numeric: tabular-nums;
}
#result-currency { font-weight: 600; }
#result-rate { color: var(--muted); font-size: .875rem; overflow-wrap: anywhere; }

.site-footer { border-top: 1px solid var(--line); }
.footer-inner { min-height: 68px; padding-block: .75rem; flex-wrap: wrap; }

dialog {
  width: min(580px, calc(100% - 32px));
  max-height: calc(100% - 32px);
  padding: 1.25rem;
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 18px;
}

dialog::backdrop { background: rgb(0 0 0 / 72%); }
dialog form { display: flex; flex-direction: column; max-height: calc(100dvh - 80px); }
.close-button { min-width: 44px; padding: 0; font-size: 1.5rem; font-weight: 400; }

fieldset {
  min-width: 0;
  margin: 0;
  padding: .25rem;
  overflow-y: auto;
  border: 0;
}

.currency-option {
  display: flex;
  align-items: center;
  gap: .75rem;
  min-height: 44px;
  padding: .45rem .5rem;
  color: var(--text);
  border-bottom: 1px solid var(--line);
  cursor: pointer;
}

.currency-option:hover { background: var(--card); }
.currency-option input { flex: none; width: 1rem; height: 1rem; margin: 0; accent-color: var(--gold); }
.currency-option span { margin: 0; }
.dialog-actions { display: flex; justify-content: end; margin-top: 1rem; }
.primary, .primary:hover:enabled { color: var(--bg); background: var(--gold); border-color: var(--gold); }
.primary:hover:enabled { filter: brightness(1.12); }

@media (max-width: 900px) {
  .wrap { width: calc(100% - 48px); }
  .intro { padding-top: 2.75rem; }
  .rates-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

@media (max-width: 680px) {
  .wrap { width: calc(100% - 36px); }
  nav { display: none; }
  .intro { grid-template-columns: minmax(0, 1fr); gap: 1.25rem; padding-block: 2.25rem 1.5rem; }
  h1 { font-size: clamp(1.75rem, 7.1vw, 2.75rem); }
  .date-control { max-width: 18rem; }
  .panel { padding: 1rem; }
  .panel-heading { gap: .75rem; }
  .converter-layout { grid-template-columns: minmax(0, 1fr); }
  .result { min-height: 120px; }
  main { padding-bottom: 2rem; }
}

@media (max-width: 460px) {
  .panel-heading { align-items: start; flex-direction: column; }
  .rate-card { padding: .75rem; }
  .rate-name { align-items: start; flex-direction: column; gap: .35rem; }
  .currency-fields { grid-template-columns: minmax(0, 1fr) 46px; }
  .currency-fields label:last-child { grid-column: 1; grid-row: 2; }
  .swap { grid-column: 2; grid-row: 1 / span 2; align-self: center; }
  .swap svg { transform: rotate(90deg); }
  .footer-inner { gap: .4rem 1rem; }
}
