/* ================================
   GLOBAL LAYOUT & BODY
================================ */
:root {
  --game-base-width: 960px;
  --game-base-height: 540px;
  --game-scale: 1;
}

html, body {
  height: 100%;
  margin: 0;
  padding: 0;
  background: #111;
  color: #fff;
  font-family: Arial, sans-serif;
  text-align: center;
  overflow-x: hidden;
  overflow-y: hidden;
}

body {
  margin: 0;
  padding: 0;
  background: #000;
  color: #fff;
  font-family: "Poppins", sans-serif;
  text-align: center;
  overflow-x: hidden;
}

/* ================================
   SHELL LAYOUT & AI TOGGLE
================================ */
#app-shell {
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 0;
  padding: 0;
  width: 100vw;
  height: 100vh;
  transition: all 250ms ease;
}

#main-column {
  width: 100%;
  height: 100%;
  max-width: none;
  position: relative;
}

#ai-toggle {
  position: fixed;
  top: 14px;
  right: 14px;
  z-index: 12000;
  background: #0d274a;
  color: #d0eaff;
  border: 2px solid #3ba4ff;
  border-radius: 10px;
  padding: 8px 12px;
  cursor: pointer;
  box-shadow: 0 0 12px #3ba4ff80;
  font-size: 18px;
}

#ai-toggle:hover {
  background: #123b6a;
}

/* ================================
   AI PANEL & CHATBOT
================================ */
#ai-panel {
  position: fixed;
  top: 60px;
  right: 14px;
  width: 36vw;
  max-width: 440px;
  min-width: 320px;
  height: calc(100vh - 80px);
  height: calc(100dvh - 80px);
  background: linear-gradient(180deg, #0a1a33, #0d274a, #123b6a);
  border: 2px solid #3ba4ff;
  border-radius: 22px;
  padding: 20px;
  box-sizing: border-box;
  box-shadow: 0 0 25px #3ba4ff80;
  display: flex;
  flex-direction: column;
  gap: 14px;
  overflow: hidden;
  transform: translateX(120%);
  opacity: 0;
  pointer-events: none;
  transition: transform 250ms ease, opacity 250ms ease;
  z-index: 11000;
}

body.panel-open #ai-panel {
  transform: translateX(0);
  opacity: 1;
  pointer-events: auto;
}

#ai-panel.collapsed {
  transform: translateX(120%);
  opacity: 0;
  pointer-events: none;
}

.ai-identity {
  display: grid;
  grid-template-columns: 1fr 1fr;
  align-items: stretch;
  gap: 12px;
  padding: 12px;
  background: rgba(255,255,255,0.06);
  border: 1px solid #3ba4ff;
  border-radius: 16px;
  box-shadow: inset 0 0 15px rgba(59,164,255,0.35);
  flex: 0 0 40%;
  min-height: 40%;
}

.ai-robot-wrap {
  display: flex;
  align-items: center;
  justify-content: flex-start;
  padding: 6px;
  background: rgba(0,0,0,0.25);
  border-radius: 12px;
}

#ai-robot {
  width: 86%;
  max-height: 100%;
  object-fit: contain;
  filter: drop-shadow(0 0 12px rgba(59,164,255,0.35));
}

.ai-identity.hidden {
  display: none;
}

.ai-meta {
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  gap: 10px;
  font-family: 'Iceberg', 'Poppins', sans-serif;
}

.ai-chip {
  background: linear-gradient(135deg, rgba(59,164,255,0.18), rgba(255,255,255,0.08));
  border: 1px solid rgba(59,164,255,0.7);
  border-radius: 12px;
  padding: 10px 12px;
  color: #d0eaff;
  box-shadow: inset 0 0 10px rgba(59,164,255,0.3);
}

.ai-chip-label {
  display: block;
  font-size: 12px;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: #8cc7ff;
}

.ai-chip-value {
  display: block;
  font-size: 18px;
  margin-top: 4px;
  color: #ffffff;
}

.ai-tabs-wrap {
  position: relative;
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 12px;
}

.ai-tab-nav {
  background: rgba(59,164,255,0.18);
  border: 1px solid rgba(59,164,255,0.7);
  color: #d0eaff;
  border-radius: 10px;
  width: 34px;
  height: 38px;
  cursor: pointer;
  box-shadow: inset 0 0 8px rgba(59,164,255,0.3);
}

.ai-tab-nav:hover {
  background: rgba(59,164,255,0.28);
}

.ai-tabs-scroll {
  overflow: hidden;
  flex: 1;
}

.ai-tabs {
  display: flex;
  gap: 8px;
  padding: 2px;
}

.ai-tab {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 10px 12px;
  background: linear-gradient(135deg, rgba(59,164,255,0.2), rgba(255,255,255,0.06));
  border: 1px solid rgba(59,164,255,0.7);
  border-radius: 12px;
  color: #d0eaff;
  cursor: pointer;
  font-weight: 600;
  transition: all 0.2s ease;
  white-space: nowrap;
}

.ai-tab .tab-icon {
  width: 18px;
  height: 18px;
  border-radius: 6px;
  background: rgba(255,255,255,0.12);
  box-shadow: inset 0 0 6px rgba(59,164,255,0.45);
  background-size: 90% 90%;
  background-repeat: no-repeat;
  background-position: center;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 12px;
  color: #d0eaff;
}

