:root {
  /* Brand */
  --green: #0d7a5f;
  --green-dark: #0a5f49;
  --green-deep: #0a3d33;       /* hero gradient anchor */
  --green-soft: #e8f5f0;
  --green-tint: #f2f9f6;
  /* Neutrals (enterprise ramp) */
  --ink: #16211d;
  --ink-2: #36433d;
  --muted: #6a7a74;
  --line: #e4ebe8;
  --line-2: #d4ded9;
  --bg: #f6f8f7;
  --panel: #ffffff;
  /* Functional */
  --user-box: #1565c0;
  --gold-box: #2e7d32;
  --danger: #c62828;
  /* Scales */
  --radius: 14px;
  --radius-sm: 9px;
  --radius-lg: 20px;
  --shadow-sm: 0 1px 2px rgba(16, 33, 28, 0.05);
  --shadow: 0 4px 16px rgba(16, 33, 28, 0.07);
  --shadow-lg: 0 14px 40px rgba(16, 33, 28, 0.12);
  --ring: 0 0 0 3px rgba(13, 122, 95, 0.18);
}

* { box-sizing: border-box; }
html { scroll-behavior: smooth; }

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  color: var(--ink);
  background: var(--bg);
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

:focus-visible { outline: 2px solid var(--green); outline-offset: 2px; }

h1, h2, h3, h4 { margin: 0 0 0.4rem; font-weight: 700; color: var(--ink); line-height: 1.25; letter-spacing: -0.01em; }
h1 { font-size: clamp(1.6rem, 3vw, 2.1rem); }
h2 { font-size: 1.3rem; }
h3 { font-size: 1.05rem; }
h4 { font-size: 0.95rem; }

.hidden { display: none !important; }
.muted { color: var(--muted); font-size: 0.92rem; line-height: 1.55; }

/* Topbar */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.7rem 1.25rem;
  background: #fff;
  border-bottom: 1px solid var(--line);
  position: sticky;
  top: 0;
  z-index: 20;
}
.brand { display: flex; align-items: center; gap: 0.7rem; text-decoration: none; color: inherit; }
.brand-logo {
  width: 40px; height: 40px; border-radius: 50%;
  object-fit: cover; flex: none;
  box-shadow: 0 0 0 1px var(--line), var(--shadow-sm);
}
.brand-logo--fallback {
  display: grid; place-items: center;
  background: var(--green); color: #fff; font-weight: 700; font-size: 1.1rem;
}
.brand-text { display: flex; flex-direction: column; line-height: 1.2; }
.brand-mark {
  width: 40px; height: 40px;
  display: grid; place-items: center;
  background: var(--green); color: #fff;
  border-radius: 50%; font-weight: 700; font-size: 1.1rem;
}
.brand-title { font-weight: 700; letter-spacing: -0.01em; }
.brand-sub { font-size: 0.76rem; color: var(--muted); }
.topbar-right { display: flex; align-items: center; gap: 0.5rem; }

