/* MudForge Client Styles - Linear.app Inspired */

@import url('https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600&display=swap');

:root {
  /* Linear-inspired colors */
  --bg-primary: #0d0d0f;
  --bg-secondary: #141416;
  --bg-tertiary: #1a1a1f;
  --bg-hover: #222228;
  --bg-terminal: #0a0a0c;

  --border-primary: #2a2a30;
  --border-subtle: #1f1f24;

  --text-primary: #f5f5f5;
  --text-secondary: #8b8b8e;
  --text-tertiary: #5c5c60;

  --accent: #5e6ad2;
  --accent-hover: #7c85e0;
  --accent-subtle: rgba(94, 106, 210, 0.15);

  --success: #4ade80;
  --success-subtle: rgba(74, 222, 128, 0.15);
  --error: #f87171;
  --error-subtle: rgba(248, 113, 113, 0.15);
  --warning: #fbbf24;
  --warning-subtle: rgba(251, 191, 36, 0.15);

  /* ANSI Colors - Refined for dark theme */
  --ansi-black: #1a1a1a;
  --ansi-red: #f87171;
  --ansi-green: #4ade80;
  --ansi-yellow: #fbbf24;
  --ansi-blue: #60a5fa;
  --ansi-magenta: #c084fc;
  --ansi-cyan: #22d3ee;
  --ansi-white: #f5f5f5;
  --ansi-bright-black: #525252;
  --ansi-bright-red: #fca5a5;
  --ansi-bright-green: #86efac;
  --ansi-bright-yellow: #fde047;
  --ansi-bright-blue: #93c5fd;
  --ansi-bright-magenta: #d8b4fe;
  --ansi-bright-cyan: #67e8f9;
  --ansi-bright-white: #ffffff;

  /* Spacing */
  --spacing-xs: 4px;
  --spacing-sm: 8px;
  --spacing-md: 16px;
  --spacing-lg: 24px;
  --spacing-xl: 32px;

  /* Typography */
  --font-sans: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  --font-mono: 'JetBrains Mono', 'Fira Code', 'Consolas', 'Monaco', monospace;
  --font-size-xs: 11px;
  --font-size-sm: 13px;
  --font-size-base: 14px;
  --font-size-lg: 16px;
  --line-height: 1.3;

  /* Layout */
  --header-height: 52px;
  --input-height: 56px;
  --border-radius: 8px;
  --border-radius-sm: 6px;

  /* Shadows */
  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.3);
  --shadow-md: 0 4px 12px rgba(0, 0, 0, 0.4);
  --shadow-lg: 0 8px 24px rgba(0, 0, 0, 0.5);
}

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

/* Base */
html,
body {
  height: 100%;
  overflow: hidden;
}

body {
  font-family: var(--font-sans);
  font-size: var(--font-size-base);
  line-height: var(--line-height);
  color: var(--text-primary);
  background-color: var(--bg-primary);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

/* Layout */
#app {
  display: flex;
  flex-direction: column;
  height: 100vh;
  background: linear-gradient(180deg, var(--bg-secondary) 0%, var(--bg-primary) 100%);
}

/* Header */
#header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  height: var(--header-height);
  padding: 0 var(--spacing-lg);
  background-color: var(--bg-secondary);
  border-bottom: 1px solid var(--border-primary);
  flex-shrink: 0;
}

#header h1 {
  font-size: var(--font-size-lg);
  font-weight: 600;
  color: var(--text-primary);
  letter-spacing: -0.02em;
  display: flex;
  align-items: center;
  gap: var(--spacing-sm);
}

#header h1::before {
  content: '';
  display: inline-block;
  width: 8px;
  height: 8px;
  background: var(--accent);
  border-radius: 2px;
}

#status {
  font-size: var(--font-size-xs);
  font-weight: 500;
  padding: var(--spacing-xs) var(--spacing-sm);
  border-radius: 9999px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  display: flex;
  align-items: center;
  gap: 6px;
}

#status::before {
  content: '';
  display: inline-block;
  width: 6px;
  height: 6px;
  border-radius: 50%;
}

#status.connected {
  color: var(--success);
  background-color: var(--success-subtle);
}

#status.connected::before {
  background-color: var(--success);
  box-shadow: 0 0 8px var(--success);
}

#status.disconnected {
  color: var(--error);
  background-color: var(--error-subtle);
}

#status.disconnected::before {
  background-color: var(--error);
}

#status.connecting {
  color: var(--warning);
  background-color: var(--warning-subtle);
}

#status.connecting::before {
  background-color: var(--warning);
  animation: pulse 1.5s infinite;
}

@keyframes pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.4; }
}

#terminal {
  height: 100%;
  padding: var(--spacing-lg);
  padding-bottom: var(--spacing-xl);
  overflow-y: auto;
  font-family: var(--font-mono);
  font-size: var(--font-size-sm);
  white-space: pre-wrap;
  word-wrap: break-word;
  scroll-behavior: smooth;
}

#terminal::-webkit-scrollbar {
  width: 6px;
}

#terminal::-webkit-scrollbar-track {
  background: transparent;
}

#terminal::-webkit-scrollbar-thumb {
  background: var(--border-primary);
  border-radius: 3px;
}

