/* PolyGlotRPG Stylesheet */
:root {
  --bg-dark: #090d16;
  --panel-bg: rgba(15, 23, 42, 0.92);
  --panel-border: rgba(56, 189, 248, 0.35);
  --primary: #38bdf8;
  --primary-hover: #0284c7;
  --accent-gold: #fbbf24;
  --accent-purple: #c084fc;
  --accent-green: #34d399;
  --text-main: #f8fafc;
  --text-muted: #94a3b8;
  --danger: #ef4444;
  --success: #10b981;
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  user-select: none;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Oxygen, Ubuntu, Cantarell, "Helvetica Neue", sans-serif;
}

body, html {
  width: 100%;
  height: 100%;
  overflow: hidden;
  background-color: var(--bg-dark);
  color: var(--text-main);
}

#game-container {
  position: relative;
  width: 100vw;
  height: 100vh;
  overflow: hidden;
}

#game-canvas {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  display: block;
}

#ui-root {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  z-index: 10;
}

#ui-root > * {
  pointer-events: auto;
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 10px 22px;
  border-radius: 8px;
  border: 1px solid transparent;
  font-weight: 700;
  font-size: 15px;
  cursor: pointer;
  transition: all 0.15s ease-in-out;
  text-shadow: 0 1px 2px rgba(0,0,0,0.4);
}

