:root {
  --bg:        #09090b;
  --bg-2:      #111114;
  --bg-3:      #17171c;
  --border:    #26262d;
  --border-2:  #33333c;
  --text:      #fafafa;
  --text-2:    #a1a1aa;
  --text-3:    #71717a;
  --accent:    #3b82f6;
  --cta:       #16a177;
  --warn:      #f59e0b;
  --error:     #ef4444;
  --font-display: 'Onest', system-ui, sans-serif;
  --font-body:    'Inter', system-ui, sans-serif;
  --font-mono:    'JetBrains Mono', ui-monospace, monospace;
  --r-sm: 4px;
  --r-md: 6px;
  --r-lg: 10px;
  --s-1: 4px;  --s-2: 8px;  --s-3: 12px; --s-4: 16px;
  --s-5: 20px; --s-6: 24px; --s-8: 32px; --s-10: 40px;
  --t-fast:   100ms;
  --t-normal: 200ms;
}

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

[hidden] {
  display: none !important;
}

html, body {
  min-height: 100vh;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-body);
  font-size: 14px;
  line-height: 1.5;
}

body {
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}

.screen {
  flex: 1;
  display: grid;
  place-items: center;
}

#screen-main {
  display: flex;
  flex-direction: column;
  place-items: initial;
  flex: 1;
  min-height: 0;
}

.auth-card {
  width: 360px;
  background: var(--bg-2);
  border: 1px solid var(--border);
  padding: var(--s-8);
  border-radius: var(--r-lg);
  display: flex;
  flex-direction: column;
  gap: var(--s-3);
}

.logo {
  font-family: var(--font-display);
  font-weight: 800;
  font-size: 24px;
  color: var(--text);
}

.logo-sub {
  font-family: var(--font-mono);
  font-size: 12px;
  color: var(--text-3);
}

.auth-hint {
  font-size: 13px;
  color: var(--text-3);
  margin-top: var(--s-3);
}

#auth-form {
  display: flex;
  flex-direction: column;
  gap: var(--s-3);
}

#auth-password {
  width: 100%;
  height: 40px;
  background: var(--bg);
  border: 1px solid var(--border-2);
  padding: 0 12px;
  font-family: var(--font-mono);
  font-size: 14px;
  color: var(--text);
  border-radius: var(--r-sm);
}

#auth-password:focus {
  border-color: var(--accent);
  outline: none;
}

.btn-primary {
  width: 100%;
  height: 40px;
  background: var(--cta);
  color: #fff;
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 14px;
  border: none;
  border-radius: var(--r-md);
  cursor: pointer;
  transition: filter var(--t-fast);
}

.btn-primary:hover {
  filter: brightness(1.08);
}

.btn-primary:disabled {
  opacity: 0.6;
  cursor: wait;
}

.inline-error {
  color: var(--error);
  font-size: 13px;
  margin-top: var(--s-2);
}

.main-header {
  height: 60px;
  background: var(--bg-2);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 var(--s-5);
}

.logo-inline {
  font-family: var(--font-display);
  font-weight: 800;
  font-size: 18px;
  color: var(--text);
}

.btn-link {
  background: none;
  border: none;
  color: var(--text-2);
  cursor: pointer;
  font-family: var(--font-body);
  font-size: 14px;
}

.btn-link:hover {
  color: var(--text);
}

