@import url('https://fonts.googleapis.com/css2?family=Press+Start+2P&display=swap');

:root {
  --gold: #ffd700;
  --gold-dim: #b8960f;
  --wood: #6b5b4f;
  --wood-light: #8b7355;
  --night: #1a1c2c;
  --night-warm: #2a1b0a;
  --pixel-shadow: #0f0f23;
  --pixel-shadow-brown: #8b4513;
  --fire-orange: #ff6600;
  --fire-glow: rgba(255, 102, 0, 0.5);
  --fire-red: #ff3300;
  --campfire-yellow: #ffcc00;
  --text-light: #e8d5b7;
  --text-dim: #a89276;
  --card-bg: rgba(26, 28, 44, 0.85);
  --panel-overlay: rgba(10, 10, 20, 0.3);
  --font-pixel: 'Press Start 2P', monospace;
  --transition-speed: 0.4s;
}

* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

html {
  width: 100%;
  height: 100%;
  overflow: hidden;
}

body {
  width: 100%;
  height: 100%;
  overflow: hidden;
  font-family: var(--font-pixel);
  background-color: var(--night);
  color: var(--text-light);
  -webkit-font-smoothing: none;
  -moz-osx-font-smoothing: unset;
  image-rendering: pixelated;
}

/* ========== Panel Wrapper — uses transform to switch panels ========== */
.panel-wrapper {
  width: 100vw;
  height: 100vh;
  overflow: hidden;
  position: relative;
}

.scroll-container {
  display: flex;
  width: 300vw;
  height: 100vh;
  transition: transform var(--transition-speed) ease-in-out;
  will-change: transform;
}

/* ========== Panels ========== */
.panel-left,
.panel-center,
.panel-right {
  flex: 0 0 100vw;
  width: 100vw;
  height: 100vh;
  position: relative;
  overflow: hidden;
  background-size: cover;
  background-position: center;
  background-repeat: no-repeat;
}

.panel-left {
  background-image: url('../data/scene1_lakeside_stalls.jpeg');
  background-color: #2a1b0a;
  display: flex;
  flex-direction: column;
}

.panel-center {
  background-image: url('../data/scene2_personal_shelter.jpeg');
  background-size: cover;
  background-position: center;
  background-repeat: no-repeat;
}

.panel-center::before {
  content: '';
  position: absolute;
  inset: 0;
  background: linear-gradient(180deg, rgba(10, 10, 20, 0.18) 0%, rgba(10, 10, 20, 0.38) 100%);
  z-index: 0;
  pointer-events: none;
}

.panel-left::before,
.panel-center::before,
.panel-right::before {
  content: '';
  position: absolute;
  inset: 0;
  background: var(--panel-overlay);
  z-index: 0;
  pointer-events: none;
}

.panel-right {
  /* default bg — overridden by #panel-campfire selectors in scene-campfire.css */
}

/* .panel-right::before override — no default, scene-campfire.css provides the glow */

/* ========== Navigation Arrows ========== */
.arrow-left,
.arrow-right {
  position: fixed;
  top: 50%;
  transform: translateY(-50%);
  z-index: 9999;
  width: 48px;
  height: 48px;
  background: var(--card-bg);
  border: 2px solid var(--gold);
  color: var(--gold);
  font-family: var(--font-pixel);
  font-size: 20px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: all var(--transition-speed);
  image-rendering: pixelated;
  user-select: none;
}

.arrow-left {
  left: 12px;
}

.arrow-right {
  right: 12px;
}

.arrow-left:hover,
.arrow-right:hover {
  background: var(--gold);
  color: var(--night);
  box-shadow: 0 0 12px var(--fire-glow);
}

.arrow-left.hidden,
.arrow-right.hidden {
  opacity: 0;
  pointer-events: none;
}

