/* =========================================================
   BrainEtch — base.css
   Design tokens, reset, common primitives (buttons, inputs,
   tags, chips, progress bars, toasts, modals).
   ========================================================= */

:root {
  --bg-base: #0d1117;
  --bg-surface: #161b22;
  --bg-raised: #1e2530;
  --bg-raised-2: #232b38;
  --border: #2a3040;
  --border-bright: #3d4a5c;

  --text-primary: #e8dcc8;
  --text-secondary: #8b9ab0;
  --text-placeholder: #4a5568;

  --accent: #d4922a;
  --accent-bright: #f0a832;
  --accent-subtle: #2a1f0a;
  --accent-deep: #3a2a0f;

  --green: #3a7d44;
  --green-bright: #4caf60;
  --orange: #c87a2a;
  --red: #8b3a3a;
  --red-bright: #c94a4a;
  --blue: #2a5a8b;
  --blue-bright: #4a8abf;
  --purple: #7a4aa8;

  --radius-sm: 6px;
  --radius-md: 10px;
  --radius-lg: 16px;
  --radius-xl: 22px;

  --shadow-card: 0 1px 0 rgba(255,255,255,0.02) inset, 0 8px 24px rgba(0,0,0,0.35);
  --shadow-deep: 0 24px 60px rgba(0,0,0,0.55);

  --font-display: 'Space Grotesk', 'Inter', system-ui, sans-serif;
  --font-body: 'DM Sans', system-ui, -apple-system, Segoe UI, Roboto, sans-serif;
  --font-mono: 'JetBrains Mono', 'IBM Plex Mono', ui-monospace, monospace;

  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg-base);
  color: var(--text-primary);
  font-family: var(--font-body);
  font-size: 14px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
  min-height: 100%;
  height: 100%;
}

body {
  overflow: hidden; /* each screen manages its own scroll */
}

/* Subtle grain overlay */
body::before {
  content: '';
  position: fixed;
  inset: 0;
  background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='220' height='220'><filter id='n'><feTurbulence type='fractalNoise' baseFrequency='0.9' numOctaves='2' stitchTiles='stitch'/><feColorMatrix type='matrix' values='0 0 0 0 1  0 0 0 0 1  0 0 0 0 1  0 0 0 0.8 0'/></filter><rect width='100%25' height='100%25' filter='url(%23n)'/></svg>");
  opacity: 0.035;
  pointer-events: none;
  z-index: 9999;
  mix-blend-mode: overlay;
}

a { color: var(--accent-bright); text-decoration: none; }
a:hover { text-decoration: underline; }

input, textarea, select, button { font-family: inherit; }
button { background: none; border: 0; color: inherit; cursor: pointer; }

::selection { background: rgba(212,146,42,0.28); color: var(--text-primary); }

/* Scrollbars */
::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 4px; border: 2px solid transparent; background-clip: padding-box; }
::-webkit-scrollbar-thumb:hover { background: var(--border-bright); background-clip: padding-box; border: 2px solid transparent; }

/* =========================================================
   App root & boot splash
   ========================================================= */
.app-root {
  position: fixed;
  inset: 0;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.boot-splash {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 20px;
}
.boot-brand {
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 40px;
  letter-spacing: -0.03em;
  color: var(--text-primary);
  opacity: 0.9;
}
.boot-loader {
  width: 120px;
  height: 1px;
  background: linear-gradient(90deg, transparent, var(--accent), transparent);
  animation: boot-sweep 1.4s ease-in-out infinite;
  background-size: 60% 100%;
  background-repeat: no-repeat;
}
@keyframes boot-sweep {
  0% { background-position: -60% 0; }
  100% { background-position: 160% 0; }
}

/* =========================================================
   Buttons
   ========================================================= */
.btn {
  font-weight: 500;
  font-size: 14px;
  border: 1px solid transparent;
  border-radius: var(--radius-md);
  padding: 12px 18px;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  transition: all 0.15s ease;
  line-height: 1;
  letter-spacing: 0.01em;
  white-space: nowrap;
}
.btn:disabled { opacity: 0.5; cursor: not-allowed; }

.btn-primary {
  background: var(--accent);
  color: #2b1a05;
  border-color: rgba(0,0,0,0.2);
  box-shadow: 0 1px 0 rgba(255,255,255,0.12) inset, 0 4px 12px rgba(212,146,42,0.18);
  font-weight: 600;
}
.btn-primary:hover:not(:disabled) { background: var(--accent-bright); }
.btn-primary:active { transform: translateY(1px); }

.btn-ghost {
  background: transparent;
  color: var(--text-primary);
  border-color: var(--border);
}
.btn-ghost:hover:not(:disabled) { border-color: var(--border-bright); background: var(--bg-raised); }

.btn-danger {
  background: transparent;
  color: var(--red-bright);
  border-color: rgba(201,74,74,0.4);
}
.btn-danger:hover { background: rgba(201,74,74,0.08); }

.btn-block { width: 100%; padding: 14px 18px; font-size: 15px; }
.btn-sm { padding: 8px 12px; font-size: 12px; }

/* =========================================================
   Inputs & Textareas
   ========================================================= */
.input, .textarea {
  width: 100%;
  background: var(--bg-raised);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 13px 14px;
  color: var(--text-primary);
  font-family: var(--font-body);
  font-size: 14px;
  transition: border-color 0.15s, box-shadow 0.15s;
}
.input::placeholder, .textarea::placeholder { color: var(--text-placeholder); }
.input:focus, .input.focused, .textarea:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(212,146,42,0.15);
}
.textarea { resize: vertical; min-height: 180px; line-height: 1.6; }
.input-error { border-color: var(--red-bright) !important; box-shadow: 0 0 0 3px rgba(201,74,74,0.15) !important; }
.field-error { color: var(--red-bright); font-size: 12px; margin-top: 6px; }
.field-hint { color: var(--text-secondary); font-size: 12px; margin-top: 6px; }

