/* lip-reader.css — Hero AAC Lip Reader */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg:       #000;
  --surface:  #0c0c0e;
  --surface2: #141416;
  --surface3: #1c1c1e;
  --border:   rgba(255,255,255,0.08);
  --border2:  rgba(255,255,255,0.14);
  --cyan:     #00c8ff;
  --purple:   #bf5af2;
  --green:    #30d158;
  --red:      #ff453a;
  --orange:   #ff9f0a;
  --yellow:   #ffd60a;
  --gray:     #86868b;
  --font:     'Inter', -apple-system, sans-serif;
}

html, body {
  height: 100%;
  background: var(--bg);
  color: #fff;
  font-family: var(--font);
  -webkit-font-smoothing: antialiased;
  overflow: hidden;
}

/* ── Nav ─────────────────────────────────────────────────────── */
.nav {
  display: flex;
  align-items: center;
  justify-content: space-between;
  height: 52px;
  padding: 0 18px;
  background: rgba(0,0,0,0.94);
  border-bottom: 1px solid var(--border);
  z-index: 100;
  position: relative;
  flex-shrink: 0;
}
.nav-back {
  display: flex; align-items: center; gap: 8px;
  text-decoration: none; color: rgba(255,255,255,0.65);
  font-size: 14px; font-weight: 500;
  transition: color 0.2s;
}
.nav-back:hover { color: #fff; }
.nav-center {
  display: flex; align-items: center; gap: 8px;
}
.nav-title {
  font-size: 14px; font-weight: 600; color: #fff;
}
.nav-badge {
  background: var(--green); color: #000;
  font-size: 9px; font-weight: 700; letter-spacing: 0.06em;
  padding: 2px 6px; border-radius: 4px;
}
.nav-right {
  display: flex; align-items: center; gap: 12px;
}
.status-dot {
  font-size: 11px; font-weight: 500; color: var(--gray);
}
.status-dot.ready  { color: var(--green); }
.status-dot.error  { color: var(--red); }
.settings-btn {
  background: rgba(255,255,255,0.06);
  border: 1px solid var(--border);
  border-radius: 8px;
  width: 32px; height: 32px;
  display: flex; align-items: center; justify-content: center;
  color: rgba(255,255,255,0.55); cursor: pointer;
  transition: background 0.15s, color 0.15s;
}
.settings-btn:hover { background: rgba(255,255,255,0.10); color: #fff; }

/* ── Settings panel ──────────────────────────────────────────── */
.settings-panel[hidden] { display: none !important; }
.settings-panel {
  position: fixed; inset: 52px 0 0 0; z-index: 90;
  background: rgba(0,0,0,0.88);
  backdrop-filter: blur(20px);
  display: flex; align-items: flex-start; justify-content: center;
  padding-top: 40px;
}
.settings-inner {
  background: var(--surface2);
  border: 1px solid var(--border2);
  border-radius: 16px;
  padding: 28px 32px;
  width: 380px;
  display: flex; flex-direction: column; gap: 20px;
}
.settings-title {
  font-size: 18px; font-weight: 700;
}
.setting-row {
  display: flex; flex-direction: column; gap: 8px;
}
.setting-row label {
  font-size: 13px; color: var(--gray); font-weight: 500;
  display: flex; justify-content: space-between;
}
.setting-select {
  background: var(--surface3); border: 1px solid var(--border2);
  border-radius: 8px; padding: 10px 12px;
  color: #fff; font-family: var(--font); font-size: 14px;
  cursor: pointer; width: 100%;
}
.setting-slider {
  width: 100%; accent-color: var(--cyan); cursor: pointer;
}
.btn-test-voice, .btn-close-settings {
  padding: 12px; border-radius: 10px;
  font-family: var(--font); font-size: 14px; font-weight: 600;
  cursor: pointer; border: none; transition: opacity 0.15s;
}
.btn-test-voice    { background: var(--surface3); color: rgba(255,255,255,0.8); border: 1px solid var(--border2); }
.btn-close-settings { background: var(--cyan); color: #000; }
.btn-test-voice:hover    { opacity: 0.8; }
.btn-close-settings:hover { opacity: 0.85; }

/* ── Main layout ─────────────────────────────────────────────── */
.layout {
  display: grid;
  grid-template-columns: 320px 1fr 300px;
  grid-template-rows: 1fr;
  height: calc(100vh - 52px);
  overflow: hidden;
  gap: 0;
}

/* ── Panel shared styles ─────────────────────────────────────── */
.panel-camera,
.panel-center,
.panel-wordbank {
  overflow-y: auto;
  overflow-x: hidden;
  scrollbar-width: thin;
  scrollbar-color: rgba(255,255,255,0.1) transparent;
}
.panel-camera   { border-right: 1px solid var(--border); background: var(--surface); padding: 12px; display: flex; flex-direction: column; gap: 10px; }
.panel-center   { background: var(--bg); padding: 14px 16px; display: flex; flex-direction: column; gap: 12px; }
.panel-wordbank { border-left: 1px solid var(--border); background: var(--surface); padding: 12px; display: flex; flex-direction: column; gap: 10px; }

.panel-label {
  font-size: 10px; font-weight: 600; letter-spacing: 0.10em;
  text-transform: uppercase; color: var(--gray);
}

/* ── Camera panel ────────────────────────────────────────────── */
.camera-header {
  display: flex; align-items: center; justify-content: space-between;
}
.viseme-live {
  font-size: 10px; font-weight: 600; color: var(--cyan); letter-spacing: 0.05em;
}
.viewport-wrap {
  position: relative; width: 100%; border-radius: 10px; overflow: hidden;
  background: #060606; border: 1px solid var(--border); flex-shrink: 0;
  aspect-ratio: 4/3;
}
.viewport-wrap video {
  width: 100%; height: 100%; object-fit: cover;
  transform: scaleX(-1); /* mirror */
  display: block;
}
.viewport-wrap canvas {
  position: absolute; inset: 0; width: 100%; height: 100%;
  transform: scaleX(-1);
}
.no-cam {
  position: absolute; inset: 0;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 10px; color: rgba(255,255,255,0.3); font-size: 13px;
  background: #060606;
}

/* Mouth zoom */
.mouth-zoom-wrap {
  position: relative;
  background: #060606; border: 1px solid var(--border); border-radius: 8px;
  overflow: hidden; flex-shrink: 0;
  height: 90px;
}
.mouth-zoom-label {
  position: absolute; top: 5px; left: 8px;
  font-size: 9px; color: rgba(255,255,255,0.35); letter-spacing: 0.06em; text-transform: uppercase;
  pointer-events: none; z-index: 2;
}
.mouth-zoom-wrap canvas {
  width: 100%; height: 100%; display: block; object-fit: contain;
}
.mouth-zoom-overlay {
  position: absolute; inset: 0;
  display: flex; align-items: center; justify-content: center;
  font-size: 11px; color: rgba(255,255,255,0.25);
  pointer-events: none;
}
.mouth-zoom-overlay.hidden { display: none; }

/* Viseme display */
.viseme-display {
  background: var(--surface2); border: 1px solid var(--border); border-radius: 10px;
  padding: 10px 12px; display: flex; flex-direction: column; gap: 8px;
}
.viseme-current {
  display: flex; align-items: center; gap: 12px;
}
.viseme-emoji {
  font-size: 36px; line-height: 1; flex-shrink: 0;
  filter: drop-shadow(0 0 8px rgba(255,255,255,0.2));
  transition: all 0.15s;
}
.viseme-info {
  display: flex; flex-direction: column; gap: 2px;
}
.viseme-label {
  font-size: 22px; font-weight: 700; line-height: 1;
  color: #fff; transition: color 0.15s;
}
.viseme-hint {
  font-size: 11px; color: var(--gray);
}

/* Viseme history bar */
.viseme-bar {
  display: flex; gap: 3px; flex-wrap: wrap;
  min-height: 18px;
}
.v-pip {
  width: 18px; height: 18px; border-radius: 4px;
  display: flex; align-items: center; justify-content: center;
  font-size: 10px; opacity: 0.8;
  animation: pip-in 0.12s ease;
}
@keyframes pip-in {
  from { transform: scale(0.6); opacity: 0; }
  to   { transform: scale(1);   opacity: 0.8; }
}

/* Sequence pills */
.seq-wrap {
  display: flex; align-items: flex-start; gap: 6px; flex-wrap: wrap;
}
.seq-label {
  font-size: 10px; color: var(--gray); font-weight: 600;
  text-transform: uppercase; letter-spacing: 0.08em;
  margin-top: 3px; flex-shrink: 0;
}
.seq-pills {
  display: flex; gap: 4px; flex-wrap: wrap; flex: 1;
}
.seq-pill {
  background: rgba(255,255,255,0.08); border: 1px solid rgba(255,255,255,0.12);
  border-radius: 6px; padding: 2px 8px;
  font-size: 11px; font-weight: 600; color: #fff;
  animation: pip-in 0.12s ease;
}
.seq-idle {
  font-size: 11px; color: rgba(255,255,255,0.20); font-style: italic;
}

/* ── Center panel ────────────────────────────────────────────── */
/* Candidates */
.candidates-wrap {
  background: var(--surface); border: 1px solid var(--border); border-radius: 12px;
  padding: 14px; display: flex; flex-direction: column; gap: 10px;
  flex-shrink: 0;
}
.candidates-header {
  display: flex; align-items: center; justify-content: space-between;
}
.candidates-hint {
  font-size: 10px; color: var(--gray);
}
.candidates-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(130px, 1fr));
  gap: 8px;
  min-height: 80px;
}
.cand-btn {
  background: var(--surface2);
  border: 2px solid rgba(255,255,255,0.10);
  border-radius: 12px; padding: 12px 10px;
  cursor: pointer; transition: all 0.15s;
  display: flex; flex-direction: column; align-items: center; gap: 6px;
  text-align: center; position: relative; overflow: hidden;
}
.cand-btn:hover { transform: translateY(-2px); filter: brightness(1.15); }
.cand-btn:active { transform: translateY(0); }
.cand-btn--top {
  border-color: rgba(255,255,255,0.30);
  box-shadow: 0 0 16px rgba(255,255,255,0.05);
}
.cand-emoji  { font-size: 24px; }
.cand-word   { font-size: 13px; font-weight: 700; color: #fff; line-height: 1.2; }
.cand-score  {
  font-size: 9px; font-weight: 600;
  padding: 2px 6px; border-radius: 10px;
  background: rgba(255,255,255,0.08); color: rgba(255,255,255,0.55);
}
.cand-bar {
  position: absolute; bottom: 0; left: 0;
  height: 3px; background: currentColor; opacity: 0.50;
  border-radius: 0 0 10px 10px;
  transition: width 0.3s;
}
.cand-idle {
  grid-column: 1 / -1;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 8px; padding: 20px;
  color: rgba(255,255,255,0.25);
}
.cand-idle-icon { font-size: 32px; }
.cand-idle p { font-size: 13px; line-height: 1.5; text-align: center; }

/* Output */
.output-wrap {
  background: var(--surface); border: 1px solid var(--border); border-radius: 12px;
  padding: 14px; display: flex; flex-direction: column; gap: 10px;
  flex: 1; min-height: 0;
}
.output-header {
  display: flex; align-items: center; justify-content: space-between;
}
.word-count {
  font-size: 10px; color: var(--gray);
}
.output-box {
  background: var(--surface2); border: 1px solid var(--border2);
  border-radius: 10px; padding: 16px;
  min-height: 90px; flex: 1;
  font-size: 22px; font-weight: 500; line-height: 1.5;
  color: #fff; overflow-y: auto;
  display: flex; align-items: flex-start; flex-wrap: wrap; gap: 0;
}
.output-placeholder { color: rgba(255,255,255,0.22); font-size: 16px; font-weight: 400; }
.output-text { }
.output-cursor {
  display: inline-block; color: var(--cyan);
  animation: blink 1s step-end infinite;
  font-weight: 300; margin-left: 1px;
}
@keyframes blink { 50% { opacity: 0; } }

/* Controls */
.controls-row {
  display: flex; gap: 6px; flex-wrap: wrap;
}
.ctrl-btn {
  display: flex; align-items: center; gap: 6px;
  padding: 10px 14px; border-radius: 10px;
  font-family: var(--font); font-size: 13px; font-weight: 600;
  cursor: pointer; border: 1px solid var(--border2);
  background: var(--surface2); color: rgba(255,255,255,0.75);
  transition: all 0.15s; flex: 1; justify-content: center;
  min-height: 44px;
}
.ctrl-btn:hover:not(:disabled) { background: var(--surface3); color: #fff; }
.ctrl-btn:disabled { opacity: 0.35; cursor: not-allowed; }
.ctrl-speak      { background: rgba(0,200,255,0.12); border-color: rgba(0,200,255,0.30); color: var(--cyan); flex: 2; }
.ctrl-speak:hover:not(:disabled) { background: rgba(0,200,255,0.22); }
.ctrl-speak-last { flex: 1.5; }
.ctrl-clear      { border-color: rgba(255,69,58,0.30); color: rgba(255,69,58,0.75); }
.ctrl-clear:hover:not(:disabled) { background: rgba(255,69,58,0.12); color: var(--red); }

/* Quick tap (re-speak) */
.quick-tap-wrap {
  background: var(--surface); border: 1px solid var(--border); border-radius: 10px;
  padding: 10px 12px; display: flex; flex-direction: column; gap: 8px;
  flex-shrink: 0;
}
.quick-tap-row { display: flex; gap: 6px; flex-wrap: wrap; }
.qtap-btn {
  background: var(--surface2); border: 1px solid var(--border2);
  border-radius: 8px; padding: 8px 14px;
  font-family: var(--font); font-size: 14px; font-weight: 600;
  color: #fff; cursor: pointer; transition: all 0.15s;
  min-height: 40px;
}
.qtap-btn:hover { background: var(--surface3); transform: translateY(-1px); }

/* ── Word bank ────────────────────────────────────────────────── */
.bank-header {
  display: flex; align-items: center; justify-content: space-between;
  flex-shrink: 0;
}
.bank-hint { font-size: 10px; color: var(--gray); }

.bank-tabs {
  display: flex; flex-direction: column; gap: 4px; flex-shrink: 0;
}
.bank-tab {
  display: flex; align-items: center; gap: 8px;
  padding: 8px 12px; border-radius: 8px;
  background: transparent; border: 1px solid transparent;
  color: rgba(255,255,255,0.50); cursor: pointer;
  font-family: var(--font); font-size: 13px; font-weight: 500;
  transition: all 0.15s; text-align: left; width: 100%;
}
.bank-tab:hover   { background: var(--surface2); color: rgba(255,255,255,0.80); }
.bank-tab.active  { background: var(--surface3); border-color: var(--border2); color: #fff; }
.bank-tab-icon  { font-size: 16px; width: 20px; text-align: center; }
.bank-tab-label { flex: 1; }
.bank-tab-count {
  font-size: 10px; color: var(--gray); background: rgba(255,255,255,0.07);
  border-radius: 8px; padding: 1px 6px;
}

.bank-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 5px;
  overflow-y: auto;
  flex: 1;
  padding-bottom: 8px;
}
.word-btn {
  display: flex; flex-direction: column; align-items: center;
  gap: 4px; padding: 8px 4px;
  background: var(--surface2); border: 1px solid var(--border);
  border-radius: 10px; cursor: pointer;
  font-family: var(--font); font-size: 11px; font-weight: 600;
  color: rgba(255,255,255,0.80); text-align: center; line-height: 1.2;
  transition: all 0.15s; min-height: 60px; justify-content: center;
}
.word-btn:hover  { transform: translateY(-2px); background: var(--surface3); color: #fff; }
.word-btn:active { transform: translateY(0); }
.word-btn-emoji  { font-size: 20px; }
.word-btn-text   { font-size: 11px; line-height: 1.2; }

/* ── Misc ─────────────────────────────────────────────────────── */
/* Notification toast */
.toast {
  position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%);
  background: rgba(30,30,30,0.95); border: 1px solid var(--border2);
  border-radius: 10px; padding: 10px 20px;
  font-size: 13px; font-weight: 500; color: #fff;
  z-index: 200; white-space: nowrap;
  animation: toast-in 0.2s ease;
  pointer-events: none;
}
@keyframes toast-in { from { opacity: 0; transform: translateX(-50%) translateY(8px); } to { opacity: 1; transform: translateX(-50%) translateY(0); } }

/* Confirm flash on word add */
.cand-btn.confirm-flash {
  animation: flash 0.35s ease;
}
@keyframes flash {
  0%   { filter: brightness(1); }
  40%  { filter: brightness(1.8); }
  100% { filter: brightness(1); }
}

/* ── Word chips in output box ────────────────────────────────── */
.word-chip {
  display: inline;
  cursor: pointer;
  border-radius: 4px;
  padding: 1px 3px;
  transition: background 0.15s, opacity 0.15s;
}
.word-chip:hover {
  background: rgba(255,255,255,0.13);
}
.word-chip--uncertain {
  text-decoration: underline;
  text-decoration-style: dashed;
  text-decoration-color: rgba(255,159,10,0.75);
  opacity: 0.72;
}
.word-chip--uncertain:hover {
  opacity: 1;
}

/* ── Correction popover ───────────────────────────────────────── */
.correction-popover[hidden] { display: none !important; }
.correction-popover {
  position: fixed; inset: 0; z-index: 300;
  display: flex; align-items: center; justify-content: center;
}
.corr-backdrop {
  position: absolute; inset: 0;
  background: rgba(0,0,0,0.72);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
}
.corr-card {
  position: relative;
  background: #1c1c1f;
  border: 1px solid rgba(255,255,255,0.14);
  border-radius: 18px;
  padding: 22px 24px 18px;
  width: min(360px, 92vw);
  max-height: 78vh;
  overflow-y: auto;
  display: flex; flex-direction: column; gap: 14px;
  box-shadow: 0 24px 60px rgba(0,0,0,0.6);
}
.corr-header {
  display: flex; align-items: center; justify-content: space-between;
}
.corr-title {
  font-size: 15px; font-weight: 600; color: rgba(255,255,255,0.9);
}
.corr-title strong { color: var(--cyan); }
.corr-close {
  background: rgba(255,255,255,0.08); border: none; border-radius: 7px;
  width: 28px; height: 28px; color: rgba(255,255,255,0.5);
  font-size: 13px; cursor: pointer; transition: background 0.15s, color 0.15s;
  display: flex; align-items: center; justify-content: center;
}
.corr-close:hover { background: rgba(255,255,255,0.15); color: #fff; }
.corr-sub {
  font-size: 12px; color: rgba(255,255,255,0.38); margin-top: -6px;
}
.corr-opts {
  display: flex; flex-wrap: wrap; gap: 8px;
  min-height: 36px;
}
.corr-option {
  background: rgba(255,255,255,0.07);
  border: 1px solid rgba(255,255,255,0.12);
  border-radius: 9px;
  padding: 7px 13px;
  color: #fff; font-size: 14px; font-family: var(--font);
  cursor: pointer; transition: background 0.15s, border-color 0.15s;
}
.corr-option:hover {
  background: rgba(255,255,255,0.14);
  border-color: rgba(255,255,255,0.28);
}
.corr-option[data-pct]::after {
  content: ' ' attr(data-pct);
  font-size: 10px; color: rgba(255,255,255,0.35); margin-left: 2px;
}
.corr-option--learned {
  border-color: rgba(0,200,255,0.45);
  background: rgba(0,200,255,0.08);
}
.corr-option--learned::before {
  content: '★ '; color: var(--cyan); font-size: 11px;
}
.corr-none {
  font-size: 13px; color: rgba(255,255,255,0.35);
}
.corr-type-wrap {
  display: flex; gap: 8px;
}
.corr-type-input {
  flex: 1; background: rgba(255,255,255,0.06);
  border: 1px solid rgba(255,255,255,0.12);
  border-radius: 9px; padding: 8px 12px;
  color: #fff; font-size: 14px; font-family: var(--font);
  outline: none; transition: border-color 0.15s;
}
.corr-type-input::placeholder { color: rgba(255,255,255,0.28); }
.corr-type-input:focus { border-color: var(--cyan); }
.corr-type-submit {
  background: rgba(0,200,255,0.15); border: 1px solid rgba(0,200,255,0.35);
  border-radius: 9px; padding: 8px 16px;
  color: var(--cyan); font-size: 13px; font-weight: 600; font-family: var(--font);
  cursor: pointer; transition: background 0.15s;
}
.corr-type-submit:hover { background: rgba(0,200,255,0.25); }
.corr-learn-note {
  font-size: 11px; color: rgba(255,255,255,0.28); text-align: right; margin-top: -4px;
}

/* ── Responsive ─────────────────────────────────────────────── */
@media (max-width: 900px) {
  .layout {
    grid-template-columns: 1fr;
    grid-template-rows: auto auto auto;
    height: auto;
    overflow: auto;
  }
  html, body { overflow: auto; }
  .panel-camera   { border-right: none; border-bottom: 1px solid var(--border); }
  .panel-wordbank { border-left: none;  border-top:    1px solid var(--border); }
  .bank-tabs { flex-direction: row; flex-wrap: wrap; }
  .bank-tab  { flex: 1; min-width: 0; }
  .bank-grid { grid-template-columns: repeat(3, 1fr); }
  .output-box { min-height: 70px; font-size: 18px; }
}
