:root {
  --bg-1: #1a1530;
  --bg-2: #2a1f4a;
  --panel: #2d2349;
  --panel-2: #3a2c5e;
  --gold: #ffd33d;
  --gold-dark: #c79914;
  --silver: #d6d6e0;
  --copper: #c97a3a;
  --iron: #a8a8b3;
  --text: #f3edff;
  --text-dim: #b6a8d6;
  --accent: #ff5fa2;
  --green: #6dd66d;
  --red: #ff5b5b;
  --shadow: 0 6px 18px rgba(0,0,0,0.45);
}

* { box-sizing: border-box; }

html, body {
  margin: 0; padding: 0;
  background: radial-gradient(circle at 30% 0%, var(--bg-2), var(--bg-1) 70%);
  color: var(--text);
  font-family: "Noto Sans SC", "PingFang SC", -apple-system, system-ui, sans-serif;
  min-height: 100vh;
  -webkit-tap-highlight-color: transparent;
}

#topbar {
  display: flex; align-items: center; gap: 16px;
  padding: 10px 18px;
  background: rgba(0,0,0,0.25);
  border-bottom: 2px solid rgba(255,255,255,0.08);
  position: sticky; top: 0; z-index: 50;
  backdrop-filter: blur(6px);
}
.brand { font-size: 22px; font-weight: 700; }
.back-link {
  display: inline-flex; align-items: center;
  padding: 6px 12px;
  border-radius: 8px;
  background: rgba(255,255,255,0.08);
  color: var(--text);
  text-decoration: none;
  font-size: 14px;
  letter-spacing: 1px;
  transition: background 0.15s;
}
.back-link:hover { background: rgba(255,255,255,0.18); }
.hud { display: flex; gap: 14px; flex: 1; }
.hud-cell {
  display: flex; align-items: center; gap: 6px;
  padding: 4px 12px;
  background: rgba(0,0,0,0.3);
  border-radius: 10px;
  font-variant-numeric: tabular-nums;
  font-weight: 600;
}
.hud-icon { font-size: 18px; }
.actions { display: flex; gap: 8px; }
.actions button {
  border: none; background: rgba(255,255,255,0.1); color: var(--text);
  width: 38px; height: 38px; border-radius: 50%;
  font-size: 18px; cursor: pointer;
  transition: background 0.15s;
}
.actions button:hover { background: rgba(255,255,255,0.2); }

#layout {
  display: grid;
  grid-template-columns: minmax(280px, 1fr) minmax(280px, 1fr) minmax(540px, 2fr);
  grid-template-rows: auto auto;
  grid-template-areas:
    "shop upgrade stage"
    "mine slots stage";
  gap: 14px;
  padding: 14px;
  max-width: 1400px;
  margin: 0 auto;
}
#shop-panel { grid-area: shop; }
#upgrade-panel { grid-area: upgrade; }
#card-stage { grid-area: stage; min-height: 540px; }
#mine-panel { grid-area: mine; }
#slots-panel { grid-area: slots; }

@media (max-width: 1100px) {
  #layout {
    grid-template-columns: 1fr 1fr;
    grid-template-areas:
      "stage stage"
      "shop upgrade"
      "mine slots";
  }
}
@media (max-width: 640px) {
  #layout { grid-template-columns: 1fr; grid-template-areas: "stage" "shop" "upgrade" "mine" "slots"; }
}

.panel {
  background: linear-gradient(180deg, var(--panel) 0%, var(--panel-2) 100%);
  border-radius: 14px;
  padding: 14px;
  box-shadow: var(--shadow);
  border: 1px solid rgba(255,255,255,0.05);
}
.panel-title {
  margin: 0 0 10px 0;
  font-size: 16px;
  letter-spacing: 1px;
  color: var(--text-dim);
  text-transform: uppercase;
}
.hint {
  color: var(--text-dim);
  font-size: 12px;
  margin: 0 0 10px 0;
}

