@import url('https://fonts.googleapis.com/css2?family=Roboto+Mono:wght@400;700&display=swap');

:root {
  --bg-color: #0f172a;
  --surface-color: #1e293b;
  --primary-color: #38bdf8;
  --secondary-color: #818cf8;
  --text-color: #e2e8f0;
  --text-muted-color: #94a3b8;
  --border-color: #334155;
  --success-color: #4ade80;
  --warning-color: #facc15;
  --danger-color: #f87171;
  --locked-color: #475569;
  --font-family: 'Roboto Mono', monospace;
  
  /* Faction Colors */
  --faction-omni: #94a3b8; /* Slate/Industrial */
  --faction-inno: #38bdf8; /* Cyan/Tech */
  --faction-synd: #f87171; /* Red/Danger */
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: var(--font-family);
  background-color: var(--bg-color);
  color: var(--text-color);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  padding: 1rem;
  overflow-y: auto;
  overflow-x: hidden;
  position: relative;
}

/* --- Tutorial System --- */
.tutorial-overlay {
    position: fixed;
    top: 0; left: 0; width: 100%; height: 100%;
    background: rgba(0, 0, 0, 0.7);
    z-index: 9990;
    pointer-events: all; /* Blocks clicks on non-highlighted items */
}

.tutorial-highlight {
    position: relative;
    z-index: 9995 !important;
    box-shadow: 0 0 0 4px var(--primary-color), 0 0 15px rgba(56, 189, 248, 0.5);
    background-color: var(--surface-color); /* Ensure opacity */
    pointer-events: auto;
    border-radius: 4px;
}

.tutorial-box {
    position: fixed;
    width: 320px;
    background: var(--surface-color);
    border: 1px solid var(--primary-color);
    padding: 1.5rem;
    border-radius: 8px;
    z-index: 9999;
    box-shadow: 0 10px 30px rgba(0,0,0,0.8);
    color: var(--text-color);
    pointer-events: auto;
}

.tutorial-box h4 {
    margin: 0 0 0.5rem 0;
    color: var(--primary-color);
    font-size: 1rem;
    text-transform: uppercase;
    letter-spacing: 1px;
}

.tutorial-box p {
    font-size: 0.9rem;
    line-height: 1.5;
    margin-bottom: 1rem;
}

.tutorial-btn {
    background: var(--primary-color);
    color: var(--bg-color);
    border: none;
    padding: 0.5rem 1rem;
    border-radius: 4px;
    cursor: pointer;
    font-weight: bold;
    float: right;
}

/* --- Glitch & Resistance Effects for Speedrun --- */
body::after {
  content: " ";
  display: block;
  position: absolute;
  top: 0; left: 0; bottom: 0; right: 0;
  background: linear-gradient(rgba(18, 16, 16, 0) 50%, rgba(0, 0, 0, 0.25) 50%), linear-gradient(90deg, rgba(255, 0, 0, 0.06), rgba(0, 255, 0, 0.02), rgba(0, 0, 255, 0.06));
  z-index: 9000;
  background-size: 100% 2px, 3px 100%;
  pointer-events: none;
  opacity: 0;
  transition: opacity 1s;
}
body.glitch-1::after { opacity: 0.1; }
body.glitch-2::after { opacity: 0.2; }
body.glitch-3::after { opacity: 0.4; }

@keyframes glitch-skew {
  0% { transform: skew(0deg); }
  20% { transform: skew(-2deg); }
  40% { transform: skew(2deg); }
  60% { transform: skew(-1deg); }
  80% { transform: skew(1deg); }
  100% { transform: skew(0deg); }
}

@keyframes jitter {
  0% { transform: translate(0,0); }
  25% { transform: translate(-2px, 2px); }
  50% { transform: translate(2px, -2px); }
  75% { transform: translate(-2px, -2px); }
  100% { transform: translate(2px, 2px); }
}

.resistance-active {
  animation: resistanceFlash 0.2s ease-out;
  border-color: var(--danger-color) !important;
  box-shadow: 0 0 15px var(--danger-color) !important;
}

