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

* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
}

:root {
  --bg-dark: #1a1a2e;
  --bg-medium: #16213e;
  --bg-light: #0f3460;
  --accent: #e94560;
  --accent2: #f5a623;
  --green: #4ade80;
  --text: #e0e0e0;
  --text-dim: #888;
  --gold: #ffd700;
  --gem: #a78bfa;
  --star: #facc15;
  --energy: #38bdf8;
  --grid-bg: #1e3a1e;
  --grid-line: #2d5a2d;
  --cell-bg: #254025;
  --cell-hover: #2d5a2d;
  --cell-locked: #1a1a1a;
  --panel-bg: rgba(22, 33, 62, 0.95);
  --pixel-font: 'Press Start 2P', monospace;
}

html, body {
  width: 100%;
  height: 100%;
  overflow: hidden;
  background: var(--bg-dark);
  font-family: var(--pixel-font);
  color: var(--text);
  font-size: 14px;
  touch-action: none;
  user-select: none;
}

/* ===== Game Container ===== */
#game-container {
  position: relative;
  width: 100%;
  height: 100%;
  max-width: 600px;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

/* ===== Top Bar ===== */
#top-bar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 8px 12px;
  background: var(--bg-medium);
  border-bottom: 2px solid var(--bg-light);
  z-index: 10;
  flex-shrink: 0;
}

#currency-display {
  display: flex;
  gap: 10px;
  font-size: 12px;
}

#currency-display span {
  background: rgba(0,0,0,0.3);
  padding: 4px 8px;
  border-radius: 4px;
  border: 1px solid rgba(255,255,255,0.1);
}

#coins-display { color: var(--gold); }
#gems-display { color: var(--gem); }
#stars-display { color: var(--star); }

#energy-bar-container {
  display: flex;
  align-items: center;
  gap: 6px;
}

#energy-bar {
  width: 80px;
  height: 12px;
  background: rgba(0,0,0,0.4);
  border: 2px solid var(--energy);
  border-radius: 2px;
  overflow: hidden;
}

#energy-fill {
  width: 100%;
  height: 100%;
  background: var(--energy);
  transition: width 0.3s;
}

#energy-text {
  font-size: 11px;
  color: var(--energy);
  white-space: nowrap;
}

/* ===== Canvas ===== */
#game-canvas {
  display: block;
  margin: 0 auto;
  image-rendering: pixelated;
  image-rendering: crisp-edges;
  cursor: pointer;
}

/* ===== Bottom Bar ===== */
#bottom-bar {
  display: flex;
  justify-content: space-around;
  align-items: center;
  padding: 8px 10px;
  background: var(--bg-medium);
  border-top: 2px solid var(--bg-light);
  z-index: 10;
  flex-shrink: 0;
}

.toolbar-btn {
  background: rgba(0,0,0,0.3);
  border: 2px solid var(--bg-light);
  color: var(--text);
  font-size: 22px;
  padding: 8px 14px;
  border-radius: 6px;
  cursor: pointer;
  font-family: var(--pixel-font);
  transition: background 0.15s;
}

.toolbar-btn:hover,
.toolbar-btn:active {
  background: var(--bg-light);
}

.toolbar-btn.active {
  background: var(--accent);
  border-color: var(--accent);
}

/* ===== Order Panel ===== */
#order-panel {
  position: absolute;
  top: 40px;
  right: 0;
  width: 220px;
  max-height: calc(100% - 90px);
  overflow-y: auto;
  background: var(--panel-bg);
  border: 2px solid var(--bg-light);
  border-radius: 8px 0 0 8px;
  z-index: 20;
  padding: 10px;
  transition: transform 0.3s;
}

#order-panel.hidden {
  transform: translateX(100%);
  pointer-events: none;
}

#order-panel-header {
  font-size: 13px;
  margin-bottom: 8px;
  color: var(--accent2);
  text-align: center;
}

