/**
 * Immortal Box (摸鱼开箱修仙传) - Style Sheet
 * Taoist Sanctuary, Bronze Cauldron & Celestial Looting.
 */

:root {
  --bg-dark: #080d14;
  --bg-cabinet: #111a24;
  --bg-card: #182330;
  --gold: #ffeaa7;
  --gold-dark: #d4af37;
  --cyan: #74b9ff;
  --purple: #a29bfe;
  --red: #ff7675;
  --green: #55efc4;
  --text-main: #f5f6fa;
  --text-muted: #8898aa;
  --border-subtle: rgba(255, 255, 255, 0.08);
  --font-serif: "Songti SC", "SimSun", "STSong", serif;
  --font-sans: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
}

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

body {
  background: var(--bg-dark);
  color: var(--text-main);
  font-family: var(--font-sans);
  min-height: 100vh;
  display: flex;
  justify-content: center;
  align-items: center;
  overflow-x: hidden;
  touch-action: manipulation;
}

#game-app {
  width: 100%;
  max-width: 640px;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  padding: 12px 14px 24px;
}

/* Nav Header */
#top-nav-bar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 8px 12px;
  background: var(--bg-cabinet);
  border-radius: 12px;
  border: 1px solid var(--border-subtle);
  margin-bottom: 12px;
  gap: 8px;
}

.nav-left, .nav-right {
  display: flex;
  gap: 6px;
  align-items: center;
  flex-wrap: wrap;
}

.nav-center h1 {
  font-size: 1.05rem;
  font-family: var(--font-serif);
  color: var(--gold);
  letter-spacing: 2px;
  white-space: nowrap;
}

/* Tactile Buttons */
.tactile-btn {
  background: #1e2b3a;
  color: #f5f6fa;
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: 8px;
  font-size: 0.78rem;
  padding: 6px 10px;
  cursor: pointer;
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.3);
  transition: transform 0.1s ease, background 0.15s ease, border-color 0.15s ease;
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.tactile-btn:hover {
  background: #27374a;
  border-color: rgba(255, 255, 255, 0.25);
}

.tactile-btn:active {
  transform: translateY(2px);
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.3);
}

.action-gold-btn {
  background: #b8860b;
  color: #ffffff;
  font-weight: bold;
  border-color: #ffd700;
}

.action-gold-btn:hover {
  background: #996515;
}

.action-trib-btn {
  background: #6c5ce7;
  color: #ffffff;
  font-weight: bold;
  border-color: #a29bfe;
}

.active-auto {
  background: #d63031 !important;
  border-color: #ff7675 !important;
}

/* Cabinet Container */
#main-cabinet {
  background: var(--bg-cabinet);
  border: 1px solid var(--border-subtle);
  border-radius: 16px;
  padding: 12px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.5);
}

/* Resource HUD */
#resource-hud {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 8px;
  background: rgba(10, 16, 24, 0.6);
  border-radius: 10px;
  padding: 8px 10px;
  border: 1px solid var(--border-subtle);
}

.hud-item {
  display: flex;
  flex-direction: column;
  align-items: center;
}

.hud-label {
  font-size: 0.68rem;
  color: var(--text-muted);
}

.hud-num {
  font-size: 0.95rem;
  font-weight: bold;
}

.hud-num.gold { color: var(--gold); }
.hud-num.cyan { color: var(--cyan); }
.hud-num.red { color: var(--red); }
.hud-num.purple { color: var(--purple); font-size: 0.78rem; text-align: center; }

/* EXP Section */
#exp-bar-section {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.exp-bar-header {
  display: flex;
  justify-content: space-between;
  font-size: 0.76rem;
  color: var(--text-muted);
}

.exp-track {
  width: 100%;
  height: 8px;
  background: #0d1520;
  border-radius: 4px;
  overflow: hidden;
  border: 1px solid rgba(255, 255, 255, 0.08);
}