/* ========== Pixel Button ========== */
.btn-pixel {
  font-family: var(--font-pixel);
  font-size: clamp(11px, 0.9vw, 14px);
  padding: 12px 24px;
  background: var(--night-warm);
  color: var(--gold);
  border: 2px solid var(--gold);
  cursor: pointer;
  transition: all var(--transition-speed);
  text-transform: uppercase;
  letter-spacing: 1px;
  image-rendering: pixelated;
  position: relative;
}

.btn-pixel:hover {
  background: var(--gold);
  color: var(--night);
  box-shadow: 4px 4px 0 var(--pixel-shadow);
  transform: translate(-2px, -2px);
}

.btn-pixel:active {
  transform: translate(0, 0);
  box-shadow: none;
}

.btn-pixel:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.btn-pixel:disabled:hover {
  background: var(--night-warm);
  color: var(--gold-dim);
  box-shadow: none;
  transform: none;
}

/* ========== Entrance Page ========== */
.entrance-page {
  width: 100vw;
  height: 100vh;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 24px;
  background: var(--night);
  text-align: center;
  padding: 32px;
}

.entrance-title {
  font-family: var(--font-pixel);
  font-size: 20px;
  color: var(--gold);
  text-shadow: 2px 2px 0 var(--pixel-shadow);
  margin-bottom: 8px;
  line-height: 1.6;
}

.entrance-subtitle {
  font-family: var(--font-pixel);
  font-size: 10px;
  color: var(--text-dim);
  margin-bottom: 32px;
  line-height: 1.8;
}

.entrance-buttons {
  display: flex;
  flex-direction: column;
  gap: 16px;
  align-items: center;
}

.entrance-buttons .btn-pixel {
  min-width: 240px;
  text-align: center;
}

/* ========== Panel Section Titles ========== */
.panel-title {
  position: relative;
  z-index: 1;
  text-align: center;
  padding-top: 20px;
  font-family: var(--font-pixel);
  font-size: clamp(12px, 1vw, 15px);
  color: var(--gold);
  text-shadow: 2px 2px 0 var(--pixel-shadow);
}

.market-grid {
  position: relative;
  z-index: 1;
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  grid-template-rows: auto;
  gap: clamp(12px, 1.8vw, 28px);
  padding: clamp(12px, 1.8vw, 32px) clamp(18px, 2.2vw, 42px);
  width: 100%;
  flex: 1;
  min-height: 0;
  margin: 0 auto;
  align-content: start;
  justify-content: stretch;
  overflow-y: auto;
}

/* ========== Market Header ========== */
.market-header {
  position: relative;
  z-index: 2;
  display: flex;
  justify-content: flex-end;
  align-items: center;
  padding: clamp(10px, 1.2vw, 18px) clamp(18px, 2.2vw, 42px) 0;
  flex-shrink: 0;
}

.market-header-title {
  display: none;
}

.market-coin-display {
  font-family: var(--font-pixel);
  font-size: clamp(13px, 1.1vw, 16px);
  color: var(--gold);
  background: var(--card-bg);
  border: 2px solid var(--gold);
  padding: 8px 16px;
  image-rendering: pixelated;
}

.stall-card {
  background: var(--card-bg);
  border: clamp(2px, 0.28vw, 3px) solid var(--wood);
  padding: clamp(16px, 1.8vw, 28px);
  text-align: center;
  cursor: pointer;
  transition: all var(--transition-speed);
  image-rendering: pixelated;
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-height: 0;
  overflow: hidden;
  min-width: 0;
}

.stall-card:hover {
  border-color: var(--gold);
  box-shadow: 0 0 12px var(--fire-glow), 4px 4px 0 var(--pixel-shadow-brown);
  transform: translate(-2px, -2px);
}

.stall-card:active {
  transform: translate(0, 0);
  box-shadow: none;
}

.stall-card-owner {
  width: clamp(60px, 5.2vw, 92px);
  height: clamp(60px, 5.2vw, 92px);
  margin: 0 auto clamp(8px, 0.7vw, 12px);
  background: rgba(0,0,0,0.3);
  border: clamp(2px, 0.22vw, 3px) solid var(--wood-light);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: clamp(26px, 2.35vw, 36px);
  line-height: 1;
  flex-shrink: 0;
}

