/* ─── Reset & Base ─────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

body {
  background: #1a1a2e;
  color: #eee;
  font-family: 'Segoe UI', system-ui, sans-serif;
  display: flex;
  flex-direction: column;
  align-items: center;
  min-height: 100vh;
  padding: 20px;
}

/* ─── Game Wrapper ──────────────────────────────────────────────── */
#game-wrapper {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
  width: 800px;
}

/* ─── Game Container (stacking context) ────────────────────────── */
#game-container {
  position: relative;
  width: 800px;
  height: 560px;
  border: 3px solid #444;
  border-radius: 6px;
  overflow: hidden;
  box-shadow: 0 8px 32px rgba(0,0,0,0.6);
}

/* ─── Canvas — z-index 0 ────────────────────────────────────────── */
#gameCanvas {
  position: absolute;
  top: 0; left: 0;
  z-index: 0;
  display: block;
  transition: opacity 0.2s;
}

#gameCanvas.dimmed {
  opacity: 0.3;
}

/* ─── Scene Overlay — z-index 10 ────────────────────────────────── */
#scene-overlay {
  position: absolute;
  top: 36px; left: 0;
  width: 100%;
  height: calc(100% - 36px);
  z-index: 10;
  display: none;
  overflow-y: auto;
  background: rgba(10, 10, 30, 0.95);
}

#scene-overlay.active {
  display: block;
}

#scene-content {
  padding: 20px;
  min-height: 100%;
}

/* ─── Scene Panel Styles ─────────────────────────────────────────── */
.scene-panel {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.scene-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding-bottom: 12px;
  border-bottom: 2px solid #333;
}

.scene-title {
  font-size: 1.5rem;
  font-weight: 700;
  letter-spacing: 0.05em;
}

.scene-subtitle {
  font-size: 0.85rem;
  color: #aaa;
  margin-top: 2px;
}

.btn-exit {
  background: #444;
  color: #eee;
  border: none;
  border-radius: 6px;
  padding: 8px 16px;
  cursor: pointer;
  font-size: 0.9rem;
  transition: background 0.15s;
}
.btn-exit:hover { background: #666; }

/* Item grid for thrift/auction */
.item-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
  gap: 12px;
}

.item-card {
  background: #1e2035;
  border: 2px solid #333;
  border-radius: 8px;
  padding: 12px;
  cursor: pointer;
  transition: border-color 0.15s, transform 0.1s;
  text-align: center;
}
.item-card:hover {
  border-color: #888;
  transform: translateY(-2px);
}

