:root {
  color-scheme: dark;
  --bg: #101218;
  --raise: #1a1e28;
  --raise-2: #232836;
  --line: rgba(246, 241, 231, 0.14);
  --text: #f6f1e7;
  --muted: #c8bfb2;
  --gold: #e4b15a;
  --gold-ink: #2a2112;
  --danger: #ffb4a8;
  --shadow: 0 16px 40px rgba(0, 0, 0, 0.28);
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  font-family: "Segoe UI", system-ui, sans-serif;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  min-height: 100vh;
  background:
    radial-gradient(1200px 420px at 50% -80px, rgba(228, 177, 90, 0.16), transparent 60%),
    var(--bg);
  color: var(--text);
}

button,
input,
select { font: inherit; color: inherit; }

button { cursor: pointer; }

.app {
  width: min(480px, 100%);
  margin: 0 auto;
  padding: calc(16px + var(--safe-top)) 16px calc(96px + var(--safe-bottom));
}

.top {
  position: sticky;
  top: 0;
  z-index: 2;
  margin: 0 -16px;
  padding: 0 16px 10px;
  background: var(--bg);
}

.title-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 14px;
}

.house-label { min-width: 0; }

.house {
  max-width: 100%;
  border: 0;
  padding: 0 22px 0 0;
  background-color: transparent;
  background-image:
    linear-gradient(45deg, transparent 50%, var(--gold) 50%),
    linear-gradient(135deg, var(--gold) 50%, transparent 50%);
  background-position: calc(100% - 10px) 55%, calc(100% - 4px) 55%;
  background-size: 6px 6px, 6px 6px;
  background-repeat: no-repeat;
  font-size: 1.7rem;
  font-weight: 650;
  line-height: 1.1;
  appearance: none;
}

.ghost {
  flex: 0 0 auto;
  min-height: 40px;
  padding: 0 14px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: transparent;
}

.ghost:hover,
.chip:hover,
.minus:hover { background: var(--raise-2); }

h2 { margin: 0 0 14px; font-weight: 650; font-size: 1rem; }

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

.status,
.hint,
.empty,
.notes,
.item-meta,
.item-note {
  color: var(--muted);
}

.status {
  margin: 10px 0 0;
  padding: 8px 12px;
  border-radius: 12px;
  background: var(--raise);
}

.worth {
  margin-top: 0;
  padding: 14px 16px;
  border: 1px solid var(--line);
  border-radius: 18px;
  background: rgba(26, 30, 40, 0.92);
  box-shadow: var(--shadow);
}

.worth-label,
.hint,
.form-error,
.empty,
.notes p { margin: 0; }

.worth-label {
  color: var(--muted);
  font-size: 0.78rem;
  letter-spacing: 0.06em;
  text-transform: uppercase;
}

.worth-range {
  margin: 6px 0 0;
  font-size: clamp(1.55rem, 7vw, 2.15rem);
  font-variant-numeric: tabular-nums;
  letter-spacing: -0.03em;
  line-height: 1.15;
  overflow-wrap: anywhere;
}

#form,
.list { scroll-margin-top: 128px; }

.card {
  margin-top: 14px;
  padding: 16px;
  border: 1px solid var(--line);
  border-radius: 18px;
  background: var(--raise);
}

.card.error { color: var(--danger); }

.form-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 14px;
}

.form-head h2 { margin: 0; }

.text-btn {
  min-height: 36px;
  padding: 0 12px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: transparent;
  color: var(--muted);
}

.text-btn:hover { background: var(--raise-2); }

fieldset {
  margin: 0 0 14px;
  padding: 0;
  border: 0;
  min-inline-size: 0;
}

legend {
  margin-bottom: 8px;
  color: var(--muted);
  font-size: 0.75rem;
  letter-spacing: 0.06em;
  text-transform: uppercase;
}

.chips {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.chip {
  min-height: 40px;
  padding: 0 12px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: transparent;
}

.chip {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
}

.counter { display: flex; align-items: center; gap: 4px; }

#rarities .chip,
#add-rarities .chip {
  flex: 1 1 calc(33.33% - 8px);
  max-width: calc(33.33% - 8px);
}

#sizes .chip { min-width: 44px; }

.count { font-variant-numeric: tabular-nums; }

.chip.is-on,
.chip[aria-pressed="true"] {
  background: var(--chip, var(--gold));
  color: var(--chip-ink, var(--gold-ink));
  border-color: transparent;
}

