/* ==========================================================================
   Luck Wave Detector — styles.css
   Layout, components, tier colours, and the red-light alert animation.
   No CSS framework. Desktop-first with basic mobile fallback.
   ========================================================================== */

:root {
  --bg: #0f172a;
  --bg-elev: #1e293b;
  --bg-elev-2: #273449;
  --text: #e2e8f0;
  --text-dim: #94a3b8;
  --border: #334155;
  --accent: #60a5fa;
  --danger: #ef4444;
  --warn: #f59e0b;
  --good: #22c55e;
  --radius: 10px;
  --gap: 14px;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: system-ui, -apple-system, "Segoe UI", "Microsoft YaHei", sans-serif;
  font-size: 14px;
  min-height: 100vh;
}

/* ---- Red-light alert overlay (heat-driven, continuous) ------------------- */
/* A full-viewport red vignette whose state is driven by the heat state
   machine (body adds is-hot / is-watch on the overlay). hot = continuous
   pulsing glow (infinite, not one-shot) so the alert persists while the
   recent stretch is genuinely hot; watch = subtle steady dim; normal = off.
   The hysteresis in detector.resolveHeatStatus prevents status thrashing,
   and the animation is gentle to avoid being seizure-inducing. */
.red-light-overlay {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 50;
  box-shadow: inset 0 0 120px 30px rgba(239, 68, 68, 0);
  transition: box-shadow 0.4s ease;
}
.red-light-overlay.is-watch {
  box-shadow: inset 0 0 90px 20px rgba(245, 158, 11, 0.18);
}
.red-light-overlay.is-hot {
  animation: red-pulse 1.8s ease-in-out infinite;
}
@keyframes red-pulse {
  0%, 100% { box-shadow: inset 0 0 110px 26px rgba(239, 68, 68, 0.30); }
  50%      { box-shadow: inset 0 0 190px 55px rgba(239, 68, 68, 0.55); }
}

/* ---- Header -------------------------------------------------------------- */
.app-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 20px;
  background: linear-gradient(180deg, var(--bg-elev), var(--bg));
  border-bottom: 1px solid var(--border);
}
.header-left { display: flex; align-items: center; gap: 12px; }
.header-left h1 { font-size: 18px; margin: 0; }
.subtitle { margin: 0; color: var(--text-dim); font-size: 12px; }
.header-right { display: flex; align-items: center; gap: 16px; }

.status-badge {
  padding: 4px 12px;
  border-radius: 999px;
  font-size: 12px;
  border: 1px solid var(--border);
  background: var(--bg-elev-2);
}
.status-badge.normal { color: var(--text-dim); }
.status-badge.watch { color: var(--warn); border-color: var(--warn); }
.status-badge.hot {
  color: #fff;
  background: var(--danger);
  border-color: var(--danger);
  animation: badge-blink 0.8s ease-in-out infinite alternate;
}
.status-badge.cooldown { color: var(--warn); border-color: var(--warn); }
@keyframes badge-blink { from { opacity: 0.6; } to { opacity: 1; } }

.switch { display: flex; align-items: center; gap: 6px; font-size: 12px; color: var(--text-dim); }

/* ---- Disclaimer ---------------------------------------------------------- */
.disclaimer {
  margin: 0;
  padding: 8px 20px;
  background: #3b1d1d;
  color: #fecaca;
  font-size: 12px;
  border-bottom: 1px solid #5b2424;
  text-align: center;
}

/* ---- Layout -------------------------------------------------------------- */
.layout {
  display: grid;
  grid-template-columns: 320px 1fr 300px;
  gap: var(--gap);
  padding: var(--gap);
  align-items: start;
}
.panel-col, .main-col, .stats-col { display: flex; flex-direction: column; gap: var(--gap); }

.card {
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
}
.card > summary {
  cursor: pointer;
  padding: 10px 14px;
  font-weight: 600;
  background: var(--bg-elev-2);
  border-bottom: 1px solid var(--border);
}
.card-body { padding: 12px 14px; }

/* ---- Forms --------------------------------------------------------------- */
.row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 8px;
}
.row label { color: var(--text-dim); font-size: 12px; flex: 0 0 auto; }
.row input[type="text"],
.row input[type="number"] {
  flex: 1;
  background: var(--bg);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: 6px;
  padding: 5px 8px;
  font-size: 13px;
  min-width: 0;
}
.checkbox-row { justify-content: flex-start; gap: 16px; }
.checkbox-row label { display: flex; align-items: center; gap: 4px; color: var(--text); }

