@font-face {
  font-family: LanternBody;
  src: url("/play/apothecary/fonts/plexsans-latin.woff2") format("woff2");
  font-display: swap;
}
@font-face {
  font-family: LanternTitle;
  src: url("/play/apothecary/fonts/cinzel-latin.woff2") format("woff2");
  font-display: swap;
}
:root {
  color-scheme: dark;
  --ink: #152c29;
  --ink-deep: #102320;
  --parchment: #f6e3ba;
  --muted: #e1cba3;
  --gold: #ecc574;
  --line: #a98a566b;
  --shadow: #071512;
  --body: LanternBody, Georgia, serif;
  --title: LanternTitle, Georgia, serif;
  --lift: cubic-bezier(0.16, 0.82, 0.32, 1);
  --controls-top: max(3px, env(safe-area-inset-top), var(--kids-inset-top, 0px));
  --controls-left: max(8px, env(safe-area-inset-left), var(--kids-inset-left, 0px));
  --controls-right: max(8px, env(safe-area-inset-right), var(--kids-inset-right, 0px));
  --control-size: 44px;
}
*,
*::before,
*::after {
  box-sizing: border-box;
}
html {
  min-height: 100%;
  background: #172c29;
}
body {
  margin: 0;
  color: var(--parchment);
  font: 16px/1.45 var(--body);
  min-height: 100vh;
  min-height: 100svh;
}
[hidden] {
  display: none !important;
}
button,
a {
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
}
button {
  font: inherit;
  color: inherit;
  cursor: pointer;
}
button:disabled {
  cursor: default;
  opacity: 0.55;
}
button:focus-visible,
a:focus-visible,
canvas:focus-visible {
  outline: 3px solid #f9d88d;
  outline-offset: 3px;
}
button:active:not(:disabled) {
  transform: translateY(1px);
}
h1,
h2,
h3,
p {
  margin: 0;
}
.field-backdrop {
  position: fixed;
  inset: 0;
  pointer-events: none;
  background: radial-gradient(ellipse at 52% 38%, #29483d, #102725 67%);
}
body.in-play .field-backdrop {
  background:
    radial-gradient(ellipse at 57% 14%, #29443af2, #142925eb 54%, #0e201fe6 100%),
    url("./art/village.webp") center bottom/cover no-repeat;
}
.shell {
  position: relative;
  margin: 0 auto;
  width: min(100%, 1260px);
  min-height: 100vh;
  min-height: 100svh;
  padding: 0 max(18px, env(safe-area-inset-right)) max(16px, env(safe-area-inset-bottom))
    max(18px, env(safe-area-inset-left));
}
.topbar {
  position: absolute;
  z-index: 4;
  inset: var(--controls-top) var(--controls-right) auto var(--controls-left);
  height: var(--control-size);
  display: flex;
  align-items: center;
  justify-content: flex-end;
  pointer-events: none;
}
@media (orientation: portrait) {
  .topbar { justify-content: flex-start; }
}
.topbar .icon-button {
  width: var(--control-size);
  height: var(--control-size);
  padding: 0;
  border: 0;
  border-radius: 8px;
  background: none;
  box-shadow: none;
  backdrop-filter: none;
  filter: drop-shadow(0 1px 2px #152c29) drop-shadow(0 0 4px #152c29);
  pointer-events: auto;
}
.topbar .icon-button:focus-visible { outline-offset: -4px; }
.topbar[inert] { visibility: hidden; }
.icon-button {
  min-width: 44px;
  min-height: 44px;
  display: grid;
  place-items: center;
  border: 1px solid #c0d2be44;
  border-radius: 50%;
  background: #1d3534bc;
  backdrop-filter: blur(10px);
  color: #fff3d1;
  text-decoration: none;
  box-shadow: 0 5px 16px #081a1655;
}
.icon-button:hover {
  background: #345047da;
}
.options span,
.options span::before,
.options span::after {
  width: 4px;
  height: 4px;
  display: block;
  background: currentColor;
  border-radius: 50%;
  position: relative;
}
.options span::before,
.options span::after {
  content: "";
  position: absolute;
  top: 0;
}
.options span::before {
  left: -7px;
}
.options span::after {
  left: 7px;
}
.primary,
.carved {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  text-align: center;
  min-height: 46px;
  padding: 8px 15px;
  border-radius: 9px;
  transition:
    background 0.16s var(--lift),
    border-color 0.16s var(--lift),
    filter 0.16s var(--lift);
}
.primary {
  background: linear-gradient(155deg, #f5d58f, #d9a44f);
  color: #221c11;
  border: 1px solid #f8dea5;
  box-shadow:
    inset 0 0 0 2px #8b57262e,
    0 4px #614620,
    0 6px 16px #071c1766;
  font-weight: 800;
}
.primary:hover:not(:disabled) {
  filter: brightness(1.12);
}
.carved {
  background: linear-gradient(155deg, #354b3d, #1d322b);
  border: 1px solid #b59a665f;
  box-shadow:
    inset 0 0 0 1px #0e21172c,
    0 2px #101b15;
  color: #f0deba;
  font-weight: 700;
}
.carved:hover:not(:disabled) {
  border-color: #efd495;
  color: #ffecc1;
  background: #3d5142;
}
.play {
  width: min(100%, 1050px);
  margin: 0 auto;
}
.stage-head {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 10px;
  margin: 1px 2px 10px;
}
.stage-place {
  min-width: 0;
}
.chapter-name {
  font-size: 12px;
  color: #e8cf96;
  line-height: 1.2;
}
.stage-place h1 {
  font: 800 clamp(21px, 3.3vw, 39px)/1.18 var(--title);
  color: #ffdf9b;
  overflow-wrap: anywhere;
}
.meters {
  display: flex;
  align-items: center;
  gap: 7px;
  flex-shrink: 0;
  padding-bottom: 2px;
}
.meter {
  display: inline-flex;
  gap: 4px;
  align-items: center;
  justify-content: center;
  border: 1px solid #b591595f;
  border-radius: 7px;
  background: #102821b8;
  min-height: 32px;
  min-width: 41px;
  padding: 2px 7px;
  font-weight: 800;
  font-variant-numeric: tabular-nums;
  color: #ffdf9d;
}
.wave-count {
  font-size: 12px;
  font-variant-numeric: tabular-nums;
  color: #f2dbae;
  white-space: nowrap;
}
.crossing-frame {
  --watch-card-width: clamp(56px, 6.4vw, 80px);
  --watch-card-height: calc(var(--watch-card-width) + 18px);
  position: relative;
  overflow: hidden;
  border-radius: 13px;
  border: 2px solid #c3a06a;
  box-shadow:
    0 0 0 1px #071b18,
    0 12px 24px #0717138c,
    0 0 22px #e3b26d17;
  background: #344c3f url("./art/village.webp") center/cover;
}
.held-tool {
  position: fixed;
  z-index: 4;
  width: 36px;
  height: 36px;
  padding: 3px;
  object-fit: contain;
  border: 1px solid #edc16e;
  border-radius: 6px;
  background: #392c21ed;
  box-shadow: 0 2px 5px #1b1614b3;
  pointer-events: none;
}
.arena {
  display: block;
  width: 100%;
  height: clamp(232px, 55svh, 548px);
  outline-offset: -5px !important;
  touch-action: none;
  cursor: crosshair;
}
.board-alert {
  position: absolute;
  left: 50%;
  top: 15%;
  width: auto;
  max-width: 90%;
  transform: translateX(-50%);
  background: #1a3129e8;
  border: 1px solid #d3ab66a0;
  border-radius: 8px;
  padding: 8px 14px;
  color: #ffe1a2;
  box-shadow: 0 5px 14px #14211690;
  font-weight: 700;
  pointer-events: none;
}
.player-deck {
  display: grid;
  gap: 9px;
  padding-top: 9px;
}
.plan {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 10px;
  align-items: center;
  min-height: 49px;
  padding: 0 2px;
}
.instruction {
  color: #eee0c0;
  line-height: 1.23;
  min-height: 1.23em;
  font-size: clamp(13px, 1.6vw, 16px);
}
.tray {
  display: grid;
  grid-template-columns: repeat(var(--slots, 3), minmax(0, 1fr));
  gap: 7px;
  align-items: stretch;
  padding: 6px;
  border: 1px solid var(--line);
  border-radius: 11px;
  background: linear-gradient(175deg, #4f4430b3, #2b3025);
  box-shadow:
    inset 0 1px 2px #f0d09137,
    0 4px 14px #0b1d18a6;
}
.tool {
  display: grid;
  grid-template-columns: 49px 1fr;
  align-items: center;
  text-align: left;
  gap: 6px;
  padding: 4px 6px;
  min-height: 61px;
  min-width: 0;
  background: linear-gradient(145deg, #51614a, #283d32);
  border: 1px solid #a58f5770;
  border-radius: 7px;
  color: #ffebc5;
  text-shadow: 0 1px #172821;
  position: relative;
}
.tool[data-terrain="water"] {
  background: linear-gradient(145deg, #44636a, #22414b);
}
.tool[aria-pressed="true"] {
  border-color: #ffdf88;
  box-shadow:
    inset 0 0 0 1px #f6cf6e,
    0 0 12px #f5b8575e;
  background: linear-gradient(145deg, #735a35, #4a432d);
}
.tool[data-affordable="false"] {
  filter: saturate(0.52);
  color: #ead3b5;
}
.tool img {
  display: block;
  pointer-events: none;
  width: 48px;
  height: 47px;
  object-fit: contain;
  filter: drop-shadow(0 2px 3px #111b15c2);
}
.tool strong {
  display: block;
  line-height: 1.02;
  overflow-wrap: break-word;
  font-size: 13px;
}
.tool em {
  display: block;
  font-size: 12px;
  font-style: normal;
  color: #f6cd87;
  font-variant-numeric: tabular-nums;
}
.commands {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
  align-items: center;
  justify-content: center;
  margin-bottom: 3px;
}
.command {
  font-size: 13px;
  min-height: 44px;
  padding: 6px 11px;
  background: #203a31;
  border: 1px solid #a68d586a;
  border-radius: 8px;
  color: #f4dfb4;
}
.command[aria-pressed="true"] {
  background: #625133;
  border-color: #f2ca77;
}
.command:hover:not(:disabled) {
  border-color: #d3b778;
}
.command small {
  font: inherit;
  font-size: 11px;
  color: #e2bd75;
}
.modal {
  position: fixed;
  z-index: 10;
  inset: 0;
  background: #0b1917bc;
  display: grid;
  align-items: center;
  justify-items: center;
  padding: max(14px, env(safe-area-inset-top)) max(14px, env(safe-area-inset-right))
    max(14px, env(safe-area-inset-bottom)) max(14px, env(safe-area-inset-left));
  backdrop-filter: blur(4px);
}
.sheet {
  width: min(100%, 680px);
  max-height: calc(100svh - 34px);
  overflow: auto;
  overscroll-behavior: contain;
  background: linear-gradient(140deg, #415447, #213a32 58%, #1c322c);
  border: 1px solid #c09d65;
  border-radius: 15px;
  padding: clamp(17px, 4vw, 30px);
  box-shadow:
    inset 0 0 0 4px #304135,
    inset 0 0 0 5px #ad935b45,
    0 16px 60px #041913b9;
  outline: none;
  scrollbar-color: #967e50 #263c30;
}
.sheet[aria-label="Full screen"] {
  width: min(100%, 890px);
}
.sheet h2 {
  font: 800 clamp(24px, 4.4vw, 43px)/1.15 var(--title);
  color: #ffda95;
  overflow-wrap: anywhere;
}
.sheet h3 {
  color: #f5d899;
  font: 700 17px/1.25 var(--title);
  margin: 13px 0 5px;
}
.sheet p {
  color: #f1e1bd;
  margin-top: 8px;
}
.sheet-top {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 12px;
}
.sheet-top .icon-button {
  font-size: 24px;
  line-height: 1;
  flex: none;
}
.sheet-actions {
  display: flex;
  gap: 10px;
  margin-top: 17px;
  flex-wrap: wrap;
}
.sheet-actions > * {
  flex: 1;
  min-width: 118px;
}
.guide-list {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}
.guide-unit,
.kit-choice,
.challenge {
  display: flex;
  align-items: center;
  gap: 8px;
  border: 1px solid #aa905451;
  border-radius: 8px;
  padding: 7px;
  background: #1b392b;
}
.guide-unit img,
.kit-choice img {
  width: 50px;
  height: 46px;
  flex: none;
  object-fit: contain;
}
.guide-unit strong,
.kit-choice strong {
  display: block;
  font-size: 14px;
  color: #ffe2aa;
  line-height: 1.16;
}
.guide-unit small,
.kit-choice small {
  display: block;
  font-size: 12px;
  line-height: 1.26;
  color: #eddbb1;
  margin-top: 3px;
}
.guide-unit .guide-lock {
  color: #ddbe85;
  font-style: italic;
}
.unlock-list {
  display: flex;
  flex-wrap: wrap;
  gap: 7px;
  margin-top: 12px;
}
.unlock-card {
  display: flex;
  align-items: center;
  flex: 1;
  gap: 8px;
  min-width: 127px;
  padding: 6px 10px;
  background: #584732;
  border: 1px solid #cfac63a1;
  border-radius: 8px;
  color: #fff0c9;
}
.unlock-card img {
  width: 43px;
  height: 43px;
  flex: none;
  object-fit: contain;
}
.unlock-card small,
.unlock-card strong {
  display: block;
  line-height: 1.15;
}
.unlock-card small {
  font-size: 11px;
  color: #f2ca84;
  margin-bottom: 4px;
}
.kit-choice {
  position: relative;
  text-align: left;
  min-height: 55px;
}
.sheet[data-view="kit"] {
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
.sheet[data-view="kit"] .sheet-top {
  flex: none;
  margin-bottom: 3px;
}
.kit-content {
  flex: 1 1 auto;
  min-height: 0;
  overflow-y: auto;
  overscroll-behavior: contain;
  scrollbar-width: thin;
  padding: 0 4px 5px 0;
}
.kit-brief { font-size: 13px; line-height: 1.28; }
.kit-list {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 7px;
}
.kit-detail {
  display: none;
}
.kit-choice[data-terrain="water"] {
  background: #24434a;
}
.kit-choice[aria-pressed="true"] {
  border-color: #f3cf7f;
  background: #4d4b2e;
}
.kit-choice[aria-pressed="true"]::after {
  content: "";
  position: absolute;
  top: 3px;
  right: 4px;
  width: 9px;
  height: 5px;
  border: solid #ffdf94;
  border-width: 0 0 2px 2px;
  transform: rotate(-45deg);
  pointer-events: none;
}
.kit-choice[data-pending="true"] {
  border-style: dashed;
  border-color: #ffd995;
  box-shadow: inset 0 0 0 1px #ffd995;
}
.kit-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex: none;
  border-top: 1px solid #bfa16968;
  padding-top: 9px;
}
.kit-footer p {
  margin: 0;
  font-size: 13px;
  line-height: 1.24;
}
.kit-footer button {
  flex: none;
  min-width: 140px;
  padding: 7px 10px;
}
.scout {
  margin: 10px 0 12px;
  padding: 6px 8px 9px;
  border: 1px solid #a98c5657;
  border-radius: 9px;
  background: #132e27;
}
.scout h3 {
  margin: 0 0 5px;
  font-size: 14px;
}
.enemy-preview {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(58px, 1fr));
  gap: 5px;
  padding: 2px;
}
.scout-enemy {
  display: grid;
  justify-items: center;
  align-content: start;
  gap: 2px;
  min-height: 56px;
  border: 1px solid #a8996370;
  border-radius: 7px;
  background: #2f4639;
  color: #ffebbf;
  line-height: 1.12;
  padding: 3px;
  font-size: 11px;
}
.scout-enemy[aria-pressed="true"] {
  border-color: #ffda86;
  background: #5a4b31;
}
.scout-enemy img {
  width: 40px;
  height: 34px;
  object-fit: contain;
  pointer-events: none;
}
.scout .scout-line {
  font-size: 13px;
  margin-top: 5px;
}
.keepsake {
  border-left: 3px solid #d7aa61;
  padding: 5px 10px;
  background: #493e2759;
  color: #fde4a9 !important;
}
.keepsakes {
  padding-left: 20px;
  font-size: 14px;
  color: #ecd5a2;
}
.modal:has(.sheet[data-view^="result"]) {
  align-items: center;
  background: radial-gradient(ellipse at center, #101e17a3, #071411cc);
}
body:has(.modal:not([hidden]) .sheet[data-view^="result"]) .scene-note { display: none; }
.sheet[data-view="result-win"] {
  width: min(calc(100vw - 28px), 620px);
  max-height: calc(100svh - 28px);
  padding: 0;
  background: transparent;
  border: 0;
  border-radius: 0;
  box-shadow: none;
  text-align: center;
}
.victory-result {
  aspect-ratio: 2.945 / 1;
  padding: 0 13%;
  background: url('./art/village-held.webp') center / contain no-repeat;
  display: grid;
  justify-items: center;
  align-content: center;
  gap: clamp(2px, .7vw, 8px);
}
.victory-copy .sheet-top { display: block; margin: 0; }
.victory-copy h2 {
  margin: 0;
  font-size: clamp(22px, 4.1vw, 34px);
  line-height: .98;
  text-wrap: balance;
}
.sheet .campaign-finale { margin: 3px auto; max-width: 430px; font-size: 14px; }
.victory-reward {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
}
.victory-art {
  width: clamp(32px, 7vw, 50px);
  height: clamp(32px, 7vw, 50px);
  flex: none;
  object-fit: contain;
  filter: drop-shadow(0 3px 5px #0b120db5);
}
.victory-reward-copy { text-align: left; line-height: 1.05; }
.victory-reward small,
.victory-reward strong { display: block; }
.victory-reward small { color: #f6d797; font-size: 11px; }
.victory-reward strong { color: #fff0bd; font: 700 18px/1.05 var(--title); }
.victory-keepsake { display: grid; gap: 1px; }
.outcome-number { color: #f1ce8e; font-size: 14px; }
.sheet[data-view="result-win"] .outcome-number { margin: 4px 0 7px; color: #fff0cf; text-shadow: 0 1px 4px #0a140e; }
.sheet[data-view="result-win"] .sheet-actions {
  width: min(100%, 365px);
  margin: 2px auto 0;
  gap: 7px;
  flex-wrap: nowrap;
}
.sheet[data-view="result-win"] .sheet-actions > * { min-width: 0; padding: 7px 10px; }
.sheet[data-view="result-lose"] { width: min(calc(100vw - 28px), 430px); text-align: center; }
.loss-result { display: grid; justify-items: center; gap: 6px; }
.loss-result .sheet-top { display: block; margin: 0; }
.loss-result .sheet-top h2 { margin: 0; }
.loss-result p { margin: 0; }
.breach-recap {
  display: grid;
  grid-template-columns: 54px minmax(0, 1fr);
  align-items: center;
  gap: 10px;
  margin: 5px 0;
  text-align: left;
}
.breach-recap img { width: 54px; height: 54px; object-fit: contain; }
.breach-recap strong { color: var(--gold, #ffdda0); }
.breach-recap p { margin-top: 3px; }
.sheet[data-view="result-lose"] .sheet-actions { justify-content: center; margin-top: 15px; }
.victory-motion { animation: victory-arrival 260ms ease-out both; }
@keyframes victory-arrival {
  from { opacity: 0.72; transform: translateY(9px); }
  to { opacity: 1; transform: translateY(0); }
}
@media (max-height: 520px) and (orientation: landscape) {
  .sheet[data-view="result-win"] { width: min(100%, 155svh, 620px); }
  .victory-copy h2 { font-size: clamp(20px, 3.7vw, 28px); }
  .victory-art { width: 38px; height: 38px; }
  .victory-reward strong { font-size: 15px; }
  .sheet[data-view="result-win"] .sheet-actions > * { padding-block: 5px; }
}
.challenge {
  margin: 8px 0;
  justify-content: space-between;
  min-height: 58px;
}
.challenge p {
  font-size: 13px;
  margin: 2px 0 0;
}
.toggle-row {
  min-height: 48px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
  padding: 6px 0;
  border-bottom: 1px solid #9e8a5b50;
}
.toggle {
  min-width: 64px;
  min-height: 44px;
}
@media (max-width: 690px) {
  .arena {
    height: clamp(226px, 43svh, 402px);
  }
  .tool {
    grid-template-columns: 1fr;
    justify-items: center;
    gap: 0;
    min-height: 63px;
    text-align: center;
    padding: 2px 2px 4px;
  }
  .tool img {
    width: 37px;
    height: 32px;
  }
  .tool strong,
  .tool em {
    font-size: 11px;
  }
  .stage-place h1 {
    font-size: clamp(19px, 5.2vw, 29px);
  }
}
@media (max-width: 430px) {
  .shell {
    padding-left: max(7px, env(safe-area-inset-left));
    padding-right: max(7px, env(safe-area-inset-right));
  }
  .meters {
    display: grid;
    grid-template-columns: auto auto;
    gap: 4px;
    text-align: right;
  }
  .meter {
    min-width: 35px;
    min-height: 26px;
    padding: 0 4px;
    font-size: 14px;
  }
  .wave-count {
    grid-column: 1/-1;
    font-size: 11px;
    line-height: 1;
  }
  .stage-head {
    margin: 3px 3px 6px;
  }
  .tray {
    gap: 4px;
    padding: 4px;
  }
  .commands {
    gap: 4px;
  }
  .command {
    font-size: 12px;
    padding: 4px 8px;
  }
  .guide-list {
    grid-template-columns: 1fr;
  }
  .kit-choice {
    gap: 3px;
    padding: 4px;
    min-height: 60px;
  }
  .kit-choice img {
    width: 35px;
    height: 37px;
  }
  .kit-choice strong {
    font-size: 12px;
  }
  .kit-choice small {
    font-size: 11px;
  }
  .kit-footer button {
    min-width: 118px;
    font-size: 13px;
  }
}
@media (max-width: 430px) and (max-height: 840px) {
  .sheet[data-view="kit"] {
    padding-top: 13px;
    padding-bottom: 13px;
  }
  .kit-content > p {
    font-size: 13px;
  }
  .enemy-preview {
    grid-template-columns: repeat(auto-fill, minmax(51px, 1fr));
    gap: 4px;
  }
  .kit-list {
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 4px;
  }
  .kit-choice {
    flex-direction: column;
    justify-content: center;
    text-align: center;
    min-height: 52px;
  }
  .kit-choice img {
    width: 31px;
    height: 30px;
  }
  .kit-choice small {
    display: none;
  }
  .kit-detail:not(:empty) {
    display: block;
    margin: 5px 0 0;
    line-height: 1.24;
  }
}
@media (max-height: 520px) and (orientation: landscape) {
  .shell {
    padding: 0 12px 8px;
    max-width: 900px;
  }
  .play {
    display: grid;
    grid-template-columns: minmax(0, 1fr) minmax(212px, 34vw);
    align-items: start;
    gap: 5px 8px;
  }
  .stage-head {
    grid-column: 1/-1;
    margin: 0 2px;
  }
  .stage-place h1 {
    font-size: clamp(18px, 3.2vw, 27px);
  }
  .arena {
    height: clamp(150px, 64svh, 315px);
  }
  .player-deck {
    padding-top: 0;
    align-content: start;
    gap: 5px;
  }
  .plan {
    grid-template-columns: minmax(0, 1fr) 88px;
    gap: 6px;
    min-height: 44px;
    padding: 0;
  }
  .plan .instruction {
    font-size: 11px;
  }
  .tray {
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 4px;
    padding: 4px;
  }
  .tool {
    grid-template-columns: 19px minmax(0, 1fr);
    justify-items: start;
    gap: 3px;
    min-height: 46px;
    padding: 2px;
    text-align: left;
  }
  .tool img {
    width: 19px;
    height: 20px;
  }
  .tool strong {
    font-size: 10px;
  }
  .tool em {
    font-size: 11px;
  }
  .commands {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 4px;
  }
  .command {
    padding: 4px 3px;
    font-size: 11px;
  }
}
@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    transition: none !important;
    scroll-behavior: auto !important;
  }
}

/* In play, the timber rack is mounted into the upper edge of the yard. */
.field-delivery {
  position: absolute;
  z-index: 3;
  display: grid;
  width: 58px;
  min-height: 54px;
  padding: 0;
  justify-items: center;
  transform: translate(-50%, -72%);
  border: 0;
  background: transparent;
  cursor: pointer;
}
.field-delivery > * { pointer-events: none; }
.field-delivery img {
  display: block;
  width: 48px;
  height: 37px;
  object-fit: contain;
  filter: drop-shadow(0 4px 4px #21190ecb);
}
.field-delivery span {
  padding: 0 6px 1px;
  border: 1px solid #d5b472;
  border-radius: 4px;
  background: #3b2a1b;
  color: #fff0bc;
  font-weight: 700;
  font-size: 13px;
}
.coin-receipts {
  position: absolute;
  inset: 0;
  z-index: 5;
  pointer-events: none;
}
.coin-receipt { position: absolute; display: grid; place-items: center; width: 24px; height: 24px; transform: translate(-50%, -50%); }
.coin-receipt .coin-icon { width: 24px; height: 24px; }
.coin-gain {
  position: absolute; left: calc(100% + 1px); top: 50%; transform: translateY(-50%);
  color: #fff1b7; font: 900 16px/1 var(--body), sans-serif;
  font-variant-numeric: tabular-nums;
  text-shadow: 0 1px 2px #281708, 1px 0 #281708, -1px 0 #281708, 0 -1px #281708;
}
.coin-receipt-edge .coin-gain { left: auto; right: calc(100% + 1px); }
.delivery-motion { animation: deliver-coins 280ms ease-out both; }
@keyframes deliver-coins {
  from { transform: translate(-85%, -112%); opacity: 0; }
  65% { transform: translate(-50%, -63%); opacity: 1; }
  to { transform: translate(-50%, -72%); opacity: 1; }
}
body.in-play { overflow: hidden; }
body.in-play .shell {
  --battle-tools-top: var(--controls-top);
  --battle-tools-left: var(--controls-left);
  --battle-tools-right: calc(var(--controls-right) + var(--control-size) + 5px);
  width: 100%;
  padding: 0;
}
@media (orientation: portrait) {
  body.in-play .shell {
    --battle-tools-left: calc(var(--controls-left) + var(--control-size) + 5px);
    --battle-tools-right: var(--controls-right);
  }
}
.play {
  display: block;
  width: 100%;
  margin: 0;
}
.crossing-frame {
  position: relative;
  isolation: isolate;
  min-width: 0;
  overflow: hidden;
  border: 0;
  border-radius: 0;
  background: #344538;
  box-shadow: none;
}
.battle-title,
.barricade-status {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip-path: inset(50%);
}
.arena {
  display: block;
  width: 100%;
  height: 100svh;
  touch-action: none;
  height: 100dvh;
  min-height: 0;
  max-height: none;
  background: #344538;
}
.arriving-watch .crossing-frame::after {
  content: "";
  position: absolute;
  z-index: 3;
  inset: 0;
  pointer-events: none;
  background: radial-gradient(ellipse at 51% 48%, #ffe09b, #36232b 96%);
  animation: enter-watch 0.34s var(--lift) both;
}
@keyframes enter-watch {
  from { opacity: 0.66; }
  to { opacity: 0; }
}
@media (prefers-reduced-motion: reduce) {
  .arriving-watch .crossing-frame::after { display: none; }
}
.watch-actions {
  position: absolute;
  z-index: 2;
  top: calc(100% + 7px);
  left: 0;
  width: max-content;
  max-width: calc(100vw - var(--battle-tools-left) - var(--battle-tools-right));
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 4px;
}
.wave-action {
  min-width: 60px;
  min-height: 44px;
  padding: 3px 10px;
  border: 0;
  color: #291b0d;
  background: transparent url('./art/title-plank.webp') center / 100% 100% no-repeat;
  box-shadow: none;
  text-shadow: 0 1px #ffdb879e;
  font-size: 15px;
  font-weight: 900;
  white-space: nowrap;
}
.wave-countdown {
  margin: 0; padding: 5px 8px; color: #ffe4a1; background: #252a20e8;
  border: 1px solid #bd96599c; border-radius: 4px; font-size: 12px; font-weight: 800;
  font-variant-numeric: tabular-nums; white-space: nowrap; pointer-events: none;
}
.wave-banner {
  position: absolute; z-index: 6; left: 0; right: 0; top: 47%; margin: 0;
  padding: 8px 12px 10px; transform: translateY(-50%); box-sizing: border-box;
  background: linear-gradient(90deg, #1b221b00, #202419ed 18% 82%, #1b221b00);
  border-block: 1px solid #e6b76655; border-image: linear-gradient(90deg, transparent, #e6b766b3, transparent) 1;
  text-align: center; color: #ffe6ac; text-shadow: 0 2px 3px #140e07;
  font: 900 clamp(23px, 5vw, 47px)/1.07 var(--title), Georgia, serif;
  pointer-events: none;
  animation: wave-banner-in 190ms ease-out both;
}
.wave-banner[data-kind="final"] { color: #ffcd79; background: linear-gradient(90deg, #2a191500, #45281bef 18% 82%, #2a191500); }
.wave-banner:empty { height: 0; padding: 0; border: 0; animation: none; }
.wave-banner[data-still] { animation: none; }
@keyframes wave-banner-in {
  from { opacity: 0; transform: translateY(-46%); }
  to { opacity: 1; transform: translateY(-50%); }
}
@media (prefers-reduced-motion: reduce) { .wave-banner { animation: none; } }
.board-alert,
.scene-note {
  position: absolute;
  z-index: 2;
  top: auto;
  bottom: max(8px, env(safe-area-inset-bottom));
  left: max(10px, env(safe-area-inset-left));
  max-width: 75%;
  padding: 5px 8px;
  color: #fff1d2;
  border: 1px solid #dbbb776e;
  border-radius: 5px;
  background: #222f23ed;
  transform: none;
  pointer-events: none;
}
.board-alert {
  left: auto;
  right: 10px;
  font-size: 12px;
}
.scene-note:has(.instruction:empty) {
  display: none;
}
.crossing-frame:has(.board-alert:not([hidden])) .scene-note {
  display: none;
}
body:has(.modal:not([hidden]) .sheet[data-view^="result"]) .scene-rack,
body:has(.modal:not([hidden]) .sheet[data-view^="result"]) .watch-actions,
body:has(.modal:not([hidden]) .sheet[data-view^="result"]) .field-delivery {
  display: none;
}
.instruction {
  min-height: 0;
  margin: 0;
  color: inherit;
  font-size: 12px;
  line-height: 1.15;
}
@media (max-width: 600px) and (orientation: portrait) {
  .scene-note { left: max(6px, env(safe-area-inset-left)); }
}
@media (max-height: 520px) and (orientation: landscape) {
  .sheet[data-view="kit"] {
    width: min(100%, 760px);
    max-height: calc(100svh - 20px);
    padding: 10px 15px 12px;
  }
  .sheet[data-view="kit"] .sheet-top { margin-bottom: 4px; }
  .sheet[data-view="kit"] .kit-list { grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 5px; }
  .sheet[data-view="kit"] .kit-choice { min-height: 48px; padding: 3px 5px; gap: 5px; }
  .sheet[data-view="kit"] .kit-choice img { width: 35px; height: 33px; }
  .sheet[data-view="kit"] .kit-choice strong { font-size: 12px; }
  .sheet[data-view="kit"] .kit-choice small {
    display: block;
    margin-top: 1px;
    color: #eddbb1;
    font-size: 12px;
    line-height: 1.1;
  }
  .sheet[data-view="kit"] .kit-detail:not(:empty) { display: block; margin: 4px 0; font-size: 12px; line-height: 1.2; }
  .sheet[data-view="kit"] .kit-brief { margin-top: 7px; font-size: 12px; }
  .sheet[data-view="kit"] .scout { margin: 6px 0; padding: 5px; }
  .sheet[data-view="kit"] .scout h3 { font-size: 13px; }
  .sheet[data-view="kit"] .enemy-preview {
    display: flex;
    gap: 4px;
    overflow-x: auto;
    overscroll-behavior-inline: contain;
    scrollbar-width: thin;
  }
  .sheet[data-view="kit"] .scout-enemy { flex: 0 0 76px; min-height: 47px; padding: 2px; font-size: 12px; }
  .sheet[data-view="kit"] .scout-enemy img { width: 31px; height: 25px; }
  .sheet[data-view="kit"] .scout-line { margin-top: 3px; font-size: 12px; }
  .sheet[data-view="kit"] .kit-footer { padding-top: 6px; }
  .sheet[data-view="kit"] .kit-footer p { font-size: 12px; }
  .sheet[data-view="kit"] .kit-footer button { min-height: 44px; }
}

@media (min-width: 620px) and (max-height: 520px) and (orientation: landscape) {
  .sheet[data-view="kit"] .kit-content {
    display: grid;
    grid-template-columns: minmax(180px, 31%) minmax(0, 1fr);
    align-content: start;
    align-items: start;
    gap: 7px 12px;
  }
  .sheet[data-view="kit"] .kit-brief { grid-column: 1 / -1; margin: 1px 0 0; }
  .sheet[data-view="kit"] .scout { margin: 0; }
  .sheet[data-view="kit"] .enemy-preview { display: grid; grid-template-columns: repeat(auto-fit, minmax(55px, 1fr)); }
  .sheet[data-view="kit"] .scout-enemy { font-size: 11px; }
  .sheet[data-view="kit"] .kit-list { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .sheet[data-view="kit"] .kit-choice { min-height: 46px; }
}

/* One materials rack. Its neighbouring buttons have their own mounting points. */
.scene-rack {
  --packet: var(--watch-card-width);
  position: absolute;
  z-index: 2;
  top: var(--battle-tools-top);
  left: var(--battle-tools-left);
  display: flex;
  align-items: stretch;
  gap: 4px;
  max-width: calc(100% - var(--battle-tools-left) - var(--battle-tools-right));
  padding: 4px;
  border: 2px solid #4e301c;
  border-radius: 9px;
  background: linear-gradient(#7a4d2552,#38241371), url('./art/title-plank.webp') center / cover, #744924;
  box-shadow: inset 0 1px #ffdb958c, 0 2px 4px #201910aa;
}
.meter-coins {
  display: grid;
  flex: 0 0 auto;
  width: var(--packet);
  grid-template-rows: auto auto;
  align-items: center;
  justify-items: center;
  align-content: center;
  gap: 4px;
  padding: 3px 1px;
  border: 1px solid #c29a5c;
  border-radius: 5px;
  color: #ffeabb;
  background: radial-gradient(ellipse at 50% 25%,#755429,#3b2a19 75%);
}
.coin-icon {
  display: inline-block;
  flex: none;
  width: 30px;
  height: 30px;
  background: url('./art/watch-coin.webp') center / contain no-repeat;
  filter: drop-shadow(0 1px 2px #26190d);
}
.meter-coins #coin-balance { font-size: 23px; font-weight: 900; line-height: 1; font-variant-numeric: tabular-nums; }
.scene-rack .tray { display: flex; flex: 0 1 auto; gap: 3px; min-width: 0; padding: 0; margin: 0; border: 0; background: none; box-shadow: none; }
.scene-rack .tool {
  display: grid; flex: none; width: var(--packet); min-width: 0; min-height: 0; height: var(--watch-card-height);
  grid-template: minmax(0,1fr) 19px / minmax(0,1fr); justify-items: stretch; align-items: stretch;
  padding: 2px; gap: 1px; border: 1px solid #4c2c19; border-radius: 5px;
  background: radial-gradient(ellipse at 45% 29%,#fff1ba,#e6c37a 65%,#bf9147);
  box-shadow: inset 0 0 0 1px #fff0b58a; text-shadow: none;
}
.scene-rack .tool[data-terrain="water"] { background: radial-gradient(ellipse at 45% 29%,#e5f4d4,#a9c9b2 65%,#6f9d96); }
.scene-rack .tool[data-affordable="false"] { filter: saturate(.36); background: #b6a68b; }
.scene-rack .tool[aria-pressed="true"] { outline: 2px solid #ffdb58; outline-offset: -2px; box-shadow: inset 0 0 0 4px #8c671f; }
.scene-rack .tool[data-suggested]:not([aria-pressed="true"]), .command[data-suggested] { outline: 2px dashed #784717; outline-offset: -3px; }

.sheet[data-view="rotate"] {
  display: grid;
  justify-items: center;
  gap: 12px;
  width: min(100%, 390px);
  padding: 24px 16px 18px;
  text-align: center;
}
.landscape-preview {
  width: min(58%, 172px);
  aspect-ratio: 2 / 1;
  border: 4px solid #503820;
  border-radius: 13px;
  background: url('./art/gatehouse-yard.webp') center / cover;
  box-shadow: 0 0 0 1px #dfb565, 0 3px 7px #111c17;
}
.sheet[data-view="rotate"] .sheet-top,
.sheet[data-view="rotate"] p { margin: 0; }
.sheet[data-view="rotate"] h2 { font-size: clamp(24px, 7vw, 30px); line-height: 1.05; }
.sheet[data-view="rotate"] .sheet-actions { display: grid; grid-template-columns: 1fr; gap: 5px; width: min(100%, 220px); margin: 3px 0 0; }
.sheet[data-view="rotate"] .plank { --plank: 44px; min-height: 44px; font-size: 15px; }
.sheet[data-view="loading"] { display: grid; justify-items: center; gap: 7px; width: min(100%, 380px); text-align: center; }
.sheet[data-view="loading"] .sheet-top, .sheet[data-view="loading"] p { margin: 0; }
.sheet[data-view="loading"] img { width: 38px; height: 52px; object-fit: contain; }
.scene-rack .tool:focus-visible { outline: 3px solid #fff4ac; outline-offset: -3px; }
.scene-rack .tool img { width: 100%; height: 100%; min-height: 0; object-fit: contain; filter: drop-shadow(0 1px 1px #4a301772); }
.scene-rack .tool[data-damaging="true"] em { color: #5f2417; background: #ffe0a1; }
.scene-rack .tool em { color: #382315; background: #fff0bc; border-top: 1px solid #bc985f; border-radius: 0 0 2px 2px; text-align: center; font-size: 15px; line-height: 17px; font-weight: 900; }
.income-mark {
  position: absolute; top: 1px; right: 1px; display: flex; gap: 1px; align-items: center;
  padding: 0 2px; border-radius: 3px; background: #47361d; color: #fff3c0; font-size: 11px; line-height: 13px;
}
.income-mark .coin-icon { width: 10px; height: 10px; }
.watch-actions .commands {
  display: flex; flex-flow: row wrap; gap: 3px; margin: 0; padding: 0; background: none; border: 0;
}
.commands .command {
  position: relative; display: grid; place-items: center; padding: 2px; width: 44px; min-width: 44px; min-height: 44px; height: 44px;
  border: 1px solid #71522f; border-radius: 5px; background: radial-gradient(ellipse at 45% 35%,#b0a178,#5e644c 75%); box-shadow: inset 0 0 0 1px #e4d9a270,0 1px 3px #332c1b8a;
}
.commands .command img { width: 33px; height: 33px; object-fit: contain; }
.commands .command small:not(:empty) { position: absolute; bottom: 1px; padding: 0 2px; background: #342814; color: #ffeec0; border-radius: 2px; line-height: 12px; }
.commands .command[aria-pressed="true"] { outline: 2px solid #ffdb58; outline-offset: -2px; }
body.at-yard :is(.commands, .workshop),
body:has(.modal:not([hidden]) .sheet[data-view^="result"]) :is(.commands, .workshop) { display: none; }
.scene-rack:has(.workshop:not([hidden])) {
  gap: 10px;
  padding: 2px 3px;
  border: 14px solid transparent;
  border-image: url('./art/workshop-panel.webp') 65 fill / 14px stretch;
  border-radius: 0;
  background: #203627 padding-box;
  box-shadow: none;
  filter: drop-shadow(0 3px 5px #21170cb3);
}
.scene-rack:has(.workshop:not([hidden])) .meter-coins {
  border: 0;
  border-right: 1px solid #e2bd7559;
  border-radius: 0;
  background: none;
  padding-right: 6px;
}
.workshop {
  display: grid; grid-template-columns: minmax(0, 236px) auto; align-items: center;
  gap: 8px; min-width: 0; color: #fff0cd;
}
.rack-detail {
  display: flex; align-items: center; gap: 8px;
}
.workshop-rack {
  position: relative; display: grid; place-items: center; flex: none; width: 48px; height: 48px; padding: 2px;
  border: 1px solid #b3915f88; border-radius: 5px; background: #3c3524; color: #ffeab9;
}
.workshop-rack::after {
  content: ''; position: absolute; left: 4px; bottom: 5px; width: 5px; height: 5px;
  border: solid currentColor; border-width: 0 0 2px 2px; transform: rotate(45deg);
}
.rack-detail img { width: 100%; height: 100%; object-fit: contain; filter: drop-shadow(0 2px 3px #0d160f); }
.upgrade-summary { min-width: 0; }
.upgrade-stat { display: grid; grid-template-columns: auto 1fr; align-items: baseline; column-gap: 6px; font-size: 20px; font-weight: 800; line-height: 1; font-variant-numeric: tabular-nums; }
.upgrade-stat small { grid-column: 1 / -1; margin-bottom: 4px; color: #ead6ad; font-size: 11px; line-height: 1; }
.upgrade-stat-change { white-space: nowrap; color: #f4cf86; }
.upgrade-stat-change strong { color: #ffe39e; font-size: 1.1em; }
.rack-detail p { margin: 3px 0 0; color: #ead6ad; font-size: 12px; line-height: 1.25; }
.rack-detail p:empty { display: none; }
.workshop-actions { display: flex; align-items: stretch; gap: 4px; }
.workshop-actions button {
  min-width: 44px; min-height: 44px; max-width: 88px; padding: 5px 7px; border-radius: 5px; border: 1px solid #e2bd7566;
  background: #162b22a6; color: #fff2cf; font: 800 13px/1.15 var(--body),sans-serif;
}
.workshop button:focus-visible { outline: 3px solid #fff4ac; outline-offset: -3px; }
.workshop #upgrade-action {
  position: relative;
  min-width: 74px;
  border: 1px solid transparent;
  border-image: url('./art/title-plank.webp') 0 112 fill / 0 16px stretch;
  background: #ddb365 padding-box;
  color: #321d0f;
  font-weight: 900;
}
.workshop #upgrade-action::before {
  content: '';
  position: absolute;
  inset: 4px 11px;
  background: linear-gradient(90deg, transparent, #f8d58bbd 20% 80%, transparent);
  pointer-events: none;
}
.workshop #upgrade-action > * { position: relative; }
.workshop #upgrade-action:disabled { filter: saturate(.35) brightness(.82); }
.workshop #upgrade-action small { display: flex; justify-content: center; align-items: center; gap: 3px; margin-top: 2px; font-size: 12px; }
.workshop #upgrade-action .coin-icon { width: 13px; height: 13px; }
.workshop-actions:not(:has(button:not([hidden]))) { display: none; }
.workshop-actions button:disabled { opacity: .65; }
.workshop .tool-layers { grid-column: 1 / -1; }
.crossing-frame:has(.workshop:not([hidden])) .scene-note { display: none; }
@media (max-width: 600px) and (orientation: portrait) {
  body.in-play .topbar { height: 78px; }
  .crossing-frame {
    --watch-card-width: clamp(44px, 10vw, 54px);
    --watch-card-height: 68px;
  }
  .crossing-frame:has(.workshop:not([hidden])) {
    --battle-tools-top: calc(var(--controls-top) + 66px);
    --battle-tools-left: var(--controls-left);
  }
  .scene-rack { gap: 2px; padding: 3px; }
  .scene-rack .tray { gap: 2px; overflow-x: auto; scrollbar-width: thin; }
  .scene-rack .tool em { font-size: 14px; }
  .meter-coins {
    position: var(--coin-position, static);
    top: 71px;
    left: calc(-1 * (var(--control-size) + 7px));
    min-height: 46px;
    width: 43px;
    gap: 0;
  }
  .meter-coins .coin-icon { width: 24px; height: 24px; }
  .meter-coins #coin-balance { font-size: 19px; }
  .scene-rack:has(.workshop:not([hidden])) { gap: 6px; }
  .workshop { grid-template-columns: minmax(0,1fr) auto; gap: 5px; }
  .workshop-rack { width: 44px; height: 44px; }
  .workshop-actions button { flex: 1; max-width: none; }
  .rack-detail { gap: 5px; }
  .upgrade-stat { font-size: 18px; }
}
/* Make room for every card at 44px by tucking the coin counter under Options on narrow phones. */
@media (max-width: 408px) and (orientation: portrait) {
  .scene-rack:has(.tray:not([hidden]) .tool:nth-child(6)) { --coin-position: absolute; }
}
@media (max-width: 355px) and (orientation: portrait) {
  .scene-rack:has(.tray:not([hidden]) .tool:nth-child(5)) { --coin-position: absolute; }
}
@media (orientation: landscape) and (max-height: 520px) and (any-pointer: coarse) {
  .crossing-frame {
    --watch-card-width: clamp(46px, 7.4vw, 60px);
    --watch-card-height: 66px;
  }
  .scene-rack {
    --rack-side: max(var(--battle-tools-left), var(--battle-tools-right));
    z-index: 3;
    left: var(--rack-side);
    right: var(--rack-side);
    width: max-content;
    max-width: calc(100% - 2 * var(--rack-side));
    margin-inline: auto;
    translate: var(--rack-x, 0px) var(--rack-y, 0px);
    padding: 3px;
  }
  .scene-rack .tray { overflow-x: auto; }
  .scene-rack .workshop { grid-template-columns: minmax(0, 270px) auto; }
  .meter-coins {
    position: relative;
    width: 44px;
    min-height: 44px;
    cursor: grab;
    touch-action: none;
    user-select: none;
  }
  .meter-coins:active { cursor: grabbing; }
  .meter-coins::before {
    content: '';
    position: absolute;
    top: 5px;
    left: 5px;
    width: 2px;
    height: 2px;
    border-radius: 50%;
    background: #e3bb7a;
    box-shadow: 4px 0 #e3bb7a, 0 4px #e3bb7a, 4px 4px #e3bb7a, 0 8px #e3bb7a, 4px 8px #e3bb7a;
  }
  .meter-coins .coin-icon { width: 23px; height: 23px; }
  .meter-coins #coin-balance { font-size: 19px; }
}
@media (orientation: landscape) and (max-height: 520px) {
  .sheet[data-view="options"] { display: grid; grid-template-columns: 1fr 1fr; column-gap: 24px; padding: 14px 22px; }
  .sheet[data-view="options"] :is(.sheet-top, .sheet-actions) { grid-column: 1 / -1; }
}