.ai-tab.active {
  background: linear-gradient(135deg, #3ba4ff, #74c2ff);
  color: #0a1a33;
  box-shadow: 0 0 12px #3ba4ff80, inset 0 0 10px rgba(255,255,255,0.35);
}

/* Tab-specific icons */
.ai-tab[data-tab="inventory"] .tab-icon {
  background-image: url("../../images/items/inventoryIcon.png");
}
.ai-tab[data-tab="notebook"] .tab-icon {
  background-image: url("../../images/items/chernobyl-knowledge-book.png");
}
.ai-tab[data-tab="chatbot"] .tab-icon {
  background-image: url("../../images/items/chatbotIcon.png");
}
.ai-tab[data-tab="leaderboard"] .tab-icon::before {
  content: "LB";
  font-size: 10px;
  font-weight: 700;
}
.ai-tab[data-tab="settings"] .tab-icon::before {
  content: "⚙";
}

.ai-tab:hover:not(.active) {
  box-shadow: 0 0 8px #3ba4ff60;
}

.ai-tab-panels {
  flex: 1 1 auto;
  display: flex;
  flex-direction: column;
  gap: 12px;
  margin-top: 0;
  min-height: 0;
}

.ai-tab-panel {
  display: none;
  flex: 1;
  min-height: 0;
}

.ai-tab-panel.active {
  display: flex;
}

#ai-panel .ai-tab-panel > * {
  flex: 1;
  min-height: 0;
}

#chatbot {
  flex: 1 1 70%;
  min-height: 0;
  display: flex;
  flex-direction: column;
  background: rgba(255,255,255,0.06);
  border: 1px solid #3ba4ff;
  border-radius: 16px;
  padding: 12px;
  box-sizing: border-box;
  gap: 10px;
  box-shadow: inset 0 0 10px rgba(59,164,255,0.35);
}

#chatbot.chatbot-embed {
  padding: 6px;
}

#chatbot.chatbot-embed #chtl-inline-bot {
  width: 100%;
  height: 100%;
  min-height: 520px;
}

#chatbot.chatbot-embed iframe {
  width: 100%;
  height: 100%;
  min-height: 520px;
  border: 0;
}

#chatbot.chat-hidden {
  display: none;
}

#chat-output {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
  gap: 8px;
  overflow-y: auto;
  background: rgba(255,255,255,0.08);
  padding: 10px;
  border-radius: 12px;
  color: #d0eaff;
  font-size: 15px;
  line-height: 1.4;
  white-space: pre-wrap;
  word-break: break-word;
}

#chat-output .chat-line {
  background: rgba(255,255,255,0.05);
  padding: 6px 8px;
  border-radius: 8px;
}

/* Leaderboard */
.leaderboard {
  flex: 1 1 55%;
  min-height: 0;
  display: flex;
  flex-direction: column;
  gap: 10px;
  background: rgba(255,255,255,0.06);
  border: 1px solid #3ba4ff;
  border-radius: 16px;
  padding: 12px;
  box-sizing: border-box;
  box-shadow: inset 0 0 10px rgba(59,164,255,0.35);
  color: #d0eaff;
}

.leaderboard-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.leaderboard-title {
  font-size: 18px;
  font-weight: 700;
}

.leaderboard-subtitle {
  font-size: 13px;
  color: rgba(208,234,255,0.8);
}

.leaderboard-meta {
  font-size: 12px;
  color: rgba(208,234,255,0.7);
}

.leaderboard-list {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding-right: 4px;
}

.leaderboard-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  background: rgba(255,255,255,0.05);
  border-radius: 10px;
  padding: 8px 10px;
  border: 1px solid rgba(59,164,255,0.3);
}

.leaderboard-rank {
  width: 24px;
  height: 24px;
  border-radius: 8px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: rgba(59,164,255,0.25);
  font-weight: 700;
  color: #d0eaff;
}

.leaderboard-name {
  font-weight: 700;
}

.leaderboard-role {
  font-size: 12px;
  color: rgba(208,234,255,0.75);
}

.leaderboard-points {
  font-weight: 700;
  color: #9fe2ff;
}

#chat-output .chat-line.user {
  background: rgba(59,164,255,0.12);
}

#chat-output .chat-line.error {
  color: #ffb2b2;
}

#chat-output .chat-line strong {
  color: #74c2ff;
}

#chat-output .chat-line.notice {
  background: rgba(59,164,255,0.10);
  border: 1px dashed rgba(59,164,255,0.55);
}

#chat-output .chat-link {
  appearance: none;
  border: none;
  background: transparent;
  padding: 0;
  margin: 0;
  color: #3ba4ff;
  text-decoration: underline;
  cursor: pointer;
  font: inherit;
}

#chat-output .chat-link:hover {
  color: #74c2ff;
}

.chatbot-modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.6);
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 20000;
  padding: 18px;
}

.chatbot-modal-overlay.show {
  display: flex;
}

.chatbot-modal {
  width: min(520px, 92vw);
  background: linear-gradient(180deg, #0a1a33, #0d274a, #123b6a);
  border: 2px solid #3ba4ff;
  border-radius: 16px;
  box-shadow: 0 0 25px rgba(59, 164, 255, 0.5);
  color: #d0eaff;
  text-align: left;
  overflow: hidden;
}

.chatbot-modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 14px;
  border-bottom: 1px solid rgba(59,164,255,0.45);
  background: rgba(0,0,0,0.18);
}

.chatbot-modal-title {
  font-weight: 700;
  letter-spacing: 0.02em;
}

