:root {
  --bg: #16100d;
  --bg2: #2a1c16;
  --paper: #e8dbc1;
  --paper-dark: #d6c5a3;
  --note: #efe6c8;
  --ink: #2a1d17;
  --ink-soft: #6b5a4a;
  --blood: #9c1c17;
  --font-heading: 'Gochi Hand', 'Comic Sans MS', cursive;
  --font-body: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', sans-serif;
  --paper-noise: 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='.9' numOctaves='3'/%3E%3CfeColorMatrix values='0 0 0 0 .35 0 0 0 0 .25 0 0 0 0 .15 0 0 0 .22 0'/%3E%3C/filter%3E%3Crect width='160' height='160' filter='url(%23n)'/%3E%3C/svg%3E");
}

* { box-sizing: border-box; }

body {
  margin: 0;
  min-height: 100vh;
  color: var(--ink);
  font-family: var(--font-body);
  font-size: 17px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  background:
    radial-gradient(ellipse at 50% 30%, transparent 30%, rgba(0,0,0,.65) 100%),
    var(--paper-noise),
    linear-gradient(var(--bg2), var(--bg));
  background-attachment: fixed;
}

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

/* Handwritten font for headings, buttons and game labels; everything else uses the system font */
h1, h2, h3, h4, h5, h6,
.title, .title span,
button, .btn,
.tab, .ccard .cname,
.player .name,
.player .status:not(.err),
.lock, .chip,
.chal-name, .chal-goal,
.tier b,
.view-btn, .help-btn,
.slot .lbl, .tally, .stat b, .m-char, .m-player,
.win-percent, .rank, .badge, .stamp, .u-type, .u-quote,
.spin-current .nm, .big-id, .tour b, .role-guide b, .how summary, .why-wrap summary {
  font-family: var(--font-heading);
  font-weight: 400;
}

/* Inputs stay readable (16px also stops mobile browsers from zooming in) */
input, select, textarea {
  font-family: var(--font-body);
  font-size: 16px;
}

.paper {
  background: var(--paper-noise), var(--paper);
}

