:root {
  --cream: #f3ead8;
  --cream-2: #f7f1e4;
  --ivory: #f4ead6;
  --ink: #2a1f16;
  --line: #6b4a2e;
  --timber: #6b4a2e;
  --brass: #c4a36a;
  --sage: #6b7f54;
  --grass: #5a7048;
  --barn: #8a3e2c;
  --amber: #c4a36a;
  --good: #3d5c3a;
  --bad: #8a3e2c;
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; height: 100%; height: 100svh; height: 100dvh; max-height: 100dvh; overflow: hidden; }
body {
  font-family: "Trebuchet MS", "PingFang SC", "Noto Sans SC", sans-serif;
  color: var(--ink);
  background: #5aa7dc;
  display: flex;
  flex-direction: column;
  padding-left: env(safe-area-inset-left);
  padding-right: env(safe-area-inset-right);
}
button, input, select { font: inherit; color: inherit; }
.hud {
  flex: 0 0 auto;
  display: flex;
  flex-wrap: wrap;
  gap: 4px 12px;
  align-items: center;
  justify-content: space-between;
  padding: 6px 12px;
  background: #f0d7a8;
  border-bottom: 3px solid #c4a06a;
  box-shadow: inset 0 1px 0 #fff3d6, inset 0 -1px 0 #d7b37a;
  z-index: 20;
}
.brand { display: flex; flex-direction: column; gap: 1px; }
.brand strong { font-size: 14px; }
.tag { font-size: 11px; color: #5a4634; }
.hud-stats { display: flex; gap: 14px; flex-wrap: wrap; }
.hud-stats b { color: var(--barn); }
.hud-help-link {
  border: 0;
  background: none;
  text-decoration: underline;
  cursor: pointer;
  color: #5a4634;
  min-height: 36px;
  padding: 4px 8px;
}
.btn, .tab-btn {
  border: 1.5px solid var(--brass);
  background: linear-gradient(#f7f1e4, #e8d9b8);
  padding: 7px 12px;
  min-height: 44px;
  cursor: pointer;
  text-decoration: none;
  color: var(--ink);
  display: inline-flex; align-items: center; justify-content: center;
  border-radius: 8px;
  box-shadow: 0 1px 0 rgba(196,163,106,.7), 0 2px 5px rgba(42,31,22,.12), inset 0 1px 0 rgba(255,248,230,.55);
}
.tab-btn.active, .btn.primary {
  background: linear-gradient(#d7c089, #b89556);
  color: #2a1c12;
}
.stage {
  flex: 1 1 auto;
  min-height: 0;
  position: relative;
  background: #5aa7dc;
}
canvas { width: 100%; height: 100%; display: block; image-rendering: pixelated; image-rendering: crisp-edges; }

.top-strip {
  flex: 0 0 auto;
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
  gap: 4px;
  padding: 0 8px;
  max-height: none;
  overflow: visible;
  z-index: 18;
}
.visit-banner {
  position: static;
  left: auto;
  transform: none;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: center;
  gap: 8px;
  background: #fff3c8;
  border: 2px solid var(--line);
  padding: 8px 10px;
  max-width: 100%;
  min-height: 52px;
  max-height: none;
  overflow: visible;
  flex-shrink: 0;
  text-align: center;
  font-size: 13px;
}
.visit-banner-text { flex: 1 1 180px; min-width: 0; }
.visit-banner .btn { flex: 0 0 auto; min-height: 44px; }
.notify-lane {
  position: static;
  left: auto;
  transform: none;
  bottom: auto;
  width: 100%;
  max-height: 16vh;
  display: flex;
  flex-direction: column;
  gap: 4px;
  pointer-events: none;
  z-index: 18;
}
.prompt, .toast {
  position: static;
  left: auto;
  bottom: auto;
  transform: none;
  background: rgba(244,234,214,.96);
  border: 1.5px solid var(--timber);
  padding: 6px 10px;
  max-width: 100%;
  text-align: center;
  font-size: 13px;
  line-height: 1.35;
  pointer-events: none;
  box-shadow: 0 2px 8px rgba(42,31,22,.12);
}
.prompt {
  max-height: 4.2em;
  overflow: hidden;
  display: -webkit-box;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 3;
}
.toast {
  display: flex;
  align-items: flex-start;
  gap: 6px;
  z-index: 13;
}
.toast-text {
  margin: 0;
  flex: 1;
  min-width: 0;
  max-height: 4.2em;
  overflow: hidden;
  display: -webkit-box;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 3;
  text-align: left;
}
.toast.ok { color: var(--good); }
.toast.err { color: var(--bad); font-weight: 700; }
.toast-dismiss {
  pointer-events: auto;
  flex: 0 0 auto;
  width: 36px;
  min-height: 36px;
  border: 2px solid var(--line);
  background: var(--cream-2);
  cursor: pointer;
}
.stick-wrap {
  position: absolute; left: 18px; bottom: 18px; z-index: 14;
}
.stick-base {
  width: 112px; height: 112px; border-radius: 50%;
  background: rgba(26,18,12,.28);
  border: 3px solid rgba(248,240,218,.7);
  position: relative;
  touch-action: none;
}
.stick-knob {
  width: 52px; height: 52px; border-radius: 50%;
  background: var(--amber);
  border: 3px solid var(--line);
  position: absolute; left: 30px; top: 30px;
}
.panel {
  position: fixed; right: 16px; top: 64px; bottom: 16px;
  width: min(420px, 94vw);
  background: var(--cream);
  display: flex; flex-direction: column;
  border: 1.5px solid var(--timber);
  box-shadow: 0 10px 28px rgba(42,31,22,.18);
  z-index: 30;
  overflow: hidden;
  padding: 0;
}
.panel-head {
  display: flex; justify-content: space-between; align-items: center;
  gap: 8px; padding: 8px 12px;
  background: linear-gradient(#7a5a38, #6b4a2e); color: var(--ivory);
  border-bottom: 2px solid var(--brass);
  position: sticky; top: 0;
}
.panel-head h2 { margin: 0; font-size: 18px; }
.panel-head .btn { background: var(--cream-2); color: var(--ink); }
.tabs { display: flex; gap: 6px; }
.panel .note, .panel p, .panel label, .totals { padding: 0 14px; }
.levels { display: flex; flex-wrap: wrap; gap: 6px; padding: 0 14px 8px; }
.chip { background: #efe6d2; border: 1px solid var(--brass); padding: 4px 8px; font-size: 12px; border-radius: 999px; }
.list { display: grid; gap: 8px; padding: 8px 14px; }
.item {
  background: #f3ead8; border: 1.5px solid var(--brass); padding: 8px 10px;
  display: flex; justify-content: space-between; gap: 8px; align-items: center;
  cursor: pointer; border-radius: 8px;
}
.item:hover { background: #ebe0c8; }
.filter-label { display: block; margin: 8px 0; }
.field, select {
  width: calc(100% - 28px); margin: 6px 14px 0;
  display: block;
  border: 1.5px solid var(--brass);
  background: #fbf6ea;
  padding: 8px;
  min-height: 40px;
}
.filter-label select { width: 100%; margin: 6px 0 0; }
.row { display: flex; flex-wrap: wrap; gap: 8px; padding: 10px 14px; }
.msg { min-height: 0; font-size: 14px; padding: 0 14px; }
.msg:empty { display: none; min-height: 0; padding: 0; margin: 0; }
.msg.ok { color: var(--good); }
.msg.err { color: var(--bad); font-weight: 700; }
@media (min-width: 901px) {
  .stick-wrap { display: none; }
}
@media (max-width: 900px) {
  .panel {
    top: auto; bottom: 0; left: 0; right: 0; width: 100%;
    max-height: 58vh; padding-bottom: 0; overflow: hidden;
  }
  #panel-wh .note { margin: 4px 0 0; padding: 0 12px; font-size: 12px; }
  #panel-wh .wh-summary { padding: 4px 12px 0; }
  #panel-wh .levels { padding: 2px 12px 4px; gap: 4px; }
  #panel-wh .lvl-chips { padding: 2px 12px 4px; gap: 4px; }
  #panel-wh .lvl-chip { min-height: 28px; padding: 2px 8px; }
  #panel-wh .pager { padding: 4px 12px 8px; }
  #panel-wh .card-grid { padding: 4px 12px 8px; }
}


.scene-hotspot {
  position: absolute;
  border: 0;
  padding: 0;
  margin: 0;
  background: transparent;
  cursor: pointer;
  z-index: 5;
  -webkit-tap-highlight-color: transparent;
}
.scene-hotspot:focus-visible {
  outline: 2px solid var(--brass);
  outline-offset: 2px;
  border-radius: 10px;
}
.hud-dock {
  position: static;
  flex: 0 0 auto;
  display: flex;
  flex-direction: column;
  gap: 0;
  justify-content: center;
  align-items: center;
  width: 100%;
  max-width: none;
  padding: 6px 8px max(8px, env(safe-area-inset-bottom));
  background: #ead4a4;
  border-top: 3px solid #c4a06a;
  z-index: 20;
  pointer-events: auto;
}
.dock-panel {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  width: 100%;
  padding: 8px 10px 6px;
  background: #f6e4bc;
  border: 3px solid #c9a56c;
  border-radius: 12px;
  box-shadow: inset 0 1px 0 #fff6df;
}
.dock-row {
  display: flex;
  flex-wrap: nowrap;
  justify-content: center;
  align-items: flex-end;
  gap: 10px 18px;
  width: 100%;
}
.medal {
  pointer-events: auto;
  position: relative;
  width: 72px;
  min-height: 84px;
  border: 0;
  background: transparent;
  padding: 0;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  align-items: center;
  -webkit-touch-callout: none;
  user-select: none;
}
.medal-disc {
  width: 64px;
  height: 56px;
  border-radius: 8px;
  display: grid;
  place-items: center;
  border: 2px solid #d7b889;
  overflow: hidden;
  background: #f7edd4;
  box-shadow: inset 0 1px 0 #fffaf0;
}
.medal-disc img { width: 100%; height: 100%; object-fit: contain; display: block; image-rendering: pixelated; image-rendering: crisp-edges; }
.medal-green, .medal-orange { background: transparent; }
.medal:active .medal-disc, .medal.is-pressed .medal-disc {
  transform: translateY(1px);
  box-shadow: 0 1px 2px rgba(42,31,22,.2);
}
.medal:disabled, .medal.is-disabled {
  opacity: .45;
  cursor: default;
}
.medal-label {
  margin-top: 4px;
  font-size: 12px;
  font-weight: 700;
  color: #3a2a1c;
  text-shadow: none;
  max-width: 76px;
  text-align: center;
  line-height: 1.15;
}
.medal-badge {
  position: absolute;
  top: -4px;
  right: 2px;
  min-width: 22px;
  height: 22px;
  padding: 0 5px;
  border-radius: 11px;
  background: #a34a38;
  color: #f4ead6;
  border: 1.5px solid #f4ead6;
  font-size: 11px;
  font-weight: 800;
  display: grid;
  place-items: center;
  z-index: 1;
}
.hud-capsule {
  position: absolute;
  right: 18px;
  bottom: 18px;
  z-index: 16;
  min-width: 108px;
  min-height: 56px;
  padding: 0 18px;
  border-radius: 28px;
  border: 4px solid #6b3a18;
  background: linear-gradient(#ffe7a8, #f0a02a);
  color: var(--ink);
  font-weight: 800;
  box-shadow: 0 5px 0 #3a220e, 0 8px 12px rgba(26,18,12,.3), inset 0 3px 0 rgba(255,255,255,.45);
  -webkit-touch-callout: none;
  user-select: none;
}
.hud-capsule:active, .hud-capsule.is-pressed {
  transform: translateY(3px);
  box-shadow: 0 2px 0 #3a220e, inset 0 4px 6px rgba(0,0,0,.16);
}
.pager {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 8px 14px;
}
.pager .btn { min-height: 44px; }
@media (min-width: 901px) {
  body { position: relative; }
  .hud-dock {
    position: absolute;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 22;
    background: transparent;
    border: 0;
    padding: 12px 16px max(14px, env(safe-area-inset-bottom));
    pointer-events: none;
  }
  .dock-panel {
    pointer-events: auto;
    width: max-content;
    max-width: min(540px, 92vw);
    padding: 8px 18px 10px;
    border-radius: 20px;
  }
  .dock-row { gap: 10px 20px; width: auto; }
  .medal { width: 72px; min-height: 86px; }
  .medal-disc { width: 56px; height: 56px; }
  .medal-label { font-size: 12px; max-width: 76px; }
}
@media (max-width: 600px) {
  .hud { padding: 4px 8px; gap: 4px 8px; }
  .brand strong { font-size: 13px; }
  .tag { font-size: 10px; }
  .hud-stats { font-size: 12px; gap: 8px; }
  .medal { width: 68px; min-height: 80px; }
  .medal-disc { width: 54px; height: 54px; }
  .medal-label { font-size: 11px; max-width: 70px; }
}

.item-on { background: #e8dcc4; outline: 2px solid var(--brass); }

.stick-wrap, .hud-capsule, #btn-interact { display: none !important; }

.visually-hidden {
  position: absolute; width: 1px; height: 1px; overflow: hidden;
  clip: rect(0 0 0 0); white-space: nowrap; border: 0; padding: 0; margin: -1px;
}
.panel-body { flex: 1 1 auto; min-height: 0; overflow: auto; }
.panel-foot {
  flex: 0 0 auto;
  position: sticky; bottom: 0;
  background: linear-gradient(#f4ead6, #efe4ce);
  border-top: 1px solid rgba(107,74,46,.25);
  padding-bottom: max(8px, env(safe-area-inset-bottom));
}
.card-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
  padding: 8px 14px 12px;
}
@media (min-width: 560px) {
  .card-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); }
}
.unit-card {
  position: relative;
  min-height: 76px;
  min-width: 0;
  border: 1.5px solid var(--brass);
  background: linear-gradient(#f7f1e4, #e8d9b8);
  border-radius: 10px;
  padding: 8px 8px 8px 6px;
  display: grid;
  grid-template-columns: 56px 1fr;
  align-items: center;
  gap: 0 8px;
  text-align: left;
  cursor: pointer;
  color: var(--ink);
  box-shadow: 0 1px 0 rgba(196,163,106,.65), 0 2px 6px rgba(42,31,22,.1);
}
.unit-card.is-on {
  outline: 2px solid var(--timber);
  box-shadow: 0 0 0 3px rgba(196,163,106,.4);
  background: linear-gradient(#efe4c8, #ddd0ae);
}
.unit-portrait { width: 56px; height: 56px; object-fit: contain; pointer-events: none; }
.unit-badge {
  position: absolute; left: 4px; top: 4px;
  background: var(--timber); color: var(--ivory);
  font-size: 10px; font-weight: 700; border-radius: 8px; padding: 1px 5px;
}
.unit-copy { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.unit-name { font-weight: 700; font-size: 13px; line-height: 1.2; }
.unit-id, .unit-stat { font-size: 11px; color: #5a4634; }
.lvl-chips {
  display: flex; flex-wrap: wrap; gap: 6px;
  padding: 4px 14px 8px;
}
.lvl-chip {
  min-height: 32px; padding: 4px 10px;
  border-radius: 999px;
  border: 1px solid var(--brass);
  background: #f7f1e4;
  color: var(--ink);
  cursor: pointer;
}
.lvl-chip.is-on {
  background: linear-gradient(#d7c089, #b89556);
}
.wh-summary, .claim-summary {
  display: flex; flex-wrap: wrap; gap: 6px; align-items: center;
  padding: 8px 14px 0; font-size: 13px;
}
.merge-eq { padding: 8px 14px 0; }
.merge-eq.is-empty { color: #5a4634; }
.eq-row { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; justify-content: center; }
.eq-slot {
  position: relative;
  width: 84px; min-height: 88px;
  border: 1.5px solid var(--brass);
  border-radius: 10px;
  background: linear-gradient(#f7f1e4, #e8d9b8);
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  padding: 14px 4px 6px;
}
.eq-slot img { width: 56px; height: 56px; object-fit: contain; }
.eq-slot .unit-badge { left: 6px; top: 4px; }
.eq-slot.is-missing { color: #5a4634; font-size: 12px; text-align: center; }
.eq-slot.is-result { box-shadow: 0 0 0 2px rgba(107,127,84,.35); }
.eq-id { font-size: 11px; }
.eq-plus, .eq-arrow { font-weight: 700; color: var(--timber); }
.eq-meta { display: flex; flex-wrap: wrap; gap: 10px; justify-content: center; margin-top: 8px; font-size: 13px; }
.coin {
  display: inline-block; width: 14px; height: 14px; margin-right: 4px; vertical-align: -2px;
  border-radius: 50%;
  background: radial-gradient(circle at 35% 30%, #f0e0b0, #c4a36a 62%, #8a6a3e);
  box-shadow: inset 0 1px 0 rgba(255,255,255,.4);
}
.eq-note { margin: 6px 0 0; font-size: 12px; color: #5a4634; }
.panel .note { font-size: 13px; color: #5a4634; }
@media (max-width: 430px) {
  .hud-dock { gap: 4px; padding: 6px 6px max(8px, env(safe-area-inset-bottom)); }
  .dock-row { gap: 6px 10px; }
  .medal { width: 64px; min-height: 78px; }
  .medal-disc { width: 52px; height: 52px; }
  .medal-label { font-size: 11px; max-width: 64px; }
}

.unit-card.is-dead { opacity: .78; filter: grayscale(.25); }
.unit-card.is-warn .unit-badge, .unit-detail.is-warn .stat.is-warn dd { color: #7a3b1c; }
.unit-card.is-dead .unit-badge { background: #5c4033; }
.unit-detail { padding: 4px 0 8px; }
.unit-detail-hero { display: flex; gap: 12px; align-items: center; padding: 4px 0 10px; }
.unit-detail-hero strong { display: block; }
.stat-list { display: grid; gap: 6px; margin: 0; }
.stat { display: grid; grid-template-columns: 7.5em 1fr; gap: 8px; padding: 6px 8px; background: linear-gradient(#f7f1e4, #efe6d2); border: 1px solid rgba(196,163,106,.55); border-radius: 8px; }
.stat dt { font-size: 12px; color: #5a4634; }
.stat dd { margin: 0; font-weight: 700; }
.stat.is-dead dd { color: #8a3e2c; }
.battle-log { margin-top: 10px; padding: 8px; border: 1px dashed rgba(107,74,46,.35); border-radius: 8px; }
.battle-summary { margin: 0 0 4px; font-weight: 700; }
.battle-log ul { margin: 6px 0 0; padding-left: 18px; }

.panel-foot.is-empty, .panel-foot[hidden] { display: none; }
.combat-rule {
  margin: 0 0 8px;
  padding: 8px 10px;
  background: #efe6d2;
  border: 1.5px solid var(--brass);
  border-radius: 8px;
  font-weight: 700;
  font-size: 14px;
}
