:root {
  --paper: #f3e8d4;
  --paper-deep: #e8d7b8;
  --ink: #2a241c;
  --ink-soft: #5a4e3f;
  --accent-a: #7a4e2d;
  --accent-b: #3d5a4c;
  --accent-c: #3d4f6a;
  --line: #c4b08a;
  --glow: #d9a441;
  --danger: #8b3a2f;
  --ok: #4a6b4e;
  --shadow: rgba(42, 36, 28, 0.14);
  --lane-win: rgba(217, 164, 65, 0.22);
  --lane-bg: rgba(255, 250, 240, 0.55);
  --safe-t: env(safe-area-inset-top, 0px);
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-l: env(safe-area-inset-left, 0px);
  --safe-r: env(safe-area-inset-right, 0px);
  /* Card widths scale with viewport; short screens shrink further */
  --hand-card-w: clamp(52px, 18vw, 92px);
  --opp-card-w: clamp(34px, 11vw, 56px);
  --lane-card-w: clamp(40px, 14vw, 64px);
  --gap: clamp(0.15rem, 0.6vh, 0.35rem);
  --pad: clamp(0.2rem, 1.2vw, 0.55rem);
  font-family: "Songti SC", "Noto Serif SC", "Source Han Serif SC", "Georgia", serif;
}

* { box-sizing: border-box; }

html {
  height: 100%;
  height: 100dvh;
  overflow: hidden;
}

