/* ==========================================================================
   Отмазочный цех — industrial dark theme (tokens in DESIGN.md)
   Motion policy: hover/focus transitions only. No keyframe animations. No CDN.
   ========================================================================== */

:root {
  /* palette */
  --bg: #0d1117;
  --bg-raised: #161b22;
  --bg-inset: #010409;
  --border: #30363d;
  --border-strong: #484f58;
  --text: #e6edf3;
  --text-dim: #8b949e;
  --accent: #ff9800;
  --accent-dim: #7d4f0e;
  --danger: #f85149;
  --success: #3fb950;
  --accent-contrast: #140c02;

  /* type */
  --font-ui: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  --font-mono: "Courier New", monospace;

  /* spacing (8px base) */
  --sp-1: 8px;
  --sp-2: 16px;
  --sp-3: 24px;
  --sp-4: 32px;
  --sp-6: 48px;

  /* shape */
  --radius: 6px;

  /* motion */
  --ease: ease;
  --speed: 0.2s;
}

/* --- reset --- */
*,
*::before,
*::after {
  box-sizing: border-box;
}

html {
  background: var(--bg);
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-ui);
  font-size: 16px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

/* --- layout --- */
.container {
  max-width: 880px;
  margin: 0 auto;
  padding: var(--sp-2);
}

main {
  display: flex;
  flex-direction: column;
  gap: var(--sp-3);
}

/* --- screens (JS-toggled) --- */
.screen {
  display: none;
}

.screen.active {
  display: block;
}

/* --- header --- */
.site-header {
  padding: var(--sp-4) 0 var(--sp-2);
}

.site-header h1 {
  margin: 0;
  font-size: clamp(1.75rem, 4vw, 2.5rem);
  font-weight: 800;
  letter-spacing: -0.02em;
  line-height: 1.1;
  text-transform: uppercase;
}

.site-header h1::before {
  content: "// ";
  color: var(--accent);
}

.tagline {
  margin: var(--sp-1) 0 0;
  color: var(--text-dim);
  font-size: 1rem;
}

.hazard-stripe {
  height: 6px;
  margin-bottom: var(--sp-3);
  background: repeating-linear-gradient(
    45deg,
    var(--accent) 0 12px,
    var(--bg-raised) 12px 24px
  );
  border-radius: 2px;
  opacity: 0.7;
}

/* --- mode cards (home screen) --- */
.mode-cards {
  display: grid;
  grid-template-columns: 1fr;
  gap: var(--sp-2);
}

.mode-card {
  background: var(--bg-raised);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: var(--sp-3);
  cursor: pointer;
  transition: border-color var(--speed) var(--ease),
    transform var(--speed) var(--ease);
}

.mode-card:hover {
  border-color: var(--accent);
  transform: translateY(-2px);
}

.mode-card:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.mode-card-icon {
  font-size: 32px;
  line-height: 1;
  margin-bottom: var(--sp-1);
}

.mode-card-title {
  font-size: 1.125rem;
  font-weight: 600;
  margin-bottom: var(--sp-1);
}

.mode-card-desc {
  font-size: 0.875rem;
  color: var(--text-dim);
  line-height: 1.5;
}

/* --- back button --- */
.back-btn {
  display: inline-flex;
  align-items: center;
  gap: var(--sp-1);
  background: none;
  border: none;
  padding: var(--sp-1) 0;
  margin-bottom: var(--sp-2);
  color: var(--text-dim);
  font-family: var(--font-ui);
  font-size: 0.875rem;
  cursor: pointer;
  transition: color var(--speed) var(--ease);
}

.back-btn:hover {
  color: var(--accent);
}

/* --- panels --- */
.panel {
  background: var(--bg-raised);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: var(--sp-3);
}

.panel h2 {
  margin: 0 0 var(--sp-2);
  font-size: 1.25rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--accent);
}

.section-note {
  margin: 0 0 var(--sp-2);
  color: var(--text-dim);
  font-size: 0.875rem;
}

/* --- fields --- */
.form-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: var(--sp-2);
}

.field {
  min-width: 0;
}

.field > label,
.field legend {
  display: block;
  margin-bottom: var(--sp-1);
  font-size: 0.8125rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-dim);
}

.field-mode {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: var(--sp-2);
}

.field-mode legend {
  padding: 0 var(--sp-1);
}

select,
textarea {
  width: 100%;
  background: var(--bg-inset);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 10px 12px;
  font-family: var(--font-ui);
  font-size: 1rem;
  transition: border-color var(--speed) var(--ease);
}

select:hover,
textarea:hover {
  border-color: var(--border-strong);
}

select:focus-visible,
textarea:focus-visible,
input[type="range"]:focus-visible,
input[type="radio"]:focus-visible,
.btn:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

textarea {
  resize: vertical;
  min-height: 3.5rem;
}

textarea[readonly] {
  font-family: var(--font-mono);
  background: var(--bg-inset);
  border-color: var(--border-strong);
}

.char-count {
  display: block;
  margin-top: 4px;
  text-align: right;
  color: var(--text-dim);
  font-size: 0.75rem;
  font-family: var(--font-mono);
}

