/*
 * Barn Bloom - style.css
 * The palette is defined once here as CSS variables (the canvas palette
 * lives in js/config.js). All sizes are in rem so the "Interface size"
 * setting can scale the whole UI through the root font size.
 */
:root {
  --cream: #fff3d6;
  --cream-2: #f6e4bd;
  --paper: #fffaf0;
  --ink: #3a2a22;
  --ink-soft: #6b5544;
  --wood: #7b4f36;
  --wood-dark: #4e3224;
  --wood-light: #b9835a;
  --leaf: #5fae5a;
  --leaf-dark: #3f8f4f;
  --gold: #ffd24a;
  --gold-dark: #b9801a;
  --water: #58b7ea;
  --water-dark: #2f86c4;
  --red: #e8686b;
  --red-dark: #b94548;
  --pink: #f28fb0;
  --violet: #8f8be8;
  --shadow: 0 0.25rem 0 rgba(58, 42, 34, 0.3);
  --radius: 0.9rem;
  --side-w: 0rem;
  --on-wood: #fff3d6;     /* text on wood or on the dark fight screen: the same in light and dark mode */
  --font: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  overflow: hidden;
  background: #2a1a12;
  color: var(--ink);
  font-family: var(--font);
  font-size: 1rem;
  line-height: 1.35;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
  -webkit-user-select: none;
}
h1, h2, h3, h4, p, ul, dl, figure { margin: 0; }
ul { padding: 0; list-style: none; }
[hidden] { display: none !important; }
button { font: inherit; color: inherit; }
kbd {
  font: 700 0.68rem var(--font);
  background: rgba(58, 42, 34, 0.14);
  border-radius: 0.3rem;
  padding: 0.05rem 0.32rem;
}
:focus-visible { outline: 0.19rem solid var(--water-dark); outline-offset: 0.12rem; }
.grow { flex: 1 1 auto; min-width: 0; }
.hint { color: var(--ink-soft); font-size: 0.85rem; }
.num { font-variant-numeric: tabular-nums; font-weight: 800; }
.num.small { font-size: 0.82rem; }

#scene {
  position: fixed; inset: 0;
  width: 100vw; height: 100vh; height: 100dvh;
  display: block;
  touch-action: none;
}

/* ---------- icons ---------- */
.ic { display: inline-flex; width: 1.25rem; height: 1.25rem; flex: none; vertical-align: middle; }
.ic svg { width: 100%; height: 100%; display: block; }
.ic.big { width: 2.6rem; height: 2.6rem; }
canvas.pic { flex: none; display: block; }
.price { display: inline-flex; align-items: center; gap: 0.2rem; font-weight: 800; white-space: nowrap; }
.price .ic { width: 1rem; height: 1rem; }

