/* castle.html — per-guild castle picker + character grid editor, in the
   new black theme. Header/background/footer come from css/home.css, page
   heading/panels/pill buttons/chips/search from css/theme-v2.css; this file
   is the castle picker, the team-row editor, and re-skins of the older
   style.css/teams.css widgets this page still uses (modals, draft cards,
   .btn inside JS-built rows). */

/* The modals, toast and draft-picker cards still read style.css's own
   tokens — point those at the mono palette on this page instead of
   restyling each widget one by one. */
.castle-page {
  --bg-page: #050505;
  --card-bg: #0b0b0b;
  --card-border: rgba(250, 250, 250, .10);
  --text: #fafafa;
  --muted: #a3a3a3;
  --accent: #fafafa;
  --accent-soft: rgba(250, 250, 250, .10);
  --accent-soft-bg: rgba(190, 242, 100, .06);
  --pink: #f472b6;
  --shadow: 0 20px 50px rgba(0, 0, 0, .5);
}

/* Wider than the other v2 pages — the picker panel + team rows need room. */
/* Same full width as index.html's sections (105rem) so the editor has room;
   the castle list itself stays narrower (below). */
.page-v2 .castle-main { max-width: 105rem; }
#castleListView { max-width: 1080px; margin: 0 auto; }

/* ===== Buttons ===== */
/* Save buttons are the white .solid primary (css/theme-v2.css); these are
   js/publish.js's in-flight / just-saved states on top of it. */
.pill-btn.btn-publish.btn-publishing { background: var(--h-nav-hover); color: var(--h-fg) !important; cursor: wait; box-shadow: none; }
.pill-btn.btn-publish.btn-published { background: var(--h-lime); }
/* Deliberately loud/dashed so it never reads as a normal, everyone-sees-it
   feature — this is a dev-only shortcut visible to the site owner alone. */
.castle-mock-btn { background: rgba(234, 179, 8, .08); color: var(--h-yellow) !important; outline: 1px dashed rgba(234, 179, 8, .5); outline-offset: -1px; font-size: 12.5px; }
.castle-mock-btn:hover { background: rgba(234, 179, 8, .16); }

/* Plain .btn (JS-built row actions, modal buttons, paste-banner cancel) —
   same muted/white pill language as .pill-btn in css/theme-v2.css. */