.tier-editor { display: flex; flex-direction: column; gap: 6px; max-height: 280px; overflow-y: auto; }
.tier-row {
  display: grid;
  grid-template-columns: 18px 14px 1fr 52px 52px 36px 22px;
  align-items: center;
  gap: 4px;
  font-size: 12px;
}
.tier-row .swatch { width: 14px; height: 14px; border-radius: 3px; border: 1px solid var(--border); }
.tier-row input { background: var(--bg); border: 1px solid var(--border); color: var(--text); border-radius: 4px; padding: 3px 5px; font-size: 12px; width: 100%; }
.tier-row .del { color: var(--danger); cursor: pointer; background: none; border: none; font-size: 14px; }

.button-row { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 10px; }
.sub-section-title { margin: 12px 0 6px; font-size: 12px; color: var(--text-dim); border-bottom: 1px solid var(--border); padding-bottom: 3px; }

/* ---- Template management -------------------------------------------------- */
.template-select {
  flex: 1;
  background: var(--bg);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: 6px;
  padding: 5px 8px;
  font-size: 13px;
  min-width: 0;
}
.template-hint { margin: 8px 0 0; color: var(--text-dim); font-size: 11px; line-height: 1.4; }
.template-select optgroup { color: var(--text-dim); font-style: normal; }

