/* Reset and Base Styles */
* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

:root {
  --bg-main: #070a13;
  --bg-panel: rgba(15, 23, 42, 0.65);
  --bg-panel-solid: #0f172a;
  --bg-control: rgba(30, 41, 59, 0.7);
  --bg-control-active: rgba(51, 65, 85, 0.9);
  
  --border-light: rgba(255, 255, 255, 0.08);
  --border-focus: rgba(56, 189, 248, 0.4);
  
  --text-main: #f8fafc;
  --text-muted: #94a3b8;
  --text-dark: #0f172a;
  
  --color-primary: #3b82f6; /* Royal Blue */
  --color-primary-glow: rgba(59, 130, 246, 0.35);
  --color-accent: #06b6d4; /* Electric Cyan */
  --color-accent-glow: rgba(6, 182, 212, 0.35);
  --color-success: #10b981; /* Emerald Green */
  --color-success-glow: rgba(16, 185, 129, 0.35);
  --color-danger: #ef4444; /* Vivid Red */
  --color-warning: #f59e0b; /* Amber */
  --color-purple: #8b5cf6; /* Violet */
  --color-purple-glow: rgba(139, 92, 246, 0.35);

  --font-ui: 'Outfit', sans-serif;
  --font-mono: 'JetBrains Mono', 'Courier New', monospace;
  
  --glass-blur: blur(12px);
  --transition-speed: 0.2s;
  --border-radius: 12px;
}

