:root { color-scheme: dark; }
  * { box-sizing: border-box; }
  body {
    margin: 0; display: flex; flex-direction: column; height: 100vh;
    background: #16181d; color: #d7dae0;
    font: 13px/1.5 "Segoe UI", "Microsoft JhengHei", sans-serif;
    overflow: hidden;
  }
  /* ---- menu bar ---- */
  #menubar {
    display: flex; gap: 2px; padding: 2px 6px;
    background: #1e2128; border-bottom: 1px solid #2c313a; flex: none;
  }
  .menu { position: relative; }
  .menu > button {
    background: none; border: none; color: #d7dae0; padding: 3px 10px;
    font: inherit; cursor: pointer; border-radius: 4px;
  }
  .menu > button:hover, .menu.open > button { background: #2c313a; }
  .menu ul {
    display: none; position: absolute; left: 0; top: 100%; z-index: 20;
    margin: 0; padding: 4px; list-style: none; min-width: 190px;
    background: #23262e; border: 1px solid #3c424e; border-radius: 6px;
    box-shadow: 0 6px 24px rgba(0,0,0,.5);
  }
  .menu.open ul { display: block; }
  .menu li { padding: 4px 12px; cursor: pointer; border-radius: 4px; white-space: nowrap; }
  .menu li:hover { background: #2b5db8; }
  .menu li.sep { padding: 0; margin: 4px 0; border-top: 1px solid #3c424e; cursor: default; }
  /* ---- toolbar ---- */
  #toolbar {
    display: flex; gap: 6px; align-items: center; padding: 5px 8px; flex-wrap: wrap;
    background: #1e2128; border-bottom: 1px solid #2c313a; flex: none;
  }
  select, button {
    background: #2c313a; color: #d7dae0; border: 1px solid #3c424e;
    border-radius: 4px; padding: 3px 8px; font: inherit; cursor: pointer;
  }
  button:hover { background: #384050; }
  button.primary { background: #2b5db8; border-color: #2b5db8; }
  button:disabled { opacity: .4; cursor: default; }
  /* 載入範例：放大 + 發光 */
  #btnExample {
    margin-left: auto;
    display: flex; flex-direction: column; align-items: center; line-height: 1.25;
    padding: 6px 22px;
    font-size: 15px; font-weight: 700;
    background: #1f7a3d; border-color: #2ea158;
    animation: exampleGlow 1.8s ease-in-out infinite;
  }
  #btnExample:hover { background: #27994d; }
  #btnExample small {
    font-size: 11px; font-weight: 400; color: #c8f0d5;
  }
  @keyframes exampleGlow {
    0%, 100% { box-shadow: 0 0 4px  #2ea15866; }
    50%      { box-shadow: 0 0 16px #2ea158cc, 0 0 32px #2ea15855; }
  }
  /* ---- main area ---- */
  #main { flex: 1; display: flex; min-height: 0; }
  #leftside { flex: 1; display: flex; flex-direction: column; min-width: 0; }
  #view { flex: 1; display: flex; align-items: center; justify-content: center; padding: 10px; min-height: 0; }
  #c {
    max-width: 100%; max-height: 100%;
    background: #fff; cursor: crosshair; image-rendering: pixelated;
    box-shadow: 0 4px 24px rgba(0,0,0,.5);
  }
  #log {
    flex: none; height: 90px; overflow-y: auto; margin: 0 10px 8px;
    background: #101216; border: 1px solid #2c313a; border-radius: 4px;
    padding: 4px 8px; font: 12px/1.5 Consolas, monospace; white-space: pre-wrap;
  }
  #panel {
    width: 300px; flex: none; padding: 8px 12px; overflow-y: auto;
    background: #1e2128; border-left: 1px solid #2c313a;
  }
  fieldset { border: 1px solid #3c424e; border-radius: 6px; margin: 0 0 10px; padding: 6px 10px; }
  legend { padding: 0 6px; color: #8ab4f8; font-weight: 600; }
  .ctl { margin: 2px 0 6px; }
  .ctl .lab { display: block; }
  .ctl input[type=range] { width: 100%; }
  .ctl select { width: 100%; }
  label.cb { display: flex; gap: 6px; align-items: center; margin: 4px 0; }
  /* ---- status bar ---- */
  #statusbar {
    flex: none; display: flex; border-top: 1px solid #2c313a; background: #1e2128;
    font-size: 12px; color: #9aa3b2;
  }
  #statusbar span { flex: 1; padding: 2px 10px; border-right: 1px solid #2c313a; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .hidden { display: none !important; }
  /* ---- pattern picker modal ---- */
  #pickerOverlay {
    position: fixed; inset: 0; display: none;
    align-items: center; justify-content: center;
    background: rgba(0,0,0,.6); z-index: 30;
  }
  #pickerOverlay.open { display: flex; }
  #pickerBox {
    display: flex; gap: 14px; padding: 16px;
    background: #1e2128; border: 1px solid #3c424e; border-radius: 8px;
    box-shadow: 0 8px 40px rgba(0,0,0,.6);
  }
  #pickerImgWrap { position: relative; cursor: crosshair; font-size: 0; align-self: flex-start; }
  #pickerImgWrap img { width: 500px; height: 500px; user-select: none; -webkit-user-drag: none; }
  #pickerMark {
    position: absolute; width: 14px; height: 14px; pointer-events: none;
    border: 2px solid #ff3b30; border-radius: 50%;
    transform: translate(-50%,-50%); left: -20px; top: -20px;
  }
  #pickerRight { width: 200px; display: flex; flex-direction: column; gap: 8px; font-size: 13px; }
  #pickerRight canvas { width: 200px; height: 200px; background: #fff; }
  #pickerVals { font-variant-numeric: tabular-nums; color: #aab2bf; white-space: pre-line; }
