:root {
  --bg0: #000000;
  --bg1: #000000;
  --shadow: 0 18px 55px rgba(0, 0, 0, .45);
  --accent: #7c3aed;
  --paper: #fbfbf7;
  --text-main: rgba(255, 255, 255, .92);
  --header-bg: rgba(10, 12, 20, .68);
  --card-bg: linear-gradient(180deg, rgba(255, 255, 255, 0.08), rgba(255, 255, 255, 0.05));
  --border-color: rgba(255, 255, 255, 0.13);
  --input-bg: rgba(10, 12, 20, .35);
}

[data-theme="light"] {
  --bg0: #f0f2f5;
  --bg1: #e4e7eb;
  --text-main: #1a1a1a;
  --header-bg: rgba(255, 255, 255, 0.85);
  --card-bg: #ffffff;
  --border-color: rgba(0, 0, 0, 0.1);
  --input-bg: #ffffff;
  --paper: #ffffff;
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  font-family: ui-sans-serif, system-ui, -apple-system, Segoe UI, Roboto, Helvetica, Arial;
  color: var(--text-main);
  background: #000000;
  overflow-x: hidden;
  transition: background 0.3s ease, color 0.3s ease;
}

[data-theme="light"] body {
  background: var(--bg0);
  background: radial-gradient(1200px 800px at 15% 10%, rgba(124, 58, 237, 0.05) 0%, transparent 60%),
              radial-gradient(900px 700px at 85% 25%, rgba(34, 197, 94, 0.05) 0%, transparent 60%),
              linear-gradient(180deg, var(--bg0), var(--bg1));
}
  
  /* background grain + glows (night = solid black; light keeps accents) */
  .bg{ position:fixed; inset:0; pointer-events:none; z-index:-1; background:#000000; }
  [data-theme="light"] .bg { background: transparent; }
  html:not([data-theme="light"]) .bg .glow { display: none; }
  html:not([data-theme="light"]) .grain { opacity: 0; }
  .grain{
    position:absolute; inset:-40%;
    background-image:url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='180' height='180'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='.9' numOctaves='3' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='180' height='180' filter='url(%23n)' opacity='.25'/%3E%3C/svg%3E");
    transform: rotate(7deg);
    opacity:.22;
    mix-blend-mode: overlay;
  }
  .glow{ position:absolute; filter: blur(45px); opacity:.25; }
  .g1{ width:420px;height:420px; left:6%; top:22%; background:#22c55e; }
  .g2{ width:520px;height:520px; right:8%; top:10%; background:#7c3aed; }
  .g3{ width:420px;height:420px; right:18%; bottom:8%; background:#f59e0b; }
  
  /* header */
  .header{
    position:sticky; top:0; z-index:10;
    display:flex; align-items:center; justify-content:space-between;
    gap:16px;
    padding:14px 18px;
    background: var(--header-bg);
    backdrop-filter: blur(14px);
    border-bottom: 1px solid var(--border-color);
  }
  
  .brand{ display:flex; align-items:center; gap:12px; }
  .mark{
    width:44px; height:44px;
    display:grid; place-items:center;
    border-radius: 16px;
    background: linear-gradient(135deg, rgba(124,58,237,.35), rgba(34,197,94,.25));
    border: 1px solid rgba(255,255,255,.18);
    box-shadow: 0 12px 35px rgba(0,0,0,.35);
  }
  .mark img{
    width: 36px;
    height: 36px;
    display:block;
    object-fit: contain;
  }
  
  .brandText .name{ font-weight:800; letter-spacing:.2px; }
  .brandText .tag{ font-size:12px; color: rgba(255,255,255,.65); margin-top:2px; }
  
  .headerActions{ display:flex; gap:10px; flex-wrap:wrap; justify-content:flex-end; }
  
  .chip{
    padding:10px 12px;
    border-radius: 999px;
    border: 1px solid var(--border-color);
    background: rgba(255,255,255,.06);
    color: var(--text-main);
    cursor:pointer;
    transition: transform .12s ease, background .12s ease, border-color .12s ease;
  }
  .chip:hover{ transform: translateY(-1px); background: rgba(255,255,255,.09); border-color: rgba(255,255,255,.20); }
  .chipPrimary{
    background: linear-gradient(135deg, rgba(124,58,237,.95), rgba(59,130,246,.85));
    border-color: rgba(255,255,255,.18);
  }
  .chipGhost{ background: rgba(255,255,255,.03); }
  
  /* layout */
  .layout{
    display:grid;
    grid-template-columns: 320px 1fr;
    gap:14px;
    padding: 14px;
    max-width: 1400px;
    margin: 0 auto;
  }
  
  /* dock */
  .dock{ display:flex; flex-direction:column; gap:12px; }
  .dockCard{
    background: var(--card-bg);
    border: 1px solid var(--border-color);
    border-radius: 22px;
    padding: 14px;
    box-shadow: var(--shadow);
    color: var(--text-main);
  }
  .dockCard.note{
    background:
      linear-gradient(180deg, rgba(255,255,255,.085), rgba(255,255,255,.05)),
      radial-gradient(500px 250px at 10% 0%, rgba(34,197,94,.18), transparent 60%);
  }
  .dockTitle{ font-weight: 800; margin-bottom: 10px; }
  .dockTitle.small{ font-size: 12px; opacity:.78; text-transform: uppercase; }
  
  .dockRow{
    display:flex;
    align-items:center;
    justify-content:space-between;
    gap:10px;
    padding: 8px 0;
  }
  .dockRow.buttons{ justify-content:flex-start; gap:10px; flex-wrap:wrap; }
  
  .k{ font-size:12px; color: rgba(255,255,255,.65); }
  
  .select{
    width: 180px;
    padding: 10px 12px;
    border-radius: 14px;
    border: 1px solid var(--border-color);
    background: var(--input-bg);
    color: var(--text-main);
    outline:none;
  }
  
  .swatch{
    display:flex; align-items:center; gap:10px;
    padding: 8px 10px;
    border-radius: 14px;
    border: 1px solid rgba(255,255,255,.14);
    background: rgba(10, 12, 20, .35);
  }
  input[type="color"]{ width:38px; height:32px; border:none; padding:0; background:transparent; }
  .swatchLabel{ font-size:12px; color: rgba(255,255,255,.65); }
  
  .sliderWrap{ display:flex; align-items:center; gap:10px; width: 180px; }
  input[type="range"]{ width: 100%; }
  .pill{
    min-width: 36px;
    text-align:center;
    padding: 6px 8px;
    border-radius: 999px;
    border: 1px solid rgba(255,255,255,.14);
    background: rgba(255,255,255,.06);
    font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  }
  
  .dockSplit{ height:1px; background: rgba(255,255,255,.10); margin: 10px 0; }
  
  .toggle{ position:relative; width:46px; height:28px; }
  .toggle input{ position:absolute; inset:0; opacity:0; }
  .toggleUI{
    position:absolute; inset:0;
    border-radius: 999px;
    border:1px solid rgba(255,255,255,.16);
    background: rgba(255,255,255,.06);
    transition: .15s ease;
  }
  .toggleUI::after{
    content:"";
    position:absolute;
    top:3px; left:3px;
    width:20px; height:20px;
    border-radius:999px;
    background: rgba(255,255,255,.85);
    box-shadow: 0 10px 20px rgba(0,0,0,.25);
    transition: .15s ease;
  }
  .toggle input:checked + .toggleUI{
    background: linear-gradient(135deg, rgba(34,197,94,.55), rgba(124,58,237,.45));
    border-color: rgba(255,255,255,.22);
  }
  .toggle input:checked + .toggleUI::after{ transform: translateX(18px); }
  
  .btn{
    padding: 10px 12px;
    border-radius: 14px;
    border: 1px solid var(--border-color);
    background: rgba(255,255,255,.06);
    color: var(--text-main);
    cursor:pointer;
    transition: transform .12s ease, background .12s ease, border-color .12s ease;
  }
  .btn:hover{ transform: translateY(-1px); background: rgba(255,255,255,.09); border-color: rgba(255,255,255,.20); }
  .btn.danger{ background: rgba(239,68,68,.18); border-color: rgba(239,68,68,.35); }
  
  .hint{ margin: 8px 0 0; font-size: 12px; color: rgba(255,255,255,.75); line-height: 1.5; }
  
  /* stage */
  .stage{
    background: rgba(255,255,255,.04);
    border: 1px solid rgba(255,255,255,.10);
    border-radius: 26px;
    padding: 12px;
    box-shadow: var(--shadow);
    overflow:hidden;
  }
  
  .stageTop{
    display:flex;
    align-items:center;
    justify-content:space-between;
    gap:12px;
    padding: 6px 6px 12px;
  }
  
  .pages{ display:flex; align-items:center; gap:10px; flex-wrap:wrap; }
  .pageBtn{
    padding: 10px 12px;
    border-radius: 14px;
    border: 1px solid var(--border-color);
    background: rgba(255,255,255,.05);
    color: var(--text-main);
    cursor:pointer;
    transition:.12s ease;
  }
  .pageBtn:hover{ transform: translateY(-1px); background: rgba(255,255,255,.08); }
  .pageBtn.add{ border-color: rgba(34,197,94,.35); }
  .pageBtn.del{ border-color: rgba(239,68,68,.35); background: rgba(239,68,68,.12); }
  .pageBtn:disabled{ opacity:.55; cursor:not-allowed; transform:none; }
  
  .pageMeta{ display:flex; align-items:center; gap:10px; }
  .pageLabel{
    font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
    color: rgba(255,255,255,.70);
    font-size:12px;
  }
  .pageName{
    width: 180px;
    padding: 10px 12px;
    border-radius: 14px;
    border: 1px solid var(--border-color);
    background: var(--input-bg);
    color: var(--text-main);
    outline:none;
  }
  
  .view{ display:flex; align-items:center; gap:10px; }
  .zoom{
    padding: 9px 12px;
    border-radius: 999px;
    border: 1px solid var(--border-color);
    background: rgba(255,255,255,.06);
    font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
    color: var(--text-main);
  }
  
  /* paper */
  .paper{
    position:relative;
    border-radius: 18px;
    background:
      radial-gradient(1200px 700px at 10% 0%, rgba(0,0,0,.05), transparent 60%),
      linear-gradient(180deg, #ffffff, var(--paper));
    border: 1px solid rgba(0,0,0,.08);
    box-shadow: 0 18px 55px rgba(0,0,0,.25);
    overflow:hidden;
  }
  
  .tape{
    position:absolute;
    width: 140px;
    height: 44px;
    background: rgba(250, 204, 21, .22);
    border: 1px solid rgba(250, 204, 21, .25);
    transform: rotate(-8deg);
    border-radius: 10px;
  }
  .t1{ top: 10px; left: 14px; }
  .t2{ top: 10px; right: 14px; transform: rotate(9deg); }
  
  #canvas{
    width:100%;
    height: calc(100vh - 210px);
    display:block;
    background: transparent;
  }
  
  /* floating text editor */
  .canvasTextEditor{
    position: fixed;
    z-index: 9999;
    min-width: 180px;
    padding: 10px 12px;
    border-radius: 12px;
    border: 1px solid rgba(0,0,0,.18);
    background: #ffffff;
    color: #0f172a;
    box-shadow: 0 18px 55px rgba(0,0,0,.25);
    outline: none;
  }
  
  .footerTip{
    margin-top: 10px;
    color: rgba(255,255,255,.70);
    font-size: 12px;
    display:flex;
    align-items:center;
    gap:8px;
  }
  kbd{
    font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
    font-size: 12px;
    padding: 4px 8px;
    border-radius: 10px;
    background: rgba(255,255,255,.08);
    border: 1px solid rgba(255,255,255,.12);
  }
  
  @media (max-width: 980px){
    .layout{ grid-template-columns: 1fr; }
    #canvas{ height: calc(100vh - 300px); }
  }