.exp-fill {
  height: 100%;
  width: 0%;
  background: linear-gradient(90deg, #6c5ce7, #00cec9);
  transition: width 0.3s ease;
}

/* Stage Canvas */
#stage-wrapper {
  position: relative;
  width: 100%;
  aspect-ratio: 2 / 1;
  background: #080d14;
  border-radius: 12px;
  overflow: hidden;
  border: 2px solid #233142;
  box-shadow: inset 0 2px 8px rgba(0, 0, 0, 0.6);
  cursor: pointer;
}

#stage-canvas {
  width: 100%;
  height: 100%;
  display: block;
}

/* Forge Main Button */
#forge-action-area {
  display: flex;
  justify-content: center;
}

.forge-main-btn {
  width: 100%;
  padding: 12px;
  font-size: 1.05rem;
  font-weight: bold;
  background: linear-gradient(135deg, #b8860b, #e67e22);
  border-color: #ffd700;
  color: #fff;
  border-radius: 12px;
  box-shadow: 0 4px 12px rgba(184, 134, 11, 0.35);
}

.forge-main-btn:hover {
  background: linear-gradient(135deg, #cd853f, #d35400);
}

/* Loot Comparison Card */
.loot-card {
  background: var(--bg-card);
  border: 2px solid var(--gold);
  border-radius: 14px;
  padding: 12px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  box-shadow: 0 6px 18px rgba(0, 0, 0, 0.4);
}

.loot-card.hidden {
  display: none;
}

.loot-card-header {
  display: flex;
  align-items: center;
  gap: 10px;
}

.loot-icon {
  font-size: 2rem;
}

.loot-name {
  font-size: 1rem;
  font-weight: bold;
}

.loot-cp-text {
  font-size: 0.8rem;
  color: var(--gold);
}

.loot-stats-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 6px;
  background: rgba(10, 16, 24, 0.5);
  padding: 8px;
  border-radius: 8px;
}

.stat-compare-row {
  display: flex;
  justify-content: space-between;
  font-size: 0.78rem;
}

.stat-up { color: #55efc4; font-weight: bold; }
.stat-down { color: #ff7675; }
.stat-same { color: #8898aa; }

.loot-affixes-row {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.affix-chip {
  background: rgba(162, 155, 254, 0.15);
  color: #a29bfe;
  border: 1px solid rgba(162, 155, 254, 0.3);
  border-radius: 6px;
  padding: 3px 6px;
  font-size: 0.72rem;
}

.loot-actions {
  display: flex;
  gap: 10px;
}

.equip-action-btn {
  flex: 1;
  background: #27ae60;
  border-color: #2ecc71;
  font-weight: bold;
  padding: 9px;
}

.smelt-action-btn {
  flex: 1;
  background: #c0392b;
  border-color: #e74c3c;
  font-weight: bold;
  padding: 9px;
}

/* 8-Slot Equipment Matrix */
.equipment-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 8px;
}

.equip-slot {
  background: var(--bg-card);
  border: 1.5px solid var(--border-subtle);
  border-radius: 10px;
  padding: 8px 4px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 4px;
  min-height: 58px;
}

.slot-icon {
  font-size: 1.25rem;
}

.slot-item-name {
  font-size: 0.68rem;
  font-weight: bold;
  text-align: center;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 100%;
}

.slot-empty-label {
  font-size: 0.62rem;
  color: var(--text-muted);
}

/* Affixes Summary Bar */
.affixes-bar {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 6px;
  background: rgba(10, 16, 24, 0.5);
  padding: 8px;
  border-radius: 10px;
}

.affix-summary-chip {
  display: flex;
  justify-content: space-between;
  font-size: 0.72rem;
  background: #16202c;
  padding: 4px 6px;
  border-radius: 6px;
  border: 1px solid var(--border-subtle);
}

.chip-name { color: var(--text-muted); }
.chip-val { color: var(--gold); font-weight: bold; }

/* Modals */
.oriental-modal {
  margin: auto;
  border: none;
  background: transparent;
  padding: 0;
  max-width: 90vw;
  width: 480px;
}

.oriental-modal::backdrop {
  background: rgba(5, 8, 12, 0.85);
  backdrop-filter: blur(4px);
}

.modal-box {
  background: var(--bg-cabinet);
  border: 1px solid rgba(255, 255, 255, 0.15);
  border-radius: 16px;
  padding: 20px;
  box-shadow: 0 12px 36px rgba(0, 0, 0, 0.6);
  color: var(--text-main);
}

.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 14px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.1);
  padding-bottom: 8px;
}

.modal-header h2 {
  font-family: var(--font-serif);
  font-size: 1.15rem;
  color: var(--gold);
}

.modal-close-x {
  background: transparent;
  border: none;
  color: var(--text-muted);
  font-size: 1.2rem;
  cursor: pointer;
  padding: 4px;
}

.modal-tip {
  font-size: 0.8rem;
  color: var(--text-muted);
  margin-bottom: 12px;
  line-height: 1.4;
}

.boss-preview-card {
  background: var(--bg-card);
  border-radius: 10px;
  padding: 12px;
  margin: 10px 0;
  border: 1px solid var(--border-subtle);
}

.boss-preview-card h3 {
  color: var(--red);
  margin-bottom: 4px;
}

.combat-log-container {
  max-height: 200px;
  overflow-y: auto;
  background: #080d14;
  border-radius: 8px;
  padding: 8px;
  margin-top: 10px;
  text-align: left;
  font-size: 0.74rem;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.combat-summary-banner {
  padding: 8px;
  border-radius: 6px;
  font-weight: bold;
  text-align: center;
}

.combat-summary-banner.victory {
  background: rgba(46, 204, 113, 0.2);
  color: #2ecc71;
  border: 1px solid #2ecc71;
}

.combat-summary-banner.defeat {
  background: rgba(231, 76, 60, 0.2);
  color: #e74c3c;
  border: 1px solid #e74c3c;
}

.combat-log-line {
  color: var(--text-muted);
}

.actor-player { color: var(--cyan); font-weight: bold; }
.actor-boss { color: var(--red); font-weight: bold; }

.cauldron-rates-box {
  margin-top: 14px;
  background: #0a1018;
  padding: 10px;
  border-radius: 8px;
}

.cauldron-rates-box h4 {
  font-size: 0.8rem;
  color: var(--gold);
  margin-bottom: 8px;
}

.rates-list {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 6px;
  font-size: 0.76rem;
}

.rate-row {
  display: flex;
  justify-content: space-between;
}

.setting-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin: 12px 0;
  font-size: 0.84rem;
}

.form-select {
  background: #1e2b3a;
  color: #fff;
  border: 1px solid rgba(255, 255, 255, 0.2);
  padding: 6px 10px;
  border-radius: 6px;
}

.offline-icon {
  font-size: 2.5rem;
  margin-bottom: 8px;
}

.offline-reward-box {
  background: var(--bg-card);
  padding: 12px;
  border-radius: 10px;
  margin: 12px 0;
  display: flex;
  justify-content: space-around;
  font-size: 0.95rem;
}

.text-center { text-align: center; }

/* Custom Scrollbars */
.rules-scroll::-webkit-scrollbar,
.combat-log-container::-webkit-scrollbar {
  width: 6px;
}

.rules-scroll::-webkit-scrollbar-track,
.combat-log-container::-webkit-scrollbar-track {
  background: #080d14;
}

.rules-scroll::-webkit-scrollbar-thumb,
.combat-log-container::-webkit-scrollbar-thumb {
  background: #233142;
  border-radius: 3px;
}

/* Mobile Responsiveness & Safe Area Inset */
@media (max-width: 768px) {
  #game-app {
    padding-bottom: max(68px, calc(16px + env(safe-area-inset-bottom)));
  }

  .tactile-btn {
    padding: 5px 8px;
    font-size: 0.72rem;
  }
}

/* Reduced Motion */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
    scroll-behavior: auto !important;
  }
}