@keyframes resistanceFlash {
  0% { transform: scale(1); background-color: var(--surface-color); }
  50% { transform: scale(1.02); background-color: rgba(248, 113, 113, 0.2); }
  100% { transform: scale(1); background-color: var(--surface-color); }
}

body.glitch-1 .modal-content { border-color: var(--warning-color); }
body.glitch-2 .modal-content { animation: glitch-skew 2s infinite; border-color: var(--danger-color); filter: contrast(1.2); }
body.glitch-3 .modal-content { animation: jitter 0.1s infinite; filter: invert(0.9); }
body.glitch-3 .grid-cell { filter: hue-rotate(90deg); }
body.glitch-2 .game-title { animation: glitch-skew 0.5s infinite; color: var(--danger-color); }

.ui-jitter { animation: jitter 0.2s infinite; }
.ui-denial:hover { transform: translateX(50px); opacity: 0.5; cursor: not-allowed; }

/* --- Global Styles --- */
#home-screen, #lobby-screen { text-align: center; width: 100%; max-width: 800px; }
.game-title { font-size: 4rem; font-weight: 700; color: var(--primary-color); text-shadow: 0 0 15px var(--primary-color); margin-bottom: 2rem; }
.play-now-btn { font-family: var(--font-family); background-color: var(--primary-color); color: var(--bg-color); border: none; padding: 1rem 2.5rem; font-size: 1.5rem; font-weight: 700; border-radius: 8px; cursor: pointer; transition: transform 0.2s ease, box-shadow 0.2s ease; margin-bottom: 1rem; text-decoration: none; display: inline-block; }
.play-now-btn:hover { transform: scale(1.05); box-shadow: 0 0 20px var(--primary-color); }
.account-actions a, .user-greeting a { color: var(--secondary-color); text-decoration: none; cursor: pointer; }
.account-actions a:hover, .user-greeting a:hover { text-decoration: underline; }
.user-greeting p { margin: 0 0 0.5rem 0; font-size: 1.2rem; }
.user-greeting p span { color: var(--primary-color); font-weight: bold; }

.lobby-subtitle { font-size: 1.2rem; color: var(--text-muted-color); margin-top: -1.5rem; margin-bottom: 2rem; }
.game-mode-selection { display: grid; grid-template-columns: 1fr 1fr; gap: 2rem; text-align: left; }
.game-mode-card { background-color: var(--surface-color); border: 1px solid var(--border-color); border-radius: 8px; padding: 2rem; text-decoration: none; color: var(--text-color); transition: border-color 0.2s, transform 0.2s; }
.game-mode-card:hover { border-color: var(--primary-color); transform: translateY(-5px); }
.game-mode-card h2 { margin: 0 0 0.5rem 0; color: var(--primary-color); }
.game-mode-card p { color: var(--text-muted-color); font-size: 0.9rem; line-height: 1.5; }

/* --- Game Container & Status --- */
#game-container { width: 100vw; height: 100vh; display: flex; flex-direction: column; padding: 0.5rem; gap: 0.5rem; }

.status-bar { width: 100%; background-color: var(--surface-color); border: 1px solid var(--border-color); border-radius: 8px; padding: 0.5rem; display: flex; justify-content: space-around; align-items: center; gap: 0.5rem; flex-wrap: wrap; transition: text-shadow 0.2s; min-height: 50px; }
.stat-item { text-align: center; }
.stat-label { color: var(--text-muted-color); font-size: 0.75rem; margin-bottom: 0.1rem; }
.stat-value { font-size: 1.2rem; font-weight: 700; color: var(--text-color); }
.stat-value.mps { color: var(--success-color); }
.stat-value.power.ok { color: var(--success-color); }
.stat-value.power.warning { color: var(--warning-color); }
.stat-value.power.danger { color: var(--danger-color); }
.brownout-warning { font-size: 0.7rem; color: var(--danger-color); animation: blink 1.5s infinite; }
@keyframes blink { 50% { opacity: 0.5; } }

