:root {
  --paper: #efeae1;
  --ink: #1b1a17;
  --muted: #5c574f;
  --line: #d5cec2;
  --tray: #2a3340;
  --cream: #f4efe6;
  --white: #fffcf7;
  --seal: #8e2f28;
  --font: "Figtree", "Avenir Next", "Segoe UI", sans-serif;
  --serif: "Fraunces", "Iowan Old Style", Palatino, serif;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  min-height: 100vh;
  color: var(--ink);
  background:
    radial-gradient(900px 420px at 0% -10%, #f7f3eb 0%, transparent 55%),
    var(--paper);
  font-family: var(--font);
  font-size: 16px;
  line-height: 1.45;
}

.top {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  justify-content: space-between;
  gap: 12px 24px;
  padding: 28px 28px 8px;
}

.display-field {
  margin-left: auto;
  align-items: flex-end;
}

.eyebrow {
  margin: 0 0 4px;
  color: var(--seal);
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.14em;
  text-transform: uppercase;
}

h1 {
  margin: 0;
  font-family: var(--serif);
  font-size: 40px;
  font-weight: 600;
  letter-spacing: -0.03em;
  line-height: 1;
}

.controls {
  display: flex;
  flex-wrap: wrap;
  gap: 16px 18px;
  align-items: end;
  padding: 18px 28px 0;
}

.field {
  display: flex;
  flex-direction: column;
  gap: 6px;
  min-width: 0;
}

.field > span {
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

select,
.amount-box,
.modes button {
  height: 46px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--white);
  color: var(--ink);
  font-family: var(--font);
  font-size: 16px;
}

select {
  min-width: 220px;
  padding: 0 12px;
}

.amount-box {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 220px;
  padding: 0 12px;
}

.symbol {
  color: var(--seal);
  font-family: var(--serif);
  font-size: 22px;
  font-weight: 600;
  line-height: 1;
}

.amount-box input {
  width: 140px;
  border: 0;
  background: transparent;
  color: var(--ink);
  font-family: var(--serif);
  font-size: 28px;
  font-variant-numeric: tabular-nums;
  font-weight: 600;
  outline: none;
}

.amount-box input::placeholder {
  color: #b3ab9f;
}

.modes {
  display: flex;
  gap: 6px;
}

.modes button {
  padding: 0 14px;
  cursor: pointer;
}

.modes button[aria-checked="true"] {
  border-color: var(--tray);
  background: var(--tray);
  color: var(--cream);
}

.hint,
.rate,
.line,
.scale-note {
  margin: 8px 28px 0;
  color: var(--muted);
  font-size: 14px;
}

.summary {
  margin: 22px 28px 0;
  font-family: var(--serif);
  font-size: 28px;
  font-weight: 600;
  letter-spacing: -0.02em;
  line-height: 1.2;
}

.line {
  min-height: 1.45em;
  color: var(--ink);
}

.tray {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  gap: 26px 28px;
  margin: 18px 20px 0;
  padding: 32px 28px 26px;
  overflow-x: auto;
  border-radius: 16px;
  background: var(--tray);
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.05);
}

.empty {
  margin: 12px 0 28px;
  color: var(--cream);
  font-size: 16px;
}

.piece {
  display: flex;
  flex: 0 0 auto;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  margin: 0;
}

.copies {
  position: relative;
  display: flex;
  flex-wrap: nowrap;
  gap: 10px;
  align-items: flex-end;
}

.art-stack {
  display: flex;
  flex: 0 0 auto;
  flex-direction: column;
  align-items: flex-end;
  gap: 6px;
}

.art {
  position: relative;
  display: grid;
  place-items: center;
  flex: 0 0 auto;
  perspective: 900px;
}

.art.can-flip {
  cursor: pointer;
}

.tools {
  display: flex;
  gap: 2px;
  padding: 3px;
  border-radius: 10px;
  background: var(--cream);
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.32);
}

.tool {
  display: grid;
  place-items: center;
  width: 28px;
  height: 28px;
  padding: 0;
  border: 0;
  border-radius: 7px;
  background: transparent;
  color: var(--ink);
  cursor: pointer;
}