.castle-page .btn {
  background: #1f1f1f; color: var(--h-fg); border: 0; border-radius: 999px;
  font-family: 'Anuphan', sans-serif; font-weight: 700;
  transition: transform .3s cubic-bezier(.23, 1, .32, 1), background .2s, color .2s;
}
.castle-page .btn:hover:not(:disabled) { background: #2b2b2b; transform: scale(1.05); }
.castle-page .btn:active:not(:disabled) { transform: scale(.95); }
.castle-page .btn-primary { background: var(--h-pill-bg); color: var(--h-pill-fg); }
.castle-page .btn-primary:hover:not(:disabled) { background: #e5e5e5; }

/* ===== STEP 1: castle picker ===== */
.castle-group .panel-title { display: flex; align-items: center; gap: 12px; }
.castle-group .panel-head .label { font-family: 'Anuphan', sans-serif; font-size: 12px; letter-spacing: .04em; }
.castle-group-icon, .castle-grid-icon {
  display: inline-grid; place-items: center; width: 42px; height: 42px; border-radius: 13px; flex-shrink: 0;
  background: linear-gradient(145deg, #1d1d1d, #0e0e0e); border: 1px solid var(--h-line);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, .06);
}
/* Per-size colour, shared by the group heading, each card and the editor
   title: outer = sky, inner = violet, main = gold (lime is kept for "complete"). */
.castle-group-outer .castle-group-icon, .castle-pick-icon-outer { color: var(--h-sky); }
.castle-group-inner .castle-group-icon, .castle-pick-icon-inner { color: #a78bfa; }
.castle-group-main .castle-group-icon, .castle-pick-icon-main { color: var(--h-yellow); }

/* Centred wrapping row, so a group with fewer cards (3 inner, 1 main)
   sits in the middle of its panel instead of hugging the left edge.
   Fixed card width (flex: 0 0, not min-width) so a long "last saved by"
   name wraps inside its card instead of widening it. `safe` keeps the
   first card reachable if the row ever gets narrower than one card. */
.castle-pick-row { display: flex; flex-wrap: wrap; justify-content: safe center; gap: 12px; }
.castle-pick-row > .castle-pick-btn { flex: 0 0 188px; }

/* Castle cards — the reference portfolio's card vocabulary: a spotlight
   and border light that follow the pointer (--mx/--my from js/castle.js
   addPickCardFx), a slight 3D tilt (--rx/--ry), faint grid with wandering
   squares (HomeFx.addGridWalkers), a big faded icon watermark, an 01 ↗
   index, and a team-count bar. Colour per size via --g (outer sky, inner
   violet, main gold). Decoration sits under the text (z-index -1). */
.castle-pick-btn {
  --g: 250, 250, 250; --mx: 50%; --my: 0%; --rx: 0deg; --ry: 0deg; --lift: 0px;
  position: relative; overflow: hidden; isolation: isolate;
  display: flex; flex-direction: column; align-items: flex-start; gap: 4px;
  padding: 18px; border-radius: 18px; min-width: 0;
  background: var(--h-mcard-bg); border: 1px solid var(--h-line); color: var(--h-fg);
  font: inherit; text-align: left; cursor: pointer;
  transform: perspective(700px) rotateX(var(--rx)) rotateY(var(--ry)) translateY(var(--lift));
  transition: transform .5s cubic-bezier(.23, 1, .32, 1), border-color .25s, background .25s, box-shadow .4s,
    opacity .7s cubic-bezier(.23, 1, .32, 1), filter .7s;
  will-change: transform;
}
.castle-pick-btn.g-outer { --g: 56, 189, 248; }
.castle-pick-btn.g-inner { --g: 167, 139, 250; }
.castle-pick-btn.g-main { --g: 234, 179, 8; }
.castle-pick-btn:hover {
  --lift: -4px; background: var(--h-mcard-hover); border-color: rgba(var(--g), .45);
  box-shadow: 0 22px 44px rgba(0, 0, 0, .5), 0 0 30px rgba(var(--g), .08);
  transition: transform .15s ease-out, border-color .25s, background .25s, box-shadow .4s;
}
.castle-pick-btn:active { --lift: -1px; }
.castle-pick-btn:focus-visible { outline: 2px solid rgba(var(--g), .9); outline-offset: 3px; }

/* grid */
.castle-pick-btn::before {
  content: ''; position: absolute; inset: 0; z-index: -1; pointer-events: none;
  background-image: linear-gradient(var(--h-grid-line) 1px, transparent 1px), linear-gradient(90deg, var(--h-grid-line) 1px, transparent 1px);
  background-size: 22px 22px; opacity: .5; transition: opacity .5s;
  -webkit-mask-image: radial-gradient(120% 90% at 0% 0%, #000 20%, transparent 75%); mask-image: radial-gradient(120% 90% at 0% 0%, #000 20%, transparent 75%);
}
.castle-pick-btn:hover::before { opacity: 1; }
.castle-pick-btn > .m-snake { position: absolute; z-index: -1; opacity: .25; }
.castle-pick-btn:hover > .m-snake { opacity: 1; }

/* pointer spotlight + border light */
.castle-pick-glow {
  position: absolute; inset: 0; z-index: -1; pointer-events: none; border-radius: inherit;
  background: radial-gradient(220px circle at var(--mx) var(--my), rgba(var(--g), .13), transparent 65%);
  opacity: 0; transition: opacity .4s;
}
.castle-pick-glow::before {
  content: ''; position: absolute; inset: -1px; border-radius: inherit; padding: 1px;
  background: radial-gradient(160px circle at var(--mx) var(--my), rgba(var(--g), .9), transparent 70%);
  -webkit-mask: linear-gradient(#000 0 0) content-box, linear-gradient(#000 0 0);
  -webkit-mask-composite: xor; mask-composite: exclude;
}
.castle-pick-btn:hover .castle-pick-glow { opacity: 1; }

/* big faded icon watermark */
.castle-pick-mark {
  position: absolute; right: -22px; bottom: -26px; z-index: -1; pointer-events: none;
  opacity: .06; transition: transform .8s cubic-bezier(.23, 1, .32, 1), opacity .5s;
}
.castle-pick-mark svg { width: 128px; height: 128px; stroke-width: 1.2; }
.castle-pick-btn:hover .castle-pick-mark { opacity: .16; transform: rotate(-8deg) scale(1.06); }

/* 01 ↗ index */
.castle-pick-corner {
  position: absolute; top: 18px; right: 16px;
  font: 600 11px 'JetBrains Mono', monospace; letter-spacing: .1em; color: var(--h-muted);
  transition: color .3s, transform .4s cubic-bezier(.23, 1, .32, 1);
}
.castle-pick-btn:hover .castle-pick-corner { color: var(--h-fg); transform: translate(3px, -3px); }

.castle-pick-icon {
  display: inline-grid; place-items: center; width: 44px; height: 44px; margin-bottom: 10px; border-radius: 13px;
  background: linear-gradient(145deg, #1d1d1d, #0e0e0e); border: 1px solid var(--h-line);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, .06);
  transition: transform .5s cubic-bezier(.23, 1, .32, 1), border-color .3s, box-shadow .3s;
}
.castle-pick-btn:hover .castle-pick-icon {
  transform: scale(1.1) rotate(-4deg); border-color: rgba(var(--g), .5);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, .06), 0 0 20px rgba(var(--g), .2);
}
.castle-pick-name { font: 700 16px 'Anuphan', sans-serif; }
.castle-pick-count { font: 600 12px 'Anuphan', sans-serif; font-variant-numeric: tabular-nums; color: var(--h-muted); }

/* team-count bar */
.castle-pick-bar { display: block; width: 100%; height: 3px; margin-top: 6px; border-radius: 3px; background: rgba(250, 250, 250, .08); overflow: hidden; }
.castle-pick-bar i { display: block; height: 100%; border-radius: inherit; background: rgb(var(--g)); box-shadow: 0 0 8px rgba(var(--g), .6); transition: width .8s cubic-bezier(.23, 1, .32, 1); }

/* Every team filled: a steady tint of the group colour. */
.castle-pick-btn.complete { border-color: rgba(var(--g), .22); }
.castle-pick-btn.complete .castle-pick-count { color: rgb(var(--g)); }

/* Not every team in this castle is fully filled yet — flag it so admins
   know at a glance which castles still need work (the ! replaces the
   01 ↗ index in the corner). */
.castle-pick-btn.incomplete { border-color: rgba(244, 63, 94, .45); }
.castle-pick-btn.incomplete:hover { border-color: var(--h-rose); }
.castle-pick-btn.incomplete .castle-pick-corner { display: none; }
.castle-pick-btn.incomplete::after {
  content: "!"; position: absolute; top: 14px; right: 14px;
  width: 20px; height: 20px; border-radius: 50%; display: grid; place-items: center;
  background: var(--h-rose); color: #fff; font: 800 12px 'Inter', sans-serif;
  box-shadow: 0 0 14px rgba(244, 63, 94, .5);
}
.castle-pick-btn.incomplete .castle-pick-count { color: var(--h-rose); }
.castle-pick-btn.incomplete .castle-pick-bar i { background: var(--h-rose); box-shadow: 0 0 8px rgba(244, 63, 94, .6); }

/* Staggered rise-in when the picker opens (js/castle.js staggerPickCards). */
.castle-pick-btn.rise:not(.risen) { opacity: 0; filter: blur(6px); --lift: 26px; }
.castle-pick-btn.rise { transition-delay: calc(var(--i, 0) * 55ms); }
.castle-pick-btn.rise.risen:hover { transition-delay: 0s; }
.castle-pick-btn.rise:not(.risen) .castle-pick-bar i { width: 0 !important; }

/* Who/when this castle was last saved to the server — see js/castle.js's
   formatLastSavedHtml(). Deliberately quiet, a "verify if you want to"
   detail. The name line can be one long unbroken Discord name, so it may
   break mid-word rather than widen the card. */
.castle-pick-lastsaved {
  display: block; margin-top: 6px; padding-top: 8px; border-top: 1px dashed var(--h-line); width: 100%;
  font: 500 10.5px/1.5 'Anuphan', sans-serif; color: var(--h-muted); opacity: .8;
}
.castle-pick-lastsaved-label { display: block; }
.castle-pick-lastsaved-name { display: block; overflow-wrap: anywhere; color: var(--h-fg); font-weight: 700; }
.castle-pick-lastsaved-time { display: block; }

/* Action dock (castle list) — a glass bar that sticks to the bottom of
   the viewport: status + meter left, actions right, owner's Mockup chip
   tucked underneath. Wraps to a stacked layout on narrow screens. */
.castle-save-bar {
  position: relative; z-index: 30;
  display: flex; align-items: center; justify-content: space-between; flex-wrap: wrap; gap: 14px 24px;
  margin-top: 32px; padding: 16px 16px 16px 20px;
  background: rgba(12, 12, 12, .78); border: 1px solid var(--h-line); border-radius: 26px;
  backdrop-filter: blur(18px) saturate(1.3); -webkit-backdrop-filter: blur(18px) saturate(1.3);
  box-shadow: 0 24px 60px rgba(0, 0, 0, .6);
}
/* Only pinned to the viewport bottom when the screen is wide enough for
   the fixed mascot (css/mascot.css, bottom-right) to sit beside the
   1080px list instead of on top of the save button. */
@media (min-width: 1440px) { .castle-save-bar { position: sticky; bottom: 16px; } }
.dock-status { display: flex; align-items: center; gap: 14px; min-width: 0; flex: 1 1 320px; }
.dock-icon {
  flex-shrink: 0; width: 46px; height: 46px; border-radius: 14px; display: grid; place-items: center;
  background: linear-gradient(145deg, #1d1d1d, #0e0e0e); border: 1px solid var(--h-line); color: var(--h-muted);
  transition: color .3s, border-color .3s, box-shadow .3s;
}
.castle-save-bar.all-done .dock-icon { color: var(--h-lime); border-color: var(--h-lime-line); box-shadow: 0 0 20px rgba(190, 242, 100, .18); }
/* Dock status icon: the checks redraw on hover and once when the last
   castle is filled. The other dock icons' motion is shared by every v2
   page — see "Icon motion" in css/theme-v2.css. */
.ico-checks { stroke-dasharray: 1; stroke-dashoffset: 0; }
.castle-save-bar:hover .ico-checks,
.castle-save-bar.all-done .ico-checks { animation: ico-draw .8s cubic-bezier(.23, 1, .32, 1); }
@media (prefers-reduced-motion: reduce) {
  .castle-save-bar:hover .ico-checks, .castle-save-bar.all-done .ico-checks { animation: none; }
}
.dock-text { display: flex; flex-direction: column; gap: 6px; min-width: 0; flex: 1; }
.dock-count { font: 800 15px 'Anuphan', sans-serif; font-variant-numeric: tabular-nums; }
.dock-meter { display: block; height: 4px; max-width: 260px; border-radius: 4px; background: rgba(250, 250, 250, .08); overflow: hidden; }
.dock-meter i { display: block; height: 100%; width: 0; border-radius: inherit; background: var(--h-fg); transition: width .6s cubic-bezier(.23, 1, .32, 1); }
.castle-save-bar.all-done .dock-meter i { background: var(--h-lime); box-shadow: 0 0 8px var(--h-lime); }
.castle-save-bar .castle-save-status { text-align: left; min-height: 0; font-size: 12px; line-height: 1.5; }
.dock-actions { display: flex; align-items: center; flex-wrap: wrap; gap: 8px; }
/* Mockup: small dashed chip under the dock, owner-only */
.castle-save-bar .castle-mock-btn {
  flex-basis: 100%; justify-content: center; order: 3;
  display: inline-flex; align-items: center; gap: 8px; padding: 8px 14px; border: 0; border-radius: 999px; cursor: pointer;
  font: 700 12px 'Anuphan', sans-serif;
}
.castle-save-bar .castle-mock-btn svg { width: 14px; height: 14px; }
.castle-save-status { font: 500 12.5px 'Anuphan', sans-serif; color: var(--h-muted); min-height: 16px; text-align: center; }

/* ===== STEP 2: team-row editor ===== */
.castle-grid-head { margin-bottom: 24px; }
.castle-grid-head .page-head-actions { margin-bottom: 28px; }
.castle-clear-bar { display: flex; flex-wrap: wrap; align-items: center; gap: 10px; }
.castle-grid-title { display: flex; align-items: center; gap: 16px; }
.castle-grid-icon { width: 58px; height: 58px; border-radius: 16px; }
.castle-grid-icon svg { width: 30px; height: 30px; }
.castle-grid-save-status { text-align: left; margin-top: 14px; }
.castle-last-saved { font: 500 12px/1.5 'Anuphan', sans-serif; color: var(--h-muted); min-height: 16px; margin-top: 4px; }
.castle-last-saved span { display: inline; }
.castle-last-saved .castle-pick-lastsaved-name { color: var(--h-fg); font-weight: 700; margin: 0 .35em; }
.castle-last-saved .castle-pick-lastsaved-time::before { content: '· '; }

/* Picker panel (left) + team rows (right), side by side. */
.castle-grid-layout { display: flex; align-items: flex-start; gap: 24px; width: 100%; }

/* ===== คลัง — the reference portfolio's card language: kicker label +
   big title, a segmented pill tab bar, slim tier section labels with a
   hairline, and tile chips that lift and glow in their element colour. */
.castle-picker-panel {
  /* The frequently-scanned area — gets whatever width is left once the
     fixed-size team rows take theirs, so more hero chips fit per row. */
  flex: 1 1 auto; min-width: 0; margin-bottom: 0; overflow: hidden;
  display: flex; flex-direction: column; gap: 14px;
  padding: clamp(18px, 2vw, 28px);
  position: sticky; top: 96px; /* clears the fixed glass header */
  /* Viewport-tall; the chip grid scrolls inside it. */
  max-height: calc(100vh - 116px);
}
.castle-picker-panel::before {
  content: ''; position: absolute; inset: 0; border-radius: inherit; pointer-events: none;
  background: radial-gradient(70% 50% at 0% 0%, rgba(255, 255, 255, .05), transparent 65%);
}
.picker-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 12px; flex: 0 0 auto; }
.picker-kicker { display: block; margin-bottom: 8px; font: 600 12px 'Anuphan', sans-serif; letter-spacing: .06em; } /* Thai reads badly at .label's wide tracking */
.picker-head .panel-title { font-size: clamp(22px, 2vw, 30px); line-height: 1.1; }
.picker-count {
  flex-shrink: 0; padding: 6px 14px; border-radius: 999px; background: #1a1a1a;
  font: 700 12px 'Anuphan', sans-serif; font-variant-numeric: tabular-nums; color: var(--h-muted);
}
.picker-tools { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; flex: 0 0 auto; }
.picker-tools .search-bar { flex: 1 1 260px; margin: 0; }
#heroPickerFilterRow { flex: 0 0 auto; }

/* Segmented tab bar — like the header nav pills */
.picker-tabs {
  display: flex; gap: 4px; flex: 0 0 auto; padding: 4px; overflow-x: auto; scrollbar-width: none;
  background: #0c0c0c; border: 1px solid var(--h-line); border-radius: 999px;
}
.picker-tabs::-webkit-scrollbar { display: none; }
.picker-tabs[hidden] { display: none; }
.picker-tab {
  flex: 0 0 auto; display: inline-flex; align-items: center; gap: 7px;
  padding: 8px 15px; border: 0; border-radius: 999px; background: transparent; cursor: pointer;
  font: 700 12.5px 'Anuphan', 'Inter', sans-serif; color: var(--h-muted);
  transition: background .25s, color .25s, transform .3s cubic-bezier(.23, 1, .32, 1);
}
.picker-tab b { font: 600 10.5px 'Inter', sans-serif; opacity: .55; }
.picker-tab:hover { color: var(--h-fg); }
.picker-tab:active { transform: scale(.95); }
.picker-tab.active { background: rgba(255, 255, 255, .1); color: #fff; }
.picker-tab:focus-visible { outline: 2px solid var(--h-lime); outline-offset: 1px; }

/* Tier colour dot — same hues as style.css's .palette-tier-* */
.picker-dot { width: 7px; height: 7px; border-radius: 50%; flex-shrink: 0; background: var(--tc, #a3a3a3); box-shadow: 0 0 8px var(--tc, transparent); }
:is(.picker-tab, .picker-section)[data-tier="0"] { --tc: #fb923c; }
:is(.picker-tab, .picker-section)[data-tier="1"] { --tc: #f5a623; }
:is(.picker-tab, .picker-section)[data-tier="2"] { --tc: #e879f9; }
:is(.picker-tab, .picker-section)[data-tier="3"] { --tc: #a78bfa; }
:is(.picker-tab, .picker-section)[data-tier="4"] { --tc: #818cf8; }
:is(.picker-tab, .picker-section)[data-tier="5"] { --tc: #f87171; }
:is(.picker-tab, .picker-section)[data-tier="6"] { --tc: #60a5fa; }

.page-v2 .castle-picker-grid {
  flex: 1; min-height: 0; margin: 0 -8px; padding: 6px 8px 14px; overflow-y: auto;
  max-height: none; /* override .hero-grid's 320px cap — bounded by the panel instead */
  display: grid; grid-template-columns: repeat(auto-fill, minmax(96px, 1fr)); gap: 10px; align-content: start;
  /* max-content rows: the chips clip their glow (overflow: hidden), which
     would otherwise let the fixed-height grid squash its auto rows to 0. */
  grid-auto-rows: max-content;
  background: transparent; border: 0; border-radius: 0;
}
.picker-section {
  grid-column: 1 / -1; display: flex; align-items: center; gap: 10px; margin-top: 16px;
  font: 700 10.5px 'Inter', 'Anuphan', sans-serif; letter-spacing: .22em; text-transform: uppercase; color: var(--h-fg);
}
.picker-section:first-child { margin-top: 2px; }
.picker-section em { flex: 1; height: 1px; background: linear-gradient(90deg, var(--h-line), transparent); }
.picker-section b { font-weight: 600; letter-spacing: .05em; color: var(--h-muted); }
.picker-empty { grid-column: 1 / -1; margin: 0; padding: 48px 0; text-align: center; font: 500 13px 'Anuphan', sans-serif; color: var(--h-muted); }

/* ===== Team rows panel — same header as the คลัง; rows highlight on
   hover; slots are tiles that glow in the hero's element colour, the
   remove × only shows on hover (always on touch), the slot being filled
   gets a lime border that runs around it, and an empty pet slot shows a
   paw instead of +. */
.castle-rows-panel {
  flex: 0 0 540px; width: 540px; margin-bottom: 0;
  display: flex; flex-direction: column; gap: 14px; padding: clamp(18px, 2vw, 26px);
}
.castle-rows-panel::before {
  content: ''; position: absolute; inset: 0; border-radius: inherit; pointer-events: none;
  background: radial-gradient(70% 40% at 100% 0%, rgba(255, 255, 255, .045), transparent 65%);
}
.castle-rows { display: flex; flex-direction: column; gap: 2px; }

.castle-row {
  display: flex; align-items: center; gap: 12px;
  margin: 0 -10px; padding: 7px 10px; border-radius: 16px;
  transition: background .25s, opacity .6s cubic-bezier(.23, 1, .32, 1), transform .6s cubic-bezier(.23, 1, .32, 1), filter .6s;
}
.castle-row:hover { background: rgba(255, 255, 255, .035); }

.castle-row-label {
  width: 28px; height: 28px; border-radius: 50%; flex: 0 0 auto;
  display: grid; place-items: center;
  background: var(--h-mcard-bg); border: 1px solid var(--h-line); color: var(--h-fg);
  font: 700 11px 'JetBrains Mono', monospace;
}
/* This team (row) isn't at the full 3 heroes yet. */
.castle-row-label.incomplete { background: rgba(244, 63, 94, .12); border-color: rgba(244, 63, 94, .45); color: var(--h-rose); }

/* Row copy / paste icon buttons (js/castle.js renderRows) — quiet until
   the row is hovered. */
.castle-page .castle-row-copy-btn, .castle-page .castle-row-paste-btn { width: 28px; height: 28px; color: var(--h-muted); }
.castle-page .castle-row-copy-btn { opacity: .35; }
.castle-row:hover .castle-row-copy-btn, .castle-page .castle-row-copy-btn:focus-visible, .castle-page .castle-row-copy-btn.copied { opacity: 1; }
.castle-page .castle-row-copy-btn:hover { color: var(--h-fg); }
.castle-page .castle-row-paste-btn { color: var(--h-lime); background: rgba(190, 242, 100, .1); }
.castle-page .castle-row-paste-btn:hover:not(:disabled) { background: var(--h-lime); color: #0a0a0a; }

.castle-row-slots { display: flex; gap: 10px; flex: 1; }

/* Thin separator right before the pet slot, kept tight so the pet slot
   reads as "right next to" the 3 hero slots, not a 4th equal member. */
.castle-row-divider { width: 1px; align-self: stretch; margin: 4px -2px 4px 2px; background: linear-gradient(transparent, var(--h-line), transparent); }

.castle-slot {
  --el: 250, 250, 250;
  position: relative; flex: 0 0 auto;
  width: 60px; height: 60px; border-radius: 16px; overflow: hidden;
  border: 1.5px dashed rgba(250, 250, 250, .14); background: #080808;
  display: flex; align-items: center; justify-content: center; cursor: pointer;
  transition: border-color .2s, transform .3s cubic-bezier(.23, 1, .32, 1), box-shadow .3s, background .2s;
}
.castle-slot[data-element="light"] { --el: 250, 204, 21; }
.castle-slot[data-element="fire"] { --el: 249, 115, 22; }
.castle-slot[data-element="dark"] { --el: 168, 85, 247; }
.castle-slot[data-element="water"] { --el: 56, 189, 248; }
.castle-slot[data-element="ground"] { --el: 180, 132, 72; }
.castle-slot:hover { transform: translateY(-3px); }
.castle-slot.filled {
  border: 1px solid rgba(var(--el), .35);
  box-shadow: 0 8px 18px rgba(0, 0, 0, .5), inset 0 -10px 16px -10px rgba(var(--el), .5);
}
.castle-slot.filled:hover { border-color: rgba(var(--el), .8); box-shadow: 0 12px 24px rgba(0, 0, 0, .55), 0 0 18px rgba(var(--el), .35); }
.castle-slot img { width: 100%; height: 100%; object-fit: cover; transition: transform .45s cubic-bezier(.23, 1, .32, 1); }
.castle-slot.filled:hover img { transform: scale(1.08); }

.castle-add-slot .slot-plus { display: grid; place-items: center; color: rgba(250, 250, 250, .35); transition: color .2s, transform .3s cubic-bezier(.23, 1, .32, 1); }
.castle-add-slot:hover { border-color: rgba(190, 242, 100, .55); background: rgba(190, 242, 100, .04); }
.castle-add-slot:hover .slot-plus { color: var(--h-lime); transform: rotate(90deg); }
.castle-pet-slot.castle-add-slot:hover .slot-plus { transform: scale(1.12) rotate(-10deg); }

/* The slot the คลัง is filling: a lime arc running around its border
   (@property-animated conic gradient; a static lime border where
   @property isn't supported) plus a soft glow. */
@property --slot-a { syntax: '<angle>'; initial-value: 0deg; inherits: false; }
.castle-slot.waiting {
  border: 1.5px solid transparent;
  background:
    linear-gradient(#0b0f06, #0b0f06) padding-box,
    conic-gradient(from var(--slot-a), var(--h-lime), rgba(190, 242, 100, .1) 35%, rgba(190, 242, 100, .1) 65%, var(--h-lime)) border-box;
  box-shadow: 0 0 0 3px rgba(190, 242, 100, .1), 0 0 18px rgba(190, 242, 100, .3);
  animation: slot-run 1.8s linear infinite;
}
.castle-slot.waiting .slot-plus { color: var(--h-lime); }
@keyframes slot-run { to { --slot-a: 360deg; } }

.castle-slot .slot-remove {
  position: absolute; top: 4px; right: 4px; z-index: 3;
  width: 20px; height: 20px; border-radius: 50%; border: 0; padding: 0; cursor: pointer;
  display: grid; place-items: center;
  background: rgba(0, 0, 0, .7); color: #fff; backdrop-filter: blur(6px); -webkit-backdrop-filter: blur(6px);
  opacity: 0; transform: scale(.6);
  transition: opacity .2s, transform .25s cubic-bezier(.23, 1, .32, 1), background .2s;
}
.castle-slot:hover .slot-remove, .castle-slot .slot-remove:focus-visible { opacity: 1; transform: none; }
.castle-slot .slot-remove:hover { background: var(--h-rose); }
@media (hover: none) { .castle-slot .slot-remove { opacity: 1; transform: none; } }

.castle-pet-slot { border-radius: 50%; }
.castle-pet-slot.filled { border: 1.5px solid rgba(244, 114, 182, .6); box-shadow: 0 8px 18px rgba(0, 0, 0, .5), 0 0 14px rgba(244, 114, 182, .22); }
.castle-pet-slot.filled:hover { border-color: #f472b6; box-shadow: 0 12px 24px rgba(0, 0, 0, .55), 0 0 20px rgba(244, 114, 182, .4); }
.castle-pet-slot .slot-remove { top: 2px; right: 2px; }

/* ===== Paste banner (css/draft-teams.css base) ===== */
.castle-page .castle-paste-banner {
  position: sticky; top: 88px; z-index: 20;
  margin: 0 0 20px; padding: 10px 14px; border-radius: 16px;
  background: rgba(20, 24, 12, .92); border: 1px solid var(--h-lime-line); color: var(--h-fg);
  font-family: 'Anuphan', sans-serif; backdrop-filter: blur(10px); -webkit-backdrop-filter: blur(10px);
}
.castle-paste-banner-icon { display: inline-grid; color: var(--h-lime); }
.castle-page .castle-paste-banner-heroes img { border-radius: 8px; border: 1px solid var(--h-line); }

/* ===== Modals (confirm + Draft picker) ===== */
/* The dark overlay/box skin and their open/close motion live in css/home.css (Popups). */
.castle-page .dp-close-btn { color: var(--h-muted); }
.castle-page .draft-pick-card:hover .saved-team-castle { color: var(--h-lime); }
.castle-page .counter-count { display: inline-flex; align-items: center; gap: 5px; }

/* js/castle.js's showConfirm/showAlert — styled stand-in for the native
   confirm()/alert() popups (see castle.html's #confirmModal). */
.confirm-modal-message { font-size: 14px; line-height: 1.7; white-space: pre-wrap; margin-bottom: 20px; }
.confirm-modal-actions { display: flex; justify-content: flex-end; gap: 10px; }

@media (max-width: 1050px) {
  .castle-grid-layout { flex-direction: column; }
  .castle-picker-panel { position: static; max-height: 60vh; width: 100%; }
  .castle-rows-panel { flex: 1 1 auto; width: 100%; }
}
@media (max-width: 680px) {
  .castle-save-bar { padding: 14px; border-radius: 22px; }
  .dock-actions { width: 100%; }
  .dock-actions .pill-btn { flex: 1 1 auto; }
  .dock-actions .btn-publish { flex-basis: 100%; order: 3; }
  .castle-pick-row > .castle-pick-btn { flex-basis: calc(50% - 6px); }
  .castle-pick-btn { padding: 14px; }
  .castle-grid-head .page-head-actions { flex-direction: column; align-items: stretch; }
  .castle-clear-bar .pill-btn { flex: 1 1 auto; justify-content: center; }
  .castle-slot { width: 50px; height: 50px; }
  .castle-row { gap: 8px; }
  .castle-row-slots { gap: 6px; }
}

/* "กรอบสีแดง" in the page hint reads in the same rose as the incomplete cards */
.page-hint .hint-red { color: var(--h-rose); }

/* ===== Team-row editor motion (js/castle.js) ===== */

/* "7/10 ทีม" progress under the castle title — group colour via --g,
   one-shot glow (.just-complete) the moment the last team is filled. */
.castle-grid-progress { --g: 250, 250, 250; display: flex; align-items: center; gap: 14px; max-width: 520px; margin-top: 16px; }
.castle-grid-progress.g-outer { --g: 56, 189, 248; }
.castle-grid-progress.g-inner { --g: 167, 139, 250; }
.castle-grid-progress.g-main { --g: 234, 179, 8; }
.castle-grid-progress-bar { flex: 1; height: 6px; border-radius: 6px; background: rgba(250, 250, 250, .08); overflow: hidden; }
.castle-grid-progress-bar i {
  display: block; height: 100%; width: 0; border-radius: inherit;
  background: linear-gradient(90deg, rgba(var(--g), .55), rgb(var(--g))); box-shadow: 0 0 10px rgba(var(--g), .55);
  transition: width .6s cubic-bezier(.23, 1, .32, 1);
}
.castle-grid-progress-text { flex-shrink: 0; font: 600 12.5px 'Anuphan', sans-serif; font-variant-numeric: tabular-nums; color: var(--h-muted); }
.castle-grid-progress.complete .castle-grid-progress-text { color: rgb(var(--g)); }
.castle-grid-progress.just-complete .castle-grid-progress-bar { animation: grid-progress-glow 1.4s ease-out; }
@keyframes grid-progress-glow {
  0% { box-shadow: 0 0 0 0 rgba(var(--g), .7); }
  40% { box-shadow: 0 0 0 6px rgba(var(--g), .25), 0 0 26px rgba(var(--g), .6); }
  100% { box-shadow: 0 0 0 0 rgba(var(--g), 0); }
}

/* Complete row: check instead of the number, brief flash when it just
   became complete. */
.castle-row-label.done { background: rgba(190, 242, 100, .14); border-color: rgba(190, 242, 100, .45); color: var(--h-lime); }
.castle-row.just-done .castle-row-label { animation: row-done-pop .6s cubic-bezier(.23, 1, .32, 1); }
.castle-row.just-done .castle-row-slots .castle-slot { animation: row-done-flash .8s ease-out; }
@keyframes row-done-pop { 0% { transform: scale(.6); } 60% { transform: scale(1.25); } 100% { transform: scale(1); } }
@keyframes row-done-flash { 0% { box-shadow: 0 0 0 0 rgba(190, 242, 100, .6); } 50% { box-shadow: 0 0 0 3px rgba(190, 242, 100, .35), 0 0 18px rgba(190, 242, 100, .4); } 100% { box-shadow: 0 6px 16px rgba(0, 0, 0, .45); } }

/* Pick flies from the คลัง into its slot (flyPickToSlot) */
.castle-fly-ghost {
  position: fixed; z-index: 9000; pointer-events: none; object-fit: cover;
  border-radius: 12px; border: 1px solid rgba(250, 250, 250, .4);
  box-shadow: 0 18px 40px rgba(0, 0, 0, .6), 0 0 24px rgba(190, 242, 100, .35);
  transform-origin: center; will-change: transform;
}
.castle-fly-ghost.pet { border-radius: 50%; }
.castle-slot.landing img { opacity: 0; }
.castle-slot.landed { animation: slot-land .45s cubic-bezier(.23, 1, .32, 1); }
@keyframes slot-land { 0% { transform: scale(.82); } 55% { transform: scale(1.12); } 100% { transform: scale(1); } }

/* คลัง chip tiles: lift, element-colour glow and a top spotlight on hover;
   ones already used in this castle dimmed with a check / count badge. */
.page-v2 .castle-picker-grid .hero-chip {
  --el: 250, 250, 250;
  position: relative; overflow: hidden; isolation: isolate; width: auto;
  padding: 8px 8px 10px; gap: 7px; border-radius: 16px; cursor: pointer;
  background: #0e0e0e; border: 1px solid rgba(255, 255, 255, .06);
  transition: transform .35s cubic-bezier(.23, 1, .32, 1), border-color .25s, background .25s, box-shadow .35s;
}
.castle-picker-grid .hero-chip[data-element="light"] { --el: 250, 204, 21; }
.castle-picker-grid .hero-chip[data-element="fire"] { --el: 249, 115, 22; }
.castle-picker-grid .hero-chip[data-element="dark"] { --el: 168, 85, 247; }
.castle-picker-grid .hero-chip[data-element="water"] { --el: 56, 189, 248; }
.castle-picker-grid .hero-chip[data-element="ground"] { --el: 180, 132, 72; }
.castle-picker-grid .hero-chip::before {
  content: ''; position: absolute; inset: 0; z-index: -1; pointer-events: none;
  background: radial-gradient(120% 70% at 50% 0%, rgba(var(--el), .22), transparent 70%);
  opacity: 0; transition: opacity .35s;
}
.page-v2 .castle-picker-grid .hero-chip img {
  width: 100%; height: auto; aspect-ratio: 1; border: 0; border-radius: 11px; background: #151515;
  transition: transform .45s cubic-bezier(.23, 1, .32, 1), opacity .25s, filter .25s;
}
.page-v2 .castle-picker-grid .hero-chip span { max-width: 100%; font: 600 11px 'Anuphan', sans-serif; color: var(--h-muted); transition: color .2s; }
.page-v2 .castle-picker-grid .hero-chip:hover {
  transform: translateY(-4px); background: #121212; border-color: rgba(var(--el), .55);
  box-shadow: 0 14px 30px rgba(0, 0, 0, .5), 0 0 22px rgba(var(--el), .18);
}
.castle-picker-grid .hero-chip:hover::before { opacity: 1; }
.castle-picker-grid .hero-chip:hover img { transform: scale(1.06); }
.page-v2 .castle-picker-grid .hero-chip:hover span { color: var(--h-fg); }
.page-v2 .castle-picker-grid .hero-chip:active { transform: translateY(-1px) scale(.96); }
.castle-picker-grid .hero-chip.used img { opacity: .35; filter: grayscale(.6); }
.castle-picker-grid .hero-chip.used:hover img { opacity: .85; filter: none; }
.chip-used {
  position: absolute; top: 6px; right: 6px; z-index: 2;
  min-width: 20px; height: 20px; padding: 0 5px; border-radius: 999px; display: grid; place-items: center;
  background: var(--h-lime); color: #0a0a0a; font: 800 11px 'Inter', sans-serif;
  box-shadow: 0 2px 8px rgba(0, 0, 0, .5);
}

/* Rows rise in when a castle opens (renderRows animateRowsNext) */
.castle-row.rise { transition-delay: calc(var(--i, 0) * 35ms); }
.castle-row.rise:not(.risen) { opacity: 0; transform: translateY(18px); filter: blur(4px); }

/* Copy icon → check for a moment after copying a row (flashCopied) */
.castle-page .castle-row-copy-btn.copied { background: var(--h-lime); color: #0a0a0a; animation: row-done-pop .45s cubic-bezier(.23, 1, .32, 1); }

@media (prefers-reduced-motion: reduce) {
  .castle-row.just-done .castle-row-label, .castle-row.just-done .castle-row-slots .castle-slot,
  .castle-slot.landed, .castle-grid-progress.just-complete .castle-grid-progress-bar { animation: none; }
}

/* ===== Our own portrait frames ===== The hero/pet art ships with the
   game's frame baked in (white rim + rarity border). Zooming the image
   ~11% crops that off, and a thin ring in the tier colour (pets: pink)
   plus a soft bottom glow is drawn on top instead — same frame in the
   team slots and the คลัง. The class icon stays visible in the corner. */
.castle-slot[data-tier], .castle-picker-grid .hero-chip[data-tier] { --tier: 250, 250, 250; }
[data-tier="0"].castle-slot, .hero-chip[data-tier="0"] { --tier: 251, 146, 60; }
[data-tier="1"].castle-slot, .hero-chip[data-tier="1"] { --tier: 245, 166, 35; }
[data-tier="2"].castle-slot, .hero-chip[data-tier="2"] { --tier: 232, 121, 249; }
[data-tier="3"].castle-slot, .hero-chip[data-tier="3"] { --tier: 167, 139, 250; }
[data-tier="4"].castle-slot, .hero-chip[data-tier="4"] { --tier: 129, 140, 248; }
[data-tier="5"].castle-slot, .hero-chip[data-tier="5"] { --tier: 248, 113, 113; }
[data-tier="6"].castle-slot, .hero-chip[data-tier="6"] { --tier: 96, 165, 250; }
.castle-pet-slot, .castle-picker-grid .hero-chip[data-kind="pet"] { --tier: 244, 114, 182; }

/* team slots */
.castle-slot.filled img { transform: scale(1.11); }
.castle-slot.filled:hover img { transform: scale(1.18); }
.castle-slot.filled::after {
  content: ''; position: absolute; inset: 0; z-index: 2; pointer-events: none; border-radius: inherit;
  box-shadow: inset 0 0 0 1.5px rgba(var(--tier, 250, 250, 250), .8), inset 0 -16px 18px -14px rgba(var(--tier, 250, 250, 250), .75);
}
.castle-slot.filled { border-color: transparent; }
.castle-slot.filled:hover { border-color: transparent; }
.castle-slot.filled:hover::after { box-shadow: inset 0 0 0 2px rgba(var(--tier, 250, 250, 250), 1), inset 0 -18px 20px -12px rgba(var(--tier, 250, 250, 250), .9); }

/* คลัง chips */
.castle-picker-grid .chip-art {
  position: relative; display: block; width: 100%; aspect-ratio: 1; overflow: hidden;
  border-radius: 12px; background: #151515;
}
.page-v2 .castle-picker-grid .hero-chip .chip-art img { display: block; width: 100%; height: 100%; object-fit: cover; border-radius: 0; transform: scale(1.11); }
.castle-picker-grid .hero-chip:hover .chip-art img { transform: scale(1.18); }
.castle-picker-grid .chip-art::after {
  content: ''; position: absolute; inset: 0; pointer-events: none; border-radius: inherit;
  box-shadow: inset 0 0 0 1.5px rgba(var(--tier, 250, 250, 250), .75), inset 0 -18px 20px -14px rgba(var(--tier, 250, 250, 250), .7);
  transition: box-shadow .3s;
}
.castle-picker-grid .hero-chip:hover .chip-art::after { box-shadow: inset 0 0 0 2px rgba(var(--tier, 250, 250, 250), 1), inset 0 -20px 22px -12px rgba(var(--tier, 250, 250, 250), .9); }
.castle-picker-grid .hero-chip.used .chip-art img { opacity: .35; filter: grayscale(.6); }
.castle-picker-grid .hero-chip.used:hover .chip-art img { opacity: .85; filter: none; }
.page-v2 .castle-picker-grid .hero-chip .chip-name { max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* Demon Slayer: Infinity Castle collab (html.collab-ic, set by
   js/page-transition.js through 28 Oct): a small 無限城 beside the title and
   biwa strings under it that strike once when the list opens. */
html.collab-ic .collab-castle {
  display: inline-block; margin-left: .5em; padding-left: .55em; vertical-align: .35em;
  border-left: 1px solid rgba(255,170,100,.3); color: rgba(255,190,130,.75);
  font: 700 .3em/1 'Noto Serif JP', 'Yu Mincho', 'Hiragino Mincho ProN', serif; letter-spacing: .25em;
  text-shadow: 0 0 18px rgba(255,120,60,.45);
}
html.collab-ic .collab-biwa { display: block; width: min(440px, 80%); height: 34px; margin: 4px 0 -4px; }

/* ===== "อ่านทีมจากรูป" modal (js/castle.js Scan section) ===== */
.scan-box { max-width: 680px; max-height: 86vh; display: flex; flex-direction: column; gap: 12px; }
.scan-head { display: flex; justify-content: space-between; align-items: center; }
.scan-hint { margin: 0; font-size: 13px; line-height: 1.6; color: var(--h-muted); }
/* Same look as counter.html's "อ่านค่าจากรูป" menu (.ce-ocr-menu in css/counter-editor-v2.css). */
.scan-menu-wrap { position: relative; display: inline-flex; }
.scan-menu {
  position: absolute; right: 0; top: calc(100% + 6px); z-index: 30; width: min(260px, calc(100vw - 32px));
  display: flex; flex-direction: column; gap: 6px; padding: 10px; border-radius: 16px;
  background: #111; border: 1px solid var(--h-line); box-shadow: 0 18px 40px rgba(0, 0, 0, .6);
}
.scan-menu[hidden] { display: none; }
.scan-menu button {
  padding: 9px 12px; border-radius: 10px; border: 1px solid var(--h-line); background: #181818; color: var(--h-fg);
  font: 600 13px 'Anuphan', sans-serif; text-align: left; cursor: pointer; transition: border-color .2s, color .2s;
}
.scan-menu button:hover, .scan-menu button:focus-visible { border-color: var(--h-lime); color: var(--h-lime); outline: none; }
.scan-menu p { margin: 2px 2px 0; font: 500 12px/1.5 'Anuphan', sans-serif; color: var(--h-muted); }
.scan-menu kbd { padding: 1px 5px; border-radius: 5px; border: 1px solid var(--h-line); background: #1c1c1c; font: 600 11px 'Inter', sans-serif; color: var(--h-fg); }
/* Inside the results window: the two buttons side by side, no floating box. */
.scan-menu.scan-menu-inline {
  position: static; width: auto; flex-direction: row; flex-wrap: wrap; padding: 0;
  background: none; border: 0; box-shadow: none;
}
.scan-menu.scan-menu-inline p { flex: 1 1 100%; }
.scan-box.over { border-color: var(--h-lime); }
.scan-status { font-size: 13px; color: var(--h-muted); min-height: 1em; }
.scan-status:empty { display: none; }
.scan-rows { overflow-y: auto; display: flex; flex-direction: column; gap: 6px; padding-right: 2px; }
.scan-row {
  display: flex; align-items: center; gap: 10px; padding: 6px 10px;
  border: 1px solid var(--h-line); border-radius: 12px; cursor: pointer;
}
.scan-row.off { opacity: .4; }
.scan-row input { accent-color: var(--h-lime); }
.scan-row-num { width: 1.6em; font-size: 12px; color: var(--h-muted); font-variant-numeric: tabular-nums; }
.scan-row-heroes { display: flex; gap: 6px; }
.scan-row-pet { margin-left: auto; padding-left: 10px; border-left: 1px solid var(--h-line); }
.scan-slot { position: relative; width: 44px; height: 44px; border-radius: 9px; overflow: hidden; border: 1px solid var(--h-line); }
.scan-slot img { width: 100%; height: 100%; object-fit: cover; display: block; }
.scan-slot.empty { border-style: dashed; }
.scan-slot { overflow: visible; }
.scan-slot img { border-radius: 8px; }
/* Unsure guess: yellow ring outside the game's own coloured frame + "!" badge. */
.scan-slot.unsure { outline: 2px solid #facc15; outline-offset: 2px; }
.scan-slot.unsure::after {
  content: "!"; position: absolute; right: -6px; top: -6px; width: 16px; height: 16px; border-radius: 50%;
  display: grid; place-items: center; background: #facc15; color: #000; font: 700 11px/1 'Inter', sans-serif;
}
.scan-slot.unknown img { filter: grayscale(1) brightness(.45); }
.scan-slot.unknown span {
  position: absolute; inset: 0; display: grid; place-items: center;
  font-weight: 700; font-size: 18px; color: var(--h-fg);
}
.scan-foot { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; }
.scan-foot[hidden] { display: none; }
.scan-legend { display: flex; flex-wrap: wrap; align-items: center; gap: 4px 12px; font-size: 12px; color: var(--h-muted); }
.scan-legend-item { display: inline-flex; align-items: center; gap: 6px; }
.scan-key { display: inline-grid; place-items: center; width: 16px; height: 16px; flex: none; border-radius: 50%; font: 700 11px/1 'Inter', sans-serif; font-style: normal; }
.scan-key.unsure { background: #facc15; color: #000; }
.scan-key.unknown { border-radius: 4px; background: #3a3a3a; color: var(--h-fg); }
.scan-foot .pill-btn:disabled { opacity: .4; pointer-events: none; }
@media (max-width: 480px) {
  .scan-slot { width: 38px; height: 38px; }
  .scan-row { gap: 6px; padding: 6px 8px; }
}

/* Slots in the scan list are buttons (tap to pick / correct). */
button.scan-slot { padding: 0; background: none; cursor: pointer; font: inherit; color: inherit; }
button.scan-slot:hover { border-color: rgba(250, 250, 250, .45); }
button.scan-slot:focus-visible { outline: 2px solid var(--h-lime); outline-offset: 2px; }
.scan-row { cursor: default; }

/* Manual pick popup */
.scan-pick-box { max-width: 620px; max-height: 88vh; display: flex; flex-direction: column; gap: 12px; }
.scan-pick-top { display: flex; gap: 14px; align-items: flex-start; }
.scan-pick-crop { width: 112px; height: 112px; flex: none; border-radius: 14px; border: 1px solid var(--h-line); object-fit: cover; background: #111; }
.scan-pick-tools { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 8px; }
.scan-pick-elements { display: flex; gap: 6px; flex-wrap: wrap; }
.scan-pick-elements[hidden] { display: none; }
.scan-pick-grid {
  overflow-y: auto; display: grid; gap: 8px; padding: 2px;
  grid-template-columns: repeat(auto-fill, minmax(72px, 1fr));
}
.scan-pick-chip {
  display: flex; flex-direction: column; align-items: center; gap: 4px; padding: 6px 4px;
  border: 1px solid var(--h-line); border-radius: 12px; background: none; color: var(--h-fg);
  font: inherit; font-size: 11px; cursor: pointer; transition: border-color .15s, background .15s;
}
.scan-pick-chip img { width: 52px; height: 52px; border-radius: 9px; object-fit: cover; }
.scan-pick-chip span { max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.scan-pick-chip:hover { border-color: rgba(250, 250, 250, .4); background: var(--h-card); }
.scan-pick-chip.current { border-color: var(--h-lime); }
.scan-pick-chip:focus-visible { outline: 2px solid var(--h-lime); outline-offset: 2px; }
#scanPickClearBtn[hidden] { display: none; }
@media (max-width: 480px) {
  .scan-pick-crop { width: 84px; height: 84px; }
  .scan-pick-grid { grid-template-columns: repeat(auto-fill, minmax(64px, 1fr)); }
}

/* Undo bar after hand-picked portraits are remembered (js/castle.js showScanUndo). */
.scan-undo {
  position: fixed; left: 50%; bottom: 96px; transform: translateX(-50%); z-index: 1200; /* above the toast */
  display: flex; align-items: center; gap: 12px; max-width: min(640px, calc(100vw - 32px));
  padding: 10px 10px 10px 16px; border-radius: 16px; border: 1px solid var(--h-line);
  background: rgba(12, 12, 12, .96); color: var(--h-fg); font-size: 13px; line-height: 1.5;
  box-shadow: 0 16px 40px rgba(0, 0, 0, .5);
}
.scan-undo[hidden] { display: none; }
.scan-undo #scanUndoText { flex: 1; min-width: 0; }
.scan-undo .pill-btn { flex: none; white-space: nowrap; }
.scan-undo .pill-btn[hidden] { display: none; }
@media (max-width: 520px) {
  .scan-undo { flex-wrap: wrap; bottom: 88px; }
}

/* Player name strip + "already seen" note in the scan list. */
.scan-row-who { display: flex; flex-direction: column; gap: 3px; width: 120px; flex: none; min-width: 0; }
.scan-row-name { width: 120px; height: auto; border-radius: 6px; border: 1px solid var(--h-line); }
.scan-row-dup { font-size: 11px; line-height: 1.3; color: #facc15; }
.scan-row.dup { border-style: dashed; }
@media (max-width: 560px) {
  .scan-row { flex-wrap: wrap; }
  .scan-row-who { width: auto; flex: 1 1 100%; flex-direction: row; align-items: center; order: 3; }
}

/* Unsaved-work notice on the castle list (js/castle.js renderUnsavedBar). */
.castle-unsaved-bar {
  display: flex; align-items: center; gap: 12px; flex-wrap: wrap; margin-top: 14px;
  padding: 10px 10px 10px 16px; border-radius: 14px; border: 1px solid rgba(250, 204, 21, .35);
  background: rgba(250, 204, 21, .06); color: var(--h-fg); font-size: 13px; line-height: 1.5;
}
.castle-unsaved-bar[hidden] { display: none; }
.castle-unsaved-bar > span { flex: 1; min-width: 200px; }

/* Castle card with unsaved edits (js/castle.js isCastleDirty). */
.castle-pick-unsaved {
  display: inline-block; margin-top: 4px; padding: 1px 8px; border-radius: 999px;
  border: 1px solid rgba(250, 204, 21, .45); color: #facc15; background: rgba(250, 204, 21, .08);
  font: 600 10.5px/1.6 'Anuphan', sans-serif;
}
.castle-grid-head .castle-unsaved-bar { margin-top: 12px; }