.site-footer {
  height: 40px;
  background: var(--bg-2);
  color: var(--text-3);
  font-family: var(--font-mono);
  font-size: 12px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

/* ==========================================================================
   Main screen — three-column layout (Phase 4 / FLAY-01)
   ========================================================================== */

.main-grid {
  flex: 1;
  display: grid;
  grid-template-columns: 35fr 25fr 35fr;
  gap: var(--s-5);
  padding: var(--s-5);
  min-width: 1200px;
  min-height: 0;
}

.col {
  display: flex;
  flex-direction: column;
  gap: var(--s-3);
  min-height: 0;
}

.col-settings {
  background: var(--bg-2);
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  padding: var(--s-5);
  overflow-y: auto;
}

.col-header {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
}

.col-title {
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 16px;
  color: var(--text);
}

.word-count {
  font-family: var(--font-mono);
  font-size: 12px;
  color: var(--text-3);
}

.text-area {
  flex: 1;
  width: 100%;
  min-height: 300px;
  background: var(--bg-2);
  border: 1px solid var(--border);
  border-radius: var(--r-md);
  padding: var(--s-3);
  font-family: var(--font-body);
  font-size: 14px;
  line-height: 1.6;
  color: var(--text);
  resize: none;
}

.text-area:focus {
  border-color: var(--accent);
  outline: none;
}

.text-area::placeholder {
  color: var(--text-3);
}

.col-actions {
  display: flex;
  gap: var(--s-2);
  flex-wrap: wrap;
}

.btn-secondary {
  height: 32px;
  padding: 0 12px;
  background: transparent;
  border: 1px solid var(--border-2);
  border-radius: var(--r-md);
  color: var(--text-2);
  font-family: var(--font-body);
  font-weight: 500;
  font-size: 13px;
  cursor: pointer;
  transition: color var(--t-fast), border-color var(--t-fast);
}

.btn-secondary:hover {
  border-color: var(--text-3);
  color: var(--text);
}

/* ==========================================================================
   Settings controls (Phase 4 / FLAY-02)
   ========================================================================== */

.settings-body {
  display: flex;
  flex-direction: column;
  gap: var(--s-5);
  flex: 1;
  min-height: 0;
}

.control {
  display: flex;
  flex-direction: column;
  gap: var(--s-2);
}

.control > label {
  display: flex;
  align-items: center;
  gap: var(--s-2);
}

.control-label {
  font-family: var(--font-body);
  font-weight: 500;
  font-size: 13px;
  color: var(--text-2);
}

.tooltip {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: var(--bg-3);
  border: 1px solid var(--border-2);
  color: var(--text-3);
  font-size: 11px;
  cursor: help;
  user-select: none;
}

.tooltip:hover,
.tooltip:focus {
  color: var(--text);
  border-color: var(--accent);
  outline: none;
}

.select-input {
  width: 100%;
  height: 36px;
  background: var(--bg);
  border: 1px solid var(--border-2);
  border-radius: var(--r-md);
  padding: 0 var(--s-3);
  color: var(--text);
  font-family: var(--font-body);
  font-size: 13px;
  cursor: pointer;
}

.select-input:focus {
  border-color: var(--accent);
  outline: none;
}

.select-input:disabled {
  opacity: 0.6;
  cursor: wait;
}

/* §4.2 length tabs */
.length-tabs {
  display: flex;
  gap: var(--s-2);
}

.length-tab {
  flex: 1;
  height: 32px;
  background: var(--bg);
  border: 1px solid var(--border-2);
  border-radius: var(--r-md);
  color: var(--text-2);
  font-family: var(--font-body);
  font-size: 13px;
  cursor: pointer;
  transition: color var(--t-fast), border-color var(--t-fast), background var(--t-fast);
}

.length-tab:hover {
  border-color: var(--text-3);
  color: var(--text);
}

.length-tab.is-active {
  background: var(--bg-3);
  border-color: var(--accent);
  color: var(--text);
}

.length-range {
  display: flex;
  gap: var(--s-3);
  margin-top: var(--s-2);
}

.range-label {
  flex: 1;
  display: flex;
  align-items: center;
  gap: var(--s-2);
  font-family: var(--font-mono);
  font-size: 12px;
  color: var(--text-3);
}

.number-input {
  flex: 1;
  height: 32px;
  background: var(--bg);
  border: 1px solid var(--border-2);
  border-radius: var(--r-sm);
  padding: 0 var(--s-2);
  color: var(--text);
  font-family: var(--font-mono);
  font-size: 13px;
}

.number-input:focus {
  border-color: var(--accent);
  outline: none;
}

/* §4.3 immersion range */
.range-input {
  width: 100%;
  accent-color: var(--accent);
  cursor: pointer;
}

.immersion-caption {
  font-family: var(--font-mono);
  font-size: 13px;
  color: var(--text-2);
}

/* §4.4 profanity toggle */
.toggle-row {
  display: flex;
  align-items: center;
  gap: var(--s-3);
}

.toggle {
  position: relative;
  display: inline-block;
  width: 40px;
  height: 22px;
  cursor: pointer;
}

.toggle input {
  opacity: 0;
  width: 0;
  height: 0;
}

.toggle-track {
  position: absolute;
  inset: 0;
  background: var(--bg-3);
  border: 1px solid var(--border-2);
  border-radius: 999px;
  transition: background var(--t-fast), border-color var(--t-fast);
}

.toggle-thumb {
  position: absolute;
  top: 2px;
  left: 2px;
  width: 16px;
  height: 16px;
  background: var(--text-2);
  border-radius: 50%;
  transition: transform var(--t-fast), background var(--t-fast);
}

.toggle input:checked + .toggle-track {
  background: var(--cta);
  border-color: var(--cta);
}

.toggle input:checked + .toggle-track .toggle-thumb {
  transform: translateX(18px);
  background: #fff;
}

.toggle-caption {
  font-family: var(--font-body);
  font-size: 13px;
  color: var(--text-3);
}

/* Plan 11.1-04 / FFTR-03: profanity control disabled when selected style.has_profanity === false */
.control.profanity-disabled {
  opacity: 0.55;
  pointer-events: auto; /* keep tooltip hover working on the wrapper */
}
.control.profanity-disabled .toggle-track {
  cursor: not-allowed;
}
.control.profanity-disabled #profanity-toggle {
  cursor: not-allowed;
}

