/* This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at https://mozilla.org/MPL/2.0/.
 *
 * «Марина в огне» v1.6a — terminal UI + cooldowns + 4-line HUD + delta flash.
 * (c) 2026 Tim Zinin.
 */

:root {
  --bg: #0a0a0a;
  --fg: #e8e8e8;
  --muted: #7a7a7a;
  --accent: #c5380e;
  --ok: #5ca05c;
  --warn: #c99a4a;
  --border: #2a2a2a;
  --border-strong: #3a3a3a;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--fg);
  font-family: "JetBrains Mono", "SF Mono", "Menlo", "Consolas", "Courier New", monospace;
  font-size: 14px;
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
  -webkit-text-size-adjust: 100%;
}

#wrapper {
  max-width: 780px;
  margin: 0 auto;
  padding: 0;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

/* ========== Sticky HUD ========== */

#hud {
  position: sticky;
  top: 0;
  z-index: 10;
  padding: 10px 16px 8px;
  background: var(--bg);
  border-bottom: 1px solid var(--border);
  font-size: 13px;
  color: var(--muted);
  display: flex;
  flex-direction: column;
  gap: 2px;
}

#hud-line1 {
  color: var(--fg);
  font-size: 13px;
  letter-spacing: 0.01em;
}

#hud-line1 .prompt { color: var(--ok); }
#hud-line1 .title  { color: var(--fg); }
#hud-line1 .auto-badge { color: var(--ok); }
#hud-line1 .coffee-badge { color: var(--warn); }

#hud-line2, #hud-line3 {
  font-size: 13px;
  line-height: 1.5;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: clip;
}

#hud-line2 .stat-label,
#hud-line3 .stat-label { color: var(--muted); }

#hud-line2 .bar,
#hud-line3 .bar { color: var(--fg); }

#hud-line2 .stat-num,
#hud-line3 .stat-num { color: var(--muted); }

#hud-line2 .stat-energy.mid,
#hud-line2 .stat-energy.mid.stat-num { color: var(--warn); }
#hud-line2 .stat-energy.low,
#hud-line2 .stat-energy.low.stat-num { color: var(--accent); }

#hud-line3 .stat-cash.neg,
#hud-line3 .stat-cash.neg.stat-num { color: var(--accent); }
#hud-line3 .stat-cash.low,
#hud-line3 .stat-cash.low.stat-num { color: var(--warn); }

#hud-line2 .sep,
#hud-line3 .sep { color: var(--border-strong); }

#hud-hint {
  padding: 6px 16px 4px;
  color: var(--muted);
  font-size: 12px;
  font-style: normal;
  background: var(--bg);
  border-bottom: 1px dashed var(--border);
  min-height: 1.2em;
}

#hud-projects {
  padding: 4px 16px 6px;
  color: var(--fg);
  font-size: 12px;
  background: var(--bg);
}

.project-line {
  color: var(--muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: clip;
}

/* Delta flash animations */
.delta-flash {
  display: inline-block;
  margin-left: 6px;
  padding: 0 4px;
  font-weight: bold;
  font-size: 12px;
  transition: opacity 1.2s ease-out, transform 1.2s ease-out;
  opacity: 1;
}
.delta-flash.pos { color: var(--ok); }
.delta-flash.neg { color: var(--accent); }
.delta-flash.fade {
  opacity: 0;
  transform: translateY(-8px);
}

/* ========== Main game area ========== */

#game {
  flex: 1;
  display: flex;
  flex-direction: column;
  padding: 12px 16px 16px;
  min-height: 0;
}

/* ========== Chat log ========== */

#log {
  flex: 1;
  overflow-y: auto;
  padding: 4px 0 12px;
  max-height: 52vh;
  min-height: 160px;
  font-size: 13px;
  line-height: 1.65;
  scrollbar-width: thin;
  scrollbar-color: var(--border-strong) transparent;
}

#log::-webkit-scrollbar { width: 6px; }
#log::-webkit-scrollbar-track { background: transparent; }
#log::-webkit-scrollbar-thumb { background: var(--border-strong); border-radius: 3px; }

.log-line {
  margin: 1px 0;
  white-space: pre-wrap;
  word-break: break-word;
}
.log-spacer { height: 7px; min-height: 7px; }
.log-system { color: var(--muted); }
.log-alert { color: var(--accent); }
.log-ok { color: var(--ok); }
.log-prompt { color: var(--ok); }
.log-divider { color: var(--border-strong); letter-spacing: -0.5px; }

/* ========== Status indicator ========== */

#status-line {
  display: none;
  padding: 8px 12px;
  margin: 6px 0;
  color: var(--muted);
  font-size: 13px;
  background: rgba(255, 255, 255, 0.02);
  border-left: 2px solid var(--accent);
}

#status-line .spinner {
  color: var(--accent);
  display: inline-block;
  width: 1.2em;
}

#status-line .status-text {
  color: var(--fg);
}

/* ========== Actions (grouped) ========== */

#actions {
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding-top: 10px;
  border-top: 1px dashed var(--border);
}

.action-group {
  display: flex;
  flex-direction: column;
  gap: 5px;
}

.action-group-maintenance,
.action-group-advance {
  padding-top: 7px;
  border-top: 1px dashed var(--border);
}

.action-btn {
  display: block;
  width: 100%;
  text-align: left;
  padding: 9px 12px;
  background: transparent;
  color: var(--fg);
  border: 1px solid var(--border);
  font-family: inherit;
  font-size: 13px;
  cursor: pointer;
  transition: background 120ms ease, border-color 120ms ease;
  position: relative;
  overflow: hidden;
}

