:root {
  --slate: #2b2f36;
  --parchment: #efe3c4;
  --parchment-edge: #b8945a;
  --ink: #1f2a44;
  --accent: #c4471f;
  --frame: #2a2118;

  --parchment-light: #f6edd5;
  --parchment-dark: #dcc896;
  --muted: #5d5846;
  --font-head: "Alegreya SC", "Palatino Linotype", Georgia, serif;
  --font-body: "Alegreya", Georgia, "Times New Roman", serif;
}

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

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  min-height: 100vh;
  font-family: var(--font-body);
  font-size: 18px;
  line-height: 1.35;
  color: #e9e2cf;
  background:
    radial-gradient(ellipse at 15% 0%, rgba(255, 255, 255, 0.07), transparent 55%),
    radial-gradient(ellipse at 90% 100%, rgba(0, 0, 0, 0.4), transparent 50%),
    repeating-linear-gradient(135deg, rgba(255, 255, 255, 0.018) 0 2px, transparent 2px 7px),
    var(--slate);
  background-attachment: fixed;
}

button, input { font: inherit; color: inherit; }
button { cursor: pointer; }
[hidden] { display: none !important; }

:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; }

/* ---------- masthead ---------- */

.masthead {
  max-width: 1280px;
  margin: 0 auto;
  padding: 22px 16px 6px;
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  justify-content: space-between;
  gap: 12px 24px;
}

.masthead h1 {
  margin: 0;
  font-family: var(--font-head);
  font-weight: 900;
  font-size: clamp(2rem, 7vw, 3.4rem);
  line-height: 1;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  text-shadow: 0 2px 0 rgba(0, 0, 0, 0.4);
}
.masthead .h-ink { color: #f1e6c8; }
.masthead .h-accent { color: #e2623a; }

.name-field { display: flex; flex-direction: column; gap: 3px; font-size: 0.85rem; color: #bdb59e; }
.name-field input {
  width: min(260px, 100%);
  padding: 8px 10px;
  border: 1px solid var(--parchment-edge);
  border-radius: 4px;
  background: var(--parchment-light);
  color: var(--ink);
  font-size: 1.05rem;
}

main { max-width: 1280px; margin: 0 auto; padding: 8px 16px 40px; }

.hint { margin: 6px 0 14px; color: #bdb59e; font-size: 0.95rem; }

/* ---------- parchment cards ---------- */

.card {
  color: var(--ink);
  background: radial-gradient(ellipse at 50% 35%, var(--parchment-light) 0%, var(--parchment) 55%, var(--parchment-dark) 100%);
  border: 1px solid var(--parchment-edge);
  border-radius: 6px;
  box-shadow: inset 0 0 46px rgba(120, 80, 30, 0.35), 0 12px 30px rgba(0, 0, 0, 0.45);
}

/* ---------- board ---------- */

.board {
  padding: 14px;
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 12px;
}

.role {
  padding: 8px 8px 10px;
  border: 1px solid rgba(31, 42, 68, 0.25);
  border-radius: 4px;
  background: rgba(255, 255, 255, 0.2);
}

.role h2 {
  margin: 0 0 6px;
  font-family: var(--font-head);
  font-weight: 800;
  font-size: 1.35rem;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--ink);
}

.tier {
  margin-top: 6px;
  padding: 5px 6px 6px;
  min-height: 62px;
  border: 2px solid transparent;
  border-radius: 4px;
  background: rgba(31, 42, 68, 0.06);
  cursor: pointer;
}
.tier:hover { background: rgba(31, 42, 68, 0.1); }
.tier.active {
  border-color: var(--accent);
  background: rgba(196, 71, 31, 0.1);
}

.tier-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  width: 100%;
  padding: 0;
  border: 0;
  background: none;
  text-align: left;
  font-family: var(--font-head);
  font-weight: 700;
  font-size: 0.95rem;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  color: var(--ink);
}
.tier.active .tier-head { color: var(--accent); }
.tier-count { font-family: var(--font-body); font-weight: 500; font-size: 0.85rem; color: var(--muted); }

.tier-icons { display: flex; flex-wrap: wrap; gap: 4px; margin-top: 4px; min-height: 40px; }
.tier-empty { align-self: center; font-size: 0.85rem; font-style: italic; color: var(--muted); }

.icon-btn {
  position: relative;
  padding: 0;
  width: 44px;
  height: 44px;
  border: 2px solid var(--frame);
  border-radius: 3px;
  background: var(--frame);
  overflow: hidden;
}
.icon-btn img { display: block; width: 100%; height: 100%; object-fit: cover; }
.tier-icons .icon-btn:hover::after,
.tier-icons .icon-btn:focus-visible::after {
  content: "×";
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  font-size: 1.6rem;
  line-height: 1;
  color: #fff;
  background: rgba(196, 71, 31, 0.78);
}

/* ---------- picker ---------- */

.pool { margin-top: 16px; padding: 0 14px 14px; }

.target-bar {
  position: sticky;
  top: 0;
  z-index: 5;
  margin: 0 -14px;
  padding: 10px 14px 8px;
  display: flex;
  flex-wrap: wrap;
  gap: 8px 14px;
  align-items: center;
  background: var(--parchment);
  border-bottom: 1px solid rgba(184, 148, 90, 0.6);
  box-shadow: 0 5px 8px -5px rgba(60, 40, 10, 0.4);
  border-radius: 6px 6px 0 0;
}

.seg { display: flex; flex: 1 1 280px; border: 2px solid var(--ink); border-radius: 4px; overflow: hidden; }
.seg button {
  flex: 1 1 auto;
  min-width: 0;
  white-space: nowrap;
  min-height: 40px;
  padding: 4px 6px;
  border: 0;
  border-left: 1px solid rgba(31, 42, 68, 0.35);
  background: var(--parchment-light);
  color: var(--ink);
  font-family: var(--font-head);
  font-weight: 700;
  font-size: 0.9rem;
  letter-spacing: 0.03em;
  text-transform: uppercase;
}
.seg button:first-child { border-left: 0; }
.seg button[aria-pressed="true"] { background: var(--ink); color: var(--parchment-light); }

.target-readout { flex: 1 0 100%; margin: 0; font-size: 0.95rem; color: var(--muted); }
.target-readout strong { color: var(--accent); font-weight: 700; }

.filters { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 12px; margin: 6px 0 10px; }
.filters input[type="search"] {
  flex: 1 1 200px;
  min-width: 0;
  padding: 8px 10px;
  border: 1px solid var(--parchment-edge);
  border-radius: 4px;
  background: var(--parchment-light);
  color: var(--ink);
  font-size: 1.05rem;
}
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip {
  min-height: 36px;
  padding: 2px 12px;
  border: 1px solid var(--ink);
  border-radius: 999px;
  background: transparent;
  color: var(--ink);
  font-size: 0.95rem;
}
.chip[aria-pressed="true"] { background: var(--ink); color: var(--parchment-light); }
.count { margin: 0; font-size: 0.9rem; color: var(--muted); }

.pool-status { padding: 18px 4px; text-align: center; color: var(--muted); }
.pool-status:empty { display: none; }
.pool-status .btn { margin-top: 10px; }

.pool-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(56px, 1fr)); gap: 6px; }