.tool svg {
  width: 16px;
  height: 16px;
  display: block;
}

.tool:hover:not(:disabled),
.tool:focus-visible:not(:disabled) {
  background: #e4ddd2;
  color: var(--ink);
}

.tool:focus-visible {
  outline: 2px solid var(--seal);
  outline-offset: 1px;
}

.tool:disabled {
  background: #d9d3c8;
  color: #7a746a;
  cursor: default;
}

.flip {
  display: grid;
  width: 100%;
  height: 100%;
  transform-style: preserve-3d;
  transition: transform 0.55s cubic-bezier(0.2, 0.7, 0.2, 1);
}

.art.is-flipped .flip {
  transform: rotateY(180deg);
}

.face {
  grid-area: 1 / 1;
  width: 100%;
  height: 100%;
  object-fit: contain;
  backface-visibility: hidden;
  filter: drop-shadow(0 10px 12px rgba(0, 0, 0, 0.38));
}

.face.back {
  transform: rotateY(180deg);
}

@media (prefers-reduced-motion: reduce) {
  .flip {
    transition: none;
  }
}

.missing-label {
  grid-area: 1 / 1;
  display: grid;
  place-items: center;
  padding: 8px;
  color: var(--cream);
  font-family: var(--serif);
  font-size: 18px;
  text-align: center;
}

.art.is-missing {
  border: 1px dashed rgba(244, 239, 230, 0.45);
  border-radius: 4px;
  color: var(--cream);
  font-family: var(--serif);
  font-size: 18px;
  text-align: center;
}

.art.coin.is-missing {
  border-radius: 50%;
}

.badge {
  position: absolute;
  top: -10px;
  left: -10px;
  padding: 3px 8px;
  border-radius: 999px;
  background: var(--cream);
  color: var(--ink);
  font-size: 13px;
  font-weight: 700;
}

body.lightbox-open {
  overflow: hidden;
}

.lightbox {
  position: fixed;
  inset: 0;
  z-index: 30;
  display: grid;
  place-items: center;
  padding: 24px;
}

.lightbox[hidden] {
  display: none;
}

.lightbox-backdrop {
  position: absolute;
  inset: 0;
  margin: 0;
  padding: 0;
  border: 0;
  background: rgba(16, 18, 22, 0.9);
  color: transparent;
  cursor: pointer;
}

.lightbox-frame {
  position: relative;
  z-index: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 16px;
  max-width: 100%;
  max-height: 100%;
}

.lightbox .tools {
  padding: 4px;
  border-radius: 12px;
}

.lightbox .tool {
  width: 36px;
  height: 36px;
  border-radius: 8px;
}

.lightbox .tool svg {
  width: 18px;
  height: 18px;
}

.lightbox-name {
  margin: 0;
  color: var(--cream);
  font-size: 18px;
  font-weight: 700;
}

figcaption {
  display: flex;
  flex-direction: column;
  gap: 2px;
  width: 100%;
  height: 4.6em;
  color: var(--cream);
  text-align: center;
}

.name {
  font-size: 14px;
  font-weight: 700;
}

.meta {
  color: rgba(244, 239, 230, 0.72);
  font-size: 12px;
}

.scale-block {
  padding: 18px 28px 36px;
}

.ruler-row {
  margin-bottom: 8px;
}

.ruler {
  position: relative;
  height: 14px;
  border-bottom: 2px solid var(--ink);
  border-left: 2px solid var(--ink);
  border-right: 2px solid var(--ink);
}

.ruler span {
  position: absolute;
  top: 14px;
  left: 0;
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}

.scale-note {
  margin: 22px 0 0;
}

.sources {
  margin: 0 28px 40px;
  color: var(--muted);
  font-size: 13px;
}

.sources summary {
  cursor: pointer;
  font-weight: 700;
}

.sources ul {
  margin: 10px 0 0;
  padding-left: 18px;
}

.sources a {
  color: var(--ink);
}

@media (max-width: 720px) {
  h1 { font-size: 32px; }
  .summary { font-size: 22px; }
  select,
  .amount-box { min-width: 0; width: 100%; }
  .controls .field { width: 100%; }
  .amount-box input { width: 100%; }
}