/* Shop cards */
#shop-cards { display: flex; flex-direction: column; gap: 10px; }
.shop-card {
  display: flex; justify-content: space-between; align-items: center;
  padding: 12px 14px;
  background: rgba(0,0,0,0.25);
  border-radius: 10px;
  border: 1px solid rgba(255,255,255,0.08);
  cursor: pointer;
  transition: transform 0.1s, background 0.15s;
}
.shop-card:hover:not(.locked):not(.disabled) {
  background: rgba(255, 211, 61, 0.15);
  transform: translateY(-1px);
}
.shop-card.locked, .shop-card.disabled { opacity: 0.5; cursor: not-allowed; }
.shop-card .name { font-weight: 700; font-size: 15px; }
.shop-card .desc { font-size: 11px; color: var(--text-dim); margin-top: 2px; }
.shop-card .price { font-size: 18px; color: var(--gold); font-weight: 700; }

/* Upgrade rows */
.upgrade-row {
  display: flex; justify-content: space-between; align-items: center;
  padding: 10px 12px;
  background: rgba(0,0,0,0.25);
  border-radius: 10px;
  margin-bottom: 8px;
}
.upgrade-row .info { flex: 1; }
.upgrade-row .title { font-weight: 600; font-size: 14px; }
.upgrade-row .meta { font-size: 11px; color: var(--text-dim); margin-top: 3px; }
.upgrade-row button {
  border: none; padding: 8px 14px; border-radius: 8px;
  background: linear-gradient(180deg, var(--gold) 0%, var(--gold-dark) 100%);
  color: #2a1900; font-weight: 700; cursor: pointer;
  font-size: 13px;
  font-variant-numeric: tabular-nums;
}
.upgrade-row button:disabled { opacity: 0.4; cursor: not-allowed; filter: grayscale(0.5); }

