/* ═══════════════════════════════════════════════════════════
   Hero ASL Communicator — Page Styles
   AAC-grade: large targets · high contrast · clean layout
═══════════════════════════════════════════════════════════ */

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

:root {
  --bg:        #06060f;
  --bg2:       #0d0d1a;
  --surface:   rgba(255,255,255,0.04);
  --surface2:  rgba(255,255,255,0.07);
  --border:    rgba(255,255,255,0.08);
  --blue:      #0071e3;
  --blue-l:    #5ab4ff;
  --green:     #30d158;
  --red:       #ff453a;
  --orange:    #ff9f0a;
  --yellow:    #ffd60a;
  --purple:    #bf5af2;
  --cyan:      #64d2ff;
  --gray:      #86868b;
  --gray2:     #48484a;
  --text:      #f5f5f7;
  --text2:     rgba(255,255,255,0.65);
  --text3:     rgba(255,255,255,0.35);
  --r-card:    14px;
  --r-btn:     10px;
  --nav-h:     56px;
}

html { color-scheme: dark; }

body.asl-body {
  background: var(--bg);
  color: var(--text);
  font-family: 'Inter', system-ui, sans-serif;
  font-size: 14px;
  min-height: 100dvh;
  overflow-x: hidden;
}

/* ── Nav ─────────────────────────────────────────────────── */
.nav {
  position: sticky; top: 0; z-index: 100;
  height: var(--nav-h);
  background: rgba(6,6,15,0.92);
  backdrop-filter: blur(20px);
  border-bottom: 1px solid var(--border);
  display: flex; align-items: center;
  padding: 0 20px; gap: 16px;
}
.nav-back {
  display: flex; align-items: center; gap: 8px;
  text-decoration: none; color: var(--text2);
  font-size: 13px; font-weight: 500;
  transition: color 0.2s;
}
.nav-back:hover { color: var(--text); }
.nav-center { flex: 1; display: flex; align-items: center; justify-content: center; gap: 10px; }
.nav-title { font-family: 'Syne', sans-serif; font-weight: 700; font-size: 15px; }
.nav-badge {
  font-size: 10px; font-weight: 700; letter-spacing: 0.08em;
  background: rgba(0,113,227,0.2); border: 1px solid rgba(0,113,227,0.45);
  color: var(--blue-l); padding: 2px 8px; border-radius: 20px;
}
.nav-right { display: flex; align-items: center; gap: 12px; }
.cam-status-dot {
  font-size: 11px; font-weight: 500; color: var(--gray);
  transition: color 0.3s;
}
.cam-status-dot.ready { color: var(--green); }
.cam-status-dot.error { color: var(--red); }
.settings-btn {
  background: var(--surface); border: 1px solid var(--border);
  color: var(--text2); border-radius: 8px;
  width: 32px; height: 32px; display: flex; align-items: center; justify-content: center;
  cursor: pointer; transition: background 0.2s, color 0.2s;
}
.settings-btn:hover { background: var(--surface2); color: var(--text); }

/* ── Main layout ─────────────────────────────────────────── */
.asl-main {
  display: grid;
  grid-template-columns: 360px 1fr;
  gap: 0;
  height: calc(100dvh - var(--nav-h));
  overflow: hidden;
}

/* ── Camera panel ────────────────────────────────────────── */
.cam-panel {
  background: var(--bg2);
  border-right: 1px solid var(--border);
  overflow-y: auto;
  display: flex; flex-direction: column; gap: 12px;
  padding: 14px;
}

.viewport-wrap {
  position: relative;
  width: 100%;
  aspect-ratio: 4/3;
  background: #000;
  border-radius: var(--r-card);
  overflow: hidden;
  border: 1px solid var(--border);
  flex-shrink: 0;
}
.viewport-wrap video {
  position: absolute; inset: 0;
  width: 100%; height: 100%;
  object-fit: cover;
  transform: scaleX(-1);
}
.viewport-wrap canvas {
  position: absolute; inset: 0;
  width: 100%; height: 100%;
}
.no-cam {
  position: absolute; inset: 0;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 8px; color: var(--gray); font-size: 13px;
  background: rgba(0,0,0,0.7);
}
.no-cam-icon { font-size: 32px; }

