/* Scoped to #mlv-app (not :root/body) -- this page is included inside
   ANetBBS's base.html, which owns the real <body> (navbar, footer,
   theme system) and already defines its own --theme-* custom
   properties. Custom properties, the wrapper's own layout/sizing, and
   the original standalone version's `body { ... }` rules all live under
   #mlv-app instead, so this game can't bleed into or collide with the
   surrounding BBS page. See also the .mlv-modal/.mlv-toast renames
   further down -- same reasoning, for classes that collide with
   Bootstrap component names instead of page-level styles. */
#mlv-app {
  --bg: #2b2620;
  --panel: #3a3226;
  --panel-light: #4a4032;
  --accent: #e0b23d;
  --text: #f0e8d8;
  --text-dim: #b8ac94;

  margin: 0 auto;
  background: var(--bg);
  color: var(--text);
  font-family: 'Segoe UI', system-ui, -apple-system, sans-serif;
  overflow: hidden;
  height: min(82vh, 900px);
  min-height: 560px;
  border-radius: 8px;
  display: flex;
  flex-direction: column;
}
#mlv-app * { box-sizing: border-box; }

/* ── Top bar ── */
#topBar {
  display: flex;
  align-items: center;
  gap: 18px;
  padding: 8px 16px;
  background: var(--panel);
  border-bottom: 3px solid var(--accent);
  flex-wrap: wrap;
}
#topBar h1 { font-size: 1.1rem; margin: 0 12px 0 0; white-space: nowrap; }
.stat { display: flex; align-items: center; gap: 5px; font-size: 0.95rem; }
.stat-icon { font-size: 1rem; }
.happiness-stat { flex-direction: column; align-items: flex-start; gap: 2px; }
.happiness-track { width: 90px; height: 6px; background: #201c16; border-radius: 3px; overflow: hidden; }
.happiness-fill { height: 100%; width: 70%; background: #5fae6e; transition: width 0.4s; }
.tax-stat { display: flex; flex-direction: column; align-items: flex-start; gap: 2px; }
.tax-stat label { font-size: 0.8rem; color: var(--text-dim); }
.tax-stat input { width: 90px; }
.speed-controls { display: flex; gap: 4px; margin-left: auto; }
.camera-controls { display: flex; gap: 4px; }
.camera-controls button {
  background: var(--panel-light); color: var(--text); border: 1px solid #55493a;
  border-radius: 4px; padding: 4px 9px; cursor: pointer; font-size: 0.9rem;
}
.camera-controls button:hover { filter: brightness(1.15); }
.camera-controls button.muted { opacity: 0.5; }
.volume-slider { width: 60px; align-self: center; accent-color: var(--accent); }
.speed-btn {
  background: var(--panel-light); color: var(--text); border: 1px solid #55493a;
  border-radius: 4px; padding: 4px 9px; cursor: pointer; font-size: 0.85rem;
}
.speed-btn.active { background: var(--accent); color: #2b2620; font-weight: bold; }
.speed-btn:hover { filter: brightness(1.15); }
.view-mode-controls { display: flex; gap: 4px; }
.viewmode-btn {
  background: var(--panel-light); color: var(--text); border: 1px solid #55493a;
  border-radius: 4px; padding: 4px 9px; cursor: pointer; font-size: 0.9rem;
}
.viewmode-btn.active { background: var(--accent); color: #2b2620; font-weight: bold; }
.viewmode-btn:hover { filter: brightness(1.15); }

/* ── Main layout ── */
#mainArea { flex: 1; display: flex; overflow: hidden; }

#sidePanel {
  width: 280px;
  background: var(--panel);
  border-right: 3px solid #201c16;
  display: flex;
  flex-direction: column;
  overflow-y: auto;
  padding: 10px;
  gap: 10px;
}
/* Flex items default to flex-shrink:1 with min-height:auto (their
   min-CONTENT size, not their natural/preferred size) -- when #sidePanel
   is shorter than the sum of its children's preferred heights (a real
   9-building Services list + info panel + town log easily exceeds a
   laptop-height viewport), the browser was squeezing every child down to
   near its text-wrapping minimum instead of leaving #sidePanel's own
   overflow-y:auto to handle the excess. A squeezed flex item still
   renders its full content (default overflow:visible), so the text just
   spilled out past its own shrunk box into the next sibling's space --
   reported live via screenshot as the whole sidebar "on top of one
   another." .log-panel is deliberately excluded: it's meant to flex-grow
   into whatever room is left, and its own #logList has its own
   overflow-y:auto for long town-log scrollback. */
.cat-tabs, .build-list, .bulldoze-btn, .info-panel { flex-shrink: 0; }

.cat-tabs { display: flex; gap: 4px; }
.cat-tab {
  flex: 1; background: var(--panel-light); color: var(--text-dim);
  border: none; padding: 6px 4px; font-size: 0.78rem; cursor: pointer; border-radius: 4px 4px 0 0;
}
.cat-tab.active { background: var(--accent); color: #2b2620; font-weight: bold; }

.build-list { display: flex; flex-direction: column; gap: 5px; min-height: 40px; }
.build-btn {
  display: flex; align-items: center; gap: 8px;
  background: var(--panel-light); border: 1px solid #55493a; border-radius: 5px;
  color: var(--text); padding: 6px 8px; cursor: pointer; text-align: left; font-size: 0.85rem;
}
.build-btn:hover:not(.locked) { filter: brightness(1.2); }
.build-btn.selected { outline: 2px solid var(--accent); background: #55493a; }
.build-btn.locked { opacity: 0.45; cursor: not-allowed; }
.swatch { width: 14px; height: 14px; border-radius: 3px; flex-shrink: 0; }
.build-name { flex: 1; }
.build-cost { color: var(--accent); font-size: 0.8rem; }
.empty-cat { color: var(--text-dim); font-size: 0.85rem; }

.bulldoze-btn {
  background: #7a3a3a; color: var(--text); border: 1px solid #a35a5a;
  border-radius: 5px; padding: 7px; cursor: pointer; font-size: 0.9rem;
}
.bulldoze-btn:hover { filter: brightness(1.2); }

.info-panel {
  background: #241f18; border-radius: 5px; padding: 8px 10px; font-size: 0.85rem;
  min-height: 70px;
}
.info-panel h3 { margin: 0 0 4px; font-size: 0.95rem; color: var(--accent); }
.info-panel p { margin: 2px 0; color: var(--text-dim); }

.log-panel { flex: 1; display: flex; flex-direction: column; min-height: 100px; }
.log-panel h4 { margin: 0 0 4px; font-size: 0.85rem; color: var(--text-dim); }
#logList { list-style: none; margin: 0; padding: 0; overflow-y: auto; font-size: 0.78rem; flex: 1; min-height: 0; }
#logList li { padding: 3px 0; border-bottom: 1px solid #4a4032; color: var(--text-dim); }
.log-day { color: var(--accent); margin-right: 4px; }
.log-milestone { color: #e0b23d; }
.log-warning { color: #e37b7b; }
.log-harvest { color: #8fc45f; }

#canvasWrap {
  flex: 1; overflow: hidden; display: flex; align-items: center; justify-content: center;
  background: repeating-conic-gradient(#241f18 0% 25%, #221d16 0% 50%) 0 0 / 40px 40px;
  padding: 14px;
  position: relative;
}
/* Camera pan/zoom is handled internally on the fixed-size canvas now (see
   js/main.js) rather than by scrolling this wrapper. */
#gameCanvas {
  image-rendering: pixelated; cursor: crosshair; box-shadow: 0 4px 24px rgba(0,0,0,0.5);
  /* Let JS own all touch gestures (tap/drag-pan/pinch-zoom, see main.js) --
     without this, mobile browsers try to handle pinch as a page-zoom
     gesture themselves even with preventDefault() in the touch handlers. */
  touch-action: none;
}

#minimapCanvas {
  position: absolute; right: 24px; bottom: 24px;
  border: 2px solid #55493a; border-radius: 4px; cursor: pointer;
  box-shadow: 0 2px 12px rgba(0,0,0,0.6);
  background: #1a160f;
}

#bottomBar {
  display: flex; align-items: center; gap: 8px; padding: 8px 16px;
  background: var(--panel); border-top: 3px solid #201c16; flex-wrap: wrap;
}
#bottomBar button {
  background: var(--panel-light); color: var(--text); border: 1px solid #55493a;
  border-radius: 4px; padding: 6px 12px; cursor: pointer; font-size: 0.85rem;
}
#bottomBar button:hover { filter: brightness(1.2); }
.hint { color: var(--text-dim); font-size: 0.78rem; margin-left: auto; }

.slot-picker { display: flex; gap: 4px; align-items: center; }
.slot-btn {
  background: var(--panel-light); color: var(--text); border: 1px solid #55493a;
  border-radius: 4px; padding: 5px 9px; cursor: pointer; font-size: 0.8rem;
  display: flex; flex-direction: column; align-items: center; line-height: 1.2;
}
.slot-btn .slot-sub { font-size: 0.68rem; color: var(--text-dim); }
.slot-btn.active { background: var(--accent); color: #2b2620; }
.slot-btn.active .slot-sub { color: #4a3f20; }
.slot-btn:hover { filter: brightness(1.15); }

#btnStats {
  background: var(--panel-light); color: var(--text); border: 1px solid #55493a;
  border-radius: 4px; padding: 4px 9px; cursor: pointer; font-size: 0.9rem;
}
#btnStats:hover { filter: brightness(1.15); }

/* ── Stats modal ──
   Prefixed mlv- on .modal/.toast (and their variants) -- this page loads
   inside ANetBBS's base.html, which loads Bootstrap CSS/JS site-wide, and
   Bootstrap defines real, actively-styled .modal and .toast components
   (including a `.toast:not(.show)`-style hidden-by-default rule). Reusing
   those bare class names here would silently collide with Bootstrap's
   own rules depending on stylesheet order -- prefixing avoids the
   collision outright instead of relying on load-order/specificity. */
.mlv-modal {
  position: fixed; inset: 0; background: rgba(0,0,0,0.55);
  display: flex; align-items: center; justify-content: center; z-index: 200;
}
.mlv-modal.hidden { display: none; }
.mlv-modal-panel {
  background: var(--panel); border: 2px solid var(--accent); border-radius: 8px;
  padding: 16px 20px; box-shadow: 0 8px 40px rgba(0,0,0,0.6);
  max-width: 92vw;
}
.mlv-modal-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 8px; }
.mlv-modal-header h2 { margin: 0; font-size: 1.1rem; }
.mlv-modal-close {
  background: var(--panel-light); color: var(--text); border: 1px solid #55493a;
  border-radius: 4px; padding: 4px 10px; cursor: pointer;
}
.mlv-modal-close:hover { filter: brightness(1.2); }
#statsCanvas { display: block; max-width: 100%; background: #201c16; border-radius: 4px; }
.mlv-modal-hint { color: var(--text-dim); font-size: 0.8rem; margin: 8px 0 0; }

.mlv-help-panel { width: 480px; }
.mlv-help-body { max-height: 70vh; overflow-y: auto; font-size: 0.88rem; line-height: 1.5; }
.mlv-help-body p { margin: 0 0 10px; }
.mlv-help-body p:last-child { margin-bottom: 0; }
.mlv-help-body strong { color: var(--accent); }

#mlvToasts {
  position: fixed; top: 70px; right: 16px; display: flex; flex-direction: column;
  gap: 6px; z-index: 100; max-width: 320px;
}
.mlv-toast {
  background: #241f18; border-left: 4px solid var(--accent); color: var(--text);
  padding: 8px 12px; border-radius: 4px; font-size: 0.85rem; opacity: 0;
  transform: translateX(20px); transition: all 0.3s;
  box-shadow: 0 2px 10px rgba(0,0,0,0.4);
}
.mlv-toast.show { opacity: 1; transform: translateX(0); }
.mlv-toast-milestone { border-left-color: #e0b23d; }
.mlv-toast-warning { border-left-color: #c0524f; }
.mlv-toast-harvest { border-left-color: #8fc45f; }
.mlv-toast-season { border-left-color: #7fb2c9; }

@media (max-width: 900px) {
  #sidePanel { width: 220px; }
  #topBar h1 { display: none; }
  #minimapCanvas { transform: scale(0.7); transform-origin: bottom right; }
}