/* Card stage */
#stage-area {
  display: flex; align-items: center; justify-content: center;
  min-height: 480px;
  position: relative;
}
.scratch-card {
  position: relative;
  width: 460px;
  max-width: 100%;
  background: linear-gradient(135deg, #faf3e0 0%, #ffe9b3 100%);
  border-radius: 16px;
  padding: 18px;
  color: #2a1900;
  box-shadow: 0 12px 36px rgba(0,0,0,0.55);
  user-select: none;
}
.scratch-card .card-header {
  display: flex; justify-content: space-between; align-items: center;
  margin-bottom: 12px;
  border-bottom: 2px dashed rgba(0,0,0,0.2);
  padding-bottom: 8px;
}
.scratch-card .card-name { font-weight: 800; font-size: 18px; letter-spacing: 1px; }
.scratch-card .card-price { font-size: 14px; color: #8a6800; font-weight: 700; }
.scratch-card .card-desc {
  font-size: 11px; color: #6a5500;
  text-align: center;
  margin-bottom: 8px;
  line-height: 1.5;
}

.scratch-area-wrap {
  position: relative;
  border-radius: 10px;
  overflow: hidden;
  background: #fff8e6;
  margin: 8px 0;
  border: 2px dashed rgba(0,0,0,0.2);
}
.scratch-content {
  display: grid;
  padding: 10px;
  position: relative;
  z-index: 1;
}
.scratch-canvas {
  position: absolute; top: 0; left: 0;
  width: 100%; height: 100%;
  z-index: 2;
  cursor: grab; touch-action: none;
}
.scratch-canvas.revealed { pointer-events: none; opacity: 0; transition: opacity 0.4s; }

.cell {
  display: flex; align-items: center; justify-content: center;
  border: 1px solid rgba(0,0,0,0.15);
  border-radius: 6px;
  background: #fff;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  font-size: 18px;
  margin: 3px;
  min-width: 38px;
  min-height: 38px;
  position: relative;
}
.cell.target { background: linear-gradient(135deg, #ffe24a 0%, #ffb733 100%); color: #5a3500; }
.cell.dim { background: #e8e2d2; color: #888; }

.lucky-banner {
  display: flex; justify-content: center; align-items: center; gap: 10px;
  padding: 8px;
  background: linear-gradient(90deg, #fff3a8 0%, #ffd33d 100%);
  border-radius: 8px;
  margin: 6px 10px;
  font-weight: 700;
  font-size: 14px;
  color: #5a3500;
}
.lucky-banner .lucky-num {
  display: inline-flex; align-items: center; justify-content: center;
  width: 38px; height: 38px;
  background: #fff;
  border-radius: 50%;
  font-size: 22px;
  border: 2px solid #c79914;
}

.row-line { display: flex; align-items: center; gap: 8px; margin: 4px 0; }
.row-line .row-cells { display: flex; flex: 1; }
.row-line .row-prize {
  font-weight: 800; font-size: 14px;
  min-width: 70px; text-align: right;
  color: #5a3500;
  background: rgba(255, 211, 61, 0.4);
  padding: 4px 8px;
  border-radius: 6px;
}
.row-line.won .row-prize {
  background: linear-gradient(90deg, var(--gold), #ff8e3c);
  color: #2a1900;
  animation: glow 0.6s;
}
.row-line.near-miss { animation: nearMiss 0.5s; }

@keyframes glow {
  0%, 100% { transform: scale(1); }
  50% { transform: scale(1.1); box-shadow: 0 0 20px var(--gold); }
}
@keyframes nearMiss {
  0%, 100% { background: transparent; }
  50% { background: rgba(255, 91, 91, 0.25); }
}

.region {
  border: 2px solid rgba(0,0,0,0.2);
  border-radius: 8px;
  padding: 8px;
  margin: 6px 0;
  background: rgba(255,255,255,0.5);
  position: relative;
}
.region.locked { opacity: 0.35; pointer-events: none; }
.region .region-header {
  display: flex; justify-content: space-between; align-items: center;
  margin-bottom: 4px;
  font-size: 13px;
}
.region .target-badge {
  background: #fff; padding: 2px 8px;
  border-radius: 12px;
  border: 1px solid #c79914;
  font-weight: 800;
}
.region .region-prize {
  color: #c79914;
  font-weight: 800;
  font-size: 16px;
}
.region.won { border-color: var(--gold); background: linear-gradient(135deg, #fff3a8 0%, #ffe9b3 100%); }
.region .region-cells { display: flex; flex-wrap: wrap; }
.region .lock-overlay {
  position: absolute; inset: 0;
  display: flex; align-items: center; justify-content: center;
  background: rgba(0,0,0,0.1);
  font-size: 32px;
  border-radius: 6px;
  pointer-events: none;
}

.grid-content {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 4px;
  padding: 10px;
}
.targets-banner {
  display: flex; justify-content: center; gap: 8px;
  padding: 6px;
  background: linear-gradient(90deg, #fff3a8 0%, #ffd33d 100%);
  border-radius: 8px;
  margin: 6px 10px;
  font-weight: 700;
  color: #5a3500;
  font-size: 13px;
}
.targets-banner .target {
  display: inline-flex; align-items: center; justify-content: center;
  width: 36px; height: 36px;
  background: #fff;
  border-radius: 50%;
  font-size: 18px;
  border: 2px solid #c79914;
}

.card-result {
  margin-top: 12px;
  padding: 12px;
  border-radius: 10px;
  text-align: center;
  display: flex; align-items: center; justify-content: space-between;
  gap: 12px;
}
.card-result.win { background: linear-gradient(90deg, #fff8c2, var(--gold)); color: #2a1900; }
.card-result.lose { background: rgba(0,0,0,0.1); color: #6a5500; }
.card-result .result-text { font-weight: 800; font-size: 16px; flex: 1; text-align: left; }
.card-result .next-btn {
  border: none;
  background: rgba(0,0,0,0.7); color: var(--gold);
  padding: 10px 18px;
  border-radius: 8px;
  font-weight: 700;
  cursor: pointer;
  font-size: 14px;
}

.empty-stage { color: var(--text-dim); text-align: center; }

/* Mine + slots */
#ore-shop { display: flex; flex-direction: column; gap: 8px; }
.ore-row {
  display: flex; justify-content: space-between; align-items: center;
  padding: 10px 12px;
  background: rgba(0,0,0,0.25);
  border-radius: 10px;
  cursor: pointer;
  border: 1px solid rgba(255,255,255,0.06);
}
.ore-row.disabled { opacity: 0.4; cursor: not-allowed; }
.ore-row .ore-icon {
  width: 28px; height: 28px;
  border-radius: 6px;
  display: inline-block;
  vertical-align: middle;
  margin-right: 10px;
  border: 1px solid rgba(0,0,0,0.4);
}
.ore-icon.iron   { background: linear-gradient(135deg, #d6d6df 0%, #6a6a78 100%); }
.ore-icon.copper { background: linear-gradient(135deg, #ffb47a 0%, #8a4d22 100%); }
.ore-icon.silver { background: linear-gradient(135deg, #ffffff 0%, #94a3b8 100%); }
.ore-icon.gold   { background: linear-gradient(135deg, #fff3a8 0%, #c79914 100%); }
.ore-row .info { flex: 1; }
.ore-row .name { font-weight: 700; }
.ore-row .desc { font-size: 11px; color: var(--text-dim); }
.ore-row .price { color: var(--gold); font-weight: 700; }
.ore-row .stock { font-size: 11px; color: var(--text-dim); margin-left: 8px; }

#mine-slots {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 10px;
}
.slot {
  background: rgba(0,0,0,0.3);
  border: 2px dashed rgba(255,255,255,0.15);
  border-radius: 12px;
  min-height: 90px;
  padding: 10px;
  text-align: center;
  position: relative;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 6px;
}
.slot.drag-over { border-color: var(--gold); background: rgba(255, 211, 61, 0.15); }
.slot.empty { color: var(--text-dim); font-size: 12px; }
.slot .slot-ore-icon {
  width: 36px; height: 36px;
  border-radius: 8px;
  border: 1px solid rgba(0,0,0,0.4);
}
.slot .slot-yield { font-weight: 700; font-size: 16px; color: var(--gold); }
.slot .slot-collect {
  border: none; background: var(--green); color: #0a2a0a;
  padding: 4px 10px;
  border-radius: 6px;
  cursor: pointer;
  font-weight: 700;
  font-size: 12px;
}
.slot .slot-clear {
  position: absolute; top: 4px; right: 6px;
  background: transparent; border: none; color: var(--red); font-size: 16px;
  cursor: pointer;
}

/* Inventory tile (draggable) */
.inv-tile {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 4px 8px;
  background: rgba(255,255,255,0.1);
  border-radius: 6px;
  margin-left: 8px;
  cursor: grab;
  font-size: 12px;
}
.inv-tile:active { cursor: grabbing; }

/* FX layer */
#fx-layer {
  position: fixed; inset: 0;
  pointer-events: none;
  z-index: 200;
  overflow: hidden;
}
.particle {
  position: absolute;
  width: 8px; height: 8px;
  border-radius: 50%;
  background: var(--gold);
  box-shadow: 0 0 8px var(--gold);
}
.float-text {
  position: absolute;
  font-size: 28px;
  font-weight: 800;
  color: var(--gold);
  text-shadow: 0 0 12px rgba(255, 211, 61, 0.7), 2px 2px 0 #000;
  pointer-events: none;
  animation: floatUp 1.6s ease-out forwards;
}
@keyframes floatUp {
  0% { transform: translateY(0); opacity: 0; }
  20% { opacity: 1; }
  100% { transform: translateY(-90px); opacity: 0; }
}

.flash-overlay {
  position: fixed; inset: 0;
  background: rgba(255,255,255,0.85);
  pointer-events: none;
  z-index: 199;
  animation: flashFade 0.6s ease-out forwards;
}
@keyframes flashFade {
  0% { opacity: 1; }
  100% { opacity: 0; }
}

#toast {
  position: fixed; bottom: 30px; left: 50%; transform: translateX(-50%);
  background: rgba(0,0,0,0.85); color: var(--text);
  padding: 10px 20px; border-radius: 8px;
  z-index: 300;
  font-weight: 600;
}