.stall-card-nickname {
  font-family: var(--font-pixel);
  font-size: clamp(14px, 1.2vw, 17px);
  line-height: 1.4;
  color: var(--gold);
  margin-bottom: clamp(8px, 0.7vw, 12px);
  text-shadow: 1px 1px 0 var(--pixel-shadow);
  flex-shrink: 0;
  width: 100%;
  overflow-wrap: break-word;
}

.stall-card-items {
  display: flex;
  flex-direction: column;
  gap: clamp(8px, 0.7vw, 14px);
  width: 100%;
  flex: 1;
  min-height: 0;
}

.stall-item {
  font-family: var(--font-pixel);
  font-size: clamp(13px, 1.1vw, 16px);
  line-height: 1.5;
  color: var(--text-light);
  background: rgba(0,0,0,0.25);
  border: clamp(2px, 0.22vw, 3px) solid var(--wood-light);
  padding: clamp(8px, 0.64vw, 12px) clamp(9px, 0.82vw, 14px);
  cursor: pointer;
  transition: all var(--transition-speed);
  position: relative;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.stall-item:hover {
  border-color: var(--gold);
  color: var(--gold);
  background: rgba(255,215,0,0.1);
}

.stall-item-price {
  color: var(--gold);
  margin-left: 4px;
  font-size: clamp(12px, 1vw, 15px);
}

.stall-item-price::before {
  content: '\263A';
  font-size: clamp(13px, 1.05vw, 16px);
  margin-right: 2px;
}

.stall-item-icon {
  position: absolute;
  top: -4px;
  right: -4px;
  font-size: clamp(18px, 1.4vw, 24px);
  animation: glow-pulse 2s ease-in-out infinite;
}

/* ========== Buy Dialog ========== */
.buy-dialog-overlay {
  position: fixed;
  inset: 0;
  z-index: 10000;
  background: rgba(0,0,0,0.7);
  display: flex;
  align-items: center;
  justify-content: center;
}

.buy-dialog {
  background: var(--night);
  border: 3px solid var(--gold);
  padding: 24px;
  text-align: center;
  font-family: var(--font-pixel);
  font-size: clamp(12px, 1vw, 15px);
  color: var(--text-light);
  image-rendering: pixelated;
  max-width: 400px;
  width: 90%;
  box-shadow: 8px 8px 0 var(--pixel-shadow);
}

.buy-dialog h3 {
  font-size: clamp(15px, 1.2vw, 18px);
  color: var(--gold);
  margin-bottom: 16px;
  text-shadow: 2px 2px 0 var(--pixel-shadow);
}

.buy-dialog p {
  margin-bottom: 12px;
  line-height: 1.8;
}

.buy-dialog .btn-row {
  display: flex;
  gap: 12px;
  justify-content: center;
  margin-top: 16px;
}

.buy-dialog-message {
  font-family: var(--font-pixel);
  font-size: clamp(10px, 0.82vw, 13px);
  padding: 8px 10px;
  width: 100%;
  background: rgba(0,0,0,0.4);
  border: 2px solid var(--wood);
  color: var(--text-light);
  outline: none;
  margin-top: 10px;
  image-rendering: pixelated;
}

.buy-dialog-message:focus {
  border-color: var(--gold);
}

.buy-dialog-message::placeholder {
  color: var(--text-dim);
  font-size: clamp(10px, 0.8vw, 12px);
}

/* ========== Shelter Hero ========== */
.shelter-hero {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -52%);
  z-index: 2;
  width: min(78vw, 760px);
  text-align: center;
  pointer-events: none;
}

.shelter-hero-title {
  margin: 0;
  font-family: var(--font-pixel);
  font-size: clamp(48px, 10vw, 112px);
  line-height: 1;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: #fff3cf;
  text-shadow:
    0 4px 0 rgba(15, 15, 35, 0.9),
    0 10px 24px rgba(0, 0, 0, 0.45);
}

