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

body {
  background-color: #0d0a08;
  color: #f5eedb;
  font-family: 'Cinzel', 'Trajan Pro', 'Georgia', serif;
  overflow: hidden;
  height: 100vh;
  width: 100vw;
  display: flex;
  justify-content: center;
  align-items: center;
}

#game-container {
  width: 100vw;
  height: 100vh;
  max-width: 1920px;
  max-height: 1080px;
  display: grid;
  grid-template-columns: 460px 1fr 480px;
  gap: 16px;
  padding: 16px;
  background: radial-gradient(circle at 50% 50%, #1a120c 0%, #0d0a08 100%);
  position: relative;
}

/* Left Panel */
.panel {
  background: rgba(22, 16, 12, 0.85);
  border: 2px solid #5a3e23;
  border-radius: 8px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.7);
  display: flex;
  flex-direction: column;
  padding: 14px;
  overflow: hidden;
}

.economy-header {
  border-bottom: 2px solid #5a3e23;
  padding-bottom: 10px;
  margin-bottom: 12px;
}

.gold-text {
  font-size: 26px;
  font-weight: bold;
  color: #ffcc00;
  text-shadow: 0 0 10px rgba(255, 204, 0, 0.4);
}

.dps-text {
  font-size: 15px;
  color: #e0b865;
  margin-top: 2px;
}

.sp-text {
  font-size: 20px;
  font-weight: bold;
  color: #55c2f5;
  margin-top: 4px;
}

.caravan-view {
  width: 100%;
  height: 240px;
  background: url('assets/concept_art/caravan_bg.png') center/cover no-repeat;
  border: 2px solid #845e34;
  border-radius: 8px;
  cursor: pointer;
  position: relative;
  transition: transform 0.05s ease;
  overflow: hidden;
}

.caravan-view:hover {
  filter: brightness(1.08);
}

.caravan-view:active {
  transform: scale(0.97);
}

.caravan-hint {
  position: absolute;
  bottom: 8px;
  left: 0;
  right: 0;
  text-align: center;
  font-size: 12px;
  background: rgba(0, 0, 0, 0.6);
  color: #ffdd88;
  padding: 4px;
}

.tabs-row {
  display: flex;
  gap: 8px;
  margin: 12px 0 8px 0;
}

.tab-btn {
  flex: 1;
  padding: 8px;
  background: #2a1c12;
  border: 1px solid #73502b;
  color: #e6c89c;
  font-weight: bold;
  cursor: pointer;
  border-radius: 4px;
}

.tab-btn.active {
  background: #5a3717;
  border-color: #e0a340;
  color: #fff;
}

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

.building-item {
  display: flex;
  align-items: center;
  background: rgba(45, 30, 20, 0.7);
  border: 1px solid #634327;
  border-radius: 6px;
  padding: 8px;
  gap: 10px;
}

.b-icon {
  width: 48px;
  height: 48px;
  object-fit: contain;
  background: rgba(0, 0, 0, 0.4);
  border-radius: 4px;
  border: 1px solid #875c35;
}

.b-info {
  flex: 1;
}

.b-name {
  font-size: 14px;
  font-weight: bold;
  color: #f7dfb8;
}

.b-lvl {
  font-size: 12px;
  color: #b0997e;
}

