/* ==========================================================================
   FOURTEEN — Majnoor Dockside Dice Game Styling
   Optimized for Desktop, Mobile Phone, Tablet, and Wrapped APK
   ========================================================================== */

:root {
  --bg-deep: #0a0e14;
  --bg-panel: rgba(16, 23, 34, 0.88);
  --bg-card: rgba(22, 32, 46, 0.75);
  --border-color: rgba(70, 95, 130, 0.35);
  --border-gold: rgba(212, 175, 55, 0.4);

  --accent-gold: #d4af37;
  --accent-gold-bright: #fbbf24;
  --accent-cyan: #38bdf8;
  --accent-spore: #34d399;
  --accent-red: #ef4444;

  --text-main: #f8fafc;
  --text-muted: #94a3b8;
  --text-dim: #64748b;

  --font-serif: 'Cinzel', serif;
  --font-sans: 'Plus Jakarta Sans', -apple-system, BlinkMacSystemFont, sans-serif;
  --font-mono: 'JetBrains Mono', monospace;

  /* Mobile Safe Area Insets (iPhone notch / Android navigation bar) */
  --sat: env(safe-area-inset-top, 0px);
  --sab: env(safe-area-inset-bottom, 0px);
  --sal: env(safe-area-inset-left, 0px);
  --sar: env(safe-area-inset-right, 0px);
}

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

html, body {
  width: 100%;
  height: 100%;
  overflow: hidden;
  background-color: var(--bg-deep);
  color: var(--text-main);
  font-family: var(--font-sans);
  touch-action: manipulation;
  user-select: none;
  -webkit-user-select: none;
}

/* 3D PlayCanvas Background Canvas */
#fourteen-canvas {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  display: block;
  z-index: 1;
}

/* Responsive UI Overlay Container */
#game-ui-container {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  z-index: 10;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  pointer-events: none; /* Let clicks pass to 3D canvas where no UI exists */
  padding-top: max(12px, var(--sat));
  padding-bottom: max(16px, var(--sab));
  padding-left: max(16px, var(--sal));
  padding-right: max(16px, var(--sar));
}

/* Header & In-Universe Branding */
.fourteen-header {
  pointer-events: auto;
  display: flex;
  justify-content: space-between;
  align-items: center;
  background: linear-gradient(180deg, rgba(10, 14, 20, 0.95) 0%, rgba(10, 14, 20, 0.4) 100%);
  padding: 10px 16px;
  border-radius: 8px;
  border: 1px solid var(--border-color);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
}

.logo-box {
  display: flex;
  align-items: center;
  gap: 12px;
}

.logo-symbol {
  width: 38px;
  height: 38px;
  border-radius: 50%;
  background: radial-gradient(circle, rgba(212, 175, 55, 0.25) 0%, rgba(10, 14, 20, 0.9) 70%);
  border: 2px solid var(--accent-gold);
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 0 12px rgba(212, 175, 55, 0.3);
  position: relative;
}

.spore-ring {
  position: absolute;
  width: 100%;
  height: 100%;
  border-radius: 50%;
  border: 1px dashed rgba(56, 189, 248, 0.5);
  animation: spore-spin 20s infinite linear;
}

@keyframes spore-spin {
  from { transform: rotate(0deg); }
  to { transform: rotate(360deg); }
}

.logo-num {
  font-family: var(--font-serif);
  font-weight: 900;
  font-size: 1.15rem;
  color: var(--accent-gold-bright);
  letter-spacing: -0.05em;
}

.logo-title {
  font-family: var(--font-serif);
  font-size: 1.15rem;
  font-weight: 800;
  letter-spacing: 0.16em;
  color: #fff;
  line-height: 1.1;
}

.logo-sub {
  font-family: var(--font-mono);
  font-size: 0.62rem;
  letter-spacing: 0.18em;
  color: var(--accent-cyan);
  display: block;
}

.header-controls {
  display: flex;
  gap: 8px;
}

.icon-btn {
  background: rgba(255, 255, 255, 0.06);
  border: 1px solid var(--border-color);
  color: var(--text-muted);
  font-family: var(--font-mono);
  font-size: 0.72rem;
  font-weight: 700;
  padding: 6px 12px;
  border-radius: 4px;
  cursor: pointer;
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  transition: all 0.2s ease;
}