/* Controls */
.global-tabs, .controls-bar { display: flex; justify-content: center; gap: 1rem; }
.control-btn { font-family: var(--font-family); background-color: var(--surface-color); color: var(--text-color); border: 1px solid var(--border-color); padding: 0.5rem 1rem; font-size: 0.9rem; border-radius: 6px; cursor: pointer; transition: background-color 0.2s, border-color 0.2s, opacity 0.2s; }
.control-btn:disabled { opacity: 0.5; cursor: not-allowed; border-color: var(--locked-color); }
.control-btn:not(:disabled):hover { border-color: var(--primary-color); }
.control-btn.active { background-color: var(--primary-color); color: var(--bg-color); font-weight: bold; }

/* --- Grid System --- */
#grid-viewport { position: relative; width: 100%; flex-grow: 1; overflow: hidden; border: 1px solid var(--border-color); border-radius: 8px; background-color: var(--bg-color); }
#grid-container { position: absolute; display: grid; gap: 8px; transition: transform 0.3s ease-out; }
.grid-cell { width: 100px; height: 100px; background-color: var(--surface-color); border: 1px solid var(--border-color); border-radius: 8px; transition: all 0.2s ease; display: flex; flex-direction: column; justify-content: center; align-items: center; cursor: pointer; font-size: 0.7rem; color: var(--text-muted-color); padding: 4px; text-align: center; position: relative; }
.grid-cell.empty { background-color: transparent; border-color: transparent; cursor: default; }
.grid-cell.available { border-style: dashed; }
.grid-cell.available:hover { background-color: #28364b; border-color: var(--secondary-color); }
.grid-cell.server:hover { transform: scale(1.05); border-color: var(--secondary-color); }
.server-icon { font-size: 2rem; margin-bottom: 0.25rem; }
#grid-svg-layer { position: absolute; top: 0; left: 0; width: 100%; height: 100%; pointer-events: none; overflow: visible; }
.connection-line { stroke: var(--secondary-color); stroke-width: 3px; opacity: 0.7; }

/* --- On-Grid Progress Bars --- */
.server-job-bar-container { position: absolute; bottom: 8px; left: 8px; right: 8px; height: 6px; background: #333; border-radius: 2px; overflow: hidden; }
.server-job-bar { height: 100%; width: 0%; transition: width 0.5s linear; }
.server-job-bar.processing { background-color: var(--warning-color); } /* Yellow for Processing */
.server-job-bar.training { background-color: var(--faction-inno); } /* Blue for Training */
.job-icon-overlay { position: absolute; top: 4px; right: 4px; font-size: 1rem; animation: pulse 1s infinite; }
@keyframes pulse { 0% { opacity: 0.7; } 50% { opacity: 1; } 100% { opacity: 0.7; } }


/* --- Operations Hub (Dashboard) --- */
.active-contracts-panel { width: 100%; background-color: var(--surface-color); border: 1px solid var(--border-color); border-radius: 8px; padding: 0.5rem; display: flex; gap: 0.5rem; flex-wrap: wrap; justify-content: center; }
.active-contracts-panel h4 { width: 100%; margin: 0 0 0.25rem 0; text-align: left; color: var(--text-muted-color); font-size: 0.8rem; border-bottom: 1px solid var(--border-color); padding-bottom: 0.25rem; }

.dashboard-section { display: flex; flex-direction: column; gap: 0.5rem; }
.warehouse-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(40px, 1fr)); gap: 0.5rem; max-height: 100px; overflow-y: auto; padding: 0.25rem; }

/* Data Cubes */
.data-cube { width: 40px; height: 40px; border-radius: 4px; border: 1px solid; display: flex; justify-content: center; align-items: center; font-size: 0.7rem; font-weight: bold; cursor: help; position: relative; transition: transform 0.1s; }
.data-cube:hover { transform: scale(1.1); z-index: 10; }
.data-cube.raw { background: repeating-linear-gradient(45deg, transparent, transparent 2px, rgba(0,0,0,0.2) 2px, rgba(0,0,0,0.2) 4px); }
.data-cube.clean { box-shadow: 0 0 5px currentColor; }