.chatbot-modal-close {
  width: 36px;
  height: 36px;
  border-radius: 10px;
  border: 1px solid rgba(59,164,255,0.6);
  background: rgba(59,164,255,0.12);
  color: #d0eaff;
  cursor: pointer;
  font-size: 20px;
  line-height: 1;
}

.chatbot-modal-body {
  padding: 14px;
  line-height: 1.5;
}

.chatbot-modal-text {
  margin-bottom: 12px;
}

.chatbot-help {
  background: rgba(255,255,255,0.06);
  border: 1px solid rgba(59,164,255,0.35);
  border-radius: 12px;
  padding: 12px;
}

.chatbot-help-title {
  font-weight: 700;
  margin-bottom: 4px;
}

.chatbot-help-subtitle {
  opacity: 0.85;
  font-size: 13px;
  margin-bottom: 10px;
}

.chatbot-help-search {
  width: 100%;
  padding: 10px;
  border-radius: 10px;
  border: 1px solid rgba(59,164,255,0.6);
  background: #0b1d36;
  color: #ffffff;
  font-size: 14px;
  box-sizing: border-box;
}

.chatbot-help-meta {
  margin-top: 8px;
  font-size: 12px;
  opacity: 0.85;
}

.chatbot-help-list {
  margin-top: 10px;
  max-height: 260px;
  overflow: auto;
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding-right: 4px;
}

.chatbot-help-item {
  text-align: left;
  border: 1px solid rgba(59,164,255,0.35);
  background: rgba(0,0,0,0.18);
  color: #d0eaff;
  padding: 10px 10px;
  border-radius: 10px;
  cursor: pointer;
  font: inherit;
}

.chatbot-help-item:hover {
  border-color: rgba(59,164,255,0.75);
  background: rgba(59,164,255,0.12);
}

.chatbot-modal-footer {
  display: flex;
  justify-content: flex-end;
  padding: 12px 14px 14px;
  border-top: 1px solid rgba(59,164,255,0.35);
}

.chatbot-modal-ok {
  border: none;
  border-radius: 10px;
  background: #3ba4ff;
  color: #071017;
  font-weight: 700;
  padding: 10px 14px;
  cursor: pointer;
  box-shadow: 0 0 10px rgba(59,164,255,0.5);
}

#chat-input {
  width: 100%;
  padding: 10px;
  border-radius: 10px;
  border: 1px solid #3ba4ff;
  background: #0b1d36;
  color: #ffffff;
  font-size: 14px;
  margin-top: 5px;
  box-sizing: border-box;
}

#chat-send {
  width: 100%;
  padding: 12px;
  border: none;
  border-radius: 10px;
  background: #3ba4ff;
  color: black;
  font-weight: bold;
  font-size: 16px;
  cursor: pointer;
  box-shadow: 0 0 10px #3ba4ff80;
}

#chat-send:hover {
  background: #6ac2ff;
}

/* ================================
   DEVICE SELECTION (POST START)
================================ */
.device-select-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.92);
  z-index: 13000;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 18px;
}

.device-select-modal {
  width: min(760px, 94vw);
  border: 2px solid rgba(59,164,255,0.6);
  border-radius: 18px;
  background: linear-gradient(180deg, rgba(10,26,51,0.92), rgba(13,39,74,0.92));
  box-shadow: 0 0 28px rgba(59,164,255,0.35);
  padding: 18px;
  text-align: center;
}

.device-select-title {
  font-family: 'Iceberg', 'Poppins', sans-serif;
  font-size: 28px;
  color: #d0eaff;
  margin-bottom: 14px;
}

.device-select-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 14px;
}

@media (max-width: 720px) {
  .device-select-grid {
    grid-template-columns: 1fr;
  }
}

.device-card {
  border: 1px solid rgba(59,164,255,0.55);
  border-radius: 16px;
  background: rgba(255,255,255,0.06);
  padding: 16px;
  display: grid;
  gap: 10px;
  justify-items: center;
}

.device-icon {
  width: 76px;
  height: 76px;
  border-radius: 18px;
  display: grid;
  place-items: center;
  color: #74c2ff;
  background: rgba(59,164,255,0.10);
  border: 1px solid rgba(59,164,255,0.35);
  box-shadow: inset 0 0 14px rgba(59,164,255,0.20);
}

.device-name {
  font-weight: 800;
  font-size: 18px;
  color: #ffffff;
}

.device-desc {
  font-size: 13px;
  opacity: 0.85;
  color: #d0eaff;
}

.device-choose {
  width: 160px;
  padding: 12px;
  border: none;
  border-radius: 12px;
  background: #3ba4ff;
  color: #071017;
  font-weight: 800;
  cursor: pointer;
  box-shadow: 0 0 12px rgba(59,164,255,0.45);
}

.device-choose:hover {
  background: #6ac2ff;
}

/* ================================
   MOBILE JOYSTICK
================================ */
#mobile-joystick {
  position: fixed;
  left: 18px;
  bottom: 18px;
  width: 140px;
  height: 140px;
  z-index: 12500;
  display: none;
  pointer-events: none; /* enabled state turns pointer-events on */
}

#mobile-joystick.side-right {
  left: auto;
  right: 18px;
}

#mobile-joystick.enabled {
  display: block;
  pointer-events: auto;
}

#mobile-joystick .joystick-base {
  position: absolute;
  left: 0;
  top: 0;
  width: 140px;
  height: 140px;
  border-radius: 999px;
  background: rgba(255,255,255,0.08);
  border: 2px solid rgba(255,255,255,0.18);
  box-shadow: inset 0 0 18px rgba(0,0,0,0.35);
  touch-action: none; /* prevents scroll while dragging */
}

