* {
  box-sizing: border-box;
}

:root {
  --bg-dark: #0a0f1a;
  --bg-mid: #141f2e;
  --bg-light: #1a2a3a;
  --panel: rgba(12, 20, 30, 0.92);
  --panel-border: rgba(255, 255, 255, 0.08);
  --gold: #c9a961;
  --cream: #f0e6d2;
  --red: #d95454;
  --green: #5dbe6f;
  --blue: #4a9fd8;
  --text: #e8f0f5;
  --muted: #a8b8c4;
  --accent: #ff6b6b;
}

* {
  margin: 0;
  padding: 0;
}

html, body {
  height: 100%;
  background: linear-gradient(135deg, var(--bg-dark) 0%, var(--bg-mid) 50%, var(--bg-dark) 100%);
  color: var(--text);
  font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
}

.app-shell {
  max-width: 1400px;
  margin: 0 auto;
  padding: 16px;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

.topbar {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  gap: 20px;
  background: var(--panel);
  border: 1px solid var(--panel-border);
  border-radius: 12px;
  padding: 16px;
  margin-bottom: 16px;
  box-shadow: 0 20px 40px rgba(0, 0, 0, 0.3);
}

.eyebrow {
  text-transform: uppercase;
  letter-spacing: 0.16em;
  font-size: 0.65rem;
  color: var(--gold);
  font-weight: 700;
}

h1 {
  margin: 6px 0 0 0;
  font-size: 1.3rem;
  color: var(--cream);
  font-weight: 600;
}

#locationText,
#levelNumber {
  margin-top: 4px;
  font-size: 0.95rem;
  color: var(--muted);
}

.game-layout {
  display: grid;
  grid-template-columns: 1fr 280px;
  gap: 16px;
  flex: 1;
}

.game-panel {
  position: relative;
  background: var(--bg-light);
  border: 1px solid var(--panel-border);
  border-radius: 12px;
  padding: 8px;
  box-shadow: 0 20px 40px rgba(0, 0, 0, 0.3);
}

#gameCanvas {
  width: 100%;
  height: auto;
  display: block;
  background: linear-gradient(to bottom, #1a3a5a 0%, #0a1020 100%);
  border-radius: 8px;
  border: 1px solid rgba(255, 255, 255, 0.05);
}

.canvas-info {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  pointer-events: none;
  font-size: 24px;
  color: rgba(255, 255, 255, 0.4);
}

.sidebar {
  display: grid;
  gap: 12px;
  overflow-y: auto;
  max-height: calc(100vh - 160px);
}

.panel {
  background: var(--panel);
  border: 1px solid var(--panel-border);
  border-radius: 12px;
  padding: 14px;
  box-shadow: 0 10px 20px rgba(0, 0, 0, 0.2);
}

.panel h2 {
  margin: 0 0 10px 0;
  font-size: 0.9rem;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--gold);
}

.quest-title {
  font-weight: 700;
  color: var(--cream);
  margin-bottom: 6px;
}

.quest-desc {
  font-size: 0.85rem;
  color: var(--muted);
  line-height: 1.4;
  margin-bottom: 8px;
}

.quest-reward {
  font-size: 0.8rem;
  color: var(--green);
  font-weight: 600;
}

.inventory-list {
  display: grid;
  gap: 6px;
}

.inventory-item {
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid var(--panel-border);
  border-radius: 6px;
  padding: 8px;
  font-size: 0.85rem;
  color: var(--muted);
  text-transform: capitalize;
  word-break: break-word;
}

.stat-row {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 8px;
  font-size: 0.9rem;
  color: var(--muted);
}

.health-bar {
  flex: 1;
  height: 16px;
  background: rgba(0, 0, 0, 0.4);
  border-radius: 4px;
  border: 1px solid var(--panel-border);
  overflow: hidden;
}

.health-fill {
  height: 100%;
  background: linear-gradient(90deg, var(--green), var(--blue));
  transition: width 0.3s ease;
  width: 100%;
}

button {
  border: none;
  border-radius: 8px;
  background: linear-gradient(135deg, var(--gold), #a87f3f);
  color: #1a1208;
  font-weight: 700;
  padding: 8px 12px;
  font-size: 0.85rem;
  cursor: pointer;
  transition: filter 0.2s ease;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

button:hover:not(.hidden) {
  filter: brightness(1.1);
}

button.hidden {
  display: none;
}

.button-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  margin-top: 10px;
}

.button-row button {
  padding: 6px 10px;
  font-size: 0.75rem;
}

.controls-panel p {
  font-size: 0.8rem;
  color: var(--muted);
  line-height: 1.6;
  margin: 0;
}

/* Dialogue Box */
.dialogue {
  position: fixed;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  width: min(600px, 90vw);
  background: rgba(10, 15, 26, 0.98);
  border: 2px solid var(--gold);
  border-radius: 12px;
  padding: 24px;
  box-shadow: 0 40px 80px rgba(0, 0, 0, 0.5);
  z-index: 100;
  backdrop-filter: blur(4px);
}

.dialogue-speaker {
  font-size: 1.1rem;
  font-weight: 700;
  color: var(--gold);
  margin-bottom: 4px;
}

.dialogue-role {
  font-size: 0.8rem;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.08em;
  margin-bottom: 12px;
}

.dialogue-text {
  color: var(--cream);
  line-height: 1.7;
  font-size: 1rem;
  margin-bottom: 16px;
}

#dialogueClose {
  width: 100%;
}

.hidden {
  display: none !important;
}

/* Popups & Modals */
.popup,
.modal {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.7);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 200;
  backdrop-filter: blur(3px);
}

.popup-content,
.modal-content {
  background: var(--panel);
  border: 2px solid var(--gold);
  border-radius: 12px;
  padding: 28px;
  width: min(500px, 90vw);
  box-shadow: 0 40px 80px rgba(0, 0, 0, 0.5);
}

.popup-title,
.modal-content h2 {
  font-size: 1.3rem;
  color: var(--cream);
  margin-bottom: 12px;
  font-weight: 700;
}

.popup-text {
  color: var(--muted);
  line-height: 1.6;
  margin-bottom: 20px;
}

.modal-content h2 {
  color: var(--gold);
}

#mapCanvas {
  width: 100%;
  border: 1px solid var(--panel-border);
  border-radius: 8px;
  margin: 16px 0;
  background: #0a0f1a;
}

#completeStats {
  color: var(--muted);
  line-height: 1.8;
  margin: 16px 0;
}

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

@media (max-width: 1200px) {
  .game-layout {
    grid-template-columns: 1fr;
  }

  .sidebar {
    max-height: 300px;
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  }
}

@media (max-width: 768px) {
  .topbar {
    grid-template-columns: 1fr;
    gap: 12px;
  }

  h1 {
    font-size: 1.1rem;
  }
}