.icon-btn:hover, .icon-btn:active {
  background: rgba(255, 255, 255, 0.14);
  color: #fff;
  border-color: var(--accent-gold);
}

.exit-link {
  color: var(--accent-cyan) !important;
  border-color: rgba(56, 189, 248, 0.3) !important;
}

/* Main Layout Grid */
.fourteen-main {
  flex: 1;
  display: grid;
  grid-template-columns: 340px 1fr;
  gap: 16px;
  margin-top: 12px;
  margin-bottom: 12px;
  min-height: 0; /* Prevents overflow */
}

/* Left Column: Chalk Slate Panel */
.chalk-slate-panel {
  pointer-events: auto;
  background: var(--bg-panel);
  border: 1px solid var(--border-color);
  border-radius: 8px;
  padding: 16px;
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  display: flex;
  flex-direction: column;
  gap: 12px;
  box-shadow: 0 12px 32px rgba(0, 0, 0, 0.6);
  max-height: calc(100vh - 180px);
  overflow-y: auto;
}

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

.slate-badge {
  font-family: var(--font-mono);
  font-size: 0.64rem;
  letter-spacing: 0.2em;
  color: var(--accent-gold);
  font-weight: 700;
}

.slate-round {
  font-family: var(--font-mono);
  font-size: 0.72rem;
  font-weight: 700;
  color: var(--text-main);
  background: rgba(255, 255, 255, 0.08);
  padding: 2px 8px;
  border-radius: 3px;
}

/* Scoreboard Cards */
.scoreboard-cards {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.player-card {
  display: flex;
  align-items: center;
  gap: 12px;
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: 6px;
  padding: 10px 14px;
  transition: all 0.25s ease;
}

.player-card.active {
  border-color: var(--accent-gold);
  background: rgba(212, 175, 55, 0.12);
  box-shadow: 0 0 16px rgba(212, 175, 55, 0.2);
}

.player-avatar {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.08);
  border: 1px solid rgba(255, 255, 255, 0.2);
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 800;
  font-size: 1.1rem;
}

.player-info {
  flex: 1;
}

.player-role {
  font-family: var(--font-mono);
  font-size: 0.62rem;
  color: var(--text-muted);
}

.player-name {
  font-weight: 700;
  font-size: 0.95rem;
  color: #fff;
}

.player-score {
  font-family: var(--font-mono);
  font-size: 1.6rem;
  font-weight: 800;
  color: var(--accent-gold-bright);
}

/* Target & Margin Bar */
.slate-margin-bar {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 6px;
  background: rgba(10, 14, 20, 0.6);
  padding: 8px;
  border-radius: 4px;
  border: 1px solid rgba(255, 255, 255, 0.05);
}

.margin-metric {
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
}

.metric-label {
  font-family: var(--font-mono);
  font-size: 0.58rem;
  color: var(--text-dim);
  letter-spacing: 0.08em;
}

.metric-val {
  font-family: var(--font-mono);
  font-size: 0.72rem;
  font-weight: 700;
  color: var(--accent-cyan);
  margin-top: 2px;
}

/* Difficulty Selector */
.difficulty-picker-box {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-top: auto;
}

.picker-label {
  font-family: var(--font-mono);
  font-size: 0.62rem;
  letter-spacing: 0.1em;
  color: var(--text-dim);
}

.difficulty-btn-group {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 6px;
}

.diff-btn {
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid var(--border-color);
  color: var(--text-muted);
  font-family: var(--font-mono);
  font-size: 0.68rem;
  font-weight: 700;
  padding: 8px 6px;
  border-radius: 4px;
  cursor: pointer;
  transition: all 0.2s ease;
}

.diff-btn:hover {
  background: rgba(255, 255, 255, 0.1);
  color: #fff;
}

.diff-btn.active {
  background: rgba(56, 189, 248, 0.16);
  border-color: var(--accent-cyan);
  color: var(--accent-cyan);
}