#mobile-joystick .joystick-stick {
  position: absolute;
  left: 50%;
  top: 50%;
  width: 70px;
  height: 70px;
  margin-left: -35px;
  margin-top: -35px;
  border-radius: 999px;
  background: rgba(59,164,255,0.22);
  border: 2px solid rgba(59,164,255,0.55);
  box-shadow: 0 0 14px rgba(59,164,255,0.25);
  transform: translate(0, 0);
}

h1 {
  position: fixed;
  left: 50%;
  top: 10px;
  transform: translateX(-50%);
  margin: 0;
  padding: 0;
  font-size: 20px;
  opacity: 0.75;
  pointer-events: none;
  z-index: 2000;
}

/* ================================
   GAME STAGE (SCALED)
================================ */
#game-frame {
  position: absolute;
  left: 50%;
  top: 50%;
  width: var(--game-base-width);
  height: var(--game-base-height);
  transform: translate(-50%, -50%) scale(var(--game-scale));
  transform-origin: center;
  overflow: hidden;
  background: #000;
}

/* ================================
   SCENES
================================ */
.scene {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  display: none;
  opacity: 0;
  transition: opacity 300ms ease;
}

.scene.active {
  display: block;
  opacity: 1;
}

/* ================================
   MAIN GAME CONTAINERS
================================ */
.chernobyl-container,
.reactor-container,
.greatwall-container,
.furtrade-container {
  margin: 0;
  width: 100%;
  height: 100%;
  position: relative;
  border: 2px solid #444;
  background: #222;
  overflow: hidden;
}

/* ================================
   FUR TRADE (SIGNS, NPC, CHEST, PANELS)
================================ */
.furtrade-sign,
.furtrade-chest,
.furtrade-npc {
  position: absolute;
  left: var(--x, 0px);
  top: var(--y, 0px);
  width: var(--w, 64px);
  height: var(--h, 64px);
  border: none;
  background-color: transparent;
  background-repeat: no-repeat;
  background-position: center;
  background-size: 100% 100%;
  image-rendering: pixelated;
  cursor: pointer;
  padding: 0;
  z-index: 3;
}

.furtrade-sign:focus-visible,
.furtrade-chest:focus-visible,
.furtrade-npc:focus-visible {
  outline: 3px solid rgba(255, 255, 255, 0.85);
  outline-offset: 2px;
}

.furtrade-sign {
  background-image: url("../../images/furtrade/sign.png");
}

.furtrade-chest {
  background-image: url("../../images/furtrade/chest-closed.png");
}

.furtrade-chest.open {
  background-image: url("../../images/furtrade/chest-open.png");
}

.furtrade-npc {
  background-image: url("../../images/furtrade/kuukpak.png");
}

.furtrade-overlay {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(0, 0, 0, 0.55);
  z-index: 9000;
}

.furtrade-panel {
  width: min(760px, 92%);
  max-height: min(440px, 86%);
  display: flex;
  flex-direction: column;
  border: 6px solid #2a1a0f;
  box-shadow: 0 16px 0 rgba(0, 0, 0, 0.35);
  background-color: #e7caa6;
  background-image: url("../../images/ui/wood-light.svg");
  background-size: 32px 32px;
  image-rendering: pixelated;
  color: #000;
  font-family: "Poppins", system-ui, -apple-system, Arial, sans-serif;
}

.furtrade-panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 10px 12px;
  border-bottom: 4px solid rgba(42, 26, 15, 0.75);
  background: rgba(255, 255, 255, 0.06);
}

.furtrade-panel-title {
  font-weight: 800;
  font-size: 18px;
  letter-spacing: 0.02em;
}

.furtrade-panel-close {
  appearance: none;
  border: 3px solid #2a1a0f;
  background: rgba(255, 255, 255, 0.12);
  color: #000;
  width: 40px;
  height: 34px;
  border-radius: 8px;
  font-size: 20px;
  line-height: 1;
  cursor: pointer;
}

.furtrade-panel-close:hover {
  background: rgba(255, 255, 255, 0.22);
}

.furtrade-panel-body {
  padding: 14px 14px 10px;
  overflow: auto;
}

.furtrade-panel-text {
  font-size: 16px;
  line-height: 1.35;
  text-align: left;
  white-space: pre-wrap;
}

.furtrade-panel-footer {
  padding: 12px 14px 14px;
  border-top: 4px solid rgba(42, 26, 15, 0.35);
}

.furtrade-trade-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.furtrade-trade-btn {
  appearance: none;
  border: 3px solid #2a1a0f;
  background: rgba(255, 255, 255, 0.14);
  color: #000;
  border-radius: 12px;
  padding: 10px;
  cursor: pointer;
  display: grid;
  grid-template-columns: 1fr;
  gap: 8px;
}

.furtrade-trade-btn:hover {
  background: rgba(255, 255, 255, 0.22);
}

.furtrade-trade-icons {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
}

.furtrade-trade-arrow {
  font-weight: 900;
  font-size: 16px;
}

.furtrade-trade-label {
  font-weight: 700;
  font-size: 13px;
  opacity: 0.9;
}

.furtrade-trade-status {
  margin-top: 10px;
  font-size: 14px;
  text-align: left;
  opacity: 0.9;
}