/* §4.6 cost block */
.cost-block {
  font-family: var(--font-mono);
  font-size: 14px;
  color: var(--text-2);
}

/* Plan 11.1-02 (FFTR-01): RUB equivalent next to USD cost */
.cost-block #cost-block-rub {
  margin-left: 0.5rem;
}
.cost-block .cost-sep {
  display: inline-block;
  width: 0.25rem;
}

/* Divider */
.settings-divider {
  border: none;
  border-top: 1px solid var(--border);
  margin: var(--s-4) 0;
}

/* Presets row */
.preset-row {
  display: flex;
  gap: var(--s-2);
}

.preset-row .select-input {
  flex: 1;
}

.preset-row .btn-secondary {
  width: 40px;
  padding: 0;
}

/* §4.7 process button (CTA) */
.btn-cta {
  width: 100%;
  height: 48px;
  background: var(--cta);
  color: #fff;
  border: none;
  border-radius: var(--r-md);
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 16px;
  cursor: pointer;
  margin-top: auto;
  transition: filter var(--t-fast);
}

.btn-cta:hover:not(:disabled) {
  filter: brightness(1.08);
}

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

/* ==========================================================================
   Tooltip popup system (Phase 4 / FLAY-03)
   Note: badge-style .tooltip base rules live above (added in Plan 04-02).
   This block only adds the floating popup + its visible state.
   ========================================================================== */

.tooltip-popup {
  position: fixed;
  z-index: 1000;
  background: var(--bg-2);
  border: 1px solid var(--border-2);
  border-radius: var(--r-md);
  padding: var(--s-2) var(--s-3);
  color: var(--text-2);
  font-family: var(--font-body);
  font-size: 13px;
  line-height: 1.4;
  max-width: 240px;
  pointer-events: none;
  opacity: 0;
  transition: opacity var(--t-fast);
}

.tooltip-popup.is-visible {
  opacity: 1;
}

/* ==========================================================================
   Preset modal (Phase 06 / FLOG-01)
   ========================================================================== */

.modal {
  position: fixed;
  inset: 0;
  z-index: 1100;
  display: flex;
  align-items: center;
  justify-content: center;
}

.modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.55);
}

.modal-card {
  position: relative;
  background: var(--bg-2);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  width: min(520px, 92vw);
  max-height: 80vh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.4);
}

.modal-header,
.modal-footer {
  padding: var(--s-4) var(--s-5);
  display: flex;
  justify-content: space-between;
  align-items: center;
  border-bottom: 1px solid var(--border);
}

.modal-header h3 {
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 16px;
  color: var(--text);
}

.modal-footer {
  border-bottom: none;
  border-top: 1px solid var(--border);
  justify-content: flex-end;
}

.modal-body {
  padding: var(--s-4) var(--s-5);
  overflow: auto;
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: var(--s-4);
}

.preset-list {
  list-style: none;
  padding: 0;
  margin: 0;
  display: flex;
  flex-direction: column;
  gap: var(--s-2);
}

.preset-list li {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: var(--s-3) var(--s-3);
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--r-md);
  font-family: var(--font-body);
  font-size: 13px;
  color: var(--text);
}

.preset-list .preset-empty {
  color: var(--text-3);
  font-style: italic;
  justify-content: center;
}

.preset-save-row {
  display: flex;
  gap: var(--s-2);
  align-items: stretch;
}

.preset-save-row .text-input {
  flex: 1;
  height: 40px;
  padding: 0 var(--s-3);
  background: var(--bg);
  color: var(--text);
  border: 1px solid var(--border-2);
  border-radius: var(--r-md);
  font-family: var(--font-body);
  font-size: 13px;
}

.preset-save-row .text-input:focus {
  border-color: var(--accent);
  outline: none;
}

.preset-save-row .btn-primary {
  width: auto;
  padding: 0 var(--s-4);
}

/* ==========================================================================
   Phase 07 / FLOG-03..06 — streaming state
   ========================================================================== */

#process-btn[data-state="streaming"] {
  background: var(--bg-3);
  color: var(--text);
  border: 1px solid var(--accent);
}

#process-btn:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

#stream-error {
  margin-top: var(--s-2);
  color: var(--error);
  font-family: var(--font-body);
  font-size: 13px;
}