.order-slot {
  background: rgba(0,0,0,0.3);
  border: 1px solid var(--bg-light);
  border-radius: 4px;
  padding: 6px;
  margin-bottom: 6px;
}

.order-slot .order-items {
  display: flex;
  gap: 4px;
  flex-wrap: wrap;
  margin: 4px 0;
}

.order-item {
  width: 32px;
  height: 32px;
  background: var(--cell-bg);
  border: 1px solid var(--grid-line);
  border-radius: 2px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 16px;
  position: relative;
}

.order-item.fulfilled {
  opacity: 0.4;
  border-color: var(--green);
}

.order-reward {
  font-size: 11px;
  color: var(--gold);
}

.order-difficulty {
  font-size: 10px;
  color: var(--text-dim);
}

.order-complete-btn {
  width: 100%;
  padding: 6px;
  background: var(--green);
  color: var(--bg-dark);
  border: none;
  border-radius: 4px;
  font-family: var(--pixel-font);
  font-size: 11px;
  cursor: pointer;
  display: none;
}

.order-complete-btn.ready {
  display: block;
}

/* ===== Inventory Drawer ===== */
#inventory-drawer {
  position: absolute;
  bottom: 44px;
  left: 0;
  width: 100%;
  height: 180px;
  background: var(--panel-bg);
  border-top: 2px solid var(--bg-light);
  z-index: 20;
  padding: 8px;
  transition: transform 0.3s;
}

#inventory-drawer.hidden {
  transform: translateY(100%);
  pointer-events: none;
}

#inventory-header {
  font-size: 13px;
  margin-bottom: 8px;
  color: var(--accent2);
  text-align: center;
}

#inventory-grid {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 4px;
}

.inventory-slot {
  aspect-ratio: 1;
  background: var(--cell-bg);
  border: 1px solid var(--grid-line);
  border-radius: 2px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 20px;
  cursor: pointer;
}

.inventory-slot.locked {
  background: var(--cell-locked);
  cursor: default;
}

.inventory-slot.locked::after {
  content: '🔒';
  font-size: 12px;
}

/* ===== Dialogue ===== */
#dialogue-overlay {
  position: absolute;
  bottom: 50px;
  left: 0;
  width: 100%;
  z-index: 30;
  padding: 8px;
}

#dialogue-overlay.hidden {
  display: none;
}

#dialogue-box {
  display: flex;
  gap: 8px;
  background: var(--panel-bg);
  border: 2px solid var(--accent2);
  border-radius: 8px;
  padding: 12px;
}

#dialogue-portrait {
  width: 48px;
  height: 48px;
  border: 2px solid var(--bg-light);
  border-radius: 4px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 32px;
  flex-shrink: 0;
}

#dialogue-content {
  flex: 1;
}

#dialogue-name {
  font-size: 12px;
  color: var(--accent2);
  margin-bottom: 4px;
}

#dialogue-text {
  font-size: 11px;
  line-height: 1.8;
  color: var(--text);
}

/* ===== Building View ===== */
#building-view {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: var(--bg-dark);
  z-index: 25;
  display: flex;
  flex-direction: column;
}

#building-view.hidden {
  display: none;
}

#building-header {
  display: flex;
  align-items: center;
  padding: 8px;
  gap: 12px;
  background: var(--bg-medium);
  border-bottom: 2px solid var(--bg-light);
}

#building-title {
  font-size: 14px;
  color: var(--accent2);
}

#building-canvas {
  flex: 1;
  width: 100%;
  image-rendering: pixelated;
  image-rendering: crisp-edges;
}

#building-tasks {
  max-height: 200px;
  overflow-y: auto;
  padding: 8px;
  background: var(--bg-medium);
}

.building-task {
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: rgba(0,0,0,0.3);
  border: 1px solid var(--bg-light);
  border-radius: 4px;
  padding: 8px;
  margin-bottom: 4px;
}