/* --- range --- */
input[type="range"] {
  width: 100%;
  accent-color: var(--accent);
  cursor: pointer;
}

.range-scale {
  display: flex;
  justify-content: space-between;
  margin-top: 4px;
  color: var(--text-dim);
  font-size: 0.75rem;
}

/* --- mode radios --- */
.field-mode .mode-options,
.field-mode {
  gap: var(--sp-1);
}

.mode-option {
  display: flex;
  align-items: center;
  gap: var(--sp-1);
  padding: 8px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  cursor: pointer;
  transition: border-color var(--speed) var(--ease),
    color var(--speed) var(--ease),
    background var(--speed) var(--ease);
}

.mode-option + .mode-option {
  margin-top: var(--sp-1);
}

.mode-option:hover {
  border-color: var(--border-strong);
}

.mode-option input[type="radio"] {
  accent-color: var(--accent);
  margin: 0;
}

.mode-option:has(input:checked) {
  border-color: var(--accent);
  background: rgba(255, 152, 0, 0.08);
  color: var(--accent);
}

.field-mode {
  display: flex;
  flex-direction: column;
}

.field-mode > legend {
  margin-bottom: 0;
}

/* --- buttons --- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--sp-1);
  padding: 10px 20px;
  border: 1px solid transparent;
  border-radius: var(--radius);
  font-family: var(--font-ui);
  font-size: 1rem;
  font-weight: 700;
  cursor: pointer;
  transition: background var(--speed) var(--ease),
    border-color var(--speed) var(--ease),
    color var(--speed) var(--ease),
    transform var(--speed) var(--ease);
}

.btn:active:not(:disabled) {
  transform: translateY(1px);
}

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

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

.btn-primary:hover:not(:disabled) {
  background: #ffb03a;
  border-color: #ffb03a;
}

.btn-ghost {
  background: transparent;
  border-color: var(--border-strong);
  color: var(--text);
}

.btn-ghost:hover:not(:disabled) {
  border-color: var(--accent);
  color: var(--accent);
}

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

.btn-danger:hover:not(:disabled) {
  border-color: var(--danger);
  color: var(--danger);
}

.field-action {
  display: flex;
  align-items: flex-end;
}

/* --- output well (excuse / chat message) --- */
.output-well {
  background: var(--bg-inset);
  border: 1px solid var(--border-strong);
  border-left: 3px solid var(--accent);
  border-radius: var(--radius);
  padding: var(--sp-2);
  margin-bottom: var(--sp-2);
}

.output-text {
  font-family: var(--font-mono);
  font-size: 1.0625rem;
  line-height: 1.6;
  white-space: pre-wrap;
  word-break: break-word;
}

/* Streaming cursor — blinking is done by JS interval (no @keyframes per motion policy) */
.stream-cursor {
  display: inline;
  font-family: var(--font-mono);
  font-size: 1.0625rem;
  color: var(--accent);
}

/* Streaming cursor: visibility toggled by JS interval (CSS keyframes forbidden) */
.stream-cursor {
  font-family: var(--font-mono);
  color: var(--accent);
}

/* --- confidence --- */
.confidence-row {
  display: flex;
  align-items: center;
  gap: var(--sp-2);
  margin-bottom: var(--sp-2);
}

.confidence-label {
  flex: none;
  font-size: 0.8125rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-dim);
}

.confidence-bar {
  flex: 1;
  height: 12px;
  background: var(--bg-inset);
  border: 1px solid var(--border);
  border-radius: 999px;
  overflow: hidden;
}

.confidence-fill {
  height: 100%;
  width: 0;
  background: var(--accent);
  border-radius: 999px;
}

.confidence-value {
  flex: none;
  min-width: 3ch;
  text-align: right;
  font-family: var(--font-mono);
  font-weight: 700;
  color: var(--accent);
}

/* --- tip --- */
.tip {
  border: 1px dashed var(--border-strong);
  border-radius: var(--radius);
  padding: var(--sp-2);
  margin-bottom: var(--sp-2);
}

.tip-label {
  display: block;
  margin-bottom: 4px;
  font-size: 0.75rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--success);
}

.tip p {
  margin: 0;
  color: var(--text);
  font-size: 0.9375rem;
}

/* --- objections accordion --- */
.objections {
  margin-bottom: var(--sp-2);
}

.objections-title {
  margin: 0 0 var(--sp-1);
  font-size: 0.875rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-dim);
}

.objection {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  margin-bottom: var(--sp-1);
  overflow: hidden;
}

.objection:last-child {
  margin-bottom: 0;
}

.objection-q {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--sp-1);
  padding: 10px 12px;
  background: transparent;
  border: none;
  color: var(--text);
  font-family: var(--font-ui);
  font-size: 0.9375rem;
  text-align: left;
  cursor: pointer;
  transition: background var(--speed) var(--ease),
    border-color var(--speed) var(--ease);
}

.objection-q:hover {
  background: rgba(255, 255, 255, 0.04);
}

.objection-caret {
  flex: none;
  color: var(--text-dim);
  font-family: var(--font-mono);
  transition: transform var(--speed) var(--ease);
}