/* ── Detection card ──────────────────────────────────────── */
.det-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-card);
  padding: 14px;
  display: flex; flex-direction: column; gap: 10px;
}
.det-header { display: flex; align-items: center; justify-content: space-between; }
.det-label { font-size: 11px; font-weight: 600; text-transform: uppercase; letter-spacing: 0.07em; color: var(--text3); }
.det-header-right { display: flex; align-items: center; gap: 6px; }
.num-mode-btn {
  font-size: 10px; font-weight: 700; letter-spacing: 0.04em;
  padding: 2px 8px; border-radius: 16px; cursor: pointer;
  background: var(--surface); border: 1px solid var(--border);
  color: var(--text3); transition: all 0.2s;
}
.num-mode-btn:hover { color: var(--text2); border-color: rgba(255,214,10,0.4); }
.num-mode-btn--active {
  background: rgba(255,214,10,0.12); border-color: rgba(255,214,10,0.5);
  color: var(--yellow);
}
.det-mode-badge {
  font-size: 10px; font-weight: 700; letter-spacing: 0.06em;
  border: 1px solid rgba(0,200,255,0.3);
  background: rgba(0,200,255,0.08); color: var(--cyan);
  padding: 2px 8px; border-radius: 20px;
}
.det-letter-row { display: flex; align-items: center; gap: 14px; }
.det-letter {
  font-family: 'Syne', sans-serif; font-weight: 800;
  font-size: 80px; line-height: 1;
  color: rgba(255,255,255,0.2);
  transition: color 0.15s, text-shadow 0.2s;
  min-width: 80px; text-align: center;
  user-select: none;
}
.det-meta { flex: 1; display: flex; flex-direction: column; gap: 6px; }
.conf-row { display: flex; align-items: center; gap: 8px; }
.conf-track {
  flex: 1; height: 4px; border-radius: 2px;
  background: rgba(255,255,255,0.08);
  overflow: hidden;
}
.conf-fill {
  height: 100%; border-radius: 2px;
  background: var(--blue-l);
  width: 0%; transition: width 0.15s, background 0.2s;
}
.conf-pct { font-size: 11px; font-weight: 600; color: var(--text2); min-width: 32px; text-align: right; }
.det-name { font-size: 12px; color: var(--text3); line-height: 1.3; }

/* Hold progress */
.hold-row { display: flex; align-items: center; gap: 10px; }
.hold-track {
  flex: 1; height: 3px; border-radius: 2px;
  background: rgba(255,255,255,0.06); overflow: hidden;
}
.hold-bar {
  height: 100%; border-radius: 2px;
  background: var(--blue);
  width: 0%; transition: width 0.05s linear, background 0.2s;
}
.hold-bar.done { background: var(--green); }
.hold-label { font-size: 10px; color: var(--text3); white-space: nowrap; }

/* Dynamic word badge */
.dynamic-badge {
  display: flex; align-items: center; gap: 8px;
  background: rgba(48,209,88,0.12); border: 1px solid rgba(48,209,88,0.3);
  border-radius: 10px; padding: 8px 12px;
  animation: fadeInUp 0.3s ease;
}
@keyframes fadeInUp { from { opacity:0; transform:translateY(6px); } to { opacity:1; transform:none; } }
.dyn-icon { font-size: 18px; }
.dyn-word { font-weight: 700; font-size: 14px; color: var(--green); letter-spacing: 0.02em; }

/* ── Shortcuts card ──────────────────────────────────────── */
.shortcuts-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-card);
  padding: 12px;
  display: flex; flex-direction: column; gap: 6px;
}
.sc-row { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.sc-key { font-size: 11px; font-weight: 500; color: var(--text2); }
.sc-val { font-size: 11px; color: var(--text3); }

/* ── Communication panel ─────────────────────────────────── */
.comm-panel {
  display: flex; flex-direction: column; gap: 12px;
  overflow-y: auto;
  padding: 14px;
}

/* ── Card base ───────────────────────────────────────────── */
.word-card, .sugg-card, .msg-card, .phrases-card, .history-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-card);
  padding: 14px;
}
.card-label { font-size: 11px; font-weight: 600; text-transform: uppercase; letter-spacing: 0.07em; color: var(--text3); }

