:root {
  --paper: #f3ebdd;
  --paper-deep: #eae0cd;
  --ink: #211b14;
  --ink-soft: #5c5142;
  --ink-faint: #8a7d68;
  --rule: #cbbfa6;
  --oxblood: #9d2f24;
  --oxblood-deep: #7a231a;
  --green: #2e6b45;
  --gold: #b5852f;
  --shadow: rgba(33, 27, 20, 0.16);
  --serif: "Fraunces", Georgia, serif;
  --mono: "Space Mono", "Courier New", monospace;
}

* { box-sizing: border-box; }

html, body { margin: 0; padding: 0; }

body {
  background:
    radial-gradient(120% 90% at 80% -10%, #f8f2e6 0%, transparent 55%),
    radial-gradient(100% 80% at -10% 110%, #efe5d2 0%, transparent 50%),
    var(--paper);
  color: var(--ink);
  font-family: var(--serif);
  font-optical-sizing: auto;
  line-height: 1.5;
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
}

/* Paper grain overlay */
.grain {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 9;
  opacity: 0.5;
  mix-blend-mode: multiply;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='160' height='160'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.85' numOctaves='3' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)' opacity='0.45'/%3E%3C/svg%3E");
}

.sheet {
  max-width: 1080px;
  margin: 0 auto;
  padding: 48px 28px 40px;
  position: relative;
  z-index: 1;
}

/* ---------- Masthead ---------- */
.masthead { text-align: center; }
.masthead__rule {
  height: 0;
  border-top: 2px solid var(--ink);
  border-bottom: 1px solid var(--ink);
  padding-top: 3px;
}
.masthead__kicker {
  font-family: var(--mono);
  text-transform: uppercase;
  letter-spacing: 0.32em;
  font-size: 11px;
  color: var(--ink-soft);
  margin: 14px 0 6px;
}
.masthead__title {
  font-weight: 900;
  font-size: clamp(2.8rem, 8vw, 5.4rem);
  line-height: 0.92;
  letter-spacing: -0.02em;
  margin: 4px 0 10px;
  font-variation-settings: "opsz" 144;
}
.masthead__sub {
  font-size: clamp(1rem, 2.4vw, 1.22rem);
  color: var(--ink-soft);
  font-style: italic;
  font-weight: 500;
  max-width: 40ch;
  margin: 0 auto 16px;
}
.masthead__sub em { color: var(--oxblood); font-style: italic; }

/* ---------- Console layout ---------- */
.console {
  display: grid;
  grid-template-columns: 0.9fr 1.1fr;
  gap: 0;
  margin-top: 30px;
  border: 1.5px solid var(--ink);
  background: rgba(255, 252, 245, 0.45);
  box-shadow: 14px 16px 0 -2px var(--shadow);
}

.panel { padding: 30px 30px 34px; }
.panel:first-child { border-right: 1.5px solid var(--ink); }

/* ---------- Fields ---------- */
.field { margin-bottom: 22px; position: relative; }
.field__label {
  display: block;
  font-family: var(--mono);
  text-transform: uppercase;
  letter-spacing: 0.18em;
  font-size: 10.5px;
  color: var(--ink-soft);
  margin-bottom: 8px;
}
.field__input {
  width: 100%;
  background: var(--paper);
  border: 1.5px solid var(--ink);
  color: var(--ink);
  font-family: var(--mono);
  font-size: 16px;
  padding: 13px 14px;
  border-radius: 0;
  outline: none;
  transition: box-shadow 0.15s, border-color 0.15s;
}
.field__input:focus { box-shadow: 4px 4px 0 0 var(--oxblood); }
.field__input::placeholder { color: var(--ink-faint); }
.field__hint {
  font-size: 12.5px;
  font-style: italic;
  color: var(--ink-faint);
  margin: 7px 2px 0;
}

/* Year combobox: looks like the country selector, with a chevron affordance */
.combo--year { position: relative; }
.combo--year::after {
  content: "";
  position: absolute;
  top: 21px;
  right: 14px;
  width: 12px;
  height: 8px;
  pointer-events: none;
  background: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8'%3E%3Cpath d='M1 1l5 5 5-5' stroke='%23211b14' stroke-width='1.6' fill='none'/%3E%3C/svg%3E") no-repeat center;
}
.field__input--year { padding-right: 34px; cursor: pointer; }
.field__input--year:disabled { opacity: 0.45; cursor: not-allowed; }
.combo--year .combo__list li { justify-content: flex-start; }

/* Amount with currency prefix */
.amount-wrap { display: flex; align-items: stretch; }
.amount-wrap__symbol {
  display: flex;
  align-items: center;
  justify-content: center;
  flex: 0 0 auto;
  min-width: 54px;
  padding: 0 12px;
  background: var(--ink);
  color: var(--paper);
  /* System UI fonts carry the widest, most legible currency-glyph coverage
     (₹ ฿ ₫ ﷼ د.إ etc.); Fraunces lacks many of them. */
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  font-weight: 600;
  font-size: 20px;
  line-height: 1;
  white-space: nowrap;
  border: 1.5px solid var(--ink);
  border-right: none;
}
/* Longer/multi-character symbols (kr, RM, R$, lei, د.إ, ﷼…) shrink to stay readable */
.amount-wrap__symbol--md { font-size: 16px; }
.amount-wrap__symbol--long { font-size: 13px; letter-spacing: 0.01em; }
.field__input--amount { font-size: 20px; font-weight: 700; }

.field-row {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: end;
  gap: 10px;
}
.years-arrow {
  font-family: var(--mono);
  font-size: 22px;
  color: var(--oxblood);
  padding-bottom: 11px;
}

/* ---------- Combobox ---------- */
.combo { position: relative; }
.combo__list {
  position: absolute;
  top: calc(100% + 4px);
  left: 0;
  right: 0;
  margin: 0;
  padding: 0;
  list-style: none;
  max-height: 264px;
  overflow-y: auto;
  background: var(--paper);
  border: 1.5px solid var(--ink);
  box-shadow: 6px 7px 0 -1px var(--shadow);
  z-index: 20;
}
.combo__list li {
  padding: 10px 14px;
  font-size: 15px;
  cursor: pointer;
  border-bottom: 1px solid var(--rule);
  display: flex;
  justify-content: space-between;
  gap: 12px;
}
.combo__list li:last-child { border-bottom: none; }
.combo__list li .iso {
  font-family: var(--mono);
  font-size: 11px;
  color: var(--ink-faint);
  align-self: center;
}
.combo__list li[aria-selected="true"],
.combo__list li:hover { background: var(--ink); color: var(--paper); }
.combo__list li[aria-selected="true"] .iso,
.combo__list li:hover .iso { color: var(--gold); }
.combo__list .combo__none {
  cursor: default;
  font-style: italic;
  color: var(--ink-faint);
  justify-content: flex-start;
}
.combo__list .combo__none:hover { background: var(--paper); color: var(--ink-faint); }

/* ---------- Calculate button ---------- */
.calc-btn {
  width: 100%;
  margin-top: 6px;
  background: var(--oxblood);
  color: #fdf6e9;
  border: 1.5px solid var(--ink);
  font-family: var(--mono);
  text-transform: uppercase;
  letter-spacing: 0.16em;
  font-size: 13px;
  font-weight: 700;
  padding: 15px;
  cursor: pointer;
  box-shadow: 5px 5px 0 0 var(--ink);
  transition: transform 0.08s, box-shadow 0.08s, background 0.15s;
}
.calc-btn:hover:not(:disabled) { background: var(--oxblood-deep); }
.calc-btn:active:not(:disabled) { transform: translate(5px, 5px); box-shadow: 0 0 0 0 var(--ink); }
.calc-btn:disabled { opacity: 0.4; cursor: not-allowed; box-shadow: 3px 3px 0 0 var(--ink); }

.form-msg {
  font-family: var(--mono);
  font-size: 12px;
  color: var(--oxblood-deep);
  margin: 12px 2px 0;
  min-height: 1em;
}
.form-msg.loading { color: var(--ink-soft); }

/* ---------- Result panel ---------- */
.panel--result {
  background:
    repeating-linear-gradient(var(--paper-deep) 0 1px, transparent 1px 32px);
  background-position: 0 8px;
}
.result-empty {
  height: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  color: var(--ink-faint);
  min-height: 360px;
}
.result-empty__mark {
  font-size: 76px;
  color: var(--rule);
  line-height: 1;
  margin-bottom: 14px;
}
.result-empty p { font-style: italic; max-width: 26ch; font-size: 1.05rem; }

.result { animation: rise 0.5s cubic-bezier(0.2, 0.8, 0.2, 1) both; }
@keyframes rise { from { opacity: 0; transform: translateY(14px); } }

.result__lede {
  font-family: var(--mono);
  text-transform: uppercase;
  letter-spacing: 0.16em;
  font-size: 11px;
  color: var(--ink-soft);
  margin: 0 0 12px;
}
.result__headline {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: 8px 12px;
  margin-bottom: 8px;
}
.result__from {
  font-family: var(--mono);
  font-size: clamp(1.3rem, 3.4vw, 1.7rem);
  font-weight: 700;
  color: var(--ink-soft);
  text-decoration: line-through;
  text-decoration-color: var(--oxblood);
  text-decoration-thickness: 2px;
}
.result__became { font-style: italic; color: var(--ink-faint); font-size: 1.1rem; }
.result__to {
  font-family: var(--mono);
  font-size: clamp(2rem, 6vw, 3rem);
  font-weight: 700;
  letter-spacing: -0.01em;
  color: var(--oxblood);
  line-height: 1.05;
}

/* Deflation: prices fell, money gained value — signal it in green */
.result.is-deflation .result__to { color: var(--green); }
.result.is-deflation .result__from { text-decoration-color: var(--green); }

.result__stats {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 0;
  margin: 24px 0 22px;
  border-top: 1.5px solid var(--ink);
  border-bottom: 1.5px solid var(--ink);
}
.stat {
  padding: 14px 10px;
  text-align: center;
}
.stat + .stat { border-left: 1px solid var(--rule); }
.stat__num {
  display: block;
  font-family: var(--mono);
  font-weight: 700;
  font-size: clamp(1.05rem, 3vw, 1.4rem);
  color: var(--ink);
}
.stat__label {
  display: block;
  font-size: 10.5px;
  font-family: var(--mono);
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--ink-faint);
  margin-top: 6px;
  line-height: 1.3;
}

.chart-frame {
  border: 1.5px solid var(--ink);
  background: var(--paper);
  padding: 14px 12px 8px;
  margin-bottom: 16px;
}
.result__foot {
  font-size: 13px;
  font-style: italic;
  color: var(--ink-soft);
  margin: 0;
}

/* ---------- Colophon ---------- */
.colophon {
  display: flex;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 22px;
  padding-top: 12px;
  border-top: 1px solid var(--rule);
  font-family: var(--mono);
  font-size: 11px;
  color: var(--ink-faint);
}

/* ---------- Responsive ---------- */
@media (max-width: 760px) {
  .console { grid-template-columns: 1fr; }
  .panel:first-child { border-right: none; border-bottom: 1.5px solid var(--ink); }
  .sheet { padding: 32px 18px 32px; }
  .result-empty { min-height: 220px; }
}