/* ---------- buttons ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 0.4rem;
  min-height: 2.5rem; padding: 0.4rem 0.9rem;
  background: var(--cream-2);
  border: 0.12rem solid rgba(58, 42, 34, 0.25);
  border-bottom-width: 0.3rem;
  border-radius: 0.8rem;
  font-weight: 800; cursor: pointer;
  transition: transform 0.08s, filter 0.15s, background 0.15s;
}
.btn:hover { filter: brightness(1.06); }
.btn:active { transform: translateY(0.12rem); border-bottom-width: 0.18rem; }
.btn:disabled { opacity: 0.5; cursor: not-allowed; filter: grayscale(0.5); transform: none; }
.btn.primary { background: var(--leaf); border-color: var(--leaf-dark); color: #fff; }
.btn.danger { background: var(--red); border-color: var(--red-dark); color: #fff; }
.btn.ghost { background: transparent; border-color: transparent; color: var(--ink-soft); }
.btn.small { min-height: 2rem; padding: 0.2rem 0.6rem; font-size: 0.85rem; }
.btn.big { min-height: 3rem; font-size: 1.05rem; width: 100%; }
.btn.icon-btn { min-height: 2rem; width: 2rem; padding: 0; border-radius: 50%; border-bottom-width: 0.12rem; }
.btn.icon-btn .ic { width: 1rem; height: 1rem; }
.btn.buy { min-width: 7.5rem; }
.chip-btn {
  min-height: 2.2rem; padding: 0.2rem 0.8rem;
  background: var(--cream-2); border: 0.12rem solid rgba(58, 42, 34, 0.2); border-radius: 999px;
  font-weight: 800; cursor: pointer;
}
.chip-btn.active { background: var(--wood); color: var(--on-wood); border-color: var(--wood-dark); }

/* ---------- HUD ---------- */
.hud {
  position: fixed; top: 0; left: 0; right: 0; z-index: 10;
  display: flex; flex-wrap: wrap; justify-content: space-between; align-items: flex-start; gap: 0.4rem;
  padding: 0.5rem; padding-top: max(0.5rem, env(safe-area-inset-top));
  pointer-events: none;
}
.hud > * { pointer-events: auto; }
.hud-group { display: flex; flex-wrap: wrap; gap: 0.35rem; align-items: center; }
.pill {
  display: inline-flex; align-items: center; gap: 0.35rem;
  min-height: 2.2rem; padding: 0.2rem 0.7rem;
  background: var(--cream); border: 0.12rem solid rgba(58, 42, 34, 0.3); border-radius: 999px;
  box-shadow: var(--shadow); font-weight: 800;
}
.pill.speed { border-bottom-width: 0.12rem; min-height: 2.2rem; cursor: pointer; }
.pill.tank.low { animation: pulse 0.9s infinite; border-color: var(--red); }
.tankbar { width: 3.2rem; height: 0.55rem; background: rgba(58, 42, 34, 0.2); border-radius: 999px; overflow: hidden; }
.tankbar i { display: block; height: 100%; background: var(--water); border-radius: 999px; transition: width 0.2s; }
.day-ic { display: inline-flex; }
.hud-btn { box-shadow: var(--shadow); background: var(--cream); min-height: 2.4rem; padding: 0.3rem 0.65rem; }
.hud-btn kbd { opacity: 0.75; }
/* Event chips hang below the HUD without changing its height (so the scene never jumps). */
.chips { position: absolute; top: 100%; left: 0.5rem; right: 0.5rem; display: flex; flex-wrap: wrap; gap: 0.35rem; pointer-events: none; }
.chips > * { pointer-events: auto; }
.chip {
  display: inline-flex; align-items: center; gap: 0.3rem;
  padding: 0.15rem 0.6rem; border-radius: 999px; font-weight: 800; font-size: 0.85rem;
  background: #3a2a22; color: var(--on-wood); border: 0.12rem solid rgba(255, 243, 214, 0.35);
  animation: pop-in 0.3s;
}
button.chip { cursor: pointer; font: 800 0.85rem var(--font); }
.chip.heat { background: #b9502a; }
.chip.rain { background: #3f6f95; }
.chip.bee { background: #a67a12; }
.chip.merchant { background: #7a4a9a; }
.chip.pest { background: #5a2a7a; }
.chip.rare { background: #8a6418; border-color: var(--gold); }

/* The barn sign hangs in the top right corner, above the side panel and just as wide.
   ui.js adds .with-sign to the HUD only when both rows of buttons fit beside it. */
.hud.with-sign { display: grid; grid-template-columns: minmax(0, 1fr) 18.5rem; column-gap: 0.5rem; }
.hud.with-sign > .hud-group { grid-column: 1; }
.barn-sign {
  display: none; position: relative; flex-direction: column; justify-content: center; gap: 0.2rem;
  padding: 0.3rem 0.75rem 0.35rem; text-align: left; cursor: pointer; color: var(--on-wood);
  background:
    repeating-linear-gradient(177deg, rgba(255, 255, 255, 0.07) 0 0.1rem, transparent 0.1rem 0.8rem),
    linear-gradient(180deg, #9c6b46, var(--wood));
  border: 0.15rem solid var(--wood-dark); border-radius: 0.7rem; box-shadow: var(--shadow);
  transform-origin: 50% -0.5rem; transition: transform 0.35s ease;
}
.hud.with-sign .barn-sign { display: flex; grid-column: 2; grid-row: 1 / span 2; align-self: stretch; }
.barn-sign:hover { transform: rotate(-1.2deg); }
/* Two ropes up to the rafters... */
.barn-sign::before {
  content: ""; position: absolute; left: 1.2rem; right: 1.2rem; top: -0.65rem; height: 0.95rem; pointer-events: none;
  background:
    linear-gradient(#d8b67a, #d8b67a) left top / 0.16rem 100% no-repeat,
    linear-gradient(#d8b67a, #d8b67a) right top / 0.16rem 100% no-repeat;
}
/* ...and the two nails that hold them. */
.barn-sign::after {
  content: ""; position: absolute; left: 1.055rem; right: 1.055rem; top: 0.1rem; height: 0.45rem; pointer-events: none;
  background:
    radial-gradient(circle, #f1e2c0 0 30%, var(--wood-dark) 34% 55%, transparent 60%) left center / 0.45rem 0.45rem no-repeat,
    radial-gradient(circle, #f1e2c0 0 30%, var(--wood-dark) 34% 55%, transparent 60%) right center / 0.45rem 0.45rem no-repeat;
}
.sign-name {
  display: block; padding: 0 1rem; text-align: center; font-size: 0.95rem; font-weight: 900; letter-spacing: 0.02em; line-height: 1.2;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis; text-shadow: 0 0.1rem 0 var(--wood-dark);
}
.sign-row { display: flex; align-items: center; justify-content: space-between; gap: 0.5rem; font-size: 0.78rem; font-weight: 800; }
.sign-season, .sign-income { display: inline-flex; align-items: center; gap: 0.25rem; white-space: nowrap; }
.sign-leaves { display: inline-flex; }
.sign-leaves .ic { width: 0.85rem; height: 0.85rem; margin-right: -0.15rem; }
.sign-income .ic { width: 0.9rem; height: 0.9rem; }
.sign-bar {
  position: relative; display: block; height: 1rem; border-radius: 999px; overflow: hidden;
  background: #f6e4bd; box-shadow: inset 0 0.1rem 0 rgba(58, 42, 34, 0.25);
}
.sign-bar i { position: absolute; left: 0; top: 0; bottom: 0; width: 0; background: var(--leaf); transition: width 0.3s; }
.sign-goal {
  position: relative; display: block; padding: 0 0.4rem; text-align: center; font-size: 0.7rem; font-weight: 800; line-height: 1rem;
  color: #3a2a22; white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.barn-sign.ready { border-color: var(--gold-dark); animation: sign-glow 1.6s ease-in-out infinite; }
.barn-sign.ready .sign-bar i { background: var(--gold); }
@keyframes sign-glow {
  0%, 100% { box-shadow: var(--shadow), 0 0 0 0 rgba(255, 210, 74, 0.8); }
  50% { box-shadow: var(--shadow), 0 0 0 0.45rem rgba(255, 210, 74, 0); }
}

/* ---------- toolbar ---------- */
.toolbar {
  position: fixed; z-index: 10;
  bottom: max(0.5rem, env(safe-area-inset-bottom));
  left: calc((100vw - var(--side-w)) / 2); transform: translateX(-50%);
  max-width: calc(100vw - var(--side-w) - 1rem);
  display: flex; align-items: center; gap: 0.35rem;
  padding: 0.45rem;
  background: rgba(78, 50, 36, 0.92); border: 0.12rem solid rgba(255, 243, 214, 0.25); border-radius: 1.2rem;
  box-shadow: 0 0.4rem 1.2rem rgba(0, 0, 0, 0.35);
  overflow-x: auto; scrollbar-width: none;
}
.toolbar::-webkit-scrollbar { display: none; }
.toolbar .sep { width: 0.12rem; height: 2.2rem; background: rgba(255, 243, 214, 0.25); flex: none; }
.tool {
  position: relative; flex: none;
  width: 3.5rem; height: 3.5rem; padding: 0;
  display: grid; place-items: center;
  background: var(--cream); border: 0.12rem solid rgba(58, 42, 34, 0.3); border-bottom-width: 0.3rem; border-radius: 0.9rem;
  cursor: pointer; transition: transform 0.1s, background 0.15s, box-shadow 0.15s;
}
.tool:hover { background: #fffbee; }
.tool:active { transform: translateY(0.12rem); }
.tool.active { background: var(--gold); border-color: var(--gold-dark); transform: translateY(-0.3rem); box-shadow: 0 0.3rem 0 rgba(0, 0, 0, 0.25); }
.tool.active::after {
  content: ""; position: absolute; bottom: -0.75rem; left: 50%; width: 0.5rem; height: 0.5rem;
  margin-left: -0.25rem; border-radius: 50%; background: var(--on-wood);
}
.tool.action { background: #d9f0ff; }
.tool.action.ready { background: #ffe9a0; animation: pulse 1.2s infinite; }
.tool:disabled { opacity: 0.45; cursor: not-allowed; }
.tool .tool-ic { width: 2rem; height: 2rem; color: var(--ink); }
.tool .tool-pic { display: grid; place-items: center; }
.tool kbd { position: absolute; top: 0.12rem; left: 0.2rem; font-size: 0.6rem; }
.tool .count {
  position: absolute; right: -0.25rem; bottom: -0.3rem;
  min-width: 1.3rem; padding: 0 0.25rem; text-align: center;
  background: #3a2a22; color: var(--on-wood); border-radius: 999px; font: 800 0.72rem var(--font);
}
.tool .count.zero { background: var(--red-dark); }
.tool .caret { position: absolute; right: 0.2rem; top: 0; font-size: 0.75rem; color: var(--ink-soft); }
.tool.mini { width: 2.9rem; height: 2.9rem; }
.tut-glow { animation: glow 1s infinite; }

.popover {
  position: fixed; z-index: 15; width: 16rem; max-width: calc(100vw - 1rem); max-height: 60vh; overflow-y: auto;
  padding: 0.6rem; background: var(--cream); border: 0.12rem solid rgba(58, 42, 34, 0.35); border-radius: var(--radius);
  box-shadow: 0 0.5rem 1.5rem rgba(0, 0, 0, 0.4); animation: pop-in 0.15s;
}
.popover h3 { font-size: 0.95rem; margin-bottom: 0.4rem; }
.pop-item {
  display: flex; align-items: center; gap: 0.5rem; width: 100%; min-height: 2.75rem; padding: 0.2rem 0.5rem; margin-bottom: 0.25rem;
  background: var(--paper); border: 0.12rem solid rgba(58, 42, 34, 0.15); border-radius: 0.7rem;
  font-weight: 700; text-align: left; cursor: pointer;
}
.pop-item:hover, .pop-item.active { background: #ffeab0; border-color: var(--gold-dark); }
.pop-count { font-weight: 800; color: var(--ink-soft); display: inline-flex; align-items: center; gap: 0.25rem; white-space: nowrap; }

/* ---------- side panel ---------- */
.side {
  position: fixed; z-index: 10; right: 0.5rem; top: calc(var(--hud-h, 4rem) + 0.3rem); bottom: 0.5rem; width: 18.5rem;
  display: flex; flex-direction: column; gap: 0.5rem;
  overflow-y: auto; scrollbar-width: thin; pointer-events: none;
}
.side > * { pointer-events: auto; }
.card {
  background: rgba(255, 243, 214, 0.96); border: 0.12rem solid rgba(58, 42, 34, 0.3); border-radius: var(--radius);
  padding: 0.75rem; box-shadow: var(--shadow);
}
.card h3 { font-size: 1.05rem; display: flex; align-items: center; gap: 0.35rem; flex-wrap: wrap; }
.info > * + * { margin-top: 0.5rem; }
.info-head { display: flex; align-items: center; gap: 0.5rem; }
.sub { color: var(--ink-soft); font-size: 0.85rem; font-weight: 700; }
.stars { color: var(--gold-dark); font-size: 0.9rem; letter-spacing: 0.05em; }
.stats { display: grid; gap: 0.3rem; }
.stat { display: grid; grid-template-columns: 3.6rem 1fr 4.2rem; align-items: center; gap: 0.4rem; font-size: 0.82rem; font-weight: 700; }
.stat.warn .bar-text { color: var(--red-dark); }
.bar-text { text-align: right; font-variant-numeric: tabular-nums; }
.bar {
  position: relative; display: block; height: 0.75rem; background: rgba(58, 42, 34, 0.22); border-radius: 999px; overflow: hidden;
}
.bar i { display: block; height: 100%; width: 0; border-radius: 999px; transition: width 0.2s; position: relative; }
.bar.water i { background: var(--water); }
.bar.health i { background: var(--red); }
.bar.growth i { background: var(--leaf); }
.bar.quality i { background: var(--gold); }
.bar .zone {
  position: absolute; top: 0; bottom: 0; z-index: 1; display: none;
  border-left: 0.14rem solid #fff; border-right: 0.14rem solid #fff; background: rgba(255, 255, 255, 0.28);
}
.bar.water .zone { display: block; }
.bar.mini { height: 0.5rem; }
dd .bar.mini { width: 8rem; display: inline-block; vertical-align: middle; }
.nutbars { display: grid; grid-template-columns: 1fr 1fr; gap: 0.25rem 0.6rem; }
.nutbar { display: flex; align-items: center; gap: 0.3rem; }
.nutbar .bar { flex: 1; height: 0.5rem; }
.nutbar.loved .bar { outline: 0.1rem dashed var(--gold-dark); outline-offset: 0.08rem; }
.synergy { font-size: 0.82rem; font-weight: 800; color: var(--leaf-dark); }
.facts { display: grid; gap: 0.2rem; font-size: 0.85rem; }
.facts li { display: flex; gap: 0.4rem; align-items: flex-start; }
.facts .ic { width: 1.05rem; height: 1.05rem; margin-top: 0.1rem; }
.actions { display: flex; gap: 0.4rem; flex-wrap: wrap; }
.feed-row { display: flex; gap: 0.5rem; flex-wrap: wrap; padding-bottom: 0.2rem; }
.seed-list { display: grid; }

.order {
  display: flex; align-items: center; gap: 0.5rem; padding: 0.45rem; margin-top: 0.4rem;
  background: #3f5546; color: #f4f8ee; border: 0.2rem solid var(--wood-light); border-radius: 0.7rem; font-size: 0.85rem;
}
.order strong, .order span { display: block; }
.order .price { display: inline-flex; }
.order-reward { display: block; }
.order .icon-btn { color: #f4f8ee; align-self: flex-start; }
.order.waiting { justify-content: center; gap: 0.35rem; min-height: 3rem; opacity: 0.9; }
.order.waiting span { display: inline; }
.pips { display: flex !important; gap: 0.2rem; margin: 0.2rem 0; }
.pips i { width: 0.7rem; height: 0.7rem; border-radius: 50%; border: 0.12rem solid #f4f8ee; }
.pips i.on { background: var(--gold); border-color: var(--gold); }
.orders-modal .order { font-size: 0.95rem; }

/* ---------- dialogs ---------- */
.overlay {
  position: fixed; inset: 0; z-index: 50; display: grid; place-items: center; padding: 0.5rem;
  background: rgba(30, 16, 10, 0.55); animation: fade-in 0.18s;
}
.modal {
  display: flex; flex-direction: column;
  width: min(34rem, 100%); max-height: min(92vh, 92dvh);
  background: var(--cream); border: 0.2rem solid var(--wood-dark); border-radius: 1.2rem; overflow: hidden;
  box-shadow: 0 1rem 3rem rgba(0, 0, 0, 0.5); animation: rise 0.22s cubic-bezier(0.2, 1.3, 0.5, 1);
  outline: none;
}
.modal.wide { width: min(54rem, 100%); }
.modal.narrow { width: min(24rem, 100%); }
.modal-head {
  display: flex; align-items: center; gap: 0.5rem; padding: 0.6rem 0.8rem;
  background: var(--wood); color: var(--on-wood);
  background-image: repeating-linear-gradient(90deg, rgba(0, 0, 0, 0.07) 0 0.12rem, transparent 0.12rem 3.2rem);
}
.modal-head h2 { flex: 1; font-size: 1.25rem; }
.modal-head .ic { width: 1.5rem; height: 1.5rem; }
.modal-head .close { background: var(--cream); color: var(--ink); }
.modal-head .close .ic { width: 1rem; height: 1rem; }
.modal-body { padding: 0.9rem; overflow-y: auto; flex: 1 1 auto; }
.modal-body > * + * { margin-top: 0.7rem; }
.modal-foot { display: flex; justify-content: flex-end; flex-wrap: wrap; gap: 0.5rem; padding: 0.7rem 0.9rem; background: var(--cream-2); }
.shop { display: flex; flex-direction: column; padding-top: 0.7rem; overflow: hidden; }
.shop.modal-body > * + * { margin-top: 0.6rem; }
.items { overflow-y: auto; display: grid; gap: 0.5rem; padding: 0.15rem 0.15rem 0.4rem; flex: 1 1 auto; min-height: 6rem; }
.tabs { display: flex; gap: 0.3rem; flex-wrap: wrap; flex: none; }
.tab {
  display: inline-flex; align-items: center; gap: 0.35rem; min-height: 2.5rem; padding: 0.3rem 0.9rem;
  background: var(--cream-2); border: 0.12rem solid rgba(58, 42, 34, 0.2); border-radius: 0.8rem 0.8rem 0.3rem 0.3rem;
  font-weight: 800; cursor: pointer;
}
.tab.active { background: var(--wood); color: var(--on-wood); border-color: var(--wood-dark); }
.badge { background: var(--red); color: #fff; border-radius: 999px; padding: 0 0.4rem; font-size: 0.75rem; }
.tab .badge { background: rgba(58, 42, 34, 0.25); color: inherit; }
.qty-row, .restock { display: flex; align-items: center; gap: 0.4rem; flex-wrap: wrap; flex: none; font-weight: 700; }
.restock { justify-content: space-between; }
.item, .entry {
  display: flex; align-items: center; gap: 0.7rem; padding: 0.6rem 0.7rem;
  background: var(--paper); border: 0.12rem solid rgba(58, 42, 34, 0.16); border-radius: var(--radius);
}
.item h4, .entry h4 { font-size: 1.02rem; display: flex; align-items: center; gap: 0.4rem; flex-wrap: wrap; }
.item p, .entry p { font-size: 0.88rem; }
.meta { color: var(--ink-soft); font-size: 0.8rem !important; margin-top: 0.15rem; }
.item-side { display: flex; flex-direction: column; align-items: flex-end; gap: 0.25rem; flex: none; text-align: right; }
.owned { font-size: 0.8rem; font-weight: 700; color: var(--ink-soft); }
.need { font-size: 0.78rem; font-weight: 700; color: var(--leaf-dark); min-height: 1em; }
.need.bad { color: var(--red-dark); }
.item.locked { background: #efe3c8; }
.item.muted { opacity: 0.75; }
.item.merchant { background: #f3e6ff; border-color: #7a4a9a; }
.item.rare { background: #fff6d6; border-color: var(--gold-dark); }
.item.rare h4 .ic { color: var(--gold-dark); }
.item.done { background: #eef7dc; }
.item.shine { animation: shine 0.9s; }
.section { font-size: 0.95rem; margin-top: 0.3rem; }
.paints { display: grid; grid-template-columns: repeat(auto-fill, minmax(8.5rem, 1fr)); gap: 0.5rem; }
.paint {
  display: grid; justify-items: center; gap: 0.3rem; padding: 0.5rem; text-align: center; font-size: 0.85rem;
  background: var(--paper); border: 0.12rem solid rgba(58, 42, 34, 0.16); border-radius: var(--radius);
}
.paint.active { border-color: var(--leaf-dark); background: #eef7dc; }
.lvl-pips { display: inline-flex; gap: 0.18rem; font-size: 0.8rem; color: var(--ink-soft); }
.lvl-pips i { width: 0.6rem; height: 0.6rem; border-radius: 0.15rem; background: rgba(58, 42, 34, 0.2); transform: rotate(45deg); }
.lvl-pips i.on { background: var(--leaf); }
.effect { font-weight: 800; color: var(--ink); margin-top: 0.2rem; }
.effect .next { color: var(--leaf-dark); }
.maxed { font-weight: 900; color: var(--gold-dark); padding: 0 0.5rem; }
.locked-note { display: flex; align-items: center; gap: 0.3rem; max-width: 11rem; font-size: 0.82rem; font-weight: 700; color: var(--ink-soft); text-align: right; }
.entry { align-items: flex-start; }
.entry.unknown { opacity: 0.8; align-items: center; }
.entry em { font-size: 0.8rem; font-weight: 400; color: var(--ink-soft); }
.entry dl { display: grid; grid-template-columns: 6.5rem 1fr; gap: 0.15rem 0.5rem; margin-top: 0.4rem; font-size: 0.85rem; }
.entry dt { font-weight: 800; color: var(--ink-soft); }
.entry dd { margin: 0; }
.stages { display: flex; gap: 0.4rem; margin-top: 0.4rem; flex-wrap: wrap; }
.stages figure { display: grid; justify-items: center; background: var(--cream-2); border-radius: 0.6rem; padding: 0.2rem 0.4rem; }
.stages figcaption { font-size: 0.7rem; font-weight: 700; color: var(--ink-soft); }
.ach .ic.big { width: 2.2rem; height: 2.2rem; color: var(--ink-soft); }
.ach .bar { margin-top: 0.3rem; max-width: 16rem; }

.settings h3 { font-size: 0.95rem; color: var(--wood); border-bottom: 0.12rem solid rgba(58, 42, 34, 0.15); padding-bottom: 0.2rem; }
.set-row { display: flex; align-items: center; gap: 0.7rem; min-height: 2.6rem; cursor: pointer; }
.set-row.wrap { flex-wrap: wrap; padding: 0.2rem 0; }
.confirm-skip { display: flex; align-items: center; gap: 0.5rem; margin-top: 0.7rem; font-size: 0.9rem; cursor: pointer; }
.confirm-skip input { width: 1.1rem; height: 1.1rem; accent-color: var(--leaf-dark); flex: none; }
.set-row small { display: block; color: var(--ink-soft); font-size: 0.8rem; font-weight: 400; }
.set-row output { width: 3rem; text-align: right; font-weight: 800; font-variant-numeric: tabular-nums; }
.set-row input[type="range"] { width: 9rem; accent-color: var(--leaf-dark); }
.set-row input[type="checkbox"] { position: absolute; opacity: 0; width: 1px; height: 1px; }
.switch { position: relative; flex: none; width: 3rem; height: 1.7rem; border-radius: 999px; background: rgba(58, 42, 34, 0.3); transition: background 0.15s; }
.switch::after {
  content: ""; position: absolute; top: 0.2rem; left: 0.2rem; width: 1.3rem; height: 1.3rem; border-radius: 50%;
  background: #fff; transition: transform 0.15s; box-shadow: 0 0.1rem 0.2rem rgba(0, 0, 0, 0.3);
}
input:checked + .switch { background: var(--leaf); }
input:checked + .switch::after { transform: translateX(1.3rem); }
input:focus-visible + .switch { outline: 0.19rem solid var(--water-dark); outline-offset: 0.12rem; }
.season-card { flex: none; background: #fff7dc; border-color: var(--gold-dark); align-items: flex-start; }
.season-card .bar { margin: 0.4rem 0 0.2rem; }
.season-card .ic.big { width: 3rem; height: 3rem; }
.gift-rows { display: grid; gap: 0.35rem; }
.gift-row {
  display: flex; align-items: center; gap: 0.6rem; min-height: 3rem; padding: 0.25rem 0.6rem; cursor: pointer;
  background: var(--paper); border: 0.12rem solid rgba(58, 42, 34, 0.16); border-radius: 0.7rem;
}
.gift-row small { display: block; color: var(--ink-soft); font-size: 0.8rem; }
.gift-row .ic.big { width: 2.2rem; height: 2.2rem; }
.text-input.qty { width: 5.5rem; text-align: right; }
.settings h4 { font-size: 0.9rem; margin-top: 0.3rem; }
.trade-result > * + *, .trade-open .grow > * + * { margin-top: 0.4rem; }
.trade-open { align-items: flex-start; }
.segmented { display: flex; gap: 0.25rem; }
.text-input {
  width: 12rem; max-width: 55%; min-height: 2.2rem; padding: 0.2rem 0.6rem; font: 700 1rem var(--font); color: var(--ink);
  background: var(--paper); border: 0.12rem solid rgba(58, 42, 34, 0.3); border-radius: 0.6rem;
  user-select: text; -webkit-user-select: text;
}
.code {
  width: 100%; resize: vertical; padding: 0.5rem; font: 0.75rem ui-monospace, Menlo, Consolas, monospace;
  background: var(--paper); border: 0.12rem solid rgba(58, 42, 34, 0.3); border-radius: 0.6rem; color: var(--ink);
  user-select: text; -webkit-user-select: text; word-break: break-all;
}
.prose h3 { font-size: 1rem; color: var(--wood); }
.prose p { font-size: 0.93rem; }
.prose.center { text-align: center; }
.keys-table, .summary { width: 100%; border-collapse: collapse; font-size: 0.9rem; }
.keys-table td, .summary td { padding: 0.25rem 0.4rem; border-bottom: 0.08rem solid rgba(58, 42, 34, 0.12); }
.summary td:last-child { text-align: right; font-weight: 800; }
.keys { display: inline-flex; gap: 0.2rem; white-space: nowrap; }
.keys kbd { font-size: 0.8rem; padding: 0.1rem 0.4rem; }
.menu-list { display: grid; gap: 0.5rem; }

/* ---------- main menu ---------- */
.menu { position: fixed; inset: 0; z-index: 30; display: grid; place-items: center; padding: 1rem; overflow-y: auto; }
.menu-card { width: min(22rem, 100%); display: grid; gap: 0.9rem; text-align: center; animation: rise 0.5s cubic-bezier(0.2, 1.3, 0.5, 1); }
.title {
  display: flex; align-items: center; justify-content: center; gap: 0.3rem; flex-wrap: wrap;
  font-size: clamp(2.8rem, 12vw, 4.6rem); font-weight: 900; line-height: 1; letter-spacing: -0.02em;
  text-shadow: 0 0.06em 0 var(--wood-dark), 0 0.12em 0 rgba(0, 0, 0, 0.35), 0 0.3em 0.6em rgba(0, 0, 0, 0.5);
}
.title .t1 { color: var(--on-wood); }
.title .t2 { color: var(--gold); }
.title-leaf { width: 0.75em; height: 0.75em; animation: sway 3s ease-in-out infinite; transform-origin: 20% 90%; filter: drop-shadow(0 0.08em 0 rgba(0, 0, 0, 0.35)); }
.tagline { color: var(--on-wood); font-weight: 700; text-shadow: 0 0.1rem 0.3rem rgba(0, 0, 0, 0.7); }
.version { color: rgba(255, 243, 214, 0.7); font-size: 0.8rem; }

/* ---------- toasts, tooltip, tutorial, misc ---------- */
.toasts {
  position: fixed; z-index: 80; top: calc(var(--hud-h, 4rem) + 2.2rem); left: calc((100vw - var(--side-w)) / 2); transform: translateX(-50%);
  width: min(26rem, calc(100vw - 1rem)); display: grid; gap: 0.4rem; pointer-events: none;
}
.toast {
  pointer-events: auto; display: flex; align-items: center; gap: 0.6rem; padding: 0.55rem 0.8rem;
  background: var(--cream); border: 0.12rem solid rgba(58, 42, 34, 0.35); border-left: 0.5rem solid var(--wood-light);
  border-radius: 0.8rem; box-shadow: 0 0.4rem 1rem rgba(0, 0, 0, 0.35); font-size: 0.9rem;
  animation: toast-in 0.3s cubic-bezier(0.2, 1.3, 0.5, 1); cursor: pointer;
}
.toast.out { opacity: 0; transform: translateY(-0.5rem); transition: opacity 0.25s, transform 0.25s; }
.toast-body { flex: 1; }
.toast-body strong { display: block; }
.toast .toast-ic { width: 1.7rem; height: 1.7rem; }
.toast.good { border-left-color: var(--leaf); }
.toast.bad { border-left-color: var(--red); }
.toast.event { border-left-color: var(--violet); }
.toast.gold { border-left-color: var(--gold); background: #fff8dc; }
.tooltip {
  position: fixed; z-index: 100; max-width: 17rem; padding: 0.35rem 0.6rem; pointer-events: none;
  background: var(--ink); color: var(--cream); border-radius: 0.5rem; font-size: 0.8rem; font-weight: 600;
  box-shadow: 0 0.3rem 0.8rem rgba(0, 0, 0, 0.4);
}
/* The tutorial card lives at the top of the side panel, so it never covers the pots. */
.tut-card {
  background: #fffbe9; border: 0.16rem solid var(--leaf-dark); border-radius: var(--radius);
  padding: 0.6rem 0.8rem; box-shadow: 0 0.4rem 1.2rem rgba(0, 0, 0, 0.4); display: grid; gap: 0.3rem; animation: rise 0.3s;
}
.tut-step { font-size: 0.72rem; font-weight: 800; color: var(--leaf-dark); text-transform: uppercase; letter-spacing: 0.06em; }
.tut-card .actions { justify-content: flex-end; }
/* Admin panel (only on the owner's computer, opened with the ` key). */
.debug {
  position: fixed; z-index: 90; left: 0.5rem; top: calc(var(--hud-h, 4rem) + 0.3rem); width: 22rem; max-width: calc(100vw - 1rem);
  max-height: calc(100vh - var(--hud-h, 4rem) - 1rem); overflow-y: auto;
  padding: 0.6rem 0.7rem; background: rgba(20, 20, 30, 0.94); color: #dfe; border-radius: 0.8rem; font-size: 0.8rem;
  box-shadow: 0 0.4rem 1.2rem rgba(0, 0, 0, 0.45);
}
.mode-fight .debug { top: 7.5rem; }
.admin-head { display: flex; align-items: center; gap: 0.4rem; }
.debug h3 { font-size: 1rem; }
.debug h4 { font-size: 0.75rem; text-transform: uppercase; letter-spacing: 0.06em; color: #9fd9b0; margin: 0.6rem 0 0.25rem; }
.admin-note { color: rgba(221, 238, 255, 0.65); font-size: 0.75rem; }
.admin-row { display: flex; flex-wrap: wrap; align-items: center; gap: 0.3rem; }
.debug .text-input { min-height: 2rem; font-size: 0.85rem; max-width: none; }
.debug .admin-sel { width: 100%; }
.debug .admin-num { width: 8rem; text-align: right; }
.admin-check { display: flex; align-items: center; gap: 0.4rem; width: 100%; cursor: pointer; padding: 0.15rem 0; }
.admin-check input { width: 1.1rem; height: 1.1rem; accent-color: var(--leaf); flex: none; }
.debug .btn.ghost { color: #dfe; }
.fps { position: fixed; z-index: 90; left: 0.4rem; bottom: 0.3rem; font: 700 0.7rem ui-monospace, monospace; color: #cfc; background: rgba(0, 0, 0, 0.5); padding: 0.1rem 0.35rem; border-radius: 0.3rem; pointer-events: none; }
.photo-hint {
  position: fixed; z-index: 95; bottom: 1rem; left: 50%; transform: translateX(-50%); pointer-events: none;
  background: rgba(0, 0, 0, 0.6); color: #fff; padding: 0.3rem 0.8rem; border-radius: 999px; font-size: 0.85rem;
}

/* ---------- modes ---------- */
.mode-menu .hud, .mode-menu .side, .mode-menu .toolbar, .mode-menu .tutorial, .mode-menu .popover, .mode-menu .debug { display: none; }
.mode-play .menu { display: none; }
.mode-visit .hud, .mode-visit .side, .mode-visit .toolbar, .mode-visit .menu, .mode-visit .popover, .mode-visit .debug { display: none; }

/* ---------- boss fights ---------- */
.mode-fight .hud, .mode-fight .side, .mode-fight .toolbar, .mode-fight .menu, .mode-fight .popover,
.mode-fight .visit-bar { display: none; }
.mode-fight #scene { cursor: crosshair; }
.fight-hud {
  position: fixed; z-index: 10; top: max(0.5rem, env(safe-area-inset-top)); left: 0; right: 0; margin: 0 auto;
  width: min(40rem, calc(100vw - 1rem)); display: grid; gap: 0.3rem; padding: 0.5rem 0.8rem;
  background: rgba(16, 26, 22, 0.88); color: var(--on-wood); border: 0.12rem solid rgba(180, 230, 200, 0.25);
  border-radius: 1rem; box-shadow: 0 0.4rem 1.2rem rgba(0, 0, 0, 0.4);
}
.fight-title { display: flex; align-items: baseline; gap: 0.5rem; flex-wrap: wrap; }
.fight-title strong { font-size: 1.15rem; }
.fight-title .sub { color: rgba(255, 243, 214, 0.7); }
.fight-hp { display: flex; align-items: center; gap: 0.6rem; }
.fight-hp .num { min-width: 8rem; text-align: right; }
.bar.boss-hp { flex: 1; height: 1rem; background: rgba(0, 0, 0, 0.45); }
.bar.boss-hp i { background: linear-gradient(90deg, #e8686b, #f2b53a); transition: width 0.1s; }
.fight-info { display: flex; flex-wrap: wrap; align-items: center; gap: 0.3rem 0.9rem; font-size: 0.85rem; font-weight: 700; }
.fight-info .ic { color: var(--on-wood); width: 1rem; height: 1rem; }
.fight-info .low { color: #ff8a8a; }
.fight-armor.bad { color: #ff9f9f; }
.fight-combo { color: var(--gold); }
.fight-buffs { color: #ffb36b; }
.fight-bar {
  position: fixed; z-index: 10; bottom: max(0.5rem, env(safe-area-inset-bottom)); left: 50%; transform: translateX(-50%);
  display: flex; align-items: center; gap: 0.4rem; padding: 0.45rem; max-width: calc(100vw - 0.6rem); overflow-x: auto;
  background: rgba(16, 26, 22, 0.92); border: 0.12rem solid rgba(180, 230, 200, 0.25); border-radius: 1.2rem;
}
.fight-bar .sep { width: 0.12rem; height: 2.2rem; background: rgba(255, 243, 214, 0.2); flex: none; }
.fight-bar .tool { background: #eef7dc; }
.fight-bar .giveup { color: var(--on-wood); }
.fight-spray .cd {
  position: absolute; inset: 0; display: grid; place-items: center; border-radius: inherit;
  background: rgba(16, 26, 22, 0.65); color: #fff; font-weight: 800; font-size: 0.85rem;
}
.fight-banner {
  position: fixed; z-index: 15; left: 0; right: 0; top: 36%; margin: 0 auto; width: max-content; max-width: calc(100vw - 2rem);
  text-align: center; pointer-events: none; color: var(--on-wood); text-shadow: 0 0.15rem 0.4rem rgba(0, 0, 0, 0.85);
}
.fight-banner strong { display: block; font-size: clamp(1.6rem, 5vw, 2.6rem); font-weight: 900; }
.fight-banner span { display: block; font-weight: 700; max-width: 28rem; margin: 0 auto; }
.fight-banner.warn strong { color: #ffb36b; }
.fight-banner.good strong { color: #c9f7c0; }
.fight-banner.show { animation: banner 2.2s ease forwards; }
@keyframes banner {
  0% { opacity: 0; transform: scale(0.8); } 10% { opacity: 1; transform: scale(1.06); } 20% { transform: scale(1); }
  80% { opacity: 1; } 100% { opacity: 0; }
}
.item.boss { align-items: flex-start; }
.item.boss canvas.pic { border-radius: 0.8rem; background: radial-gradient(circle at 50% 40%, #1d4a3a, #0e1c18); }
.wounds { margin-top: 0.2rem; font-size: 0.85rem; font-weight: 800; color: var(--leaf-dark); }
.reqs { display: grid; gap: 0.15rem; margin-top: 0.35rem; font-size: 0.82rem; font-weight: 700; }
.reqs li { display: flex; align-items: center; gap: 0.3rem; }
.reqs .ok { color: var(--leaf-dark); }
.reqs .no { color: var(--red-dark); }
.reqs .ic { width: 0.95rem; height: 0.95rem; }
.fight-help { flex: none; font-size: 0.88rem; }
.fight-help summary { cursor: pointer; font-weight: 800; color: var(--wood); }
.fight-help ul { list-style: disc; padding-left: 1.2rem; margin-top: 0.3rem; display: grid; gap: 0.2rem; }

/* Banner shown while visiting a friend's barn. */
.visit-bar {
  position: fixed; z-index: 10; top: max(0.5rem, env(safe-area-inset-top)); left: 0; right: 0; margin: 0 auto;
  display: flex; align-items: center; justify-content: center; flex-wrap: wrap; gap: 0.3rem 0.7rem;
  width: max-content; max-width: calc(100vw - 1rem); padding: 0.45rem 0.8rem;
  background: var(--cream); border: 0.12rem solid rgba(58, 42, 34, 0.3); border-radius: 1rem; box-shadow: var(--shadow);
  animation: rise 0.3s;
}
.visit-bar strong { font-size: 1.05rem; }
.visit-bar .hint { text-align: center; }
.photo .hud, .photo .side, .photo .toolbar, .photo .tutorial, .photo .toasts, .photo .popover, .photo .debug { display: none; }
.mobile-only { display: none; }

/* Wide screens: the side panel is always visible and the scene makes room for it. */
@media (min-width: 900px) {
  .mode-play { --side-w: 19.5rem; }
  .mode-play .hud { padding-right: 0.5rem; }
}

/* Phones and narrow windows: the info panel becomes a bottom sheet. */
@media (max-width: 899px) {
  .mobile-only { display: inline-flex; }
  .hud-btn .btn-label, .hud-btn kbd { display: none; }
  .hud-btn { width: 2.6rem; padding: 0; }
  .pill { min-height: 2rem; padding: 0.1rem 0.5rem; font-size: 0.9rem; }
  .pill.clock .num { font-size: 0.75rem; }
  .tankbar { width: 2rem; }
  .pill.tank .num { display: none; }
  .side { top: auto; right: 0.5rem; left: 0.5rem; width: auto; bottom: 5.2rem; max-height: 46vh; }
  .side .info, .side .orders { display: none; }
  .has-selection .side .info { display: block; }
  .has-selection .tutorial { display: none; }
  .toolbar { left: 50%; max-width: calc(100vw - 0.6rem); border-radius: 1rem; }
  .tool { width: 3.1rem; height: 3.1rem; }
  .item { flex-wrap: wrap; }
  .item-side { flex-direction: row; align-items: center; flex-wrap: wrap; width: 100%; justify-content: space-between; }
  .entry { flex-wrap: wrap; }
  .entry dl { grid-template-columns: 5.5rem 1fr; }
}
@media (hover: none) { .tool kbd, .hud-btn kbd { display: none; } }

/* ---------- animations ---------- */
@keyframes fade-in { from { opacity: 0; } }
@keyframes rise { from { opacity: 0; transform: translateY(1rem) scale(0.96); } }
@keyframes pop-in { from { opacity: 0; transform: scale(0.8); } }
@keyframes toast-in { from { opacity: 0; transform: translateY(-1rem) scale(0.95); } }
@keyframes pulse { 50% { filter: brightness(1.18); transform: scale(1.04); } }
@keyframes glow { 0%, 100% { box-shadow: 0 0 0 0 rgba(123, 207, 106, 0.9); } 50% { box-shadow: 0 0 0 0.6rem rgba(123, 207, 106, 0); } }
@keyframes sway { 0%, 100% { transform: rotate(-8deg); } 50% { transform: rotate(10deg); } }
@keyframes shine {
  0% { box-shadow: 0 0 0 0 rgba(255, 210, 74, 0.9); background: #fff3b8; }
  100% { box-shadow: 0 0 0 1rem rgba(255, 210, 74, 0); }
}

/* Reduced motion: from the setting (body.reduced) or the system preference. */
.reduced *, .reduced *::before, .reduced *::after { animation: none !important; transition: none !important; }
.reduced .barn-sign:hover { transform: none; }
@media (prefers-reduced-motion: reduce) {
  .title-leaf, .tut-glow, .pill.tank.low, .tool.action.ready, .barn-sign.ready { animation: none; }
  .barn-sign:hover { transform: none; }
}

/* Colour-blind friendly mode: patterns on top of colours. */
.cb .bar.water i { background-image: repeating-linear-gradient(45deg, rgba(255, 255, 255, 0.45) 0 0.2rem, transparent 0.2rem 0.45rem); }
.cb .bar.health i { background-image: repeating-linear-gradient(90deg, rgba(255, 255, 255, 0.45) 0 0.15rem, transparent 0.15rem 0.4rem); }
.cb .bar.quality i { background-image: radial-gradient(rgba(58, 42, 34, 0.45) 30%, transparent 32%); background-size: 0.4rem 0.4rem; }
.cb .stat.warn .bar-text::before { content: "! "; }
.cb .need.bad::before { content: "\2716  "; }
.cb .tool .count.zero { outline: 0.12rem dashed #fff; }

/* ---------- dark mode (Settings > Theme) ----------
   Only menus and panels turn dark; the barn keeps its own day and night.
   The shared palette gets dark versions here. Anything that always sits on
   wood or on the dark fight screen uses fixed colours (--on-wood) instead. */
html.dark {
  color-scheme: dark;
  --cream: #3a2c23;
  --cream-2: #4a392d;
  --paper: #2c211a;
  --ink: #f5e8d2;
  --ink-soft: #cbb79e;
  --shadow: 0 0.25rem 0 rgba(0, 0, 0, 0.45);
  --line: rgba(255, 236, 205, 0.16);
}
.dark .card { background: rgba(58, 44, 35, 0.96); }
/* :where keeps these weak, so special borders (merchant, season card, ...) still win. */
.dark :where(.card, .item, .entry, .paint, .gift-row, .popover, .pop-item, .text-input, .code, .visit-bar) { border-color: var(--line); }
.dark :where(.bar, .tankbar) { background: rgba(255, 236, 205, 0.14); }
.dark .lvl-pips i:not(.on) { background: rgba(255, 236, 205, 0.2); }
.dark .switch { background: rgba(255, 236, 205, 0.22); }
.dark kbd { background: rgba(255, 236, 205, 0.14); }
/* Light tints become dark tints. */
.dark .item.locked { background: #352920; }
.dark .item.merchant { background: #3a2c47; }
.dark .item.rare { background: #3d3120; }
.dark .item.done, .dark .paint.active { background: #2c3a25; }
.dark .season-card, .dark .toast.gold { background: #3d3120; }
.dark .tut-card { background: #2f2a1b; }
.dark .pop-item:hover, .dark .pop-item.active { background: #55401f; }
.dark .tool:hover { background: #4a392d; }
.dark .tool.action { background: #22394a; }
.dark .tool.action.ready { background: #5a4a1c; }
.dark .fight-bar .tool { background: #2d4436; }
/* The selected tool stays gold, so its icon and letter stay dark. */
.dark .tool.active, .dark .tool.active .tool-ic { color: #3a2a22; }
.dark .tool.active .caret { color: #6b5544; }
/* Coloured text gets lighter so it stays readable on dark panels. */
.dark .need, .dark .wounds, .dark .synergy, .dark .effect .next, .dark .tut-step, .dark .reqs .ok { color: #9ad48f; }
.dark .need.bad, .dark .reqs .no, .dark .stat.warn .bar-text { color: #ff9a8f; }
.dark .stars, .dark .maxed { color: #f2c14e; }
.dark .settings h3, .dark .prose h3, .dark .fight-help summary { color: #e0b083; }