/* Center Column: Tactical Live HUD & Reactive Dialogue */
.turn-center-panel {
  display: flex;
  flex-direction: column;
  justify-content: flex-start;
  align-items: flex-end;
  gap: 14px;
}

/* Opponent Dialogue Bubble */
.opponent-dialogue-bubble {
  pointer-events: auto;
  max-width: 440px;
  background: rgba(16, 23, 34, 0.92);
  border: 1px solid var(--border-color);
  border-left: 3px solid var(--accent-cyan);
  padding: 12px 16px;
  border-radius: 6px;
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  display: flex;
  align-items: flex-start;
  gap: 12px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.5);
  animation: bubble-pop 0.3s cubic-bezier(0.16, 1, 0.3, 1);
}

@keyframes bubble-pop {
  from { opacity: 0; transform: translateY(-8px); }
  to { opacity: 1; transform: translateY(0); }
}

.bubble-avatar {
  font-size: 1.4rem;
  flex-shrink: 0;
}

.bubble-content {
  flex: 1;
}

.bubble-speaker {
  font-family: var(--font-mono);
  font-size: 0.66rem;
  font-weight: 700;
  letter-spacing: 0.14em;
  color: var(--accent-cyan);
}

.bubble-text {
  font-size: 0.88rem;
  line-height: 1.45;
  color: #e2e8f0;
  margin-top: 2px;
}

