:root {
    --bg: #f1f5f9;
    --card: #ffffff;
    --panel: #f8fafc;
    --border: #e2e8f0;
    --text: #0f172a;
    --dim: #64748b;
    --accent: #2563eb;
    --accent-soft: #eff6ff;
    --good: #16a34a;
    --good-soft: #f0fdf4;
    --bad: #dc2626;
    --bad-soft: #fef2f2;
    --warn: #b45309;
    --shadow: 0 1px 3px rgba(15, 23, 42, 0.08), 0 1px 2px rgba(15, 23, 42, 0.04);
  }
  * { box-sizing: border-box; }
  body {
    margin: 0;
    background: var(--bg);
    color: var(--text);
    font-family: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", sans-serif;
    display: flex;
    justify-content: center;
    padding: 20px 16px 40px;
    -webkit-font-smoothing: antialiased;
  }
  main { width: 100%; max-width: 520px; }

  header { display: flex; align-items: center; gap: 12px; margin-bottom: 6px; }
  .logo {
    width: 42px; height: 42px; border-radius: 12px;
    background: var(--accent);
    display: flex; align-items: center; justify-content: center;
    box-shadow: var(--shadow);
    flex-shrink: 0;
    text-decoration: none;
  }
  a.logo { cursor: pointer; }
  .logo svg { width: 24px; height: 24px; }
  h1 { font-size: 1.25rem; margin: 0; letter-spacing: -0.01em; }
  .tagline { color: var(--dim); font-size: 0.8rem; margin: 2px 0 0; }

  .install-chip {
    padding: 8px 14px;
    font-size: 0.82rem;
    font-weight: 600;
    border: 1.5px solid var(--accent);
    border-radius: 999px;
    background: var(--accent-soft);
    color: var(--accent);
    cursor: pointer;
    flex-shrink: 0;
  }
  .ioshint {
    margin-top: 14px;
    padding: 12px 16px;
    background: var(--accent-soft);
    border: 1.5px solid var(--accent);
    border-radius: 12px;
    font-size: 0.85rem;
    color: var(--text);
    line-height: 1.5;
  }
  .card {
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: 16px;
    padding: 18px;
    margin-top: 16px;
    box-shadow: var(--shadow);
  }
  .card-label {
    font-size: 0.7rem; font-weight: 700; letter-spacing: 0.08em;
    text-transform: uppercase; color: var(--dim); margin-bottom: 10px;
  }
  .hint { color: var(--dim); font-size: 0.85rem; line-height: 1.45; }
  .hz { color: var(--accent); font-variant-numeric: tabular-nums; font-weight: 600; }

  /* Reference library */
  .ref-row {
    display: flex; align-items: center; gap: 12px;
    padding: 14px 12px;
    border: 1.5px solid var(--border);
    border-radius: 12px;
    margin-bottom: 10px;
    cursor: pointer;
    transition: border-color 0.15s, background 0.15s;
  }
  .ref-row.active { border-color: var(--accent); background: var(--accent-soft); }
  .ref-row .radio {
    width: 18px; height: 18px; border-radius: 50%;
    border: 2px solid var(--border); flex-shrink: 0;
    display: flex; align-items: center; justify-content: center;
  }
  .ref-row.active .radio { border-color: var(--accent); }
  .ref-row.active .radio::after {
    content: ""; width: 9px; height: 9px; border-radius: 50%; background: var(--accent);
  }
  .ref-info { flex: 1; min-width: 0; }
  .ref-name { font-weight: 600; font-size: 0.95rem; }
  .ref-peaks { color: var(--dim); font-size: 0.78rem; font-variant-numeric: tabular-nums; }
  .icon-btn {
    background: none; border: none; padding: 10px; cursor: pointer;
    color: var(--dim); border-radius: 8px; flex-shrink: 0;
    display: flex; align-items: center;
  }
  .icon-btn:hover { background: var(--panel); color: var(--text); }
  .icon-btn svg { width: 17px; height: 17px; }
  .wlink {
    text-decoration: underline dotted;
    cursor: pointer;
    display: inline-block;
    padding: 4px 2px;
  }
  .wlink:hover { color: var(--accent); }
  .wedit {
    background: var(--panel);
    border: 1.5px solid var(--border);
    border-radius: 12px;
    padding: 14px;
    margin: -2px 0 10px;
  }
  .wedit-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
  .wedit-grid label { font-size: 0.75rem; color: var(--dim); font-weight: 600; }
  .wedit-grid input { margin-top: 4px; }
  .wedit .wlink { padding: 6px 0; display: inline-block; }

  .btn {
    width: 100%;
    padding: 14px;
    font-size: 1rem;
    font-weight: 600;
    border: none;
    border-radius: 12px;
    background: var(--accent);
    color: #fff;
    cursor: pointer;
    box-shadow: var(--shadow);
    transition: filter 0.15s;
  }
  .btn:hover { filter: brightness(1.08); }
  button.btn.secondary {
    background: var(--card); color: var(--text);
    border: 1.5px solid var(--border); box-shadow: none;
  }
  button.btn.ghost {
    background: none; color: var(--accent); box-shadow: none;
    border: 1.5px dashed var(--border); font-weight: 500;
  }
  button.btn.listening { background: var(--bad); }
  button.btn:disabled { opacity: 0.55; cursor: default; }
  .btnrow { display: flex; gap: 12px; margin-top: 16px; }
  #mainBtn { margin-top: 16px; }

  input[type="text"], input[type="number"] {
    width: 100%;
    padding: 12px 14px;
    font-size: 1rem;
    border: 1.5px solid var(--border);
    border-radius: 12px;
    margin-top: 10px;
    background: var(--card);
    color: var(--text);
    outline: none;
  }
  input[type="text"]:focus, input[type="number"]:focus { border-color: var(--accent); }

  #status {
    margin: 12px 2px 0;
    font-size: 0.9rem;
    min-height: 1.3em;
    color: var(--dim);
  }
  #status.active { color: var(--text); }

  /* Live monitor */
  #liveWrap { display: none; }
  #liveWrap.show { display: block; }
  .meter-row { display: flex; gap: 10px; align-items: center; margin: 14px 0 8px; }
  .meter {
    position: relative; flex: 1; height: 8px;
    background: var(--panel);
    border: 1px solid var(--border);
    border-radius: 4px; overflow: hidden;
  }
  .meter-fill {
    height: 100%; width: 0%;
    background: linear-gradient(90deg, #86efac, var(--good));
    transition: width 60ms linear;
  }
  .meter-tick { position: absolute; top: 0; height: 100%; width: 2px; background: var(--accent); left: 0%; }
  .meter-row select {
    font-size: 0.78rem; padding: 8px 10px;
    background: var(--card); color: var(--text);
    border: 1.5px solid var(--border); border-radius: 8px;
  }
  .debug {
    font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
    font-size: 0.68rem; color: #94a3b8;
    min-height: 2.3em; margin-bottom: 8px; white-space: pre-line;
  }
  canvas {
    width: 100%; height: 150px;
    background: var(--panel);
    border: 1px solid var(--border);
    border-radius: 12px; display: block;
  }

  /* Verdict */
  .verdict-big { text-align: center; padding: 10px 6px 4px; }
  .verdict-icon {
    width: 64px; height: 64px; border-radius: 50%;
    margin: 0 auto 12px;
    display: flex; align-items: center; justify-content: center;
    font-size: 2rem; font-weight: 800;
  }
  .verdict-big.match .verdict-icon { background: var(--good-soft); color: var(--good); }
  .verdict-big.nomatch .verdict-icon { background: var(--bad-soft); color: var(--bad); }
  .verdict-big .word { font-size: 1.6rem; font-weight: 800; letter-spacing: 0.03em; }
  .verdict-big.match .word { color: var(--good); }
  .verdict-big.nomatch .word { color: var(--bad); }
  .verdict-big .sub2 { color: var(--dim); font-size: 0.85rem; margin-top: 8px; line-height: 1.5; }

  /* Import banner */
  #importBanner {
    display: none;
    background: var(--accent-soft);
    border: 1.5px solid var(--accent);
    border-radius: 16px;
    padding: 16px 18px;
    margin-top: 16px;
    font-size: 0.9rem;
  }
  #importBanner.show { display: block; }

  .toast {
    position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%);
    background: var(--text); color: #fff;
    padding: 10px 18px; border-radius: 999px;
    font-size: 0.85rem; box-shadow: 0 4px 12px rgba(15,23,42,0.25);
    opacity: 0; pointer-events: none; transition: opacity 0.25s;
    z-index: 10;
  }
  .toast.show { opacity: 1; }

  .warnbox {
    display: none;
    margin-top: 12px; padding: 12px 16px;
    background: #fffbeb; border: 1px solid #fde68a;
    border-radius: 12px; font-size: 0.82rem; color: var(--warn);
  }
  .howto {
    margin-top: 16px; padding: 12px 16px;
    background: var(--card); border: 1px solid var(--border);
    border-radius: 12px; font-size: 0.82rem; color: var(--dim);
    line-height: 1.5;
  }
  footer {
    margin-top: 22px; font-size: 0.72rem; color: #94a3b8; line-height: 1.55;
  }

  /* Utilities (extracted from former inline styles) */
  .hidden { display: none !important; }
  .dim { color: var(--dim); }
  .mt6 { margin-top: 6px; }
  .mt8 { margin-top: 8px; }
  .mt10 { margin-top: 10px; }
  .mt12 { margin-top: 12px; }
  .btn.small { font-size: 0.85rem; padding: 10px; }
  .note { font-weight: 600; }
  .note.good { color: var(--good); }
  .note.warn { color: var(--warn); }
  .note.bad { color: var(--bad); }
  details summary { cursor: pointer; padding: 6px 0; }
  .wtable {
    margin-top: 6px;
    display: grid;
    grid-template-columns: 1fr auto;
    gap: 10px 12px;
    align-items: center;
  }
  .header-grow { flex: 1; }
  .inline-icon { vertical-align: -2px; }
  .dismiss-link { float: right; color: inherit; cursor: pointer; text-decoration: underline; }
  .build { color: #b6c0cd; font-size: 0.72rem; margin-top: 5px; }
  .card-label.tight { margin-bottom: 6px; }
  .center { text-align: center; }

  /* Landing page */
  .hero { text-align: center; padding: 34px 0 26px; }
  .hero h2 { font-size: 1.9rem; margin: 0 0 12px; letter-spacing: -0.02em; line-height: 1.2; }
  .hero-sub { color: var(--dim); font-size: 0.95rem; line-height: 1.55; max-width: 420px; margin: 0 auto 20px; }
  .btn.cta {
    display: flex;
    align-items: center;
    justify-content: center;
    text-decoration: none;
    width: 100%;
    max-width: 340px;
    height: 56px;
    padding: 0 16px;
    margin: 22px auto;
    font-size: 1.05rem;
    line-height: 1;
  }
  .hero .btn.cta { margin-top: 8px; margin-bottom: 10px; }
  .hero .btn.cta.secondary { margin-top: 0; }
  .steps-list { margin: 0; padding-left: 20px; }
  .steps-list li { margin-bottom: 10px; font-size: 0.9rem; line-height: 1.5; color: var(--dim); }
  .steps-list li b { color: var(--text); }
  .features { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin-top: 16px; }
  .feature { display: flex; flex-direction: column; gap: 6px; font-size: 0.9rem; }
  .feature .fi { font-size: 1.4rem; }
  @media (max-width: 430px) { .features { grid-template-columns: 1fr; } }

  /* Guide modal */
  .modal-overlay {
    position: fixed; inset: 0; z-index: 50;
    background: rgba(15, 23, 42, 0.55);
    display: flex; align-items: flex-end; justify-content: center;
    padding: 0;
  }
  @media (min-width: 480px) { .modal-overlay { align-items: center; padding: 20px; } }
  .modal {
    background: var(--card);
    width: 100%; max-width: 460px;
    max-height: 82vh;
    border-radius: 18px 18px 0 0;
    display: flex; flex-direction: column;
    box-shadow: 0 -4px 24px rgba(15, 23, 42, 0.2);
    animation: modal-in 0.18s ease-out;
  }
  @media (min-width: 480px) { .modal { border-radius: 18px; } }
  @keyframes modal-in { from { transform: translateY(24px); opacity: 0.6; } to { transform: none; opacity: 1; } }
  .modal-head {
    display: flex; align-items: center; justify-content: space-between;
    padding: 16px 18px; border-bottom: 1px solid var(--border);
    font-size: 1.05rem;
  }
  .modal-body { overflow-y: auto; padding: 8px; -webkit-overflow-scrolling: touch; }
  .modal-row {
    display: flex; justify-content: space-between; align-items: center; gap: 12px;
    width: 100%; text-align: left;
    padding: 14px 12px;
    background: none; border: none; border-radius: 10px;
    font-size: 0.95rem; color: var(--text); cursor: pointer;
  }
  .modal-row:hover, .modal-row:active { background: var(--panel2); }
  .modal-row + .modal-row { border-top: 1px solid var(--border); }

  .privacy-link {
    text-align: center;
    padding-top: 20px;
    font-size: 0.8rem;
  }
  .privacy-link a { color: var(--dim); }

  /* Landing SEO markup */
  .brandname { font-size: 1.25rem; font-weight: 700; margin: 0; letter-spacing: -0.01em; }
  .hero h1 {
    font-size: 1.9rem; margin: 0 0 12px; letter-spacing: -0.02em; line-height: 1.2;
  }
  .feature h3 { font-size: 0.95rem; margin: 0; }
  .card h2.card-label { margin-bottom: 10px; }
  .card details { border-top: 1px solid var(--border); padding: 12px 0 4px; }
  .card details:first-of-type { border-top: none; }
  .card details summary { cursor: pointer; font-size: 0.92rem; }
  .card details p { margin: 8px 0 4px; }