.btn-primary {
  background: linear-gradient(135deg, #0284c7 0%, #38bdf8 100%);
  color: #ffffff;
  border-color: #7dd3fc;
  box-shadow: 0 4px 14px rgba(56, 189, 248, 0.35);
}
.btn-primary:hover {
  transform: translateY(-2px);
  box-shadow: 0 6px 20px rgba(56, 189, 248, 0.5);
}

.btn-secondary {
  background: linear-gradient(135deg, #475569 0%, #64748b 100%);
  color: #ffffff;
  border-color: #94a3b8;
}
.btn-secondary:hover {
  background: #64748b;
  transform: translateY(-2px);
}

.btn-neutral {
  background: rgba(30, 41, 59, 0.8);
  color: #e2e8f0;
  border-color: #475569;
}
.btn-neutral:hover {
  background: rgba(51, 65, 85, 0.95);
  border-color: #94a3b8;
}

.btn-disabled {
  opacity: 0.45;
  cursor: not-allowed;
  pointer-events: none;
}

.btn-danger {
  background: linear-gradient(135deg, #b91c1c 0%, #ef4444 100%);
  color: #fff;
}

.btn-tts {
  background: rgba(56, 189, 248, 0.2);
  border: 1px solid var(--primary);
  color: var(--primary);
  border-radius: 6px;
  padding: 6px 14px;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.2s;
}
.btn-tts:hover {
  background: rgba(56, 189, 248, 0.4);
}

.screen-title-overlay {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: radial-gradient(circle at center, rgba(30, 58, 138, 0.4) 0%, rgba(9, 13, 22, 0.96) 80%);
  backdrop-filter: blur(6px);
}

.title-card {
  width: 520px;
  max-width: 90vw;
  padding: 42px 36px;
  background: var(--panel-bg);
  border: 1.5px solid var(--panel-border);
  border-radius: 18px;
  text-align: center;
  box-shadow: 0 20px 50px rgba(0, 0, 0, 0.7);
}

.game-logo {
  font-size: 46px;
  font-weight: 900;
  letter-spacing: -1px;
}
.logo-poly { color: #38bdf8; }
.logo-glot { color: #fbbf24; }
.logo-rpg { color: #ec4899; margin-left: 4px; }

.game-subtitle {
  color: var(--text-muted);
  font-size: 15px;
  margin-top: 6px;
  margin-bottom: 24px;
}

.title-crystal-display {
  display: flex;
  flex-direction: column;
  align-items: center;
  margin-bottom: 28px;
}
.crystal-icon {
  font-size: 48px;
  margin-bottom: 12px;
}
.pulse-glow {
  animation: pulse 2s infinite ease-in-out;
}
@keyframes pulse {
  0%, 100% { transform: scale(1); filter: drop-shadow(0 0 10px #38bdf8); }
  50% { transform: scale(1.12); filter: drop-shadow(0 0 25px #818cf8); }
}

.region-badges {
  display: flex;
  gap: 8px;
  font-size: 22px;
}

.title-menu-buttons {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.screen-creation-overlay {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(9, 13, 22, 0.94);
  backdrop-filter: blur(8px);
}

.creation-card {
  width: 560px;
  max-width: 92vw;
  padding: 34px 30px;
  background: var(--panel-bg);
  border: 1.5px solid var(--panel-border);
  border-radius: 16px;
}

.card-title {
  font-size: 26px;
  font-weight: 800;
  color: #38bdf8;
  margin-bottom: 6px;
}
.card-desc {
  font-size: 14px;
  color: var(--text-muted);
  margin-bottom: 22px;
}

.form-group {
  margin-bottom: 16px;
}
.form-group label {
  display: block;
  font-size: 13px;
  font-weight: 600;
  color: #cbd5e1;
  margin-bottom: 6px;
}
.form-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
}

.input-text, .input-select {
  width: 100%;
  padding: 10px 14px;
  background: #1e293b;
  border: 1px solid #475569;
  border-radius: 8px;
  color: #ffffff;
  font-size: 14px;
  outline: none;
}
.input-text:focus, .input-select:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 2px rgba(56, 189, 248, 0.2);
}

.appearance-picker {
  margin-top: 10px;
  margin-bottom: 24px;
}
.color-pickers {
  display: flex;
  gap: 20px;
  margin-top: 8px;
}
.color-pickers div {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
  color: #cbd5e1;
}
.color-pickers input[type="color"] {
  border: none;
  width: 32px;
  height: 32px;
  border-radius: 6px;
  cursor: pointer;
  background: transparent;
}

.creation-actions {
  display: flex;
  justify-content: space-between;
  margin-top: 24px;
}

.game-hud {
  position: absolute;
  inset: 0;
  pointer-events: none;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  padding: 18px;
}

.hud-top-left {
  display: flex;
  flex-direction: column;
  gap: 10px;
  pointer-events: auto;
}

.hud-profile-card {
  display: flex;
  align-items: center;
  gap: 12px;
  background: rgba(15, 23, 42, 0.88);
  border: 1.5px solid rgba(56, 189, 248, 0.4);
  padding: 10px 16px;
  border-radius: 14px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.5);
  backdrop-filter: blur(4px);
}

.hud-avatar-circle {
  width: 44px;
  height: 44px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 20px;
  font-weight: 800;
  color: #ffffff;
  border: 2px solid #ffffff;
}

.hud-user-info {
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.hud-name-row {
  display: flex;
  align-items: center;
  gap: 8px;
}
.hud-player-name {
  font-weight: 800;
  font-size: 16px;
}
.hud-badge-level {
  background: #3b82f6;
  color: #ffffff;
  padding: 2px 7px;
  border-radius: 6px;
  font-size: 11px;
  font-weight: 700;
}
.hud-badge-lang {
  background: #8b5cf6;
  color: #ffffff;
  padding: 2px 7px;
  border-radius: 6px;
  font-size: 11px;
  font-weight: 700;
}

.hud-xp-bar-container {
  position: relative;
  width: 170px;
  height: 12px;
  background: #1e293b;
  border-radius: 6px;
  overflow: hidden;
  border: 1px solid #334155;
}
.hud-xp-bar-fill {
  height: 100%;
  background: linear-gradient(90deg, #3b82f6, #60a5fa);
  transition: width 0.3s ease;
}
.hud-xp-text {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  font-size: 8px;
  font-weight: 800;
  color: #ffffff;
  text-shadow: 0 1px 2px rgba(0,0,0,0.8);
}

.hud-stats-pills {
  display: flex;
  gap: 8px;
}
.pill {
  padding: 5px 12px;
  border-radius: 20px;
  font-size: 12px;
  font-weight: 700;
  background: rgba(15, 23, 42, 0.85);
  border: 1px solid rgba(255, 255, 255, 0.15);
  backdrop-filter: blur(4px);
}
.pill-hp { color: #f87171; border-color: rgba(248, 113, 113, 0.4); }
.pill-coins { color: #fbbf24; border-color: rgba(251, 191, 36, 0.4); }
.pill-streak { color: #fb923c; border-color: rgba(251, 146, 60, 0.4); }

.hud-top-right {
  position: absolute;
  top: 18px;
  right: 18px;
  pointer-events: auto;
}
.hud-quest-tracker {
  background: rgba(15, 23, 42, 0.88);
  border: 1.5px solid rgba(251, 191, 36, 0.4);
  border-radius: 12px;
  padding: 10px 16px;
  max-width: 280px;
  backdrop-filter: blur(4px);
  box-shadow: 0 6px 18px rgba(0,0,0,0.4);
}
.quest-tracker-header {
  font-size: 13px;
  font-weight: 800;
  color: #fbbf24;
  margin-bottom: 4px;
}
.quest-tracker-step {
  font-size: 12px;
  color: #e2e8f0;
  line-height: 1.3;
}

.hud-bottom-bar {
  display: flex;
  justify-content: center;
  gap: 10px;
  pointer-events: auto;
}
.hud-btn {
  background: rgba(15, 23, 42, 0.9);
  border: 1.5px solid rgba(56, 189, 248, 0.3);
  color: #f1f5f9;
  padding: 8px 14px;
  border-radius: 10px;
  font-size: 13px;
  font-weight: 700;
  cursor: pointer;
  transition: all 0.15s ease;
  backdrop-filter: blur(4px);
}
.hud-btn:hover {
  background: #1e293b;
  border-color: #38bdf8;
  transform: translateY(-2px);
  box-shadow: 0 4px 12px rgba(56, 189, 248, 0.3);
}

.modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(9, 13, 22, 0.75);
  backdrop-filter: blur(6px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 50;
}

.modal-card {
  width: 600px;
  max-width: 92vw;
  max-height: 85vh;
  background: var(--panel-bg);
  border: 1.5px solid var(--panel-border);
  border-radius: 18px;
  padding: 26px;
  overflow-y: auto;
  box-shadow: 0 20px 60px rgba(0,0,0,0.7);
  display: flex;
  flex-direction: column;
}

.modal-large {
  width: 860px;
}

.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 20px;
  border-bottom: 1px solid rgba(255,255,255,0.1);
  padding-bottom: 12px;
}
.modal-header h2 {
  font-size: 20px;
  font-weight: 800;
  color: #38bdf8;
}
.modal-close-btn {
  background: none;
  border: none;
  color: #94a3b8;
  font-size: 20px;
  cursor: pointer;
}
.modal-close-btn:hover { color: #fff; }

.dialogue-box {
  width: 720px;
  max-width: 94vw;
  background: var(--panel-bg);
  border: 2px solid var(--panel-border);
  border-radius: 18px;
  padding: 24px;
  box-shadow: 0 20px 60px rgba(0,0,0,0.8);
}

.dialogue-speaker-banner {
  display: flex;
  align-items: center;
  gap: 14px;
  margin-bottom: 16px;
  border-bottom: 1px solid rgba(255,255,255,0.1);
  padding-bottom: 12px;
}
.speaker-avatar-thumb {
  font-size: 28px;
}
.dialogue-speaker-name {
  font-size: 18px;
  font-weight: 800;
  color: #fbbf24;
}
.dialogue-speaker-role {
  font-size: 12px;
  color: #94a3b8;
}

.dialogue-content-area {
  margin-bottom: 18px;
}
.dialogue-speech-text {
  font-size: 19px;
  line-height: 1.45;
  color: #ffffff;
  font-weight: 600;
}
.dialogue-translation-text {
  font-size: 14px;
  color: #94a3b8;
  margin-top: 8px;
}

.dialogue-feedback-banner {
  padding: 10px 14px;
  border-radius: 8px;
  font-size: 14px;
  font-weight: 600;
  margin-bottom: 16px;
}
.fb-correct {
  background: rgba(16, 185, 129, 0.2);
  border: 1px solid var(--success);
  color: #6ee7b7;
}
.fb-error {
  background: rgba(239, 68, 68, 0.2);
  border: 1px solid var(--danger);
  color: #fca5a5;
}

.dialogue-options-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.dialogue-option-btn {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 18px;
  background: rgba(30, 41, 59, 0.7);
  border: 1.5px solid #475569;
  border-radius: 10px;
  color: #f8fafc;
  font-size: 15px;
  font-weight: 600;
  text-align: left;
  cursor: pointer;
  transition: all 0.15s ease;
}
.dialogue-option-btn:hover {
  background: #334155;
  border-color: var(--primary);
  transform: translateX(4px);
}
.option-letter {
  color: var(--primary);
  font-weight: 800;
}

.combat-arena-modal {
  width: 740px;
  max-width: 94vw;
  background: radial-gradient(circle at center, #1e1b4b 0%, #090d16 100%);
  border: 2px solid #8b5cf6;
  border-radius: 20px;
  padding: 28px;
  box-shadow: 0 25px 70px rgba(0,0,0,0.85);
}

.combat-header {
  display: flex;
  justify-content: space-between;
  margin-bottom: 24px;
}
.combat-entity-hud {
  width: 240px;
}
.combat-name {
  font-weight: 800;
  font-size: 15px;
  margin-bottom: 4px;
}
.bar-container {
  height: 12px;
  background: #1e293b;
  border-radius: 6px;
  overflow: hidden;
  border: 1px solid #475569;
}
.bar-fill {
  height: 100%;
  transition: width 0.3s ease;
}
.bar-hp-enemy { background: #ef4444; }
.bar-hp-player { background: #10b981; }
.bar-label {
  font-size: 11px;
  font-weight: 700;
  color: #94a3b8;
  margin-top: 2px;
}

.combat-question-card {
  background: rgba(15, 23, 42, 0.85);
  border: 1.5px solid #6366f1;
  border-radius: 14px;
  padding: 20px;
  text-align: center;
  margin-bottom: 18px;
}
.combat-badge-type {
  display: inline-block;
  background: #4f46e5;
  color: #fff;
  font-size: 10px;
  font-weight: 800;
  padding: 3px 8px;
  border-radius: 6px;
  margin-bottom: 8px;
}
.combat-prompt-text {
  font-size: 20px;
  font-weight: 700;
  color: #ffffff;
  margin-bottom: 10px;
}

.combat-options-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
  margin-bottom: 20px;
}
.combat-opt-btn {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 14px 16px;
  background: #1e293b;
  border: 1.5px solid #475569;
  border-radius: 10px;
  color: #ffffff;
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.15s ease;
}
.combat-opt-btn:hover:not(:disabled) {
  border-color: #a855f7;
  background: #334155;
  transform: translateY(-2px);
}
.combat-opt-btn.eliminated {
  opacity: 0.25;
  text-decoration: line-through;
  cursor: not-allowed;
}
.opt-key {
  background: #334155;
  color: #a855f7;
  padding: 2px 7px;
  border-radius: 4px;
  font-weight: 800;
}

.combat-action-bar {
  display: flex;
  gap: 12px;
  justify-content: center;
}

.combat-end-card {
  text-align: center;
  padding: 30px;
}
.combat-end-card h2 {
  font-size: 32px;
  font-weight: 900;
  margin-bottom: 10px;
}
.victory-theme h2 { color: #34d399; }
.defeat-theme h2 { color: #f87171; }
.combat-rewards-pill {
  display: flex;
  justify-content: center;
  gap: 16px;
  margin: 20px 0;
  font-weight: 800;
  font-size: 16px;
  color: #fbbf24;
}

.lexicon-tabs {
  display: flex;
  gap: 10px;
  margin-bottom: 16px;
}
.tab-btn {
  background: #1e293b;
  border: 1px solid #475569;
  color: #cbd5e1;
  padding: 8px 16px;
  border-radius: 8px;
  cursor: pointer;
  font-weight: 700;
  font-size: 13px;
}
.tab-btn.active {
  background: var(--primary);
  color: #0f172a;
  border-color: var(--primary);
}

.lexicon-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
  gap: 12px;
  max-height: 55vh;
  overflow-y: auto;
  padding-right: 6px;
}
.lexicon-card {
  background: #1e293b;
  border: 1px solid #334155;
  border-radius: 12px;
  padding: 14px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.lexicon-card-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
}
.vocab-word {
  font-size: 18px;
  font-weight: 800;
  color: #38bdf8;
}
.vocab-tier {
  font-size: 10px;
  font-weight: 800;
  padding: 2px 6px;
  border-radius: 6px;
  text-transform: uppercase;
}
.tier-novo { background: #64748b; color: #fff; }
.tier-aprendendo { background: #f59e0b; color: #000; }
.tier-familiar { background: #3b82f6; color: #fff; }
.tier-bom { background: #8b5cf6; color: #fff; }
.tier-dominado { background: #10b981; color: #fff; }
.tier-mastered { background: #ec4899; color: #fff; }

.vocab-translation {
  font-size: 14px;
  font-weight: 700;
  color: #f1f5f9;
}
.vocab-example {
  font-size: 12px;
  color: #94a3b8;
  font-style: italic;
}
.vocab-example-pt {
  font-size: 11px;
  color: #64748b;
}
.vocab-cultural {
  font-size: 11px;
  color: #fbbf24;
  margin-top: 4px;
}
.vocab-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-top: 8px;
}
.mastery-bar-container {
  flex: 1;
  height: 6px;
  background: #0f172a;
  border-radius: 3px;
  overflow: hidden;
  margin-right: 8px;
}
.mastery-bar-fill {
  height: 100%;
  background: var(--primary);
}
.btn-tts-mini {
  background: none;
  border: none;
  font-size: 16px;
  cursor: pointer;
}

.flashcard-study-container {
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 20px;
}
.study-counter {
  font-size: 13px;
  font-weight: 700;
  color: var(--text-muted);
  margin-bottom: 16px;
}
.study-card {
  width: 380px;
  height: 220px;
  background: #1e293b;
  border: 2px solid var(--primary);
  border-radius: 16px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 24px;
  text-align: center;
  cursor: pointer;
  box-shadow: 0 10px 30px rgba(0,0,0,0.5);
  margin-bottom: 24px;
  transition: transform 0.3s;
}
.study-card:hover {
  transform: translateY(-4px);
}
.study-card .flashcard-back { display: none; }
.study-card.flipped .flashcard-front { display: none; }
.study-card.flipped .flashcard-back { display: block; }

.flash-term { font-size: 32px; font-weight: 900; color: #38bdf8; }
.flash-roman { font-size: 14px; color: #a855f7; margin-top: 4px; }
.flash-hint { font-size: 12px; color: #64748b; margin-top: 14px; }
.flash-trans { font-size: 28px; font-weight: 800; color: #34d399; margin-bottom: 8px; }
.flash-ex { font-size: 13px; color: #cbd5e1; font-style: italic; }
.flash-ex-pt { font-size: 12px; color: #94a3b8; }
.flashcard-actions {
  display: flex;
  gap: 14px;
}

#toast-container {
  position: absolute;
  top: 20px;
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  flex-direction: column;
  gap: 8px;
  z-index: 1000;
  pointer-events: none;
}
.toast {
  background: rgba(15, 23, 42, 0.95);
  border: 1.5px solid var(--primary);
  border-radius: 10px;
  padding: 10px 18px;
  color: #fff;
  min-width: 280px;
  box-shadow: 0 8px 24px rgba(0,0,0,0.6);
  animation: slideDown 0.3s ease;
  backdrop-filter: blur(6px);
}
.toast-success { border-color: var(--success); }
.toast-achievement { border-color: var(--accent-gold); }
.toast-title { font-weight: 800; font-size: 13px; color: var(--primary); }
.toast-achievement .toast-title { color: var(--accent-gold); }
.toast-message { font-size: 12px; color: #e2e8f0; margin-top: 2px; }
.toast-fade-out { opacity: 0; transform: translateY(-10px); transition: all 0.4s ease; }

@keyframes slideDown {
  from { opacity: 0; transform: translateY(-15px); }
  to { opacity: 1; transform: translateY(0); }
}

.inventory-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
  gap: 12px;
}
.inventory-slot {
  display: flex;
  align-items: center;
  gap: 12px;
  background: #1e293b;
  border: 1.5px solid #334155;
  border-radius: 10px;
  padding: 12px;
}
.equipped-slot { border-color: #38bdf8; background: rgba(56, 189, 248, 0.1); }
.item-icon { font-size: 28px; }
.item-name { font-weight: 800; font-size: 14px; }
.item-qty { font-size: 11px; color: #94a3b8; }
.item-desc { font-size: 11px; color: #cbd5e1; margin-top: 2px; }

.quests-container {
  display: flex;
  flex-direction: column;
  gap: 14px;
  max-height: 60vh;
  overflow-y: auto;
}
.quest-card {
  background: #1e293b;
  border: 1.5px solid #334155;
  border-radius: 12px;
  padding: 16px;
}
.quest-card.status-active { border-color: #fbbf24; }
.quest-card.status-completed { border-color: #10b981; opacity: 0.85; }
.quest-header { display: flex; align-items: center; gap: 10px; margin-bottom: 8px; }
.quest-name { font-weight: 800; font-size: 16px; color: #fff; }
.quest-type-pill { background: #3b82f6; font-size: 10px; padding: 2px 6px; border-radius: 4px; font-weight: 700; }
.quest-status-badge { margin-left: auto; font-size: 11px; font-weight: 800; color: #fbbf24; }
.quest-desc { font-size: 13px; color: #94a3b8; margin-bottom: 8px; }
.quest-goal { font-size: 12px; color: #cbd5e1; margin-bottom: 10px; }
.quest-steps-list { display: flex; flex-direction: column; gap: 4px; margin-bottom: 10px; }
.quest-step-item { font-size: 12px; color: #e2e8f0; display: flex; gap: 8px; }
.step-done { color: #34d399; text-decoration: line-through; }
.quest-rewards-bar { font-size: 12px; font-weight: 700; color: #fbbf24; border-top: 1px solid #334155; padding-top: 8px; }

.regions-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
  gap: 14px;
  max-height: 60vh;
  overflow-y: auto;
}
.region-card {
  background: #1e293b;
  border: 1.5px solid #334155;
  border-radius: 12px;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.region-unlocked { border-color: #38bdf8; }
.region-locked { opacity: 0.6; }
.region-header { display: flex; align-items: center; gap: 10px; padding-left: 8px; }
.region-flag { font-size: 28px; }
.region-title { font-weight: 800; font-size: 15px; }
.region-capital { font-size: 11px; color: #94a3b8; }
.region-desc { font-size: 12px; color: #cbd5e1; line-height: 1.3; }
.region-crystal { font-size: 12px; font-weight: 700; color: #c084fc; }
.region-highlights { font-size: 11px; color: #94a3b8; }
.region-highlights ul { padding-left: 16px; margin-top: 4px; }
.lock-label { font-size: 12px; font-weight: 700; color: #f87171; }

.skills-tree-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
  gap: 12px;
}
.skill-node {
  background: #1e293b;
  border: 1.5px solid #334155;
  border-radius: 10px;
  padding: 14px;
}
.skill-node.unlocked { border-color: #34d399; background: rgba(52, 211, 153, 0.08); }
.skill-category { font-size: 10px; font-weight: 800; color: #38bdf8; text-transform: uppercase; }
.skill-title { font-size: 15px; font-weight: 800; margin: 2px 0 6px 0; }
.skill-desc { font-size: 12px; color: #94a3b8; margin-bottom: 8px; }
.skill-bonus { font-size: 11px; font-weight: 700; color: #fbbf24; }
.skill-status-tag { font-size: 11px; font-weight: 800; margin-top: 8px; color: #cbd5e1; }

.achievements-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
  max-height: 60vh;
  overflow-y: auto;
}
.achievement-card {
  display: flex;
  align-items: center;
  gap: 14px;
  background: #1e293b;
  border: 1.5px solid #334155;
  border-radius: 12px;
  padding: 12px 16px;
}
.achievement-card.ach-unlocked { border-color: #fbbf24; background: rgba(251, 191, 36, 0.08); }
.ach-icon { font-size: 30px; }
.ach-body { flex: 1; }
.ach-title { font-weight: 800; font-size: 15px; }
.ach-desc { font-size: 12px; color: #94a3b8; }
.ach-progress-bar { width: 100%; height: 6px; background: #0f172a; border-radius: 3px; overflow: hidden; margin-top: 6px; }
.ach-progress-fill { height: 100%; background: #fbbf24; }
.ach-badge { font-weight: 800; font-size: 11px; color: #fbbf24; }

.settings-form { display: flex; flex-direction: column; gap: 14px; }
.settings-actions { display: flex; flex-direction: column; gap: 8px; margin-top: 14px; border-top: 1px solid #334155; padding-top: 14px; }

/* Fit the playable interface to phones, tablets and short landscape screens. */
#game-container { height: 100dvh; }
#ui-root > .game-hud { pointer-events: none; }
.screen-title-overlay, .screen-creation-overlay { overflow-y: auto; padding: 16px; }
.title-card, .creation-card { max-height: calc(100dvh - 32px); overflow-y: auto; flex-shrink: 0; }
.dialogue-box, .combat-arena-modal { max-height: calc(100dvh - 24px); overflow-y: auto; }
.modal-card { max-height: calc(100dvh - 24px); }
.modal-close-btn { min-width: 44px; min-height: 44px; flex-shrink: 0; }
.dialogue-speaker-banner { flex-wrap: wrap; }
.hud-top-left { align-self: flex-start; max-width: 100%; }
.hud-player-name { max-width: 180px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.touch-controls { display: none; }

@media (max-width: 700px), (pointer: coarse) {
  .touch-controls {
    position: absolute; inset: auto 0 0; display: flex; justify-content: space-between;
    align-items: flex-end; padding: 10px max(12px, env(safe-area-inset-right)) max(12px, env(safe-area-inset-bottom)) max(12px, env(safe-area-inset-left));
    pointer-events: none !important; z-index: 20;
  }
  .touch-controls button {
    min-width: 48px; min-height: 48px; border-radius: 12px;
    border: 1px solid #7dd3fc; background: rgba(15, 23, 42, .88); color: #fff;
    font-size: 16px; font-weight: 700; touch-action: none; pointer-events: auto;
    -webkit-touch-callout: none;
  }
  .touch-controls button:active { background: #075985; }
  .touch-dpad { display: grid; grid-template-columns: repeat(3, 48px); grid-template-rows: repeat(2, 48px); gap: 4px; }
  .touch-dpad [data-touch-key="w"] { grid-column: 2; }
  .touch-dpad [data-touch-key="a"] { grid-column: 1; grid-row: 2; }
  .touch-dpad [data-touch-key="s"] { grid-column: 2; grid-row: 2; }
  .touch-dpad [data-touch-key="d"] { grid-column: 3; grid-row: 2; }
  .touch-actions { display: flex; gap: 8px; }
  .touch-actions button { padding: 8px 10px; }
  .game-hud { padding: max(8px, env(safe-area-inset-top)) 8px 122px; }
  .hud-bottom-bar { justify-content: flex-start; overflow-x: auto; flex-shrink: 0; gap: 6px; }
  .hud-btn { flex-shrink: 0; min-height: 44px; padding: 8px 10px; }
  .hud-top-right { top: 120px; right: 8px; max-width: 48%; }
  .hud-quest-tracker { padding: 6px; }
  .quest-tracker-step { font-size: 11px; }
  .hud-profile-card { padding: 8px; gap: 8px; }
  .hud-stats-pills { gap: 4px; flex-wrap: wrap; }
  .pill { padding: 4px 7px; font-size: 11px; }
  .hud-name-row { flex-wrap: wrap; gap: 4px; }
  .hud-player-name { max-width: 130px; }
  .hud-avatar-circle { flex-shrink: 0; }
  .title-card, .creation-card { padding: 20px 16px; max-width: 100%; width: 100%; }
  .game-logo { font-size: 34px; }
  .region-badges { gap: 5px; flex-wrap: wrap; justify-content: center; }
  .form-row, .creation-actions, .flashcard-actions, .combat-action-bar { flex-wrap: wrap; }
  .form-group { min-width: 0; }
  .input-text, .input-select { font-size: 16px; }
  .modal-card, .dialogue-box, .combat-arena-modal { max-width: calc(100vw - 16px); padding: 14px; }
  .modal-header h2 { font-size: 18px; overflow-wrap: anywhere; }
  .inventory-grid, .regions-grid, .skills-tree-grid, .combat-options-grid { grid-template-columns: 1fr; }
  .inventory-slot { min-width: 0; }
  .item-info { min-width: 0; overflow-wrap: anywhere; }
  .region-selection-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .region-select-item { min-width: 0; }
  .dialogue-option-btn, .combat-opt-btn, .btn { min-height: 44px; }
  .dialogue-speech-text { font-size: 18px; }
  #toast-container { width: calc(100% - 20px); }
  .toast { min-width: 0; }
}
@media (max-height: 500px) and (min-width: 500px) {
  .game-hud { padding-bottom: 116px; }
  .hud-quest-tracker { max-width: 220px; }
  .hud-top-right { top: 8px; max-width: 38%; }
  .hud-bottom-bar { align-self: flex-end; max-width: 60%; }
}

@media (max-width: 360px) {
  .touch-actions { flex-direction: column; gap: 4px; }
}

/* Keep the six title actions visible without a scrollable menu. */
.screen-title-overlay { overflow: hidden; padding: 12px; }
.title-card {
  width: 520px; max-width: 100%; max-height: none; overflow: visible;
  padding: 24px 30px;
}
.title-card .game-subtitle { margin-bottom: 14px; }
.title-card .title-crystal-display { margin-bottom: 18px; }
.title-card .crystal-icon { font-size: 42px; margin-bottom: 8px; }
.title-menu-buttons { gap: 8px; }
.title-menu-buttons .btn { min-height: 44px; padding: 8px 14px; }
.region-badges { flex-wrap: wrap; justify-content: center; }

@media (max-width: 700px) {
  .title-card { width: 440px; padding: 20px 16px; }
  .title-menu-buttons { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .title-menu-buttons .btn { font-size: 14px; }
}
@media (max-height: 620px) {
  .title-card { width: 520px; padding: 16px 20px; }
  .title-card .game-logo { font-size: 32px; }
  .title-card .game-subtitle { font-size: 13px; margin-bottom: 8px; }
  .title-card .title-crystal-display { margin-bottom: 12px; }
  .title-card .crystal-icon { font-size: 32px; margin-bottom: 4px; }
  .title-card .region-badges { font-size: 18px; }
  .title-menu-buttons { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
@media (max-height: 360px) and (min-width: 500px) {
  .title-card { width: 760px; display: grid; grid-template-columns: 1fr 1.3fr; column-gap: 24px; }
  .title-card .game-logo, .title-card .game-subtitle, .title-card .title-crystal-display { grid-column: 1; }
  .title-card .title-crystal-display { margin-bottom: 0; }
  .title-menu-buttons { grid-column: 2; grid-row: 1 / 4; align-content: center; }
}
/* Avoid the HUD and notifications covering one another. */
#toast-container { top: 144px; width: min(560px, calc(100% - 24px)); }
@media (max-width: 700px), (pointer: coarse) {
  #toast-container { top: 156px; }
}
@media (max-height: 500px) and (min-width: 500px) {
  #toast-container { top: 88px; width: min(440px, calc(100% - 24px)); }
}
@media (prefers-reduced-motion: reduce) {
  .pulse-glow { animation: none; }
  .btn, .hud-btn, .toast, .bar-fill { transition: none; }
}
@media (max-width: 700px) {
  .lexicon-tabs { flex-wrap: wrap; }
  .lexicon-grid { grid-template-columns: minmax(0, 1fr); }
  .flashcard-study-container { padding: 12px 0; }
  .study-card { width: 100%; max-width: 380px; height: auto; min-height: 220px; overflow-wrap: anywhere; }
  .flashcard-actions { justify-content: center; gap: 8px; }
  .flashcard-actions .btn { padding: 8px 12px; }
}
@media (max-height: 360px) and (max-width: 499px) {
  .title-card { padding: 12px 14px; }
  .title-card .crystal-icon { display: none; }
  .title-card .title-crystal-display { margin-bottom: 8px; }
}
@media (max-height: 280px) {
  .title-card .game-subtitle, .title-card .title-crystal-display { display: none; }
  .title-card .game-logo { font-size: 26px; margin-bottom: 8px; }
}
.entrance-list, .learning-stages { display: grid; gap: 8px; margin: 12px 0; }
.entrance-list .btn { text-align: left; justify-content: flex-start; }
.entrance-list button:disabled { opacity: .5; cursor: not-allowed; }
#btn-practice { margin: 16px 0; }
.hud-bottom-bar { flex-wrap: wrap; }
@media (max-width: 700px), (pointer: coarse) { .hud-bottom-bar { flex-wrap: nowrap; } }
/* Long dialogs scroll as a whole instead of collapsing their sections. */
.modal-card > * { flex-shrink: 0; }

/* Title menu panels share the world's dark crystal palette. */
.region-selection-intro { color: #94a3b8; line-height: 1.5; margin: -4px 0 18px; }
.region-selection-grid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 12px; }
.region-select-item {
  display: flex; flex-direction: column; align-items: flex-start; gap: 8px;
  min-width: 0; padding: 18px 14px; border-radius: 14px; border: 1px solid #334155;
  background: linear-gradient(145deg, #1e293b, #111c30); color: #e2e8f0;
  font: inherit; text-align: left; cursor: pointer;
  transition: border-color .15s, background .15s;
}
.region-select-item:hover:not(:disabled) { border-color: #38bdf8; background: #16324a; }
.region-select-item:focus-visible { outline: 3px solid #fbbf24; outline-offset: 3px; }
.region-select-item:disabled { opacity: .55; cursor: not-allowed; }
.sel-flag { display: grid; place-items: center; min-width: 44px; height: 40px; border-radius: 10px; background: rgba(56,189,248,.1); font-size: 26px; }
.sel-lang { color: #f8fafc; font-size: 17px; font-weight: 800; }
.sel-title { color: #94a3b8; font-size: 12px; line-height: 1.5; overflow-wrap: anywhere; }
.sel-action { margin-top: auto; padding-top: 6px; color: #38bdf8; font-size: 11px; font-weight: 700; }
.how-to-play-body, .credits-body { display: grid; gap: 14px; }
.guide-section { border: 1px solid #334155; border-radius: 14px; padding: 16px; background: rgba(30,41,59,.65); }
.guide-section h3 { color: #7dd3fc; font-size: 15px; margin: 0 0 12px; }
.guide-section p, .credits-hero p { color: #cbd5e1; font-size: 14px; line-height: 1.7; }
.guide-section p + p { margin-top: 10px; }
.controls-list { list-style: none; padding: 0; margin: 0; display: grid; gap: 0; }
.controls-list li { color: #cbd5e1; font-size: 14px; line-height: 1.6; padding: 9px 0; border-bottom: 1px solid rgba(148,163,184,.12); }
.controls-list li:first-child { padding-top: 0; }
.controls-list li:last-child { border: 0; padding-bottom: 0; }
.controls-list b { color: #f8fafc; }
.credits-hero { text-align: center; padding: 22px 16px; border: 1px solid #285572; border-radius: 14px; background: radial-gradient(ellipse at top, #15334a, #111c30); }
.credits-crystal { font-size: 36px; }
.credits-hero h3 { font-size: 28px; color: #38bdf8; margin: 8px 0; }
.credits-hero .credits-author { margin-bottom: 12px; }
.credits-author strong { color: #fbbf24; overflow-wrap: anywhere; }
@media (max-width: 700px) {
  .region-selection-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
  .region-select-item { padding: 14px 12px; }
  .guide-section { padding: 14px; }
}
@media (prefers-reduced-motion: reduce) { .region-select-item { transition: none; } }