.input-wrap { position: relative; }
.input-wrap .eye {
  position: absolute;
  right: 14px; top: 50%;
  transform: translateY(-50%);
  color: var(--text-secondary);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
}

/* =========================================================
   Tags / chips / pills
   ========================================================= */
.tag {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 11px;
  font-weight: 500;
  padding: 4px 10px;
  border-radius: 999px;
  color: var(--accent);
  border: 1px solid var(--accent);
  background: rgba(212,146,42,0.06);
  letter-spacing: 0.02em;
  cursor: pointer;
  white-space: nowrap;
}
.tag.ghost {
  color: var(--text-secondary);
  border-color: var(--border);
  border-style: dashed;
  background: transparent;
}
.tag.removable .x {
  opacity: 0.6;
  font-size: 10px;
  cursor: pointer;
  padding: 0 2px;
}
.tag.removable .x:hover { opacity: 1; color: var(--red-bright); }

.chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 13px;
  padding: 8px 14px;
  border-radius: 999px;
  background: var(--bg-raised);
  border: 1px solid var(--border);
  color: var(--text-secondary);
  white-space: nowrap;
  cursor: pointer;
  transition: all 0.12s;
}
.chip:hover { border-color: var(--border-bright); color: var(--text-primary); }
.chip.active {
  background: var(--accent-subtle);
  border-color: var(--accent);
  color: var(--accent-bright);
}
.chip .count { font-size: 11px; opacity: 0.8; }

.pill-select {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 7px 12px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--bg-raised);
  font-size: 12px;
  color: var(--text-primary);
  cursor: pointer;
}
.pill-select:hover { border-color: var(--border-bright); }

.pill-group {
  display: inline-flex;
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  overflow: hidden;
  flex-wrap: wrap;
}
.pill-group button {
  background: transparent;
  border: 0;
  border-right: 1px solid var(--border);
  color: var(--text-secondary);
  padding: 8px 14px;
  font-size: 12px;
  cursor: pointer;
}
.pill-group button:last-child { border-right: 0; }
.pill-group button.active { background: var(--accent-subtle); color: var(--accent-bright); }
.pill-group button:hover:not(.active) { color: var(--text-primary); background: var(--bg-raised); }

/* =========================================================
   Progress bar
   ========================================================= */
.progress {
  height: 6px;
  border-radius: 3px;
  background: var(--bg-raised);
  overflow: hidden;
  position: relative;
}
.progress .fill {
  height: 100%;
  border-radius: 3px;
  background: linear-gradient(90deg, var(--green), var(--green-bright));
  transition: width 0.4s ease;
}
.progress.amber .fill { background: linear-gradient(90deg, var(--accent), var(--accent-bright)); }

/* =========================================================
   Ornaments
   ========================================================= */
.ornament-rule {
  display: flex; align-items: center; gap: 12px;
}
.ornament-rule .line { flex: 1; height: 1px; background: var(--border); }
.ornament-rule .diamond {
  width: 6px; height: 6px;
  background: var(--accent);
  transform: rotate(45deg);
  box-shadow: 0 0 10px rgba(212,146,42,0.4);
}

/* =========================================================
   Offline badge, Toasts, Modals
   ========================================================= */
.offline-badge {
  position: fixed;
  top: calc(12px + var(--safe-top));
  right: 12px;
  z-index: 8000;
  padding: 6px 12px;
  border-radius: 999px;
  font-size: 11px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  background: rgba(201,74,74,0.12);
  border: 1px solid rgba(201,74,74,0.4);
  color: var(--red-bright);
}