/* Tactical Poisoned Gift Card */
.tactical-life-card {
  pointer-events: auto;
  width: 100%;
  max-width: 440px;
  background: var(--bg-panel);
  border: 1px solid var(--border-color);
  border-radius: 8px;
  padding: 18px;
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  box-shadow: 0 16px 40px rgba(0, 0, 0, 0.6);
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.life-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.turn-turn-badge {
  font-family: var(--font-mono);
  font-size: 0.68rem;
  font-weight: 800;
  letter-spacing: 0.18em;
  color: var(--accent-gold-bright);
  background: rgba(245, 158, 11, 0.14);
  padding: 3px 8px;
  border-radius: 3px;
  border: 1px solid rgba(245, 158, 11, 0.3);
}

.life-rolls-stream {
  font-family: var(--font-mono);
  font-size: 0.72rem;
  color: var(--text-muted);
}

/* Big Life Display */
.life-metric-cluster {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  border-bottom: 1px solid rgba(255, 255, 255, 0.08);
  padding-bottom: 10px;
}

.life-big-box {
  display: flex;
  align-items: baseline;
  gap: 4px;
}

.life-counter {
  font-family: var(--font-serif);
  font-size: 3.2rem;
  font-weight: 900;
  line-height: 1;
  color: #fff;
  transition: color 0.2s ease;
}

.life-counter.full-life {
  color: var(--accent-gold-bright);
  text-shadow: 0 0 20px rgba(245, 158, 11, 0.6);
}

.life-counter.faded {
  color: var(--accent-red);
  text-shadow: 0 0 20px rgba(239, 68, 68, 0.6);
}

.life-denom {
  font-family: var(--font-mono);
  font-size: 1.2rem;
  color: var(--text-dim);
  font-weight: 700;
}

.life-status-tag {
  font-family: var(--font-mono);
  font-size: 0.68rem;
  font-weight: 700;
  letter-spacing: 0.1em;
  color: var(--accent-cyan);
  text-align: right;
}

/* The Poisoned Gift Analysis Box */
.poisoned-gift-box {
  display: flex;
  justify-content: space-between;
  align-items: center;
  background: rgba(10, 14, 20, 0.7);
  border: 1px solid rgba(255, 255, 255, 0.06);
  border-radius: 6px;
  padding: 10px 14px;
}

.gift-col {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.gift-divider {
  font-family: var(--font-mono);
  color: var(--text-dim);
  font-size: 1.1rem;
}

.gift-label {
  font-family: var(--font-mono);
  font-size: 0.6rem;
  letter-spacing: 0.1em;
  color: var(--text-dim);
}

.gift-value {
  font-family: var(--font-mono);
  font-size: 0.82rem;
  font-weight: 700;
  color: #fff;
}

.gift-col.warning .gift-value {
  color: var(--accent-gold);
}

/* Bust Probability Gauge */
.bust-odds-bar {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.bust-odds-track {
  width: 100%;
  height: 6px;
  background: rgba(255, 255, 255, 0.08);
  border-radius: 3px;
  overflow: hidden;
}

.bust-odds-fill {
  height: 100%;
  border-radius: 3px;
  background: var(--accent-spore);
  transition: width 0.3s ease, background-color 0.3s ease;
}

.bust-odds-fill.med {
  background: var(--accent-gold);
}

.bust-odds-fill.high {
  background: var(--accent-red);
}

.bust-odds-caption {
  font-family: var(--font-mono);
  font-size: 0.64rem;
  color: var(--text-muted);
}

/* Bottom Controls Bar (Touch-First & APK Ergonomic) */
.fourteen-controls-bar {
  pointer-events: auto;
  display: flex;
  justify-content: center;
  width: 100%;
  margin-top: auto;
}

.controls-inner {
  display: flex;
  gap: 14px;
  width: 100%;
  max-width: 580px;
}

.action-btn {
  flex: 1;
  min-height: 58px;
  border-radius: 8px;
  border: 1px solid transparent;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  padding: 10px 20px;
  transition: transform 0.12s ease, box-shadow 0.15s ease, filter 0.15s ease;
}

.action-btn:active:not(.disabled) {
  transform: scale(0.97);
}

.action-icon {
  font-size: 1.6rem;
}

.action-labels {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  line-height: 1.15;
}

.action-main {
  font-family: var(--font-serif);
  font-size: 1.05rem;
  font-weight: 800;
  letter-spacing: 0.08em;
}

.action-sub {
  font-family: var(--font-mono);
  font-size: 0.64rem;
  opacity: 0.75;
  letter-spacing: 0.05em;
}

/* Roll Button Styling */
.roll-btn {
  background: linear-gradient(135deg, #0284c7 0%, #0369a1 100%);
  color: #fff;
  border-color: rgba(56, 189, 248, 0.4);
  box-shadow: 0 4px 16px rgba(2, 132, 199, 0.4);
}

.roll-btn:hover:not(.disabled) {
  filter: brightness(1.15);
  box-shadow: 0 6px 24px rgba(56, 189, 248, 0.5);
}

/* Bank Button Styling */
.bank-btn {
  background: linear-gradient(135deg, #d97706 0%, #b45309 100%);
  color: #fff;
  border-color: rgba(245, 158, 11, 0.4);
  box-shadow: 0 4px 16px rgba(217, 119, 6, 0.4);
}

.bank-btn:hover:not(.disabled) {
  filter: brightness(1.15);
  box-shadow: 0 6px 24px rgba(245, 158, 11, 0.5);
}

.action-btn.disabled, .action-btn:disabled {
  opacity: 0.35;
  filter: grayscale(0.8);
  cursor: not-allowed;
  pointer-events: none;
}

/* ==========================================================================
   Modals (Rules & Victory)
   ========================================================================== */
.modal-overlay {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(10, 14, 20, 0.85);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  animation: fade-in 0.2s ease;
}

.modal-overlay.hidden {
  display: none !important;
}

.rules-panel, .victory-panel {
  background: linear-gradient(145deg, rgba(20, 27, 40, 0.98), rgba(12, 17, 26, 0.98));
  border: 1px solid var(--border-gold);
  border-radius: 8px;
  width: 100%;
  max-width: 540px;
  padding: 24px;
  box-shadow: 0 24px 64px rgba(0, 0, 0, 0.8), 0 0 32px rgba(212, 175, 55, 0.2);
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.rules-header, .victory-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.rules-badge, .victory-badge {
  font-family: var(--font-mono);
  font-size: 0.66rem;
  letter-spacing: 0.2em;
  color: var(--accent-gold);
  font-weight: 700;
}

.modal-close-btn {
  background: none;
  border: none;
  color: var(--text-muted);
  font-size: 1.2rem;
  cursor: pointer;
}

.rules-title, .victory-title {
  font-family: var(--font-serif);
  font-size: 1.5rem;
  font-weight: 900;
  color: #fff;
  letter-spacing: 0.08em;
}

.rules-scrollable {
  max-height: 50vh;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 14px;
  padding-right: 6px;
  font-size: 0.88rem;
  line-height: 1.55;
  color: #cbd5e1;
}

.rule-block h3 {
  font-family: var(--font-serif);
  font-size: 0.88rem;
  color: var(--accent-gold);
  margin-bottom: 4px;
}

.rule-block.lore-quote {
  background: rgba(212, 175, 55, 0.08);
  border-left: 3px solid var(--accent-gold);
  padding: 8px 12px;
  border-radius: 4px;
  color: #f1f5f9;
}

.rule-block ul {
  padding-left: 18px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.modal-action-btn {
  width: 100%;
  min-height: 48px;
  background: linear-gradient(135deg, var(--accent-gold) 0%, #b45309 100%);
  color: #000;
  font-family: var(--font-serif);
  font-weight: 900;
  font-size: 0.95rem;
  letter-spacing: 0.1em;
  border: none;
  border-radius: 6px;
  cursor: pointer;
  transition: filter 0.2s ease;
}

.modal-action-btn:hover {
  filter: brightness(1.15);
}

/* Victory Modal Specifics */
.victory-scores {
  font-family: var(--font-mono);
  font-size: 2.8rem;
  font-weight: 900;
  color: var(--accent-gold-bright);
  text-align: center;
}

.victory-lead {
  font-family: var(--font-mono);
  font-size: 0.82rem;
  color: var(--text-muted);
  text-align: center;
}

.victory-quote {
  background: rgba(10, 14, 20, 0.6);
  border: 1px solid rgba(255, 255, 255, 0.06);
  padding: 12px 16px;
  border-radius: 6px;
  font-style: italic;
  font-size: 0.85rem;
  line-height: 1.5;
  color: #e2e8f0;
}

/* ==========================================================================
   Responsive Adaptations (Phone Portrait, Tablet, and Desktop)
   ========================================================================== */

/* Tablet (Medium Screens <= 1024px) */
@media (max-width: 1024px) {
  .fourteen-main {
    grid-template-columns: 280px 1fr;
    gap: 12px;
  }
}

/* Mobile Phone (Portrait Screens <= 768px) */
@media (max-width: 768px) {
  .fourteen-header {
    padding: 8px 12px;
  }

  .logo-title {
    font-size: 1rem;
  }

  .logo-sub {
    font-size: 0.54rem;
  }

  .icon-btn {
    padding: 5px 8px;
    font-size: 0.65rem;
  }

  .fourteen-main {
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    gap: 10px;
    margin-top: 6px;
    margin-bottom: 6px;
  }

  /* Compact Chalk Slate on mobile */
  .chalk-slate-panel {
    max-height: none;
    padding: 10px 12px;
    gap: 8px;
  }

  .scoreboard-cards {
    flex-direction: row;
    gap: 8px;
  }

  .player-card {
    flex: 1;
    padding: 6px 10px;
    gap: 8px;
  }

  .player-avatar {
    width: 28px;
    height: 28px;
    font-size: 0.9rem;
  }

  .player-name {
    font-size: 0.82rem;
  }

  .player-role {
    display: none;
  }

  .player-score {
    font-size: 1.25rem;
  }

  .slate-margin-bar {
    padding: 4px 6px;
  }

  .difficulty-picker-box {
    display: none; /* Accessible via header settings on small screens */
  }

  /* Center Turn Panel */
  .turn-center-panel {
    align-items: stretch;
    gap: 8px;
  }

  .opponent-dialogue-bubble {
    max-width: 100%;
    padding: 8px 12px;
  }

  .bubble-text {
    font-size: 0.78rem;
  }

  .tactical-life-card {
    max-width: 100%;
    padding: 12px 14px;
    gap: 10px;
  }

  .life-counter {
    font-size: 2.4rem;
  }

  .controls-inner {
    max-width: 100%;
    gap: 10px;
  }

  .action-btn {
    min-height: 52px;
    padding: 8px 14px;
  }

  .action-main {
    font-size: 0.95rem;
  }
}
