@import url('https://fonts.googleapis.com/css2?family=Cinzel:wght@500;700;900&family=Crimson+Pro:ital,wght@0,400;0,700;1,400&family=Outfit:wght@400;600;900&display=swap');

:root {
  --bg-dark: #0a0a0c;
  --surface-dark: #16151a;
  --surface-panel: rgba(20, 18, 24, 0.85);
  --border-gold: #c0a062;
  --border-dark: #2a2530;
  --text-main: #eeddcc;
  --text-muted: #8a7a8c;
  --accent-red: #8B0000;
  --accent-glow: rgba(183, 28, 28, 0.6);
  --green: #34C759;
  --yellow: #FFD60A;
}

html, body {
  margin: 0;
  padding: 0;
  width: 100%;
  height: 100%;
  background-color: var(--bg-dark);
  color: var(--text-main);
  font-family: 'Outfit', sans-serif;
  overflow: hidden;
}

* { box-sizing: border-box; }

/* ═══ Dynamic Background ═══ */
.rpg-bg {
  position: fixed;
  top: -20px; left: -20px; right: -20px; bottom: -20px;
  background-image: url('/static/img/characters/bigd.jpg');
  background-size: cover;
  background-position: center;
  filter: blur(30px) brightness(0.2) saturate(1.3);
  z-index: 0;
  transition: background-image 1s ease;
}
.rpg-bg-overlay {
  position: fixed;
  top: 0; left: 0; width: 100%; height: 100%;
  background: radial-gradient(ellipse at 30% 50%, transparent 0%, var(--bg-dark) 80%);
  z-index: 1;
}

/* ═══ APP LAYOUT — strict 100vh 3-column grid ═══ */
.app-layout {
  position: relative;
  z-index: 2;
  display: grid;
  grid-template-columns: 280px 1fr 300px;
  grid-template-rows: 1fr;
  gap: 20px;
  padding: 20px;
  width: 100%;
  height: 100vh;
  max-width: 1500px;
  margin: 0 auto;
  overflow: hidden;
}

/* ═══ LEFT COLUMN ═══ */
.rpg-left {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center; /* vertically center the card */
  min-height: 0; /* prevent flex overflow */
}

/* Portrait Card Frame */
.portrait-frame {
  position: relative;
  width: 100%;
  max-height: 80vh; /* never taller than viewport */
  aspect-ratio: 3/4;
  background: var(--surface-dark);
  border: 4px solid var(--border-gold);
  border-radius: 12px;
  box-shadow:
    0 0 40px rgba(0,0,0,0.9),
    inset 0 0 20px rgba(0,0,0,0.8),
    0 0 15px rgba(192, 160, 98, 0.15);
  overflow: hidden;
  flex-shrink: 1; /* allow it to shrink if needed */
}
.portrait-frame::before {
  content: '';
  position: absolute;
  top: 8px; left: 8px; right: 8px; bottom: 8px;
  border: 1px dashed rgba(192, 160, 98, 0.35);
  z-index: 2;
  pointer-events: none;
}
.portrait-img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  transition: 0.5s ease;
}
.portrait-name-plate {
  position: absolute;
  bottom: 0; left: 0; right: 0;
  background: linear-gradient(to top, rgba(0,0,0,0.95) 30%, transparent);
  padding: 40px 12px 16px;
  text-align: center;
  z-index: 3;
}
.p-name {
  font-family: 'Cinzel', serif;
  font-size: 1.6rem;
  font-weight: 900;
  color: var(--border-gold);
  letter-spacing: 2px;
  text-shadow: 2px 2px 6px #000;
  margin-bottom: 2px;
  text-transform: uppercase;
}
.p-sub {
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 1px;
}
.pin-top {
  position: absolute;
  top: -8px; left: 50%;
  transform: translateX(-50%);
  width: 16px; height: 16px;
  background: #B71C1C;
  border-radius: 50%;
  box-shadow: 1px 3px 6px rgba(0,0,0,0.6), inset -1px -1px 4px rgba(0,0,0,0.4);
  z-index: 10;
}