.building-task.completed {
  opacity: 0.5;
  border-color: var(--green);
}

.task-info {
  font-size: 11px;
}

.task-name {
  color: var(--text);
  margin-bottom: 2px;
}

.task-cost {
  color: var(--star);
}

.task-build-btn {
  padding: 6px 12px;
  background: var(--star);
  color: var(--bg-dark);
  border: none;
  border-radius: 4px;
  font-family: var(--pixel-font);
  font-size: 10px;
  cursor: pointer;
}

.task-build-btn:disabled {
  opacity: 0.4;
  cursor: default;
}

/* ===== Shop ===== */
#shop-overlay {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(0,0,0,0.7);
  z-index: 30;
  display: flex;
  align-items: center;
  justify-content: center;
}

#shop-overlay.hidden { display: none; }

#shop-panel {
  background: var(--panel-bg);
  border: 2px solid var(--accent2);
  border-radius: 8px;
  padding: 12px;
  width: 90%;
  max-width: 400px;
  max-height: 80%;
  overflow-y: auto;
}

#shop-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 14px;
  color: var(--accent2);
  margin-bottom: 12px;
}

.close-btn {
  background: var(--accent);
  border: none;
  color: white;
  width: 24px;
  height: 24px;
  border-radius: 4px;
  cursor: pointer;
  font-size: 12px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.shop-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: rgba(0,0,0,0.3);
  border: 1px solid var(--bg-light);
  border-radius: 4px;
  padding: 8px;
  margin-bottom: 6px;
}

.shop-item-info {
  font-size: 11px;
}

.shop-buy-btn {
  padding: 6px 12px;
  background: var(--accent);
  color: white;
  border: none;
  border-radius: 4px;
  font-family: var(--pixel-font);
  font-size: 10px;
  cursor: pointer;
}

.shop-buy-btn:disabled {
  opacity: 0.4;
  cursor: default;
}

.shop-buy-btn.free {
  background: var(--green);
  color: var(--bg-dark);
}

/* ===== Collection ===== */
#collection-overlay {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(0,0,0,0.7);
  z-index: 30;
  display: flex;
  align-items: center;
  justify-content: center;
}

#collection-overlay.hidden { display: none; }

#collection-panel {
  background: var(--panel-bg);
  border: 2px solid var(--accent2);
  border-radius: 8px;
  padding: 12px;
  width: 90%;
  max-width: 400px;
  max-height: 80%;
  overflow-y: auto;
}

#collection-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 14px;
  color: var(--accent2);
  margin-bottom: 12px;
}

.collection-chain {
  margin-bottom: 12px;
}

.collection-chain-name {
  font-size: 12px;
  color: var(--accent2);
  margin-bottom: 4px;
}

.collection-items {
  display: flex;
  gap: 4px;
  flex-wrap: wrap;
}

.collection-item {
  width: 36px;
  height: 36px;
  background: var(--cell-bg);
  border: 1px solid var(--grid-line);
  border-radius: 2px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 18px;
}

.collection-item.undiscovered {
  opacity: 0.2;
}

.collection-item.undiscovered::after {
  content: '?';
  font-size: 14px;
}

/* ===== Tutorial ===== */
#tutorial-overlay {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  z-index: 50;
  pointer-events: none;
}

#tutorial-overlay.hidden { display: none; }

#tutorial-highlight {
  position: absolute;
  border: 3px solid var(--accent2);
  border-radius: 4px;
  box-shadow: 0 0 0 9999px rgba(0,0,0,0.7);
  pointer-events: none;
}

#tutorial-arrow {
  position: absolute;
  font-size: 24px;
  animation: bounce 0.6s infinite alternate;
}

@keyframes bounce {
  from { transform: translateY(0); }
  to { transform: translateY(-8px); }
}