/* ── Word card ───────────────────────────────────────────── */
.word-card-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 10px; flex-wrap: wrap; gap: 8px; }
.word-btns { display: flex; gap: 6px; }
.wb-btn {
  padding: 5px 11px; border-radius: 7px; font-size: 12px; font-weight: 500;
  background: var(--surface2); border: 1px solid var(--border);
  color: var(--text2); cursor: pointer; transition: background 0.2s, color 0.2s;
  white-space: nowrap;
}
.wb-btn:hover { background: rgba(255,255,255,0.12); color: var(--text); }
.wb-btn--danger { color: #ff6961; border-color: rgba(255,69,58,0.3); }
.wb-btn--danger:hover { background: rgba(255,69,58,0.15); color: var(--red); }

.word-display {
  font-family: 'Syne', monospace; font-size: 32px; font-weight: 700;
  letter-spacing: 0.12em; color: var(--text);
  min-height: 46px; line-height: 1;
  display: flex; align-items: baseline; gap: 2px;
}
.word-text { color: var(--blue-l); }
.word-cursor {
  color: var(--cyan); font-weight: 300;
  animation: blink 1.1s step-end infinite;
}
@keyframes blink { 0%,100%{opacity:1} 50%{opacity:0} }
.word-placeholder { font-size: 12px; color: var(--text3); margin-top: 6px; line-height: 1.4; }

.letter-trail { display: flex; flex-wrap: wrap; gap: 4px; margin-top: 8px; min-height: 24px; }
.lt-pill {
  font-family: 'Syne', monospace; font-size: 13px; font-weight: 700; letter-spacing: 0.05em;
  background: rgba(0,113,227,0.15); border: 1px solid rgba(0,113,227,0.3);
  color: var(--blue-l); padding: 2px 7px; border-radius: 6px;
}

/* ── Suggestions ─────────────────────────────────────────── */
.sugg-card { display: flex; flex-direction: column; gap: 8px; }
.sugg-row {
  display: flex; flex-wrap: wrap; gap: 6px; min-height: 32px;
  align-items: flex-start;
}
.sugg-idle { font-size: 12px; color: var(--text3); align-self: center; }
.sugg-chip {
  padding: 6px 14px; border-radius: 20px; font-size: 13px; font-weight: 500;
  background: rgba(255,255,255,0.06); border: 1px solid rgba(255,255,255,0.12);
  color: var(--text2); cursor: pointer;
  transition: background 0.15s, color 0.15s, border-color 0.15s;
}
.sugg-chip:hover { background: rgba(0,113,227,0.2); border-color: rgba(0,113,227,0.5); color: var(--blue-l); }
.sugg-chip.top-pick {
  background: rgba(0,113,227,0.15); border-color: rgba(0,113,227,0.4); color: var(--blue-l);
}

/* ── Message card ────────────────────────────────────────── */
.msg-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 10px; }
.word-count { font-size: 11px; color: var(--text3); font-variant-numeric: tabular-nums; }
.msg-output {
  font-size: 20px; font-weight: 500; line-height: 1.5;
  color: var(--text); min-height: 60px; word-break: break-word;
}
.msg-placeholder { font-size: 13px; color: var(--text3); line-height: 1.5; }

/* ── Output row ──────────────────────────────────────────── */
.output-row { display: grid; grid-template-columns: 1fr 1fr 1fr 1fr; gap: 8px; }
.out-btn {
  padding: 10px 6px; border-radius: var(--r-btn); font-size: 12px; font-weight: 600;
  background: var(--surface); border: 1px solid var(--border);
  color: var(--text2); cursor: pointer;
  transition: background 0.2s, color 0.2s, border-color 0.2s;
  white-space: nowrap; text-align: center;
}
.out-btn:hover:not(:disabled) { background: var(--surface2); color: var(--text); }
.out-btn:disabled { opacity: 0.35; cursor: not-allowed; }
.out-btn--speak {
  background: rgba(48,209,88,0.12); border-color: rgba(48,209,88,0.3); color: var(--green);
}
.out-btn--speak:hover:not(:disabled) { background: rgba(48,209,88,0.22); }
.out-btn--clear {
  background: rgba(255,69,58,0.08); border-color: rgba(255,69,58,0.2); color: #ff6961;
}
.out-btn--clear:hover:not(:disabled) { background: rgba(255,69,58,0.18); }