/* ================================
   OFF SCHOOL: EGYPT TIC TAC TOE
================================ */
.offschool-ttt-container {
  margin: 0;
  width: 100%;
  height: 115;
  position: relative;
  border: 2px solid #444;
  display: flex;
  align-items: center;
  justify-content: center;
  background:
    radial-gradient(120% 120% at 50% 0%, rgba(255, 246, 214, 0.9) 0%, rgba(227, 192, 140, 0.85) 55%, rgba(171, 120, 62, 0.9) 100%),
    linear-gradient(135deg, rgba(83, 52, 23, 0.35), rgba(140, 92, 45, 0.2));
  overflow: hidden;
}

.ttt-frame {
  width: min(760px, 92%);
  padding: 18px 20px 22px;
  border: 6px solid #3a2414;
  border-radius: 16px;
  background-color: #e7caa6;
  background-image: url("../../images/ui/wood-light.svg");
  background-size: 36px 36px;
  image-rendering: pixelated;
  box-shadow: 0 18px 0 rgba(0, 0, 0, 0.3);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
}

.ttt-title {
  font-family: "Cinzel", "Garamond", serif;
  font-size: 20px;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: #2a1a0f;
  text-align: center;
}

.ttt-status {
  font-family: "Cinzel", "Garamond", serif;
  font-size: 14px;
  color: rgba(42, 26, 15, 0.85);
  text-align: center;
  min-height: 18px;
}

.ttt-board {
  width: min(420px, 78vw);
  aspect-ratio: 1 / 1;
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  grid-template-rows: repeat(3, 1fr);
  gap: 10px;
  padding: 12px;
  border-radius: 12px;
  border: 4px solid #3a2414;
  background: linear-gradient(145deg, rgba(112, 72, 34, 0.6), rgba(165, 112, 60, 0.7));
  box-shadow: inset 0 0 0 2px rgba(255, 255, 255, 0.1);
}

.ttt-cell {
  appearance: none;
  border: 3px solid #2a1a0f;
  border-radius: 10px;
  background: linear-gradient(160deg, rgba(241, 214, 172, 0.95), rgba(190, 140, 82, 0.9));
  box-shadow: inset 0 2px 6px rgba(0, 0, 0, 0.2);
  font-family: "Cinzel", "Garamond", serif;
  font-size: clamp(28px, 6vw, 64px);
  font-weight: 700;
  color: #3a2414;
  cursor: pointer;
}

.ttt-cell:disabled {
  cursor: default;
  opacity: 0.9;
}

.ttt-cell.is-x {
  color: #5b2f16;
}

.ttt-cell.is-o {
  color: #1f3a2c;
}

.ttt-cell.win {
  box-shadow: 0 0 0 2px rgba(255, 225, 160, 0.7), inset 0 0 10px rgba(255, 230, 180, 0.6);
  background: linear-gradient(160deg, rgba(255, 236, 194, 0.95), rgba(208, 155, 92, 0.9));
}

.ttt-reset {
  margin-top: 4px;
  appearance: none;
  border: 3px solid #2a1a0f;
  border-radius: 10px;
  padding: 8px 14px;
  background: rgba(255, 255, 255, 0.2);
  font-family: "Cinzel", "Garamond", serif;
  font-weight: 700;
  letter-spacing: 0.02em;
  color: #2a1a0f;
  cursor: pointer;
}

.ttt-reset:hover {
  background: rgba(255, 255, 255, 0.35);
}

/* Reactor scene background color fix */
#scene-reactor {
  background: #000;
}

/* ================================
   SCHOOL SCENE
================================ */
.school-container {
  position: relative;
  width: 100%;
  height: 100%;
  margin: 0;
  border: 2px solid #444;
  background: #111;
  overflow: hidden;
}

#schoolCanvas {
  width: 100%;
  height: 100%;
  display: block;
}

.school-label {
  position: absolute;
  padding: 4px 10px;
  background: rgba(0,0,0,0.7);
  color: #fff;
  border-radius: 6px;
  font-size: 14px;
  pointer-events: none;
  display: none; /* labels hidden because signage is baked into hallway art */
}
.door-btn,
.room-back-btn,
.portal-btn {
  position: absolute;
  background: rgba(0,0,0,0.65);
  color: #fff;
  border: 1px solid #555;
  border-radius: 8px;
  padding: 8px 10px;
  cursor: pointer;
  font-size: 13px;
  box-shadow: 0 0 8px rgba(0,0,0,0.4);
  transition: transform 120ms ease, background 120ms ease;
  z-index: 6;
}
.door-btn:hover,
.room-back-btn:hover,
.portal-btn:hover {
  background: rgba(0,0,0,0.8);
  transform: translateY(-1px);
}
.door-btn.history { left: 110px; top: 320px; }
.door-btn.supply  { left: 420px; top: 320px; }
.door-btn.social  { left: 730px; top: 320px; }
.room-back-btn    { left: 12px; top: 12px; display: none; }
.portal-btn       { left: 700px; top: 280px; display: none; opacity: 0; background: rgba(255,0,255,0.25); border: 2px dashed rgba(255,0,255,0.8); box-shadow: 0 0 10px rgba(255,0,255,0.6); width: 140px; height: 160px; z-index: 9999; }

.room-action {
  position: absolute;
  background: rgba(0,0,0,0.65);
  color: #fff;
  border: 1px solid #555;
  border-radius: 8px;
  padding: 8px 10px;
  cursor: pointer;
  font-size: 13px;
  box-shadow: 0 0 8px rgba(0,0,0,0.4);
  transition: transform 120ms ease, background 120ms ease;
  z-index: 6;
}
.room-action:hover { background: rgba(0,0,0,0.8); transform: translateY(-1px); }
.room-action.teacher { left: 415px; top: 280px; }
.room-action.whiteboard { left: 580px; top: 140px; }
.room-action.bluebook { left: 835px; top: 300px; }

