  :root{
    --ink:#111;
    --bg:#f7f6f2;
    --muted:#66645f;
    --line:#171717;
    --green:#1c7a3d;
    --red:#c1341f;
    --soft-red:#b85c54;
    --surface:#f7f6f2;
    --inverse:#f7f6f2;
    --hover:rgba(0,0,0,.025);
    --hover-strong:rgba(0,0,0,.045);
    --soft:rgba(0,0,0,.035);
    --soft-border:rgba(0,0,0,.12);
  }

  html[data-theme="dark"]{
    --ink:#f2f1ec;
    --bg:#111;
    --muted:#aaa79f;
    --line:#d8d6cf;
    --green:#77c28d;
    --red:#df6b60;
    --soft-red:#df746b;
    --surface:#111;
    --inverse:#111;
    --hover:rgba(255,255,255,.045);
    --hover-strong:rgba(255,255,255,.075);
    --soft:rgba(255,255,255,.055);
    --soft-border:rgba(255,255,255,.16);
  }

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

  html,body{
    width:100%;
    min-height:100%;
    background:var(--bg);
    color:var(--ink);
    font-family:ui-monospace,"SFMono-Regular","SF Mono",Menlo,Consolas,"Liberation Mono",monospace;
    -webkit-font-smoothing:antialiased;
    text-rendering:geometricPrecision;
  }

  body{
    display:flex;
    justify-content:center;
  }

  button,input{ font:inherit; }
  button{ color:inherit; }

  .ui-icon{
    width:18px;
    height:18px;
    display:block;
    flex:none;
    overflow:visible;
    stroke:currentColor;
    stroke-width:1.65;
    stroke-linecap:round;
    stroke-linejoin:round;
  }

  #app{
    width:100%;
    max-width:480px;
    min-height:100dvh;
    display:flex;
    flex-direction:column;
    background:var(--bg);
  }

  header{
    padding:15px 22px 5px;
    min-height:44px;
    display:flex;
    justify-content:space-between;
    align-items:center;
  }

  .lobby-link{
    width:34px;
    height:34px;
    display:inline-flex;
    align-items:center;
    justify-content:center;
    color:var(--ink);
    text-decoration:none;
    border:1px solid var(--soft-border);
    border-radius:50%;
    background:var(--soft);
    transition:background .15s ease, border-color .15s ease;
  }

  .lobby-link:hover{
    background:var(--soft);
    border-color:var(--soft-border);
  }

  /* Keep the back control subtle in dark mode — never a white disc. */
  html[data-theme="dark"] .lobby-link{
    background:rgba(255,255,255,.045);
    border-color:rgba(255,255,255,.08);
  }
  html[data-theme="dark"] .lobby-link:hover{
    background:rgba(255,255,255,.075);
    border-color:rgba(255,255,255,.14);
  }

  .lobby-link .ui-icon{ width:18px; height:18px; transform:translateX(-.5px); }

  header .prog{
    font-size:12px;
    color:var(--ink);
    letter-spacing:.08em;
    white-space:nowrap;
  }

  .header-right{ display:flex; align-items:center; gap:14px; }

  .theme-toggle{
    width:34px;
    height:34px;
    border:1px solid var(--soft-border);
    border-radius:50%;
    background:transparent;
    display:inline-flex;
    align-items:center;
    justify-content:center;
    cursor:pointer;
    color:var(--ink);
    transition:background .18s ease, border-color .18s ease, transform .18s ease;
  }
  .theme-toggle:hover{ background:var(--soft); }
  .theme-toggle:active{ transform:scale(.96); }
  .theme-toggle .ui-icon{ width:17px; height:17px; }

  /* quiet cockpit ruler */
  .ticks{
    position:relative;
    height:14px;
    margin:0 22px;
    border-bottom:1px solid var(--line);
    overflow:hidden;
    display:flex;
    align-items:flex-end;
  }

  .ticks span{
    flex:1;
    height:7px;
    border-left:1px solid var(--line);
    opacity:.7;
  }

  .ticks span:nth-child(even){ opacity:0; }
  .ticks span:first-child{ border-left:none; }

  main{
    flex:1;
    padding:46px 22px 40px;
    display:flex;
    flex-direction:column;
  }

  h1{
    font-size:25px;
    line-height:1.2;
    font-weight:700;
    letter-spacing:-.035em;
    margin-bottom:7px;
  }

  .sub{
    max-width:410px;
    font-size:13px;
    line-height:1.75;
    color:var(--muted);
    margin-bottom:46px;
  }

  .level-tabs{
    display:flex;
    gap:20px;
    margin:0 0 26px;
    border-bottom:1px solid var(--line);
    overflow-x:auto;
    scrollbar-width:none;
  }

  .level-tabs::-webkit-scrollbar{ display:none; }

  .level-tab{
    position:relative;
    flex:none;
    appearance:none;
    border:0;
    background:transparent;
    color:var(--muted);
    padding:0 0 12px;
    font-size:11px;
    letter-spacing:.09em;
    text-transform:uppercase;
    cursor:pointer;
    white-space:nowrap;
  }

  .level-tab.active{ color:var(--ink); }
  .level-tab.active::after{
    content:"";
    position:absolute;
    left:0;
    right:0;
    bottom:-1px;
    height:2px;
    background:var(--ink);
  }

  .cat-list{
    display:flex;
    flex-direction:column;
    border-top:none;
  }

  .cat-item{
    min-height:76px;
    padding:0 2px;
    border:none;
    border-bottom:1px solid var(--line);
    display:flex;
    justify-content:space-between;
    align-items:center;
    gap:18px;
    background:transparent;
    color:inherit;
    text-align:left;
    cursor:pointer;
  }

  .cat-item:first-child{ border-top:none; }

  .cat-item > span:first-child{
    display:flex;
    align-items:baseline;
    gap:16px;
    min-width:0;
    font-size:15px;
  }

  .cat-item .idx{
    color:var(--ink);
    font-weight:400;
    margin-right:0;
    flex:none;
  }

  .cat-item span.n{
    font-size:12px;
    color:var(--ink);
    white-space:nowrap;
  }

  .cat-item:hover{ background:var(--hover); }
  .cat-item:active{ background:var(--hover-strong); }
  .cat-item.open{ border-bottom-color:transparent; }
  .cat-item:disabled{
    cursor:not-allowed;
    color:var(--muted);
    opacity:.48;
  }
  .cat-item:disabled:hover,
  .cat-item:disabled:active{ background:transparent; }

  .full-count-tabs{ margin-top:-8px; }

  .full-check-panel{
    padding:24px 2px 48px;
    display:flex;
    flex-direction:column;
    gap:18px;
    transform-origin:top;
  }

  .full-check-panel.opening{ animation:softIn .34s cubic-bezier(.22,.7,.24,1) both; }

  .full-check-heading{ margin-bottom:10px; }
  .full-check-heading h2{
    margin-top:0;
    font-size:19px;
    line-height:1.25;
    letter-spacing:-.025em;
  }
  .full-check-heading p{
    margin-top:9px;
    color:var(--muted);
    font-size:12px;
    line-height:1.55;
  }

  .progress-summary{
    margin-top:42px;
    padding:18px;
    background:var(--soft);
  }

  html[data-theme="dark"] .progress-summary{ background:rgba(255,255,255,.045); }

  .progress-total{
    font-size:16px;
    font-weight:700;
    line-height:1.3;
  }

  .progress-track{
    width:100%;
    height:2px;
    margin-top:15px;
    background:var(--soft-border);
    overflow:hidden;
  }

  .progress-track span{
    display:block;
    height:100%;
    background:var(--ink);
  }

  .progress-note{
    margin-top:13px;
    color:var(--muted);
    font-size:12px;
    line-height:1.45;
  }

  .progress-guest{
    display:flex;
    align-items:center;
    justify-content:space-between;
    gap:18px;
  }

  .progress-guest-title{
    font-size:16px;
    font-weight:700;
    line-height:1.3;
  }

  .progress-login{
    min-width:88px;
    height:38px;
    padding:0 18px;
    border:1px solid var(--ink);
    border-radius:0;
    background:var(--ink);
    color:var(--inverse);
    cursor:pointer;
    font-size:11px;
    font-weight:700;
    letter-spacing:.08em;
    text-transform:uppercase;
  }

  .cat-config{
    padding:5px 2px 48px;
    border-bottom:1px solid var(--line);
    display:flex;
    flex-direction:column;
    gap:16px;
    transform-origin:top;
  }

  .cat-config.opening{
    animation:accordionOpen .34s cubic-bezier(.22,.7,.24,1) both;
  }

  .config-label{
    font-size:10px;
    letter-spacing:.12em;
    text-transform:uppercase;
    color:var(--muted);
  }

  .count-tabs{
    display:flex;
    gap:8px;
    flex-wrap:wrap;
  }

  .count-tab{
    min-width:48px;
    height:34px;
    padding:0 12px;
    border:1px solid var(--line);
    background:transparent;
    color:var(--ink);
    cursor:pointer;
    font-size:12px;
  }

  .count-tab.active{ background:var(--ink); color:var(--inverse); }

  .config-check{
    display:flex;
    align-items:center;
    gap:11px;
    font-size:12px;
    line-height:1.45;
    cursor:pointer;
  }

  .config-check input{ width:17px; height:17px; flex:none; accent-color:var(--ink); }

  .start-btn{
    width:100%;
    margin-top:2px;
    border:1px solid var(--line);
    background:var(--ink);
    color:var(--inverse);
    padding:13px 14px;
    cursor:pointer;
    font-size:11px;
    text-transform:uppercase;
    letter-spacing:.1em;
  }

  .header-left{ display:flex; align-items:center; gap:10px; min-width:0; }
  .header-title{
    font-size:11px;
    letter-spacing:.09em;
    text-transform:uppercase;
    white-space:nowrap;
    overflow:hidden;
    text-overflow:ellipsis;
    max-width:220px;
  }

  .toggle-row{
    margin-top:28px;
    padding-top:0;
    border-top:none;
    display:flex;
    align-items:center;
    gap:12px;
    font-size:12px;
    line-height:1.45;
    cursor:pointer;
  }

  .toggle-row input{
    width:18px;
    height:18px;
    flex:none;
    accent-color:var(--ink);
  }

  /* question */
  .term-frame{
    position:relative;
    padding:24px 22px 26px;
    border:none;
    background:var(--soft);
    border-radius:0;
    margin-top:0;
  }

  .term-frame::before,
  .term-frame::after,
  .term-frame .cbl,
  .term-frame .cbr{
    display:none;
  }

  .term{
    font-size:30px;
    font-weight:700;
    line-height:1.08;
    letter-spacing:-.045em;
    text-transform:uppercase;
  }

  .question-prompt{
    margin-top:14px;
    max-width:420px;
    font-size:15px;
    line-height:1.55;
    color:var(--muted);
  }

  .options{
    display:flex;
    flex-direction:column;
    margin-top:34px;
  }

  .opt{
    min-height:80px;
    padding:0 8px;
    border:none;
    border-bottom:1px solid var(--line);
    background:transparent;
    color:inherit;
    text-align:left;
    cursor:pointer;
    display:grid;
    grid-template-columns:22px 1fr;
    align-items:center;
    gap:12px;
    font-size:14px;
    line-height:1.5;
  }

  .opt:first-child{ border-top:none; }
  .opt:disabled{ cursor:default; }
  .opt:hover:not(:disabled){ background:var(--hover); }

  .opt .lt{
    color:var(--ink);
    font-weight:700;
    font-size:15px;
  }


  .opt.correct{
    background:var(--ink);
    color:var(--inverse);
  }

  .opt.correct .lt{ color:var(--inverse); }

  .opt.wrong{
    background:transparent;
    text-decoration:line-through;
    color:var(--muted);
  }

  .opt.dim{ color:var(--muted); }

  .explain{
    scroll-margin-top:16px;
    position:relative;
    margin-top:24px;
    padding-top:0;
    padding-right:0;
  }

  .explain .verdict,
  .explain .term-name{ padding-right:86px; }

  .explain .verdict{
    font-size:11px;
    text-transform:uppercase;
    letter-spacing:.14em;
    margin-bottom:12px;
    font-weight:700;
  }

  .explain .verdict.ok{ color:var(--green); }
  .explain .verdict.bad{ color:var(--red); }
  .explain .term-name{ font-size:16px; font-weight:700; margin-bottom:8px; }
  .explain .def{ font-size:13px; line-height:1.65; color:var(--muted); }

  .btn{
    margin-top:26px;
    border:1px solid var(--line);
    border-radius:0;
    background:var(--ink);
    color:var(--inverse);
    font-size:13px;
    padding:15px 16px;
    width:100%;
    cursor:pointer;
    text-transform:uppercase;
    letter-spacing:.09em;
  }

  .btn.ghost{ background:transparent; color:var(--ink); margin-top:10px; }

  .result-tabs{
    display:flex;
    gap:22px;
    align-items:center;
    margin:24px 0 2px;
    border-bottom:1px solid var(--line);
  }

  .share-block{
    /* Temporarily hidden; keep the sharing implementation available. */
    display:none;
    grid-template-columns:1fr auto;
    gap:14px 16px;
    align-items:center;
    padding:18px;
    border:1px solid var(--line);
    background:var(--soft);
  }

  .share-copy span{
    display:block;
    font-size:13px;
    font-weight:700;
    letter-spacing:.08em;
    text-transform:uppercase;
  }

  .share-copy small{
    display:block;
    margin-top:5px;
    color:var(--muted);
    font-size:10px;
    letter-spacing:.04em;
  }

  .share-main{
    min-width:92px;
    height:38px;
    padding:0 18px;
    border:1px solid var(--ink);
    background:var(--ink);
    color:var(--inverse);
    cursor:pointer;
    font-size:11px;
    font-weight:700;
    letter-spacing:.08em;
    text-transform:uppercase;
    display:inline-flex;
    align-items:center;
    justify-content:center;
    gap:8px;
  }
  .share-main .ui-icon{ width:15px; height:15px; }

  .share-actions{
    grid-column:1 / -1;
    display:flex;
    flex-wrap:wrap;
    gap:7px;
  }

  .share-actions button{
    min-height:31px;
    padding:0 10px;
    border:1px solid var(--soft-border);
    background:var(--surface);
    color:var(--ink);
    cursor:pointer;
    font-size:10px;
    display:inline-flex;
    align-items:center;
    justify-content:center;
    gap:7px;
    line-height:1;
  }

  .share-actions .ui-icon{ width:14px; height:14px; }

  .share-actions button:hover{ background:var(--hover-strong); }

  .share-status{
    grid-column:1 / -1;
    min-height:0;
    color:var(--muted);
    font-size:10px;
    line-height:1.4;
  }

  .share-status:empty{ display:none; }

  .result-tab{
    position:relative;
    appearance:none;
    border:0;
    background:transparent;
    color:var(--muted);
    padding:0 0 12px;
    font-size:11px;
    letter-spacing:.1em;
    text-transform:uppercase;
    cursor:pointer;
  }

  .result-tab.active{ color:var(--ink); }
  .result-tab.active::after{
    content:"";
    position:absolute;
    left:0; right:0; bottom:-1px;
    height:2px;
    background:var(--ink);
  }

  .result-tab .count{ color:var(--muted); margin-left:5px; }

  .result-row{
    position:relative;
    border-bottom:1px solid var(--line);
    padding:22px 2px;
    padding-right:2px;
  }

  .result-row .rq,
  .result-row .rterm{ padding-right:86px; }

  .result-row .rq{ font-size:11px; color:var(--muted); margin-bottom:7px; letter-spacing:.06em; }
  .result-row.incorrect .rq{ color:var(--soft-red); }
  .result-row .rterm{ font-size:16px; font-weight:700; text-transform:uppercase; margin-bottom:8px; }
  .result-row .rline{ font-size:13px; margin-bottom:4px; line-height:1.5; }
  .result-row .rline.ok{ font-weight:700; }
  .result-row .rline.bad{ color:var(--muted); text-decoration:line-through; }
  .result-row .rdef{ font-size:13px; color:var(--muted); margin-top:10px; line-height:1.6; }

  .lang-row{
    position:absolute;
    top:0;
    right:0;
    display:flex;
    align-items:center;
    gap:8px;
    margin:0;
  }

  .result-row .lang-row{
    top:20px;
    right:2px;
  }

  .lang-switch{
    display:inline-flex;
    align-items:center;
    border:1px solid var(--line);
    background:transparent;
  }

  .lang-btn{
    appearance:none;
    border:0;
    border-right:1px solid var(--line);
    background:transparent;
    color:var(--muted);
    min-width:36px;
    height:26px;
    padding:0 9px;
    font-size:10px;
    letter-spacing:.1em;
    cursor:pointer;
  }

  .lang-btn:last-child{ border-right:0; }
  .lang-btn.active{ background:var(--ink); color:var(--inverse); }
  .def.th, .rdef.th{
    font-family:system-ui,-apple-system,"Segoe UI",sans-serif;
    letter-spacing:0;
  }

  .def.lang-changing,
  .rdef.lang-changing{
    animation:languageSwap .28s cubic-bezier(.22,.7,.24,1) both;
  }

  .empty-results{ padding:34px 2px; color:var(--muted); font-size:13px; border-bottom:1px solid var(--line); }

  .score-wrap{
    display:flex;
    align-items:center;
    gap:20px;
    padding:20px 0 24px;
    margin-bottom:4px;
  }

  .score-ring{
    width:91px;
    height:91px;
    flex:none;
    position:relative;
    display:grid;
    place-items:center;
  }

  .score-ring svg{ width:100%; height:100%; transform:rotate(-90deg); }
  .score-ring .track{ fill:none; stroke:rgba(17,17,17,.13); stroke-width:5; }
  .score-ring .progress{
    fill:none;
    stroke:var(--ink);
    stroke-width:5;
    stroke-linecap:round;
    stroke-dasharray:100;
    stroke-dashoffset:var(--ring-offset);
    animation:ringFill .9s cubic-bezier(.22,.7,.24,1) .30s both;
  }
  .score-ring .pct{
    position:absolute;
    font-size:11px;
    font-weight:700;
    letter-spacing:.03em;
  }

  .score{ font-size:32px; font-weight:700; }
  .score .verdict{
    display:block;
    margin-top:5px;
    font-size:11px;
    line-height:1.35;
    color:var(--ink);
    font-weight:600;
    letter-spacing:.1em;
    text-transform:uppercase;
  }

  .score .of{
    font-size:11px;
    color:var(--muted);
    font-weight:400;
    display:block;
    margin-top:4px;
    letter-spacing:.1em;
    text-transform:uppercase;
  }

  .score-ring.result-step{
    opacity:0;
    transform:scale(.94);
    animation:resultRingIn .46s cubic-bezier(.22,.7,.24,1) .08s forwards;
  }
  .score.result-step{
    opacity:0;
    transform:translateY(8px);
    animation:softIn .46s cubic-bezier(.22,.7,.24,1) .52s forwards;
  }
  .result-tabs.result-step{
    opacity:0;
    transform:translateY(8px);
    animation:softIn .46s cubic-bezier(.22,.7,.24,1) .78s forwards;
  }
  .share-block.result-step{
    opacity:0;
    transform:translateY(8px);
    animation:softIn .46s cubic-bezier(.22,.7,.24,1) .70s forwards;
  }

  @keyframes resultRingIn{
    from{ opacity:0; transform:scale(.94); }
    to{ opacity:1; transform:scale(1); }
  }



  /* soft motion system */
  @keyframes softIn{
    from{ opacity:0; transform:translateY(10px); }
    to{ opacity:1; transform:translateY(0); }
  }

  @keyframes accordionOpen{
    from{ opacity:0; transform:translateY(-6px) scaleY(.985); }
    to{ opacity:1; transform:translateY(0) scaleY(1); }
  }

  @keyframes ringFill{
    from{ stroke-dashoffset:100; }
    to{ stroke-dashoffset:var(--ring-offset); }
  }

  @keyframes answerReveal{
    0%{ opacity:.15; transform:translateY(8px); }
    100%{ opacity:1; transform:translateY(0); }
  }

  @keyframes gentleFlash{
    0%{ opacity:.45; }
    100%{ opacity:1; }
  }

  @keyframes languageSwap{
    from{ opacity:0; transform:translateY(4px); }
    to{ opacity:1; transform:translateY(0); }
  }

  .anim-in{
    opacity:0;
    animation:softIn .48s cubic-bezier(.22,.7,.24,1) forwards;
    animation-delay:var(--delay,0ms);
  }

  .quiz-reveal{
    animation:answerReveal .42s cubic-bezier(.22,.7,.24,1) both;
  }

  .opt.correct.quiz-reveal{ animation-duration:.52s; }
  .opt.wrong.quiz-reveal{ animation-duration:.34s; }

  .results-animate .result-row,
  .results-animate .empty-results{
    opacity:0;
    animation:softIn .42s cubic-bezier(.22,.7,.24,1) forwards;
    animation-delay:var(--row-delay,0ms);
  }

  @media (prefers-reduced-motion: reduce){
    .anim-in,
    .quiz-reveal,
    .cat-config.opening,
    .score-ring .progress,
    .results-animate .result-row,
    .results-animate .empty-results,
    .result-step{
      opacity:1 !important;
      transform:none !important;
      animation:none !important;
    }
    .def.lang-changing,
    .rdef.lang-changing{ animation:none !important; }
  }

  @media (max-width:480px){
    .level-tabs{ gap:12px; }
    .level-tab{ font-size:10px; letter-spacing:.07em; }
  }

  @media (max-width:380px){
    header{ padding-left:18px; padding-right:18px; }
    .ticks{ margin-left:18px; margin-right:18px; }
    main{ padding-left:18px; padding-right:18px; }
    h1{ font-size:23px; }
    .term{ font-size:27px; }
    .cat-item > span:first-child{ gap:12px; font-size:14px; }
    .opt{ padding-left:4px; padding-right:4px; gap:10px; font-size:13px; }
  }