.item-card .card-emoji { font-size: 2rem; }
.item-card .card-name { font-size: 0.85rem; font-weight: 600; margin-top: 4px; }
.item-card .card-condition { font-size: 0.75rem; color: #aaa; }
.item-card .card-price { font-size: 1rem; font-weight: 700; color: #2ecc71; margin-top: 6px; }
.item-card .card-est { font-size: 0.7rem; color: #888; }

/* Condition colors */
.cond-poor    { color: #e74c3c; }
.cond-fair    { color: #f39c12; }
.cond-good    { color: #3498db; }
.cond-excellent { color: #2ecc71; }

/* Inventory list */
.inv-table {
  width: 100%;
  border-collapse: collapse;
}
.inv-table th, .inv-table td {
  text-align: left;
  padding: 8px 10px;
  border-bottom: 1px solid #333;
  font-size: 0.85rem;
}
.inv-table th { color: #aaa; font-weight: 600; text-transform: uppercase; font-size: 0.75rem; }
.inv-table tr:hover td { background: #1e2035; }

/* Buttons */
.btn {
  border: none;
  border-radius: 6px;
  padding: 8px 18px;
  cursor: pointer;
  font-size: 0.9rem;
  font-weight: 600;
  transition: opacity 0.15s, transform 0.1s;
}
.btn:hover { opacity: 0.85; transform: translateY(-1px); }
.btn:active { transform: translateY(0); }
.btn:disabled { opacity: 0.4; cursor: not-allowed; transform: none; }

.btn-green  { background: #27ae60; color: #fff; }
.btn-red    { background: #e74c3c; color: #fff; }
.btn-blue   { background: #2980b9; color: #fff; }
.btn-purple { background: #8e44ad; color: #fff; }
.btn-orange { background: #e67e22; color: #fff; }
.btn-gray   { background: #555; color: #eee; }

.btn-advance {
  background: linear-gradient(135deg, #f39c12, #e67e22);
  color: #fff;
  font-size: 1rem;
  padding: 12px 28px;
}

/* Price input */
.price-input {
  background: #1e2035;
  border: 2px solid #444;
  border-radius: 6px;
  color: #eee;
  padding: 6px 10px;
  font-size: 0.9rem;
  width: 120px;
}
.price-input:focus { outline: none; border-color: #888; }

/* Auction card */
.auction-card {
  background: #1e2035;
  border: 2px solid #2980b9;
  border-radius: 8px;
  padding: 16px;
  display: flex;
  gap: 16px;
  align-items: center;
}
.auction-card .card-emoji { font-size: 2.5rem; }
.auction-card .auction-info { flex: 1; }
.auction-card .auction-bids { display: flex; flex-direction: column; gap: 8px; align-items: flex-end; }

/* Storage unit card */
.storage-card {
  background: #1e2035;
  border: 2px solid #8e44ad;
  border-radius: 8px;
  padding: 16px;
  display: flex;
  gap: 16px;
  align-items: center;
}

/* Day summary panel */
.day-summary {
  background: #1e2035;
  border: 2px solid #2ecc71;
  border-radius: 8px;
  padding: 16px;
}
.day-summary h3 { color: #2ecc71; margin-bottom: 10px; }

/* Empty state */
.empty-state {
  text-align: center;
  color: #666;
  padding: 40px;
  font-size: 0.95rem;
}

/* Section headers inside scenes */
.section-label {
  font-size: 0.75rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: #888;
  margin-bottom: 8px;
}

/* ─── HUD — z-index 20 ───────────────────────────────────────────── */
#hud {
  position: absolute;
  top: 0; left: 0; right: 0;
  height: 36px;
  z-index: 20;
  pointer-events: auto;
  display: flex;
  flex-wrap: nowrap;
  align-items: center;
  gap: 10px;
  padding: 0 14px;
  background: rgba(0,0,0,0.65);
  font-size: 0.82rem;
  font-weight: 600;
  letter-spacing: 0.02em;
  overflow: visible;
}
#hud span { white-space: nowrap; pointer-events: none; }
#hud-cash    { color: #2ecc71; }
#hud-day     { color: #f39c12; }
#hud-networth { color: #3498db; }
#hud-inv     { color: #bbb; }
#hud-trends  { color: #ddd; font-size: 0.78rem; opacity: 0.9; }

/* ─── Market Trends Bar ──────────────────────────────────────────── */
.market-trends-bar {
  background: rgba(255,255,255,0.05);
  border: 1px solid rgba(255,255,255,0.1);
  border-radius: 6px;
  padding: 6px 14px;
  font-size: 0.8rem;
  color: #ccc;
  margin-bottom: 4px;
}

/* ─── Dialog Overlay — z-index 30 ───────────────────────────────── */
#dialog-overlay {
  position: absolute;
  top: 0; left: 0;
  width: 100%; height: 100%;
  z-index: 30;
  background: rgba(0,0,0,0.7);
  display: flex;
  align-items: center;
  justify-content: center;
}
#dialog-overlay.hidden { display: none; }

#dialog-box {
  background: #1a1a2e;
  border: 2px solid #555;
  border-radius: 12px;
  padding: 28px;
  width: 360px;
  max-width: 90%;
  text-align: center;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

#dialog-emoji { font-size: 3.5rem; }
#dialog-name  { font-size: 1.3rem; font-weight: 700; }
#dialog-meta  { font-size: 0.8rem; color: #aaa; }
#dialog-desc  { font-size: 0.85rem; color: #ccc; font-style: italic; border-top: 1px solid #333; padding-top: 8px; }
#dialog-value { font-size: 1rem; font-weight: 700; color: #2ecc71; }
#dialog-actions { display: flex; gap: 10px; justify-content: center; flex-wrap: wrap; }
#dialog-close {
  background: none;
  border: 1px solid #555;
  color: #aaa;
  border-radius: 6px;
  padding: 6px 16px;
  cursor: pointer;
  font-size: 0.85rem;
}
#dialog-close:hover { background: #333; }

/* ─── Toast Container — z-index 40 ──────────────────────────────── */
#toast-container {
  position: absolute;
  bottom: 16px;
  right: 16px;
  z-index: 40;
  pointer-events: none;
  display: flex;
  flex-direction: column;
  gap: 8px;
  align-items: flex-end;
}

.toast {
  background: rgba(30, 32, 53, 0.95);
  border: 1px solid #555;
  border-radius: 8px;
  padding: 10px 16px;
  font-size: 0.85rem;
  max-width: 280px;
  animation: toast-in 0.3s ease, toast-out 0.3s ease forwards;
  animation-delay: 0s, 2.7s;
  box-shadow: 0 4px 12px rgba(0,0,0,0.4);
}
.toast.toast-success { border-color: #2ecc71; }
.toast.toast-error   { border-color: #e74c3c; }
.toast.toast-info    { border-color: #3498db; }

@keyframes toast-in {
  from { opacity: 0; transform: translateX(20px); }
  to   { opacity: 1; transform: translateX(0); }
}
@keyframes toast-out {
  from { opacity: 1; }
  to   { opacity: 0; transform: translateX(20px); }
}

/* ─── Canvas Controls (skills + gear) — inline in HUD ───────────── */
#canvas-controls {
  display: flex;
  flex-direction: row;
  gap: 4px;
  align-items: center;
  margin-left: auto;
  flex-shrink: 0;
}

#btn-skills-canvas, #btn-gear {
  width: 26px;
  height: 26px;
  background: rgba(255,255,255,0.1);
  border: 1px solid rgba(255,255,255,0.22);
  border-radius: 6px;
  color: #eee;
  font-size: 0.85rem;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.15s;
}
#btn-skills-canvas:hover, #btn-gear:hover { background: rgba(255,255,255,0.22); }

#gear-wrap { position: relative; }

#gear-dropdown {
  position: absolute;
  top: calc(100% + 4px);
  right: 0;
  background: #1a1a2e;
  border: 1px solid #555;
  border-radius: 8px;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  min-width: 140px;
  box-shadow: 0 4px 16px rgba(0,0,0,0.5);
}
#gear-dropdown button,
#gear-dropdown a {
  background: none;
  border: none;
  color: #eee;
  padding: 10px 14px;
  text-align: left;
  cursor: pointer;
  font-size: 0.85rem;
  white-space: nowrap;
  transition: background 0.15s;
  text-decoration: none;
  display: block;
}
#gear-dropdown button:hover,
#gear-dropdown a:hover { background: #2c3e50; }

#gear-tip { display: none; }
body.touch-device #gear-tip { display: block; }

/* ─── Tip Jar ────────────────────────────────────────────────────── */
#tip-jar {
  text-align: center;
  padding: 10px 12px;
  color: #888;
  font-size: 0.8rem;
}
#tip-jar p {
  margin: 0 0 8px;
  letter-spacing: 0.02em;
}
#tip-jar a {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  background: linear-gradient(135deg, #f6d365 0%, #f39c12 100%);
  color: #3a1f00;
  font-weight: 800;
  font-size: 0.9rem;
  padding: 9px 22px 9px 18px;
  border-radius: 999px;
  text-decoration: none;
  border: 2px solid rgba(255,255,255,0.35);
  box-shadow: 0 2px 8px rgba(243,156,18,0.45), inset 0 1px 0 rgba(255,255,255,0.4);
  transition: transform 0.12s, box-shadow 0.12s, filter 0.12s;
  letter-spacing: 0.03em;
}
#tip-jar a:hover {
  transform: translateY(-2px) scale(1.04);
  box-shadow: 0 5px 16px rgba(243,156,18,0.6), inset 0 1px 0 rgba(255,255,255,0.4);
  filter: brightness(1.06);
}
#tip-jar a:active {
  transform: translateY(0) scale(0.98);
  box-shadow: 0 1px 4px rgba(243,156,18,0.4);
}
.tip-jar-icon  { font-size: 1.15rem; line-height: 1; }
.tip-jar-coins { font-size: 0.95rem; line-height: 1; }
.tip-jar-label { font-size: inherit; }

/* ─── Skills Menu ────────────────────────────────────────────────── */
#skills-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.75);
  z-index: 200;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
}
#skills-panel {
  background: #1e2a3a;
  border: 1px solid #3a4a5a;
  border-radius: 12px;
  width: 100%;
  max-width: 720px;
  max-height: 90vh;
  overflow-y: auto;
  padding: 24px;
  box-shadow: 0 16px 48px rgba(0,0,0,0.6);
}
#skills-panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 20px;
}
#skills-panel-header h2 {
  font-size: 1.2rem;
  font-weight: 700;
  color: #f0e6c8;
  letter-spacing: 0.04em;
}
#skills-close {
  background: transparent;
  border: 1px solid #555;
  color: #aaa;
  border-radius: 6px;
  padding: 4px 12px;
  cursor: pointer;
  font-size: 0.85rem;
  transition: background 0.15s;
}
#skills-close:hover { background: #2c3e50; color: #eee; }
#skills-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(190px, 1fr));
  gap: 12px;
}
.skill-card {
  background: #16212e;
  border: 1px solid #2c3e50;
  border-radius: 8px;
  padding: 14px;
}
.skill-card-header {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  margin-bottom: 8px;
}
.skill-name {
  font-weight: 700;
  font-size: 0.9rem;
  color: #d0e8f0;
}
.skill-level {
  font-size: 0.75rem;
  font-weight: 700;
  color: #f39c12;
  white-space: nowrap;
}
.skill-max { color: #2ecc71; }
.skill-xp-bar {
  height: 6px;
  background: #2c3e50;
  border-radius: 3px;
  overflow: hidden;
  margin-bottom: 4px;
}
.skill-xp-fill {
  height: 100%;
  background: linear-gradient(90deg, #3498db, #2ecc71);
  border-radius: 3px;
  transition: width 0.3s ease;
}
.skill-xp-text {
  font-size: 0.7rem;
  color: #666;
  margin-bottom: 8px;
}
.skill-desc {
  font-size: 0.75rem;
  color: #7a8a9a;
  line-height: 1.4;
}


/* ─── Utilities ──────────────────────────────────────────────────── */
.hidden { display: none !important; }
.flex-row { display: flex; gap: 10px; align-items: center; }
.ml-auto { margin-left: auto; }
.text-green { color: #2ecc71; }
.text-red   { color: #e74c3c; }
.text-gold  { color: #f39c12; }

/* ─── D-pad + mobile skills button (hidden by default) ──────────── */
#dpad, #dpad-enter { display: none; }

/* ─── Rotate overlay (portrait touch) ───────────────────────────── */
#rotate-msg {
  display: none;
  position: fixed;
  inset: 0;
  z-index: 9999;
  background: #1a1a2e;
  color: #eee;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: 40px;
  gap: 16px;
}
#rotate-inner {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
  text-align: center;
}
#rotate-icon { font-size: 3.5rem; animation: rotate-hint 2s ease-in-out infinite; }
#rotate-sub  { font-size: 0.9rem; color: #888; }
@keyframes rotate-hint {
  0%, 100% { transform: rotate(0deg); }
  40%       { transform: rotate(90deg); }
  60%       { transform: rotate(90deg); }
}

@media (orientation: portrait) {
  body.touch-device #rotate-msg { display: flex; }
}

/* ─── Landscape touch — fullscreen game ─────────────────────────── */
body.touch-device {
  padding: 0;
  overflow: hidden;
  justify-content: center;
  align-items: center;
  height: 100vh;
}
body.touch-device #game-wrapper {
  width: 100vw;
  height: 100vh;
  gap: 0;
  justify-content: center;
  align-items: center;
}
body.touch-device #game-container {
  height: 100vh;
  width: auto;
  aspect-ratio: 800 / 560;
  max-width: 100vw;
  border: none;
  border-radius: 0;
  touch-action: none;
}
body.touch-device #gameCanvas { width: 100%; height: 100%; }
body.touch-device #save-bar,
body.touch-device #tip-jar { display: none; }
body.touch-device #hud { font-size: 0.7rem; padding: 0 10px; gap: 8px; }
body.touch-device #hud-networth { display: none; }
body.touch-device #scene-content { padding: 14px; overflow-x: auto; }
body.touch-device .scene-title { font-size: 1.1rem; }
body.touch-device .inv-table { min-width: 540px; }
body.touch-device .inv-table th,
body.touch-device .inv-table td { padding: 5px 6px; font-size: 0.78rem; }

/* D-pad */
body.touch-device #dpad {
  display: grid;
  grid-template-columns: repeat(3, 54px);
  grid-template-rows: repeat(3, 54px);
  gap: 5px;
  position: absolute;
  bottom: 14px;
  left: 14px;
  z-index: 8;
  touch-action: none;
}
body.touch-device #dpad-up    { grid-column: 2; grid-row: 1; }
body.touch-device #dpad-left  { grid-column: 1; grid-row: 2; }
body.touch-device #dpad-right { grid-column: 3; grid-row: 2; }
body.touch-device #dpad-down  { grid-column: 2; grid-row: 3; }

body.touch-device #dpad button {
  background: rgba(255,255,255,0.12);
  border: 2px solid rgba(255,255,255,0.28);
  border-radius: 10px;
  color: rgba(255,255,255,0.85);
  font-size: 1.3rem;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
  cursor: pointer;
}
body.touch-device #dpad button:active { background: rgba(255,255,255,0.28); }

body.touch-device #dpad-enter {
  display: flex;
  align-items: center;
  justify-content: center;
  position: absolute;
  bottom: 14px;
  right: 14px;
  z-index: 8;
  width: 70px;
  height: 70px;
  background: rgba(46,204,113,0.18);
  border: 2px solid rgba(46,204,113,0.5);
  border-radius: 50%;
  color: rgba(255,255,255,0.85);
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0.06em;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
  cursor: pointer;
}
body.touch-device #dpad-enter:active { background: rgba(46,204,113,0.38); }