body {
  font-family: var(--font-ui);
  background-color: var(--bg-main);
  color: var(--text-main);
  height: 100vh;
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

/* Scrollbar Customization */
::-webkit-scrollbar {
  width: 6px;
  height: 6px;
}
::-webkit-scrollbar-track {
  background: rgba(0, 0, 0, 0.2);
}
::-webkit-scrollbar-thumb {
  background: rgba(255, 255, 255, 0.15);
  border-radius: 3px;
}
::-webkit-scrollbar-thumb:hover {
  background: rgba(255, 255, 255, 0.3);
}

/* Header Bar */
.app-header {
  height: 56px;
  background-color: rgba(7, 10, 19, 0.85);
  backdrop-filter: var(--glass-blur);
  -webkit-backdrop-filter: var(--glass-blur);
  border-bottom: 1px solid var(--border-light);
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0 20px;
  z-index: 100;
  flex-shrink: 0;
}

.header-logo {
  display: flex;
  align-items: center;
  gap: 12px;
}

.logo-pulse {
  width: 10px;
  height: 10px;
  background-color: var(--color-accent);
  border-radius: 50%;
  box-shadow: 0 0 10px var(--color-accent);
  animation: pulse-ring 2s infinite;
}

@keyframes pulse-ring {
  0% { transform: scale(0.9); opacity: 1; }
  50% { transform: scale(1.2); opacity: 0.5; box-shadow: 0 0 15px var(--color-accent); }
  100% { transform: scale(0.9); opacity: 1; }
}

.header-logo h1 {
  font-size: 1.2rem;
  font-weight: 700;
  letter-spacing: 1px;
  background: linear-gradient(135deg, #ffffff 30%, var(--color-accent) 100%);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
}

.logo-subtitle {
  font-size: 0.75rem;
  color: var(--text-muted);
  font-family: var(--font-mono);
  border-left: 1px solid var(--border-light);
  padding-left: 12px;
  margin-left: 4px;
}

.header-status {
  display: flex;
  gap: 20px;
}

.status-item {
  font-size: 0.8rem;
  background: rgba(255, 255, 255, 0.03);
  padding: 4px 10px;
  border-radius: 6px;
  border: 1px solid var(--border-light);
}

.status-label {
  color: var(--text-muted);
  margin-right: 4px;
}

.status-value {
  color: var(--color-accent);
  font-weight: 600;
  font-family: var(--font-mono);
}

/* App Container Layout */
.app-container {
  display: flex;
  flex: 1;
  height: calc(100vh - 146px); /* minus header (56px) and footer (90px) */
  min-height: 0; /* Prevent flex content from growing beyond viewport height */
  overflow: hidden;
  position: relative;
}

/* Left Sidebar: Operation Panel */
.operation-panel {
  width: 330px;
  height: 100%;
  max-height: 100%;
  background: var(--bg-panel);
  backdrop-filter: var(--glass-blur);
  -webkit-backdrop-filter: var(--glass-blur);
  border-right: 1px solid var(--border-light);
  overflow-y: auto;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 16px;
  flex-shrink: 0;
}

.panel-section {
  background: rgba(255, 255, 255, 0.02);
  border: 1px solid var(--border-light);
  border-radius: var(--border-radius);
  overflow: hidden;
  flex-shrink: 0; /* Prevent sections from shrinking/collapsing and overlapping */
}

.section-title {
  font-size: 0.9rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  padding: 10px 14px;
  background: rgba(255, 255, 255, 0.04);
  border-bottom: 1px solid var(--border-light);
  color: var(--text-main);
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.section-content {
  padding: 14px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

/* Settings and Form Controls */
.setting-group {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.setting-group label {
  font-size: 0.75rem;
  color: var(--text-muted);
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

select, input[type="number"], .text-input {
  background: var(--bg-control);
  border: 1px solid var(--border-light);
  color: var(--text-main);
  padding: 8px 12px;
  border-radius: 8px;
  font-family: var(--font-ui);
  font-size: 0.85rem;
  width: 100%;
  outline: none;
  transition: border-color var(--transition-speed);
}

select:focus, input[type="number"]:focus, .text-input:focus {
  border-color: var(--color-accent);
  box-shadow: 0 0 5px rgba(6, 182, 212, 0.2);
}

.input-row {
  display: flex;
  gap: 10px;
}

.input-field {
  display: flex;
  align-items: center;
  flex: 1;
  background: var(--bg-control);
  border: 1px solid var(--border-light);
  border-radius: 8px;
  overflow: hidden;
}

.input-addon {
  padding: 0 10px;
  font-size: 0.75rem;
  font-family: var(--font-mono);
  color: var(--text-muted);
  border-right: 1px solid var(--border-light);
}

.input-field input {
  border: none;
  background: transparent;
  padding: 8px;
  color: var(--text-main);
  width: 100%;
  outline: none;
  font-family: var(--font-mono);
  font-size: 0.85rem;
}

.range-container {
  display: flex;
  align-items: center;
  gap: 10px;
}

input[type="range"] {
  flex: 1;
  accent-color: var(--color-accent);
  height: 4px;
}

.range-val {
  font-family: var(--font-mono);
  font-size: 0.8rem;
  color: var(--color-accent);
  min-width: 45px;
  text-align: right;
}

/* Textarea / Code Editor */
.code-textarea {
  background: #030712;
  border: 1px solid var(--border-light);
  color: var(--color-success);
  font-family: var(--font-mono);
  font-size: 0.8rem;
  padding: 8px;
  border-radius: 8px;
  resize: vertical;
  outline: none;
  width: 100%;
  min-height: 180px;
  box-sizing: border-box;
}

.code-textarea:focus {
  border-color: var(--color-success);
}

.ratio-rule-map {
  border: 1px solid var(--border-light);
  border-radius: 8px;
  padding: 10px;
  background: rgba(15, 23, 42, 0.5);
}

.ratio-rule-note,
.ratio-rule-empty,
.setting-note {
  font-family: var(--font-mono);
  font-size: 0.68rem;
  line-height: 1.45;
  color: var(--text-muted);
}

.ratio-rule-table {
  display: flex;
  flex-direction: column;
  gap: 4px;
  max-height: 220px;
  overflow: auto;
}

.ratio-rule-row {
  display: grid;
  grid-template-columns: 52px minmax(0, 1fr) minmax(0, 1fr) 40px;
  gap: 6px;
  align-items: center;
  font-family: var(--font-mono);
  font-size: 0.68rem;
  line-height: 1.35;
  padding: 5px 6px;
  border-radius: 6px;
  background: rgba(255, 255, 255, 0.035);
}

.ratio-rule-row.is-custom {
  background: rgba(6, 182, 212, 0.09);
  border: 1px solid rgba(6, 182, 212, 0.25);
}

.ratio-rule-degree {
  color: var(--color-accent);
  font-weight: 600;
}

.ratio-rule-field {
  display: grid;
  grid-template-columns: 14px minmax(0, 1fr);
  gap: 4px;
  align-items: center;
  min-width: 0;
  font-family: var(--font-mono);
  font-size: 0.68rem;
  text-transform: none;
  letter-spacing: 0;
}

.ratio-rule-field span {
  color: var(--text-muted);
}

.ratio-rule-field input {
  width: 100%;
  min-width: 0;
  box-sizing: border-box;
  border: 1px solid var(--border-light);
  border-radius: 5px;
  background: rgba(3, 7, 18, 0.85);
  color: var(--text-main);
  padding: 4px 5px;
  font-family: var(--font-mono);
  font-size: 0.68rem;
  outline: none;
}

.ratio-rule-field input:focus {
  border-color: var(--color-accent);
}

.ratio-rule-field input::placeholder {
  color: rgba(148, 163, 184, 0.6);
}

.ratio-rule-field [data-ratio-kind="birth"] {
  color: var(--color-success);
}

.ratio-rule-field [data-ratio-kind="survival"] {
  color: var(--text-main);
}

.ratio-rule-reset {
  border: 1px solid var(--border-light);
  border-radius: 5px;
  background: rgba(15, 23, 42, 0.9);
  color: var(--text-muted);
  font-family: var(--font-mono);
  font-size: 0.62rem;
  padding: 4px;
  cursor: pointer;
}

.ratio-rule-reset:hover {
  border-color: var(--color-accent);
  color: var(--color-accent);
}

/* Checkbox Styling */
.checkbox-group {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.checkbox-label {
  display: flex;
  align-items: center;
  gap: 8px;
  cursor: pointer;
  font-size: 0.8rem;
  user-select: none;
}

.checkbox-label input[type="checkbox"] {
  accent-color: var(--color-accent);
  width: 15px;
  height: 15px;
  cursor: pointer;
}

.screensaver-control {
  padding-top: 2px;
}

.preset-button-row {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

/* Buttons */
.btn {
  background: var(--bg-control);
  color: var(--text-main);
  border: 1px solid var(--border-light);
  padding: 8px 16px;
  border-radius: 8px;
  font-family: var(--font-ui);
  font-weight: 500;
  font-size: 0.85rem;
  cursor: pointer;
  transition: all var(--transition-speed);
  display: inline-flex;
  justify-content: center;
  align-items: center;
}

.btn:hover {
  background: var(--bg-control-active);
  border-color: var(--text-muted);
}

.btn-small {
  padding: 5px 9px;
  font-size: 0.72rem;
}

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

.btn-primary:hover {
  background: #2563eb;
  box-shadow: 0 0 10px var(--color-primary-glow);
}

.btn-accent {
  background: var(--color-accent);
  border-color: transparent;
  color: var(--text-dark);
  font-weight: 600;
}

.btn-accent:hover {
  background: #0891b2;
  box-shadow: 0 0 10px var(--color-accent-glow);
  color: white;
}

.btn-danger {
  background: var(--color-danger);
  border-color: transparent;
}

.btn-danger:hover {
  background: #dc2626;
  box-shadow: 0 0 10px rgba(239, 68, 68, 0.35);
}

.btn-full {
  width: 100%;
  margin-top: 5px;
}

.btn-group-row {
  display: flex;
  gap: 8px;
  width: 100%;
}

.btn-half {
  flex: 1;
}

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

.control-row {
  display: flex;
  gap: 8px;
}

.control-row .btn {
  flex: 1;
}

/* File Drop Zone */
.file-drop-zone {
  border: 2px dashed var(--border-light);
  padding: 20px;
  border-radius: var(--border-radius);
  text-align: center;
  font-size: 0.75rem;
  color: var(--text-muted);
  cursor: pointer;
  transition: all var(--transition-speed);
  background: rgba(255, 255, 255, 0.01);
}

.file-drop-zone:hover, .file-drop-zone.dragover {
  border-color: var(--color-accent);
  background: rgba(6, 182, 212, 0.05);
  color: var(--text-main);
}

/* Center Panel: Main Canvas View */
.main-view-container {
  flex: 1;
  background: #050811;
  display: flex;
  flex-direction: column;
  position: relative;
}

.canvas-toolbar {
  height: 48px;
  background: rgba(15, 23, 42, 0.6);
  backdrop-filter: var(--glass-blur);
  -webkit-backdrop-filter: var(--glass-blur);
  border-bottom: 1px solid var(--border-light);
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0 16px;
  z-index: 10;
}

.toolbar-group {
  display: flex;
  align-items: center;
  gap: 8px;
}

.toolbar-label {
  font-size: 0.75rem;
  color: var(--text-muted);
  text-transform: uppercase;
  margin-right: 4px;
}

.btn-tool {
  background: var(--bg-control);
  color: var(--text-muted);
  border: 1px solid var(--border-light);
  padding: 6px 12px;
  border-radius: 6px;
  font-family: var(--font-ui);
  font-size: 0.8rem;
  font-weight: 500;
  cursor: pointer;
  transition: all var(--transition-speed);
}

.btn-tool:hover {
  background: rgba(255, 255, 255, 0.05);
  color: var(--text-main);
}

.btn-tool.active {
  background: var(--color-accent);
  color: var(--text-dark);
  border-color: transparent;
  font-weight: 600;
  box-shadow: 0 0 8px var(--color-accent-glow);
}

.btn-sm {
  padding: 4px 10px;
  font-size: 0.75rem;
}

.canvas-wrapper {
  flex: 1;
  position: relative;
  overflow: hidden;
  width: 100%;
}

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

/* Floating Inspector HUD */
.inspector-hud {
  position: absolute;
  top: 16px;
  right: 16px;
  width: 280px;
  background: rgba(15, 23, 42, 0.85);
  backdrop-filter: var(--glass-blur);
  -webkit-backdrop-filter: var(--glass-blur);
  border: 1px solid var(--border-light);
  border-radius: var(--border-radius);
  box-shadow: 0 10px 25px rgba(0, 0, 0, 0.5);
  z-index: 20;
  overflow: hidden;
}

.hud-header {
  padding: 10px 14px;
  background: rgba(255, 255, 255, 0.05);
  border-bottom: 1px solid var(--border-light);
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.hud-header h3 {
  font-size: 0.8rem;
  font-weight: 600;
  letter-spacing: 0.5px;
  text-transform: uppercase;
  color: var(--color-accent);
}

.hud-close {
  background: transparent;
  border: none;
  color: var(--text-muted);
  font-size: 1.2rem;
  cursor: pointer;
  line-height: 1;
}

.hud-close:hover {
  color: var(--text-main);
}

.hud-body {
  padding: 14px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.hud-row {
  display: flex;
  justify-content: space-between;
  font-size: 0.75rem;
  font-family: var(--font-mono);
  border-bottom: 1px dashed rgba(255, 255, 255, 0.03);
  padding-bottom: 4px;
}

.hud-lbl {
  color: var(--text-muted);
}

.hud-val {
  color: var(--text-main);
  font-weight: 600;
  max-width: 170px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.hud-explanation {
  font-size: 0.7rem;
  color: var(--text-muted);
  font-style: italic;
  margin-top: 4px;
}

/* Right Sidebar: CLI Console Panel */
.console-panel {
  width: 350px;
  background: var(--bg-panel);
  backdrop-filter: var(--glass-blur);
  -webkit-backdrop-filter: var(--glass-blur);
  border-left: 1px solid var(--border-light);
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
}

.console-header {
  padding: 12px 16px;
  background: rgba(0, 0, 0, 0.2);
  border-bottom: 1px solid var(--border-light);
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.console-header h2 {
  font-size: 0.85rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--text-main);
}

.btn-clear-log {
  background: transparent;
  border: 1px solid var(--border-light);
  color: var(--text-muted);
  font-size: 0.7rem;
  padding: 2px 8px;
  border-radius: 4px;
  cursor: pointer;
  font-family: var(--font-ui);
}

.btn-clear-log:hover {
  background: rgba(255, 255, 255, 0.05);
  color: var(--text-main);
}

.console-log {
  flex: 1;
  overflow-y: auto;
  padding: 12px;
  font-family: var(--font-mono);
  font-size: 0.75rem;
  line-height: 1.4;
  display: flex;
  flex-direction: column;
  gap: 6px;
  background: rgba(0, 0, 0, 0.3);
}

.log-line {
  word-break: break-all;
  white-space: pre-wrap;
}

.system-line {
  color: var(--text-muted);
}

.command-line {
  color: var(--color-accent);
  font-weight: 600;
}

.output-line {
  color: #c0caf5; /* light purple/blue console text */
}

.error-line {
  color: var(--color-danger);
  font-weight: 600;
}

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

.highlight-line {
  color: var(--color-warning);
}

.console-input-wrapper {
  display: flex;
  align-items: center;
  background: #020617;
  border-top: 1px solid var(--border-light);
  padding: 10px 12px;
}

.console-prompt {
  font-family: var(--font-mono);
  font-weight: 700;
  color: var(--color-accent);
  margin-right: 8px;
  font-size: 0.85rem;
}

#console-input {
  flex: 1;
  background: transparent;
  border: none;
  outline: none;
  color: var(--text-main);
  font-family: var(--font-mono);
  font-size: 0.8rem;
  width: 100%;
}

/* Bottom Timeline and Status Bar */
.app-footer {
  height: 90px;
  background: rgba(7, 10, 19, 0.95);
  backdrop-filter: var(--glass-blur);
  -webkit-backdrop-filter: var(--glass-blur);
  border-top: 1px solid var(--border-light);
  display: flex;
  flex-direction: column;
  z-index: 100;
  flex-shrink: 0;
}

.timeline-container {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 8px 20px;
  border-bottom: 1px solid var(--border-light);
  background: rgba(255, 255, 255, 0.01);
}

.timeline-slider-wrapper {
  flex: 1;
  display: flex;
  align-items: center;
}

#slider-timeline {
  width: 100%;
  accent-color: var(--color-primary);
  height: 6px;
}

.status-bar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 6px 20px;
  flex: 1;
}

.status-group {
  display: flex;
  gap: 12px;
  align-items: center;
}

.status-pill {
  font-size: 0.75rem;
  color: var(--text-muted);
  background: rgba(255, 255, 255, 0.03);
  padding: 3px 10px;
  border-radius: 20px;
  border: 1px solid var(--border-light);
  font-family: var(--font-mono);
}

.status-pill strong {
  color: var(--text-main);
}

.status-pill-accent {
  font-size: 0.75rem;
  color: var(--color-accent);
  font-weight: 600;
  font-family: var(--font-mono);
}

/* Animations */
@keyframes glow-pulse {
  0% { box-shadow: 0 0 5px rgba(6, 182, 212, 0.2); }
  50% { box-shadow: 0 0 15px rgba(6, 182, 212, 0.5); }
  100% { box-shadow: 0 0 5px rgba(6, 182, 212, 0.2); }
}

/* Responsive adjustment for small screens */
@media (max-width: 1100px) {
  body {
    height: auto;
    min-height: 100vh;
    min-height: 100dvh;
    overflow: auto;
  }

  .app-header {
    height: auto;
    min-height: 56px;
    align-items: flex-start;
    flex-direction: column;
    gap: 10px;
    padding: 12px 14px;
  }

  .header-logo {
    width: 100%;
    min-width: 0;
    flex-wrap: wrap;
    gap: 8px 10px;
  }

  .header-logo h1 {
    font-size: 1rem;
    line-height: 1.2;
  }

  .logo-subtitle {
    width: 100%;
    border-left: none;
    padding-left: 22px;
    margin-left: 0;
  }

  .header-status {
    width: 100%;
    gap: 8px;
    flex-wrap: wrap;
  }

  .status-item {
    flex: 1 1 130px;
    min-width: 0;
  }

  .app-container {
    flex-direction: column;
    height: auto;
    min-height: 0;
    overflow: visible;
  }
  
  .operation-panel, .console-panel {
    order: 2;
    width: 100%;
    height: auto;
    max-height: none;
    border-right: none;
    border-left: none;
  }
  
  .main-view-container {
    order: 1;
    height: min(62vh, 560px);
    min-height: 420px;
    flex: none;
    border-bottom: 1px solid var(--border-light);
  }

  .canvas-toolbar {
    height: auto;
    min-height: 48px;
    align-items: stretch;
    flex-direction: column;
    gap: 8px;
    padding: 10px;
  }

  .toolbar-group {
    flex-wrap: wrap;
    gap: 6px;
  }

  .toolbar-label {
    width: 100%;
  }

  .btn-tool,
  .canvas-toolbar .btn {
    flex: 1 1 110px;
    min-height: 36px;
    padding: 7px 8px;
    white-space: normal;
    line-height: 1.15;
  }

  .canvas-wrapper {
    min-height: 320px;
  }

  .console-panel {
    order: 3;
    min-height: 280px;
  }

  .console-log {
    min-height: 220px;
  }

  .app-footer {
    height: auto;
    min-height: 90px;
  }

  .timeline-container,
  .status-bar {
    flex-wrap: wrap;
    gap: 8px;
    padding-left: 14px;
    padding-right: 14px;
  }

  .timeline-slider-wrapper {
    min-width: 160px;
  }

  .status-group {
    flex-wrap: wrap;
    gap: 8px;
  }
}

@media (max-width: 640px) {
  .operation-panel {
    padding: 12px;
    gap: 12px;
  }

  .main-view-container {
    height: 58vh;
    min-height: 360px;
  }

  .section-content {
    padding: 12px;
  }

  .control-row,
  .btn-group-row,
  .input-row {
    flex-wrap: wrap;
  }

  .control-row .btn,
  .btn-half,
  .input-field {
    flex: 1 1 130px;
  }

  .range-container {
    gap: 8px;
  }

  .range-val {
    min-width: 50px;
  }

  .inspector-hud {
    left: 10px;
    right: 10px;
    top: 10px;
    width: auto;
    max-height: calc(100% - 20px);
    overflow-y: auto;
  }

  .hud-row {
    gap: 12px;
  }

  .hud-val {
    max-width: 55%;
  }

  .timeline-container {
    align-items: stretch;
  }

  .timeline-container .btn {
    flex: 1 1 90px;
  }

  .timeline-slider-wrapper {
    flex-basis: 100%;
    order: -1;
  }

  .status-pill,
  .status-pill-accent {
    line-height: 1.35;
  }
}

@media (max-width: 420px) {
  .header-logo h1 {
    font-size: 0.92rem;
  }

  .logo-subtitle {
    padding-left: 0;
    font-size: 0.68rem;
  }

  .main-view-container {
    min-height: 470px;
  }

  .btn-tool,
  .canvas-toolbar .btn {
    flex-basis: calc(50% - 4px);
  }

  .status-item,
  .status-pill,
  .status-pill-accent {
    width: 100%;
  }
}