#terminal::-webkit-scrollbar-thumb:hover {
  background: var(--text-tertiary);
}

/* Terminal lines */
.line {
  display: block;
  min-height: 1.3em;
  padding: 1px 0;
}

.line.input {
  color: var(--accent);
  opacity: 0.9;
}

.line.input::before {
  content: '› ';
  color: var(--text-tertiary);
}

.line.system {
  color: var(--text-secondary);
  font-style: italic;
}

.line.error {
  color: var(--error);
}

/* ANSI color classes */
.ansi-bold { font-weight: 600; }
.ansi-dim { opacity: 0.6; }
.ansi-italic { font-style: italic; }
.ansi-underline { text-decoration: underline; text-underline-offset: 2px; }
.ansi-reverse { filter: invert(1); }
.ansi-hidden { visibility: hidden; }
.ansi-strikethrough { text-decoration: line-through; }

.ansi-fg-black { color: var(--ansi-black); }
.ansi-fg-red { color: var(--ansi-red); }
.ansi-fg-green { color: var(--ansi-green); }
.ansi-fg-yellow { color: var(--ansi-yellow); }
.ansi-fg-blue { color: var(--ansi-blue); }
.ansi-fg-magenta { color: var(--ansi-magenta); }
.ansi-fg-cyan { color: var(--ansi-cyan); }
.ansi-fg-white { color: var(--ansi-white); }

.ansi-fg-bright-black { color: var(--ansi-bright-black); }
.ansi-fg-bright-red { color: var(--ansi-bright-red); }
.ansi-fg-bright-green { color: var(--ansi-bright-green); }
.ansi-fg-bright-yellow { color: var(--ansi-bright-yellow); }
.ansi-fg-bright-blue { color: var(--ansi-bright-blue); }
.ansi-fg-bright-magenta { color: var(--ansi-bright-magenta); }
.ansi-fg-bright-cyan { color: var(--ansi-bright-cyan); }
.ansi-fg-bright-white { color: var(--ansi-bright-white); }

.ansi-bg-black { background-color: var(--ansi-black); }
.ansi-bg-red { background-color: var(--ansi-red); }
.ansi-bg-green { background-color: var(--ansi-green); }
.ansi-bg-yellow { background-color: var(--ansi-yellow); }
.ansi-bg-blue { background-color: var(--ansi-blue); }
.ansi-bg-magenta { background-color: var(--ansi-magenta); }
.ansi-bg-cyan { background-color: var(--ansi-cyan); }
.ansi-bg-white { background-color: var(--ansi-white); }

/* Input */
#input-container {
  display: flex;
  height: var(--input-height);
  padding: var(--spacing-sm) var(--spacing-lg);
  background-color: var(--bg-secondary);
  border-top: 1px solid var(--border-primary);
  gap: var(--spacing-sm);
  align-items: center;
  flex-shrink: 0;
}

#input {
  flex: 1;
  height: 40px;
  padding: 0 var(--spacing-md);
  font-family: var(--font-mono);
  font-size: var(--font-size-sm);
  color: var(--text-primary);
  background-color: var(--bg-tertiary);
  border: 1px solid var(--border-primary);
  border-radius: var(--border-radius);
  outline: none;
  transition: all 0.15s ease;
}

#input:hover {
  border-color: var(--border-primary);
  background-color: var(--bg-hover);
}

#input:focus {
  border-color: var(--accent);
  background-color: var(--bg-tertiary);
  box-shadow: 0 0 0 3px var(--accent-subtle);
}

#input::placeholder {
  color: var(--text-tertiary);
}

#send-btn {
  height: 40px;
  padding: 0 var(--spacing-lg);
  font-family: var(--font-sans);
  font-size: var(--font-size-sm);
  font-weight: 500;
  color: white;
  background-color: var(--accent);
  border: none;
  border-radius: var(--border-radius);
  cursor: pointer;
  transition: all 0.15s ease;
}

#send-btn:hover {
  background-color: var(--accent-hover);
  transform: translateY(-1px);
  box-shadow: var(--shadow-md);
}

#send-btn:active {
  transform: translateY(0);
  box-shadow: none;
}

/* Accessibility */
.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

/* Responsive */
@media (max-width: 600px) {
  :root {
    --font-size-sm: 12px;
    --font-size-base: 13px;
  }

  #header {
    padding: 0 var(--spacing-md);
  }

  #header h1 {
    font-size: var(--font-size-base);
  }

  #terminal {
    padding: var(--spacing-md);
  }

  #input-container {
    padding: var(--spacing-sm) var(--spacing-md);
  }

  #send-btn {
    padding: 0 var(--spacing-md);
  }
}

/* Code Editor */
.code-editor-wrapper {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  display: flex;
  flex-direction: column;
  background-color: var(--bg-primary);
  z-index: 1000;
}

.code-editor-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: var(--spacing-sm) var(--spacing-lg);
  background-color: var(--bg-secondary);
  border-bottom: 1px solid var(--border-primary);
}

.code-editor-filepath {
  font-family: var(--font-mono);
  font-size: var(--font-size-sm);
  font-weight: 500;
  color: var(--text-primary);
}

.code-editor-buttons {
  display: flex;
  gap: var(--spacing-sm);
}

