
  *, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
  :root {
    --bg: #F4F2EE; --surface: #FDFCFA; --border: #E2DED6;
    --text: #1A1816; --muted: #8A8378; --accent: #1A1816;
    --green: #2D6A4F; --green-lt: #D8EDDF; --red: #C0392B;
    --sidebar-w: 240px; --radius: 14px;
  }
  html, body { height: 100%; font-family: 'DM Sans', sans-serif; background: var(--bg); color: var(--text); overflow: hidden; }
  .shell { display: flex; height: 100vh; }

  /* SIDEBAR */
  .sidebar {
    width: var(--sidebar-w); background: var(--surface);
    border-right: 1px solid var(--border);
    display: flex; flex-direction: column; padding: 28px 0 24px; flex-shrink: 0;
  }
  .logo { padding: 0 24px 32px; display: flex; align-items: center; gap: 10px; }
  .logo-mark { width: 34px; height: 34px; background: var(--text); border-radius: 10px; display: grid; place-items: center; }
  .logo-mark svg { width: 18px; height: 18px; fill: none; stroke: #fff; stroke-width: 2; }
  .logo-name { font-family: 'DM Serif Display', serif; font-size: 18px; letter-spacing: -.3px; }
  .nav-section { padding: 0 12px; flex: 1; }
  .nav-label { font-size: 10px; font-weight: 600; letter-spacing: 1.2px; text-transform: uppercase; color: var(--muted); padding: 0 12px 8px; }
  .nav-item {
    display: flex; align-items: center; gap: 10px; padding: 9px 12px; border-radius: 9px;
    cursor: pointer; font-size: 14px; font-weight: 500; color: var(--muted);
    transition: all .15s; margin-bottom: 2px;
  }
  .nav-item:hover { background: var(--bg); color: var(--text); }
  .nav-item.active { background: var(--text); color: #fff; }
  .nav-item svg { width: 16px; height: 16px; flex-shrink: 0; }
  .nav-divider { height: 1px; background: var(--border); margin: 14px 12px; }
  .live-btn {
    margin: 0 12px; display: flex; align-items: center; justify-content: center; gap: 8px;
    padding: 11px; border-radius: 10px; background: var(--green); color: #fff;
    font-size: 14px; font-weight: 600; cursor: pointer; transition: opacity .15s; border: none;
  }
  .live-btn:hover { opacity: .88; }
  .live-btn .dot { width: 7px; height: 7px; border-radius: 50%; background: #a8f5c8; animation: blink 1.4s infinite; }
  @keyframes blink { 0%,100%{opacity:1} 50%{opacity:.3} }

  /* MAIN */
  .main { flex: 1; overflow-y: auto; padding: 36px 40px; }
  .page { display: none; animation: fadeUp .3s ease; }
  .page.active { display: block; }
  @keyframes fadeUp { from{opacity:0;transform:translateY(8px)} to{opacity:1;transform:translateY(0)} }
  .page-header { margin-bottom: 32px; }
  .page-header h1 { font-family: 'DM Serif Display', serif; font-size: 28px; letter-spacing: -.4px; }
  .page-header p { color: var(--muted); font-size: 14px; margin-top: 4px; }

  /* DASHBOARD */
  .stats-row { display: grid; grid-template-columns: repeat(3,1fr); gap: 16px; margin-bottom: 28px; }
  .stat-card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 22px 24px; }
  .stat-card .label { font-size: 12px; font-weight: 600; letter-spacing: .8px; text-transform: uppercase; color: var(--muted); }
  .stat-card .value { font-family: 'DM Serif Display', serif; font-size: 38px; margin-top: 6px; }
  .stat-card .sub { font-size: 12px; color: var(--muted); margin-top: 2px; }
  .dashboard-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 20px; }
  .card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 24px; }
  .card h3 { font-size: 14px; font-weight: 600; margin-bottom: 18px; }

  /* Calendar */
  .cal-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 16px; }
  .cal-header .month { font-family: 'DM Serif Display', serif; font-size: 18px; }
  .cal-nav { display: flex; gap: 6px; }
  .cal-nav button { width: 28px; height: 28px; border-radius: 7px; border: 1px solid var(--border); background: transparent; cursor: pointer; font-size: 14px; color: var(--text); transition: background .1s; }
  .cal-nav button:hover { background: var(--bg); }
  .cal-grid { display: grid; grid-template-columns: repeat(7,1fr); gap: 4px; text-align: center; }
  .cal-day-name { font-size: 11px; font-weight: 600; color: var(--muted); padding: 4px 0; }
  .cal-day { aspect-ratio: 1; display: grid; place-items: center; font-size: 13px; border-radius: 7px; cursor: pointer; transition: background .1s; }
  .cal-day:hover { background: var(--bg); }
  .cal-day.today { background: var(--text); color: #fff; font-weight: 600; }
  .cal-day.has-session { position: relative; }
  .cal-day.has-session::after { content:''; position:absolute; bottom:3px; left:50%; transform:translateX(-50%); width:4px; height:4px; border-radius:50%; background:var(--green); }
  .cal-day.empty { cursor: default; }
  .session-list { display: flex; flex-direction: column; gap: 10px; }
  .session-item { display: flex; align-items: center; justify-content: space-between; padding: 12px 14px; background: var(--bg); border-radius: 10px; font-size: 13px; }
  .session-item .s-left { display: flex; flex-direction: column; gap: 2px; }
  .session-item .s-date { font-weight: 500; }
  .session-item .s-words { color: var(--muted); font-size: 12px; }
  .session-item .s-acc { font-weight: 600; color: var(--green); font-size: 13px; }
  .bar-chart { display: flex; align-items: flex-end; gap: 6px; height: 80px; }
  .bar-wrap {
  flex: 1;
  display: flex;
  flex-direction: column;
  justify-content: flex-end;   /* IMPORTANT */
  align-items: center;
  height: 100%;                /* IMPORTANT */
  gap: 5px;
}
 .bar {
  width: 100%;
  border-radius: 5px 5px 0 0;
  background: var(--border);
  min-height: 4px;   /* ensures bar is visible */
}
  .bar.filled { background: var(--text); }
  .bar-label { font-size: 10px; color: var(--muted); }

  /* LIVE PAGE */
  .live-layout { display: grid; grid-template-columns: 1fr 360px; gap: 24px; }

  .cam-wrapper { position: relative; }
  .cam-container {
    background: #0f0f0f; border-radius: var(--radius);
    aspect-ratio: 16/9; position: relative; overflow: hidden;
    border: 1px solid var(--border);
  }
  #input-video {
    width: 100%; height: 100%; object-fit: cover; display: none;
    border-radius: var(--radius); transform: scaleX(-1);
  }
  #output-canvas {
    position: absolute; top: 0; left: 0; width: 100%; height: 100%;
    border-radius: var(--radius); display: none; transform: scaleX(-1);
  }
  .cam-placeholder { position: absolute; inset: 0; display: flex; flex-direction: column; align-items: center; justify-content: center; color: #555; }
  .cam-placeholder svg { width: 48px; height: 48px; stroke: #444; margin-bottom: 12px; }
  .cam-placeholder p { font-size: 13px; }

  /* detected letter overlay */
  .detected-badge {
    position: absolute; top: 16px; left: 16px;
    background: rgba(0,0,0,.72); backdrop-filter: blur(8px);
    border-radius: 12px; padding: 10px 18px; color: #fff;
    font-size: 13px; display: none; z-index: 10;
  }
  .detected-badge.show { display: block; }
  .detected-badge .big-letter { font-family: 'DM Serif Display', serif; font-size: 56px; line-height: 1; color: #a8f5c8; }
  .detected-badge .conf { font-size: 11px; color: #aaa; margin-top: 2px; }

  /* stable progress ring */
  .stable-ring {
    position: absolute; top: 14px; right: 16px;
    width: 44px; height: 44px; display: none; z-index: 10;
  }
  .stable-ring.show { display: block; }
  .stable-ring svg { transform: rotate(-90deg); }
  .stable-ring circle { fill: none; stroke-width: 4; }
  .ring-bg { stroke: rgba(255,255,255,.15); }
  .ring-fill { stroke: #a8f5c8; stroke-linecap: round; transition: stroke-dashoffset .1s linear; }

  .warning-badge {
    position: absolute; bottom: 16px; left: 16px;
    background: rgba(192,57,43,.85); backdrop-filter: blur(6px);
    border-radius: 8px; padding: 7px 13px;
    color: #fff; font-size: 12px; font-weight: 500;
    display: none; z-index: 10;
  }
  .warning-badge.show { display: block; }

  /* api status pill */
  .api-status {
    position: absolute; bottom: 16px; right: 16px;
    padding: 5px 12px; border-radius: 20px; font-size: 11px; font-weight: 600;
    display: none; z-index: 10;
  }
  .api-status.show { display: flex; align-items: center; gap: 5px; }
  .api-status.ok { background: rgba(45,106,79,.85); color: #fff; }
  .api-status.err { background: rgba(192,57,43,.85); color: #fff; }
  .api-status .s-dot { width: 6px; height: 6px; border-radius: 50%; background: currentColor; }

  .cam-controls { display: flex; gap: 10px; margin-top: 14px; align-items: center; }
  .btn { padding: 9px 20px; border-radius: 9px; border: 1px solid var(--border); background: var(--surface); font-family: 'DM Sans', sans-serif; font-size: 13px; font-weight: 500; cursor: pointer; transition: all .15s; color: var(--text); }
  .btn:hover { background: var(--bg); }
  .btn.primary { background: var(--text); color: #fff; border-color: var(--text); }
  .btn.primary:hover { opacity: .85; }
  .btn.danger { background: var(--red); color: #fff; border-color: var(--red); }
  .btn.danger:hover { opacity: .85; }

  .hint { font-size: 12px; color: var(--muted); margin-top: 10px; line-height: 1.6; }
  .hint code { background: var(--bg); padding: 2px 6px; border-radius: 4px; font-size: 11px; }

  /* RIGHT PANEL */
  .live-panel { display: flex; flex-direction: column; gap: 14px; }
  .output-box { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 20px; }
  .output-box .ob-label { font-size: 11px; font-weight: 600; letter-spacing: .9px; text-transform: uppercase; color: var(--muted); margin-bottom: 10px; }
  .output-box .ob-text { font-family: 'DM Serif Display', serif; font-size: 22px; line-height: 1.5; min-height: 60px; word-break: break-word; }
  .cursor-blink { display: inline-block; width: 2px; height: 22px; background: var(--text); margin-left: 2px; animation: blink 1s infinite; vertical-align: middle; }

  .suggestions-box { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px 20px; }
  .suggestions-box .ob-label { font-size: 11px; font-weight: 600; letter-spacing: .9px; text-transform: uppercase; color: var(--muted); margin-bottom: 10px; }
  .sugg-chips { display: flex; flex-wrap: wrap; gap: 8px; }
  .sugg-chip { padding: 6px 14px; border-radius: 20px; border: 1px solid var(--border); background: var(--bg); font-size: 13px; cursor: pointer; transition: all .15s; }
  .sugg-chip:hover { background: var(--text); color: #fff; border-color: var(--text); }

  .actions-row { display: flex; gap: 8px; flex-wrap: wrap; }
  .action-key { padding: 7px 13px; border-radius: 8px; border: 1px solid var(--border); background: var(--surface); font-size: 12px; cursor: pointer; font-family: 'DM Sans', sans-serif; transition: background .12s; display: flex; align-items: center; gap: 5px; }
  .action-key span { font-size: 10px; color: var(--muted); font-weight: 600; }
  .action-key:hover { background: var(--bg); }
  .speak-btn-lg { width: 100%; padding: 13px; border-radius: 10px; background: var(--green); color: #fff; border: none; font-family: 'DM Sans', sans-serif; font-size: 14px; font-weight: 600; cursor: pointer; transition: opacity .15s; display: flex; align-items: center; justify-content: center; gap: 8px; }
  .speak-btn-lg:hover { opacity: .88; }

  /* SETTINGS */
  .settings-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 20px; }
  .form-group { margin-bottom: 20px; }
  .form-label { font-size: 12px; font-weight: 600; color: var(--muted); text-transform: uppercase; letter-spacing: .8px; margin-bottom: 7px; display: block; }
  .form-input, .form-select { width: 100%; padding: 10px 14px; border: 1px solid var(--border); border-radius: 9px; background: var(--bg); font-family: 'DM Sans', sans-serif; font-size: 14px; color: var(--text); outline: none; transition: border-color .15s; }
  .form-input:focus, .form-select:focus { border-color: var(--text); }
  .toggle-row { display: flex; align-items: center; justify-content: space-between; padding: 14px 0; border-bottom: 1px solid var(--border); }
  .toggle-row:last-child { border-bottom: none; }
  .toggle-info .t-title { font-size: 14px; font-weight: 500; }
  .toggle-info .t-desc { font-size: 12px; color: var(--muted); margin-top: 2px; }
  .toggle { position: relative; width: 42px; height: 24px; }
  .toggle input { display: none; }
  .toggle-track { width: 42px; height: 24px; border-radius: 12px; background: var(--border); cursor: pointer; transition: background .2s; display: block; }
  .toggle input:checked + .toggle-track { background: var(--green); }
  .toggle-thumb { position: absolute; top: 3px; left: 3px; width: 18px; height: 18px; border-radius: 50%; background: #fff; transition: transform .2s; pointer-events: none; box-shadow: 0 1px 3px rgba(0,0,0,.2); }
  .toggle input:checked ~ .toggle-thumb { transform: translateX(18px); }

  /* PROFILE */
  .profile-avatar { width: 80px; height: 80px; border-radius: 50%; background: var(--text); display: grid; place-items: center; font-family: 'DM Serif Display', serif; font-size: 28px; color: #fff; margin-bottom: 16px; }

  /* HELP */
  .help-item { padding: 18px 0; border-bottom: 1px solid var(--border); }
  .help-item:last-child { border-bottom: none; }
  .help-item .q { font-weight: 600; font-size: 14px; cursor: pointer; display: flex; justify-content: space-between; align-items: center; }
  .help-item .a { font-size: 13px; color: var(--muted); margin-top: 10px; line-height: 1.6; display: none; }
  .help-item .a.open { display: block; }

  /* ABOUT */
  .about-hero { text-align: center; padding: 40px 0 32px; }
  .about-hero .big-logo-mark { width: 64px; height: 64px; background: var(--text); border-radius: 18px; display: grid; place-items: center; margin: 0 auto 16px; }
  .about-hero .big-logo-mark svg { width: 32px; height: 32px; fill: none; stroke: #fff; stroke-width: 1.8; }
  .about-hero h2 { font-family: 'DM Serif Display', serif; font-size: 30px; }
  .about-hero p { color: var(--muted); font-size: 14px; margin-top: 8px; }
  .about-hero .version { display: inline-block; margin-top: 12px; padding: 4px 12px; border: 1px solid var(--border); border-radius: 20px; font-size: 12px; color: var(--muted); }
  .tech-stack { display: grid; grid-template-columns: repeat(3,1fr); gap: 12px; margin-top: 28px; }
  .tech-card { border: 1px solid var(--border); border-radius: 11px; padding: 16px; text-align: center; background: var(--surface); }
  .tech-card .tc-icon { font-size: 24px; margin-bottom: 6px; }
  .tech-card .tc-name { font-size: 13px; font-weight: 600; }
  .tech-card .tc-desc { font-size: 11px; color: var(--muted); margin-top: 3px; }

  .main::-webkit-scrollbar { width: 5px; }
  .main::-webkit-scrollbar-track { background: transparent; }
  .main::-webkit-scrollbar-thumb { background: var(--border); border-radius: 10px; }