/* ═══ MIDDLE COLUMN ═══ */
.rpg-center {
  display: flex;
  flex-direction: column;
  background: var(--surface-panel);
  border: 1px solid var(--border-dark);
  border-radius: 16px;
  backdrop-filter: blur(12px);
  padding: 24px;
  box-shadow: 0 8px 30px rgba(0,0,0,0.5);
  min-height: 0; /* critical: allow flex children to shrink */
  overflow: hidden; /* don't let it spill outside the grid cell */
}
.rpg-header {
  flex-shrink: 0;
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 16px;
}
.rpg-logo {
  font-family: 'Cinzel', serif;
  font-size: 2rem;
  font-weight: 900;
  color: #fff;
  text-shadow: 0 0 8px rgba(255, 60, 0, 0.5);
  display: flex;
  align-items: center;
  gap: 10px;
}
.rpg-logo span { font-size: 1.6rem; }

/* Views */
.view-panel {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 0;
  overflow-y: auto;
  overflow-x: hidden;
  scrollbar-width: none; /* Firefox */
  -ms-overflow-style: none; /* IE/Edge */
}
.view-panel::-webkit-scrollbar { display: none; } /* Chrome/Safari */
#view-home.view-panel {
  justify-content: center;
  align-items: center;
}

.hidden { display: none !important; }