.code-editor-buttons button {
  padding: var(--spacing-xs) var(--spacing-md);
  font-family: var(--font-sans);
  font-size: var(--font-size-xs);
  font-weight: 500;
  border-radius: var(--border-radius-sm);
  cursor: pointer;
  transition: all 0.15s ease;
}

.code-editor-save {
  color: white;
  background-color: var(--accent);
  border: none;
}

.code-editor-save:hover {
  background-color: var(--accent-hover);
}

.code-editor-close {
  color: var(--text-secondary);
  background-color: transparent;
  border: 1px solid var(--border-primary);
}

.code-editor-close:hover {
  color: var(--text-primary);
  background-color: var(--bg-hover);
  border-color: var(--border-primary);
}

.code-editor-area {
  flex: 1;
  display: flex;
  overflow: hidden;
}

.code-editor-lines {
  width: 50px;
  padding: var(--spacing-md) var(--spacing-sm);
  background-color: var(--bg-secondary);
  text-align: right;
  overflow: hidden;
  user-select: none;
  border-right: 1px solid var(--border-subtle);
}

.code-editor-line-number {
  height: 20px;
  line-height: 20px;
  color: var(--text-tertiary);
  font-family: var(--font-mono);
  font-size: var(--font-size-xs);
}

.code-editor-textarea {
  flex: 1;
  padding: var(--spacing-md);
  font-family: var(--font-mono);
  font-size: var(--font-size-sm);
  line-height: 20px;
  color: var(--text-primary);
  background-color: var(--bg-terminal);
  border: none;
  outline: none;
  resize: none;
  white-space: pre;
  overflow: auto;
  tab-size: 2;
}

.code-editor-textarea::-webkit-scrollbar {
  width: 6px;
  height: 6px;
}

.code-editor-textarea::-webkit-scrollbar-track {
  background: transparent;
}

.code-editor-textarea::-webkit-scrollbar-thumb {
  background: var(--border-primary);
  border-radius: 3px;
}

.code-editor-errors {
  max-height: 150px;
  padding: var(--spacing-md);
  background-color: var(--error-subtle);
  border-top: 1px solid var(--error);
  overflow-y: auto;
}

.code-editor-error-title {
  font-weight: 600;
  font-size: var(--font-size-sm);
  color: var(--error);
  margin-bottom: var(--spacing-sm);
}

.code-editor-error-item {
  padding: var(--spacing-xs) 0;
  cursor: pointer;
  border-bottom: 1px solid var(--border-subtle);
  font-size: var(--font-size-xs);
}

.code-editor-error-item:last-child {
  border-bottom: none;
}

.code-editor-error-item:hover {
  background-color: rgba(255, 255, 255, 0.03);
}

.code-editor-error-location {
  font-family: var(--font-mono);
  color: var(--warning);
  margin-right: var(--spacing-sm);
}

.code-editor-error-message {
  color: var(--text-primary);
}

.code-editor-status {
  padding: var(--spacing-xs) var(--spacing-lg);
  background-color: var(--bg-secondary);
  color: var(--text-tertiary);
  font-size: var(--font-size-xs);
  border-top: 1px solid var(--border-subtle);
}

/* IDE Modal */
.ide-modal {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  display: flex;
  flex-direction: column;
  background-color: var(--bg-primary);
  z-index: 2000;
}

.ide-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: var(--spacing-sm) var(--spacing-lg);
  background-color: var(--bg-secondary);
  border-bottom: 1px solid var(--border-primary);
  flex-shrink: 0;
}

.ide-filepath {
  font-family: var(--font-mono);
  font-size: var(--font-size-sm);
  font-weight: 500;
  color: var(--text-primary);
}

.ide-buttons {
  display: flex;
  gap: var(--spacing-sm);
}

.ide-btn {
  padding: var(--spacing-xs) var(--spacing-md);
  font-family: var(--font-sans);
  font-size: var(--font-size-xs);
  font-weight: 500;
  border-radius: var(--border-radius-sm);
  cursor: pointer;
  transition: all 0.15s ease;
}

.ide-btn-save {
  color: white;
  background-color: var(--accent);
  border: none;
}

.ide-btn-save:hover {
  background-color: var(--accent-hover);
}

.ide-btn-close {
  color: var(--text-secondary);
  background-color: transparent;
  border: 1px solid var(--border-primary);
}

.ide-btn-close:hover {
  color: var(--text-primary);
  background-color: var(--bg-hover);
}

.ide-theme-select {
  padding: var(--spacing-xs) var(--spacing-sm);
  font-family: var(--font-sans);
  font-size: var(--font-size-xs);
  color: var(--text-primary);
  background-color: var(--bg-tertiary);
  border: 1px solid var(--border-primary);
  border-radius: var(--border-radius-sm);
  cursor: pointer;
  outline: none;
}

.ide-theme-select:hover {
  background-color: var(--bg-hover);
}

.ide-theme-select:focus {
  border-color: var(--accent);
}

.ide-editor-container {
  flex: 1;
  overflow: hidden;
  background-color: var(--bg-terminal);
}

.ide-editor-container .cm-editor {
  height: 100%;
}

.ide-editor-container .cm-scroller {
  overflow: auto;
}