.chip.is-on:hover,
.chip[aria-pressed="true"]:hover { background: var(--chip, var(--gold)); }

.chip.is-selected {
  outline: 2px solid var(--text);
  outline-offset: 2px;
}

.detail { margin: 4px 0 16px; }

.detail h3 { margin: 0 0 8px; font-size: 1rem; }

.detail-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin: 0;
  padding: 0;
  list-style: none;
}

.detail-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 10px 12px;
  border-radius: 12px;
  background: var(--bg);
}

.detail-item p { margin: 0; }

.detail-price { color: #d7f5c8; font-variant-numeric: tabular-nums; }

.exact-total {
  margin: 6px 0 0;
  font-size: 1.35rem;
  font-variant-numeric: tabular-nums;
}

.fab {
  position: fixed;
  z-index: 4;
  left: max(16px, calc(50% - 240px + 16px));
  bottom: calc(16px + var(--safe-bottom));
  width: 56px;
  height: 56px;
  border: 0;
  border-radius: 50%;
  background: var(--gold);
  color: var(--gold-ink);
  font-size: 2rem;
  line-height: 1;
  box-shadow: var(--shadow);
}

.sheet {
  position: fixed;
  z-index: 3;
  left: max(16px, calc(50% - 240px + 16px));
  right: max(16px, calc(50% - 240px + 16px));
  bottom: calc(84px + var(--safe-bottom));
  max-height: min(70vh, 560px);
  overflow: auto;
  margin: 0;
  padding: 16px;
  border: 1px solid var(--line);
  border-radius: 18px;
  background: var(--raise);
  box-shadow: var(--shadow);
}

.sheet fieldset:last-of-type { margin-bottom: 0; }

.minus {
  width: 32px;
  height: 32px;
  padding: 0;
  border: 1px solid var(--line);
  border-radius: 50%;
  background: transparent;
  line-height: 1;
}

.exact { margin-top: 4px; }

.exact .field {
  margin-top: 0;
  color: var(--muted);
  font-size: 0.75rem;
  letter-spacing: 0.06em;
  text-transform: uppercase;
}

.exact input {
  margin-top: 8px;
  font-variant-numeric: tabular-nums;
  font-size: 1.25rem;
}

.field {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-top: 10px;
}

.field span {
  color: var(--muted);
  font-size: 0.75rem;
  letter-spacing: 0.06em;
  text-transform: uppercase;
}

input {
  width: 100%;
  min-height: 48px;
  padding: 0 12px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--bg);
  font-size: 16px;
}

.hint { margin-top: 8px; font-size: 0.85rem; }

.form-error {
  margin-top: 12px;
  color: var(--danger);
}

.primary {
  width: 100%;
  min-height: 48px;
  margin-top: 14px;
  border: 0;
  border-radius: 14px;
  background: var(--gold);
  color: var(--gold-ink);
  font-weight: 700;
}

.primary:hover { filter: brightness(1.05); }

.list {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin: 12px 0 0;
  padding: 0;
  list-style: none;
}

.list:empty { margin: 0; }

.item {
  display: grid;
  grid-template-columns: 8px minmax(0, 1fr);
  gap: 10px;
  padding: 12px;
  border-radius: 14px;
  background: var(--bg);
}

.item.is-editing { outline: 1px solid var(--gold); }

.rail {
  border-radius: 99px;
  background: var(--rarity, var(--line));
}

.item-title {
  margin: 0;
  font-weight: 650;
}

.item-meta,
.item-note { margin: 4px 0 0; font-size: 0.88rem; }

.item-worth {
  margin: 6px 0 0;
  font-variant-numeric: tabular-nums;
}

.item-worth.exact { color: #d7f5c8; }

.item-actions {
  display: flex;
  gap: 8px;
  margin-top: 10px;
}

.item-actions button {
  min-height: 36px;
  padding: 0 12px;
}

.empty { margin-top: 10px; }

.notes {
  margin: 18px 4px 0;
  font-size: 0.92rem;
}

.notes summary { cursor: pointer; }

.notes p { margin-top: 10px; }

code {
  font-family: ui-monospace, "Cascadia Code", Consolas, monospace;
  font-size: 0.88em;
}

button:focus-visible,
input:focus-visible,
select:focus-visible,
summary:focus-visible {
  outline: 2px solid var(--gold);
  outline-offset: 2px;
}

@media (prefers-reduced-motion: reduce) {
  * { scroll-behavior: auto; }
}