/* ---- Buttons ------------------------------------------------------------- */
.btn {
  cursor: pointer;
  border: 1px solid var(--border);
  background: var(--bg-elev-2);
  color: var(--text);
  padding: 7px 12px;
  border-radius: 6px;
  font-size: 13px;
  transition: background 0.15s, border-color 0.15s, box-shadow 0.15s;
}
.btn:hover { background: #334564; }
.btn:disabled { opacity: 0.45; cursor: not-allowed; }
.btn-primary { background: var(--accent); color: #0b1220; border-color: var(--accent); font-weight: 600; }
.btn-primary:hover { background: #7cb6ff; }
.btn-secondary { background: #475569; }
.btn-danger { background: #7f1d1d; border-color: #991b1b; }
.btn-draw { background: #1d4ed8; border-color: #1e40af; font-weight: 600; }
.btn-draw:hover { background: #2563eb; }

/* Hot highlight on draw buttons during a hot heat state */
.btn-draw.hot {
  background: var(--danger);
  border-color: #b91c1c;
  box-shadow: 0 0 0 2px rgba(239, 68, 68, 0.4);
  animation: btn-glow 1.2s ease-in-out infinite alternate;
}
/* Watch state: subtle amber highlight, no strong flashing */
.btn-draw.watch {
  background: #b45309;
  border-color: #92400e;
  box-shadow: 0 0 0 2px rgba(245, 158, 11, 0.25);
}
@keyframes btn-glow { from { box-shadow: 0 0 0 2px rgba(239,68,68,0.25); } to { box-shadow: 0 0 0 5px rgba(239,68,68,0.55); } }

.draw-buttons { display: flex; gap: 8px; flex-wrap: wrap; }

/* ---- Current result & recent strip -------------------------------------- */
.current-result, .recent-strip-wrap {
  margin-top: 12px;
  display: flex;
  align-items: center;
  gap: 8px;
}
.label { color: var(--text-dim); font-size: 12px; flex: 0 0 auto; }
.result-pill {
  padding: 4px 12px;
  border-radius: 999px;
  font-weight: 600;
  border: 1px solid var(--border);
}
.result-pill.placeholder { color: var(--text-dim); }
.recent-strip {
  display: flex;
  gap: 3px;
  flex-wrap: wrap;
  align-content: center;
}
.recent-chip {
  width: 16px;
  height: 16px;
  border-radius: 3px;
  border: 1px solid rgba(255, 255, 255, 0.15);
}

/* ---- Chart --------------------------------------------------------------- */
.chart-card .card-body { padding: 8px; }
.chart { width: 100%; height: 320px; }

/* ---- Stats --------------------------------------------------------------- */
.stats-col h2 { margin: 0 0 8px; font-size: 15px; }
.stats-col h3 { margin: 14px 0 6px; font-size: 13px; color: var(--text-dim); }
.stat-list { list-style: none; padding: 0; margin: 0; display: grid; grid-template-columns: 1fr; gap: 4px; font-size: 12px; }
.stat-list li { display: flex; justify-content: space-between; color: var(--text-dim); border-bottom: 1px dashed var(--border); padding-bottom: 3px; }
.stat-list b { color: var(--text); font-weight: 600; }

.tier-table { width: 100%; border-collapse: collapse; font-size: 12px; }
.tier-table th, .tier-table td { text-align: left; padding: 4px 6px; border-bottom: 1px solid var(--border); }
.tier-table th { color: var(--text-dim); font-weight: 500; }
.tier-dot { display: inline-block; width: 10px; height: 10px; border-radius: 2px; margin-right: 5px; vertical-align: middle; }

/* ---- Footer & toast ------------------------------------------------------ */
.app-footer {
  padding: 12px 20px;
  text-align: center;
  color: var(--text-dim);
  border-top: 1px solid var(--border);
}
.toast {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%) translateY(20px);
  background: var(--bg-elev-2);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 8px 16px;
  border-radius: 8px;
  font-size: 13px;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.25s, transform 0.25s;
  z-index: 100;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

/* ---- Responsive (basic mobile fallback) --------------------------------- */
@media (max-width: 980px) {
  .layout { grid-template-columns: 1fr; }
  .chart { height: 240px; }
}

/* ==========================================================================
   Mini Mode (?view=mini) — giant status button, no ECharts
   ========================================================================== */

.hidden { display: none !important; }

/* Entry button in full-mode header */
.mini-entry { font-size: 12px; padding: 5px 10px; }

.is-mini-mode { min-height: 100dvh; overflow: hidden; }

.mini-mode {
  min-height: 100dvh;
  padding: 16px;
  display: grid;
  place-items: center;
  background:
    radial-gradient(circle at top, rgba(59, 130, 246, 0.16), transparent 38%),
    #0f172a;
  color: #e5e7eb;
}

.mini-card {
  width: min(100%, 420px);
  border: 1px solid rgba(148, 163, 184, 0.25);
  border-radius: 24px;
  padding: 18px;
  background: rgba(15, 23, 42, 0.94);
  box-shadow: 0 24px 80px rgba(0, 0, 0, 0.35);
}

.mini-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 14px;
}
.mini-title { font-size: 16px; font-weight: 700; }
.mini-run-state { font-size: 12px; color: #93c5fd; }

/* Giant status button — perception only, never a draw trigger */
.mini-status-button {
  width: 100%;
  min-height: 190px;
  border: 0;
  border-radius: 28px;
  padding: 22px;
  display: grid;
  place-items: center;
  gap: 8px;
  color: #fff;
  text-align: center;
  cursor: default;
  transition: transform 160ms ease, filter 160ms ease, box-shadow 160ms ease;
}
.mini-status-text { font-size: clamp(28px, 9vw, 44px); font-weight: 900; letter-spacing: 0.04em; }
.mini-heat-value { font-size: clamp(34px, 11vw, 58px); line-height: 1; }
.mini-status-hint { font-size: 14px; opacity: 0.82; }

.mini-status-button.is-idle {
  background: linear-gradient(135deg, #1f2937, #111827);
  box-shadow: inset 0 0 0 1px rgba(148, 163, 184, 0.18);
}
.mini-status-button.is-normal {
  background: linear-gradient(135deg, #1e293b, #0f172a);
  box-shadow: inset 0 0 0 1px rgba(148, 163, 184, 0.2);
}
.mini-status-button.is-watch {
  background: linear-gradient(135deg, #92400e, #451a03);
  animation: miniWatchBreath 1.4s ease-in-out infinite;
}
.mini-status-button.is-hot {
  background: linear-gradient(135deg, #dc2626, #7f1d1d);
  animation: miniHotPulse 0.7s ease-in-out infinite;
}

@keyframes miniWatchBreath {
  0%, 100% { transform: scale(1); filter: brightness(1); box-shadow: 0 0 18px rgba(251, 146, 60, 0.28); }
  50%      { transform: scale(1.018); filter: brightness(1.18); box-shadow: 0 0 34px rgba(251, 146, 60, 0.55); }
}
@keyframes miniHotPulse {
  0%, 100% { transform: scale(1); filter: brightness(1); box-shadow: 0 0 20px rgba(239, 68, 68, 0.42); }
  50%      { transform: scale(1.035); filter: brightness(1.28); box-shadow: 0 0 54px rgba(239, 68, 68, 0.95); }
}

@media (prefers-reduced-motion: reduce) {
  .mini-status-button { animation: none !important; }
}

/* Metrics row */
.mini-metrics {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
  margin: 14px 0;
}
.mini-metric {
  border: 1px solid rgba(148, 163, 184, 0.18);
  border-radius: 14px;
  padding: 10px;
  background: rgba(30, 41, 59, 0.7);
  text-align: center;
}
.mini-metric span { display: block; font-size: 12px; color: #94a3b8; margin-bottom: 4px; }
.mini-metric strong { font-size: 18px; }

.mini-last-result {
  min-height: 38px;
  padding: 10px;
  border-radius: 14px;
  background: rgba(15, 23, 42, 0.86);
  color: #cbd5e1;
  font-size: 14px;
}

.mini-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin-top: 14px;
}
.mini-actions button {
  min-height: 46px;
  border-radius: 14px;
  border: 0;
  font-weight: 700;
  cursor: pointer;
}
#miniToggleAutoBtn { background: #2563eb; color: #fff; }
#miniFullModeBtn { background: #334155; color: #e5e7eb; }

.mini-disclaimer {
  margin: 12px 0 0;
  color: #94a3b8;
  font-size: 11px;
  line-height: 1.5;
  text-align: center;
}