.action-btn::before {
  content: "[ ] ";
  color: var(--muted);
  position: relative;
  z-index: 2;
}

.action-btn > * {
  position: relative;
  z-index: 2;
}

.action-btn:hover:not([disabled]):not(.action-disabled) {
  background: rgba(197, 56, 14, 0.08);
  border-color: var(--accent);
}

.action-btn:hover:not([disabled]):not(.action-disabled)::before {
  content: "[>] ";
  color: var(--accent);
}

.action-btn[disabled] {
  color: var(--muted);
  cursor: not-allowed;
  opacity: 0.45;
}

.action-btn[disabled]::before {
  content: "[x] ";
  color: var(--border-strong);
}

.action-btn.action-disabled {
  pointer-events: none;
  cursor: wait;
  color: var(--muted);
}

/* Cooldown fill bar (A Dark Room style, filled rectangle shrinks left→right) */
.action-cooldown {
  position: absolute;
  top: 0;
  left: 0;
  height: 100%;
  background: rgba(197, 56, 14, 0.18);
  border-right: 1px solid var(--accent);
  z-index: 1;
  width: 100%;
  pointer-events: none;
}

/* ========== Footer ========== */

#footer {
  padding: 10px 16px 14px;
  border-top: 1px solid var(--border);
  font-size: 11px;
  color: var(--muted);
  background: var(--bg);
  line-height: 1.5;
}

#footer a {
  color: var(--muted);
  text-decoration: none;
  border-bottom: 1px dotted var(--muted);
}

#footer a:hover {
  color: var(--fg);
  border-bottom-color: var(--fg);
}

/* ========== Ending screen ========== */

#ending {
  display: none;
  padding: 20px 16px 32px;
  flex: 1;
}

.ending-line {
  margin: 4px 0;
  white-space: pre-wrap;
  word-break: break-word;
  font-size: 14px;
  line-height: 1.7;
}

.ending-line.ending-divider {
  color: var(--border-strong);
  margin: 12px 0;
}

.ending-line.ending-cta {
  color: var(--ok);
  margin-top: 18px;
}

.ending-link {
  display: inline-block;
  margin-top: 12px;
  padding: 9px 14px;
  color: var(--fg);
  text-decoration: none;
  border: 1px solid var(--accent);
  font-family: inherit;
  font-size: 13px;
}

.ending-link:hover {
  background: rgba(197, 56, 14, 0.12);
}

/* ========== Inline lead form ========== */

.lead-form {
  margin: 14px 0 10px;
  padding: 14px 14px 12px;
  border: 1px solid var(--border);
  background: rgba(255, 255, 255, 0.015);
}

.lead-form-header {
  color: var(--muted);
  font-size: 12px;
  letter-spacing: 0.02em;
  margin-bottom: 10px;
}

.lead-field {
  display: block;
  margin-bottom: 10px;
}

.lead-field span {
  display: block;
  font-size: 12px;
  color: var(--muted);
  margin-bottom: 3px;
}

.lead-field input,
.lead-field textarea {
  display: block;
  width: 100%;
  padding: 8px 10px;
  background: #141414;
  color: var(--fg);
  border: 1px solid var(--border);
  font-family: inherit;
  font-size: 14px;
  resize: vertical;
  border-radius: 0;
  -webkit-appearance: none;
}

.lead-field input:focus,
.lead-field textarea:focus {
  outline: none;
  border-color: var(--accent);
}

.lead-form-actions {
  display: flex;
  gap: 8px;
  margin-top: 6px;
}

.lead-submit,
.lead-cancel {
  padding: 8px 14px;
  background: transparent;
  color: var(--fg);
  border: 1px solid var(--border);
  font-family: inherit;
  font-size: 13px;
  cursor: pointer;
}

.lead-submit { border-color: var(--accent); }
.lead-submit::before { content: "[ ] "; color: var(--muted); }
.lead-cancel::before { content: "[ ] "; color: var(--muted); }
.lead-submit:hover:not([disabled]) { background: rgba(197, 56, 14, 0.10); }
.lead-submit:hover:not([disabled])::before { content: "[>] "; color: var(--accent); }
.lead-submit[disabled] { opacity: 0.55; cursor: not-allowed; }

.lead-status {
  margin-top: 8px;
  font-size: 12px;
  min-height: 1.2em;
  color: var(--muted);
}

.lead-status.err { color: var(--accent); }

/* ========== Mobile (≤520px) ========== */

@media (max-width: 520px) {
  html, body { font-size: 13px; }

  #wrapper { max-width: 100%; }

  #hud {
    padding: 9px 12px 6px;
  }

  #hud-line1 { font-size: 12px; }
  #hud-line2, #hud-line3 {
    font-size: 11px;
    letter-spacing: -0.01em;
  }

  #hud-hint {
    padding: 5px 12px 4px;
    font-size: 11px;
  }

  #hud-projects {
    padding: 3px 12px 5px;
    font-size: 11px;
  }

  #game {
    padding: 10px 12px 12px;
  }

  #log {
    max-height: 48vh;
    min-height: 140px;
    font-size: 12px;
  }

  .action-btn {
    font-size: 12px;
    padding: 8px 10px;
  }

  .lead-field input,
  .lead-field textarea {
    font-size: 16px; /* avoid iOS zoom */
  }

  #footer { padding: 9px 12px 12px; font-size: 10px; }
}

@media (max-width: 380px) {
  #hud-line2, #hud-line3 {
    font-size: 10px;
    letter-spacing: -0.02em;
  }
}