.lesson-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.75);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 12000;
}

.lesson-frame {
  position: relative;
  width: 900px;
  max-width: 95vw;
  aspect-ratio: 16/9;
  background: #000;
  overflow: hidden;
  border-radius: 18px;
  box-shadow: 0 0 30px rgba(0,0,0,0.6);
}
.lesson-frame.presentation {
  background: #f1e2c2;
}

.lesson-border {
  position: absolute;
  inset: 0;
  pointer-events: none;
  z-index: 4;
  opacity: 0.6;
  mix-blend-mode: multiply;
}

.lesson-image {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: contain;
  z-index: 2;
  filter: saturate(1.1);
}

.lesson-text {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  padding: 18px;
  background: linear-gradient(180deg, transparent, rgba(0,0,0,0.75));
  color: #fff;
  font-size: 18px;
  line-height: 1.4;
  z-index: 5;
  text-align: center;
}
.lesson-text.presentation {
  font-size: 20px;
  line-height: 1.4;
  max-width: 88%;
  margin: 0 auto 12px;
  color: #1f1b14;
  background: none;
  text-shadow: none;
  top: 20%;
  bottom: auto;
  transform: translateY(-10%);
}

/* Portal animation overlay */
.portal-overlay {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  pointer-events: none;
  z-index: 15000;
}
.portal-black {
  position: absolute;
  inset: 0;
  background: #000;
  opacity: 1;
  transition: opacity 0.4s ease;
}
.portal-black.fade-out { opacity: 0; }
.portal-ring {
  position: relative;
  width: 220px;
  height: 280px;
  background-repeat: no-repeat;
  background-size: contain;
  background-position: center;
  opacity: 1;
  transform: scale(0.4);
}
.portal-ring.expand {
  animation: portalExpand 1.6s cubic-bezier(0.35, 0, 0.7, 1) forwards;
}
.portal-loading {
  position: absolute;
  bottom: 18%;
  left: 50%;
  transform: translateX(-50%);
  color: #fff;
  font-size: 22px;
  letter-spacing: 0.08em;
  opacity: 0;
  transition: opacity 0.3s ease;
}
.portal-loading.show { opacity: 1; }
@keyframes portalExpand {
  from { transform: scale(0.4); }
  50% { transform: scale(3); }
  70% { transform: scale(8); }
  to   { transform: scale(18); }
}

.lesson-close {
  position: absolute;
  top: 12px;
  right: 12px;
  background: rgba(0,0,0,0.65);
  color: #fff;
  border: 1px solid #777;
  border-radius: 8px;
  padding: 6px 10px;
  cursor: pointer;
  z-index: 4;
}

.test-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.75);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 12000;
}

.test-modal {
  width: 900px;
  max-width: 95vw;
  max-height: 90vh;
  background: #0f1b2f;
  color: #e8f2ff;
  border: 2px solid #3ba4ff;
  border-radius: 16px;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  box-shadow: 0 0 25px rgba(59,164,255,0.35);
}

.test-body {
  padding: 16px;
  overflow-y: auto;
  display: grid;
  gap: 12px;
}

.test-footer {
  padding: 12px 16px;
  border-top: 1px solid rgba(255,255,255,0.1);
  display: flex;
  justify-content: flex-end;
  gap: 10px;
}

.test-btn {
  background: #3ba4ff;
  color: #0a1a33;
  border: none;
  border-radius: 8px;
  padding: 10px 14px;
  font-weight: 700;
  cursor: pointer;
}

.test-btn.secondary {
  background: #1f2d44;
  color: #d7e9ff;
  border: 1px solid #3ba4ff;
}

.whiteboard-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.65);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 12000;
}

.whiteboard-modal {
  background: #f6f6f6;
  border-radius: 12px;
  padding: 12px;
  box-shadow: 0 0 18px rgba(0,0,0,0.4);
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.whiteboard-canvas {
  background: #fff;
  border: 1px solid #ccc;
  border-radius: 10px;
  cursor: crosshair;
}
.school-label.history { left: 70px; top: 230px; }
.school-label.social  { right: 70px; top: 230px; }
.school-label.supply  { left: 50%; transform: translateX(-50%); top: 40px; }

/* ================================
   MAP SCREEN
================================ */
.map-container {
  position: relative;
  width: 100%;
  height: 100%;
  display: block;
}

.map {
  width: 100%;
  height: 100%;
  object-fit: cover;
  border: 2px solid #444;
}

.map-btn {
  position: absolute;
  background: rgba(0,0,0,0.7);
  color: white;
  border: none;
  border-radius: 6px;
  padding: 4px 8px;
  cursor: pointer;
}
.map-btn.return-btn {
  bottom: 12px;
  left: 12px;
}

/* ================================
   QUESTION MARKS & INTERACTIVES
================================ */
.qmark {
  position: absolute;
  width: 26px;
  height: 26px;
  border-radius: 50%;
  border: none;
  background: #000;
  color: white;
  font-weight: bold;
  cursor: pointer;
}

.qmark:hover {
  background: #333;
}

.glow {
  box-shadow: 0 0 12px 4px rgba(255, 255, 255, 0.7);
  animation: pulse 1.6s infinite alternate;
}

@keyframes pulse {
  from { box-shadow: 0 0 12px 4px rgba(255,255,255,0.7); }
  to   { box-shadow: 0 0 20px 8px rgba(255,255,255,0.3); }
}

/* ================================
   DIALOG BOXES
================================ */
.dialog {
  position: absolute;
  left: 50%;
  transform: translateX(-50%);
  bottom: 14px;
  width: calc(100% - 60px);
  max-width: 640px;
  background: rgba(0,0,0,0.9);
  padding: 12px;
  border-radius: 8px;
  border: 1px solid #333;
  display: none;
  color: #fff;
  z-index: 10;
}

/* ================================
   BACK BUTTON
================================ */
.back-btn {
  position: absolute;
  top: 8px;
  left: 8px;
  background: #444;
  padding: 6px 8px;
  border: none;
  color: #fff;
  border-radius: 6px;
  cursor: pointer;
  z-index: 10;
}

.back-btn:hover {
  background: #666;
}

/* ================================
   REACTOR LAYERING
================================ */
#reactorCanvas {
  position: absolute;
  top: 0;
  left: 0;
  z-index: 1;
}
#reactor-qmark,
#back-to-chernobyl,
#reactor-dialog {
  position: absolute;
  z-index: 2;
}