.objection.open .objection-caret {
  transform: rotate(90deg);
  color: var(--accent);
}

.objection.open {
  border-color: var(--accent);
}

.objection-a {
  display: none;
  padding: 0 12px 12px;
  color: var(--text-dim);
  font-size: 0.9375rem;
}

.objection-a p {
  margin: 0;
  font-family: var(--font-mono);
}

.objection.open .objection-a {
  display: block;
}

/* --- result actions --- */
.result-actions {
  margin-top: var(--sp-2);
  display: flex;
  gap: var(--sp-1);
}

/* --- history --- */
.history-list {
  display: flex;
  flex-direction: column;
  gap: var(--sp-1);
}

.history-item {
  background: var(--bg-inset);
  border: 1px solid var(--border);
  border-left: 3px solid var(--border-strong);
  border-radius: var(--radius);
  padding: var(--sp-2);
  transition: border-color var(--speed) var(--ease);
}

.history-item:hover {
  border-color: var(--border-strong);
}

.history-item.favorited {
  border-left-color: var(--accent);
}

.history-head {
  display: flex;
  align-items: baseline;
  flex-wrap: wrap;
  gap: var(--sp-1);
  margin-bottom: var(--sp-1);
}

.history-type {
  font-size: 0.75rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--accent);
}

.history-mode {
  font-size: 0.75rem;
  color: var(--text-dim);
}

.history-date {
  margin-left: auto;
  font-size: 0.75rem;
  color: var(--text-dim);
  font-family: var(--font-mono);
}

.history-excuse {
  margin: 0 0 var(--sp-1);
  font-family: var(--font-mono);
  font-size: 0.9375rem;
  line-height: 1.5;
  white-space: pre-wrap;
  word-break: break-word;
}

.history-meta {
  display: flex;
  align-items: center;
  gap: var(--sp-1);
}

.history-confidence {
  font-family: var(--font-mono);
  font-size: 0.8125rem;
  color: var(--text-dim);
}

.history-confidence strong {
  color: var(--accent);
}

.history-actions {
  margin-left: auto;
  display: flex;
  gap: 4px;
}

.icon-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  background: transparent;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text-dim);
  cursor: pointer;
  transition: border-color var(--speed) var(--ease),
    color var(--speed) var(--ease);
}

.icon-btn:hover {
  border-color: var(--accent);
  color: var(--accent);
}

.icon-btn.favorited {
  border-color: var(--accent);
  color: var(--accent);
}

.icon-btn.delete:hover {
  border-color: var(--danger);
  color: var(--danger);
}

/* --- history section (per-mode screens) --- */
.history-section {
  margin-top: var(--sp-3);
  padding-top: var(--sp-3);
  border-top: 1px solid var(--border);
}

.history-title {
  margin: 0 0 var(--sp-2);
  font-size: 1rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--accent);
}

/* --- filter tabs (history screen) --- */
.filter-tabs {
  display: flex;
  flex-wrap: wrap;
  gap: var(--sp-1);
  margin-bottom: var(--sp-2);
}

.filter-tab {
  padding: 6px 12px;
  border: 1px solid var(--border);
  border-radius: 4px;
  background: transparent;
  color: var(--text-dim);
  font-family: var(--font-ui);
  font-size: 0.875rem;
  cursor: pointer;
  transition: border-color var(--speed) var(--ease),
    color var(--speed) var(--ease),
    background var(--speed) var(--ease);
}

.filter-tab:hover {
  border-color: var(--border-strong);
}

.filter-tab.active {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--accent-contrast);
}

/* --- type badges (history screen) --- */
.type-badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 4px;
  font-size: 0.75rem;
  font-weight: 700;
}

.type-badge-generate {
  background: rgba(255, 152, 0, 0.15);
  color: var(--accent);
}

.type-badge-sabotage {
  background: rgba(56, 139, 253, 0.15);
  color: #58a6ff;
}

/* --- toast --- */
.toast {
  position: fixed;
  bottom: var(--sp-3);
  left: 50%;
  transform: translateX(-50%);
  max-width: calc(100vw - 32px);
  background: var(--bg-raised);
  border: 1px solid var(--danger);
  border-radius: var(--radius);
  padding: 12px 20px;
  color: var(--text);
  font-size: 0.9375rem;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.5);
  z-index: 10;
}

.toast.success {
  border-color: var(--success);
}

/* --- footer --- */
.site-footer {
  margin-top: var(--sp-4);
  padding-bottom: var(--sp-4);
  color: var(--text-dim);
  font-size: 0.8125rem;
  text-align: center;
}

.site-footer p {
  margin: 0;
}

/* --- responsive --- */
@media (min-width: 640px) {
  .form-grid {
    grid-template-columns: 1fr 1fr;
  }

  .field-mode,
  .field-action {
    grid-column: 1 / -1;
  }

  .mode-cards {
    grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
  }
}

/* --- reduced motion: transitions are state feedback; keep them short --- */
@media (prefers-reduced-motion: reduce) {
  * {
    transition-duration: 0.01ms !important;
  }
}