/* ── Quick phrases ───────────────────────────────────────── */
.phrases-card { display: flex; flex-direction: column; gap: 10px; }
.phrases-grid {
  display: grid; grid-template-columns: repeat(2, 1fr); gap: 7px;
}
.phrase-btn {
  display: flex; align-items: center; gap: 8px;
  padding: 9px 12px; border-radius: 10px;
  background: rgba(255,255,255,0.04);
  border: 1px solid var(--border);
  color: var(--text2); cursor: pointer; text-align: left;
  transition: background 0.15s, border-color 0.15s, color 0.15s;
}
.phrase-btn:hover {
  background: rgba(var(--ph-color-rgb, 255,255,255), 0.08);
  border-color: rgba(255,255,255,0.16);
  color: var(--text);
}
.ph-icon { font-size: 16px; flex-shrink: 0; }
.ph-text { font-size: 12px; font-weight: 500; line-height: 1.3; }
.phrase-btn.urgent { border-color: rgba(255,69,58,0.25); }
.phrase-btn.urgent .ph-text { color: #ff8a82; }

/* ── History card ────────────────────────────────────────── */
.history-card { display: flex; flex-direction: column; gap: 8px; }
.history-list { display: flex; flex-direction: column; gap: 6px; }
.hist-item {
  display: flex; align-items: center; justify-content: space-between; gap: 8px;
  background: var(--surface2); border-radius: 8px; padding: 8px 10px;
}
.hist-text { font-size: 13px; color: var(--text2); flex: 1; word-break: break-word; }
.hist-speak {
  background: none; border: none; cursor: pointer; font-size: 14px;
  padding: 4px; border-radius: 6px; flex-shrink: 0;
  color: var(--text3); transition: color 0.2s;
}
.hist-speak:hover { color: var(--green); }

/* ── Settings overlay ────────────────────────────────────── */
.settings-overlay {
  position: fixed; inset: 0; z-index: 200;
  background: rgba(0,0,0,0.6); backdrop-filter: blur(6px);
  display: flex; align-items: center; justify-content: center;
  padding: 20px;
}
.settings-overlay[hidden] { display: none; }
.settings-panel {
  background: #12121f; border: 1px solid var(--border);
  border-radius: 18px; width: 100%; max-width: 420px;
  overflow: hidden;
}
.settings-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
}
.settings-title { font-family: 'Syne', sans-serif; font-weight: 700; font-size: 15px; }
.settings-close {
  background: var(--surface); border: 1px solid var(--border);
  color: var(--text2); width: 28px; height: 28px; border-radius: 7px;
  cursor: pointer; font-size: 12px; transition: background 0.2s;
}
.settings-close:hover { background: var(--surface2); color: var(--text); }
.settings-body { padding: 16px 20px; display: flex; flex-direction: column; gap: 18px; }
.sett-group { display: flex; flex-direction: column; gap: 8px; }
.sett-label { font-size: 12px; font-weight: 500; color: var(--text2); }
.sett-label strong { color: var(--text); }
.hand-toggle { display: flex; gap: 6px; }
.hand-btn {
  flex: 1; padding: 7px; border-radius: 8px; font-size: 12px; font-weight: 600;
  background: var(--surface); border: 1px solid var(--border);
  color: var(--text3); cursor: pointer; transition: all 0.2s;
}
.hand-btn--active, .hand-btn.active {
  background: rgba(0,113,227,0.2); border-color: rgba(0,113,227,0.5); color: var(--blue-l);
}
.sett-range { width: 100%; accent-color: var(--blue); }
.voice-select {
  background: var(--surface); border: 1px solid var(--border);
  color: var(--text2); border-radius: 8px; padding: 7px 10px;
  font-size: 12px; width: 100%; outline: none;
}
.test-voice-btn {
  padding: 9px; border-radius: 8px; font-size: 12px; font-weight: 600;
  background: rgba(48,209,88,0.12); border: 1px solid rgba(48,209,88,0.3);
  color: var(--green); cursor: pointer; transition: background 0.2s;
}
.test-voice-btn:hover { background: rgba(48,209,88,0.22); }
.toggle-wrap { display: flex; align-items: center; cursor: pointer; }
.toggle-wrap input { display: none; }
.toggle-slider {
  width: 40px; height: 22px; background: var(--gray2);
  border-radius: 11px; position: relative; transition: background 0.2s;
}
.toggle-slider::after {
  content:''; position:absolute; top:3px; left:3px;
  width:16px; height:16px; background:#fff;
  border-radius: 50%; transition: transform 0.2s;
}
.toggle-wrap input:checked + .toggle-slider { background: var(--green); }
.toggle-wrap input:checked + .toggle-slider::after { transform: translateX(18px); }