.pool-champ {
  position: relative;
  aspect-ratio: 1;
  padding: 0;
  border: 2px solid var(--frame);
  border-radius: 3px;
  background: var(--frame);
  overflow: hidden;
}
.pool-champ img { display: block; width: 100%; height: 100%; object-fit: cover; }
.pool-champ:hover { border-color: var(--accent); }
.pool-champ.placed img { filter: brightness(0.75); }
.pool-champ.in-tier { border-color: var(--accent); box-shadow: 0 0 0 2px var(--accent); }
.pool-champ.in-tier img { filter: none; }

.badge {
  position: absolute;
  right: 0;
  bottom: 0;
  min-width: 18px;
  padding: 0 4px;
  font-family: var(--font-head);
  font-weight: 800;
  font-size: 0.78rem;
  line-height: 18px;
  text-align: center;
  color: #fff;
  background: var(--ink);
  border-top-left-radius: 4px;
}
.pool-champ.in-tier .badge { background: var(--accent); }

/* ---------- actions / footer ---------- */

.actions { display: flex; flex-wrap: wrap; gap: 10px; margin-top: 18px; }

.btn {
  min-height: 46px;
  padding: 8px 18px;
  border: 2px solid var(--parchment-edge);
  border-radius: 4px;
  background: var(--parchment-light);
  color: var(--ink);
  font-family: var(--font-head);
  font-weight: 800;
  font-size: 1rem;
  letter-spacing: 0.05em;
  text-transform: uppercase;
}
.btn:hover:not(:disabled) { background: #fff7e0; }
.btn-primary { background: var(--accent); border-color: #8f2f12; color: #fff; }
.btn-primary:hover:not(:disabled) { background: #d4532a; }
.btn-quiet { margin-left: auto; background: transparent; color: #d8cfb8; border-color: #6d6a60; }
.btn-quiet:hover:not(:disabled) { background: rgba(255, 255, 255, 0.08); }
.btn:disabled { opacity: 0.45; cursor: not-allowed; }

.site-footer { max-width: 1280px; margin: 0 auto; padding: 0 16px 32px; color: #c9c2ac; font-size: 0.95rem; }
.site-footer p { margin: 0; max-width: 78ch; }

.toast {
  position: fixed;
  left: 50%;
  bottom: 22px;
  transform: translate(-50%, 20px);
  max-width: calc(100vw - 32px);
  padding: 10px 18px;
  border-radius: 4px;
  background: var(--ink);
  color: var(--parchment-light);
  box-shadow: 0 6px 18px rgba(0, 0, 0, 0.5);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.18s, transform 0.18s;
  z-index: 20;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }

@media (max-width: 520px) {
  body { font-size: 17px; }
  .target-bar { gap: 6px; padding: 8px 14px 6px; }
  .seg { flex-basis: 100%; }
  .seg button { padding: 4px 3px; font-size: 0.78rem; letter-spacing: 0; }
  .target-readout { font-size: 0.9rem; }
  .btn-quiet { margin-left: 0; }
  .actions .btn { flex: 1 1 100%; }
}

@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; }
}