.faction-OmniCorp { color: var(--faction-omni); border-color: var(--faction-omni); background-color: rgba(148, 163, 184, 0.1); }
.faction-Innovatech { color: var(--faction-inno); border-color: var(--faction-inno); background-color: rgba(56, 189, 248, 0.1); }
.faction-Syndicate { color: var(--faction-synd); border-color: var(--faction-synd); background-color: rgba(248, 113, 113, 0.1); animation: glitch-skew 3s infinite; }

/* Model Cards */
.model-list { display: flex; flex-direction: column; gap: 0.5rem; max-height: 120px; overflow-y: auto; }
.model-card { background: var(--bg-color); border: 1px solid var(--border-color); border-radius: 4px; padding: 0.5rem; display: flex; justify-content: space-between; align-items: center; font-size: 0.8rem; }
.model-info { display: flex; flex-direction: column; }
.model-income { color: var(--success-color); font-weight: bold; }
.saturation-bar-container { width: 60px; height: 4px; background: #333; margin-top: 4px; border-radius: 2px; }
.saturation-bar { height: 100%; background: var(--primary-color); transition: width 0.5s; }


/* --- 3-Column Marketplace Modal --- */
.market-terminal { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 1rem; height: 500px; }
.market-column { background: var(--bg-color); border: 1px solid var(--border-color); border-radius: 6px; padding: 1rem; display: flex; flex-direction: column; gap: 1rem; overflow-y: auto; }
.market-column h3 { text-align: center; margin: 0 0 1rem 0; border-bottom: 2px solid; padding-bottom: 0.5rem; font-size: 1rem; }
.market-item { background: var(--surface-color); border: 1px solid var(--border-color); padding: 0.75rem; border-radius: 4px; display: flex; flex-direction: column; gap: 0.5rem; transition: transform 0.1s; }
.market-item:hover { transform: translateY(-2px); border-color: currentColor; }
.market-item h4 { margin: 0; font-size: 0.9rem; }
.market-item p { margin: 0; font-size: 0.75rem; color: var(--text-muted-color); }
.market-stats { display: flex; justify-content: space-between; font-size: 0.75rem; font-weight: bold; }

/* Market Column Themes */
.col-omni h3 { color: var(--faction-omni); border-color: var(--faction-omni); }
.col-omni .market-item { border-left: 3px solid var(--faction-omni); }

.col-inno h3 { color: var(--faction-inno); border-color: var(--faction-inno); }
.col-inno .market-item { border-left: 3px solid var(--faction-inno); }

.col-synd h3 { color: var(--faction-synd); border-color: var(--faction-synd); }
.col-synd .market-item { border-left: 3px solid var(--faction-synd); }


/* --- Tech Tree Visuals --- */
.tech-tree-container { position: relative; width: 100%; height: 500px; background: #0f172a; border-radius: 8px; overflow: hidden; border: 1px solid var(--border-color); box-shadow: inset 0 0 20px rgba(0,0,0,0.5); }
.tech-tree-svg { position: absolute; top: 0; left: 0; width: 100%; height: 100%; pointer-events: none; z-index: 1; }
.connector-line { stroke: var(--border-color); stroke-width: 2px; transition: stroke 0.3s; }
.connector-line.unlocked { stroke: var(--primary-color); }

.tech-node { position: absolute; transform: translate(-50%, -50%); width: 120px; padding: 0.5rem; background: var(--surface-color); border: 1px solid var(--border-color); border-radius: 4px; text-align: center; font-size: 0.8rem; cursor: pointer; transition: all 0.2s; z-index: 2; }
.tech-node.active { border-color: var(--success-color); background: rgba(74, 222, 128, 0.1); color: var(--success-color); box-shadow: 0 0 10px rgba(74, 222, 128, 0.2); }
.tech-node.unlocked { border-color: var(--primary-color); color: var(--primary-color); }
.tech-node.locked { opacity: 0.5; filter: grayscale(1); cursor: not-allowed; }
.tech-node.hw-locked { border-color: var(--warning-color); color: var(--warning-color); opacity: 0.7; }

.tech-node:hover:not(.locked) { transform: translate(-50%, -50%) scale(1.1); z-index: 10; box-shadow: 0 0 15px rgba(0,0,0,0.5); }
.node-level { font-size: 0.7rem; margin-top: 2px; color: var(--text-muted-color); border-top: 1px solid rgba(255,255,255,0.1); padding-top: 2px; }

/* --- Rich Tooltip (Glassmorphism) --- */
.tooltip-rich {
    position: absolute;
    width: 280px;
    background: rgba(30, 41, 59, 0.95);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    backdrop-filter: blur(8px);
    box-shadow: 0 10px 25px rgba(0, 0, 0, 0.5);
    padding: 0;
    z-index: 9999;
    pointer-events: none;
    display: none;
    font-size: 0.85rem;
    overflow: hidden;
}
.tooltip-rich.visible { display: block; }
.tooltip-header { padding: 0.75rem; background: rgba(255, 255, 255, 0.05); border-bottom: 1px solid var(--border-color); display: flex; justify-content: space-between; align-items: center; }
.tooltip-title { font-weight: bold; color: var(--text-color); }
.tooltip-status { font-size: 0.7rem; padding: 2px 6px; border-radius: 4px; text-transform: uppercase; font-weight: bold; }
.status-active { background: rgba(74, 222, 128, 0.2); color: var(--success-color); border: 1px solid var(--success-color); }
.status-available { background: rgba(56, 189, 248, 0.2); color: var(--primary-color); border: 1px solid var(--primary-color); }
.status-locked { background: rgba(148, 163, 184, 0.2); color: var(--text-muted-color); border: 1px solid var(--text-muted-color); }

.tooltip-body { padding: 0.75rem; display: flex; flex-direction: column; gap: 0.75rem; }
.req-section h6, .cost-section h6 { margin: 0 0 0.25rem 0; font-size: 0.7rem; text-transform: uppercase; color: var(--text-muted-color); letter-spacing: 0.05em; }
.req-item { display: flex; justify-content: space-between; font-size: 0.8rem; padding: 2px 0; }
.req-item.met { color: var(--success-color); }
.req-item.missing { color: var(--danger-color); }
.cost-row { display: flex; justify-content: space-between; font-weight: bold; color: var(--warning-color); }

/* --- Modal Styles (General) --- */
.modal-overlay { position: fixed; top: 0; left: 0; width: 100%; height: 100%; background-color: rgba(0, 0, 0, 0.7); display: flex; justify-content: center; align-items: center; z-index: 1000; opacity: 0; visibility: hidden; transition: opacity 0.3s ease, visibility 0.3s ease; }
.modal-overlay.visible { opacity: 1; visibility: visible; }
.modal-content { background-color: var(--surface-color); border: 1px solid var(--border-color); border-radius: 8px; width: 90%; max-width: 900px; max-height: 85vh; transform: scale(0.95); transition: transform 0.3s ease; display: flex; flex-direction: column; }
.modal-overlay.visible .modal-content { transform: scale(1); }
.modal-header { padding: 1.5rem 1.5rem 0 1.5rem; }
.modal-body { padding: 1.5rem; overflow-y: auto; }
.modal-title { margin: 0 0 1.5rem 0; color: var(--primary-color); font-size: 1.25rem; font-weight: 700; border-bottom: 1px solid var(--border-color); padding-bottom: 1rem; display: flex; justify-content: space-between; align-items: center; }
.close-btn { background: none; border: none; color: var(--text-muted-color); font-size: 1.5rem; cursor: pointer; transition: color 0.2s; }
.close-btn:hover { color: var(--text-color); }
.modal-btn { font-family: var(--font-family); border: none; padding: 0.5rem 1rem; font-size: 0.9rem; font-weight: 700; border-radius: 6px; cursor: pointer; transition: background-color 0.2s ease, opacity 0.2s ease, transform 0.1s; }
.modal-btn:active:not(:disabled) { transform: translateY(2px); }
.modal-btn.primary { background-color: var(--success-color); color: var(--bg-color); }
.modal-btn:disabled { background-color: var(--locked-color); cursor: not-allowed; opacity: 0.6; }
.modal-btn.secondary { background-color: var(--border-color); color: var(--text-color); }
.modal-btn.full-width { width: 100%; margin-top: 0.5rem; }

/* --- Improved Develop Plot Options --- */
.develop-plot-options { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 1rem; }
.server-option { 
  background: var(--bg-color); border: 1px dashed var(--border-color); border-radius: 8px; padding: 1.5rem; 
  cursor: pointer; transition: all 0.2s; position: relative; overflow: hidden;
}
.server-option:hover { border-style: solid; border-color: var(--primary-color); transform: translateY(-2px); box-shadow: 0 4px 12px rgba(0,0,0,0.3); }
.server-option.disabled { opacity: 0.5; cursor: not-allowed; border-color: var(--locked-color); }
.server-option h3 { margin: 0 0 0.5rem 0; font-size: 1rem; color: var(--text-color); display: flex; align-items: center; gap: 0.5rem; }
.server-option p { font-size: 0.8rem; color: var(--text-muted-color); line-height: 1.4; margin-bottom: 1rem; min-height: 2.8em; }
.server-option .cost { font-weight: bold; color: var(--warning-color); font-size: 0.9rem; border-top: 1px solid var(--border-color); padding-top: 0.5rem; }
.server-option::before { content: ""; position: absolute; top: 0; left: 0; width: 4px; height: 100%; background: var(--border-color); transition: background 0.2s; }
.server-option:hover::before { background: var(--primary-color); }

/* Infrastructure List */
.infra-list { display: flex; flex-direction: column; gap: 1rem; }
.infra-item { background-color: var(--bg-color); padding: 1rem; border-radius: 6px; border: 1px solid var(--border-color); display: grid; grid-template-columns: 2fr 1fr; align-items: center; gap: 1rem; }
.infra-details h4 { margin: 0 0 0.25rem 0; color: var(--text-color); }
.infra-details p { margin: 0; font-size: 0.8rem; color: var(--text-muted-color); }
.infra-actions { text-align: right; }
.infra-cost { font-size: 0.9rem; margin-bottom: 0.5rem; color: var(--text-muted-color); }

/* Notifications */
#notifications-container { position: fixed; bottom: 1rem; right: 1rem; z-index: 2000; display: flex; flex-direction: column; gap: 0.5rem; pointer-events: none; }
.notification { background-color: var(--surface-color); border: 1px solid var(--border-color); color: var(--text-color); padding: 0.75rem 1rem; border-radius: 6px; font-size: 0.9rem; animation: slideIn 0.3s ease-out, fadeOut 0.5s 4.5s forwards; box-shadow: 0 4px 6px rgba(0,0,0,0.3); }
@keyframes slideIn { from { transform: translateX(100%); opacity: 0; } to { transform: translateX(0); opacity: 1; } }
@keyframes fadeOut { to { opacity: 0; display: none; } }

/* Game Over */
.game-over-overlay { position: fixed; top: 0; left: 0; width: 100%; height: 100%; background-color: rgba(0,0,0,0.9); z-index: 5000; display: flex; justify-content: center; align-items: center; text-align: center; color: var(--danger-color); }
.game-over-content { max-width: 600px; animation: fadeIn 3s; }
.game-over-content h1 { font-size: 3rem; text-shadow: 0 0 10px var(--danger-color); }
.game-over-content p { font-size: 1.2rem; }
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }

/* Responsive */
@media (max-width: 768px) {
  .status-bar { flex-direction: column; align-items: stretch; }
  .market-terminal { grid-template-columns: 1fr; height: auto; }
}