/* ================================================
   AKADEMI QITHMIR — RPG Theme
   Dark fantasy JRPG style
   ================================================ */

/* --- RESET & BASE --- */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

@keyframes bgFloat {
  0% { background-position: 0% 50%; }
  50% { background-position: 100% 50%; }
  100% { background-position: 0% 50%; }
}
@keyframes fadeIn {
  from { opacity: 0; transform: translateY(12px); }
  to   { opacity: 1; transform: translateY(0); }
}
@keyframes glowPulse {
  0%, 100% { box-shadow: 0 0 8px rgba(200,168,78,0.3); }
  50%      { box-shadow: 0 0 20px rgba(200,168,78,0.7); }
}
@keyframes spin { to { transform: rotate(360deg); } }
@keyframes slideRight {
  from { width: 0%; }
}

:root {
  --bg-dark: #0a0a12;
  --bg-panel: #12121e;
  --bg-card: #1a1a2e;
  --gold: #c8a84e;
  --gold-dim: #8a7e5a;
  --gold-bright: #f0d060;
  --text-primary: #e8e0d0;
  --text-secondary: #9a9280;
  --hp-green: #2ecc71;
  --hp-yellow: #f1c40f;
  --hp-red: #e74c3c;
  --exp-color: #9b59b6;
  --accent-blue: #5dade2;
  --accent-purple: #a569bd;
  --border-color: #2a2a40;
  --btn-bg: #1e1e34;
  --btn-hover: #2e2e4e;
}

html, body {
  height: 100%;
  width: 100%;
  overflow: hidden;
  background: var(--bg-dark);
  background-image:
    radial-gradient(ellipse at 20% 30%, rgba(100,60,180,0.08) 0%, transparent 50%),
    radial-gradient(ellipse at 80% 70%, rgba(60,100,200,0.06) 0%, transparent 50%);
  color: var(--text-primary);
  font-family: 'Inter', 'Segoe UI', system-ui, sans-serif;
  font-size: 15px;
  line-height: 1.6;
}

/* --- SCREENS --- */
.screen {
  display: none;
  width: 100%;
  height: 100vh;
  position: absolute;
  top: 0; left: 0;
}
.screen.active {
  display: flex;
  align-items: center;
  justify-content: center;
}