/* ================================
   INVENTORY POPUP
================================ */
.inventory {
  position: relative;
  width: 100%;
  height: 100%;
  max-height: none;
  overflow-y: auto;
  background: rgba(12, 24, 44, 0.55);
  border: 1px solid rgba(59,164,255,0.6);
  border-radius: 12px;
  padding: 14px;
  box-shadow: inset 0 0 12px rgba(0,0,0,0.45);
  z-index: 1;
  box-sizing: border-box;
}

.inventory h2 {
  margin: 0 0 10px;
  color: #d0eaff;
}

.inventory-item {
  display: flex;
  align-items: center;
  background: rgba(255,255,255,0.05);
  padding: 8px;
  margin-bottom: 8px;
  border-radius: 10px;
  border: 1px solid rgba(59,164,255,0.35);
  box-shadow: inset 0 0 8px rgba(59,164,255,0.25);
}

.inventory-item.active {
  border-color: rgba(59,164,255,0.85);
  box-shadow: 0 0 10px rgba(59,164,255,0.35), inset 0 0 8px rgba(59,164,255,0.25);
}

.inventory-item.active img {
  width: 48px;
  height: 48px;
}

.inventory-item img {
  width: 40px;
  height: 40px;
  margin-right: 10px;
  filter: drop-shadow(0 0 4px rgba(59,164,255,0.35));
}

/* ================================
   FADE OVERLAY
================================ */
.fade-overlay {
  position: fixed;
  top: 0; left: 0; right: 0; bottom: 0;
  background: #000;
  opacity: 0;
  pointer-events: none;
  transition: opacity 1.5s ease;
  z-index: 3000;
}
.fade-overlay.active {
  opacity: 1;
  pointer-events: auto;
}

/* ================================
   NOTEBOOK
================================ */
#notebook {
  position: relative;
  width: 100%;
  height: 100%;
  display: flex;
  justify-content: center;
  align-items: stretch;
  color: black;
}

.notebook-frame {
  width: 100%;
  height: 100%;
  background: #6d4c31;
  border: 10px solid #3e2717;
  border-radius: 12px;
  box-shadow: inset 0 0 18px rgba(0, 0, 0, 0.7);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  box-sizing: border-box;
}

.notebook-tabs {
  display: flex;
  justify-content: center;
  gap: 10px;
  background: #cfa867;
  padding: 8px;
}

.notebook-tabs button {
  background: #e4c075;
  border: 2px solid #8a6b2d;
  padding: 6px 14px;
  border-radius: 8px;
  font-weight: bold;
  cursor: pointer;
  transition: background 0.2s ease;
}

.notebook-tabs button:hover {
  background: #f1d492;
}

.active-tab {
  background: #ffebaf !important;
  border-color: #b68d37 !important;
}

.notebook-paper {
  flex: 1;
  background: #fff5d5;
  margin: 10px;
  border-radius: 10px;
  padding: 20px;
  overflow-y: auto;
  box-shadow: inset 0 0 10px rgba(0,0,0,0.15);
}

.notebook-section {
  display: none;
}

.notebook-section.active {
  display: block;
}

.book-grid {
  display: flex;
  gap: 20px;
  justify-content: center;
  margin-bottom: 15px;
}

.book-slot {
  text-align: center;
  cursor: pointer;
}

.book-slot img {
  width: 64px;
  height: 64px;
}

.book-slot.locked {
  opacity: 0.4;
  pointer-events: none;
}

.book-text {
  margin-top: 10px;
  line-height: 1.4;
}

#noteArea {
  width: 100%;
  height: 260px;
  background: #fff5d5;
  border: 2px solid #a38546;
  border-radius: 8px;
  padding: 10px;
  resize: none;
  font-family: 'Courier New', monospace;
}

.settings-placeholder {
  width: 100%;
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  color: #d0eaff;
  background: rgba(255,255,255,0.05);
  border: 1px dashed rgba(59,164,255,0.6);
  border-radius: 12px;
  box-shadow: inset 0 0 10px rgba(59,164,255,0.25);
}

.settings-panel {
  width: 100%;
  height: 100%;
  display: flex;
  flex-direction: column;
  gap: 16px;
  background: rgba(255,255,255,0.04);
  border: 1px solid rgba(59,164,255,0.35);
  border-radius: 12px;
  padding: 12px;
  box-sizing: border-box;
  box-shadow: inset 0 0 10px rgba(0,0,0,0.25);
}

