:root {
  color-scheme: light;
  --bg: #f5f4f0;
  --surface: #ffffff;
  --ink: #17191c;
  --muted: #6d7077;
  --line: #dedfdc;
  --purple: #6d50f8;
  --purple-2: #8d79ff;
  --purple-soft: #ece9ff;
  --code: #17191d;
  --code-muted: #858996;
  --code-line: #252831;
  --mint: #b7f5d6;
  --amber: #ffdd90;
  --radius: 22px;
  --shadow: 0 28px 70px rgba(27, 24, 42, .11);
}

* { box-sizing: border-box; }
html { scroll-behavior: smooth; }
body {
  margin: 0;
  min-width: 320px;
  background:
    radial-gradient(circle at 8% 12%, rgba(109,80,248,.09), transparent 24rem),
    radial-gradient(circle at 94% 28%, rgba(183,245,214,.26), transparent 24rem),
    var(--bg);
  color: var(--ink);
  font-family: Inter, ui-sans-serif, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}
button, select, textarea { font: inherit; }
button, select { color: inherit; }
button { cursor: pointer; }
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0,0,0,0); white-space: nowrap; border: 0; }

.app-shell { width: min(1460px, 100%); margin: 0 auto; padding: 0 34px; }
.topbar { height: 82px; display: flex; align-items: center; justify-content: space-between; border-bottom: 1px solid rgba(23,25,28,.1); }
.brand { display: flex; align-items: center; gap: 12px; color: var(--ink); text-decoration: none; font-size: 1.35rem; font-weight: 850; letter-spacing: -.05em; }
.brand > span:last-child span { color: var(--purple); }
.brand-mark { width: 34px; height: 34px; display: grid; align-content: center; gap: 4px; padding: 7px; background: var(--ink); border-radius: 10px; transform: rotate(-3deg); }
.brand-mark i { height: 3px; border-radius: 3px; background: #fff; display: block; }
.brand-mark i:nth-child(2) { width: 72%; background: var(--mint); }
.brand-mark i:nth-child(3) { width: 88%; background: var(--purple-2); }
.top-actions { display: flex; align-items: center; gap: 12px; }
.key-btn { min-height: 39px; display: flex; align-items: center; gap: 8px; padding: 0 13px; border: 1px solid var(--line); border-radius: 999px; background: var(--surface); color: var(--ink); font-size: .8rem; font-weight: 750; }
.key-btn:hover { border-color: var(--purple); }
.key-status-dot { width: 8px; height: 8px; border-radius: 50%; background: #d29b34; box-shadow: 0 0 0 4px rgba(210,155,52,.12); }
.key-btn.has-key .key-status-dot { background: #39bd7b; box-shadow: 0 0 0 4px rgba(57,189,123,.12); }
.privacy-pill { display: flex; align-items: center; gap: 8px; padding: 8px 13px; border: 1px solid var(--line); background: rgba(255,255,255,.55); border-radius: 999px; color: var(--muted); font-size: .82rem; font-weight: 650; }
.privacy-pill b { font-weight: 650; }
.privacy-pill span { width: 7px; height: 7px; border-radius: 50%; background: #39bd7b; box-shadow: 0 0 0 4px rgba(57,189,123,.12); }
.privacy-pill.ai-active span { background: var(--purple); box-shadow: 0 0 0 4px rgba(109,80,248,.12); }
.icon-btn { width: 39px; height: 39px; display: grid; place-items: center; border: 1px solid var(--line); border-radius: 50%; background: var(--surface); }
.icon-btn svg { width: 19px; fill: none; stroke: currentColor; stroke-width: 1.8; }

.intro { padding: 55px 0 38px; max-width: 770px; }
.eyebrow { display: flex; align-items: center; gap: 9px; color: var(--purple); font-weight: 800; font-size: .75rem; letter-spacing: .13em; text-transform: uppercase; }
.eyebrow span { width: 22px; height: 2px; background: currentColor; }
.intro h1 { margin: 15px 0 15px; font-size: clamp(2.6rem, 5vw, 5.2rem); line-height: .96; letter-spacing: -.065em; font-weight: 820; }
.intro h1 em { font-family: Georgia, serif; color: var(--purple); font-weight: 500; }
.intro p { max-width: 670px; margin: 0; font-size: clamp(1rem, 1.5vw, 1.18rem); color: var(--muted); line-height: 1.65; }

.workspace { border: 1px solid rgba(23,25,28,.11); border-radius: var(--radius); background: var(--surface); box-shadow: var(--shadow); overflow: hidden; }
.workspace-toolbar { min-height: 72px; display: flex; align-items: center; justify-content: space-between; gap: 20px; padding: 14px 18px 14px 24px; border-bottom: 1px solid var(--line); }
.file-name { display: flex; align-items: center; gap: 10px; }
.file-dot { width: 10px; height: 10px; border-radius: 3px; background: var(--purple); transform: rotate(45deg); }
.file-name strong { font-family: "SFMono-Regular", Consolas, monospace; font-size: .93rem; }
.file-name small { color: var(--muted); }
.toolbar-actions { display: flex; align-items: center; gap: 9px; }
.select-wrap { position: relative; }
.select-wrap::after { content: "⌄"; position: absolute; right: 12px; top: 8px; pointer-events: none; color: var(--muted); }
select, .ghost-btn, .primary-btn { min-height: 40px; border-radius: 11px; border: 1px solid var(--line); background: #fff; padding: 0 14px; font-weight: 700; font-size: .86rem; }
select { appearance: none; padding-right: 34px; }
.ghost-btn:hover, .icon-btn:hover { border-color: #b6b5b2; background: #fafafa; }
.primary-btn { display: flex; align-items: center; gap: 8px; border-color: var(--purple); background: var(--purple); color: #fff; padding: 0 17px; box-shadow: 0 6px 18px rgba(109,80,248,.25); }
.primary-btn:hover { background: #5e41ea; }
.primary-btn svg { width: 17px; fill: none; stroke: currentColor; stroke-width: 2; }
.local-analyze-btn { display: flex; align-items: center; gap: 7px; }
.local-analyze-btn svg { width: 16px; fill: none; stroke: currentColor; stroke-width: 2; }
.ai-btn { min-width: 158px; justify-content: center; }
.ai-btn:disabled { opacity: .68; cursor: wait; }
.sparkle { font-size: 1rem; }
.ai-btn.loading .sparkle { animation: sparkle-spin 1.1s linear infinite; }
@keyframes sparkle-spin { to { transform: rotate(360deg); } }
.ai-notice { display: flex; align-items: center; gap: 10px; padding: 11px 20px; border-bottom: 1px solid #dcd6ff; background: #f2efff; color: #51448f; font-size: .86rem; line-height: 1.45; }
.ai-notice[hidden] { display: none; }
.ai-notice-icon { color: var(--purple); font-size: 1rem; }
.ai-notice button { margin-left: auto; border: 0; background: transparent; color: #7d72a8; font-size: 1.25rem; }
.ai-notice.error { border-bottom-color: #f0c7c7; background: #fff0f0; color: #8d3434; }
.ai-notice.error .ai-notice-icon { color: #c34444; }

.analysis-grid { position: relative; display: grid; grid-template-columns: minmax(0, 1.05fr) 64px minmax(350px, .75fr); min-height: 510px; }
.code-panel, .explain-panel { min-width: 0; padding: 24px; }
.code-panel { background: var(--code); color: #f3f5f7; }
.explain-panel { position: relative; display: flex; flex-direction: column; background: linear-gradient(145deg, #fff 0%, #fbfaff 100%); }
.panel-kicker { height: 30px; display: flex; align-items: flex-start; justify-content: space-between; color: var(--code-muted); font-weight: 800; font-size: .7rem; letter-spacing: .13em; text-transform: uppercase; }
.panel-kicker button { border: 0; background: none; color: #bbb6ff; font-weight: 700; letter-spacing: 0; text-transform: none; }
.hint-legend { margin-left: 10px; color: #737886; font-size: .75rem; font-weight: 650; letter-spacing: 0; text-transform: none; }
.explain-panel .panel-kicker { color: #96939e; }
.step-counter { letter-spacing: 0; text-transform: none; color: var(--purple); }
.editor-wrap { position: relative; height: 424px; display: grid; grid-template-columns: 44px 1fr; overflow: auto; border-top: 1px solid rgba(255,255,255,.08); }
.line-nums { margin: 0; padding: 17px 12px 30px 0; text-align: right; color: #5f6470; line-height: 1.82; font: 14px/1.82 "SFMono-Regular", Consolas, monospace; user-select: none; border-right: 1px solid rgba(255,255,255,.08); }
textarea { width: 100%; height: 100%; resize: none; border: 0; outline: 0; padding: 17px 20px 30px; background: transparent; color: #f1f3f6; caret-color: var(--mint); font: 14px/1.82 "SFMono-Regular", Consolas, monospace; tab-size: 2; white-space: pre; overflow: auto; }
.code-lines { min-width: 100%; padding: 17px 0 30px; font: 14px/1.82 "SFMono-Regular", Consolas, monospace; white-space: pre; }
.code-line { position: relative; min-height: 25.5px; padding: 0 18px 0 20px; color: #e8eaf0; cursor: pointer; transition: background .18s, color .18s; }
.code-line:hover { background: rgba(255,255,255,.06); }
.code-line.active { background: linear-gradient(90deg, rgba(109,80,248,.34), rgba(109,80,248,.10)); color: #fff; }
.code-line.active::before { content: ""; position: absolute; left: 0; top: 3px; bottom: 3px; width: 3px; border-radius: 4px; background: var(--purple-2); }
.code-line.block-peer { background: rgba(109,80,248,.08); }
.token-key { color: #c6a9ff; } .token-str { color: #b7f5d6; } .token-num { color: #ffcf7e; } .token-comment { color: #717681; font-style: italic; }
.code-hint {
  position: relative;
  display: inline-block;
  border-bottom: 1px dashed rgba(183,245,214,.7);
  border-radius: 2px;
  cursor: help;
  outline: none;
}
.code-hint::before,
.code-hint::after {
  position: absolute;
  z-index: 30;
  left: 50%;
  pointer-events: none;
  opacity: 0;
  visibility: hidden;
  transform: translate(-50%, 6px);
  transition: opacity .16s ease, transform .16s ease, visibility .16s;
}
.code-hint::before {
  content: attr(data-tip);
  bottom: calc(100% + 11px);
  width: max-content;
  max-width: min(330px, 70vw);
  padding: 11px 13px;
  border: 1px solid rgba(255,255,255,.13);
  border-radius: 11px;
  background: #30323a;
  box-shadow: 0 12px 30px rgba(0,0,0,.36);
  color: #fff;
  font: 600 13px/1.45 Inter, ui-sans-serif, sans-serif;
  white-space: normal;
  text-align: left;
}
.code-hint::after {
  content: "";
  bottom: calc(100% + 5px);
  width: 10px;
  height: 10px;
  background: #30323a;
  transform: translate(-50%, 0) rotate(45deg);
}
.code-hint:hover::before,
.code-hint:hover::after,
.code-hint:focus::before,
.code-hint:focus::after {
  opacity: 1;
  visibility: visible;
}
.code-hint:hover::before,
.code-hint:focus::before { transform: translate(-50%, 0); }
.code-hint:focus { box-shadow: 0 0 0 2px rgba(183,245,214,.45); }
.code-hint.token-ai { border-bottom-color: #b7aaff; background: rgba(109,80,248,.09); }
.code-line:nth-child(-n+3) .code-hint::before { top: calc(100% + 11px); bottom: auto; }
.code-line:nth-child(-n+3) .code-hint::after { top: calc(100% + 5px); bottom: auto; }
.connector { width: 64px; height: 100%; overflow: visible; background: linear-gradient(90deg, var(--code) 50%, #fff 50%); }
.connector path { fill: none; stroke: var(--purple); stroke-width: 2.5; stroke-linecap: round; filter: drop-shadow(0 3px 4px rgba(109,80,248,.25)); }
.connector marker path { fill: var(--purple); stroke: none; }

.explanation { max-width: 560px; margin: auto 0; padding: 18px 12px 18px 20px; animation: appear .28s ease both; }
@keyframes appear { from { opacity: 0; transform: translateY(7px); } to { opacity: 1; transform: none; } }
.explain-icon { width: 51px; height: 51px; display: grid; place-items: center; border-radius: 16px; background: var(--purple-soft); color: var(--purple); font-family: Georgia, serif; font-size: 1.5rem; font-weight: 800; margin-bottom: 24px; }
.explain-meta { margin-bottom: 10px; color: var(--purple); font-size: .74rem; font-weight: 850; letter-spacing: .1em; text-transform: uppercase; }
.source-row { display: flex; flex-wrap: wrap; align-items: center; gap: 9px; margin-bottom: 10px; }
.source-row .explain-meta { margin-bottom: 0; }
.analysis-source { padding: 5px 8px; border-radius: 7px; font-size: .68rem; font-weight: 850; letter-spacing: .05em; text-transform: uppercase; }
.analysis-source.local { background: #eceef1; color: #676a71; }
.analysis-source.ai { background: var(--purple-soft); color: var(--purple); }
.explanation h2 { margin: 0 0 15px; font-size: clamp(1.55rem, 2.4vw, 2.35rem); line-height: 1.1; letter-spacing: -.04em; }
.explanation > p { margin: 0; color: var(--muted); font-size: 1rem; line-height: 1.7; }
.explanation code { padding: 2px 6px; border-radius: 6px; background: #eeeafc; color: #5d43d7; font: .9em "SFMono-Regular", Consolas, monospace; }
.plain-box { margin-top: 24px; padding: 16px 18px; border-left: 3px solid var(--purple); border-radius: 0 12px 12px 0; background: #f5f3ff; }
.plain-box span { display: block; margin-bottom: 6px; color: var(--purple); font-size: .7rem; font-weight: 850; text-transform: uppercase; letter-spacing: .09em; }
.plain-box p { margin: 0; color: #4a4654; line-height: 1.55; }
.step-controls { display: flex; justify-content: center; align-items: center; gap: 10px; padding-top: 20px; }
.round-btn { width: 42px; height: 42px; border: 1px solid var(--line); border-radius: 50%; background: #fff; font-size: 1.55rem; line-height: 1; }
.round-btn:hover { border-color: var(--purple); color: var(--purple); }
.round-btn:disabled { opacity: .35; cursor: default; }
.play-btn { min-height: 42px; display: flex; align-items: center; gap: 9px; padding: 0 18px; border: 0; border-radius: 999px; background: var(--ink); color: #fff; font-weight: 800; }
.play-btn:hover { background: var(--purple); }
.play-icon { font-size: .68rem; }

.how-it-works { display: grid; grid-template-columns: repeat(3, 1fr); gap: 16px; padding: 26px 0 44px; }
.how-it-works article { display: flex; gap: 14px; padding: 18px; border: 1px solid rgba(23,25,28,.09); border-radius: 16px; background: rgba(255,255,255,.55); }
.feature-icon { flex: 0 0 auto; width: 40px; height: 40px; display: grid; place-items: center; border-radius: 12px; font: 800 .72rem "SFMono-Regular", Consolas, monospace; }
.feature-icon.violet { background: var(--purple-soft); color: var(--purple); }.feature-icon.mint { background: var(--mint); color: #16704a; }.feature-icon.amber { background: var(--amber); color: #74500b; }
.how-it-works h3 { margin: 1px 0 5px; font-size: .98rem; }.how-it-works p { margin: 0; color: var(--muted); font-size: .84rem; line-height: 1.5; }
footer { display: flex; justify-content: space-between; padding: 22px 0 35px; border-top: 1px solid rgba(23,25,28,.1); color: var(--muted); font-size: .78rem; }

.key-dialog { width: min(520px, calc(100% - 28px)); padding: 0; border: 0; border-radius: 22px; background: transparent; color: var(--ink); box-shadow: 0 28px 80px rgba(16,14,28,.32); }
.key-dialog::backdrop { background: rgba(15,15,20,.62); backdrop-filter: blur(5px); }
.key-card { position: relative; padding: 30px; border: 1px solid var(--line); border-radius: 22px; background: var(--surface); }
.dialog-close { position: absolute; top: 16px; right: 16px; width: 34px; height: 34px; border: 0; border-radius: 50%; background: #f0eff3; color: #77727f; font-size: 1.35rem; }
.key-icon { width: 48px; height: 48px; display: grid; place-items: center; border-radius: 15px; background: var(--purple-soft); color: var(--purple); font-size: 1.7rem; font-weight: 900; }
.key-card h2 { margin: 18px 0 8px; font-size: 1.65rem; letter-spacing: -.035em; }
.key-card > p { margin: 0 0 20px; color: var(--muted); line-height: 1.55; }
.key-field { display: grid; gap: 8px; color: var(--ink); font-size: .78rem; font-weight: 800; }
.password-wrap { display: grid; grid-template-columns: 1fr auto; border: 1px solid var(--line); border-radius: 12px; background: var(--surface); overflow: hidden; }
.password-wrap:focus-within { border-color: var(--purple); box-shadow: 0 0 0 3px rgba(109,80,248,.12); }
.password-wrap input { min-width: 0; height: 46px; padding: 0 14px; border: 0; outline: 0; background: transparent; color: var(--ink); font: 14px "SFMono-Regular", Consolas, monospace; }
.password-wrap button { padding: 0 13px; border: 0; border-left: 1px solid var(--line); background: transparent; color: var(--purple); font-size: .78rem; font-weight: 800; }
.remember-key { display: flex; align-items: center; gap: 9px; margin-top: 15px; color: var(--ink); font-size: .88rem; }
.remember-key input { width: 17px; height: 17px; accent-color: var(--purple); }
.key-card .key-safety { margin: 8px 0 0; font-size: .76rem; }
.key-actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 22px; }
.danger-btn { min-height: 40px; margin-right: auto; padding: 0 13px; border: 1px solid #e1b5b5; border-radius: 11px; background: transparent; color: #a63f3f; font-weight: 750; }
.key-message { min-height: 1.2em; margin: 12px 0 0 !important; color: #a63f3f !important; font-size: .8rem; }

body.dark { --bg: #111215; --surface: #1a1b1f; --ink: #f2f2f3; --muted: #a4a5ab; --line: #303238; }
body.dark { background: radial-gradient(circle at 8% 12%, rgba(109,80,248,.18), transparent 24rem), #111215; }
body.dark .workspace-toolbar, body.dark select, body.dark .ghost-btn, body.dark .icon-btn, body.dark .round-btn { background: #202126; }
body.dark .explain-panel { background: #1a1b1f; }
body.dark .connector { background: linear-gradient(90deg, var(--code) 50%, #1a1b1f 50%); }
body.dark .plain-box { background: #262238; } body.dark .plain-box p { color: #d3cedf; }
body.dark .explanation code { background: #302a4b; color: #c5b9ff; }
body.dark .how-it-works article, body.dark .privacy-pill { background: rgba(255,255,255,.035); }
body.dark .dialog-close { background: #292a30; }

@media (max-width: 980px) {
  .analysis-grid { grid-template-columns: 1fr; }
  .connector { display: none; }
  .explain-panel { min-height: 470px; border-top: 1px solid var(--line); }
  .toolbar-actions { flex-wrap: wrap; justify-content: flex-end; }
  .how-it-works { grid-template-columns: 1fr; }
}
@media (max-width: 700px) {
  .app-shell { padding: 0 14px; }
  .topbar { height: 68px; }
  .privacy-pill { display: none; }
  .key-btn { margin-left: auto; }
  .intro { padding: 40px 4px 28px; }
  .workspace-toolbar { align-items: flex-start; flex-direction: column; padding: 16px; }
  .toolbar-actions { width: 100%; justify-content: stretch; }
  .select-wrap { width: 100%; }.select-wrap select { width: 100%; }
  .toolbar-actions .select-wrap { order: 1; }
  .toolbar-actions .local-analyze-btn { display: flex; flex: 1; order: 2; justify-content: center; }
  .toolbar-actions .ai-btn { flex: 1; order: 3; }
  .toolbar-actions #exampleBtn { display: none; }
  .code-panel, .explain-panel { padding: 18px 14px; }
  .hint-legend { display: none; }
  .editor-wrap { height: 380px; grid-template-columns: 36px 1fr; }
  textarea, .code-lines { font-size: 13px; }.line-nums { font-size: 13px; }
  .explanation { padding-left: 5px; }
  footer { flex-direction: column; gap: 7px; }
}