/* ─── Achievements Overlay ───────────────────────────────────────── */
#achievements-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.75);
  z-index: 200;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
}
#achievements-overlay.hidden { display: none; }
#achievements-panel {
  background: #1e2a3a;
  border: 1px solid #3a4a5a;
  border-radius: 12px;
  width: 100%;
  max-width: 720px;
  max-height: 90vh;
  overflow-y: auto;
  padding: 24px;
  box-shadow: 0 16px 48px rgba(0,0,0,0.6);
}
#achievements-panel-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  margin-bottom: 20px;
}
#achievements-panel-header h2 {
  font-size: 1.2rem;
  font-weight: 700;
  color: #f0e6c8;
  letter-spacing: 0.04em;
}
#achievements-progress {
  font-size: 0.8rem;
  color: #888;
  margin-top: 4px;
}
#achievements-close {
  background: transparent;
  border: 1px solid #555;
  color: #aaa;
  border-radius: 6px;
  padding: 4px 12px;
  cursor: pointer;
  font-size: 0.85rem;
  transition: background 0.15s;
  flex-shrink: 0;
}
#achievements-close:hover { background: #2c3e50; color: #eee; }
#achievements-grid {
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.achievement-group-header {
  font-size: 0.75rem;
  font-weight: 700;
  color: #888;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  padding: 10px 0 4px;
  border-bottom: 1px solid #2c3e50;
  margin-top: 4px;
}
.achievement-card {
  display: flex;
  align-items: center;
  gap: 14px;
  border-radius: 8px;
  padding: 10px 14px;
  border: 1px solid #2c3e50;
}
.achievement-card.unlocked {
  background: #1a2a1a;
  border-color: #27ae60;
}
.achievement-card.locked {
  background: #16202e;
  opacity: 0.55;
}
.achievement-emoji {
  font-size: 1.8rem;
  width: 36px;
  text-align: center;
  flex-shrink: 0;
}
.achievement-body { flex: 1; }
.achievement-name {
  font-size: 0.9rem;
  font-weight: 700;
  color: #e8e8e8;
}
.achievement-card.locked .achievement-name { color: #666; }
.achievement-desc {
  font-size: 0.78rem;
  color: #999;
  margin-top: 2px;
}
.achievement-day {
  font-size: 0.72rem;
  color: #27ae60;
  margin-top: 3px;
}

/* ─── Shop Tabs ──────────────────────────────────────────────────── */
.shop-tabs {
  display: flex;
  gap: 4px;
  border-bottom: 2px solid #333;
  margin-bottom: 10px;
}
.shop-tab {
  background: none;
  border: none;
  border-bottom: 3px solid transparent;
  margin-bottom: -2px;
  padding: 7px 16px;
  color: #888;
  font-size: 0.85rem;
  font-weight: 600;
  cursor: pointer;
  transition: color 0.15s, border-color 0.15s;
  white-space: nowrap;
}
.shop-tab:hover { color: #ccc; }
.shop-tab.active {
  color: #27ae60;
  border-bottom-color: #27ae60;
}
.shop-tab-count {
  font-size: 0.75rem;
  font-weight: 700;
  color: inherit;
  opacity: 0.75;
}

/* ─── Shop Upgrades ──────────────────────────────────────────────── */
.upgrade-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  gap: 8px;
  margin-top: 6px;
}
.upgrade-cat-header {
  grid-column: 1 / -1;
  font-size: 0.75rem;
  font-weight: 700;
  color: #888;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  padding: 6px 0 2px;
  border-bottom: 1px solid #333;
  margin-top: 6px;
}
.upgrade-card {
  background: #1e2a1e;
  border: 1px solid #2d3d2d;
  border-radius: 8px;
  padding: 10px 12px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.upgrade-card.owned {
  border-color: #27ae60;
  background: #1a2e1a;
  opacity: 0.8;
}
.upgrade-card.locked {
  opacity: 0.55;
}
.upgrade-card-title {
  font-size: 0.9rem;
  font-weight: 700;
  color: #e8e8e8;
}
.upgrade-card-desc {
  font-size: 0.78rem;
  color: #999;
  line-height: 1.3;
}
.upgrade-card-effect {
  font-size: 0.8rem;
  color: #2ecc71;
  font-weight: 600;
}
.upgrade-prereq {
  font-size: 0.72rem;
  color: #e67e22;
}
.upgrade-owned-badge {
  font-size: 0.8rem;
  color: #27ae60;
  font-weight: 700;
  margin-top: 4px;
}