/* Mode Menu (Home) */
.mode-menu {
  display: flex;
  flex-direction: column;
  gap: 16px;
  width: 100%;
  align-items: center;
}
.btn-rpg {
  width: 100%;
  max-width: 420px;
  padding: 14px 20px;
  background: linear-gradient(180deg, #2a2530 0%, #1a1620 100%);
  border: 2px solid var(--border-gold);
  border-radius: 8px;
  color: var(--border-gold);
  font-family: 'Outfit', 'PingFang SC', sans-serif;
  font-size: 1rem;
  font-weight: 800;
  letter-spacing: 1px;
  cursor: pointer;
  transition: 0.2s;
  box-shadow: 0 4px 10px rgba(0,0,0,0.6);
  position: relative;
  overflow: hidden;
}
.btn-rpg::before {
  content: '';
  position: absolute;
  top: 0; left: -100%; width: 50%; height: 100%;
  background: linear-gradient(to right, transparent, rgba(192, 160, 98, 0.2), transparent);
  transform: skewX(-20deg);
  transition: 0.6s;
}
.btn-rpg:hover {
  transform: translateY(-2px);
  box-shadow: 0 0 20px rgba(192, 160, 98, 0.25);
}
.btn-rpg:hover::before { left: 200%; }
.btn-rpg:active { transform: translateY(1px); }

/* Language Selector */
.rpg-select {
  background: #111;
  color: var(--text-main);
  border: 1px solid var(--border-dark);
  padding: 10px;
  font-family: inherit;
  font-size: 0.95rem;
  border-radius: 8px;
  width: 100%;
  max-width: 420px;
  margin: 0 auto 16px;
  display: block;
  text-align: center;
  outline: none;
}

/* ─── Lesson Card ─── */
.lesson-card {
  flex-shrink: 0;
  border: 2px solid var(--accent-red);
  background: rgba(40, 10, 15, 0.4);
  border-radius: 12px;
  padding: 20px;
  box-shadow: inset 0 0 30px rgba(139, 0, 0, 0.1);
}
.lesson-text {
  font-family: 'Crimson Pro', serif;
  font-size: 1.6rem;
  font-weight: 700;
  line-height: 1.4;
  color: #fff;
  margin-bottom: 10px;
}
.lesson-cn {
  font-size: 0.9rem;
  color: #aaa;
  font-style: italic;
  font-family: 'Outfit', sans-serif;
  border-top: 1px solid rgba(255,255,255,0.1);
  padding-top: 10px;
  line-height: 1.5;
}

/* ─── Unified Player Script Card (all modes) ─── */
.player-script {
  border: 2px solid var(--border-gold);
  background: rgba(15, 10, 25, 0.85);
  border-radius: 12px;
  padding: 20px 24px;
  max-width: 700px;
  margin: 0 auto 16px;
  box-shadow: 0 0 25px rgba(192,160,98,0.1), inset 0 0 30px rgba(0,0,0,0.3);
}
.player-script-label {
  font-family: 'Cinzel', serif;
  font-weight: 900;
  font-size: 0.8rem;
  color: var(--border-gold);
  letter-spacing: 2px;
  margin-bottom: 8px;
}
.player-script-text {
  font-family: 'Crimson Pro', serif;
  font-size: 1.5rem;
  font-weight: 700;
  line-height: 1.5;
  color: #FFD60A;
  text-shadow: 0 0 12px rgba(255,214,10,0.3);
  margin-bottom: 8px;
}
.player-script-cn {
  font-family: 'Outfit', 'PingFang SC', sans-serif;
  font-size: 0.85rem;
  color: #aaa;
  font-style: italic;
  border-top: 1px solid rgba(192,160,98,0.15);
  padding-top: 8px;
  line-height: 1.5;
}

/* Waveform */
.waveform-container {
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 4px;
  height: 80px;
  flex-shrink: 0;
  margin: 24px 0;
}
.wave-bar {
  width: 6px;
  background: linear-gradient(to top, #B71C1C, #FFD60A);
  border-radius: 4px;
  animation: wave 1s infinite alternate ease-in-out;
  opacity: 0.2;
}
.wave-bar.active { opacity: 1; }
@keyframes wave {
  0% { height: 10px; }
  100% { height: 75px; }
}

/* Prompt */
.your-turn-prompt {
  text-align: center;
  font-family: 'Cinzel', serif;
  color: #FFD60A;
  font-size: 1.2rem;
  font-weight: 900;
  letter-spacing: 2px;
  text-shadow: 0 0 15px rgba(255, 214, 10, 0.6);
  animation: prompt-pulse 1s infinite alternate;
  margin: 10px 0 16px;
  flex-shrink: 0;
}
@keyframes prompt-pulse {
  from { transform: scale(1); opacity: 0.8; }
  to { transform: scale(1.05); opacity: 1; }
}

/* AI Chat Log */
.ai-reaction {
  background: rgba(20, 20, 25, 0.6);
  border: 1px solid var(--border-dark);
  padding: 14px;
  border-radius: 8px;
  font-family: 'Crimson Pro', serif;
  font-size: 1.15rem;
  color: #ddd;
  line-height: 1.5;
  flex: 1;
  min-height: 60px;
  overflow-y: auto;
}
/* Alias for old class */
.chat-bubble {
  background: rgba(20, 20, 25, 0.6);
  border: 1px solid var(--border-dark);
  padding: 14px;
  border-radius: 8px;
  font-family: 'Crimson Pro', serif;
  font-size: 1.15rem;
  color: #ddd;
  line-height: 1.5;
  margin-bottom: 8px;
}
.chat-bubble.streaming { border-left: 3px solid var(--border-gold); }

/* Score */
.score-container {
  text-align: center;
  flex-shrink: 0;
}
.score-num {
  font-family: 'Cinzel', serif;
  font-size: 1.5rem;
  font-weight: 900;
  color: var(--border-gold);
  margin-bottom: 6px;
}
.score-big.pass { color: var(--green); }
.score-big.fail { color: #FF5252; }
.score-bar-bg {
  height: 8px;
  background: #222;
  border-radius: 4px;
  overflow: hidden;
}
.score-bar-fill {
  height: 100%;
  width: 0%;
  background: linear-gradient(to right, #B71C1C, #FFD60A);
  transition: width 0.5s ease-out;
}

/* Lesson Bottom Actions */
.lesson-actions {
  display: flex;
  justify-content: center;
  gap: 16px;
  align-items: center;
  flex-shrink: 0;
  padding: 12px 0 4px;
}
.rec-orb {
  width: 70px;
  height: 70px;
  background: radial-gradient(circle, var(--accent-red) 30%, #400000 100%);
  border: 2px solid var(--border-gold);
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  color: #fff;
  font-weight: 900;
  font-size: 0.75rem;
  cursor: pointer;
  box-shadow: 0 0 20px var(--accent-glow);
  transition: 0.2s;
  user-select: none;
  flex-shrink: 0;
}
.rec-orb:hover { transform: scale(1.08); }
.rec-orb.recording {
  background: #FFD60A;
  color: #000;
  animation: pulse-rec 1s infinite alternate;
}
@keyframes pulse-rec {
  from { box-shadow: 0 0 20px rgba(255, 214, 10, 0.4); }
  to { box-shadow: 0 0 40px rgba(255, 214, 10, 1); }
}
.action-btn {
  background: transparent;
  color: var(--text-muted);
  border: none;
  font-size: 0.9rem;
  font-family: 'Outfit', sans-serif;
  font-weight: 600;
  cursor: pointer;
  padding: 8px 14px;
  transition: 0.2s;
}
.action-btn:hover { color: #fff; }

/* ═══ RIGHT COLUMN ═══ */
.rpg-right {
  display: flex;
  flex-direction: column;
  gap: 16px;
  min-height: 0; /* critical */
  overflow: hidden;
}

/* Stats Panel */
.right-panel {
  background: var(--surface-panel);
  border: 1px solid var(--border-dark);
  border-radius: 12px;
  padding: 14px 16px;
  backdrop-filter: blur(10px);
  flex-shrink: 0;
}
.stat-item {
  display: flex;
  justify-content: space-between;
  margin-bottom: 4px;
  font-family: 'Outfit', 'PingFang SC', sans-serif;
  font-size: 0.75rem;
  color: var(--text-main);
}
.stat-val { font-weight: 900; font-size: 0.8rem; }
.stat-bar { height: 4px; background:#222; border-radius:2px; margin-bottom:10px; }
.stat-bar:last-child { margin-bottom: 0; }
.stat-bar-f { height: 100%; background: var(--border-gold); border-radius:2px; width: 0%; transition:1s;}

/* ─── Roster Panel ─── */
.roster-panel {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 0; /* critical for scroll */
  overflow: hidden;
}
.roster-header {
  display: flex;
  gap: 8px;
  margin-bottom: 12px;
  flex-shrink: 0;
}
.roster-tab {
  flex: 1;
  background: #111;
  border: 1px solid var(--border-dark);
  color: var(--text-muted);
  font-family: 'Outfit', sans-serif;
  font-size: 0.7rem;
  font-weight: 800;
  letter-spacing: 1px;
  padding: 6px 0;
  cursor: pointer;
  border-radius: 6px;
  transition: 0.2s;
  text-transform: uppercase;
}
.roster-tab.active {
  background: var(--surface-dark);
  border-color: var(--border-gold);
  color: var(--border-gold);
}
.roster-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  grid-auto-rows: max-content;
  gap: 12px;
  overflow-y: auto;
  flex: 1;
  min-height: 0;
  padding-right: 4px;
  align-content: start;
}
.roster-grid::-webkit-scrollbar { width: 5px; }
.roster-grid::-webkit-scrollbar-thumb { background: #333; border-radius: 3px; }
.roster-card {
  position: relative;
  width: 100%;
  aspect-ratio: 3/4;
  border: 2px solid var(--border-dark);
  border-radius: 8px;
  overflow: hidden;
  cursor: pointer;
  transition: 0.2s;
}
.roster-card:hover {
  border-color: #666;
  transform: translateY(-2px);
}
.roster-card.active {
  border-color: var(--border-gold);
  box-shadow: 0 0 12px rgba(192,160,98,0.4);
}
.roster-card img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

/* ─── Gauntlet Fullscreen Mode ─── */
.app-layout.gauntlet-fullscreen {
  grid-template-columns: 1fr;
}
.app-layout.gauntlet-fullscreen .rpg-left,
.app-layout.gauntlet-fullscreen .rpg-right {
  display: none;
}
.app-layout.gauntlet-fullscreen .rpg-center {
  overflow-y: auto;
  overflow-x: hidden;
  max-width: 100%;
}

/* ─── Gauntlet Draft Cards ─── */
.gaunt-draft-grid {
  display: flex;
  gap: 32px;
  justify-content: center;
  align-items: center;
  margin: 20px 0;
  flex-wrap: wrap;
}
.g-card {
  width: 200px;
  height: 300px;
  perspective: 800px;
  cursor: pointer;
  transition: transform 0.3s;
  position: relative;
}
.g-card:hover {
  transform: translateY(-12px);
}
.g-card-face {
  position: absolute;
  width: 100%;
  height: 100%;
  border-radius: 12px;
  backface-visibility: hidden;
  transition: transform 0.6s;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-direction: column;
  font-family: 'Cinzel', serif;
  font-weight: 900;
  overflow: hidden;
}
.g-card-front {
  background: linear-gradient(135deg, #1a0a0e 0%, #2a1520 50%, #0a0515 100%);
  border: 2px solid var(--border-gold);
  color: var(--border-gold);
  box-shadow: 0 0 30px rgba(139,0,0,0.3), inset 0 0 40px rgba(0,0,0,0.5);
}
.g-card-front::before {
  content: '';
  position: absolute;
  top: 0; left: 0; right: 0; bottom: 0;
  background: repeating-linear-gradient(
    45deg,
    transparent,
    transparent 10px,
    rgba(192,160,98,0.03) 10px,
    rgba(192,160,98,0.03) 20px
  );
  pointer-events: none;
}
.g-card-front .g-card-skull {
  font-size: 72px;
  filter: drop-shadow(0 0 15px rgba(192,160,98,0.4));
  animation: skull-float 2s ease-in-out infinite alternate;
}
@keyframes skull-float {
  from { transform: translateY(0); }
  to { transform: translateY(-6px); }
}
.g-card-front .g-card-title {
  font-size: 0.9rem;
  letter-spacing: 3px;
  margin-top: 16px;
  text-shadow: 0 0 10px rgba(192,160,98,0.5);
}
.g-card-front .g-card-floor-tag {
  font-size: 0.65rem;
  color: #FF5252;
  margin-top: 8px;
  letter-spacing: 2px;
}
.g-card-back {
  display: flex;
  background: #0a0515;
  border: 2px solid #FFD60A;
  flex-direction: column;
  gap: 0;
  transform: rotateY(180deg);
  box-shadow: 0 0 40px rgba(255,214,10,0.3);
}
.g-card-back .g-card-portrait {
  width: 100%;
  height: 70%;
  object-fit: cover;
  border-radius: 10px 10px 0 0;
}
.g-card-back .g-card-info {
  padding: 12px;
  text-align: center;
  flex: 1;
  display: flex;
  flex-direction: column;
  justify-content: center;
}
.g-card-back .g-card-judge-name {
  font-size: 1rem;
  font-weight: 900;
  text-transform: uppercase;
  color: #FFD60A;
  text-shadow: 0 0 10px rgba(255,214,10,0.5);
}
.g-card-back .g-card-difficulty {
  font-size: 0.7rem;
  color: #FF5252;
  margin-top: 4px;
  letter-spacing: 1px;
}
.g-card.flipped .g-card-front { transform: rotateY(180deg); }
.g-card.flipped .g-card-back { transform: rotateY(0deg); }
.g-card.fade-out { opacity: 0.15; transform: scale(0.9); pointer-events: none; }

.g-card-icon { font-size: 2.5rem; }
.g-card-diff-tag { font-size: 0.7rem; color: var(--text-muted); }

/* ─── Helpers ─── */
.lat-tag { font-size:0.6rem; padding: 2px 6px; border-radius: 4px; background:#222; margin-right:4px; font-family:'Outfit'; }
.lat-ise { color: #34C759; }
.lat-asr { color: #FFD60A; }

/* ─── Modal Overlay ─── */
.rpg-modal {
  position: fixed; top: 0; left: 0; right: 0; bottom: 0;
  background: rgba(0,0,0,0.85); z-index: 1000;
  display: none; align-items: center; justify-content: center;
  backdrop-filter: blur(12px);
}
.rpg-modal-content {
  background: var(--surface-panel); border: 2px solid var(--border-gold);
  width: 90%; max-width: 500px; padding: 24px; border-radius: 12px;
  box-shadow: 0 0 50px rgba(0,0,0,0.8);
}