/* --- TITLE SCREEN --- */
#title-screen {
  background: var(--bg-dark);
  background-image:
    radial-gradient(ellipse at center, rgba(100,60,180,0.12) 0%, transparent 60%),
    radial-gradient(ellipse at 30% 20%, rgba(60,100,200,0.08) 0%, transparent 40%);
}
.title-container {
  text-align: center;
  animation: fadeIn 1s ease-out;
}
.crystal-ball {
  width: 90px; height: 90px;
  margin: 0 auto 24px;
  position: relative;
}
.crystal-glow {
  position: absolute;
  inset: -10px;
  border-radius: 50%;
  background: radial-gradient(circle, rgba(200,168,78,0.3) 0%, transparent 70%);
  animation: glowPulse 3s ease-in-out infinite;
}
.crystal-inner {
  width: 100%; height: 100%;
  border-radius: 50%;
  background: radial-gradient(circle at 35% 35%, #2a2a4e, #1a1a3e 60%, #0a0a1e);
  border: 2px solid var(--gold-dim);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 36px;
  color: var(--gold);
  position: relative;
  z-index: 1;
  box-shadow: inset 0 0 30px rgba(200,168,78,0.1);
}
.game-title {
  font-family: 'MedievalSharp', serif;
  font-size: 3rem;
  color: var(--gold);
  line-height: 1.2;
  text-shadow: 0 0 30px rgba(200,168,78,0.3);
  letter-spacing: 2px;
}
.title-sub {
  font-size: 2.2rem;
  display: block;
  color: var(--gold-bright);
}
.title-desc {
  color: var(--text-secondary);
  margin-top: 12px;
  font-size: 0.95rem;
  letter-spacing: 3px;
  text-transform: uppercase;
}
.title-tagline {
  color: var(--gold-dim);
  font-style: italic;
  margin-top: 8px;
  font-size: 0.85rem;
}
.btn-magic {
  margin-top: 40px;
  padding: 14px 48px;
  font-size: 1.1rem;
  font-family: 'MedievalSharp', serif;
  color: var(--gold-bright);
  background: linear-gradient(135deg, #1a1a3e, #2a1a4e);
  border: 2px solid var(--gold);
  border-radius: 8px;
  cursor: pointer;
  transition: all 0.3s ease;
  box-shadow: 0 0 20px rgba(200,168,78,0.2);
  letter-spacing: 2px;
}
.btn-magic:hover {
  background: linear-gradient(135deg, #2a2a5e, #3a2a6e);
  box-shadow: 0 0 35px rgba(200,168,78,0.4);
  transform: translateY(-2px);
}
.btn-magic:active {
  transform: translateY(0);
}

/* --- NAME SCREEN --- */
.name-container {
  text-align: center;
  max-width: 500px;
}
.scroll-panel {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: 12px;
  padding: 32px;
  margin-top: 20px;
  animation: fadeIn 0.6s ease-out;
}
.scroll-text {
  color: var(--text-primary);
  font-size: 1.05rem;
  margin-bottom: 24px;
  line-height: 1.8;
}
.input-group {
  display: flex;
  flex-direction: column;
  gap: 12px;
  align-items: center;
}
.rpg-input {
  width: 100%;
  max-width: 340px;
  padding: 12px 16px;
  background: #0e0e1a;
  border: 2px solid var(--border-color);
  border-radius: 8px;
  color: var(--text-primary);
  font-size: 1rem;
  font-family: inherit;
  text-align: center;
  outline: none;
  transition: border-color 0.3s;
}
.rpg-input:focus {
  border-color: var(--gold-dim);
  box-shadow: 0 0 12px rgba(200,168,78,0.15);
}
.rpg-input::placeholder {
  color: var(--text-secondary);
}

/* --- BUTTONS --- */
.btn-rpg {
  padding: 12px 36px;
  background: linear-gradient(135deg, #2a1a3e, #1a2a4e);
  border: 2px solid var(--gold-dim);
  border-radius: 8px;
  color: var(--gold);
  font-size: 1rem;
  font-family: 'MedievalSharp', serif;
  cursor: pointer;
  transition: all 0.3s ease;
  letter-spacing: 1px;
}
.btn-rpg:hover {
  background: linear-gradient(135deg, #3a2a5e, #2a3a6e);
  border-color: var(--gold);
  box-shadow: 0 0 20px rgba(200,168,78,0.25);
  transform: translateY(-1px);
}
.btn-rpg:active {
  transform: translateY(0);
}
.btn-small {
  padding: 8px 20px;
  font-size: 0.85rem;
}

/* ==============================================
   GAME SCREEN LAYOUT
   ============================================== */
#game-screen {
  overflow: hidden;
}
.game-container {
  display: grid;
  grid-template-columns: 1fr 240px;
  grid-template-rows: auto 1fr auto;
  gap: 0;
  width: 100%;
  height: 100vh;
  max-width: 1200px;
  margin: 0 auto;
  padding: 0;
  position: relative;
}

/* --- TOP HUD --- */
.rpg-hud-top {
  grid-column: 1 / -1;
  background: linear-gradient(180deg, #0d0d1a, #12122a);
  border-bottom: 2px solid var(--border-color);
  padding: 8px 20px;
  z-index: 10;
}
.hud-title-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 4px;
}
.hud-title {
  font-family: 'MedievalSharp', serif;
  color: var(--gold);
  font-size: 0.85rem;
  letter-spacing: 2px;
}
.hud-level {
  font-family: 'Press Start 2P', monospace;
  color: var(--gold-bright);
  font-size: 0.7rem;
}
.hud-stats-row {
  display: flex;
  gap: 16px;
  align-items: center;
  margin-bottom: 6px;
  font-size: 0.78rem;
  color: var(--text-secondary);
}
.hud-player-name {
  color: var(--gold);
  font-weight: 600;
  font-size: 0.85rem;
}
.hud-race {
  color: var(--accent-purple);
}
.hud-status {
  color: var(--hp-green);
}

/* BARS */
.hud-bars {
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.hud-bar-row {
  display: flex;
  align-items: center;
  gap: 8px;
}
.bar-label {
  font-family: 'Press Start 2P', monospace;
  font-size: 0.55rem;
  width: 32px;
  color: var(--text-secondary);
}
.bar-track {
  flex: 1;
  height: 16px;
  background: #0a0a18;
  border: 1px solid #2a2a40;
  border-radius: 8px;
  overflow: hidden;
  position: relative;
}
.bar-fill {
  height: 100%;
  border-radius: 8px;
  transition: width 0.5s ease;
  position: relative;
}
.bar-fill::after {
  content: '';
  position: absolute;
  top: 0; left: 0; right: 0;
  height: 50%;
  background: rgba(255,255,255,0.1);
  border-radius: 8px 8px 0 0;
}
.hp-fill {
  background: linear-gradient(90deg, var(--hp-green), #27ae60);
}
.exp-fill {
  background: linear-gradient(90deg, #8e44ad, var(--exp-color));
}
.bar-text {
  font-family: 'Press Start 2P', monospace;
  font-size: 0.5rem;
  color: var(--text-secondary);
  width: 70px;
  text-align: right;
  white-space: nowrap;
}

/* --- MAIN CONTENT (page-based) --- */
.game-content {
  grid-column: 1;
  grid-row: 2;
  overflow-y: auto;
  padding: 20px 24px;
  background: var(--bg-panel);
  min-height: 0;
}
.page-container {
  min-height: 200px;
}
.page-content {
  animation: fadeIn 0.5s ease-out;
}
.page-content p {
  margin-bottom: 12px;
  line-height: 1.8;
}
.page-content .narrative {
  color: var(--text-primary);
  font-size: 0.95rem;
}
.page-content .narrative em {
  color: var(--gold-dim);
  font-style: italic;
}
.page-content .narrative strong {
  color: var(--gold);
}
.page-content .question-text {
  font-size: 1.05rem;
  color: var(--gold-bright);
  font-weight: 600;
  margin-bottom: 16px;
  line-height: 1.6;
}

/* ─── Chat History ──────────────────────────────────────────────── */
.chat-history {
  grid-column: 1;
  grid-row: 2;
  overflow-y: auto;
  overflow-x: hidden;
  padding: 12px 16px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  background: var(--bg-main);
  min-height: 0;
  height: 100%;
  scroll-behavior: smooth;
}
.chat-msg {
  padding: 10px 14px;
  border-radius: 10px;
  line-height: 1.7;
  font-size: 0.92rem;
  animation: fadeIn 0.4s ease;
  white-space: pre-wrap;
  word-break: break-word;
}
.chat-narrative {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  color: var(--text);
}
.chat-player {
  align-self: flex-end;
  max-width: 80%;
  background: linear-gradient(135deg, #1a2a4a, #1a1a3a);
  border: 1px solid var(--purple);
  border-radius: 10px 10px 4px 10px;
  color: var(--cyan);
  font-style: italic;
  font-size: 0.85rem;
}
.chat-error {
  align-self: center;
  background: rgba(255, 68, 102, 0.1);
  border: 1px solid var(--danger);
  color: var(--danger);
  font-size: 0.85rem;
  text-align: center;
}
.chat-system {
  align-self: center;
  background: rgba(212, 168, 67, 0.1);
  border: 1px solid var(--gold-dim);
  color: var(--gold);
  font-size: 0.85rem;
  text-align: center;
}
.chat-msg strong { color: var(--gold); }
.chat-msg em { color: var(--purple); font-style: italic; }

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

/* ─── Input Area ────────────────────────────────────────────────── */
.input-area {
  display: flex;
  gap: 8px;
  max-width: 500px;
  margin: 0 auto;
  align-items: center;
}
.input-area .rpg-input {
  flex: 1;
  max-width: none;
  text-align: left;
}
.spell-area {
  display: flex;
  flex-direction: column;
  gap: 6px;
  max-width: 500px;
  margin: 8px auto 0;
  padding-top: 8px;
  border-top: 1px dashed rgba(123, 77, 255, 0.3);
}
.spell-label {
  font-size: 0.8rem;
  color: var(--purple);
  font-family: 'MedievalSharp', serif;
  letter-spacing: 1px;
  text-align: center;
}
.spell-input-row {
  display: flex;
  gap: 8px;
  align-items: center;
}
.spell-input {
  font-family: 'Traditional Arabic', 'Scheherazade New', 'Amiri', serif !important;
  font-size: 1.3rem !important;
  direction: rtl;
  text-align: right;
  background: rgba(123, 77, 255, 0.08) !important;
  border-color: var(--purple) !important;
}
.spell-input::placeholder {
  font-size: 1rem;
  color: var(--purple);
  opacity: 0.5;
}
.spell-input:focus {
  box-shadow: 0 0 15px var(--purple-glow) !important;
}
.btn-spell {
  background: linear-gradient(135deg, var(--purple) 0%, #5a2dcc 100%) !important;
  font-family: 'MedievalSharp', serif;
  white-space: nowrap;
}

/* --- RIGHT SIDEBAR --- */
.game-sidebar {
  grid-column: 2;
  grid-row: 2;
  background: #0d0d1a;
  border-left: 1px solid var(--border-color);
  padding: 12px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.sidebar-panel {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: 8px;
  overflow: hidden;
}
.panel-title {
  background: linear-gradient(90deg, #1a1a30, #12122a);
  padding: 6px 10px;
  font-size: 0.75rem;
  color: var(--gold-dim);
  border-bottom: 1px solid var(--border-color);
  font-weight: 600;
  letter-spacing: 1px;
}
.panel-body {
  padding: 8px 10px;
  font-size: 0.78rem;
  color: var(--text-secondary);
  min-height: 30px;
}
.coin-display {
  color: var(--gold);
  font-weight: 600;
  font-size: 0.85rem;
  margin-bottom: 4px;
}
.item-list {
  font-size: 0.78rem;
}

/* --- CHOICES / ACTIONS --- */
.game-actions {
  grid-column: 1 / -1;
  grid-row: 3;
  background: #0d0d1a;
  border-top: 2px solid var(--border-color);
  padding: 12px 24px;
  min-height: 90px;
}
.choices-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  max-width: 700px;
  margin: 0 auto;
}
.choice-btn {
  padding: 10px 16px;
  background: var(--btn-bg);
  border: 1px solid var(--border-color);
  border-radius: 8px;
  color: var(--text-primary);
  font-size: 0.82rem;
  cursor: pointer;
  transition: all 0.25s ease;
  text-align: left;
  font-family: inherit;
  line-height: 1.4;
  position: relative;
  overflow: hidden;
}
.choice-btn::before {
  content: '';
  position: absolute;
  top: 0; left: -100%;
  width: 100%; height: 100%;
  background: linear-gradient(90deg, transparent, rgba(200,168,78,0.05), transparent);
  transition: left 0.5s ease;
}
.choice-btn:hover::before {
  left: 100%;
}
.choice-btn:hover {
  background: var(--btn-hover);
  border-color: var(--gold-dim);
  box-shadow: 0 0 12px rgba(200,168,78,0.15);
  transform: translateY(-1px);
}
.choice-btn:active {
  transform: translateY(0);
}
.choice-btn .choice-key {
  color: var(--gold);
  font-weight: 700;
  margin-right: 6px;
}
.choice-btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
  transform: none !important;
}

/* Custom action */
.custom-action-area {
  display: flex;
  gap: 8px;
  max-width: 500px;
  margin: 0 auto;
  align-items: center;
}
.custom-action-area .rpg-input {
  text-align: left;
  max-width: none;
  flex: 1;
}

/* Spell (mantra) input area */
.spell-area {
  display: flex;
  flex-direction: column;
  gap: 6px;
  max-width: 500px;
  margin: 8px auto 0;
  padding-top: 8px;
  border-top: 1px dashed rgba(123, 77, 255, 0.3);
}
.spell-label {
  font-size: 0.8rem;
  color: var(--purple);
  font-family: 'MedievalSharp', serif;
  letter-spacing: 1px;
  text-align: center;
}
.spell-input-row {
  display: flex;
  gap: 8px;
  align-items: center;
}
.spell-input {
  font-family: 'Traditional Arabic', 'Scheherazade New', 'Amiri', 'Times New Roman', serif !important;
  font-size: 1.3rem !important;
  direction: rtl;
  text-align: right;
  background: rgba(123, 77, 255, 0.08) !important;
  border-color: var(--purple) !important;
}
.spell-input::placeholder {
  font-size: 1rem;
  color: var(--purple);
  opacity: 0.5;
}
.spell-input:focus {
  box-shadow: 0 0 15px var(--purple-glow) !important;
}
.btn-spell {
  background: linear-gradient(135deg, var(--purple) 0%, #5a2dcc 100%) !important;
  font-family: 'MedievalSharp', serif;
  white-space: nowrap;
}

/* Loading indicator */
.loading-indicator {
  text-align: center;
  padding: 16px;
  color: var(--gold-dim);
  font-size: 0.85rem;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
}
.loading-spinner {
  display: inline-block;
  width: 20px; height: 20px;
  border: 2px solid var(--border-color);
  border-top-color: var(--gold);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

/* ==============================================
   RESPONSIVE
   ============================================== */
@media (max-width: 768px) {
  .game-container {
    grid-template-columns: 1fr;
    grid-template-rows: auto auto 1fr auto;
  }
  .game-sidebar {
    display: none;
  }
  .game-content {
    padding: 16px;
  }
  .choices-grid {
    grid-template-columns: 1fr;
  }
  .choice-btn {
    font-size: 0.9rem;
    padding: 12px 16px;
  }
  .game-title {
    font-size: 2.2rem;
  }
  .title-sub {
    font-size: 1.6rem;
  }
}

@media (max-width: 480px) {
  .hud-stats-row {
    flex-wrap: wrap;
    gap: 8px;
  }
  .bar-label {
    width: 28px;
    font-size: 0.5rem;
  }
  .bar-text {
    font-size: 0.45rem;
    width: 60px;
  }
}

/* Scroll to bottom button */
.scroll-bottom-btn {
  position: fixed;
  bottom: 100px;
  right: 260px;
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: var(--purple);
  color: white;
  border: 2px solid var(--gold-dim);
  font-size: 1.2rem;
  cursor: pointer;
  opacity: 0;
  transform: translateY(10px);
  transition: all 0.3s ease;
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 2px 10px rgba(0,0,0,0.4);
}
.scroll-bottom-btn.visible {
  opacity: 1;
  transform: translateY(0);
}
.scroll-bottom-btn:hover {
  background: var(--gold);
  color: #000;
}
@media (max-width: 768px) {
  .scroll-bottom-btn {
    right: 20px;
    bottom: 100px;
  }
}