.shelter-hero-subtitle {
  margin: 18px 0 0;
  font-family: var(--font-pixel);
  font-size: clamp(12px, 2.2vw, 22px);
  letter-spacing: 0.28em;
  color: var(--gold);
  text-shadow: 0 2px 0 rgba(15, 15, 35, 0.9);
}

/* ========== Character Container ========== */
.character-container {
  position: absolute;
  bottom: 20%;
  left: 50%;
  transform: translateX(-50%);
  width: 200px;
  height: 280px;
  z-index: 2;
  display: none;
  flex-direction: column;
  align-items: center;
}

.character-sprite {
  position: relative;
  width: 160px;
  height: 240px;
  margin: 0 auto;
}

.character-base {
  position: absolute;
  bottom: 20px;
  left: 50%;
  transform: translateX(-50%);
  font-size: 80px;
  line-height: 1;
  text-align: center;
  z-index: 2;
  filter: drop-shadow(2px 4px 0 rgba(0,0,0,0.4));
  transition: all 0.3s ease;
  display: none;
}

.character-name {
  font-family: var(--font-pixel);
  font-size: clamp(9px, 0.82vw, 12px);
  color: var(--gold);
  text-shadow: 1px 1px 0 var(--pixel-shadow);
  margin-top: 8px;
  text-align: center;
}

/* Equipped decor layers */
.decor-layer {
  position: absolute;
  font-size: 32px;
  line-height: 1;
  text-align: center;
  pointer-events: none;
  filter: drop-shadow(1px 2px 0 rgba(0,0,0,0.3));
  transition: all 0.3s ease;
  z-index: 0;
}

.decor-slot-head    { left: 50%; top: 5%;  transform: translateX(-50%); z-index: 5; }
.decor-slot-body    { left: 50%; top: 38%; transform: translateX(-50%); z-index: 3; }
.decor-slot-back    { left: 50%; top: 32%; transform: translateX(-50%); z-index: 1; }
.decor-slot-hand    { left: 68%; top: 42%; transform: translateX(-50%); z-index: 4; }
.decor-slot-legs    { left: 50%; top: 68%; transform: translateX(-50%); z-index: 2; }

/* ========== Backpack Button ========== */
.backpack-toggle {
  position: absolute;
  bottom: 32px;
  right: 32px;
  z-index: 10;
  width: 56px;
  height: 56px;
  background: var(--card-bg);
  border: 2px solid var(--gold);
  color: var(--gold);
  font-family: var(--font-pixel);
  font-size: 24px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: all var(--transition-speed);
  image-rendering: pixelated;
}

.backpack-toggle:hover {
  background: var(--gold);
  color: var(--night);
  box-shadow: 0 0 12px var(--fire-glow);
  transform: scale(1.1);
}

.backpack-toggle.open {
  background: var(--gold);
  color: var(--night);
}

/* ========== Shelter Section (Backpack overlay) ========== */
.shelter-section {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  width: 320px;
  max-width: 90vw;
  max-height: 70vh;
  z-index: 20;
  background: var(--card-bg);
  backdrop-filter: blur(4px);
  border: 2px solid var(--gold);
  display: none;
  flex-direction: column;
  padding: 16px;
  overflow: hidden;
}

.shelter-section.open {
  display: flex;
}

.shelter-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding-bottom: 12px;
  border-bottom: 2px solid var(--wood);
  margin-bottom: 12px;
  flex-shrink: 0;
}

.shelter-header-title {
  font-family: var(--font-pixel);
  font-size: clamp(12px, 0.95vw, 15px);
  color: var(--gold);
  text-shadow: 1px 1px 0 var(--pixel-shadow);
}

.shelter-close {
  width: 36px;
  height: 36px;
  background: none;
  border: 2px solid var(--gold);
  color: var(--gold);
  font-family: var(--font-pixel);
  font-size: 14px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all var(--transition-speed);
  image-rendering: pixelated;
}