/* ── FPS badge ───────────────────────────────────────────── */
.fps-badge {
  font-size: 11px; font-weight: 600; font-variant-numeric: tabular-nums;
  color: var(--gray); background: var(--surface);
  border: 1px solid var(--border);
  padding: 2px 8px; border-radius: 20px; min-width: 58px; text-align: center;
  transition: color 0.3s, border-color 0.3s;
}
.fps-badge.fps-good { color: var(--green); border-color: rgba(48,209,88,0.3); }
.fps-badge.fps-ok   { color: var(--yellow); border-color: rgba(255,214,10,0.3); }
.fps-badge.fps-bad  { color: var(--red); border-color: rgba(255,69,58,0.3); }

/* ── Top-3 candidate row ─────────────────────────────────── */
.top3-row {
  display: flex; flex-direction: column; gap: 5px;
  margin-top: 2px; min-height: 0;
}
.top3-item {
  display: grid; grid-template-columns: 32px 1fr 32px;
  align-items: center; gap: 7px;
  padding: 4px 6px; border-radius: 7px;
  background: rgba(255,255,255,0.03);
  border: 1px solid transparent;
  transition: border-color 0.2s;
}
.top3-item--lead {
  background: rgba(255,255,255,0.05);
  border-color: rgba(255,255,255,0.08);
}
.top3-letter {
  font-family: 'Syne', sans-serif; font-weight: 800; font-size: 15px;
  color: var(--c, #fff); text-align: center;
}
.top3-bar-wrap {
  height: 4px; background: rgba(255,255,255,0.07); border-radius: 2px; overflow: hidden;
}
.top3-bar { height: 100%; border-radius: 2px; transition: width 0.12s linear; }
.top3-pct { font-size: 10px; font-weight: 600; color: var(--text3); text-align: right; }

/* ── Next-word row ───────────────────────────────────────── */
.nextword-row {
  display: flex; flex-wrap: wrap; align-items: center;
  gap: 5px; margin-top: 8px; min-height: 0;
}
.nw-label {
  font-size: 10px; font-weight: 600; text-transform: uppercase;
  letter-spacing: 0.07em; color: var(--text3); flex-shrink: 0;
}
.nw-chip {
  padding: 4px 11px; border-radius: 16px; font-size: 12px; font-weight: 500;
  background: rgba(48,209,88,0.08); border: 1px solid rgba(48,209,88,0.2);
  color: var(--green); cursor: pointer;
  transition: background 0.15s, border-color 0.15s;
}
.nw-chip:hover { background: rgba(48,209,88,0.18); border-color: rgba(48,209,88,0.45); }

/* ── Calibration badge ───────────────────────────────────── */
.cal-badge {
  display: inline-block;
  font-size: 10px; font-weight: 600; letter-spacing: 0.05em;
  background: var(--surface); border: 1px solid var(--border);
  color: var(--gray); padding: 2px 7px; border-radius: 14px;
  margin-left: 6px; vertical-align: middle;
  transition: color 0.2s, border-color 0.2s, background 0.2s;
}
.cal-badge--active {
  color: var(--green); background: rgba(48,209,88,0.1);
  border-color: rgba(48,209,88,0.3);
}

/* ── Settings divider + train buttons ────────────────────── */
.sett-divider {
  height: 1px; background: var(--border); margin: 2px 0;
}
.train-btns { display: flex; flex-direction: column; gap: 6px; }
.train-btn {
  padding: 8px 12px; border-radius: 8px; font-size: 12px; font-weight: 600;
  background: var(--surface); border: 1px solid var(--border);
  color: var(--text2); cursor: pointer; text-align: left;
  transition: background 0.2s, color 0.2s;
}
.train-btn:hover { background: rgba(0,113,227,0.15); border-color: rgba(0,113,227,0.4); color: var(--blue-l); }
.train-btn--danger { color: #ff6961; border-color: rgba(255,69,58,0.25); }
.train-btn--danger:hover { background: rgba(255,69,58,0.15); color: var(--red); border-color: rgba(255,69,58,0.5); }

/* ── Training overlay ────────────────────────────────────── */
.train-overlay {
  position: fixed; inset: 0; z-index: 250;
  background: rgba(0,0,0,0.75); backdrop-filter: blur(8px);
  display: flex; align-items: center; justify-content: center;
  padding: 20px;
}
.train-overlay[hidden] { display: none; }
.train-panel {
  background: #12121f; border: 1px solid var(--border);
  border-radius: 20px; width: 100%; max-width: 380px;
  overflow: hidden;
}
.train-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 16px 20px; border-bottom: 1px solid var(--border);
}
.train-title { font-family: 'Syne', sans-serif; font-weight: 700; font-size: 15px; }
.train-body {
  padding: 28px 24px; display: flex; flex-direction: column; gap: 16px;
  align-items: center; text-align: center;
}
.train-sign-big {
  font-family: 'Syne', sans-serif; font-weight: 800; font-size: 100px; line-height: 1;
  transition: color 0.2s;
}
.train-ref-text {
  font-size: 13px; color: var(--text2); line-height: 1.5;
  min-height: 38px;
}
.train-status-text {
  font-size: 14px; font-weight: 600; color: var(--text);
  min-height: 22px;
}
.train-bar-wrap {
  width: 100%; height: 6px; background: rgba(255,255,255,0.07);
  border-radius: 3px; overflow: hidden;
}
.train-bar {
  height: 100%; background: var(--blue); border-radius: 3px;
  width: 0%; transition: width 0.1s linear, background 0.2s;
}
.train-actions { display: flex; gap: 8px; flex-wrap: wrap; justify-content: center; }
.train-action-btn {
  padding: 9px 20px; border-radius: 10px; font-size: 13px; font-weight: 600;
  background: var(--surface); border: 1px solid var(--border);
  color: var(--text2); cursor: pointer; transition: background 0.2s, color 0.2s;
}
.train-action-btn:hover { background: var(--surface2); color: var(--text); }
.train-action-btn--accept {
  background: rgba(48,209,88,0.15); border-color: rgba(48,209,88,0.35); color: var(--green);
}
.train-action-btn--accept:hover { background: rgba(48,209,88,0.25); }
.train-action-btn--skip { color: var(--text3); }

/* ── Toast ───────────────────────────────────────────────── */
.toast-el {
  position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%);
  background: rgba(30,30,50,0.95); border: 1px solid var(--border);
  color: var(--text); padding: 10px 20px; border-radius: 24px;
  font-size: 13px; font-weight: 500; pointer-events: none;
  transition: opacity 0.3s; z-index: 300; white-space: nowrap;
}

/* ── Responsive: collapse to single column on mobile ─────── */
@media (max-width: 768px) {
  .asl-main {
    grid-template-columns: 1fr;
    height: auto;
    overflow: visible;
  }
  .cam-panel {
    border-right: none;
    border-bottom: 1px solid var(--border);
    position: static;
  }
  .output-row { grid-template-columns: 1fr 1fr; }
  .phrases-grid { grid-template-columns: 1fr; }
  .det-letter { font-size: 60px; }
  .word-display { font-size: 24px; }
}