.ide-error-panel {
  max-height: 180px;
  padding: var(--spacing-md);
  background-color: var(--error-subtle);
  border-top: 2px solid var(--error);
  overflow-y: auto;
  flex-shrink: 0;
}

.ide-error-title {
  font-weight: 600;
  font-size: var(--font-size-sm);
  color: var(--error);
  margin-bottom: var(--spacing-sm);
}

.ide-error-list {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.ide-error-item {
  padding: var(--spacing-xs) var(--spacing-sm);
  cursor: pointer;
  border-radius: var(--border-radius-sm);
  font-size: var(--font-size-xs);
  display: flex;
  align-items: flex-start;
  gap: var(--spacing-sm);
}

.ide-error-item:hover {
  background-color: rgba(255, 255, 255, 0.05);
}

.ide-error-location {
  font-family: var(--font-mono);
  color: var(--warning);
  white-space: nowrap;
  flex-shrink: 0;
}

.ide-error-message {
  color: var(--text-primary);
  word-break: break-word;
}

.ide-status {
  padding: var(--spacing-xs) var(--spacing-lg);
  background-color: var(--bg-secondary);
  color: var(--text-tertiary);
  font-size: var(--font-size-xs);
  border-top: 1px solid var(--border-subtle);
  flex-shrink: 0;
}

/* Main Content Layout */
#main-content {
  flex: 1;
  display: flex;
  overflow: hidden;
}

/* Terminal */
#terminal-container {
  flex: 1;
  overflow: hidden;
  background-color: var(--bg-terminal);
  position: relative;
}

/* Quest Sidebar - Docked Left */
#quest-container {
  width: 220px;
  min-width: 220px;
  background-color: var(--bg-secondary);
  border-right: 1px solid var(--border-primary);
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
  overflow: hidden;
}

.quest-panel {
  display: flex;
  flex-direction: column;
  height: 100%;
}

.quest-panel.collapsed .quest-panel-content {
  display: none;
}

.quest-panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: var(--spacing-sm) var(--spacing-md);
  background-color: var(--bg-tertiary);
  border-bottom: 1px solid var(--border-primary);
  flex-shrink: 0;
}