.settings-section {
  display: flex;
  flex-direction: column;
  gap: 6px;
  color: #d0eaff;
}

.settings-label {
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  font-size: 13px;
  color: #e5f2ff;
}

.other-controls {
  font-size: 13px;
  color: #cfe8ff;
  padding: 8px 10px;
  background: rgba(255,255,255,0.04);
  border: 1px solid rgba(59,164,255,0.2);
  border-radius: 10px;
}

.control-picker {
  display: flex;
  align-items: center;
  gap: 10px;
  background: rgba(255,255,255,0.05);
  border: 1px solid rgba(59,164,255,0.4);
  border-radius: 12px;
  padding: 8px 10px;
}

.control-arrow {
  background: rgba(59,164,255,0.18);
  border: 1px solid rgba(59,164,255,0.6);
  color: #d0eaff;
  border-radius: 8px;
  width: 34px;
  height: 34px;
  cursor: pointer;
  box-shadow: inset 0 0 8px rgba(59,164,255,0.3);
}

.control-arrow:hover {
  background: rgba(59,164,255,0.28);
}

.control-display {
  flex: 1;
  text-align: center;
  font-weight: 600;
}

.volume-control {
  display: flex;
  align-items: center;
  gap: 10px;
}

#music-volume {
  flex: 1;
  accent-color: #3ba4ff;
}

#music-volume-value {
  min-width: 48px;
  text-align: right;
}

.changelog-button {
  background: linear-gradient(135deg, rgba(59,164,255,0.25), rgba(255,255,255,0.08));
  border: 1px solid rgba(59,164,255,0.7);
  color: #d0eaff;
  padding: 10px 14px;
  border-radius: 10px;
  cursor: pointer;
  font-weight: 600;
  box-shadow: inset 0 0 8px rgba(59,164,255,0.35);
}

.changelog-button:hover {
  background: linear-gradient(135deg, rgba(59,164,255,0.35), rgba(255,255,255,0.12));
}

.changelog-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.65);
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 11000;
}

.changelog-overlay.show {
  display: flex;
}

.changelog-modal {
  width: 640px;
  max-width: 90vw;
  max-height: 80vh;
  background: #0d1c33;
  border: 2px solid #3ba4ff;
  border-radius: 14px;
  box-shadow: 0 0 25px rgba(59,164,255,0.35);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.changelog-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 16px;
  background: linear-gradient(135deg, rgba(59,164,255,0.25), rgba(255,255,255,0.06));
  color: #d0eaff;
  font-weight: 700;
  letter-spacing: 0.04em;
}

.changelog-close {
  background: rgba(255,255,255,0.08);
  border: 1px solid rgba(59,164,255,0.6);
  color: #d0eaff;
  border-radius: 8px;
  width: 34px;
  height: 34px;
  cursor: pointer;
}

.changelog-body {
  padding: 16px;
  overflow-y: auto;
  color: #e8f2ff;
  line-height: 1.4;
  display: grid;
  gap: 10px;
}

.changelog-version {
  padding: 10px;
  border: 1px solid rgba(59,164,255,0.3);
  border-radius: 10px;
  background: rgba(255,255,255,0.04);
}

.changelog-version h4 {
  margin: 0 0 6px;
  color: #99d2ff;
}

.changelog-version ul {
  margin: 0;
  padding-left: 18px;
}
/* ================================
   GREAT WALL ANIMATION
================================ */
#wall-animation {
  position: relative;
  width: 100%;
  height: 100%;
}

#wall-frame {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  opacity: 0;
  transition: opacity 1s ease-in-out;
  z-index: 1;
}

#wall-dialog {
  z-index: 2;
}

#wall-animation {
  position: relative;
  width: 960px;
  height: 540px;
}

#wall-frame {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  opacity: 0;
  transition: opacity 1s ease-in-out;
  z-index: 1;
}

#wall-dialog {
  position: absolute;
  bottom: 20px;
  left: 50%;
  transform: translateX(-50%);
  background: rgba(0, 0, 0, 0.85);
  color: #fff;
  padding: 12px 20px;
  border-radius: 10px;
  max-width: 80%;
  font-size: 1.1em;
  text-align: center;
  opacity: 0;
  transition: opacity 1s ease-in-out;
  line-height: 1.4em;
  z-index: 2;
}

/* Raise Great Wall animation frame */
#scene-greatwall-animation .greatwall-container {
  margin-top: -10px;
}

/* ---------- GLOBAL DIALOG BOX (DUPLICATE) ---------- */
.dialog {
  position: absolute;
  bottom: 400 px; /* ← raise it up (try values 60–120) */
  left: 50%;
  transform: translateX(-50%);
  width: 80%;
  padding: 14px 20px;
  background: rgba(0, 0, 0, 0.85);
  color: #fff;
  font-family: "Poppins", sans-serif;
  font-size: 18px;
  border-radius: 10px;
  border: 2px solid rgba(255,255,255,0.3);
  text-align: center;
  z-index: 9999;
  display: none;
  pointer-events: none;
  box-shadow: 0 0 20px rgba(0,0,0,0.6);
}

.dialog.show {
  display: block;
  animation: fadeIn 0.25s ease forwards;
}

@keyframes fadeIn {
  from { opacity: 0; transform: translate(-50%, 20px); }
  to   { opacity: 1; transform: translate(-50%, 0); }
}