.b-buy-btn {
  background: linear-gradient(180deg, #3d6a2a 0%, #204514 100%);
  border: 1px solid #62a344;
  color: #e5ffcc;
  padding: 8px 12px;
  font-weight: bold;
  font-size: 13px;
  border-radius: 4px;
  cursor: pointer;
  min-width: 105px;
  text-align: center;
}

.b-buy-btn:disabled {
  background: #332b25;
  border-color: #55483e;
  color: #7a6e64;
  cursor: not-allowed;
}

/* Center Panel (Board & Cards) */
.center-panel {
  display: flex;
  flex-direction: column;
  align-items: center;
  position: relative;
}

.game-title {
  font-size: 30px;
  font-weight: 900;
  color: #ffd269;
  text-shadow: 0 0 15px rgba(255, 190, 60, 0.6), 2px 2px 4px #000;
  letter-spacing: 2px;
  text-align: center;
  margin-bottom: 6px;
}

.status-bar {
  display: flex;
  justify-content: space-between;
  width: 580px;
  margin-bottom: 8px;
  font-size: 16px;
}

.wave-tag {
  color: #ff5555;
  font-weight: bold;
}

.moves-tag {
  color: #55ff77;
  font-weight: bold;
}

.battle-banner {
  width: 580px;
  background: rgba(18, 12, 8, 0.9);
  border: 1px solid #774f2b;
  padding: 6px 12px;
  border-radius: 4px;
  color: #ffea9f;
  text-align: center;
  font-size: 14px;
  margin-bottom: 10px;
}

.grid-board {
  width: 560px;
  height: 560px;
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  grid-template-rows: repeat(5, 1fr);
  gap: 8px;
  background: #19110b;
  border: 4px solid #5a3c20;
  border-radius: 12px;
  padding: 8px;
  box-shadow: inset 0 0 30px rgba(0, 0, 0, 0.9), 0 10px 30px rgba(0, 0, 0, 0.8);
}

.cell {
  background: #2b1f17;
  border: 1px solid #4a3423;
  border-radius: 6px;
  position: relative;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  transition: all 0.15s ease;
}

.cell.light {
  background: #36281e;
}

.cell.danger {
  background: rgba(180, 25, 25, 0.45);
  border: 2px solid #ff3333;
  box-shadow: inset 0 0 15px rgba(255, 0, 0, 0.5);
  animation: pulse-red 1.2s infinite alternate;
}

.cell.valid-move {
  background: rgba(40, 160, 60, 0.45);
  border: 2px solid #55ff77;
  box-shadow: inset 0 0 18px rgba(50, 255, 100, 0.6);
  cursor: crosshair;
}

@keyframes pulse-red {
  from { box-shadow: inset 0 0 10px rgba(255, 0, 0, 0.4); }
  to { box-shadow: inset 0 0 20px rgba(255, 0, 0, 0.8); }
}

.unit-sprite {
  max-width: 80%;
  max-height: 70%;
  object-fit: contain;
  filter: drop-shadow(0 4px 6px #000);
}

.unit-label {
  font-size: 11px;
  color: #ffdc88;
  text-shadow: 1px 1px 3px #000;
  text-align: center;
}

.unit-hp {
  font-size: 10px;
  color: #ff7777;
  font-weight: bold;
}

.end-turn-btn {
  margin-top: 10px;
  padding: 8px 24px;
  background: linear-gradient(180deg, #6e361c 0%, #3e1b0c 100%);
  border: 1px solid #c76735;
  color: #ffd0b0;
  font-weight: bold;
  font-size: 14px;
  border-radius: 4px;
  cursor: pointer;
}

/* Hand Cards Area */
.cards-hand {
  display: flex;
  gap: 16px;
  margin-top: 14px;
  justify-content: center;
}

.card {
  width: 125px;
  height: 175px;
  background: linear-gradient(180deg, #2b1f17 0%, #150e09 100%);
  border: 2px solid #7c5731;
  border-radius: 8px;
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 8px;
  cursor: pointer;
  box-shadow: 0 6px 16px rgba(0, 0, 0, 0.6);
  transition: transform 0.15s ease, border-color 0.15s ease;
  position: relative;
}

.card:hover {
  transform: translateY(-8px);
  border-color: #ffd060;
}

.card.selected {
  transform: translateY(-12px);
  border-color: #ffee33;
  box-shadow: 0 0 25px rgba(255, 230, 50, 0.7);
}

.card.rarity-sun {
  border-color: #ffaa00;
  background: linear-gradient(180deg, #3d2c0b 0%, #1a1203 100%);
  box-shadow: 0 0 15px rgba(255, 170, 0, 0.5);
}

.card-title {
  font-size: 12px;
  font-weight: bold;
  text-align: center;
  color: #ffea9f;
  margin-bottom: 4px;
}

.card-icon {
  width: 60px;
  height: 60px;
  object-fit: contain;
  margin: auto 0;
}

.card-cost {
  font-size: 11px;
  color: #88ff99;
}

/* Right Panel (Character & Silkroad) */
.char-header {
  display: flex;
  gap: 14px;
  border-bottom: 2px solid #5a3e23;
  padding-bottom: 12px;
}

.char-avatar {
  width: 100px;
  height: 120px;
  border: 2px solid #845e34;
  border-radius: 6px;
  object-fit: cover;
  background: #110b07;
}

.char-stats {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.char-name {
  font-size: 18px;
  font-weight: bold;
  color: #ffd777;
}

.char-lvl {
  font-size: 14px;
  color: #b0997e;
}

.bar-container {
  width: 100%;
  height: 20px;
  background: #20150e;
  border: 1px solid #553a23;
  border-radius: 4px;
  position: relative;
  overflow: hidden;
}

.bar-fill {
  height: 100%;
  transition: width 0.2s ease;
}

.bar-fill.hp {
  background: linear-gradient(90deg, #a61c1c 0%, #ff4444 100%);
}

.bar-fill.mp {
  background: linear-gradient(90deg, #184da3 0%, #3a85ff 100%);
}

.bar-fill.route {
  background: linear-gradient(90deg, #b8860b 0%, #ffd700 100%);
}

.bar-text {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 11px;
  font-weight: bold;
  color: #fff;
  text-shadow: 1px 1px 2px #000;
}

.jobs-selector {
  display: flex;
  gap: 6px;
  margin-top: 10px;
}

.job-btn {
  flex: 1;
  padding: 6px 4px;
  background: #2b1f17;
  border: 1px solid #634327;
  color: #ffd090;
  font-size: 11px;
  font-weight: bold;
  border-radius: 4px;
  cursor: pointer;
}

.job-btn.active {
  background: #6e401b;
  border-color: #ffd060;
  color: #fff;
}

.sub-box {
  margin-top: 12px;
  background: rgba(30, 20, 14, 0.7);
  border: 1px solid #634327;
  border-radius: 6px;
  padding: 10px;
}

.sub-title {
  font-size: 14px;
  font-weight: bold;
  color: #ffde88;
  margin-bottom: 6px;
}

.rarity-badges {
  display: flex;
  gap: 6px;
  margin-bottom: 8px;
}

.badge {
  padding: 2px 8px;
  font-size: 11px;
  font-weight: bold;
  border-radius: 3px;
}

.badge.sos { background: #5a1980; color: #ff99ff; border: 1px solid #c240ff; }
.badge.som { background: #164f80; color: #7ad0ff; border: 1px solid #3fa2ff; }
.badge.sun { background: #805c10; color: #ffea70; border: 1px solid #ffd030; }

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

.inv-slot {
  width: 50px;
  height: 50px;
  background: #19110b;
  border: 2px solid #5a3e23;
  border-radius: 4px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.inv-slot.tier-sos { border-color: #b840ff; box-shadow: 0 0 8px rgba(184, 64, 255, 0.4); }
.inv-slot.tier-som { border-color: #40a0ff; box-shadow: 0 0 8px rgba(64, 160, 255, 0.4); }
.inv-slot.tier-sun { border-color: #ffc400; box-shadow: 0 0 10px rgba(255, 196, 0, 0.6); }

.inv-item-img {
  width: 40px;
  height: 40px;
  object-fit: contain;
}

.chest-action-btn {
  width: 100%;
  padding: 12px;
  background: linear-gradient(180deg, #996e1b 0%, #593c09 100%);
  border: 1px solid #e0b040;
  color: #fff4d0;
  font-weight: bold;
  font-size: 15px;
  border-radius: 6px;
  cursor: pointer;
  margin-top: 8px;
  text-shadow: 1px 1px 2px #000;
}

.rebirth-btn {
  width: 100%;
  padding: 12px;
  background: linear-gradient(180deg, #8a1f1f 0%, #4a0d0d 100%);
  border: 1px solid #d44d4d;
  color: #ffcccc;
  font-weight: bold;
  font-size: 14px;
  border-radius: 6px;
  cursor: pointer;
  margin-top: auto;
}

/* Floating Click/Damage Numbers */
.floating-num {
  position: absolute;
  pointer-events: none;
  font-weight: 900;
  font-size: 24px;
  animation: float-up 0.9s forwards ease-out;
  text-shadow: 2px 2px 4px #000;
  z-index: 9999;
}

@keyframes float-up {
  0% { transform: translateY(0) scale(0.9); opacity: 1; }
  100% { transform: translateY(-70px) scale(1.15); opacity: 0; }
}