#result-actions {
  display: flex;
  gap: var(--s-2);
  margin-top: var(--s-3);
  flex-wrap: wrap;
}

#result-actions[hidden] {
  display: none;
}

/* ==========================================================================
   Phase 07 / FLOG-05 — word-level diff view
   ========================================================================== */

.diff-view {
  flex: 1;
  background: var(--bg-2);
  border: 1px solid var(--border);
  border-radius: var(--r-md);
  padding: 12px;
  font-family: var(--font-body);
  font-size: 14px;
  line-height: 1.6;
  color: var(--text);
  white-space: pre-wrap;
  word-wrap: break-word;
  overflow-y: auto;
}

.diff-view[hidden] {
  display: none;
}

.diff-view .diff-eq {
  color: var(--text);
}

.diff-view .diff-add {
  background: rgba(22, 161, 119, 0.25);
  color: var(--text);
}

.diff-view .diff-del {
  background: rgba(239, 68, 68, 0.25);
  color: var(--text-2);
  text-decoration: line-through;
}

#diff-btn.is-active {
  background: var(--bg-3);
  border-color: var(--accent);
  color: var(--text);
}

/* ========== Detection indicator (FHST-04) ========== */
.detection-indicator {
  display: flex;
  align-items: center;
  gap: var(--s-2);
  margin-top: var(--s-3);
  padding: var(--s-2) var(--s-3);
  background: var(--bg-2);
  border: 1px solid var(--border);
  border-radius: var(--r-md);
  font-family: var(--font-body);
  font-size: 13px;
  color: var(--text-2);
}

.detection-indicator[hidden] {
  display: none;
}

.detection-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--text-3);
  flex-shrink: 0;
}

.detection-dot.is-low { background: var(--cta); }
.detection-dot.is-medium { background: var(--warn); }
.detection-dot.is-high { background: var(--error); }

/* ========== History accordion (FHST-01..03) ========== */
.history-accordion {
  margin-top: var(--s-5);
  background: var(--bg-2);
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  overflow: hidden;
}

.history-summary {
  list-style: none;
  cursor: pointer;
  padding: var(--s-3) var(--s-5);
  display: flex;
  align-items: center;
  gap: var(--s-3);
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 14px;
  color: var(--text);
  user-select: none;
}

.history-summary::-webkit-details-marker { display: none; }

.history-chevron {
  display: inline-block;
  font-family: var(--font-mono);
  color: var(--text-3);
  transition: transform var(--t-fast);
}

.history-accordion[open] .history-chevron {
  transform: rotate(90deg);
}

.history-count {
  margin-left: auto;
  font-family: var(--font-mono);
  font-size: 12px;
  color: var(--text-3);
}

.history-body {
  padding: var(--s-4) var(--s-5) var(--s-5);
  border-top: 1px solid var(--border);
}

.history-controls {
  display: flex;
  align-items: center;
  gap: var(--s-3);
  margin-bottom: var(--s-4);
}

.history-filter-label {
  font-family: var(--font-body);
  font-size: 13px;
  color: var(--text-2);
}

.history-state {
  padding: var(--s-4);
  text-align: center;
  font-family: var(--font-body);
  font-size: 13px;
  color: var(--text-3);
}

.history-state[hidden] { display: none; }

.history-table {
  width: 100%;
  border-collapse: collapse;
  font-family: var(--font-body);
  font-size: 13px;
}

.history-table[hidden] { display: none; }

.history-table th,
.history-table td {
  padding: var(--s-2) var(--s-3);
  text-align: left;
  border-bottom: 1px solid var(--border);
  vertical-align: top;
}

.history-table th {
  font-weight: 500;
  color: var(--text-3);
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.history-table tbody tr.history-row:hover {
  background: var(--bg-3);
}

.history-table .history-cell-date {
  font-family: var(--font-mono);
  font-size: 12px;
  color: var(--text-3);
  white-space: nowrap;
}

.history-table .history-cell-model {
  font-family: var(--font-mono);
  font-size: 12px;
  color: var(--text-2);
  white-space: nowrap;
}

.history-table .history-cell-preview {
  color: var(--text-2);
  max-width: 240px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.history-table .history-cell-actions {
  display: flex;
  gap: var(--s-2);
  white-space: nowrap;
}

.history-footer {
  margin-top: var(--s-4);
  display: flex;
  justify-content: center;
}

.btn-danger {
  height: 32px;
  padding: 0 12px;
  background: transparent;
  border: 1px solid var(--border-2);
  color: var(--text-2);
  font-family: var(--font-body);
  font-weight: 500;
  font-size: 13px;
  border-radius: var(--r-md);
  cursor: pointer;
}

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