.quest-panel-title {
  font-size: var(--font-size-xs);
  font-weight: 500;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.quest-btn {
  width: 18px;
  height: 18px;
  padding: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 10px;
  font-weight: 600;
  color: var(--text-secondary);
  background-color: var(--bg-hover);
  border: 1px solid var(--border-primary);
  border-radius: var(--border-radius-sm);
  cursor: pointer;
  transition: all 0.15s ease;
}

.quest-btn:hover {
  color: var(--text-primary);
  background-color: var(--bg-tertiary);
  border-color: var(--accent);
}

.quest-panel-content {
  flex: 1;
  overflow-y: auto;
  padding: var(--spacing-sm);
  display: flex;
  flex-direction: column;
  gap: var(--spacing-sm);
}

.quest-panel-content::-webkit-scrollbar {
  width: 4px;
}

.quest-panel-content::-webkit-scrollbar-track {
  background: transparent;
}

.quest-panel-content::-webkit-scrollbar-thumb {
  background: var(--border-primary);
  border-radius: 2px;
}

.quest-empty {
  color: var(--text-tertiary);
  font-size: var(--font-size-sm);
  text-align: center;
  padding: var(--spacing-lg) var(--spacing-sm);
}

.quest-item {
  padding: var(--spacing-sm);
  background-color: var(--bg-tertiary);
  border: 1px solid var(--border-subtle);
  border-radius: var(--border-radius-sm);
  cursor: pointer;
  transition: all 0.15s ease;
}

.quest-item:hover {
  border-color: var(--accent);
  background-color: var(--bg-hover);
}

.quest-item.quest-completed {
  border-color: var(--success);
}

.quest-item.quest-completed .quest-name {
  color: var(--success);
}

.quest-item.quest-completed .quest-progress-bar {
  background: linear-gradient(90deg, #22c55e, #4ade80);
}

.quest-name {
  font-size: var(--font-size-sm);
  font-weight: 500;
  color: var(--text-primary);
  margin-bottom: var(--spacing-xs);
  line-height: 1.3;
}

.quest-progress {
  height: 6px;
  background-color: var(--bg-primary);
  border-radius: 3px;
  overflow: hidden;
  margin-bottom: var(--spacing-xs);
}

.quest-progress-bar {
  height: 100%;
  background: linear-gradient(90deg, #eab308, #fbbf24);
  border-radius: 3px;
  transition: width 0.3s ease;
}

.quest-progress-text {
  font-size: var(--font-size-xs);
  color: var(--text-secondary);
  line-height: 1.3;
}

/* Stats Panel - Floating Toolbar */
#stats-container {
  position: absolute;
  top: 260px;
  right: 8px;
  z-index: 100;
}

.stats-panel {
  background-color: var(--bg-secondary);
  border: 1px solid var(--border-primary);
  border-radius: var(--border-radius);
  box-shadow: var(--shadow-lg);
  opacity: 0.95;
  transition: opacity 0.15s ease, box-shadow 0.15s ease;
}

.stats-panel:hover {
  opacity: 1;
}

.stats-panel.dragging {
  opacity: 0.85;
  box-shadow: var(--shadow-lg), 0 0 0 2px var(--accent);
  cursor: grabbing;
}

.stats-panel.collapsed .stats-panel-content {
  display: none;
}

.stats-panel.hidden {
  display: none;
}

.stats-panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: var(--spacing-xs) var(--spacing-sm);
  background-color: var(--bg-tertiary);
  border-bottom: 1px solid var(--border-primary);
  border-radius: var(--border-radius) var(--border-radius) 0 0;
  cursor: grab;
  user-select: none;
}

.stats-panel-header:active {
  cursor: grabbing;
}

.stats-panel-title {
  font-size: var(--font-size-xs);
  font-weight: 500;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.stats-btn {
  width: 18px;
  height: 18px;
  padding: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 10px;
  font-weight: 600;
  color: var(--text-secondary);
  background-color: var(--bg-hover);
  border: 1px solid var(--border-primary);
  border-radius: var(--border-radius-sm);
  cursor: pointer;
  transition: all 0.15s ease;
}

.stats-btn:hover {
  color: var(--text-primary);
  background-color: var(--bg-tertiary);
  border-color: var(--accent);
}

.stats-panel-content {
  padding: var(--spacing-sm);
  display: flex;
  flex-direction: column;
  gap: var(--spacing-sm);
}

/* Level display */
.stats-level {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: var(--spacing-xs) var(--spacing-sm);
  background-color: var(--bg-tertiary);
  border-radius: var(--border-radius-sm);
}

.stats-level-label {
  font-size: var(--font-size-xs);
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.stats-level-value {
  font-size: var(--font-size-base);
  font-weight: 600;
  color: var(--accent);
}

/* Stat bars */
.stats-bar-group {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

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

.stats-bar-label {
  font-size: var(--font-size-xs);
  font-weight: 500;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.stats-bar-value {
  font-size: var(--font-size-xs);
  font-family: var(--font-mono);
  color: var(--text-secondary);
  white-space: nowrap;
}

.stats-bar {
  width: 140px;
  height: 10px;
  background-color: var(--bg-tertiary);
  border-radius: 3px;
  overflow: hidden;
}

.stats-bar-fill {
  height: 100%;
  transition: width 0.3s ease, background-color 0.3s ease;
  border-radius: 3px;
}

/* HP bar colors */
.stats-bar-hp .stats-bar-fill,
.stats-bar-fill.hp-high {
  background: linear-gradient(90deg, #22c55e, #4ade80);
}

.stats-bar-fill.hp-medium {
  background: linear-gradient(90deg, #eab308, #fbbf24);
}

.stats-bar-fill.hp-low {
  background: linear-gradient(90deg, #f97316, #fb923c);
}

.stats-bar-fill.hp-critical {
  background: linear-gradient(90deg, #dc2626, #ef4444);
  animation: hp-pulse 1s ease-in-out infinite;
}

@keyframes hp-pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.6; }
}

/* MP bar colors */
.stats-bar-mp .stats-bar-fill,
.stats-bar-fill.mp-high {
  background: linear-gradient(90deg, #3b82f6, #60a5fa);
}

.stats-bar-fill.mp-low {
  background: linear-gradient(90deg, #06b6d4, #22d3ee);
}

/* XP bar colors */
.stats-bar-xp .stats-bar-fill {
  background: linear-gradient(90deg, #eab308, #fbbf24);
}

/* Gold display */
.stats-gold-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.stats-gold-header {
  display: flex;
  align-items: center;
  gap: var(--spacing-xs);
  font-size: var(--font-size-xs);
  font-weight: 500;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.stats-gold-icon {
  font-size: var(--font-size-xs);
}

.stats-gold-value {
  font-size: var(--font-size-xs);
  font-family: var(--font-mono);
  color: var(--text-secondary);
}

.stats-gold-bank {
  opacity: 0.7;
}

/* Map Panel - Floating Toolbar */
#map-container {
  position: absolute;
  top: 8px;
  right: 8px;
  z-index: 100;
}

.map-panel {
  background-color: var(--bg-secondary);
  border: 1px solid var(--border-primary);
  border-radius: var(--border-radius);
  box-shadow: var(--shadow-lg);
  opacity: 0.95;
  transition: opacity 0.15s ease, box-shadow 0.15s ease;
  display: flex;
  flex-direction: column;
  width: 220px;
  height: 240px;
  min-width: 150px;
  min-height: 150px;
  max-width: 500px;
  max-height: 500px;
  position: relative;
}

.map-panel:hover {
  opacity: 1;
}

.map-panel.dragging {
  opacity: 0.85;
  box-shadow: var(--shadow-lg), 0 0 0 2px var(--accent);
  cursor: grabbing;
}

.map-panel.collapsed {
  width: auto !important;
  height: auto !important;
  min-height: 0;
}

.map-panel.resizing {
  opacity: 0.9;
  box-shadow: var(--shadow-lg), 0 0 0 2px var(--accent);
}

/* Resize handle */
.map-resize-handle {
  position: absolute;
  bottom: 0;
  right: 0;
  width: 16px;
  height: 16px;
  cursor: nwse-resize;
  z-index: 10;
}

.map-resize-handle::before {
  content: '';
  position: absolute;
  bottom: 4px;
  right: 4px;
  width: 8px;
  height: 8px;
  border-right: 2px solid var(--text-tertiary);
  border-bottom: 2px solid var(--text-tertiary);
  opacity: 0.5;
  transition: opacity 0.15s ease;
}

.map-resize-handle:hover::before {
  opacity: 1;
  border-color: var(--accent);
}

.map-panel.collapsed .map-panel-content,
.map-panel.collapsed .map-panel-legend,
.map-panel.collapsed .map-zoom-level,
.map-panel.collapsed .map-btn-zoom-in,
.map-panel.collapsed .map-btn-zoom-out,
.map-panel.collapsed .map-resize-handle {
  display: none;
}

.map-panel.hidden {
  display: none;
}

.map-panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: var(--spacing-xs) var(--spacing-sm);
  background-color: var(--bg-tertiary);
  border-bottom: 1px solid var(--border-primary);
  border-radius: var(--border-radius) var(--border-radius) 0 0;
  flex-shrink: 0;
  cursor: grab;
  user-select: none;
}

.map-panel-header:active {
  cursor: grabbing;
}

.map-panel-title {
  font-size: var(--font-size-xs);
  font-weight: 500;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.map-panel-controls {
  display: flex;
  align-items: center;
  gap: 2px;
}

.map-btn {
  width: 18px;
  height: 18px;
  padding: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 10px;
  font-weight: 600;
  color: var(--text-secondary);
  background-color: var(--bg-hover);
  border: 1px solid var(--border-primary);
  border-radius: var(--border-radius-sm);
  cursor: pointer;
  transition: all 0.15s ease;
}

.map-btn:hover {
  color: var(--text-primary);
  background-color: var(--bg-tertiary);
  border-color: var(--accent);
}

.map-zoom-level {
  font-size: var(--font-size-xs);
  font-weight: 500;
  color: var(--text-secondary);
  min-width: 14px;
  text-align: center;
}

.map-panel-content {
  flex: 1;
  overflow: hidden;
  background-color: var(--bg-terminal);
}

.map-svg {
  width: 100%;
  height: 100%;
  background-color: var(--bg-terminal);
}

.map-svg rect {
  cursor: pointer;
  transition: opacity 0.15s ease;
}

.map-svg rect:hover {
  opacity: 0.8 !important;
}

.player-marker {
  animation: player-pulse 1.5s ease-in-out infinite;
}

@keyframes player-pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.7; }
}

.map-panel-legend {
  display: flex;
  flex-wrap: wrap;
  gap: var(--spacing-xs);
  padding: var(--spacing-xs) var(--spacing-sm);
  background-color: var(--bg-tertiary);
  border-top: 1px solid var(--border-primary);
  border-radius: 0 0 var(--border-radius) var(--border-radius);
  flex-shrink: 0;
}

.map-legend-item {
  display: flex;
  align-items: center;
  gap: 2px;
  font-size: 9px;
  color: var(--text-secondary);
}

.map-legend-marker {
  font-family: var(--font-mono);
  font-size: var(--font-size-xs);
}

.map-legend-marker.player {
  color: #ffffff;
  font-weight: bold;
}

.map-legend-marker.explored {
  color: #4a7c23;
}

.map-legend-marker.revealed {
  color: #2d4d16;
  opacity: 0.7;
}

.map-legend-marker.hinted {
  color: #666666;
}

/* =============================================================================
   GUI Modal System
   ============================================================================= */

/* Modal Overlay */
.gui-modal-overlay {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background-color: rgba(0, 0, 0, 0.75);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 3000;
  animation: fadeIn 0.15s ease-out;
}

@keyframes fadeIn {
  from { opacity: 0; }
  to { opacity: 1; }
}

/* Modal Container */
.gui-modal {
  background-color: var(--bg-secondary);
  border: 1px solid var(--border-primary);
  border-radius: var(--border-radius);
  box-shadow: var(--shadow-lg);
  display: flex;
  flex-direction: column;
  max-height: 90vh;
  overflow: hidden;
  animation: slideIn 0.2s ease-out;
}

@keyframes slideIn {
  from {
    opacity: 0;
    transform: translateY(-20px) scale(0.98);
  }
  to {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
}

/* Modal Sizes */
.gui-modal-small { width: 400px; max-width: 95vw; }
.gui-modal-medium { width: 600px; max-width: 95vw; }
.gui-modal-large { width: 800px; max-width: 95vw; }
.gui-modal-fullscreen { width: 95vw; height: 90vh; }
.gui-modal-auto { max-width: 95vw; min-width: 300px; }

/* Modal Header */
.gui-modal-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  padding: var(--spacing-md) var(--spacing-lg);
  background-color: var(--bg-tertiary);
  border-bottom: 1px solid var(--border-primary);
  flex-shrink: 0;
}

.gui-modal-title-wrapper {
  flex: 1;
  min-width: 0;
}

.gui-modal-title {
  font-size: var(--font-size-lg);
  font-weight: 600;
  color: var(--text-primary);
  margin: 0;
}

.gui-modal-subtitle {
  font-size: var(--font-size-sm);
  color: var(--text-secondary);
  margin-top: 2px;
}

.gui-modal-close {
  width: 28px;
  height: 28px;
  border: none;
  background: transparent;
  color: var(--text-secondary);
  cursor: pointer;
  border-radius: var(--border-radius-sm);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 20px;
  flex-shrink: 0;
  margin-left: var(--spacing-sm);
  transition: background-color 0.15s ease, color 0.15s ease;
}

.gui-modal-close:hover {
  background-color: var(--bg-hover);
  color: var(--text-primary);
}

/* Modal Body */
.gui-modal-body {
  flex: 1;
  padding: var(--spacing-lg);
  overflow-y: auto;
}

/* Modal Footer */
.gui-modal-footer {
  display: flex;
  gap: var(--spacing-sm);
  justify-content: flex-end;
  padding: var(--spacing-md) var(--spacing-lg);
  background-color: var(--bg-tertiary);
  border-top: 1px solid var(--border-primary);
  flex-shrink: 0;
}

.gui-modal-footer:empty {
  display: none;
}

/* Global Error */
.gui-global-error {
  padding: var(--spacing-sm) var(--spacing-md);
  margin-bottom: var(--spacing-md);
  background-color: var(--error-subtle);
  border: 1px solid var(--error);
  border-radius: var(--border-radius-sm);
  color: var(--error);
  font-size: var(--font-size-sm);
}

/* =============================================================================
   GUI Form Elements
   ============================================================================= */

/* Field Wrapper */
.gui-field {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.gui-label {
  font-size: var(--font-size-sm);
  font-weight: 500;
  color: var(--text-secondary);
}

/* Text Input */
.gui-input,
.gui-select,
.gui-textarea {
  padding: var(--spacing-sm) var(--spacing-md);
  font-family: var(--font-sans);
  font-size: var(--font-size-sm);
  color: var(--text-primary);
  background-color: var(--bg-tertiary);
  border: 1px solid var(--border-primary);
  border-radius: var(--border-radius-sm);
  outline: none;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

.gui-input:focus,
.gui-select:focus,
.gui-textarea:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-subtle);
}

.gui-input:disabled,
.gui-select:disabled,
.gui-textarea:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.gui-input::placeholder,
.gui-textarea::placeholder {
  color: var(--text-tertiary);
}

.gui-input-error {
  border-color: var(--error) !important;
}

.gui-field-error {
  font-size: var(--font-size-xs);
  color: var(--error);
  margin-top: 2px;
}

/* Textarea */
.gui-textarea {
  resize: vertical;
  min-height: 80px;
}

/* Select */
.gui-select {
  cursor: pointer;
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' fill='%238b8b8e' viewBox='0 0 16 16'%3E%3Cpath d='M4 6l4 4 4-4'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 12px center;
  padding-right: 36px;
}

/* Radio Group */
.gui-radio-group {
  display: flex;
  flex-direction: column;
  gap: var(--spacing-sm);
}

.gui-radio-option {
  display: flex;
  align-items: center;
  gap: var(--spacing-sm);
  cursor: pointer;
  font-size: var(--font-size-sm);
  color: var(--text-primary);
}

.gui-radio-option input[type="radio"] {
  appearance: none;
  width: 16px;
  height: 16px;
  border: 2px solid var(--border-primary);
  border-radius: 50%;
  background-color: var(--bg-tertiary);
  cursor: pointer;
  transition: border-color 0.15s ease;
}

.gui-radio-option input[type="radio"]:checked {
  border-color: var(--accent);
  background: radial-gradient(circle, var(--accent) 40%, transparent 45%);
}

.gui-radio-option input[type="radio"]:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

/* Checkbox */
.gui-checkbox-wrapper {
  display: flex;
  align-items: center;
  gap: var(--spacing-sm);
  cursor: pointer;
  font-size: var(--font-size-sm);
  color: var(--text-primary);
}

.gui-checkbox {
  appearance: none;
  width: 16px;
  height: 16px;
  border: 2px solid var(--border-primary);
  border-radius: 4px;
  background-color: var(--bg-tertiary);
  cursor: pointer;
  transition: border-color 0.15s ease, background-color 0.15s ease;
}

.gui-checkbox:checked {
  border-color: var(--accent);
  background-color: var(--accent);
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='10' height='10' fill='white' viewBox='0 0 16 16'%3E%3Cpath d='M13.854 3.646a.5.5 0 0 1 0 .708l-7 7a.5.5 0 0 1-.708 0l-3.5-3.5a.5.5 0 1 1 .708-.708L6.5 10.293l6.646-6.647a.5.5 0 0 1 .708 0z'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: center;
}

.gui-checkbox:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

/* Slider */
.gui-slider-wrapper {
  display: flex;
  align-items: center;
  gap: var(--spacing-md);
}

.gui-slider {
  flex: 1;
  -webkit-appearance: none;
  appearance: none;
  height: 6px;
  background: var(--bg-tertiary);
  border-radius: 3px;
  outline: none;
  border: 1px solid var(--border-primary);
}

.gui-slider::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 16px;
  height: 16px;
  background: var(--accent);
  border-radius: 50%;
  cursor: pointer;
  transition: transform 0.15s ease;
}

.gui-slider::-webkit-slider-thumb:hover {
  transform: scale(1.1);
}

.gui-slider::-moz-range-thumb {
  width: 16px;
  height: 16px;
  background: var(--accent);
  border: none;
  border-radius: 50%;
  cursor: pointer;
}

.gui-slider:disabled {
  opacity: 0.5;
}

.gui-slider-value {
  min-width: 40px;
  text-align: right;
  font-size: var(--font-size-sm);
  color: var(--text-secondary);
}

/* =============================================================================
   GUI Buttons
   ============================================================================= */

.gui-btn {
  padding: var(--spacing-sm) var(--spacing-lg);
  font-family: var(--font-sans);
  font-size: var(--font-size-sm);
  font-weight: 500;
  border-radius: var(--border-radius-sm);
  cursor: pointer;
  transition: all 0.15s ease;
  border: 1px solid transparent;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--spacing-xs);
}

.gui-btn-primary {
  background-color: var(--accent);
  color: white;
}

.gui-btn-primary:hover:not(:disabled) {
  background-color: var(--accent-hover);
}

.gui-btn-secondary {
  background-color: transparent;
  border-color: var(--border-primary);
  color: var(--text-secondary);
}

.gui-btn-secondary:hover:not(:disabled) {
  background-color: var(--bg-hover);
  color: var(--text-primary);
}

.gui-btn-danger {
  background-color: var(--error);
  color: white;
}

.gui-btn-danger:hover:not(:disabled) {
  background-color: #dc2626;
}

.gui-btn-success {
  background-color: var(--success);
  color: #0d0d0f;
}

.gui-btn-success:hover:not(:disabled) {
  background-color: #22c55e;
}

.gui-btn-ghost {
  background-color: transparent;
  color: var(--text-secondary);
}

.gui-btn-ghost:hover:not(:disabled) {
  background-color: var(--bg-hover);
  color: var(--text-primary);
}

.gui-btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

/* =============================================================================
   GUI Display Elements
   ============================================================================= */

.gui-text {
  color: var(--text-primary);
  font-size: var(--font-size-sm);
}

.gui-heading {
  color: var(--text-primary);
  font-weight: 600;
  margin: 0;
}

h1.gui-heading { font-size: 24px; }
h2.gui-heading { font-size: 20px; }
h3.gui-heading { font-size: 16px; }
h4.gui-heading { font-size: 14px; }
h5.gui-heading { font-size: 13px; }
h6.gui-heading { font-size: 12px; }

.gui-paragraph {
  color: var(--text-secondary);
  font-size: var(--font-size-sm);
  line-height: 1.5;
}

.gui-divider {
  border: none;
  border-top: 1px solid var(--border-primary);
  margin: var(--spacing-md) 0;
}

.gui-image {
  max-width: 100%;
  height: auto;
  border-radius: var(--border-radius-sm);
}

.gui-icon {
  font-size: 24px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.gui-spacer {
  height: var(--spacing-md);
}

.gui-progress {
  width: 100%;
  height: 8px;
  background-color: var(--bg-tertiary);
  border-radius: 4px;
  overflow: hidden;
  border: 1px solid var(--border-primary);
}

.gui-progress-fill {
  height: 100%;
  background: linear-gradient(90deg, var(--accent), var(--accent-hover));
  transition: width 0.3s ease;
}

.gui-html {
  color: var(--text-primary);
  font-size: var(--font-size-sm);
}

/* =============================================================================
   GUI Layout Containers
   ============================================================================= */

.gui-layout-vertical {
  display: flex;
  flex-direction: column;
}

.gui-layout-horizontal {
  display: flex;
  flex-direction: row;
  align-items: flex-start;
}

.gui-layout-grid {
  display: grid;
}

.gui-layout-form {
  display: flex;
  flex-direction: column;
}

/* Tabs */
.gui-layout-tabs {
  display: flex;
  flex-direction: column;
}

.gui-tab-headers {
  display: flex;
  gap: 2px;
  border-bottom: 1px solid var(--border-primary);
  padding: 0;
  margin-bottom: var(--spacing-md);
}

.gui-tab-header {
  padding: var(--spacing-sm) var(--spacing-md);
  border: none;
  background: transparent;
  color: var(--text-secondary);
  cursor: pointer;
  border-bottom: 2px solid transparent;
  margin-bottom: -1px;
  font-family: var(--font-sans);
  font-size: var(--font-size-sm);
  font-weight: 500;
  transition: color 0.15s ease, border-color 0.15s ease;
}

.gui-tab-header:hover {
  color: var(--text-primary);
}

.gui-tab-header.active {
  color: var(--accent);
  border-bottom-color: var(--accent);
}

.gui-tab-panels {
  flex: 1;
}

.gui-tab-panel {
  /* Panels are shown/hidden via display property */
}

/* Responsive - compact floating panels on small screens */
@media (max-width: 768px) {
  /* Make floating stats more compact on mobile */
  .stats-bar {
    width: 100px;
  }

  /* Make map smaller on mobile */
  .map-panel {
    width: 180px;
    max-height: 220px;
  }

  .map-panel-content {
    min-height: 120px;
  }
}

/* Print styles - hide for printing */
@media print {
  #header,
  #input-container,
  #map-container,
  .code-editor-wrapper,
  .ide-modal {
    display: none;
  }

  #terminal {
    height: auto;
    overflow: visible;
  }
}