.shelter-close:hover {
  background: var(--gold);
  color: var(--night);
}

/* ========== Shelter Tabs ========== */
.shelter-tabs {
  display: flex;
  gap: 0;
  margin-bottom: 12px;
  flex-shrink: 0;
}

.shelter-tab {
  flex: 1;
  padding: 10px 0;
  font-family: var(--font-pixel);
  font-size: clamp(9px, 0.74vw, 11px);
  color: var(--text-dim);
  background: rgba(0,0,0,0.3);
  border: 2px solid var(--wood);
  cursor: pointer;
  text-align: center;
  transition: all var(--transition-speed);
  image-rendering: pixelated;
}

.shelter-tab:first-child {
  border-right: none;
}

.shelter-tab.active {
  color: var(--gold);
  background: var(--night-warm);
  border-color: var(--gold);
}

.shelter-tab:hover:not(.active) {
  color: var(--text-light);
  border-color: var(--wood-light);
}

/* ========== Shelter Grid ========== */
.shelter-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
  overflow-y: auto;
  flex: 1;
  padding-right: 4px;
  align-content: start;
}

.shelter-grid::-webkit-scrollbar {
  width: 4px;
}

.shelter-grid::-webkit-scrollbar-track {
  background: rgba(0,0,0,0.2);
}

.shelter-grid::-webkit-scrollbar-thumb {
  background: var(--wood);
}

.shelter-item {
  background: rgba(0,0,0,0.35);
  border: 2px solid var(--wood);
  padding: 8px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  cursor: pointer;
  transition: all var(--transition-speed);
  image-rendering: pixelated;
  min-height: 90px;
}

.shelter-item:hover {
  border-color: var(--gold);
  background: rgba(255, 215, 0, 0.08);
}

.shelter-item.equipped {
  border-color: var(--gold);
  background: rgba(255, 215, 0, 0.12);
  box-shadow: 0 0 8px rgba(255, 215, 0, 0.2);
}

.shelter-item-icon {
  font-size: 28px;
  line-height: 1;
  width: 100%;
  aspect-ratio: 4 / 3;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(0,0,0,0.25);
  border: 1px solid rgba(255,255,255,0.06);
}

.shelter-item-name {
  font-family: var(--font-pixel);
  font-size: clamp(8px, 0.62vw, 10px);
  color: var(--text-light);
  text-align: center;
  line-height: 1.4;
}

.shelter-item-slot {
  font-family: var(--font-pixel);
  font-size: 6px;
  color: var(--text-dim);
  text-transform: uppercase;
}

.shelter-item-action {
  font-family: var(--font-pixel);
  font-size: 7px;
  padding: 4px 8px;
  border: 1px solid var(--gold);
  background: transparent;
  color: var(--gold);
  cursor: pointer;
  transition: all var(--transition-speed);
  image-rendering: pixelated;
  margin-top: auto;
}

.shelter-item-action:hover {
  background: var(--gold);
  color: var(--night);
}

.shelter-item-action.unequip {
  border-color: var(--fire-orange);
  color: var(--fire-orange);
}

.shelter-item-action.unequip:hover {
  background: var(--fire-orange);
  color: var(--night);
}

/* ========== Background Grid ========== */
.bg-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 10px;
  overflow-y: auto;
  flex: 1;
  padding-right: 4px;
  align-content: start;
}

.bg-item {
  background: rgba(0,0,0,0.4);
  border: 2px solid var(--wood);
  padding: 12px 8px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  cursor: pointer;
  transition: all var(--transition-speed);
  image-rendering: pixelated;
}

.bg-item:hover {
  border-color: var(--gold);
}

.bg-item.active {
  border-color: var(--gold);
  box-shadow: 0 0 8px rgba(255, 215, 0, 0.25);
}

.bg-item-preview {
  width: 100%;
  aspect-ratio: 4 / 3;
  border: 1px solid var(--wood);
}