/* ── Unified account chip (shared connection-state indicator) ──── */
.account {
  display: inline-flex; align-items: center; gap: 0.55rem;
  padding: 0.26rem 0.32rem 0.26rem 0.4rem;
  border: 1px solid var(--line); border-radius: 999px; background: var(--panel);
}
.account-avatar {
  position: relative; flex: none;
  width: 30px; height: 30px; border-radius: 50%;
  display: grid; place-items: center;
  font-weight: 700; font-size: 0.76rem;
  background: #eceff1; color: var(--muted);
}
.account-avatar::after {
  content: ""; position: absolute; right: -1px; bottom: -1px;
  width: 9px; height: 9px; border-radius: 50%;
  background: #b6c0bc; box-shadow: 0 0 0 2px var(--panel);
}
.account-meta { display: flex; flex-direction: column; line-height: 1.18; min-width: 0; }
.account-status {
  font-size: 0.64rem; font-weight: 700; letter-spacing: 0.04em;
  text-transform: uppercase; color: var(--muted);
}
.account-name {
  font-size: 0.82rem; font-weight: 600; color: var(--ink);
  max-width: 15ch; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.account-btn {
  flex: none; border: 0; cursor: pointer; border-radius: 999px;
  font-size: 0.76rem; font-weight: 600; padding: 0.34rem 0.72rem;
  background: var(--green); color: #fff; text-decoration: none; line-height: 1;
}
.account-btn:hover { background: var(--green-dark); }

.account--on .account-avatar { background: var(--green-soft); color: var(--green-dark); }
.account--on .account-avatar::after { background: #16a34a; }
.account--on .account-status { color: var(--green-dark); }
.account--on .account-btn { background: transparent; color: var(--muted); border: 1px solid var(--line); }
.account--on .account-btn:hover { background: var(--green-tint); color: var(--ink); }

.account--off .account-name { display: none; }

.account--checking .account-name { display: none; }
.account--checking .account-avatar::after { background: #f1b24a; animation: account-pulse 1s ease-in-out infinite; }
.account--checking .account-btn { visibility: hidden; }

@keyframes account-pulse { 0%, 100% { opacity: 1; } 50% { opacity: 0.3; } }

@media (max-width: 560px) { .account-meta { display: none; } }

.exam-verdict {
  font-weight: 800; letter-spacing: 0.04em; text-align: center;
  padding: 0.5rem 0.75rem; border-radius: 10px; margin-bottom: 0.75rem; font-size: 0.95rem;
}
.exam-verdict--pass { background: var(--green-soft); color: var(--green-dark); }
.exam-verdict--fail { background: #fbe9e7; color: var(--danger); }

/* Buttons */
.btn {
  border: 1px solid transparent; border-radius: 10px;
  padding: 0.55rem 0.95rem; font-size: 0.9rem; font-weight: 600;
  cursor: pointer; transition: background 0.15s ease, border-color 0.15s ease, transform 0.12s ease, box-shadow 0.15s ease;
  display: inline-flex; align-items: center; justify-content: center; gap: 0.4rem;
  text-decoration: none; line-height: 1.2;
}
.btn:active { transform: translateY(1px); }
.btn-primary { background: var(--green); color: #fff; box-shadow: var(--shadow-sm); }
.btn-primary:hover { background: var(--green-dark); box-shadow: var(--shadow); transform: translateY(-1px); }
.btn-ghost { background: #fff; border-color: var(--line-2); color: var(--ink); }
.btn-ghost:hover { background: var(--green-tint); border-color: var(--green); color: var(--green-dark); }
.btn-sm { padding: 0.3rem 0.6rem; font-size: 0.8rem; }
.btn-lg { padding: 0.8rem 1.4rem; font-size: 1rem; border-radius: 12px; }
.btn-block { width: 100%; }

.manual-token {
  display: flex; gap: 0.5rem; padding: 0.75rem 1.25rem;
  background: #fff; border-bottom: 1px solid var(--line);
}
.manual-token input { flex: 1; padding: 0.5rem; border: 1px solid var(--line); border-radius: 8px; }

/* Layout */
.layout { max-width: 1180px; margin: 0 auto; padding: 1.5rem 1.25rem 0; }
.view-title { margin: 0 0 0.3rem; }
.panel { background: transparent; }

/* Hero */
.lab-hero {
  position: relative;
  overflow: hidden;
  border-radius: var(--radius-lg);
  padding: 3rem 2.4rem 2.7rem;
  margin: 0.5rem 0 1.75rem;
  color: #fff;
  text-align: center;
  background:
    radial-gradient(120% 140% at 50% 0%, rgba(255,255,255,0.16) 0%, rgba(255,255,255,0) 50%),
    linear-gradient(135deg, var(--green) 0%, var(--green-dark) 52%, var(--green-deep) 100%);
  box-shadow: var(--shadow-lg);
}
.lab-hero::after {
  content: ""; position: absolute; inset: 0; pointer-events: none;
  background-image: radial-gradient(rgba(255,255,255,0.10) 1px, transparent 1px);
  background-size: 22px 22px; opacity: 0.3;
  -webkit-mask-image: radial-gradient(120% 120% at 50% 0%, #000 0%, transparent 72%);
  mask-image: radial-gradient(120% 120% at 50% 0%, #000 0%, transparent 72%);
}
.lab-hero-inner { position: relative; z-index: 1; max-width: 660px; margin: 0 auto; }
.lab-hero-logo {
  width: 64px; height: 64px; border-radius: 50%; object-fit: cover;
  display: block; margin: 0 auto 1.1rem;
  box-shadow: 0 0 0 4px rgba(255,255,255,0.16), 0 8px 24px rgba(0,0,0,0.22);
}
.lab-hero-logo--fallback {
  display: grid; place-items: center;
  background: rgba(255,255,255,0.16); color: #fff; font-weight: 800; font-size: 1.6rem;
}
.lab-hero-title {
  margin: 0 0 0.7rem; font-size: clamp(1.8rem, 3.4vw, 2.6rem);
  line-height: 1.12; letter-spacing: -0.02em; font-weight: 800;
}
.lab-hero-sub { margin: 0 auto 1.6rem; font-size: 1.06rem; line-height: 1.55; color: rgba(255,255,255,0.92); max-width: 560px; }
.lab-hero-cta { display: flex; flex-wrap: wrap; gap: 0.7rem; justify-content: center; }
.lab-hero-cta .btn-primary {
  background: #fff; color: var(--green-dark); border-color: #fff;
  box-shadow: 0 8px 24px rgba(0,0,0,0.18);
}
.lab-hero-cta .btn-primary:hover {
  background: #f3fbf8; color: var(--green-dark);
  box-shadow: 0 12px 30px rgba(0,0,0,0.24); transform: translateY(-1px);
}
.lab-hero-cta .btn-ghost { background: rgba(255,255,255,0.10); border-color: rgba(255,255,255,0.35); color: #fff; }
.lab-hero-cta .btn-ghost:hover { background: rgba(255,255,255,0.18); border-color: #fff; color: #fff; }
.lab-hero-trust {
  list-style: none; margin: 1.7rem 0 0; padding: 0;
  display: flex; flex-wrap: wrap; justify-content: center; gap: 0.5rem 1.5rem;
  font-size: 0.9rem; color: rgba(255,255,255,0.9);
}
.lab-hero-trust li { display: flex; align-items: center; gap: 0.45rem; }
.lab-hero-trust li::before {
  content: "✓"; display: grid; place-items: center;
  width: 18px; height: 18px; border-radius: 50%;
  background: rgba(255,255,255,0.2); font-size: 0.72rem; font-weight: 700;
}

/* How it works */
.how {
  display: grid; grid-template-columns: repeat(3, 1fr); gap: 1rem; margin-bottom: 2rem;
}
.how-step {
  display: flex; gap: 0.8rem; align-items: flex-start;
  background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 1.1rem 1.2rem; box-shadow: var(--shadow-sm);
}
.how-num {
  flex: none; width: 30px; height: 30px; border-radius: 50%;
  display: grid; place-items: center; font-weight: 800; font-size: 0.95rem;
  background: var(--green-soft); color: var(--green-dark);
}
.how-step strong { display: block; margin-bottom: 0.15rem; font-size: 0.98rem; }
.how-step p { margin: 0; }

.catalog-head { margin-bottom: 1.1rem; }
.catalog-head .view-title { font-size: 1.45rem; }
.catalog-head .muted { max-width: 62ch; }

.me-strip {
  display: flex; flex-wrap: wrap; gap: 0;
  background: #fff; border: 1px solid var(--line); border-radius: var(--radius);
  padding: 0; margin: 0 0 1.25rem; box-shadow: var(--shadow-sm); overflow: hidden;
}
.me-strip .stat {
  flex: 1 1 130px; padding: 0.85rem 1.2rem;
  border-right: 1px solid var(--line);
}
.me-strip .stat:last-child { border-right: none; }
.me-strip .stat strong { display: block; font-size: 1.5rem; font-weight: 800; color: var(--ink); letter-spacing: -0.02em; line-height: 1.15; }
.me-strip .stat span { font-size: 0.72rem; color: var(--muted); text-transform: uppercase; letter-spacing: 0.06em; font-weight: 600; }

/* Cards */
.card-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(290px, 1fr)); gap: 1.1rem; margin-top: 0; scroll-margin-top: 1rem; }
.card {
  background: #fff; border: 1px solid var(--line); border-radius: var(--radius);
  padding: 1.35rem; box-shadow: var(--shadow-sm); display: flex; flex-direction: column; gap: 0.55rem;
  transition: transform 0.16s ease, box-shadow 0.16s ease, border-color 0.16s ease;
}
.card:hover { transform: translateY(-3px); box-shadow: var(--shadow); border-color: var(--line-2); }
.card h3 { margin: 0; font-size: 1.1rem; }
.card > p.muted:first-of-type {
  margin: 0; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden;
}
.card > p.muted:last-of-type {
  margin: auto 0 0; font-size: 0.78rem; padding-top: 0.85rem; border-top: 1px solid var(--line);
}
.card .btn { margin-top: 0.65rem; }
.badge { align-self: flex-start; font-size: 0.68rem; text-transform: uppercase; letter-spacing: 0.06em;
  background: var(--green-soft); color: var(--green-dark); padding: 0.25rem 0.6rem; border-radius: 999px; font-weight: 700; }
.label-chips { display: flex; flex-wrap: wrap; gap: 0.35rem; margin-top: 0.05rem; }
.chip { font-size: 0.73rem; background: var(--green-tint); border: 1px solid var(--line); padding: 0.18rem 0.55rem; border-radius: 999px; color: var(--ink-2); font-weight: 500; }

/* Workspace */
.workspace-head { display: flex; align-items: center; gap: 1rem; margin-bottom: 1.25rem; padding-bottom: 1.1rem; border-bottom: 1px solid var(--line); }
.workspace-title { flex: 1; }
.workspace-title h2 { margin: 0; font-size: 1.2rem; }
.task-nav { display: flex; gap: 0.4rem; }
.workspace-body { display: grid; grid-template-columns: 1fr 340px; gap: 1.5rem; align-items: start; }

.canvas-wrap { background: #fff; border: 1px solid var(--line); border-radius: var(--radius); padding: 0.85rem; box-shadow: var(--shadow-sm); }
#annotCanvas { width: 100%; height: auto; border-radius: 8px; cursor: crosshair; background: #eef2f1; touch-action: none; display: block; }
.hint { font-size: 0.8rem; color: var(--muted); margin: 0.5rem 0 0; }

.side { display: flex; flex-direction: column; gap: 1rem; }
.side-block { background: #fff; border: 1px solid var(--line); border-radius: var(--radius); padding: 1rem; box-shadow: var(--shadow-sm); }
.side-block h3 { margin: 0 0 0.7rem; font-size: 0.9rem; text-transform: uppercase; letter-spacing: 0.05em; color: var(--ink-2); }
.count { background: var(--green-soft); color: var(--green-dark); border-radius: 999px; padding: 0 0.5rem; font-size: 0.8rem; }

.label-picker { display: flex; flex-wrap: wrap; gap: 0.4rem; }
.label-opt { border: 1px solid var(--line); background: #fff; border-radius: 8px; padding: 0.35rem 0.7rem; cursor: pointer; font-size: 0.85rem; font-weight: 600; }
.label-opt.active { background: var(--green); color: #fff; border-color: var(--green); }

.box-list { list-style: none; margin: 0 0 0.5rem; padding: 0; max-height: 180px; overflow: auto; }
.box-list li { display: flex; align-items: center; justify-content: space-between; padding: 0.3rem 0; border-bottom: 1px solid var(--line); font-size: 0.85rem; }
.box-list .lbl { font-weight: 600; }
.box-list .del { color: var(--danger); cursor: pointer; border: none; background: none; font-weight: 700; }

/* Polygon + keypoint controls */
.btn-row { display: flex; gap: 0.4rem; flex-wrap: wrap; }
.kp-list { list-style: none; margin: 0 0 0.5rem; padding: 0; max-height: 220px; overflow: auto; }
.kp-list li { display: flex; align-items: center; gap: 0.45rem; padding: 0.3rem 0; border-bottom: 1px solid var(--line); font-size: 0.85rem; }
.kp-list .lbl { flex: 1; font-weight: 600; }
.kp-list .del { color: var(--green-dark); cursor: pointer; border: none; background: none; font-weight: 700; }
.kp-dot { width: 10px; height: 10px; border-radius: 50%; background: var(--line); flex: none; }
.kp-item--placed .kp-dot { background: var(--green); }
.kp-item--skipped .kp-dot { background: var(--danger); }
.kp-item--next { background: rgba(13,122,95,0.08); border-radius: 6px; }
.kp-item--next .kp-dot { background: var(--green-dark); box-shadow: 0 0 0 3px rgba(13,122,95,0.2); }
.kp-item--next .lbl { color: var(--green-dark); }

/* Result */
.result-box { background: #fff; border: 1px solid var(--line); border-radius: var(--radius); padding: 1.1rem; box-shadow: var(--shadow-sm); }
.score-ring { font-size: 2.4rem; font-weight: 800; color: var(--green-dark); }
.metric-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 0.4rem 1rem; margin-top: 0.6rem; }
.metric-grid div { display: flex; justify-content: space-between; font-size: 0.85rem; border-bottom: 1px dashed var(--line); padding: 0.2rem 0; }
.metric-grid b { color: var(--ink); }
.legend { display: flex; gap: 1rem; margin-top: 0.6rem; font-size: 0.8rem; }
.legend span { display: inline-flex; align-items: center; gap: 0.3rem; }
.swatch { width: 14px; height: 14px; border-radius: 3px; display: inline-block; }
.swatch--user { background: var(--user-box); }
.swatch--gold { background: var(--gold-box); }

/* Quiz (language / multiple-choice tasks) */
.quiz-wrap { background: #fff; border: 1px solid var(--line); border-radius: var(--radius); padding: 1.25rem 1.35rem; box-shadow: var(--shadow-sm); }
.quiz-prompt { margin: 0 0 1rem; font-weight: 600; color: var(--green-dark); }
.quiz-q { padding: 0.8rem 0; border-bottom: 1px solid var(--line); }
.quiz-q:last-child { border-bottom: none; }
.quiz-stem { margin: 0 0 0.6rem; font-weight: 600; display: flex; align-items: baseline; gap: 0.5rem; }
.quiz-num { background: var(--green-soft); color: var(--green-dark); border-radius: 999px; min-width: 1.5rem; height: 1.5rem; display: inline-grid; place-items: center; font-size: 0.8rem; font-weight: 700; flex: none; }
.quiz-opts { display: flex; flex-direction: column; gap: 0.4rem; }
.quiz-opt { text-align: left; border: 1px solid var(--line); background: #fff; border-radius: 8px; padding: 0.5rem 0.75rem; cursor: pointer; font-size: 0.9rem; transition: all 0.12s ease; }
.quiz-opt:hover:not(:disabled) { border-color: var(--green); background: var(--green-soft); }
.quiz-opt.selected { border-color: var(--green); background: var(--green-soft); font-weight: 600; }
.quiz-opt:disabled { cursor: default; }
.quiz-opt.opt-correct { border-color: var(--gold-box); background: #e8f5e9; font-weight: 600; }
.quiz-opt.opt-wrong { border-color: var(--danger); background: #fbe9e7; }

/* ── OCR / transcription tasks ── */
.ocr-wrap { background: #fff; border: 1px solid var(--line); border-radius: var(--radius); padding: 1.25rem 1.35rem; box-shadow: var(--shadow-sm); display: flex; flex-direction: column; gap: 0.9rem; }
.ocr-image { width: 100%; max-height: 360px; object-fit: contain; border: 1px solid var(--line); border-radius: 8px; background: #fafafa; }
.ocr-image.hidden { display: none; }
.ocr-input { width: 100%; box-sizing: border-box; resize: vertical; min-height: 7rem; padding: 0.7rem 0.85rem; border: 1px solid var(--line); border-radius: 8px; font-family: ui-monospace, "Cascadia Code", "Consolas", monospace; font-size: 0.95rem; line-height: 1.5; }
.ocr-input:focus { outline: none; border-color: var(--green); box-shadow: 0 0 0 2px var(--green-soft); }
.ocr-input:disabled { background: #f5f5f5; color: var(--ink-soft, #555); }
.ocr-reference { margin-top: 0.7rem; }
.ocr-reference pre { margin: 0.3rem 0 0; padding: 0.6rem 0.75rem; background: var(--green-soft); border-radius: 8px; white-space: pre-wrap; word-break: break-word; font-family: ui-monospace, "Cascadia Code", "Consolas", monospace; font-size: 0.85rem; }

/* Footer */
.footer { max-width: 1180px; margin: 3rem auto 0; padding: 1.5rem 1.25rem 2.5rem; display: flex; justify-content: space-between; align-items: center; flex-wrap: wrap; gap: 1rem; color: var(--muted); font-size: 0.85rem; border-top: 1px solid var(--line); }
.footer-left { display: flex; align-items: center; flex-wrap: wrap; gap: 0.45rem; }
.footer a { color: var(--green-dark); font-weight: 600; text-decoration: none; }
.footer a:hover { text-decoration: underline; }
.social-links { display: flex; align-items: center; gap: 0.55rem; flex-wrap: wrap; }
.social-links a {
  display: inline-flex; align-items: center; justify-content: center;
  width: 38px; height: 38px; border-radius: 50%;
  background: var(--green-soft); border: 1px solid var(--line);
  color: var(--green-dark); text-decoration: none;
  transition: background 0.2s ease, color 0.2s ease, transform 0.2s ease, border-color 0.2s ease;
}
.social-links a:hover {
  background: var(--green); border-color: var(--green); color: #fff;
  text-decoration: none; transform: translateY(-2px);
}
.social-links svg { width: 16px; height: 16px; fill: currentColor; display: block; }

/* Toasts */
.toast-container { position: fixed; top: 1rem; right: 1rem; z-index: 50; display: flex; flex-direction: column; gap: 0.5rem; }
.toast { background: var(--ink); color: #fff; padding: 0.6rem 0.9rem; border-radius: 8px; font-size: 0.85rem; box-shadow: 0 4px 14px rgba(0,0,0,0.2); }
.toast--err { background: var(--danger); }
.toast--ok { background: var(--green); }

@media (max-width: 820px) {
  .workspace-body { grid-template-columns: 1fr; }
  .how { grid-template-columns: 1fr; gap: 0.7rem; }
  .lab-hero { padding: 2.2rem 1.4rem; }
  .brand-sub { display: none; }
}