.toast-root {
  position: fixed;
  bottom: calc(24px + var(--safe-bottom));
  left: 50%;
  transform: translateX(-50%);
  z-index: 9500;
  display: flex;
  flex-direction: column;
  gap: 10px;
  align-items: center;
  pointer-events: none;
}
.toast {
  background: var(--bg-raised-2);
  border: 1px solid var(--border-bright);
  color: var(--text-primary);
  padding: 12px 18px;
  border-radius: var(--radius-md);
  font-size: 13px;
  box-shadow: var(--shadow-deep);
  pointer-events: auto;
  animation: toast-in 0.25s ease-out both;
  max-width: 90vw;
}
.toast.success { border-color: var(--green-bright); }
.toast.error { border-color: var(--red-bright); }
@keyframes toast-in {
  from { transform: translateY(16px); opacity: 0; }
  to { transform: translateY(0); opacity: 1; }
}

.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(5,7,10,0.6);
  backdrop-filter: blur(6px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 9000;
  padding: 20px;
  animation: fade-in 0.18s ease-out;
}
.modal {
  background: var(--bg-surface);
  border: 1px solid var(--border-bright);
  border-radius: var(--radius-lg);
  padding: 28px;
  max-width: 480px;
  width: 100%;
  box-shadow: var(--shadow-deep);
  animation: modal-in 0.22s ease-out;
}
.modal h2 {
  font-family: var(--font-display);
  font-weight: 600;
  font-size: 22px;
  letter-spacing: -0.02em;
  margin: 0 0 10px;
}

/* =========================================================
   Big result modal — for scored tool outcomes
   ========================================================= */
.result-modal {
  max-width: 560px;
  text-align: center;
  padding: 36px 32px;
}
.result-modal .rm-icon {
  font-size: 56px;
  line-height: 1;
  margin-bottom: 12px;
}
.result-modal .rm-title {
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 28px;
  letter-spacing: -0.02em;
  margin: 0 0 8px;
  color: var(--text-primary);
}
.result-modal .rm-score {
  font-family: var(--font-mono);
  font-size: 48px;
  font-weight: 600;
  color: var(--accent-bright);
  margin: 10px 0 6px;
  letter-spacing: -0.03em;
}
.result-modal .rm-subtitle {
  color: var(--text-secondary);
  font-size: 14px;
  margin: 0 0 20px;
}
.result-modal .rm-body {
  text-align: left;
  background: var(--bg-base);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 16px 18px;
  font-family: var(--font-mono);
  font-size: 13px;
  line-height: 1.7;
  max-height: 280px;
  overflow-y: auto;
  margin: 0 0 20px;
  white-space: pre-wrap;
  word-break: break-word;
}
.result-modal .rm-body .ok  { color: var(--green-bright); }
.result-modal .rm-body .bad { color: var(--red-bright); text-decoration: line-through; opacity: 0.8; }
.result-modal .rm-body .mis { color: var(--accent-bright); background: var(--accent-subtle); padding: 0 3px; border-radius: 3px; }
.result-modal .actions { justify-content: center; margin-top: 0; }
.result-modal .actions .btn { min-width: 120px; }
.modal p { color: var(--text-secondary); margin: 0 0 18px; line-height: 1.55; }
.modal .actions { display: flex; gap: 10px; justify-content: flex-end; margin-top: 18px; }
@keyframes modal-in {
  from { transform: translateY(10px) scale(0.98); opacity: 0; }
  to { transform: none; opacity: 1; }
}
@keyframes fade-in {
  from { opacity: 0; }
  to { opacity: 1; }
}

/* Dropdown menu (context menus, overflow menus) */
.menu {
  position: absolute;
  background: var(--bg-raised-2);
  border: 1px solid var(--border-bright);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-deep);
  padding: 6px;
  z-index: 7000;
  min-width: 180px;
  animation: modal-in 0.14s ease-out;
}
.menu .item {
  padding: 8px 12px;
  font-size: 13px;
  color: var(--text-primary);
  border-radius: var(--radius-sm);
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 10px;
  user-select: none;
}
.menu .item:hover { background: var(--bg-raised); }
.menu .item.danger { color: var(--red-bright); }
.menu .item .ic { width: 16px; display: inline-flex; justify-content: center; }
.menu .sep { height: 1px; background: var(--border); margin: 4px 2px; }

/* Confetti canvas */
.confetti-canvas {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 8500;
}

/* Utility */
.hidden { display: none !important; }
.sr-only {
  position: absolute; width: 1px; height: 1px;
  padding: 0; margin: -1px; overflow: hidden;
  clip: rect(0,0,0,0); white-space: nowrap; border: 0;
}
.fade-in { animation: fade-in 0.25s ease-out; }
.screen-enter { animation: screen-enter 0.28s cubic-bezier(.22,.9,.33,1); }
@keyframes screen-enter {
  from { transform: translateY(8px); opacity: 0; }
  to { transform: none; opacity: 1; }
}