.bg-item-preview.lake {
  background: linear-gradient(180deg, #ff9a56, #e8553d, #8b3a6e, #1a1c2c);
}

.bg-item-preview.aurora {
  background: linear-gradient(180deg, #0a1628, #1a3a5c, #2d6a4f, #0a1628);
  position: relative;
  overflow: hidden;
}

.bg-item-preview.aurora::after {
  content: '';
  position: absolute;
  top: 30%;
  left: 10%;
  width: 80%;
  height: 30%;
  background: linear-gradient(90deg, transparent, rgba(0,255,150,0.4), rgba(0,200,255,0.4), transparent);
  border-radius: 50%;
}

.bg-item-preview.campfire {
  background: linear-gradient(180deg, #0a0a1a, #1a1025, #2a1520, #3a1010);
  position: relative;
}

.bg-item-preview.campfire::after {
  content: '';
  position: absolute;
  bottom: 15%;
  left: 50%;
  transform: translateX(-50%);
  width: 20px;
  height: 20px;
  background: radial-gradient(circle, var(--fire-orange), transparent);
  border-radius: 50%;
}

.bg-item-name {
  font-family: var(--font-pixel);
  font-size: clamp(8px, 0.62vw, 10px);
  color: var(--text-light);
  text-align: center;
  line-height: 1.4;
}

/* Empty backpack state */
.empty-backpack {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 12px;
  flex: 1;
  color: var(--text-dim);
  font-family: var(--font-pixel);
  font-size: 10px;
  text-align: center;
}

.empty-backpack-icon {
  font-size: 40px;
  opacity: 0.5;
}

/* ========== User-uploaded items in stalls ========== */
.stall-card-user {
  border-color: var(--gold) !important;
  background: rgba(26, 28, 44, 0.95) !important;
  position: relative;
}

.stall-card-user .stall-card-owner {
  border-color: var(--gold) !important;
  background: rgba(255, 215, 0, 0.08) !important;
}

.stall-card-user-item {
  border-style: dashed !important;
  border-color: var(--gold-dim) !important;
  background: rgba(26, 28, 44, 0.92);
  position: relative;
}
.stall-card-user-item::before {
  content: '';
  position: absolute;
  inset: 4px;
  border: 1px dashed rgba(255, 215, 0, 0.25);
  pointer-events: none;
  image-rendering: pixelated;
}

.stall-item-user {
  border-style: dashed;
  border-color: var(--gold-dim);
  display: flex;
  align-items: center;
  gap: 6px;
}

.stall-item-user-upload {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.stall-item-thumb {
  width: 28px;
  height: 28px;
  image-rendering: pixelated;
  border: 1px solid var(--wood-light);
  flex-shrink: 0;
}

/* ========== User-uploaded items in shelter ========== */
.shelter-item-thumb {
  width: 100%;
  height: 100%;
  object-fit: contain;
  image-rendering: pixelated;
}

.shelter-item-user {
  border-style: dashed;
  border-color: var(--gold-dim);
}

@keyframes blink {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.3; }
}

.pixel-blink {
  animation: blink 1s step-end infinite;
}

@keyframes glow-pulse {
  0%, 100% { box-shadow: 0 0 4px var(--gold); }
  50% { box-shadow: 0 0 16px var(--gold), 0 0 32px var(--fire-glow); }
}

/* ========== Music Toggle Button ========== */
.music-toggle {
  position: fixed;
  top: 12px;
  left: 12px;
  z-index: 10000;
  width: 36px;
  height: 36px;
  background: var(--night);
  border: 2px solid var(--gold);
  color: var(--gold);
  font-size: 16px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  image-rendering: pixelated;
  transition: all var(--transition-speed);
}
.music-toggle:hover {
  background: var(--gold);
  color: var(--night);
}
.music-toggle.panel-market {
  left: clamp(18px, 2.2vw, 42px);
}
.music-toggle.panel-shelter {
  left: 12px;
}
.music-toggle.panel-campfire {
  left: 12px;
}

