:root {
  --bg: #11161f;
  --panel: #1f2734;
  --text: #f5f7fa;
  --accent: #4dd7ff;
  --danger: #ff5c5c;
  --ok: #82ff9b;
  --warn: #ffd66f;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: Inter, Segoe UI, Tahoma, sans-serif;
  color: var(--text);
  background: linear-gradient(120deg, #0b0f17, #152033);
  /* Keep the app pinned to the viewport to avoid page-level scrolling. */
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  overscroll-behavior: none;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.6rem;
  padding: 0.35rem 0.75rem;
  background: linear-gradient(180deg, #0a0f19, #060a11);
  border-bottom: 1px solid #2a3a55;
}

/* Smaller heading keeps HUD readable on laptop-height displays. */
.topbar h1 { margin: 0; font-size: 0.82rem; line-height: 1.2; max-width: 9ch; white-space: nowrap; opacity: 0.9; }
/* Compact HUD text/gaps reduce wrapping and preserve canvas space. */
.hud {
  display: flex;
  flex-wrap: wrap;
  gap: 0.3rem 0.55rem;
  font-size: 0.72rem;
  line-height: 1.3;
  flex: 1;
}
.hud > span {
  padding: 0.12rem 0.35rem;
  border-radius: 3px;
  background: rgba(255,255,255,0.04);
}
.hud > span.floor-clock-group {
  background: none;
  padding: 0;
}
.floor-clock-group > span {
  padding: 0.12rem 0.35rem;
  border-radius: 3px;
  background: rgba(255,255,255,0.04);
}
.top-controls { display: flex; gap: 0.32rem; flex-shrink: 0; }

.start-overlay {
  position: fixed;
  inset: 0;
  z-index: 120;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1rem;
  background: rgba(3, 8, 18, 0.88);
  backdrop-filter: blur(4px);
}

/* Ensure the splash truly disappears when JS toggles `hidden=true`.
   Class-level `display:flex` would otherwise override the browser's default [hidden] rule. */
.start-overlay[hidden] {
  display: none !important;
}

.start-card {
  width: min(720px, 96vw);
  background: #0e1726;
  border: 1px solid #4a628c;
  border-radius: 14px;
  padding: 0.95rem;
}

.start-subtitle { margin-top: 0.2rem; color: #b9d7f5; }

.start-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 0.6rem;
}

.start-grid label {
  display: flex;
  flex-direction: column;
  gap: 0.22rem;
  font-size: 0.8rem;
}

.start-grid input,
.start-grid select,
.start-grid textarea {
  border: 1px solid #4a628c;
  border-radius: 8px;
  background: #11233e;
  color: #eaf6ff;
  min-height: 2rem;
  padding: 0.2rem 0.4rem;
}

.ratios { margin-bottom: 0.6rem; }

.start-btn {
  width: 100%;
  min-height: 2.35rem;
  border: 1px solid #7bb9ff;
  border-radius: 9px;
  background: linear-gradient(180deg, #153455, #0f2742);
  color: #eaf6ff;
  font-weight: 700;
  cursor: pointer;
}

.start-btn:hover { background: linear-gradient(180deg, #1a4068, #143252); }


.splash-actions {
  display: grid;
  grid-template-columns: 1fr;
  gap: 0.55rem;
  margin-top: 0.55rem;
}

.splash-settings-btn {
  width: 100%;
  min-height: 2.35rem;
  font-weight: 700;
}

.splash-settings-dialog {
  width: min(860px, 94vw);
  max-height: 86vh;
  overflow: auto;
}

.splash-settings-dialog::backdrop {
  background: rgba(3, 8, 18, 0.7);
  backdrop-filter: blur(3px);
}

.startup-loading {
  margin-top: 0.5rem;
  border: 1px solid #3f5f89;
  border-radius: 10px;
  background: #0d2038;
  padding: 0.5rem 0.6rem;
}

.startup-loading-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.6rem;
  font-size: 0.78rem;
  color: #d8ecff;
}

.startup-loading-track {
  margin-top: 0.35rem;
  width: 100%;
  height: 0.56rem;
  border-radius: 999px;
  border: 1px solid #547fb1;
  background: #0a1526;
  overflow: hidden;
}

.startup-loading-bar {
  width: 0%;
  height: 100%;
  background: linear-gradient(90deg, #57a4ff, #95d7ff);
  transition: width 180ms ease-out;
}

.settings-footer-actions {
  margin-top: 0.55rem;
}

.llm-grid {
  margin-bottom: 0.35rem;
}

.llm-toggle input {
  inline-size: 1.2rem;
  block-size: 1.2rem;
  margin-top: 0.25rem;
}

.llm-actions {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  margin: 0.15rem 0 0.55rem;
}

.secondary-btn {
  min-height: 2rem;
  border: 1px solid #6f8fb7;
  border-radius: 8px;
  background: #102640;
  color: #d9edff;
  cursor: pointer;
  padding: 0.25rem 0.55rem;
}
.secondary-btn:hover { background: #153455; }

.llm-status-error {
  color: #ffd2d2;
}

.llm-actions-wrap {
  flex-wrap: wrap;
  justify-content: flex-start;
}

#optLlmRemoteModel,
#optLlmLocalEndpoint,
#optLlmManualModel {
  width: 100%;
}

.floor-clock-group {
  display: inline-flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 0.42rem;
}

#dayLabel,
#period,
#roomTarget,
#floorStatus {
  white-space: nowrap;
}

.control {
  border: 1px solid #38648a;
  background: #0b1a2e;
  color: #d8efff;
  font-size: 0.88rem;
  border-radius: 8px;
  min-width: 1.9rem;
  min-height: 1.9rem;
  cursor: pointer;
}
.control:hover { background: #102640; }

main {
  display: grid;
  grid-template-columns: 1fr minmax(250px, 280px);
  gap: 1rem;
  padding: 1rem;
  /* Allow the content area to shrink under a flexible header. */
  flex: 1;
  min-width: 0;
  min-height: 0;
}

main > * {
  min-width: 0;
}

.canvas-wrap {
  background: #0d1623;
  border: 1px solid #31415e;
  border-radius: 10px;
  padding: 0.5rem;
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  /* Prevent the canvas region from creating extra page height. */
  min-height: 0;
  overflow: hidden;
}

canvas {
  width: 100%;
  height: auto;
  max-width: 100%;
  max-height: 100%;
  border-radius: 8px;
  display: block;
  image-rendering: pixelated;
  touch-action: none;
}

.touch-controls {
  position: absolute;
  left: 0.75rem;
  right: 0.75rem;
  bottom: calc(0.75rem + env(safe-area-inset-bottom, 0px));
  display: flex;
  align-items: end;
  justify-content: space-between;
  gap: 0.9rem;
  z-index: 48;
  pointer-events: none;
}

.touch-controls[hidden] {
  display: none !important;
}

.touch-pad,
.touch-camera,
.touch-actions {
  pointer-events: auto;
}

.touch-pad {
  display: grid;
  grid-template-columns: repeat(3, minmax(3.2rem, 4.2rem));
  grid-template-areas:
    ". up run"
    "left down right";
  gap: 0.42rem;
  align-items: center;
}

.touch-actions {
  display: grid;
  grid-template-columns: repeat(5, minmax(3.1rem, 4.4rem));
  gap: 0.42rem;
}

.touch-camera {
  display: grid;
  grid-template-columns: 1fr;
  gap: 0.34rem;
  align-self: end;
}

.touch-btn {
  min-height: 3rem;
  border: 1px solid rgba(163, 210, 255, 0.7);
  border-radius: 14px;
  background: linear-gradient(180deg, rgba(12, 31, 57, 0.94), rgba(9, 21, 40, 0.94));
  color: #eef7ff;
  font-weight: 700;
  letter-spacing: 0.02em;
  box-shadow: 0 10px 22px rgba(0, 0, 0, 0.32);
  backdrop-filter: blur(8px);
  touch-action: manipulation;
  user-select: none;
}

.touch-btn:active,
.touch-btn.is-pressed {
  transform: translateY(1px) scale(0.985);
  background: linear-gradient(180deg, rgba(20, 58, 101, 0.96), rgba(14, 35, 64, 0.96));
  border-color: #9dd8ff;
}

.touch-btn-up { grid-area: up; }
.touch-btn-left { grid-area: left; }
.touch-btn-down { grid-area: down; }
.touch-btn-right { grid-area: right; }
.touch-btn-run { grid-area: run; font-size: 0.78rem; }
.touch-btn-primary { border-color: rgba(255, 221, 141, 0.8); }
.touch-btn-camera {
  min-width: 3rem;
  min-height: 2.45rem;
  font-size: 1rem;
  padding: 0.2rem 0.4rem;
}
.touch-btn-camera-reset {
  min-width: 3.6rem;
  font-size: 0.74rem;
  letter-spacing: 0.01em;
}

.touch-hint {
  position: absolute;
  left: 0.95rem;
  top: 0.85rem;
  z-index: 46;
  margin: 0;
  padding: 0.3rem 0.55rem;
  border: 1px solid rgba(140, 198, 255, 0.62);
  border-radius: 999px;
  background: rgba(10, 22, 40, 0.78);
  color: #d7edff;
  font-size: 0.68rem;
  letter-spacing: 0.01em;
}

.touch-hint[hidden] {
  display: none !important;
}


/* Hover card that follows the pointer and reports entity vitals quickly. */

.day-transition-overlay {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(180deg, rgba(2, 6, 14, 0.15), rgba(2, 6, 14, 0.84));
  z-index: 30;
}

/* Keep day/night banner behavior consistent: hidden attribute must trump display:flex. */
.day-transition-overlay[hidden] {
  display: none !important;
}

.day-transition-card {
  width: min(82%, 460px);
  padding: 1rem 1.1rem;
  border-radius: 12px;
  border: 1px solid #6c8fc5;
  background: rgba(7, 18, 34, 0.94);
  box-shadow: 0 14px 30px rgba(0, 0, 0, 0.4);
  text-align: center;
}

.day-transition-card h3 {
  margin: 0;
  color: #d8ebff;
  font-size: 1.02rem;
}

.day-transition-card p {
  margin: 0.45rem 0 0;
  color: #bdd7f8;
  font-size: 0.82rem;
}

.entity-tooltip {
  position: absolute;
  z-index: 40;
  pointer-events: none;
  min-width: 170px;
  max-width: 240px;
  padding: 0.4rem 0.5rem;
  border: 1px solid #74a7d6;
  border-radius: 8px;
  background: rgba(8, 15, 28, 0.93);
  color: #e7f3ff;
  font-size: 0.72rem;
  line-height: 1.3;
  box-shadow: 0 8px 18px rgba(0, 0, 0, 0.35);
  outline: 1px solid rgba(255, 255, 255, 0.08);
  white-space: nowrap;
}
.panel {
  background: var(--panel);
  border: 1px solid #31415e;
  border-radius: 10px;
  padding: 0.7rem;
  /* Keep instructions accessible at all resolutions. */
  min-height: 0;
  overflow: auto;
  font-size: 0.78rem;
}

.panel h2, .panel h3 { margin-top: 0.35rem; margin-bottom: 0.35rem; line-height: 1.15; }
.panel p, .panel li { margin: 0.2rem 0; line-height: 1.22; }

.dot {
  display: inline-block;
  width: 0.58rem;
  height: 0.58rem;
  border-radius: 50%;
  margin-right: 0.4rem;
}

.player { background: #ffe04d; }
.teacher { background: #8eb2ff; }
.bully { background: #ff5f88; }
.swot { background: #8effd3; }
.hero { background: #ffd58e; }
.weird { background: #c58eff; }

.todo-carousel {
  width: 100%;
  display: flex;
  align-items: center;
  gap: 0.38rem;
  border: 1px solid #3b5d86;
  background: linear-gradient(180deg, #11213a, #0b162a);
  color: #e8f3ff;
  border-radius: 8px;
  padding: 0.3rem 0.42rem;
  cursor: pointer;
}
.todo-carousel:hover {
  border-color: #5f8fbe;
  background: linear-gradient(180deg, #162b49, #10203b);
}
.todo-carousel-icon { flex: 0 0 auto; }
.todo-carousel-window {
  flex: 1;
  overflow: hidden;
  white-space: nowrap;
}
.todo-carousel-text {
  display: inline-block;
  padding-left: 100%;
  animation: todoTicker 96s linear infinite;
}
@keyframes todoTicker {
  0% { transform: translateX(0); }
  100% { transform: translateX(-100%); }
}
.todo-help {
  margin: 0.3rem 0 0.45rem;
  font-size: 0.7rem;
  color: #b9d7f5;
}
.todo {
  margin: 0;
  padding-left: 1rem;
  font-size: 0.76rem;
}
.todo li { margin-bottom: 0.25rem; }

.event-filters {
  display: flex;
  flex-wrap: wrap;
  gap: 0.55rem 0.75rem;
  font-size: 0.72rem;
  margin-top: 0.18rem;
}

.events {
  margin-top: 0.35rem;
  max-height: 220px;
  overflow: hidden;
  border-top: 1px dashed #43597d;
  padding-top: 0.45rem;
  font-size: 0.74rem;
}

.event-line.speech { color: #bde0ff; }
.event-line.action { color: #f7f7f7; }
.event-line.thought { color: #c9e8ff; }
.event-line.world { color: #ffe8a6; }
.event-line .event-time {
  /* Keep timestamps readable but quieter than event text. */
  color: #d6deea;
}



.llm-debug-log {
  margin-top: 0.35rem;
  max-height: 170px;
  overflow: auto;
  border: 1px dashed #43597d;
  border-radius: 8px;
  padding: 0.35rem 0.45rem;
  font-size: 0.7rem;
  background: rgba(9, 16, 28, 0.7);
}

.llm-debug-line {
  margin-bottom: 0.22rem;
  line-height: 1.25;
  word-break: break-word;
}

.llm-debug-info { color: #bfe3ff; }
.llm-debug-warn { color: #ffe4a1; }
.llm-debug-error { color: #ffc4c4; }

dialog {
  max-width: 560px;
  border-radius: 12px;
  border: 1px solid #4a628c;
  background: #0e1726;
  color: white;
}

dialog button {
  border: 1px solid #4a628c;
  background: #11233e;
  color: #eaf6ff;
  border-radius: 8px;
  padding: 0.35rem 0.55rem;
  cursor: pointer;
}


dialog h3 {
  margin: 0.75rem 0 0.4rem;
  font-size: 0.95rem;
  color: #d7ecff;
}

/* Structured help lists keep keyboard/touch guidance quick to scan. */
.help-controls,
.help-legend {
  margin: 0 0 0.65rem;
  padding-left: 1.1rem;
  display: grid;
  gap: 0.28rem;
}

.help-controls li,
.help-legend li {
  line-height: 1.3;
}

.help-legend .dot {
  margin-right: 0.45rem;
  vertical-align: middle;
}

/* Support callout is styled as a compact card for clear discoverability in Help. */
.help-support {
  margin: 0.3rem 0 0.65rem;
  padding: 0.55rem 0.65rem;
  border: 1px solid #4a628c;
  border-radius: 8px;
  background: #101f35;
  font-size: 0.82rem;
  line-height: 1.35;
}

.help-support a {
  color: #9dd2ff;
  font-weight: 700;
}

.help-support a:hover {
  color: #c8e7ff;
}

/* Prominent close control improves discoverability and touch usability. */
.dialog-close {
  margin-top: 0.4rem;
  min-height: 2.4rem;
  width: 100%;
  font-weight: 700;
  font-size: 0.95rem;
  border-width: 2px;
  border-color: #7bb9ff;
  background: linear-gradient(180deg, #153455, #0f2742);
}

.dialog-close:hover {
  background: linear-gradient(180deg, #1a4068, #143252);
}

@media (max-width: 1200px) {
  /* On smaller displays stack sections and return to page scrolling. */
  body { overflow: auto; }
  main { grid-template-columns: 1fr; }
  .panel { max-height: none; overflow: visible; }
}

@media (max-width: 900px) {
  .topbar {
    flex-direction: column;
    align-items: stretch;
  }

  .topbar h1 {
    max-width: none;
    font-size: 1rem;
  }

  .top-controls {
    flex-wrap: wrap;
  }

  main {
    gap: 0.75rem;
    padding: 0.7rem;
  }

  .canvas-wrap {
    padding: 0.35rem;
  }

  .touch-actions {
    grid-template-columns: repeat(5, minmax(2.8rem, 1fr));
  }
}

@media (max-width: 700px) {
  .start-grid {
    grid-template-columns: 1fr;
  }

  .touch-controls {
    flex-direction: column;
    align-items: stretch;
  }

  .touch-pad {
    justify-content: start;
  }

  .touch-actions {
    grid-template-columns: repeat(5, minmax(2.65rem, 1fr));
  }

  .touch-btn {
    min-height: 2.7rem;
    border-radius: 12px;
    font-size: 0.76rem;
  }
}


.class-question-panel {
  position: absolute;
  right: 0.8rem;
  top: 0.8rem;
  width: 340px;
  border: 1px solid #88c9ff;
  border-radius: 10px;
  background: rgba(7, 18, 33, 0.96);
  color: #e8f6ff;
  padding: 0.55rem;
  z-index: 44;
  box-shadow: 0 10px 24px rgba(0, 0, 0, 0.42);
}
.class-question-panel header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
}
.class-question-panel h3 {
  margin: 0;
  font-size: 0.82rem;
}
.class-question-panel p {
  margin: 0.32rem 0;
  font-size: 0.74rem;
}
.class-question-choices {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.34rem;
}
.class-question-choice {
  border: 1px solid #4e7ca8;
  background: linear-gradient(180deg, #143252, #102640);
  color: #dff0ff;
  border-radius: 7px;
  font-size: 0.73rem;
  text-align: left;
  padding: 0.35rem;
  cursor: pointer;
}
.class-question-choice:hover {
  background: linear-gradient(180deg, #1a4068, #143252);
  border-color: #7fc5ff;
}


.interaction-panel {
  position: absolute;
  right: 0.8rem;
  top: 0.8rem;
  width: 320px;
  max-height: calc(100% - 1.6rem);
  overflow: auto;
  border: 1px solid #6ea7d9;
  border-radius: 10px;
  background: rgba(7, 14, 25, 0.95);
  padding: 0.55rem;
  z-index: 45;
  box-shadow: 0 10px 24px rgba(0, 0, 0, 0.42);
}
.interaction-panel header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.4rem;
}
.interaction-panel h3 {
  margin: 0;
  font-size: 0.82rem;
}
.interaction-panel button {
  background: #102640;
  color: #d8efff;
  border: 1px solid #38648a;
  border-radius: 7px;
  cursor: pointer;
}
.interaction-panel p { margin: 0.35rem 0; font-size: 0.72rem; }
.interaction-options {
  display: grid;
  grid-template-columns: 1fr;
  gap: 0.34rem;
}
.interaction-options button {
  width: 100%;
  text-align: left;
  padding: 0.35rem 0.4rem;
  font-size: 0.72rem;
}

/* Vending Machine Shop Panel */
.vending-panel {
  position: absolute;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  width: 320px;
  max-width: calc(100% - 1.2rem);
  max-height: calc(100% - 1.6rem);
  overflow: auto;
  border: 2px solid #5ac85a;
  border-radius: 12px;
  background: rgba(7, 14, 25, 0.97);
  padding: 0.6rem;
  z-index: 50;
  box-shadow: 0 12px 32px rgba(0, 0, 0, 0.55);
}
.vending-panel[hidden] { display: none; }
.vending-panel header {
  display: flex; align-items: center; justify-content: space-between;
  gap: 0.4rem; margin-bottom: 0.3rem;
}
.vending-panel h3 { margin: 0; font-size: 0.85rem; color: #d8efff; }
.vending-panel button { background: #102640; color: #d8efff; border: 1px solid #38648a; border-radius: 7px; cursor: pointer; }
.vending-money {
  font-size: 0.75rem; color: #ffd166; padding: 0.25rem 0.4rem;
  background: rgba(255, 209, 102, 0.08); border-radius: 6px; margin-bottom: 0.4rem;
}
.vending-items {
  display: flex; flex-direction: column; gap: 4px;
}
.vending-item {
  display: flex; align-items: center; gap: 0.5rem;
  padding: 0.4rem 0.5rem; border: 1px solid #2a4a6a; border-radius: 8px;
  background: rgba(16, 38, 64, 0.6); cursor: pointer;
  transition: border-color 0.15s, background 0.15s;
}
.vending-item:hover { border-color: #5ac85a; background: rgba(30, 60, 40, 0.5); }
.vending-item:active { background: rgba(50, 90, 60, 0.5); }
.vending-item.too-expensive { opacity: 0.4; cursor: not-allowed; }
.vending-item .vi-icon { font-size: 1.4rem; flex-shrink: 0; width: 28px; text-align: center; }
.vending-item .vi-info { flex: 1; min-width: 0; }
.vending-item .vi-name { font-size: 0.75rem; font-weight: bold; color: #d8efff; }
.vending-item .vi-desc { font-size: 0.6rem; color: #8ab8d8; }
.vending-item .vi-price {
  font-size: 0.75rem; font-weight: bold; color: #5ac85a;
  flex-shrink: 0; padding: 0.2rem 0.4rem;
  background: rgba(90, 200, 90, 0.1); border-radius: 5px;
}
.vending-item.too-expensive .vi-price { color: #ff6666; }
.vending-hint { font-size: 0.6rem; color: #6a8a6a; margin: 0.4rem 0 0; text-align: center; }

body.compact-mobile .vending-panel { width: 280px; }

/* Locker Inventory Panel */
.locker-panel {
  position: absolute;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  width: 340px;
  max-width: calc(100% - 1.2rem);
  max-height: calc(100% - 1.6rem);
  overflow: auto;
  border: 2px solid #6ea7d9;
  border-radius: 12px;
  background: rgba(7, 14, 25, 0.97);
  padding: 0.6rem;
  z-index: 50;
  box-shadow: 0 12px 32px rgba(0, 0, 0, 0.55);
}
.locker-panel header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.4rem;
  margin-bottom: 0.4rem;
}
.locker-panel h3 {
  margin: 0;
  font-size: 0.85rem;
  color: #d8efff;
}
.locker-panel h4 {
  margin: 0 0 0.3rem;
  font-size: 0.7rem;
  color: #8ab8d8;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}
.locker-panel button {
  background: #102640;
  color: #d8efff;
  border: 1px solid #38648a;
  border-radius: 7px;
  cursor: pointer;
}
.locker-inventory-container {
  display: flex;
  flex-direction: column;
  gap: 0.3rem;
}
.locker-inventory-section {
  background: rgba(16, 38, 64, 0.6);
  border: 1px solid #2a4a6a;
  border-radius: 8px;
  padding: 0.45rem;
}
.locker-inventory-divider {
  text-align: center;
  font-size: 0.65rem;
  color: #6ea7d9;
  padding: 0.15rem 0;
}
.inventory-slots {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 4px;
}
.inventory-slot {
  position: relative;
  width: 100%;
  aspect-ratio: 1;
  border: 1px solid #2a4a6a;
  border-radius: 6px;
  background: rgba(10, 22, 38, 0.8);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.3rem;
  cursor: default;
  transition: border-color 0.15s, background 0.15s;
  user-select: none;
  -webkit-user-select: none;
}
.inventory-slot.occupied {
  cursor: pointer;
  border-color: #38648a;
}
.inventory-slot.occupied:hover {
  border-color: #8cc8ff;
  background: rgba(30, 60, 100, 0.7);
}
.inventory-slot.occupied:active {
  background: rgba(50, 90, 140, 0.7);
}
.inventory-slot .slot-label {
  position: absolute;
  bottom: 1px;
  left: 0;
  right: 0;
  text-align: center;
  font-size: 0.42rem;
  color: #8ab8d8;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  padding: 0 2px;
  line-height: 1.1;
}
.inventory-slot.empty-slot {
  border-style: dashed;
  border-color: #1e3450;
}
.inventory-slot.drag-over {
  border-color: #ffd166;
  background: rgba(255, 209, 102, 0.15);
}
.inventory-slot.dragging {
  opacity: 0.4;
}
.inventory-slot.selected-for-trade {
  border-color: #5aff5a;
  background: rgba(90, 255, 90, 0.15);
  box-shadow: 0 0 6px rgba(90, 255, 90, 0.3);
}

/* Inventory money display */
.inventory-money {
  font-size: 0.75rem;
  color: #ffd166;
  padding: 0.3rem 0.45rem;
  background: rgba(255, 209, 102, 0.08);
  border-radius: 6px;
  margin-bottom: 0.4rem;
}

/* Trade Panel */
.trade-panel[hidden] { display: none; }
.trade-panel {
  position: absolute;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  width: 580px;
  max-width: calc(100% - 1.2rem);
  max-height: calc(100% - 1.6rem);
  overflow: auto;
  border: 2px solid #6ea7d9;
  border-radius: 12px;
  background: rgba(7, 14, 25, 0.97);
  padding: 0.6rem;
  z-index: 52;
  box-shadow: 0 12px 32px rgba(0, 0, 0, 0.55);
}
.trade-panel header {
  display: flex; align-items: center; justify-content: space-between;
  gap: 0.4rem; margin-bottom: 0.4rem;
}
.trade-panel h3 { margin: 0; font-size: 0.85rem; color: #d8efff; }
.trade-panel h4 { margin: 0 0 0.3rem; font-size: 0.7rem; color: #8ab8d8; text-transform: uppercase; }
.trade-panel button { background: #102640; color: #d8efff; border: 1px solid #38648a; border-radius: 7px; cursor: pointer; }
.trade-container {
  display: flex;
  gap: 0.5rem;
  align-items: flex-start;
}
.trade-side {
  flex: 1;
  background: rgba(16, 38, 64, 0.6);
  border: 1px solid #2a4a6a;
  border-radius: 8px;
  padding: 0.45rem;
  min-width: 0;
}
.trade-side .inventory-slots {
  grid-template-columns: repeat(3, 1fr);
}
.trade-offer-area {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.35rem;
  min-width: 90px;
}
.trade-offer-section {
  text-align: center;
}
.trade-offer-slot {
  width: 52px;
  height: 52px;
  border: 2px dashed #38648a;
  border-radius: 8px;
  background: rgba(10, 22, 38, 0.8);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.5rem;
  margin: 0 auto;
  cursor: pointer;
  transition: border-color 0.15s;
}
.trade-offer-slot.has-item {
  border-style: solid;
  border-color: #5aff5a;
}
.trade-arrow { color: #6ea7d9; font-size: 1.1rem; }
.trade-money-offer {
  margin-top: 0.25rem;
  font-size: 0.7rem;
  color: #ffd166;
}
.trade-money-offer input {
  width: 40px;
  background: #0a1626;
  color: #ffd166;
  border: 1px solid #38648a;
  border-radius: 4px;
  padding: 0.15rem 0.25rem;
  font-size: 0.7rem;
  text-align: center;
}
.trade-submit-btn {
  width: 100%;
  padding: 0.4rem;
  font-size: 0.75rem;
  background: #1a4a2a !important;
  border-color: #3a8a4a !important;
  color: #aaffaa !important;
  font-weight: bold;
}
.trade-submit-btn:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}
.trade-submit-btn:not(:disabled):hover {
  background: #2a6a3a !important;
}
.trade-feedback {
  font-size: 0.65rem;
  color: #8ab8d8;
  text-align: center;
  margin: 0.2rem 0 0;
  min-height: 1em;
}

/* Fullscreen School Map */
.school-map-overlay {
  position: absolute;
  inset: 0;
  z-index: 55;
  background: rgba(5, 10, 18, 0.97);
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 0.6rem;
}
.school-map-overlay[hidden] { display: none; }
.school-map-overlay header {
  display: flex; align-items: center; justify-content: space-between;
  width: 100%; max-width: 920px; margin-bottom: 0.4rem;
}
.school-map-overlay h3 { margin: 0; font-size: 0.9rem; color: #d8efff; }
.school-map-overlay button { background: #102640; color: #d8efff; border: 1px solid #38648a; border-radius: 7px; cursor: pointer; padding: 0.25rem 0.5rem; }
#schoolMapCanvas {
  max-width: 100%;
  max-height: calc(100% - 4rem);
  border: 1px solid #2a4a6a;
  border-radius: 8px;
  background: #060a11;
}
.map-legend {
  display: flex;
  gap: 0.8rem;
  font-size: 0.65rem;
  color: #8ab8d8;
  margin: 0.4rem 0 0;
  flex-wrap: wrap;
  justify-content: center;
}
.legend-dot {
  display: inline-block;
  width: 10px;
  height: 10px;
  border-radius: 3px;
  vertical-align: middle;
  margin-right: 2px;
}

body.compact-mobile .trade-panel {
  width: 100%;
}
body.compact-mobile .trade-container {
  flex-direction: column;
}
body.compact-mobile .trade-side .inventory-slots {
  grid-template-columns: repeat(4, 1fr);
}

body.compact-mobile .locker-panel {
  width: 290px;
}
body.compact-mobile .inventory-slots {
  grid-template-columns: repeat(4, 1fr);
}

body.compact-mobile {
  overflow: hidden;
}

body.compact-mobile .topbar {
  flex-direction: column;
  align-items: stretch;
  gap: 0.45rem;
  padding: 0.35rem 0.5rem;
}

body.compact-mobile .topbar h1 {
  max-width: none;
  font-size: 0.8rem;
}

body.compact-mobile .hud {
  gap: 0.18rem 0.45rem;
  font-size: 0.67rem;
}

body.compact-mobile .top-controls {
  flex-wrap: wrap;
}

body.compact-mobile main {
  display: flex;
  flex-direction: column;
  gap: 0.45rem;
  padding: 0.45rem;
  overflow: hidden;
}

body.compact-mobile main > * {
  width: 100%;
  max-width: 100%;
}

body.compact-mobile .panel {
  display: none;
}

body.compact-mobile .canvas-wrap {
  flex: 1 1 auto;
  width: 100%;
  min-height: 0;
  padding: 0.3rem;
}

body.compact-mobile canvas {
  width: auto;
  height: auto;
  max-width: 100%;
  max-height: 100%;
  aspect-ratio: 1280 / 700;
}

body.compact-mobile .touch-hint {
  display: none !important;
}

body.compact-mobile .touch-controls {
  left: 0.4rem;
  right: 0.4rem;
  bottom: calc(0.4rem + env(safe-area-inset-bottom, 0px));
  gap: 0.45rem;
}

body.compact-mobile .touch-pad {
  grid-template-columns: repeat(3, minmax(2.35rem, 3.15rem));
  gap: 0.28rem;
}

body.compact-mobile .touch-camera {
  gap: 0.24rem;
}

body.compact-mobile .touch-actions {
  grid-template-columns: repeat(5, minmax(2.25rem, 1fr));
  gap: 0.28rem;
  max-width: min(24rem, 54vw);
}

body.compact-mobile .touch-btn {
  min-height: 2.35rem;
  border-radius: 11px;
  font-size: 0.66rem;
  padding: 0.2rem 0.32rem;
}

body.compact-mobile .touch-btn-camera {
  min-width: 2.8rem;
  min-height: 2.12rem;
  font-size: 0.92rem;
}

body.compact-mobile .touch-btn-camera-reset {
  min-width: 3.35rem;
  font-size: 0.62rem;
}

body.compact-mobile .class-question-panel {
  top: 0.45rem;
  right: 0.45rem;
  left: 0.45rem;
  width: auto;
  max-width: none;
  max-height: calc(100% - 0.9rem);
  padding: 0.45rem;
}

body.compact-mobile .interaction-panel {
  top: 0.45rem;
  right: 0.45rem;
  left: auto;
  width: min(15rem, calc(100% - 5.1rem));
  max-width: min(15rem, calc(100% - 5.1rem));
  max-height: min(10.8rem, calc(100% - 6.4rem));
  padding: 0.42rem;
}

body.compact-mobile .interaction-panel h3 {
  font-size: 0.74rem;
}

body.compact-mobile .interaction-panel p {
  font-size: 0.64rem;
}

body.compact-mobile .interaction-options button {
  padding: 0.3rem 0.34rem;
  font-size: 0.64rem;
}

body.compact-mobile #interactionHint {
  display: none;
}

body.compact-mobile .class-question-choices {
  grid-template-columns: 1fr;
}

body.compact-mobile .day-transition-card {
  width: min(92%, 360px);
  padding: 0.85rem 0.95rem;
}

body.compact-mobile .entity-tooltip {
  min-width: 0;
  max-width: min(12rem, calc(100% - 1rem));
}

.tooltip-meter {
  display: inline-block;
  width: 54px;
  height: 6px;
  border: 1px solid #6f8daa;
  border-radius: 999px;
  overflow: hidden;
  vertical-align: middle;
  margin-left: 0.2rem;
}
.tooltip-meter > span {
  display: block;
  height: 100%;
}