/* ---------- header / players ---------- */
.top {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 12px 20px;
  padding: 16px clamp(16px, 4vw, 40px);
}
.title {
  margin: 0;
  font-size: 40px;
  line-height: 1;
  color: var(--paper);
  text-shadow: 3px 3px 0 #000;
  transform: rotate(-2deg);
}
.title span { color: #e24a3b; }

.players { display: flex; flex-wrap: wrap; gap: 10px; flex: 1; }

.player {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 10px 6px 6px;
  background: var(--paper-noise), var(--paper);
  border: 3px solid var(--ink);
  border-radius: 6px 12px 8px 14px;
  box-shadow: 3px 3px 0 rgba(0,0,0,.5);
  max-width: 100%;
}
.player:nth-child(odd) { transform: rotate(-1deg); }
.player:nth-child(even) { transform: rotate(1deg); }
.player .swatch {
  position: relative;
  width: 34px; height: 34px;
  border-radius: 50%;
  border: 3px solid var(--ink);
  overflow: hidden;
  flex: none;
  cursor: pointer;
}
.player .swatch input { position: absolute; inset: -10px; width: 60px; height: 60px; opacity: 0; cursor: pointer; }
.player img { width: 34px; height: 34px; border: 2px solid var(--ink); border-radius: 4px; flex: none; }
.player .who { display: flex; flex-direction: column; min-width: 0; line-height: 1.05; }
.player .name { font-size: 20px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 170px; }
.player .status { font-size: 14px; color: var(--ink-soft); }
.player .status.err { color: var(--blood); }
.player .mini { background: none; border: 0; cursor: pointer; font-size: 20px; padding: 0 2px; color: var(--ink-soft); }
.player .mini:hover { color: var(--ink); }

.add-player { display: flex; gap: 8px; flex-wrap: wrap; }
.add-player input {
  width: min(280px, 100%);
  padding: 6px 10px;
  background: var(--paper-noise), var(--note);
  border: 3px solid var(--ink);
  border-radius: 8px 4px 10px 6px;
}
.btn {
  padding: 6px 14px;
  background: #c9372c;
  color: #fff4e6;
  border: 3px solid var(--ink);
  border-radius: 10px 6px 12px 4px;
  box-shadow: 2px 2px 0 #000;
  cursor: pointer;
}
.btn:hover { background: #dd4436; }
.btn:disabled { opacity: .5; cursor: default; }

/* ---------- character select ---------- */
.select { padding: 0 clamp(16px, 4vw, 40px); }
.select-bar { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 18px; margin-bottom: 6px; color: var(--paper); }
.tabs { display: flex; gap: 6px; }
.tab {
  background: transparent;
  color: var(--paper);
  border: 2px solid transparent;
  border-radius: 8px;
  padding: 2px 10px;
  cursor: pointer;
  font-size: 20px;
}
.tab[aria-selected="true"] { border-color: var(--paper); background: rgba(232,219,193,.1); }
.check { display: flex; align-items: center; gap: 6px; cursor: pointer; }
.check input { accent-color: #c9372c; width: 18px; height: 18px; }

.carousel-wrap { position: relative; display: flex; align-items: center; gap: 6px; }
.nav {
  flex: none;
  width: 40px; height: 64px;
  font-size: 40px; line-height: 1;
  background: none; border: 0; color: var(--paper);
  cursor: pointer;
}
.nav:hover { color: #e24a3b; }
.carousel {
  display: flex;
  gap: 10px;
  overflow-x: auto;
  scroll-snap-type: x proximity;
  padding: 10px 4px 14px;
  flex: 1;
  outline: none;
  scrollbar-color: var(--paper-dark) transparent;
}
.ccard {
  flex: none;
  scroll-snap-align: center;
  width: 104px;
  padding: 6px 4px 6px;
  background: var(--paper-noise), var(--paper);
  border: 3px solid var(--ink);
  border-radius: 10px 6px 12px 8px;
  cursor: pointer;
  text-align: center;
  box-shadow: 3px 3px 0 rgba(0,0,0,.55);
  transition: transform .12s;
}
.ccard:hover { transform: translateY(-3px) rotate(-1deg); }
.ccard.tainted { background: var(--paper-noise), #cdb9a8; }
.ccard.sel { border-color: #c9372c; box-shadow: 0 0 0 3px #c9372c, 3px 3px 0 rgba(0,0,0,.55); transform: translateY(-4px); }
.ccard .portrait { width: 64px; height: 64px; display: block; margin: 0 auto; }
.ccard .cname { font-size: 15px; line-height: 1.05; height: 32px; display: flex; align-items: center; justify-content: center; }
.pips { display: flex; flex-direction: column; gap: 3px; margin-top: 4px; }
.pip { height: 6px; border: 1.5px solid var(--ink); border-radius: 3px; overflow: hidden; background: rgba(0,0,0,.08); }
.pip i { display: block; height: 100%; }
.divider { flex: none; align-self: stretch; width: 3px; background: var(--blood); margin: 0 6px; border-radius: 2px; }

/* ---------- stage ---------- */
.stage {
  display: grid;
  grid-template-columns: minmax(220px, 300px) minmax(0, 640px);
  justify-content: center;
  align-items: start;
  gap: 28px;
  padding: 18px clamp(16px, 4vw, 40px) 30px;
}

.char-card {
  position: relative;
  padding: 18px 16px 20px;
  background: var(--paper-noise), var(--paper);
  border: 3px solid var(--ink);
  clip-path: polygon(0 2%, 8% 0, 30% 1.5%, 55% 0, 80% 2%, 100% 0, 99% 30%, 100% 60%, 98% 100%, 70% 98.5%, 40% 100%, 12% 98%, 0 100%, 1.5% 60%, 0 30%);
  transform: rotate(-1.5deg);
  text-align: center;
}
.char-card.tainted { background: var(--paper-noise), #cdb9a8; }
.char-card .portrait { width: 100%; height: auto; max-width: 220px; }
.char-card h2 { margin: 4px 0 2px; font-size: 38px; line-height: 1; font-weight: 400; }
.char-card .sub { color: var(--ink-soft); font-size: 16px; }
.tally { list-style: none; padding: 0; margin: 14px 0 0; display: grid; gap: 6px; text-align: left; }
.tally li { display: flex; align-items: center; gap: 8px; font-size: 18px; }
.tally .dot { width: 16px; height: 16px; border-radius: 50%; border: 2.5px solid var(--ink); flex: none; }
.tally .nm { flex: 1; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.tally .sc { font-size: 22px; }

.note {
  position: relative;
  padding: 44px clamp(12px, 3vw, 30px) 26px;
  background: var(--paper-noise), linear-gradient(175deg, #f4ecd0, var(--note) 60%, #e3d6b2);
  box-shadow: 6px 8px 0 rgba(0,0,0,.55);
  transform: rotate(1deg);
}
.note::before {
  content: "";
  position: absolute;
  top: -14px; left: 50%;
  width: 130px; height: 34px;
  transform: translateX(-50%) rotate(-3deg);
  background: rgba(220, 210, 170, .75);
  border: 1px solid rgba(0,0,0,.12);
}
/* 13 marks in rows of 4 / 5 / 4 */
.note-grid { display: grid; grid-template-columns: repeat(10, 1fr); gap: 6px 4px; }
.note-grid .slot { grid-column: span 2; }
.note-grid .slot:nth-child(1), .note-grid .slot:nth-child(10) { grid-column: 2 / span 2; }
.slot {
  display: flex; flex-direction: column; align-items: center;
  padding: 4px 2px;
  border-radius: 10px;
  position: relative;
}
.slot:hover { background: rgba(0,0,0,.05); }
.slot .mark-svg { width: min(92px, 22vw); height: min(92px, 22vw); }
.slot .lbl { font-size: 16px; line-height: 1.05; text-align: center; color: var(--ink-soft); min-height: 1.1em; }
.slot .miss { font-size: 18px; letter-spacing: 2px; line-height: 1.1; min-height: 1.1em; text-align: center; }
.slot.unknown .q {
  position: absolute; top: 16%; left: 50%; transform: translateX(-50%);
  font-size: 34px; color: var(--ink-soft);
}
.mk-empty { fill: rgba(60, 40, 25, .07); }
.mk-unknown { fill: rgba(60, 40, 25, .04); }
.mark-svg.unknown { opacity: .6; }

.legend { display: flex; flex-wrap: wrap; gap: 6px 16px; justify-content: center; margin-top: 14px; font-size: 15px; color: var(--ink-soft); }
.legend .sw { display: inline-block; width: 18px; height: 12px; border: 2px solid var(--ink); vertical-align: middle; margin-right: 4px; }

.empty-hint { text-align: center; color: var(--ink-soft); margin: 0 0 12px; font-size: 18px; }

.foot { text-align: center; color: #9c8b75; font-size: 14px; padding: 0 16px 20px; }

/* ---------- nav + views ---------- */
.views { display: flex; gap: 4px; }
.view-btn {
  background: none; border: 0; cursor: pointer;
  color: var(--paper); font-size: 24px; padding: 2px 10px;
  border-bottom: 3px solid transparent;
}
.view-btn:hover { color: #fff; }
.view-btn[aria-current="page"] { color: #ff6b5b; border-bottom-color: #c9372c; }
.view[hidden] { display: none; }
::view-transition-old(root) { animation: page-out .22s ease-in both; }
::view-transition-new(root) { animation: page-in .3s ease-out both; }
@keyframes page-out { to { opacity: 0; transform: translateX(-40px) rotate(-1deg); } }
@keyframes page-in { from { opacity: 0; transform: translateX(40px) rotate(1deg); } }
@media (prefers-reduced-motion: reduce) { ::view-transition-old(root), ::view-transition-new(root) { animation: none; } }

.pip.locked { opacity: .35; border-style: dashed; }
.tally .lock { font-size: 14px; }

/* ---------- sheets (challenges / squad) ---------- */
.sheet {
  max-width: 1000px;
  margin: 12px auto 30px;
  padding: 22px clamp(12px, 3vw, 32px) 28px;
  background: var(--paper-noise), var(--paper);
  box-shadow: 6px 8px 0 rgba(0,0,0,.55);
}
.sheet-head { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 20px; }
.sheet h2 { margin: 0; font-size: 36px; font-weight: 400; }
.sheet-h3 { margin: 26px 0 0; font-size: 28px; font-weight: 400; }
.sheet-sub { color: var(--ink-soft); margin: 6px 0 14px; }
.sheet code { font-size: 14px; }
.sheet .tab { color: var(--ink); font-size: 18px; }
.sheet .tab[aria-selected="true"] { border-color: var(--ink); background: rgba(0,0,0,.06); }
.empty-hint.light { margin: 18px 0; }
.check.dark { color: var(--ink); }

.chip-demo { display: inline-flex; align-items: center; justify-content: center; width: 22px; height: 22px; border-radius: 50%; border: 2.5px solid var(--ink); font-size: 12px; vertical-align: middle; }
.chip-demo.lock { border-style: dashed; opacity: .6; }
.chip-demo.done { background: var(--ink); color: var(--paper); }

.chips { display: flex; flex-wrap: wrap; gap: 6px; justify-content: flex-end; max-width: 280px; }
.chip {
  display: inline-flex; align-items: center; gap: 4px;
  padding: 1px 8px 1px 4px;
  border: 2.5px solid var(--pc);
  border-radius: 14px;
  font-size: 15px;
  white-space: nowrap;
}
.chip em { font-style: normal; max-width: 90px; overflow: hidden; text-overflow: ellipsis; }
.chip.open::before { content: ""; width: 12px; height: 12px; border-radius: 50%; border: 2px solid var(--pc); }
.chip.done { background: var(--pc); color: #fff; text-shadow: 1px 1px 0 rgba(0,0,0,.5); }
.chip.lock { border-style: dashed; opacity: .55; }

.squad-controls { display: flex; flex-wrap: wrap; gap: 10px 18px; align-items: center; margin-bottom: 14px; }
.goal { display: flex; align-items: center; gap: 6px; }
.goal .dot { width: 16px; height: 16px; border-radius: 50%; border: 2.5px solid var(--ink); }
.goal select {
  max-width: 260px;
  padding: 4px 6px;
  background: var(--note);
  border: 2.5px solid var(--pc);
  border-radius: 8px;
}
.squad-results { display: grid; gap: 12px; }
.squad { border: 2.5px solid var(--ink); border-radius: 12px 8px 14px 10px; padding: 10px 12px; background: rgba(255,255,255,.22); }
.squad.best { background: rgba(242, 201, 76, .2); border-width: 3.5px; }
.rank { font-size: 26px; }
.members { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 8px; }
.member {
  display: grid; grid-template-columns: 56px 1fr; column-gap: 8px; align-content: start;
  text-align: left; cursor: pointer;
  padding: 6px 8px;
  background: var(--paper-noise), var(--note);
  border: 3px solid var(--pc);
  border-radius: 10px;
}
.member:hover { transform: translateY(-2px); }
.member .portrait { grid-row: 1 / span 4; width: 56px; height: 56px; }
.m-player { font-size: 14px; color: var(--ink-soft); }
.m-char { font-size: 20px; line-height: 1; }
.m-gain { font-size: 14px; }
.m-tags em { font-style: normal; font-size: 12px; margin-right: 4px; padding: 0 5px; border-radius: 5px; color: #fff; white-space: nowrap; }
.t-sup { background: #2f6fb3; }
.t-pow { background: #2f8f4e; }
.t-hard { background: #8a6d3b; }
.t-fri { background: var(--blood); }

.tier-list { display: grid; grid-template-columns: repeat(auto-fill, minmax(290px, 1fr)); gap: 8px; margin-top: 8px; }
.tier { display: grid; grid-template-columns: 48px 1fr; gap: 8px; align-items: start; padding: 6px 8px; border: 2px solid rgba(0,0,0,.25); border-radius: 8px; cursor: pointer; }
.tier:hover { background: rgba(0,0,0,.05); }
.tier .portrait { width: 48px; height: 48px; }
.tier b { font-weight: 400; font-size: 19px; }

@media (max-width: 760px) {
  .note-grid { grid-template-columns: repeat(3, 1fr); }
  .note-grid .slot, .note-grid .slot:nth-child(1), .note-grid .slot:nth-child(10) { grid-column: auto; }
  .note-grid .slot:nth-child(13) { grid-column: 2; }
      .view-btn { font-size: 20px; padding: 2px 6px; }
  .stage { grid-template-columns: 1fr; }
  .char-card { display: grid; grid-template-columns: 110px 1fr; gap: 0 12px; text-align: left; align-items: center; }
  .char-card .portrait { grid-row: span 3; }
  .tally { grid-column: 1 / -1; }
  .title { font-size: 32px; }
  .nav { display: none; }
}

/* ---------- stats, unlock dialog, squad breakdown ---------- */
.stats { display: grid; grid-template-columns: auto auto; gap: 1px 8px; justify-content: center; margin-top: 8px; }
.stat { display: contents; font-size: 14px; color: var(--ink-soft); }
.stat b { font-weight: 400; text-align: right; }
.stat .dots { display: inline-flex; gap: 2px; align-items: center; }
.stat .dots i { width: 9px; height: 9px; border: 1.5px solid var(--ink); border-radius: 50%; }
.stat .dots i.on { background: #2f8f4e; }
.stat .dots i.on.bad { background: var(--blood); }
.tier .stats { justify-content: start; margin: 2px 0 4px; }

button.slot { background: none; border: 0; font: inherit; color: inherit; cursor: pointer; }
button.slot:focus-visible { outline: 3px solid #c9372c; }

.unlock {
  width: min(460px, calc(100vw - 32px));
  padding: 20px 20px 18px;
  border: 3px solid var(--ink);
  border-radius: 10px 6px 12px 8px;
  background: var(--paper-noise), var(--note);
  color: var(--ink);
  box-shadow: 6px 8px 0 rgba(0,0,0,.55);
}
.unlock::backdrop { background: rgba(10, 6, 4, .6); }
.unlock h3 { margin: 0; font-size: 28px; font-weight: 400; line-height: 1.05; }
.unlock p { margin: 8px 0; line-height: 1.25; }
.u-close { position: absolute; top: 6px; right: 8px; background: none; border: 0; font-size: 22px; cursor: pointer; color: var(--ink-soft); }
.u-head { display: flex; gap: 12px; align-items: center; padding-right: 20px; }
.u-head img { border: 3px solid var(--ink); border-radius: 6px; flex: none; }
.u-kind { font-size: 15px; color: var(--ink-soft); margin: 0 !important; }
.u-type { display: inline-block; margin-top: 2px; font-size: 13px; padding: 0 6px; border-radius: 6px; background: var(--ink); color: var(--paper); }
.u-quote { font-size: 20px; color: #7a4b2a; }
.u-note { font-size: 15px; color: var(--blood); }
.u-who { justify-content: flex-start; max-width: none; margin: 10px 0 6px; }
.u-wiki { color: #9c1c17; }

.why { display: flex; flex-wrap: wrap; gap: 2px 14px; font-size: 15px; color: var(--ink-soft); margin: -2px 0 8px; }
.why b { color: var(--ink); font-weight: 400; }
.how { margin: 18px 0 0; padding: 8px 12px; border: 2px dashed rgba(0,0,0,.3); border-radius: 8px; }
.how summary { cursor: pointer; font-size: 20px; }
.how ul { margin: 4px 0 8px; padding-left: 20px; }
.how li { margin: 2px 0; }
.pros, .cons { margin: 2px 0 0; padding-left: 16px; font-size: 14px; line-height: 1.2; }
.pros li::marker { content: "+ "; color: #2f8f4e; }
.cons li::marker { content: "− "; color: var(--blood); }

/* ---------- spindown ---------- */
.estimate { margin: 8px 0 14px; padding: 8px 12px; border: 2.5px dashed var(--blood); border-radius: 8px; background: rgba(156, 28, 23, .07); line-height: 1.25; }
.estimate b { color: var(--blood); font-weight: 400; }
.spin-controls { display: flex; flex-wrap: wrap; align-items: center; gap: 10px 20px; margin-bottom: 12px; }
.spin-field { display: flex; align-items: center; gap: 6px; }
.spin-field select { padding: 4px 6px; background: var(--note); border: 2.5px solid var(--ink); border-radius: 8px; max-width: 240px; }
.spin-controls .check input:checked + * { color: var(--blood); }
.spin-search { position: relative; max-width: 460px; }
.spin-search input { width: 100%; padding: 8px 12px; font-size: 20px; background: var(--paper-noise), var(--note); border: 3px solid var(--ink); border-radius: 10px 6px 12px 8px; }
.spin-results { position: absolute; z-index: 5; left: 0; right: 0; margin: 4px 0 0; padding: 4px; list-style: none; background: var(--note); border: 2.5px solid var(--ink); border-radius: 8px; box-shadow: 4px 5px 0 rgba(0,0,0,.4); max-height: 320px; overflow-y: auto; }
.spin-results li { padding: 4px 8px; border-radius: 6px; cursor: pointer; display: flex; gap: 8px; align-items: baseline; }
.spin-results li:hover, .spin-results li.active { background: rgba(0,0,0,.08); }
.iid { color: var(--ink-soft); font-size: 15px; min-width: 42px; }
.qual { color: #b8860b; letter-spacing: -1px; font-size: 14px; white-space: nowrap; }
.qual.q0 { color: #8a7a6a; }
.spin-out { margin-top: 16px; display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 18px; }
.spin-out h3 { margin: 0 0 6px; font-size: 24px; font-weight: 400; }
.spin-current { grid-column: 1 / -1; display: grid; grid-template-columns: auto 1fr; gap: 2px 12px; padding: 10px 14px; border: 3px solid var(--ink); border-radius: 12px 8px 14px 10px; background: rgba(255,255,255,.3); }
.spin-current .big-id { grid-row: span 3; font-size: 40px; color: var(--ink-soft); align-self: center; }
.spin-current .nm { font-size: 30px; line-height: 1; }
.spin-current .q { color: #7a4b2a; }
.spin-current .d { font-size: 15px; color: var(--ink-soft); }
.chain { list-style: none; margin: 0; padding: 0; display: grid; gap: 4px; }
.chain li { display: grid; grid-template-columns: 44px 1fr; gap: 0 8px; align-items: baseline; }
.chain .uses { font-size: 15px; color: var(--ink-soft); text-align: right; }
.chain button { text-align: left; background: none; border: 0; padding: 2px 6px; border-radius: 6px; cursor: pointer; display: flex; flex-wrap: wrap; gap: 0 8px; align-items: baseline; }
.chain button:hover { background: rgba(0,0,0,.07); }
.chain .hit.q4 { background: rgba(242, 201, 76, .35); }
.chain .hit.q3 { background: rgba(242, 201, 76, .15); }
.chain .who { display: inline-flex; gap: 2px; }
.chain .who i { width: 9px; height: 9px; border-radius: 50%; border: 1.5px solid var(--ink); display: inline-block; }
.skipped { grid-column: 2; font-size: 13px; color: var(--ink-soft); padding-left: 6px; line-height: 1.15; }
.skipped s { text-decoration-thickness: 1.5px; }
.spin-note { font-size: 14px; color: var(--ink-soft); margin: 6px 0 0; }
@media (max-width: 760px) { .spin-out { grid-template-columns: 1fr; } }

/* ---------- how-to popup ---------- */
.help-btn { width: 30px; height: 30px; margin-left: 6px; border-radius: 50%; border: 2.5px solid var(--paper); background: none; color: var(--paper); font-size: 20px; line-height: 1; cursor: pointer; align-self: center; }
.help-btn:hover { border-color: #ff6b5b; color: #ff6b5b; }
.unlock.intro { width: min(600px, calc(100vw - 32px)); }
.intro h3 { padding-right: 24px; }
.steps { margin: 10px 0 8px; padding-left: 22px; }
.steps li { margin: 4px 0; line-height: 1.25; }
.steps em, .intro-foot em { font-style: normal; color: var(--blood); }
.tour { display: grid; grid-template-columns: repeat(auto-fit, minmax(230px, 1fr)); gap: 8px; margin: 10px 0; }
.tour button { display: grid; gap: 2px; text-align: left; padding: 8px 10px; background: rgba(255,255,255,.35); border: 2.5px solid var(--ink); border-radius: 10px 6px 12px 8px; cursor: pointer; }
.tour button:hover { background: rgba(242, 201, 76, .25); transform: translateY(-1px); }
.tour b { font-size: 22px; font-weight: 400; color: var(--blood); }
.tour span { font-size: 15px; line-height: 1.2; color: var(--ink-soft); }
.intro-foot { font-size: 15px; color: var(--ink-soft); }
.intro-ok { display: block; margin: 10px 0 0 auto; font-size: 20px; }

/* =====================================================================
   UX pass: feedback, clarity, mobile, animations
   ===================================================================== */

/* ---------- toasts ---------- */
.toast-container {
  position: fixed; bottom: 16px; left: 16px; right: 16px; z-index: 1000;
  display: flex; flex-direction: column; align-items: flex-start; gap: 8px;
  pointer-events: none;
}
.toast {
  max-width: min(420px, 100%);
  padding: 10px 14px;
  background: var(--ink); color: var(--paper);
  border: 2.5px solid var(--paper);
  border-radius: 10px 6px 12px 8px;
  box-shadow: 4px 5px 0 rgba(0,0,0,.5);
  font-size: 17px; line-height: 1.25;
  animation: toast-in .3s ease-out;
  pointer-events: auto;
}
.toast.ok { border-color: #43b049; }
.toast.err { border-color: #e24a3b; }
.toast.out { animation: toast-out .3s ease-in forwards; }
@keyframes toast-in { from { transform: translateY(40px); opacity: 0; } }
@keyframes toast-out { to { transform: translateY(40px); opacity: 0; } }

/* ---------- player chip: loading / error / progress ---------- */
.player .swatch::after {
  content: ""; position: absolute; inset: 3px;
  border-radius: 50%;
  border: 3px solid transparent;
}
.player.loading .swatch::after {
  border-color: var(--paper) var(--paper) transparent transparent;
  animation: spin .9s linear infinite;
}
.player.loading { animation: chip-pulse 1.4s ease-in-out infinite; }
.player.loading .status { animation: fade-pulse 1.4s ease-in-out infinite; }
.player.err { border-color: var(--blood); background: var(--paper-noise), #ecd2c4; }
.player .status.err { white-space: normal; max-width: 280px; line-height: 1.15; }
@keyframes spin { to { transform: rotate(360deg); } }
@keyframes fade-pulse { 50% { opacity: .5; } }
@keyframes chip-pulse { 50% { box-shadow: 3px 3px 0 rgba(0,0,0,.5), 0 0 0 4px rgba(242, 201, 76, .45); } }

.player-progress { display: flex; align-items: center; gap: 6px; font-size: 14px; color: var(--ink-soft); white-space: nowrap; }
.progress-bar { width: 80px; height: 8px; border: 1.5px solid var(--ink); border-radius: 4px; overflow: hidden; background: rgba(0,0,0,.08); }
.progress-fill { display: block; height: 100%; width: var(--progress, 0%); background: var(--pc, #2f8f4e); animation: grow .8s ease-out; }
@keyframes grow { from { width: 0; } }

.add-player input.shake { animation: shake .4s; border-color: var(--blood); }
@keyframes shake { 20%, 60% { transform: translateX(-6px); } 40%, 80% { transform: translateX(6px); } }

/* ---------- marks: tooltip, hover, selection, missing dots ---------- */
.slot { transition: transform .15s, box-shadow .15s, background .15s; border-radius: 12px; }
.slot:hover { transform: scale(1.06); background: rgba(242, 201, 76, .16); box-shadow: 0 0 0 2px rgba(242, 201, 76, .5); }
.slot.sel { background: rgba(201, 55, 44, .08); box-shadow: 0 0 0 3px #c9372c, 0 0 14px rgba(201, 55, 44, .45); }
.slot.pop { animation: pop .35s ease-out; }
@keyframes pop { 40% { transform: scale(1.15); } 100% { transform: scale(1); } }

.slot[data-tip]:hover::after,
.slot[data-tip]:focus-visible::after {
  content: attr(data-tip);
  position: absolute; bottom: calc(100% + 6px); left: 50%;
  transform: translateX(-50%) rotate(-1deg);
  width: max-content; max-width: 220px;
  padding: 6px 10px;
  background: var(--ink); color: var(--paper);
  border-radius: 8px;
  font-size: 15px; line-height: 1.2; text-align: center;
  box-shadow: 3px 4px 0 rgba(0,0,0,.4);
  pointer-events: none; z-index: 20;
}
.slot[data-tip]:hover::before,
.slot[data-tip]:focus-visible::before {
  content: ""; position: absolute; bottom: 100%; left: 50%;
  transform: translateX(-50%);
  border: 6px solid transparent; border-top-color: var(--ink); border-bottom: 0;
  z-index: 20;
}
@media (hover: none) { .slot[data-tip]:hover::after, .slot[data-tip]:hover::before { display: none; } }

.slot .miss { display: flex; justify-content: center; gap: 4px; min-height: 16px; margin-top: 2px; }
.dot-missing {
  width: 12px; height: 12px; border-radius: 50%;
  background: var(--pc); border: 2px solid var(--ink);
  animation: dot-pulse 2s ease-in-out infinite;
}
@keyframes dot-pulse {
  0%, 100% { box-shadow: 0 0 0 0 color-mix(in srgb, var(--pc) 70%, transparent); }
  60% { box-shadow: 0 0 0 5px transparent; }
}
.pip { height: 8px; border-width: 2px; border-radius: 4px; }
.pip i { animation: grow .6s ease-out; }

.ccard { position: relative; }
.cstar { position: absolute; top: -8px; right: -6px; font-size: 22px; color: #f2c94c; text-shadow: 1px 1px 0 var(--ink), -1px -1px 0 var(--ink), 1px -1px 0 var(--ink), -1px 1px 0 var(--ink); animation: pop .5s ease-out; }
.tally li.complete .sc { color: #b8860b; }
.stamp { font-size: 13px; padding: 0 5px; border-radius: 5px; background: #f2c94c; border: 1.5px solid var(--ink); transform: rotate(-4deg); animation: pop .5s ease-out; }

/* ---------- challenges: cards ---------- */
.chal-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(290px, 1fr)); gap: 12px; margin-top: 12px; }
.chal-card {
  display: flex; flex-direction: column; gap: 6px;
  padding: 12px;
  border: 3px solid var(--ink);
  border-radius: 10px 6px 12px 8px;
  background: var(--paper-noise), var(--note);
  box-shadow: 3px 3px 0 rgba(0,0,0,.3);
  transition: transform .15s, box-shadow .15s;
  animation: card-in .35s ease-out both;
}
.chal-card:hover { transform: translateY(-3px); box-shadow: 4px 7px 0 rgba(0,0,0,.3); }
.chal-card.locked { background: var(--paper-noise), #d4c7b4; }
.chal-card.locked .chal-portrait, .chal-card.locked .chal-info { opacity: .6; }
.chal-card.done { background: var(--paper-noise), #f1dea0; border-color: #b8860b; }
.chal-card.open { border-color: #2f8f4e; }
@keyframes card-in { from { opacity: 0; transform: translateY(8px); } }
.chal-header { display: flex; gap: 10px; }
.chal-portrait { width: 64px; height: 64px; flex: none; border: 2px solid var(--ink); border-radius: 8px; background: rgba(255,255,255,.35); }
.chal-portrait .portrait { width: 100%; height: 100%; }
.chal-info { flex: 1; min-width: 0; }
.chal-name { margin: 0; font-size: 22px; font-weight: 400; line-height: 1.05; }
.chal-n { color: var(--ink-soft); font-size: 16px; }
.chal-goal, .chal-reward { margin: 3px 0 0; font-size: 15px; line-height: 1.15; }
.chal-reward { color: var(--ink-soft); }
.chal-req { margin: 0; font-size: 13px; line-height: 1.2; color: var(--ink-soft); }
.chal-card .chips { justify-content: flex-start; max-width: none; }
.badge { align-self: flex-start; padding: 2px 10px; border-radius: 8px; font-size: 16px; border: 2px solid var(--ink); }
.badge-locked { background: rgba(0,0,0,.12); color: var(--ink-soft); border-style: dashed; }
.badge-open { background: #2f8f4e; color: #fff; }
.badge-done { background: #f2c94c; }

/* ---------- squad: role buttons + big win bar ---------- */
.role-guide { margin: 6px 0 14px; padding: 8px 12px; border: 2px dashed rgba(0,0,0,.3); border-radius: 8px; }
.role-guide p { margin: 2px 0; }
.role-guide ul { margin: 2px 0 4px; padding-left: 20px; }
.squad-controls { flex-direction: column; align-items: stretch; }
.goal { flex-wrap: wrap; gap: 8px 12px; }
.goal-who { display: flex; align-items: center; gap: 6px; min-width: 120px; }
.goal-buttons { display: flex; gap: 6px; }
.goal-button {
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 1px;
  min-width: 66px; min-height: 52px; padding: 4px 8px;
  background: var(--paper-noise), var(--note);
  border: 3px solid var(--ink); border-radius: 10px 6px 12px 8px;
  cursor: pointer; transition: transform .12s, box-shadow .12s;
}
.goal-button:hover { transform: translateY(-2px); box-shadow: 0 4px 0 rgba(0,0,0,.25); }
.goal-button.selected { background: var(--pc); border-color: var(--ink); color: #fff; text-shadow: 1px 1px 0 rgba(0,0,0,.6); box-shadow: 0 0 0 2px var(--pc); }
.goal-icon { font-size: 22px; line-height: 1; }
.goal-button-label { font-size: 16px; line-height: 1; }
.hunt-select { padding: 6px 8px; min-height: 44px; background: var(--note); border: 3px solid var(--pc); border-radius: 8px; max-width: 260px; animation: card-in .25s ease-out; }

.squad { animation: card-in .35s ease-out both; }
.squad:nth-child(2) { animation-delay: .05s; } .squad:nth-child(3) { animation-delay: .1s; } .squad:nth-child(4) { animation-delay: .15s; } .squad:nth-child(5) { animation-delay: .2s; }
.squad-win { display: flex; align-items: center; gap: 12px; margin-bottom: 6px; }
.squad-win .rank { font-size: 28px; min-width: 38px; text-align: center; }
.win-percent { font-size: 40px; line-height: 1; color: #2f8f4e; min-width: 78px; text-align: right; }
.win-bar-container { flex: 1; display: flex; flex-direction: column; gap: 3px; min-width: 0; }
.win-bar { height: 18px; border: 2.5px solid var(--ink); border-radius: 9px; overflow: hidden; background: rgba(0,0,0,.08); }
.win-bar-fill { height: 100%; width: var(--win-percent, 0%); background: linear-gradient(90deg, #43b049, #2f8f4e); animation: grow .7s ease-out; }
.win-label { font-size: 15px; color: var(--ink-soft); }
.win-label b { color: #b8860b; font-weight: 400; }
.why-wrap { margin: 0 0 8px; }
.why-wrap summary { cursor: pointer; font-size: 15px; color: var(--ink-soft); }
.why-wrap .why { margin: 4px 0 0; }

/* ---------- spindown intro ---------- */
.spin-intro { margin: 6px 0 8px; line-height: 1.25; }
.spin-intro b { color: var(--blood); font-weight: 400; }
.chain li { animation: card-in .25s ease-out both; }

/* ---------- view fade (fallback when View Transitions aren't supported) ---------- */
.view.fade-in { animation: fade-in .3s ease-out; }
@keyframes fade-in { from { opacity: 0; transform: translateY(10px); } }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; animation-iteration-count: 1 !important; transition: none !important; }
}

/* ---------- mobile: 44px touch targets, readable small text ---------- */
@media (max-width: 760px) {
  .btn, .tab, .view-btn, .nav, .player .mini, .tour button, .spin-results li, .chain button, .u-close, .intro-ok { min-height: 44px; }
  .player .mini { min-width: 40px; }
  .help-btn { width: 40px; height: 40px; }
  .check { min-height: 44px; }
  .check input { width: 22px; height: 22px; }
  .spin-field select, .goal select { min-height: 44px; }
  .add-player { flex-direction: column; width: 100%; }
  .add-player input, .add-player .btn { width: 100%; min-height: 44px; }
  .player .swatch { width: 40px; height: 40px; }
  .views { flex-wrap: wrap; }
  .player .status.err { max-width: 200px; }
  .goal-who { min-width: 0; width: 100%; }
  .goal-button { flex: 1; }
  .goal-buttons { flex: 1; }
  .hunt-select { max-width: none; width: 100%; }
  .win-percent { font-size: 32px; min-width: 60px; }
  .chal-grid { grid-template-columns: 1fr; }
  /* Gochi Hand stays for headings and labels; small reading text uses the system font */
  .chal-goal, .chal-reward, .chal-req, .tier p, .pros, .cons, .spin-current .d, .estimate, .spin-intro,
  .sheet-sub, .unlock p, .tour span, .intro-foot, .skipped, .role-guide, .how, .win-label, .why, .toast, .steps {
    font-family: system-ui, -apple-system, 'Segoe UI', sans-serif;
    font-size: 14px;
  }
}

/* ---------- recently checked players ---------- */
.recent { display: flex; flex-wrap: wrap; align-items: center; gap: 6px 8px; width: 100%; }
.recent[hidden] { display: none; }
.recent-label { color: var(--paper-dark); font-size: 15px; }
.recent-item { display: inline-flex; align-items: center; background: rgba(232,219,193,.12); border: 2px solid rgba(232,219,193,.45); border-radius: 16px; }
.recent-item:hover { border-color: var(--paper); }
.recent-add { display: inline-flex; align-items: center; gap: 6px; padding: 2px 4px 2px 3px; background: none; border: 0; color: var(--paper); cursor: pointer; font-size: 16px; }
.recent-add:disabled { opacity: .5; cursor: default; }
.recent-add img { width: 22px; height: 22px; border-radius: 50%; }
.recent-add span { max-width: 140px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.recent-forget { background: none; border: 0; color: var(--paper-dark); cursor: pointer; padding: 0 8px 0 2px; font-size: 13px; }
.recent-forget:hover { color: #ff6b5b; }
@media (max-width: 760px) { .recent-add, .recent-forget { min-height: 40px; } }

/* ---------- item pool (beta) ---------- */
.beta-sup { font-size: 11px; color: #f2c94c; vertical-align: super; }
.beta-tag { font-size: 16px; padding: 0 8px; border-radius: 6px; background: #f2c94c; border: 2px solid var(--ink); vertical-align: middle; }
.pool-summary { margin: 12px 0 8px; color: var(--ink-soft); }
.pool-summary b { color: var(--ink); }
.pool-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(170px, 1fr)); gap: 8px; }
.pool-grid > .spin-note, .pool-grid > .empty-hint { grid-column: 1 / -1; }
.pool-item {
  display: flex; flex-direction: column; gap: 2px; text-align: left;
  padding: 6px 8px; cursor: pointer;
  background: rgba(255,255,255,.3);
  border: 2px solid rgba(0,0,0,.35); border-radius: 8px 5px 9px 6px;
  transition: transform .12s, box-shadow .12s;
}
.pool-item:hover { transform: translateY(-2px); box-shadow: 0 4px 0 rgba(0,0,0,.2); border-color: var(--ink); }
.pool-item.q4 { background: rgba(242, 201, 76, .35); }
.pool-item.q3 { background: rgba(242, 201, 76, .15); }
.pool-item.locked { opacity: .6; border-style: dashed; }
.pool-top { display: flex; justify-content: space-between; align-items: baseline; gap: 6px; }
.pool-name { font-family: var(--font-heading); font-size: 18px; line-height: 1.1; }
.pool-bottom { display: flex; justify-content: space-between; align-items: center; min-height: 14px; }
.pool-tag { font-size: 12px; color: var(--ink-soft); }
.pool-item .who { display: inline-flex; gap: 2px; margin-left: auto; }
.pool-item .who i { width: 10px; height: 10px; border-radius: 50%; border: 1.5px solid var(--ink); display: inline-block; }
@media (max-width: 760px) { .pool-grid { grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); } .pool-item { min-height: 44px; } }

/* ---------- squad goal (route + marks per player) ---------- */
.squad-goal { display: flex; align-items: center; gap: 12px; margin-bottom: 8px; }
.squad-goal .rank { font-size: 30px; min-width: 38px; text-align: center; }
.goal-text { display: flex; flex-direction: column; line-height: 1.15; }
.goal-kicker { font-size: 14px; color: var(--ink-soft); }
.goal-route { font-family: var(--font-heading); font-size: 28px; line-height: 1.05; color: var(--blood); }
.goal-sum { font-size: 15px; color: var(--ink-soft); }
.goal-sum b { color: #b8860b; font-weight: 400; }
.goal-unlocked { font-size: 13px; color: var(--ink-soft); margin-left: 4px; }
.member { display: flex; flex-direction: column; gap: 6px; padding: 6px 8px; background: var(--paper-noise), var(--note); border: 3px solid var(--pc); border-radius: 10px; cursor: default; }
.member:hover { transform: none; }
.member-head { display: grid; grid-template-columns: 56px 1fr; column-gap: 8px; text-align: left; background: none; border: 0; padding: 0; cursor: pointer; }
.member-head:hover .m-char { text-decoration: underline; }
.member-head .portrait { grid-row: 1 / span 3; width: 56px; height: 56px; }
.m-marks { display: flex; flex-direction: column; gap: 4px; }
.m-row { display: flex; flex-wrap: wrap; align-items: center; gap: 4px 8px; }
.m-row.bonus { opacity: .8; }
.m-label { font-size: 12px; text-transform: uppercase; letter-spacing: .5px; color: var(--ink-soft); min-width: 44px; }
.goal-mark { display: inline-flex; align-items: center; gap: 2px; font-size: 13px; line-height: 1; }
.goal-mark .mark-svg { width: 24px; height: 24px; }
.m-none { font-size: 13px; color: var(--ink-soft); }
.bonus-tips { margin: 8px 0 0; font-size: 13px; color: var(--ink-soft); line-height: 1.3; }
.squad .squad-win { margin-top: 10px; }
.squad .win-percent { font-size: 30px; }