body {
  margin: 0;
  height: 100%;
  height: 100dvh;
  height: 100svh;
  overflow: hidden;
  overscroll-behavior: none;
  background:
    radial-gradient(ellipse at 50% 0%, #faf3e4 0%, transparent 55%),
    radial-gradient(ellipse at 50% 100%, #e9dcc2 0%, transparent 50%),
    var(--paper);
  color: var(--ink);
  padding:
    var(--safe-t)
    var(--safe-r)
    var(--safe-b)
    var(--safe-l);
}

.app {
  max-width: 720px;
  margin: 0 auto;
  height: 100%;
  max-height: 100%;
  display: flex;
  flex-direction: column;
  padding: var(--pad);
  gap: var(--gap);
  overflow: hidden;
  position: relative;
  min-height: 0;
}

/* ===== Top bar — single thin toolbar ===== */
.topbar {
  display: flex;
  flex-wrap: nowrap;
  align-items: center;
  gap: 0.25rem 0.4rem;
  padding: 0.15rem 0.1rem 0.25rem;
  border-bottom: 1.5px solid var(--ink);
  flex-shrink: 0;
  min-height: 0;
  overflow-x: auto;
  scrollbar-width: none;
}
.topbar::-webkit-scrollbar { display: none; }

.topbar-left {
  display: flex;
  flex-wrap: nowrap;
  gap: 0.25rem;
  align-items: center;
  flex-shrink: 0;
}

.match-title {
  margin: 0;
  font-size: clamp(0.85rem, 3.2vw, 1.25rem);
  letter-spacing: 0.28em;
  font-weight: 700;
  text-align: center;
  padding-left: 0.28em;
  flex: 0 0 auto;
  white-space: nowrap;
}

.turn-badge, .phase-badge {
  border: 1px solid var(--line);
  background: rgba(255,255,255,0.4);
  padding: 0.1rem 0.4rem;
  border-radius: 999px;
  font-size: 0.68rem;
  white-space: nowrap;
}

.phase-badge { border-color: var(--glow); background: #fff6df; }

.controls {
  display: flex;
  flex-wrap: nowrap;
  gap: 0.2rem;
  align-items: center;
  justify-content: flex-end;
  flex-shrink: 0;
}

button {
  font: inherit;
  cursor: pointer;
  border: 1.5px solid var(--ink);
  background: var(--paper);
  color: var(--ink);
  padding: 0.15rem 0.4rem;
  border-radius: 999px;
  font-size: 0.7rem;
  transition: background 0.15s, transform 0.1s;
  white-space: nowrap;
}

button:hover { background: var(--paper-deep); }
button:active { transform: translateY(1px); }
button.primary {
  background: var(--ink);
  color: var(--paper);
}
button.primary:hover { background: #3d3428; }
button:disabled { opacity: 0.45; cursor: not-allowed; }

.speed {
  display: flex;
  align-items: center;
  gap: 0.15rem;
  font-size: 0.68rem;
  color: var(--ink-soft);
}

.speed select {
  font: inherit;
  border: 1px solid var(--line);
  background: var(--paper);
  border-radius: 6px;
  padding: 0.08rem 0.2rem;
  font-size: 0.68rem;
}

/* ===== Player zones ===== */
.player-zone {
  display: flex;
  flex-direction: column;
  gap: 0.15rem;
  flex-shrink: 0;
  padding: 0.2rem 0.35rem;
  border-radius: 8px;
  border: 1.5px solid var(--ink);
  background: rgba(255,255,255,0.28);
  min-height: 0;
  overflow: hidden;
}

.player-zone.opponent {
  border-color: var(--accent-b);
  background: linear-gradient(180deg, rgba(61,90,76,0.08), rgba(255,255,255,0.2));
}

.player-zone.self {
  border-color: var(--accent-a);
  background: linear-gradient(0deg, rgba(122,78,45,0.1), rgba(255,255,255,0.2));
}

.zone-meta {
  display: flex;
  align-items: center;
  gap: 0.35rem;
  flex-wrap: nowrap;
  min-height: 0;
}

.zone-name {
  font-weight: 700;
  letter-spacing: 0.2em;
  font-size: clamp(0.72rem, 2.5vw, 0.9rem);
}

.opponent .zone-name { color: var(--accent-b); }
.self .zone-name { color: var(--accent-a); }

.energy-gem {
  display: inline-flex;
  align-items: center;
  gap: 0.15rem;
  border: 1.5px solid var(--glow);
  background: #fff6df;
  border-radius: 999px;
  padding: 0.05rem 0.4rem;
  font-weight: 700;
  font-size: 0.75rem;
  min-width: 2.6rem;
  justify-content: center;
}

.gem-icon { color: var(--glow); font-size: 0.65rem; }

.total-score {
  font-size: clamp(1rem, 3.5vw, 1.3rem);
  font-weight: 800;
  min-width: 1.6rem;
  text-align: center;
  line-height: 1;
}

.opponent .total-score { color: var(--accent-b); }
.self .total-score { color: var(--accent-a); }

.zone-extra {
  margin-left: auto;
  display: flex;
  gap: 0.45rem;
  font-size: 0.65rem;
  color: var(--ink-soft);
  white-space: nowrap;
}

/* Hands — compact single row */
.hand {
  display: flex;
  gap: 0.2rem;
  overflow-x: auto;
  overflow-y: hidden;
  padding: 0.1rem 0.05rem;
  scrollbar-width: thin;
  align-items: flex-end;
  justify-content: center;
  min-height: 0;
}

.hand-opp {
  align-items: center;
  /* height from cards; no forced min-height */
}

.hand-self {
  /* fan slightly; height from cards */
}

.hand-self .snap-card {
  transition: transform 0.15s;
}
.hand-self .snap-card:nth-child(1) { transform: rotate(-5deg) translateY(3px); }
.hand-self .snap-card:nth-child(2) { transform: rotate(-2.5deg) translateY(1px); }
.hand-self .snap-card:nth-child(3) { transform: rotate(0deg); }
.hand-self .snap-card:nth-child(4) { transform: rotate(2.5deg) translateY(1px); }
.hand-self .snap-card:nth-child(5) { transform: rotate(5deg) translateY(3px); }
.hand-self .snap-card:nth-child(n+6) { transform: rotate(6deg) translateY(4px); }

/* ===== SNAP-like card chrome (portrait 2:3) ===== */
.snap-card {
  --card-w: var(--lane-card-w);
  position: relative;
  width: var(--card-w);
  aspect-ratio: 2 / 3;
  flex: 0 0 auto;
  border-radius: 8px;
  border: 2px solid var(--ink);
  background:
    linear-gradient(165deg, #fffdf6 0%, #f0e2c4 55%, #e6d4ae 100%);
  box-shadow:
    0 1px 0 rgba(42,36,28,0.18),
    0 2px 6px var(--shadow);
  overflow: hidden;
  display: flex;
  flex-direction: column;
  user-select: none;
}

.snap-card.side-a { border-color: var(--accent-a); }
.snap-card.side-b { border-color: var(--accent-b); }
.snap-card.side-c { border-color: var(--accent-c); }

.snap-card.spell {
  border-style: dashed;
  background:
    linear-gradient(165deg, #faf6ec 0%, #ebe0c8 60%, #e0d2b4 100%);
}

.snap-card.highlight {
  outline: 2px solid var(--glow);
  box-shadow: 0 0 0 3px rgba(217,164,65,0.35), 0 2px 6px var(--shadow);
}

.snap-card.flash { animation: flash 0.55s ease; }

.snap-card .badge-cost {
  position: absolute;
  top: 2px;
  left: 2px;
  z-index: 3;
  width: 1.45em;
  height: 1.45em;
  border-radius: 50%;
  border: 1.5px solid var(--ink);
  background: radial-gradient(circle at 35% 30%, #fff8e0, #e8c86a 70%, #c9a038);
  color: var(--ink);
  font-weight: 800;
  font-size: 0.62rem;
  display: flex;
  align-items: center;
  justify-content: center;
  line-height: 1;
  box-shadow: 0 1px 2px var(--shadow);
}

.snap-card .art {
  flex: 1 1 auto;
  margin: 1.5em 4px 0;
  border-radius: 5px 5px 2px 2px;
  border: 1px solid rgba(42,36,28,0.25);
  background:
    radial-gradient(ellipse at 50% 40%, rgba(255,255,255,0.55), transparent 65%),
    repeating-linear-gradient(
      -18deg,
      transparent,
      transparent 6px,
      rgba(42,36,28,0.04) 6px,
      rgba(42,36,28,0.04) 7px
    ),
    linear-gradient(180deg, #efe4cc, #dcc9a4);
  position: relative;
  min-height: 0;
}

.snap-card.side-a .art {
  background:
    radial-gradient(ellipse at 50% 35%, rgba(255,240,220,0.7), transparent 60%),
    linear-gradient(180deg, #f3e0c8, #d4b48a);
}
.snap-card.side-b .art {
  background:
    radial-gradient(ellipse at 50% 35%, rgba(220,240,230,0.7), transparent 60%),
    linear-gradient(180deg, #d8e6de, #a8c0b0);
}
.snap-card.side-c .art {
  background:
    radial-gradient(ellipse at 50% 30%, rgba(170, 190, 220, 0.55), transparent 55%),
    linear-gradient(160deg, #6a7f9a, #3d4f6a 70%);
}
.snap-card.spell .art {
  background:
    radial-gradient(ellipse at 50% 40%, rgba(255,255,255,0.5), transparent 60%),
    repeating-linear-gradient(45deg, #efe6d2, #efe6d2 4px, #e5d9bf 4px, #e5d9bf 8px);
}

.snap-card .art::after {
  content: "";
  position: absolute;
  inset: 18% 22%;
  border: 1px dashed rgba(42,36,28,0.18);
  border-radius: 4px;
  opacity: 0.7;
}

/* ===== Sample art hooks (STYLE.md · layer C only) ===== */
.snap-card .art.has-sample {
  background-image: var(--art-url);
  background-size: cover;
  background-position: center 30%;
  background-repeat: no-repeat;
  border-color: rgba(42,36,28,0.35);
}
.snap-card .art.has-sample::after {
  display: none; /* hide dashed placeholder when sample art present */
}
.snap-card.face-down .art.has-sample {
  background-image: none;
}


.snap-card .name-band {
  flex: 0 0 auto;
  margin: 2px 3px 2px;
  padding: 0.1rem 0.15rem;
  text-align: center;
  background: rgba(42,36,28,0.88);
  color: var(--paper);
  border-radius: 3px;
  font-weight: 700;
  font-size: 0.55rem;
  letter-spacing: 0.03em;
  line-height: 1.15;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  z-index: 2;
}

.snap-card.side-a .name-band { background: rgba(122,78,45,0.92); }
.snap-card.side-b .name-band { background: rgba(61,90,76,0.92); }
.snap-card.side-c .name-band { background: rgba(61,79,106,0.92); }

.snap-card .card-text {
  flex: 0 0 auto;
  margin: 0 3px 1.4em;
  padding: 0 0.08rem;
  font-size: 0.42rem;
  line-height: 1.15;
  color: var(--ink-soft);
  text-align: center;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
  min-height: 0;
}

.snap-card .badge-pwr {
  position: absolute;
  bottom: 2px;
  right: 2px;
  z-index: 3;
  width: 1.45em;
  height: 1.45em;
  border-radius: 50%;
  border: 1.5px solid var(--ink);
  background: radial-gradient(circle at 35% 30%, #e8f0e4, #6a8f6e 65%, #3d5a42);
  color: #fff;
  font-weight: 800;
  font-size: 0.62rem;
  display: flex;
  align-items: center;
  justify-content: center;
  line-height: 1;
  box-shadow: 0 1px 2px var(--shadow);
}

.snap-card.spell .badge-pwr {
  background: radial-gradient(circle at 35% 30%, #eee, #9a9080 70%, #5a5248);
  font-size: 0.5rem;
}

/* Size variants */
.hand-self .snap-card { --card-w: var(--hand-card-w); }
.hand-opp .snap-card {
  --card-w: var(--opp-card-w);
  border-width: 1.5px;
}
.hand-opp .snap-card .badge-cost,
.hand-opp .snap-card .badge-pwr {
  width: 1.3em;
  height: 1.3em;
  font-size: 0.52rem;
  border-width: 1.5px;
  top: 1px; left: 1px;
}
.hand-opp .snap-card .badge-pwr { top: auto; left: auto; bottom: 1px; right: 1px; }
.hand-opp .snap-card .art { margin: 1.2em 2px 0; }
.hand-opp .snap-card .name-band {
  font-size: 0.42rem;
  margin: 1px 1px 1.2em;
  padding: 0.06rem 0.08rem;
}
.hand-opp .snap-card .card-text { display: none; }

.lane-cards .snap-card {
  --card-w: var(--lane-card-w);
  border-width: 1.5px;
}
.lane-cards .snap-card .badge-cost,
.lane-cards .snap-card .badge-pwr {
  width: 1.3em;
  height: 1.3em;
  font-size: 0.55rem;
  border-width: 1.5px;
}
.lane-cards .snap-card .art { margin: 1.25em 2px 0; }
.lane-cards .snap-card .name-band {
  font-size: 0.45rem;
  margin: 1px 1px 1.25em;
  padding: 0.06rem 0.08rem;
}
.lane-cards .snap-card .card-text { display: none; }

@keyframes flash {
  0% { filter: brightness(1.25); transform: scale(1.06); }
  100% { filter: none; transform: scale(1); }
}

/* ===== Three SNAP lanes (middle grows) ===== */
.lanes {
  flex: 1 1 0;
  min-height: 0;
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: clamp(0.15rem, 1vw, 0.4rem);
  container-type: size;
  overflow: hidden;
}

.habitat {
  min-width: 0;
  min-height: 0;
  display: flex;
  flex-direction: column;
  border: 1.5px solid var(--ink);
  border-radius: 8px;
  background: var(--lane-bg);
  overflow: hidden;
}

.habitat.winning {
  background: var(--lane-win);
  box-shadow: inset 0 0 0 1.5px rgba(217, 164, 65, 0.55);
}

.habitat-banner {
  flex-shrink: 0;
  text-align: center;
  padding: 0.15rem 0.2rem 0.1rem;
  border-bottom: 1px solid var(--line);
  background: rgba(255,255,255,0.35);
}

.habitat-banner h3 {
  margin: 0;
  font-size: clamp(0.65rem, 2.4vw, 0.9rem);
  letter-spacing: 0.12em;
  font-weight: 700;
  line-height: 1.2;
}

.habitat-banner .hint {
  font-size: clamp(0.48rem, 1.7vw, 0.62rem);
  color: var(--ink-soft);
  line-height: 1.25;
  margin-top: 0.05rem;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.habitat-banner .hab-icon {
  display: inline-block;
  min-width: 1.1em;
  margin-right: 0.15em;
  font-size: 0.85em;
  opacity: 0.9;
}

.habitat.fog-hidden {
  background: rgba(90, 110, 120, 0.12);
}
.habitat.fog-hidden .lane-score {
  letter-spacing: 0.08em;
  color: var(--ink-soft) !important;
  opacity: 0.85;
}
.habitat[data-key="yangguang"] .habitat-banner { background: rgba(255, 230, 160, 0.45); }
.habitat[data-key="shiji"] .habitat-banner { background: rgba(230, 210, 180, 0.5); }
.habitat[data-key="feita"] .habitat-banner { background: rgba(200, 190, 210, 0.4); }
.habitat[data-key="chaoxi"] .habitat-banner { background: rgba(170, 210, 220, 0.4); }
.habitat[data-key="wuyin"] .habitat-banner { background: rgba(160, 170, 180, 0.45); }
.habitat[data-key="miguan"] .habitat-banner { background: rgba(240, 200, 140, 0.45); }
.habitat[data-key="huisheng"] .habitat-banner { background: rgba(200, 220, 200, 0.45); }
.habitat[data-key="duanqiao"] .habitat-banner { background: rgba(200, 180, 170, 0.45); }
.habitat[data-key="yedeng"] .habitat-banner { background: rgba(80, 70, 100, 0.18); }
.habitat[data-key="daoxiang"] .habitat-banner { background: rgba(210, 230, 160, 0.45); }
.habitat[data-key="chaliao"] .habitat-banner { background: rgba(220, 200, 170, 0.5); }
.habitat[data-key="kongting"] .habitat-banner { background: rgba(190, 210, 200, 0.4); }
.habitat[data-key="yueya"] .habitat-banner { background: rgba(180, 200, 230, 0.45); }

.lane-stack {
  flex: 1 1 0;
  min-height: 0;
  display: flex;
  flex-direction: column;
  gap: 1px;
}

.lane-half {
  flex: 1 1 0;
  min-height: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0.1rem;
  padding: 0.12rem;
  overflow: hidden;
}

.lane-opp {
  border-bottom: 1px dashed rgba(61, 90, 76, 0.35);
}

.lane-self {
  border-top: 1px dashed rgba(122, 78, 45, 0.3);
}

.lane-score {
  font-size: clamp(0.7rem, 2.5vw, 0.95rem);
  font-weight: 800;
  line-height: 1;
  flex-shrink: 0;
}

.lane-opp .lane-score { color: var(--accent-b); }
.lane-self .lane-score { color: var(--accent-a); }

.lane-cards {
  display: flex;
  flex-wrap: wrap;
  gap: 2px;
  justify-content: center;
  align-content: center;
  align-items: center;
  min-height: 0;
  width: 100%;
  overflow: hidden;
}

/* Scale lane cards to available lane height via container */
@container (max-height: 420px) {
  .lane-cards .snap-card { --card-w: clamp(32px, 18cqh, 48px); }
}
@container (min-height: 421px) {
  .lane-cards .snap-card { --card-w: clamp(44px, 14cqi, 64px); }
}

/* ===== Log drawer — thin toggle + overlay sheet ===== */
.log-drawer {
  flex-shrink: 0;
  position: relative;
  z-index: 12;
  border: 1.5px solid var(--ink);
  border-radius: 8px;
  background: rgba(255,255,255,0.45);
  overflow: visible;
}

.log-toggle {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: space-between;
  border: none;
  border-radius: 8px;
  background: rgba(42,36,28,0.06);
  padding: 0.25rem 0.65rem;
  font-size: 0.75rem;
  letter-spacing: 0.18em;
  border-bottom: 1px solid transparent;
}

.log-drawer.open .log-toggle {
  border-radius: 8px 8px 0 0;
  border-bottom-color: var(--line);
}

.log-toggle .chev {
  letter-spacing: 0;
  transition: transform 0.2s;
}

.log-drawer.open .log-toggle .chev {
  transform: rotate(180deg);
}

.log-body {
  display: none;
  position: absolute;
  left: 0;
  right: 0;
  bottom: 100%;
  max-height: min(36vh, 220px);
  overflow: hidden;
  border: 1.5px solid var(--ink);
  border-bottom: none;
  border-radius: 8px 8px 0 0;
  background: rgba(250, 243, 228, 0.97);
  box-shadow: 0 -6px 20px var(--shadow);
}

.log-drawer.open .log-body {
  display: block;
}

.log {
  height: min(34vh, 200px);
  overflow-y: auto;
  font-size: 0.72rem;
  line-height: 1.45;
  color: var(--ink-soft);
  padding: 0.4rem 0.6rem 0.5rem;
  -webkit-overflow-scrolling: touch;
}

.log .entry { margin-bottom: 0.1rem; }
.log .entry.sys { color: var(--ink); font-weight: 600; }
.log .entry.a { color: var(--accent-a); }
.log .entry.b { color: var(--accent-b); }
.log .entry.win { color: var(--ok); font-weight: 700; }
.log .entry.warn { color: var(--danger); }

/* Banner */
.banner {
  position: fixed;
  inset: auto 50% 3.5rem auto;
  transform: translateX(50%);
  background: var(--ink);
  color: var(--paper);
  padding: 0.55rem 1.1rem;
  border-radius: 999px;
  font-size: 0.95rem;
  letter-spacing: 0.12em;
  box-shadow: 0 8px 24px var(--shadow);
  z-index: 30;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.25s;
}
.banner.show { opacity: 1; }

/* ===== Short / narrow screens — squeeze further ===== */
@media (max-width: 430px) {
  .match-title { display: none; }
  .zone-extra { display: none; }
  .habitat-banner .hint {
    -webkit-line-clamp: 1;
  }
  .hand-self .snap-card .card-text { display: none; }
  .hand-self .snap-card .name-band { margin-bottom: 1.25em; }
}

@media (max-height: 780px) {
  :root {
    --hand-card-w: clamp(44px, 15vw, 72px);
    --opp-card-w: clamp(30px, 9vw, 46px);
    --lane-card-w: clamp(34px, 12vw, 52px);
    --gap: 0.15rem;
    --pad: 0.25rem;
  }
  .player-zone { padding: 0.12rem 0.25rem; }
  .habitat-banner { padding: 0.08rem 0.12rem; }
  .habitat-banner .hint {
    display: -webkit-box;
    -webkit-line-clamp: 2;
    font-size: 0.42rem;
  }
  .hand-self .snap-card .card-text { display: none; }
  .hand-self .snap-card .name-band { margin-bottom: 1.2em; }
  .hand-self .snap-card:nth-child(n) { transform: none; }
}

@media (max-height: 680px) {
  :root {
    --hand-card-w: clamp(38px, 13vw, 58px);
    --opp-card-w: clamp(26px, 8vw, 38px);
    --lane-card-w: clamp(30px, 10vw, 44px);
  }
  .match-title { font-size: 0.9rem; letter-spacing: 0.25em; }
  .turn-badge, .phase-badge { font-size: 0.62rem; padding: 0.05rem 0.3rem; }
  button { font-size: 0.62rem; padding: 0.1rem 0.32rem; }
  .log-toggle { padding: 0.18rem 0.5rem; font-size: 0.68rem; }
}

/* Wider desktop */
@media (min-width: 900px) {
  .app {
    max-width: 900px;
    padding: 0.5rem 0.85rem;
  }
  :root {
    --hand-card-w: 100px;
    --opp-card-w: 60px;
    --lane-card-w: 70px;
  }
  .match-title { font-size: 1.45rem; }
  .habitat-banner h3 { font-size: 1rem; }
}

/* Side log on very wide screens */
@media (min-width: 1100px) {
  .app {
    max-width: 1100px;
    display: grid;
    grid-template-columns: 1fr 250px;
    grid-template-rows: auto auto 1fr auto;
    gap: 0.4rem 0.65rem;
    height: 100%;
  }
  .topbar { grid-column: 1 / -1; }
  .opponent { grid-column: 1; }
  .lanes { grid-column: 1; grid-row: 3; min-height: 0; }
  .self { grid-column: 1; grid-row: 4; }
  .log-drawer {
    grid-column: 2;
    grid-row: 2 / 5;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    position: static;
  }
  .log-drawer .log-body {
    display: block !important;
    position: static;
    max-height: none;
    flex: 1;
    min-height: 0;
    border: none;
    border-radius: 0;
    box-shadow: none;
    background: transparent;
  }
  .log-drawer .log {
    height: 100%;
    max-height: none;
    min-height: 0;
  }
  .log-toggle .chev { display: none; }
}

/* ===== Mode toggle / human play ===== */
.mode-toggle {
  display: inline-flex;
  border: 1.5px solid var(--ink);
  border-radius: 999px;
  overflow: hidden;
  flex-shrink: 0;
}
.mode-toggle button {
  border: none;
  border-radius: 0;
  background: transparent;
  padding: 0.15rem 0.45rem;
  font-size: 0.68rem;
}
.mode-toggle button.active {
  background: var(--ink);
  color: var(--paper);
}
.mode-toggle button + button {
  border-left: 1px solid var(--ink);
}

.watch-controls, .human-controls {
  display: inline-flex;
  align-items: center;
  gap: 0.2rem;
  flex-shrink: 0;
}

.subbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.35rem;
  flex-shrink: 0;
  min-height: 0;
  padding: 0 0.1rem;
}

.play-hint {
  flex: 1;
  min-width: 0;
  font-size: clamp(0.62rem, 2.4vw, 0.78rem);
  color: var(--ink-soft);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  line-height: 1.2;
}

.deck-pick {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  flex-shrink: 0;
  font-size: 0.68rem;
  color: var(--ink-soft);
}
.deck-pick-label { font-weight: 700; color: var(--ink); }
.deck-opt {
  display: inline-flex;
  align-items: center;
  gap: 0.15rem;
  cursor: pointer;
  white-space: nowrap;
}
.deck-opt input { margin: 0; accent-color: var(--accent-a); }

.snap-card.selected {
  outline: 2.5px solid var(--glow);
  outline-offset: 2px;
  transform: translateY(-6px) scale(1.04) !important;
  z-index: 3;
  box-shadow: 0 6px 14px var(--shadow);
}
.snap-card.legal-target {
  outline: 2px dashed var(--ok);
  outline-offset: 1px;
  cursor: pointer;
  animation: pulse-legal 1.2s ease infinite;
}
.snap-card.unaffordable {
  opacity: 0.42;
  filter: grayscale(0.35);
}
.snap-card.face-down .art {
  background: repeating-linear-gradient(
    -45deg,
    rgba(61, 90, 76, 0.25),
    rgba(61, 90, 76, 0.25) 4px,
    rgba(61, 90, 76, 0.08) 4px,
    rgba(61, 90, 76, 0.08) 8px
  );
}
.snap-card.face-down .name-band { letter-spacing: 0.2em; }

.habitat.legal-hab {
  outline: 2.5px solid var(--ok);
  outline-offset: -2px;
  cursor: pointer;
  box-shadow: inset 0 0 0 2px rgba(74, 107, 78, 0.25);
}
.habitat.legal-hab:hover {
  background: rgba(74, 107, 78, 0.08);
}

@keyframes pulse-legal {
  0%, 100% { outline-color: var(--ok); }
  50% { outline-color: var(--glow); }
}

body.mode-human .player-zone.self {
  box-shadow: 0 0 0 1.5px rgba(217, 164, 65, 0.45);
}
body.mode-human .energy-gem {
  font-size: 0.85rem;
  min-width: 3rem;
  padding: 0.08rem 0.5rem;
}
#btn-end:not(:disabled) {
  background: var(--accent-a);
  color: var(--paper);
  border-color: var(--accent-a);
  font-weight: 700;
}

@media (min-width: 1100px) {
  .subbar { grid-column: 1 / -1; }
  .app {
    grid-template-rows: auto auto auto 1fr auto;
  }
  .opponent { grid-row: 3; }
  .lanes { grid-row: 4; }
  .self { grid-row: 5; }
  .log-drawer { grid-row: 3 / 6; }
}

@media (max-width: 420px) {
  .mode-toggle button { padding: 0.12rem 0.32rem; font-size: 0.62rem; }
  .deck-pick { font-size: 0.62rem; }
  .play-hint { font-size: 0.6rem; }
}

.matchup-pick {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.35rem 0.5rem;
  font-size: 0.78rem;
}
.matchup-pick select {
  font: inherit;
  font-size: 0.78rem;
  background: var(--paper-deep);
  border: 1px solid var(--line);
  border-radius: 4px;
  color: var(--ink);
  padding: 0.1rem 0.25rem;
}
.matchup-pick .vs { opacity: 0.7; }
.deck-pick { flex-wrap: wrap; max-width: 100%; }

/* ===== First-time coach (我打AI) ===== */
.coach-overlay {
  position: fixed;
  inset: 0;
  z-index: 40;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1rem;
  background: rgba(42, 36, 28, 0.45);
  backdrop-filter: blur(2px);
}
.coach-overlay[hidden] { display: none !important; }
.coach-card {
  position: relative;
  width: min(360px, 92vw);
  background: var(--paper);
  border: 1.5px solid var(--ink);
  border-radius: 12px;
  box-shadow: 0 16px 40px var(--shadow);
  padding: 1.1rem 1.15rem 1rem;
  color: var(--ink);
}
.coach-card h2 {
  margin: 0 0 0.75rem;
  font-size: 1.05rem;
  letter-spacing: 0.06em;
  font-weight: 700;
}
.coach-close {
  position: absolute;
  top: 0.35rem;
  right: 0.4rem;
  width: 1.75rem;
  height: 1.75rem;
  border: none;
  background: transparent;
  color: var(--ink-soft);
  font-size: 1.35rem;
  line-height: 1;
  cursor: pointer;
  border-radius: 6px;
  padding: 0;
}
.coach-close:hover { background: var(--paper-deep); color: var(--ink); }
.coach-steps {
  list-style: none;
  margin: 0 0 0.85rem;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 0.55rem;
}
.coach-steps li {
  display: flex;
  gap: 0.65rem;
  align-items: flex-start;
}
.coach-steps .n {
  flex: 0 0 1.55rem;
  width: 1.55rem;
  height: 1.55rem;
  border-radius: 999px;
  background: var(--accent-a);
  color: var(--paper);
  font-size: 0.82rem;
  font-weight: 700;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  margin-top: 0.05rem;
}
.coach-steps strong {
  display: block;
  font-size: 0.92rem;
  margin-bottom: 0.1rem;
}
.coach-steps span:not(.n) {
  display: block;
  font-size: 0.78rem;
  color: var(--ink-soft);
  line-height: 1.35;
}
.coach-persist {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  font-size: 0.78rem;
  color: var(--ink-soft);
  margin-bottom: 0.65rem;
  cursor: pointer;
  user-select: none;
}
.coach-persist input { accent-color: var(--accent-a); }
.coach-ok {
  width: 100%;
  padding: 0.45rem 0.75rem;
  font-size: 0.9rem;
  letter-spacing: 0.08em;
}
@media (max-width: 420px) {
  .coach-card { padding: 0.95rem 0.9rem 0.85rem; }
  .coach-card h2 { font-size: 0.95rem; }
}

/* ===== Full-card art (art already prints cost / power / name) ===== */
.snap-card.full-art {
  border: none;
  background: transparent;
  box-shadow: none;
  overflow: visible;
  border-radius: 0;
}
.snap-card.full-art .full-art-img {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: contain;
  pointer-events: none;
  filter: drop-shadow(0 2px 4px var(--shadow));
}
.snap-card.full-art .card-text {
  position: absolute; left: 4%; right: 4%; bottom: 2%;
  background: rgba(20,16,10,0.78); color: #fff; border-radius: 4px; z-index: 2;
}
.snap-card.full-art .live-pwr { z-index: 3; }
.snap-card.full-art.selected .full-art-img,
.snap-card.full-art.highlight .full-art-img { filter: drop-shadow(0 0 6px gold); }
.snap-card.full-art.legal-target .full-art-img { filter: drop-shadow(0 0 5px #4fd18b); }
.snap-card.full-art.unaffordable .full-art-img { filter: grayscale(0.6) brightness(0.75); }

/* =====================================================================
   SNAP-style dark board (2026-10-15)
   ===================================================================== */
:root {
  --paper: #1b1914;
  --paper-deep: #2a251c;
  --ink: #eadcb8;
  --ink-soft: #b9a67e;
  --line: #8a6a35;
  --gold: #d6aa5a;
  --bronze: #8a6a35;
  --panel: rgba(16, 18, 20, 0.62);
  --shadow: rgba(0, 0, 0, 0.45);
  --lane-bg: rgba(10, 14, 16, 0.45);
  --lane-win: rgba(214, 170, 90, 0.10);
  --accent-a: #f08a2c;
  --accent-b: #5aa8e0;
}
body {
  background: #0c0f12 url("assets/ui/bg.webp") center / cover fixed no-repeat !important;
  color: var(--ink);
}
body::before {
  content: ""; position: fixed; inset: 0; pointer-events: none; z-index: 0;
  background: radial-gradient(ellipse at 50% 45%, rgba(0,0,0,0.15), rgba(0,0,0,0.65) 85%);
}
.app { position: relative; z-index: 1; }
.player-zone, .player-zone.opponent, .player-zone.self, .log-drawer, .log-body, .side-log {
  background: var(--panel) !important;
  border-color: rgba(214,170,90,0.45) !important;
  backdrop-filter: blur(3px);
}
button, select, .turn-badge, .phase-badge, .energy-gem {
  background: rgba(30, 26, 20, 0.85) !important;
  color: var(--ink) !important;
  border-color: var(--bronze) !important;
}
button:hover { background: rgba(70, 55, 30, 0.9) !important; }
button.primary, .mode-toggle button.active { background: linear-gradient(180deg,#d6aa5a,#8a6a35) !important; color: #1b1408 !important; }
.match-title { color: var(--gold); text-shadow: 0 0 10px rgba(214,170,90,0.4); }
.log .entry.sys { color: var(--ink); }
.snap-card .name-band { color: #f6ecd4; }
.snap-card:not(.full-art) { border-color: var(--bronze); }

/* ----- lanes ----- */
.lanes { gap: clamp(0.25rem, 1.2vw, 0.7rem); }
.habitat, .habitat.winning {
  background: linear-gradient(180deg, rgba(8,12,14,0.35), rgba(8,12,14,0.15) 50%, rgba(8,12,14,0.35));
  border: 1px solid rgba(214,170,90,0.28);
  box-shadow: inset 0 0 18px rgba(0,0,0,0.5);
  overflow: visible;
}
.lane-stack { gap: 0; }
.lane-half { border: none !important; padding: 0.2rem 0.15rem; overflow: visible; }
.lane-cards { overflow: visible; gap: clamp(2px, 0.5vw, 6px); }
.lane-opp .lane-cards { align-content: flex-end; }
.lane-self .lane-cards { align-content: flex-start; }

/* location tile */
.loc-tile {
  position: relative; flex: 0 0 auto;
  margin: 0 4%;
  aspect-ratio: var(--loc-ar-css, 16 / 7);
  border-radius: 10px;
  background: #111 var(--loc-url) center / cover no-repeat;
  border: 2px solid var(--gold);
  box-shadow: 0 0 0 2px rgba(0,0,0,0.6), 0 4px 16px rgba(0,0,0,0.7), inset 0 0 22px rgba(0,0,0,0.65);
  display: flex; align-items: flex-end; justify-content: center;
  overflow: visible;
}
.habitat.fog-hidden .loc-tile { filter: saturate(0.4) brightness(0.8); }
.habitat.legal-hab .loc-tile { box-shadow: 0 0 0 2px #4fd18b, 0 0 18px #4fd18b; }
.loc-tile .loc-text {
  width: 100%; text-align: center;
  background: linear-gradient(0deg, rgba(0,0,0,0.85), rgba(0,0,0,0.35) 70%, transparent) !important;
  border: none !important; border-radius: 0 0 8px 8px;
  padding: 1.25em 0.4em 1.35em;
  align-self: stretch; display: flex; flex-direction: column; justify-content: center;
}
.loc-tile .loc-text h3 {
  margin: 0; color: #f7e3b0; font-size: clamp(0.8rem, 1.7vw, 1.15rem) !important;
  letter-spacing: 0.15em; text-shadow: 0 1px 3px #000;
}
.loc-tile .loc-text .hint {
  color: #eadcc0; font-size: clamp(0.58rem, 1.1vw, 0.78rem) !important;
  line-height: 1.25; text-shadow: 0 1px 2px #000;
  display: block; -webkit-line-clamp: unset;
}
.loc-pwr {
  position: absolute; left: 50%; transform: translate(-50%, -50%);
  min-width: 2.1em; height: 2.1em; padding: 0 0.3em;
  border-radius: 50%; display: grid; place-items: center;
  font-weight: 900; font-size: clamp(0.85rem, 1.8vw, 1.25rem); line-height: 1;
  color: #fff; text-shadow: 0 1px 2px #000;
  border: 2px solid rgba(255,255,255,0.55);
  box-shadow: 0 2px 6px rgba(0,0,0,0.7);
  z-index: 4;
}
.loc-pwr-opp { top: 0; background: radial-gradient(circle at 35% 30%, #8fc4ec, #2c5c86 75%); }
.loc-pwr-self { top: 100%; background: radial-gradient(circle at 35% 30%, #ffc27a, #c45a12 75%); }
.loc-pwr.lead { border-color: #ffe9a8; box-shadow: 0 0 0 2px rgba(255,214,120,0.6), 0 0 14px 3px rgba(255,200,90,0.75); transform: translate(-50%,-50%) scale(1.15); }

/* ----- bigger board cards: sized by lane width/height, 2 per row (max 4 per side) ----- */
.lanes {
  --lane-w: calc((100cqi - 2 * clamp(0.25rem, 1.2vw, 0.7rem)) / 3);
  --half-h: calc((100cqh - (100cqi / 3) * var(--loc-h-ratio, 0.4375) - 16px) / 2);
}
.lane-cards .snap-card {
  --card-w: min(calc(var(--lane-w) / 2 - 8px), calc((var(--half-h) - 10px) * 2 / 3)) !important;
  font-size: calc(var(--card-w) * 0.11);
}
.lane-cards:has(> :nth-child(3)) .snap-card {
  --card-w: min(calc(var(--lane-w) / 2 - 8px), calc((var(--half-h) / 2 - 6px) * 2 / 3)) !important;
}
.lane-cards .snap-card .badge-cost, .lane-cards .snap-card .badge-pwr { font-size: 1em; width: 1.5em; height: 1.5em; }
.lane-cards .snap-card .name-band { font-size: 0.85em; }
.lane-cards .snap-card .art { margin: 1.5em 2px 0; }

/* hands */
:root { --hand-card-w: clamp(70px, 19vw, 132px); --opp-card-w: clamp(40px, 9vw, 78px); }
@media (min-width: 900px) { :root { --hand-card-w: 128px; --opp-card-w: 74px; } }
@media (max-height: 780px) { :root { --hand-card-w: clamp(64px, 17vw, 110px); --opp-card-w: clamp(36px, 8vw, 60px); } }
.hand-self .snap-card { font-size: calc(var(--card-w) * 0.1); }
.hand-opp .snap-card { font-size: calc(var(--card-w) * 0.11); }
.hand-opp .snap-card .badge-cost, .hand-opp .snap-card .badge-pwr { font-size: 1em; }
.hand-opp .snap-card .name-band { font-size: 0.8em; }
.snap-card.full-art { overflow: visible; }

.snap-card .badge-cost, .snap-card .badge-pwr { color: #2a1a08; border-color: #3a2a12; }
.snap-card .badge-pwr { color: #fff; }
@media (max-width: 600px) {
  .lanes { --loc-h-ratio: 0.8; }
  .loc-tile { --loc-ar-css: 5 / 4; margin: 0 2%; }
  .loc-tile .loc-text { padding: 1.1em 0.2em 1.2em; }
  .loc-tile .loc-text h3 { font-size: 0.78rem !important; letter-spacing: 0.05em; }
  .loc-tile .loc-text .hint { font-size: 0.56rem !important; }
  .loc-pwr { font-size: 0.78rem; min-width: 1.9em; height: 1.9em; }
  .lane-cards .snap-card { --card-w: min(calc(var(--lane-w) / 2 - 4px), calc((var(--half-h) - 8px) * 2 / 3)) !important; }
}
@media (max-width: 600px) {
  .lane-half { padding: 0.15rem 0; }
  .lane-cards { gap: 2px; }
  .lane-cards .snap-card { --card-w: min(calc(var(--lane-w) / 2 - 12px), calc((var(--half-h) - 8px) * 2 / 3)) !important; }
  .lane-cards:has(> :nth-child(3)) .snap-card { --card-w: min(calc(var(--lane-w) / 2 - 12px), calc((var(--half-h) / 2 - 4px) * 2 / 3)) !important; }
}

/* ===== Settings drawer; main view = board only (2026-10-15b) ===== */
.topbar { display: flex; align-items: center; justify-content: space-between; padding: 0.1rem 0.2rem; min-height: 0; }
.topbar .match-title { font-size: clamp(0.9rem, 2vw, 1.1rem) !important; letter-spacing: 0.35em; margin: 0; }
.gear-btn {
  width: 2.1rem; height: 2.1rem; border-radius: 50% !important; padding: 0 !important;
  font-size: 1.15rem !important; line-height: 1; display: grid; place-items: center;
  background: radial-gradient(circle at 35% 30%, #5a4524, #241a0e 75%) !important;
  border: 1.5px solid var(--gold) !important; color: #f2d58f !important;
  box-shadow: 0 2px 8px rgba(0,0,0,0.6);
}
.gear-btn[aria-expanded="true"] { box-shadow: 0 0 10px rgba(214,170,90,0.8); }
.settings-scrim { position: fixed; inset: 0; background: rgba(0,0,0,0.45); z-index: 40; }
.settings-panel {
  position: fixed; top: 0; right: 0; bottom: 0; z-index: 41;
  width: min(380px, 92vw); padding: 0.8rem; overflow-y: auto;
  display: flex; flex-direction: column; gap: 0.6rem;
  background: rgba(14, 16, 18, 0.94); border-left: 2px solid var(--gold);
  box-shadow: -8px 0 24px rgba(0,0,0,0.6); color: var(--ink);
}
.settings-panel[hidden], .settings-scrim[hidden] { display: none !important; }
.settings-head { display: flex; justify-content: space-between; align-items: center; }
.settings-head h2 { margin: 0; font-size: 1rem; color: var(--gold); letter-spacing: 0.2em; }
.settings-panel .dev-top { display: flex; flex-direction: column; gap: 0.5rem; }
.settings-panel .topbar-left, .settings-panel .controls, .settings-panel .watch-controls,
.settings-panel .subbar, .settings-panel .matchup-pick, .settings-panel .deck-pick { display: flex; flex-wrap: wrap; gap: 0.35rem; align-items: center; overflow: visible; }
.settings-panel .subbar { flex-direction: column; align-items: flex-start; }
.settings-panel .play-hint { color: var(--ink-soft); }
.settings-panel .watch-controls[hidden], .settings-panel .deck-pick[hidden], .settings-panel .matchup-pick[hidden] { display: none; }
.settings-panel .log-drawer { position: static !important; flex: 1 1 auto; min-height: 220px; display: flex; flex-direction: column; border-radius: 8px; }
.settings-panel .log-drawer .log-body { display: block !important; position: static !important; max-height: none !important; flex: 1; overflow: auto; box-shadow: none; }
.settings-panel .log-drawer .log { max-height: none; height: auto; }
.settings-panel .log-toggle { pointer-events: none; }
.settings-panel .log-toggle .chev { display: none; }
.zone-extra { display: none !important; }
.main-actions { display: flex; gap: 0.35rem; margin-left: auto; align-items: center; }
.main-actions .human-controls { display: flex; gap: 0.35rem; }
.main-actions .human-controls[hidden], .main-actions [hidden] { display: none !important; }
.main-actions button.primary { font-size: clamp(0.8rem, 1.6vw, 1rem) !important; padding: 0.35em 1.1em !important; border-radius: 999px; }
/* board uses full width (no side log column) */
@media (min-width: 900px) { .app { max-width: 1200px !important; } }
@media (min-width: 1100px) {
  .app { display: flex !important; flex-direction: column; max-width: 1200px !important; }
}
@media (min-width: 601px) {
  .lanes { --loc-h: clamp(72px, 11vh, 104px); --half-h: calc((100cqh - var(--loc-h) - 16px) / 2); }
  .loc-tile { aspect-ratio: auto; height: var(--loc-h); }
}
@media (min-width: 900px) { :root { --hand-card-w: 112px; --opp-card-w: 64px; } }
@media (max-width: 430px) { .topbar .match-title { display: block !important; } }

/* =====================================================================
   PHONE-COLUMN SNAP LAYOUT (2026-10-15c) — overrides everything above
   ===================================================================== */
html, body { height: 100%; }
body { overflow: hidden; }
body .app {
  display: flex !important; flex-direction: column;
  width: 100%; max-width: 480px !important; height: 100dvh; margin: 0 auto;
  padding: calc(var(--safe-t) + 4px) 6px calc(var(--safe-b) + 4px) !important; gap: 4px;
  background: rgba(0,0,0,0.18); box-shadow: 0 0 40px rgba(0,0,0,0.6);
}
body .player-zone.opponent { display: none !important; }

/* ---- top HUD ---- */
.hud-top {
  position: relative; flex: 0 0 auto; display: grid !important;
  grid-template-columns: 1fr auto 1fr; align-items: start; padding: 2px 2px 0 !important;
  border: none !important; background: none !important; min-height: 74px;
}
.hud-top .match-title { position: absolute; left: 50%; bottom: -2px; transform: translateX(-50%); font-size: 0.62rem !important; letter-spacing: 0.5em; opacity: 0.55; }
.hud-player { display: flex; flex-direction: column; align-items: flex-start; gap: 2px; }
.hud-opp { align-items: flex-end; padding-right: 0; }
.hex-avatar {
  width: 58px; height: 64px; display: grid; place-items: center;
  clip-path: polygon(50% 0, 100% 25%, 100% 75%, 50% 100%, 0 75%, 0 25%);
  background: linear-gradient(160deg, #f3d48a, #8a6a35 55%, #3a2a12);
  position: relative;
}
.hex-avatar::before {
  content: ""; position: absolute; inset: 3px;
  clip-path: inherit; background: radial-gradient(circle at 50% 35%, #3b5566, #121a20 80%);
}
.hex-avatar.opp-av::before { background: radial-gradient(circle at 50% 35%, #5a3a3a, #1c1010 80%); }
.hex-avatar span { position: relative; font-size: 1.6rem; font-weight: 900; color: #f2d58f; text-shadow: 0 0 8px rgba(242,213,143,0.6); }
.hud-name {
  font-size: 0.72rem; font-weight: 700; color: #f7e8c4; padding: 2px 12px 2px 8px;
  background: linear-gradient(90deg, rgba(40,70,100,0.95), rgba(40,70,100,0.2));
  clip-path: polygon(0 0, 100% 0, 92% 100%, 0 100%); white-space: nowrap;
}
.hud-opp .hud-name { padding: 2px 8px 2px 12px; background: linear-gradient(270deg, rgba(120,40,30,0.95), rgba(120,40,30,0.2)); clip-path: polygon(0 0, 100% 0, 100% 100%, 8% 100%); }
.turn-cube {
  width: 54px; height: 54px; margin-top: 4px; display: grid; place-items: center;
  transform: rotate(45deg); border-radius: 8px;
  background: linear-gradient(135deg, rgba(255,226,150,0.85), rgba(150,105,40,0.75));
  border: 2px solid #ffe7a6; box-shadow: 0 0 18px rgba(255,200,90,0.75), inset 0 0 12px rgba(255,255,255,0.5);
}
.turn-cube span { transform: rotate(-45deg); font-size: 1.7rem; font-weight: 900; color: #2a1806; text-shadow: 0 1px 0 rgba(255,255,255,0.5); }
.hud-top .gear-btn { position: absolute; right: 2px; top: 74px; width: 1.7rem; height: 1.7rem; font-size: 0.95rem !important; z-index: 5; }

/* ---- lanes: 3 columns, opp cards above / location / ours below ---- */
body .lanes {
  flex: 1 1 0; min-height: 0; display: grid !important; grid-template-columns: repeat(3, minmax(0,1fr));
  gap: 6px; container-type: size; overflow: visible;
  --lane-w: calc((100cqi - 12px) / 3);
  --loc-h: calc(var(--lane-w) * 1.12);
  --half-h: calc((100cqh - var(--loc-h)) / 2 - 6px);
}
body .habitat, body .habitat.winning { background: none !important; border: none !important; box-shadow: none !important; border-radius: 0; }
body .habitat.drop-over .loc-tile, body .habitat.legal-hab .loc-tile { box-shadow: 0 0 0 2px #ffe08a, 0 0 18px 4px rgba(255,210,110,0.85) !important; }
body .lane-stack { height: 100%; display: flex; flex-direction: column; }
body .lane-half { flex: 1 1 0; padding: 4px 0 !important; overflow: visible; }
body .lane-opp { justify-content: flex-end; }
body .lane-self { justify-content: flex-start; }
body .lane-cards { display: grid !important; grid-template-columns: repeat(2, auto); justify-content: center; gap: 3px; width: auto; }
body .lane-opp .lane-cards { align-content: end; direction: ltr; }
body .lane-cards .snap-card,
body .lane-cards:has(> :nth-child(3)) .snap-card {
  --card-w: min(calc(var(--lane-w) / 2 - 3px), calc((var(--half-h) / 2 - 4px) * 2 / 3)) !important;
}
body .lane-cards:not(:has(> :nth-child(3))) .snap-card {
  --card-w: min(calc(var(--lane-w) / 2 - 3px), calc((var(--half-h) - 6px) * 2 / 3)) !important;
}
body .lane-cards .snap-card { font-size: calc(var(--card-w) * 0.13); }

/* location tile: framed portrait */
body .loc-tile {
  flex: 0 0 auto; height: var(--loc-h) !important; aspect-ratio: auto !important; margin: 0 !important;
  border-radius: 6px; border: 3px solid transparent !important;
  background:
    linear-gradient(#000, #000) padding-box,
    linear-gradient(160deg, #ffe7a6, #a37a35 40%, #4a3414 60%, #d9b265) border-box !important;
  box-shadow: 0 4px 14px rgba(0,0,0,0.75) !important;
  display: block; position: relative;
}
body .loc-tile::before {
  content: ""; position: absolute; inset: 0; border-radius: 3px;
  background: var(--loc-url) center / cover no-repeat;
}
body .loc-tile .loc-text {
  position: absolute; inset: 0; padding: 22% 6% 22% !important; border-radius: 3px;
  background: linear-gradient(180deg, rgba(0,0,0,0.15), rgba(0,0,0,0.55) 45%, rgba(0,0,0,0.25)) !important;
  display: flex; flex-direction: column; justify-content: center; align-items: center; gap: 3px;
}
body .loc-tile .loc-text h3 { font-size: clamp(0.78rem, 3.6cqi, 1.05rem) !important; letter-spacing: 0.08em; }
body .loc-tile .loc-text .hint { font-size: clamp(0.56rem, 2.5cqi, 0.72rem) !important; }
body .loc-pwr {
  width: 2.2em; min-width: 0; height: 2.4em; border-radius: 0; padding: 0;
  clip-path: polygon(50% 0, 100% 25%, 100% 75%, 50% 100%, 0 75%, 0 25%);
  border: none; font-size: 0.9rem; box-shadow: none;
}
body .loc-pwr-opp { top: 0; background: linear-gradient(160deg, #cfe3f2, #4c7aa0 60%, #213a52); }
body .loc-pwr-self { top: 100%; background: linear-gradient(160deg, #ffd9a0, #d0681c 60%, #6a2e08); }
body .loc-pwr.lead { filter: drop-shadow(0 0 6px #ffd27a) brightness(1.15); transform: translate(-50%,-50%) scale(1.18); box-shadow: none; }

/* ---- bottom: hand + action bar ---- */
body .player-zone.self {
  flex: 0 0 auto; display: flex; flex-direction: column; gap: 4px;
  background: none !important; border: none !important; backdrop-filter: none; padding: 0 !important;
}
body .hand-self {
  display: flex; justify-content: center; align-items: flex-end; flex-wrap: nowrap; overflow: visible;
  padding: 4px 6px 0; min-height: 0;
  --hand-card-w: min(84px, calc((100vw - 30px) / 5));
}
body .hand-self .snap-card {
  --card-w: var(--hand-card-w) !important; font-size: calc(var(--card-w) * 0.11);
  transform: none !important; margin: 0 -5px; transition: transform 0.12s;
}
body .hand-self .snap-card.selected { transform: translateY(-12px) scale(1.06) !important; z-index: 5; }
body .hand-self .snap-card .card-text { display: none; }
.action-bar {
  display: grid; grid-template-columns: 1fr auto 1fr; align-items: center; gap: 6px; height: 64px;
}
.retreat-btn {
  justify-self: start; height: 46px; min-width: 100px; padding: 0 18px !important; font-size: 1.15rem !important; font-weight: 900;
  color: #ffe6d8 !important; letter-spacing: 0.15em; border: none !important;
  background: linear-gradient(180deg, #b8321e, #6a140c) !important;
  clip-path: polygon(0 0, 100% 0, 88% 100%, 0 100%); border-radius: 0 !important;
}
.energy-orb {
  width: 62px; height: 62px; border-radius: 50%; display: grid; place-items: center;
  background: radial-gradient(circle at 40% 35%, #fff4cf, #f0b84a 40%, #8a5a12 75%);
  box-shadow: 0 0 18px 4px rgba(255,190,80,0.75), inset 0 0 10px rgba(255,255,255,0.6);
  border: 2px solid #ffe7a6;
}
.energy-orb span { font-size: 1.8rem; font-weight: 900; color: #2a1806; text-shadow: 0 1px 0 rgba(255,255,255,0.5); }
.end-slot { justify-self: end; display: flex; align-items: center; gap: 4px; }
.end-slot .human-controls { display: flex; gap: 4px; align-items: center; }
.end-slot .human-controls[hidden], .end-slot [hidden] { display: none !important; }
.end-btn {
  height: 52px; min-width: 112px; padding: 0 12px 0 22px !important; border: none !important; border-radius: 0 !important;
  display: flex; flex-direction: column; justify-content: center; align-items: center; line-height: 1.05;
  font-size: 1.05rem !important; font-weight: 900; letter-spacing: 0.08em; color: #2a1806 !important;
  background: linear-gradient(180deg, #ffe39a, #c08a2e 60%, #7a5216) !important;
  clip-path: polygon(12% 0, 100% 0, 100% 100%, 0 100%);
  box-shadow: none;
}
.end-btn small { font-size: 0.7rem; font-weight: 700; opacity: 0.8; }
.end-btn:disabled { filter: grayscale(0.7) brightness(0.6); }
#btn-cancel, #btn-skip-extra { font-size: 0.75rem !important; }
.watch-badge { display: none; color: var(--ink-soft); font-size: 0.8rem; }
body.mode-watch .watch-badge { display: block; }
.drag-ghost { position: fixed; z-index: 60; pointer-events: none; filter: drop-shadow(0 8px 14px rgba(0,0,0,0.7)); }
body .hand-self .snap-card { touch-action: none; }
.banner { z-index: 30; }
body .zone-meta[hidden] { display: none !important; }
body .player-zone.self { border: none !important; box-shadow: none !important; }
.hud-top .gear-btn { top: auto; bottom: -30px; right: 4px; }
.hud-top .gear-btn { top: 10px !important; bottom: auto !important; right: auto !important; left: calc(50% + 40px); }
html { overflow: hidden; }
.hint-main {
  align-self: center; margin-bottom: 2px; padding: 4px 14px; border-radius: 999px;
  background: rgba(20,14,6,0.88); border: 1px solid var(--gold); color: #f7e3b0; font-size: 0.8rem;
  box-shadow: 0 0 12px rgba(214,170,90,0.5);
}
.hint-main[hidden] { display: none !important; }
/* ===== 二选一 choice sheet ===== */
.choice-sheet-scrim { position: fixed; inset: 0; z-index: 70; background: rgba(0,0,0,0.55); display: flex; align-items: flex-end; justify-content: center; }
.choice-sheet {
  width: min(480px, 100vw); padding: 16px 14px calc(14px + var(--safe-b));
  background: linear-gradient(180deg, rgba(34,26,14,0.97), rgba(14,12,8,0.98));
  border-top: 2px solid var(--gold); border-radius: 16px 16px 0 0;
  box-shadow: 0 -8px 30px rgba(0,0,0,0.7); animation: sheetUp 0.18s ease-out;
}
@keyframes sheetUp { from { transform: translateY(40%); opacity: 0; } to { transform: none; opacity: 1; } }
.choice-title { text-align: center; color: var(--gold); font-weight: 800; letter-spacing: 0.2em; margin-bottom: 12px; font-size: 1.05rem; }
.choice-row { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.choice-btn {
  display: flex !important; flex-direction: column; align-items: center; gap: 4px; padding: 14px 8px !important; min-height: 92px;
  border-radius: 12px !important; border: 2px solid #e8c77a !important;
  background: linear-gradient(180deg, #6a4d22, #3a2810 60%, #24180a) !important; color: #f7e3b0 !important;
  box-shadow: inset 0 1px 0 rgba(255,230,160,0.4), 0 4px 10px rgba(0,0,0,0.6);
}
.choice-btn b { font-size: 1.35rem; letter-spacing: 0.15em; color: #ffe7a6; text-shadow: 0 0 8px rgba(255,200,90,0.5); }
.choice-btn span { font-size: 0.78rem; opacity: 0.9; line-height: 1.3; text-align: center; }
.choice-btn:active { transform: scale(0.97); }
.choice-cancel { display: block; margin: 10px auto 0; font-size: 0.8rem !important; background: none !important; border: none !important; color: var(--ink-soft) !important; }
/* ===== Inspect modal ===== */
.inspect-scrim { position: fixed; inset: 0; z-index: 80; background: rgba(4,6,8,0.82); backdrop-filter: blur(4px); display: grid; place-items: center; animation: fadeIn 0.15s; }
@keyframes fadeIn { from { opacity: 0; } }
.inspect-box { position: relative; width: min(360px, 88vw); display: flex; flex-direction: column; align-items: center; gap: 12px; }
.inspect-x { position: absolute; top: -6px; right: -6px; z-index: 3; width: 36px; height: 36px; border-radius: 50% !important; padding: 0 !important; font-size: 1.3rem !important; border: 1.5px solid var(--gold) !important; }
.inspect-card { display: flex; justify-content: center; }
.inspect-card .snap-card { --card-w: min(230px, 60vw, 38vh) !important; font-size: calc(var(--card-w) * 0.1) !important; transform: none !important; margin: 0 !important; cursor: default; }
.inspect-card .snap-card .card-text { display: none; }
.inspect-card .snap-card.full-art .full-art-img { filter: drop-shadow(0 10px 24px rgba(0,0,0,0.8)); }
.inspect-loc { width: min(300px, 80vw); aspect-ratio: 3 / 4; max-height: 46vh; border-radius: 8px; background: #000 center / cover no-repeat; border: 3px solid var(--gold); box-shadow: 0 10px 30px rgba(0,0,0,0.8); }
.inspect-panel {
  width: 100%; padding: 12px 14px; border-radius: 12px; text-align: center;
  background: linear-gradient(180deg, rgba(60,44,20,0.95), rgba(24,18,8,0.97)); border: 1.5px solid var(--gold);
  color: #f2e4c2; box-shadow: 0 6px 20px rgba(0,0,0,0.6);
}
.inspect-panel h3 { margin: 0 0 6px; color: #ffe7a6; font-size: 1.3rem; letter-spacing: 0.2em; }
.inspect-panel p { margin: 6px 0 0; font-size: 0.92rem; line-height: 1.5; }
.inspect-stats { display: flex; justify-content: center; gap: 8px; flex-wrap: wrap; }
.inspect-stats .st { padding: 2px 10px; border-radius: 999px; font-size: 0.8rem; font-weight: 800; border: 1px solid rgba(255,231,166,0.5); }
.inspect-stats .cost { background: #234a74; }
.inspect-stats .pwr { background: #8a3e10; }
.inspect-stats .pwr s { opacity: 0.6; font-weight: 400; margin-left: 2px; }
.inspect-stats .arch { background: rgba(0,0,0,0.4); }
.loc-tile { cursor: zoom-in; }
/* inspect v2: bigger art, plain text on backdrop */
.inspect-box { width: auto; max-width: 96vw; gap: 10px; }
.inspect-card .snap-card { --card-w: min(88vw, calc(70vh * 2 / 3), calc((100vh - 230px) * 2 / 3)) !important; }
.inspect-loc { width: min(88vw, calc(70vh * 3 / 4), calc((100vh - 200px) * 3 / 4)); max-height: none; }
.inspect-panel { background: none !important; border: none !important; box-shadow: none !important; padding: 0 10px !important; max-width: min(88vw, 520px); text-shadow: 0 1px 3px #000, 0 0 10px rgba(0,0,0,0.9); }
.inspect-panel h3 { font-size: 1.45rem; margin-bottom: 4px; }
.inspect-stats { display: block; font-size: 0.95rem; font-weight: 700; color: #e8cf94; }
.inspect-stats s { opacity: 0.6; font-weight: 400; }
.inspect-panel p { font-size: 1rem; }
.inspect-x { position: fixed !important; top: 14px !important; right: 14px !important; }
.inspect-scrim, .inspect-scrim * { cursor: pointer; -webkit-tap-highlight-color: transparent; }
.inspect-card .snap-card, .inspect-loc { cursor: default; }
.inspect-card .live-pwr, .inspect-card .badge-pwr.live-pwr { display: none !important; }