#tutorial-text-box {
  position: absolute;
  background: var(--panel-bg);
  border: 2px solid var(--accent2);
  border-radius: 8px;
  padding: 12px;
  max-width: 260px;
  pointer-events: auto;
}

#tutorial-text {
  font-size: 12px;
  line-height: 1.8;
  margin-bottom: 10px;
}

#tutorial-next-btn {
  padding: 8px 16px;
  background: var(--accent2);
  color: var(--bg-dark);
  border: none;
  border-radius: 4px;
  font-family: var(--pixel-font);
  font-size: 11px;
  cursor: pointer;
}

/* ===== Sell Zone ===== */
#sell-zone {
  position: absolute;
  bottom: 50px;
  left: 50%;
  transform: translateX(-50%);
  background: rgba(233, 69, 96, 0.9);
  padding: 8px 24px;
  border-radius: 8px;
  font-size: 12px;
  z-index: 15;
  border: 2px solid var(--accent);
  transition: opacity 0.2s, transform 0.2s;
}

#sell-zone.hidden {
  opacity: 0;
  pointer-events: none;
  transform: translateX(-50%) translateY(20px);
}

#sell-zone.active {
  background: rgba(233, 69, 96, 1);
  transform: translateX(-50%) scale(1.1);
}

/* ===== Toast ===== */
#toast-container {
  position: absolute;
  top: 50px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 40;
  display: flex;
  flex-direction: column;
  gap: 4px;
  pointer-events: none;
}

.toast {
  background: var(--panel-bg);
  border: 1px solid var(--accent2);
  border-radius: 4px;
  padding: 8px 16px;
  font-size: 12px;
  animation: toast-in 0.3s, toast-out 0.3s 2s forwards;
  white-space: nowrap;
}

@keyframes toast-in {
  from { opacity: 0; transform: translateY(-10px); }
  to { opacity: 1; transform: translateY(0); }
}

@keyframes toast-out {
  from { opacity: 1; }
  to { opacity: 0; }
}

/* ===== Bubble item ===== */
.bubble-timer {
  position: absolute;
  font-size: 7px;
  color: var(--accent);
  text-align: center;
  pointer-events: none;
}

/* ===== Scrollbar ===== */
::-webkit-scrollbar {
  width: 4px;
}

::-webkit-scrollbar-track {
  background: var(--bg-dark);
}

::-webkit-scrollbar-thumb {
  background: var(--bg-light);
  border-radius: 2px;
}

/* ===== Events/Bingo ===== */
.bingo-grid {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 3px;
  max-width: 280px;
  margin: 0 auto;
}

.bingo-cell {
  aspect-ratio: 1;
  background: var(--cell-bg);
  border: 1px solid var(--grid-line);
  border-radius: 2px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  font-size: 14px;
  cursor: pointer;
}

.bingo-cell.completed {
  background: var(--green);
  opacity: 0.8;
}

.bingo-cell .bingo-task-text {
  font-size: 6px;
  margin-top: 2px;
  color: var(--text-dim);
}

/* ===== Season pass ===== */
.season-track {
  display: flex;
  gap: 4px;
  overflow-x: auto;
  padding: 8px 0;
}

.season-node {
  min-width: 48px;
  height: 48px;
  background: var(--cell-bg);
  border: 1px solid var(--grid-line);
  border-radius: 4px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 16px;
}

.season-node.claimed {
  border-color: var(--green);
  background: rgba(74, 222, 128, 0.2);
}

.season-node.current {
  border-color: var(--accent2);
  box-shadow: 0 0 8px var(--accent2);
}

/* ===== Mobile responsive ===== */
@media (max-width: 400px) {
  #currency-display { gap: 6px; }
  #currency-display span { padding: 3px 5px; font-size: 10px; }
  #energy-bar { width: 60px; }
  #energy-text { font-size: 9px; }
  .toolbar-btn { padding: 4px 8px; font-size: 16px; }
  #order-panel { width: 190px; }
}
