  :root {
    --bg: #f4f4f7;
    --panel: #ffffff;
    --ink: #16161a;
    --muted: #6b6b76;
    --line: #e3e3ea;
    --accent: #4f46e5;
    --accent-weak: #eef0fe;
    --danger: #c0392b;
    --radius: 14px;
    --shadow: 0 1px 2px rgba(16,16,26,.04), 0 8px 24px rgba(16,16,26,.06);
  }
  * { box-sizing: border-box; }
  html, body { height: 100%; }
  body {
    margin: 0;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", system-ui, sans-serif;
    color: var(--ink);
    background: var(--bg);
    line-height: 1.45;
    display: flex;
    flex-direction: column;
    overflow: hidden;
  }
  .app-header {
    display: flex;
    align-items: center;
    gap: 14px;
    padding: 18px 24px;
    border-bottom: 1px solid var(--line);
    background: var(--panel);
  }
  .logo {
    width: 38px; height: 38px;
    display: grid; place-items: center;
    border-radius: 10px;
    background: linear-gradient(135deg, #2a2a32, #16161a);
    border: 1px solid var(--line);
    color: #f4f4f7;
    font-size: 21px;
    font-weight: 700;
    line-height: 1;
    /* embossed/raised look to echo the relief ("Ukibori") theme */
    text-shadow: 0 1px 0 rgba(255,255,255,.28), 0 -1px 1px rgba(0,0,0,.55);
  }
  .app-header h1 { margin: 0; font-size: 17px; letter-spacing: -.01em; }
  .app-header h1 .kanji { color: var(--muted); font-weight: 600; font-size: 13px; margin-left: 5px; letter-spacing: .04em; }
  .app-header .tagline { margin: 2px 0 0; font-size: 12.5px; color: var(--muted); }

  main {
    flex: 1;
    min-height: 0;
    width: 100%;
    max-width: 1280px;
    margin: 0 auto;
    padding: 18px 24px 24px;
    display: flex;
    flex-direction: column;
    gap: 14px;
  }

  /* Side-by-side workspace: options sidebar (left) + image area (right). */
  .workspace {
    flex: 1;
    min-height: 0;
    display: flex;
    gap: 14px;
  }
  body:not(.has-image) .workspace { display: none; }

  .sidebar {
    width: 320px;
    flex-shrink: 0;
    display: flex;
    flex-direction: column;
    min-height: 0;
    background: var(--panel);
    border: 1px solid var(--line);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
  }
  .sidebar-head {
    padding: 14px 18px 12px;
    border-bottom: 1px solid var(--line);
  }
  .sidebar-footer {
    border-top: 1px solid var(--line);
    padding: 14px 18px;
    display: flex;
    flex-direction: column;
    gap: 8px;
  }
  .sidebar-footer #download { width: 100%; }
  .sidebar-footer .status { font-size: 12.5px; }

  /* Accordion sections */
  .acc { border-top: 1px solid var(--line); }
  #controls .acc:first-child { border-top: 0; }
  .acc > summary {
    list-style: none;
    cursor: pointer;
    user-select: none;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 14px 0;
    font-size: 13px;
    font-weight: 600;
    color: var(--ink);
  }
  .acc > summary::-webkit-details-marker { display: none; }
  .acc > summary::after {
    content: "\25b8";
    color: var(--muted);
    font-size: 11px;
    transition: transform .15s;
  }
  .acc[open] > summary::after { transform: rotate(90deg); }
  .acc-body { padding-bottom: 16px; display: flex; flex-direction: column; gap: 16px; }

  /* Dropzone */
  .dropzone {
    border: 2px dashed #c4c4cf;
    border-radius: var(--radius);
    background: var(--panel);
    padding: 30px 24px;
    text-align: center;
    cursor: pointer;
    transition: border-color .15s, background .15s, padding .15s;
  }
  .dropzone:hover { border-color: var(--accent); }
  .dropzone.dragover { border-color: var(--accent); background: var(--accent-weak); }
  .dropzone .drop-icon { font-size: 26px; line-height: 1; }
  .dropzone .drop-title { margin: 10px 0 2px; font-weight: 600; }
  .dropzone .drop-sub { margin: 0; font-size: 13px; color: var(--muted); }
  .dropzone .drop-compact { display: none; font-size: 13px; font-weight: 600; color: var(--muted); }
  .link { color: var(--accent); cursor: pointer; font-weight: 600; }

  /* Before an image is loaded the dropzone fills the empty space. */
  body:not(.has-image) .dropzone { flex: 1; display: grid; place-items: center; }
  /* After loading it collapses to a slim bar to give the preview room. */
  body.has-image .dropzone { padding: 10px 16px; }
  body.has-image .dropzone .drop-full { display: none; }
  body.has-image .dropzone .drop-compact { display: block; }

  /* Toolbar */
  [hidden] { display: none !important; }
  .toolbar {
    flex: 1;
    min-height: 0;
    overflow-y: auto;
    padding: 4px 18px 0;
    transition: opacity .15s;
  }
  .toolbar.disabled { opacity: .5; pointer-events: none; }
  .seg-group.mode-switch { display: flex; width: 100%; }
  .seg-group.mode-switch .seg { flex: 1; text-align: center; }
  .fields {
    display: grid;
    grid-template-columns: 1fr;
    gap: 16px;
    align-items: end;
  }
  .actions { display: flex; flex-wrap: wrap; align-items: center; gap: 10px; }

  /* Segmented control */
  .seg-group { display: inline-flex; background: var(--bg); border: 1px solid var(--line); border-radius: 10px; padding: 3px; gap: 3px; }
  .seg {
    font: inherit; font-size: 13px; font-weight: 600;
    padding: 7px 14px; border: 0; border-radius: 7px;
    background: transparent; color: var(--muted); cursor: pointer;
    transition: background .12s, color .12s;
  }
  .seg:hover { color: var(--ink); }
  .seg.seg-active { background: #fff; color: var(--ink); box-shadow: 0 1px 2px rgba(16,16,26,.08); }
  .seg-group.seg-sm .seg { padding: 5px 11px; font-size: 12.5px; }

  .field { display: flex; flex-direction: column; gap: 8px; }
  .field-head { display: flex; align-items: center; justify-content: space-between; }
  .field-head label { font-size: 12.5px; font-weight: 600; color: var(--muted); }
  .badge {
    font-variant-numeric: tabular-nums;
    font-size: 12px; font-weight: 600;
    background: var(--accent-weak); color: var(--accent);
    padding: 2px 9px; border-radius: 999px; min-width: 34px; text-align: center;
  }
  input[type=range] { width: 100%; accent-color: var(--accent); cursor: pointer; }
  .field-actions { flex-direction: row; flex-wrap: wrap; align-items: center; gap: 10px; }

  .btn {
    font: inherit; font-size: 13px; font-weight: 600;
    padding: 9px 14px; border-radius: 10px;
    border: 1px solid var(--line); background: #fff; color: var(--ink);
    cursor: pointer; transition: background .12s, border-color .12s, transform .05s;
  }
  .btn:hover { background: #f7f7fb; }
  .btn:active { transform: translateY(1px); }
  .btn-primary { background: var(--accent); border-color: var(--accent); color: #fff; }
  .btn-primary:hover { background: #4338ca; }

  .toggle { display: inline-flex; align-items: center; gap: 7px; font-size: 13px; font-weight: 600; cursor: pointer; user-select: none; }
  .toggle input { width: 16px; height: 16px; accent-color: var(--accent); cursor: pointer; }

  input[type=color] {
    width: 100%; max-width: 64px; height: 34px; padding: 2px;
    border: 1px solid var(--line); border-radius: 8px; background: #fff; cursor: pointer;
  }
  .fields.circle-row,
  .fields.threed-row { margin-top: 0; padding-top: 0; border-top: 0; }

  .hint { font-size: 11.5px; color: var(--muted); }
  .status { margin: 0; font-size: 13px; color: var(--muted); }
  .status.error { color: var(--danger); font-weight: 600; }

  /* Preview */
  .preview {
    display: none;
    border: 1px solid var(--line);
    border-radius: var(--radius);
    padding: 16px;
    background-color: #fff;
    background-image:
      linear-gradient(45deg, #ececf2 25%, transparent 25%),
      linear-gradient(-45deg, #ececf2 25%, transparent 25%),
      linear-gradient(45deg, transparent 75%, #ececf2 75%),
      linear-gradient(-45deg, transparent 75%, #ececf2 75%);
    background-size: 20px 20px;
    background-position: 0 0, 0 10px, 10px -10px, -10px 0;
    box-shadow: var(--shadow);
  }
  .preview.ready {
    display: flex;
    flex: 1;
    min-height: 0;
    align-items: center;
    justify-content: center;
  }
  #output {
    max-width: 100%;
    max-height: 100%;
    width: auto;
    height: auto;
    border-radius: 6px;
    box-shadow: 0 2px 10px rgba(16,16,26,.18);
    background: #fff;
  }
  /* When keeping transparency, let the preview's checkerboard show through. */
  body.alpha #output { background: transparent; }

  /* Narrow windows: fall back to stacked layout. */
  @media (max-width: 860px) {
    body { overflow: auto; }
    .workspace { flex-direction: column; }
    .sidebar { width: 100%; }
    .toolbar { overflow-y: visible; }
    .preview.ready { min-height: 360px; }
  }
