/* ─── Design tokens: light default, dark via system or toggle ─── */
  :root {
    color-scheme: light dark;
    --bg: #f8f5ee;
    --surface: #fffdf8;
    --surface-2: #eee7da;
    --surface-3: #e5dccb;
    --text: #26312d;
    --muted: #64746c;
    --line: rgba(38, 49, 45, 0.12);
    --accent: #3f8068;
    --accent-2: #b58a3e;
    --accent-fg: #fffdf8;
    --mark-filter: none;
    --shadow: 0 18px 52px rgba(72, 80, 67, 0.13);
    --radius: 1.2rem;
    --radius-sm: .7rem;
  }
  @media (prefers-color-scheme: dark) {
    :root:not([data-theme="day"]) {
      --bg: #101816;
      --surface: #17211e;
      --surface-2: #20302a;
      --surface-3: #25372f;
      --text: #f1f7f2;
      --muted: #b2c2ba;
      --line: rgba(241, 247, 242, 0.12);
      --accent: #7fd3b1;
      --accent-2: #d4b16a;
      --accent-fg: #10201a;
      --mark-filter: invert(92%) sepia(15%) saturate(287%) hue-rotate(103deg) brightness(104%) contrast(94%);
      --shadow: 0 22px 64px rgba(0, 0, 0, 0.28);
    }
  }
  :root[data-theme="night"] {
    --bg: #101816;
    --surface: #17211e;
    --surface-2: #20302a;
    --surface-3: #25372f;
    --text: #f1f7f2;
    --muted: #b2c2ba;
    --line: rgba(241, 247, 242, 0.12);
    --accent: #7fd3b1;
    --accent-2: #d4b16a;
    --accent-fg: #10201a;
    --mark-filter: invert(92%) sepia(15%) saturate(287%) hue-rotate(103deg) brightness(104%) contrast(94%);
    --shadow: 0 22px 64px rgba(0, 0, 0, 0.28);
  }
  :root[data-theme="day"] {
    color-scheme: light;
    --bg: #f8f5ee;
    --surface: #fffdf8;
    --surface-2: #eee7da;
    --surface-3: #e5dccb;
    --text: #26312d;
    --muted: #64746c;
    --line: rgba(38, 49, 45, 0.12);
    --accent: #3f8068;
    --accent-2: #b58a3e;
    --accent-fg: #fffdf8;
    --mark-filter: none;
    --shadow: 0 18px 52px rgba(72, 80, 67, 0.13);
  }
   /* ─── Reset & base ─── */
  *, *::before, *::after { box-sizing: border-box; }
  html { scroll-behavior: smooth; }
  body {
    margin: 0;
    font-family: "Manrope", "Noto Sans TC", "PingFang TC", "Microsoft JhengHei", "Heiti TC", ui-sans-serif, system-ui, sans-serif;
    background:
      radial-gradient(circle at top left, color-mix(in srgb, var(--accent) 11%, transparent), transparent 30rem),
      radial-gradient(circle at 88% 6%, color-mix(in srgb, var(--accent-2) 12%, transparent), transparent 24rem),
      var(--bg);
    color: var(--text);
    line-height: 1.6;
    min-height: 100dvh;
    transition: background .25s ease, color .25s ease;
  }
  h1, h2, h3, p { margin-top: 0; }
  a { color: inherit; }
  button { font-family: inherit; cursor: pointer; }
   /* ─── Header ─── */
  .site-header {
    position: sticky; top: 0; z-index: 20;
    display: flex; align-items: center; justify-content: space-between; gap: 1rem;
    padding: .8rem clamp(1rem, 4vw, 2.5rem);
    backdrop-filter: blur(18px);
    background: color-mix(in srgb, var(--bg) 80%, transparent);
    border-bottom: 1px solid var(--line);
  }
  .brand { display: inline-flex; align-items: center; gap: .65rem; text-decoration: none; font-weight: 800; letter-spacing: -.02em; font-size: .97rem; }
  .brand-mark { width: 2rem; height: 2rem; object-fit: contain; filter: var(--mark-filter); }
  .breadcrumb { display: flex; align-items: center; gap: .45rem; font-size: .88rem; color: var(--muted); }
  .breadcrumb a { text-decoration: none; }
  .breadcrumb a:hover { color: var(--text); }
  .breadcrumb-sep { opacity: .45; }
  .breadcrumb-current { color: var(--text); font-weight: 600; }
  .header-right { display: flex; align-items: center; gap: .75rem; }
  .header-nav-links { display: flex; align-items: center; gap: 1.2rem; }
  .header-nav-links a { text-decoration: none; color: var(--muted); font-size: .88rem; }
  .header-nav-links a:hover { color: var(--text); }
  .theme-toggle {
    width: 2.5rem; height: 2.5rem;
    border: 1px solid var(--line);
    background: color-mix(in srgb, var(--surface) 86%, transparent);
    color: var(--text);
    border-radius: 999px;
    display: grid; place-items: center;
    cursor: pointer;
    backdrop-filter: blur(16px);
  }
  .theme-toggle .theme-icon { grid-area: 1 / 1; width: 1.05rem; height: 1.05rem; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; transition: opacity .18s ease, transform .18s ease; }
  .theme-toggle .sun circle { fill: currentColor; stroke: none; }
  /* Show moon by default (dark assumed), override for light */
  .theme-toggle .moon { opacity: 1; transform: scale(1) rotate(0deg); }
  .theme-toggle .sun  { opacity: 0; transform: scale(.7) rotate(-20deg); }
  :root[data-theme="day"] .theme-toggle .moon { opacity: 0; transform: scale(.7) rotate(-20deg); }
  :root[data-theme="day"] .theme-toggle .sun  { opacity: 1; transform: scale(1) rotate(0deg); }
  @media (prefers-color-scheme: light) {
    :root:not([data-theme="night"]) .theme-toggle .moon { opacity: 0; transform: scale(.7) rotate(-20deg); }
    :root:not([data-theme="night"]) .theme-toggle .sun  { opacity: 1; transform: scale(1) rotate(0deg); }
  }
   /* ─── Page layout ─── */
  .page-wrap { width: min(1200px, calc(100% - 2rem)); margin: 0 auto; padding: 2rem 0 4rem; }
  .page-header { margin-bottom: 1.75rem; }
  .eyebrow { margin: 0 0 .6rem; color: var(--accent); text-transform: uppercase; letter-spacing: .14em; font-size: .75rem; font-weight: 850; }
  .page-title { font-family: "Noto Sans TC", "PingFang TC", "Manrope", sans-serif; font-size: clamp(1.6rem, 4vw, 2.4rem); line-height: 1.18; letter-spacing: -.01em; margin: 0 0 .4rem; }
  .page-desc { color: var(--muted); font-size: .92rem; margin: 0; }
   /* ─── Main editor layout ─── */
  .editor-layout {
    display: grid;
    grid-template-columns: 1fr 320px;
    grid-template-rows: auto 1fr;
    gap: 1rem;
    align-items: start;
  }
  .editor-col { grid-column: 1; grid-row: 1 / 3; display: flex; flex-direction: column; gap: 0; }
  .sidebar { grid-column: 2; display: flex; flex-direction: column; gap: 1rem; }
   /* ─── Textarea panel ─── */
  .textarea-panel {
    display: flex; flex-direction: column;
    background: linear-gradient(160deg, color-mix(in srgb, var(--surface) 92%, transparent), color-mix(in srgb, var(--surface-2) 60%, transparent));
    border: 1px solid var(--line);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    overflow: hidden;
    height: 100%;
  }
  .textarea-toolbar {
    display: flex; align-items: center; justify-content: space-between; gap: .5rem;
    padding: .65rem .85rem;
    border-bottom: 1px solid var(--line);
    flex-wrap: wrap;
    row-gap: .5rem;
  }
  .toolbar-label { font-size: .8rem; font-weight: 700; color: var(--muted); letter-spacing: .04em; text-transform: uppercase; }
  .toolbar-actions { display: flex; align-items: center; gap: .4rem; flex-wrap: wrap; }
  .main-textarea {
    flex: 1;
    width: 100%; min-height: 420px;
    padding: 1rem 1.1rem;
    border: none; outline: none; resize: vertical;
    background: transparent;
    color: var(--text);
    font-family: "Manrope", "Noto Sans TC", ui-sans-serif, sans-serif;
    font-size: 1rem; line-height: 1.7;
    caret-color: var(--accent);
  }
  .main-textarea::placeholder { color: var(--muted); opacity: .7; }
  .char-counter {
    padding: .45rem .85rem;
    border-top: 1px solid var(--line);
    font-size: .78rem; color: var(--muted);
    text-align: right;
  }
   /* ─── Buttons ─── */
  .btn {
    display: inline-flex; align-items: center; justify-content: center; gap: .35rem;
    padding: .42rem .85rem;
    border-radius: 999px;
    border: 1px solid var(--line);
    background: color-mix(in srgb, var(--surface-2) 80%, transparent);
    color: var(--text);
    font-size: .82rem; font-weight: 700;
    text-decoration: none;
    transition: transform .15s ease, background .15s ease, border-color .15s ease;
    white-space: nowrap;
  }
  .btn:hover { transform: translateY(-1px); background: color-mix(in srgb, var(--surface-3) 90%, transparent); }
  .btn:active { transform: translateY(0); }
  .btn.accent {
    background: var(--accent);
    color: var(--accent-fg);
    border-color: transparent;
  }
  .btn.accent:hover { background: color-mix(in srgb, var(--accent) 88%, var(--text)); }
  .btn.danger {
    color: #f47c7c;
    border-color: color-mix(in srgb, #f47c7c 30%, transparent);
  }
  .btn.danger:hover { background: color-mix(in srgb, #f47c7c 10%, transparent); }
  .btn.sm { padding: .3rem .65rem; font-size: .77rem; }
  .btn.copied {
    background: color-mix(in srgb, var(--accent) 18%, transparent);
    color: var(--accent);
    border-color: color-mix(in srgb, var(--accent) 35%, transparent);
  }
   /* ─── Stats panel ─── */
  .panel {
    background: linear-gradient(160deg, color-mix(in srgb, var(--surface) 92%, transparent), color-mix(in srgb, var(--surface-2) 60%, transparent));
    border: 1px solid var(--line);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    overflow: hidden;
  }
  .panel-header {
    display: flex; align-items: center; justify-content: space-between;
    padding: .7rem 1rem;
    border-bottom: 1px solid var(--line);
  }
  .panel-title { font-size: .78rem; font-weight: 800; letter-spacing: .06em; text-transform: uppercase; color: var(--muted); margin: 0; }
  .stats-grid { display: grid; grid-template-columns: 1fr 1fr; }
  .stat-item {
    padding: .85rem 1rem;
    border-right: 1px solid var(--line);
    border-bottom: 1px solid var(--line);
  }
  .stat-item:nth-child(even) { border-right: none; }
  .stat-item:nth-last-child(-n+2) { border-bottom: none; }
  .stat-item.full { grid-column: 1 / -1; border-right: none; }
  .stat-item.full:last-child { border-bottom: none; }
  .stat-value { font-size: 1.55rem; font-weight: 800; line-height: 1; margin-bottom: .3rem; color: var(--text); font-variant-numeric: tabular-nums; }
  .stat-value.accent-val { color: var(--accent); }
  .stat-label { font-size: .73rem; color: var(--muted); font-weight: 600; letter-spacing: .03em; }
   /* ─── Actions panel ─── */
  .actions-section { display: flex; flex-direction: column; gap: .5rem; }
  .action-group-label { font-size: .72rem; font-weight: 800; text-transform: uppercase; letter-spacing: .08em; color: var(--muted); margin-bottom: .15rem; padding: 0 .1rem; }
  .action-row { display: flex; flex-wrap: wrap; gap: .4rem; }
   /* ─── Output panel ─── */
  .output-panel { display: none; flex-direction: column; }
  .output-panel.visible { display: flex; }
  .output-textarea {
    width: 100%; min-height: 120px;
    padding: .85rem 1rem;
    border: none; outline: none; resize: vertical;
    background: transparent;
    color: var(--accent);
    font-family: "Manrope", "Noto Sans TC", ui-sans-serif, sans-serif;
    font-size: .95rem; line-height: 1.7;
  }
  .output-footer {
    display: flex; align-items: center; justify-content: space-between; gap: .5rem;
    padding: .5rem .85rem;
    border-top: 1px solid var(--line);
    flex-wrap: wrap;
  }
  .output-label { font-size: .78rem; color: var(--muted); font-weight: 600; }
   /* ─── Toast ─── */
  .toast {
    position: fixed; bottom: 1.5rem; left: 50%; transform: translateX(-50%) translateY(4px);
    background: var(--surface-3);
    border: 1px solid var(--line);
    color: var(--text);
    padding: .55rem 1.1rem;
    border-radius: 999px;
    font-size: .85rem; font-weight: 700;
    box-shadow: 0 8px 32px rgba(0,0,0,.28);
    opacity: 0; pointer-events: none;
    transition: opacity .2s ease, transform .2s ease;
    z-index: 100; white-space: nowrap;
  }
  .toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
   /* ─── Footer ─── */
  footer {
    width: min(1200px, calc(100% - 2rem));
    margin: 0 auto; padding: 1.75rem 0 2.5rem;
    color: var(--muted); border-top: 1px solid var(--line);
    display: flex; justify-content: space-between; align-items: center; gap: 1rem; font-size: .88rem;
  }
  .brand-breadcrumb {
    display: flex;
    align-items: center;
    gap: 1rem;
  }
  .panel-body {
    padding: .85rem 1rem;
    display: flex;
    flex-direction: column;
    gap: .5rem;
  }
  .output-actions {
    display: flex;
    gap: .4rem;
    flex-wrap: wrap;
  }
  .footer-link {
    color: var(--muted);
    text-decoration: none;
    font-size: .88rem;
  }
   /* ─── Responsive ─── */
  @media (max-width: 800px) {
    .editor-layout { grid-template-columns: 1fr; grid-template-rows: auto; }
    .editor-col { grid-column: 1; grid-row: auto; }
    .sidebar { grid-column: 1; }
    .main-textarea { min-height: 280px; }
    .stats-grid { grid-template-columns: repeat(2, 1fr); }
    .header-nav-links { display: none; }
    .mobile-back { display: flex; }
  }
  .mobile-back {
    display: none;
    align-items: center;
    gap: .4rem;
    padding: .5rem clamp(1rem,4vw,2rem);
    font-size: .82rem;
    color: var(--muted);
    border-bottom: 1px solid var(--line);
  }
  .mobile-back a { color: var(--accent); text-decoration: none; }
  @media (max-width: 480px) {
    .breadcrumb { font-size: .8rem; }
    .stats-grid { grid-template-columns: 1fr 1fr; }
    footer { flex-direction: column; align-items: flex-start; }
  }
