:root {
    --bg: #0e1116;
    --panel: #171b22;
    --panel-2: #1d222b;
    --border: #2a2f3a;
    --text: #fff;
    --text-dim: #fff;
    --accent: #4f7cff;
    --accent-soft: #2dd4bf;
  }
  * { box-sizing: border-box; }
  html, body { margin: 0; height: 100%; }
  body {
    font-family: -apple-system, "Segoe UI", "Hiragino Kaku Gothic ProN", Meiryo, sans-serif;
    background: var(--bg);
    color: var(--text);
    display: flex;
    flex-direction: column;
    height: 100vh;
    overflow: hidden;
  }

  /* ---------- Top bar ---------- */
  .topbar {
    height: 48px;
    flex: 0 0 48px;
    background: var(--panel);
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    padding: 0 16px;
    gap: 12px;
    position: relative;
  }
  .topbar .brand { font-weight: 600; font-size: 14px; }
  /* 左上のホームボタン(家アイコン) */
  .topbar .home-btn {
    display: inline-flex; align-items: center; justify-content: center;
    width: 34px; height: 34px; border-radius: 8px;
    color: #fff; text-decoration: none; flex: 0 0 auto;
    transition: background 0.12s ease;
  }
  .topbar .home-btn:hover { background: #262c37; }
  .topbar .home-btn svg { display: block; fill: #fff; }
  /* ページ見出しをトップバー内に収める(独立バーを廃止して高さ節約) */
  .topbar-h1 {
    margin: 0; min-width: 0;
    font-size: 14px; font-weight: 600; color: #aab2c0;
    white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
    border-left: 1px solid var(--border); padding-left: 12px;
  }
  .topbar .brand-logo {
    height: 28px;
    width: auto;
    display: block;
    margin-right: 4px;
  }
  .topbar .spacer { flex: 1; }
  .topbar button {
    background: var(--panel-2);
    color: var(--text);
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 6px 14px;
    font-size: 13px;
    cursor: pointer;
  }
  .topbar button:hover { background: #262c37; }
  .topbar button:disabled { opacity: 0.35; cursor: not-allowed; }
  .topbar button:disabled:hover { background: var(--panel-2); }
  #btnUndo, #btnRedo { font-size: 22px; padding: 2px 12px; line-height: 1; }
  .topbar .tutorial-link {
    color: var(--text); text-decoration: none;
    font-size: 13px; padding: 5px 12px;
    border-radius: 8px; border: 1px solid var(--border);
    background: var(--panel-2); white-space: nowrap;
  }
  .topbar .tutorial-link:hover { background: #262c37; }
  .topbar button.primary {
    background: var(--accent);
    border-color: var(--accent);
    color: #fff;
  }
  /* 「メニュー」ボタンはPCでは非表示(常設サイドバーを使う)。スマホでのみ表示。 */
  .menu-toggle { display: none; }

  /* 姉妹サイトへのリンク(PCのみ表示。色付きボタン風) */
  .site-links {
    display: flex;
    align-items: center;
    gap: 10px;
    font-size: 13px;
    position: absolute;
    left: 50%;
    transform: translateX(-50%);
  }
  .site-links a {
    color: #fff;
    text-decoration: none;
    white-space: nowrap;
    padding: 5px 12px;
    border-radius: 8px;
    font-weight: 600;
    transition: opacity 0.15s, transform 0.15s;
  }
  .site-links a:hover {
    opacity: 0.88;
    transform: translateY(-1px);
  }
  /* 各サイトのテーマカラー */
  .site-links a:nth-child(1) { background: #4f7cff; }  /* アジアのカレンダー: 青 */
  .site-links a:nth-child(2) { background: #e0598b; }  /* ウェブカラー: ピンク */
  .site-links a:nth-child(3) { background: #e8883a; }  /* 絵文字: オレンジ */

  /* ---------- Body ---------- */
  .body { flex: 1; display: flex; min-height: 0; }

  /* ---------- Sidebar ---------- */
  .sidebar {
    width: 248px;
    flex: 0 0 248px;
    background: var(--panel);
    border-right: 1px solid var(--border);
    overflow-y: auto;
    padding: 14px 12px;
  }
  .sidebar h2 { font-size: 15px; margin: 4px 4px 12px; }
  .group-title {
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    color: var(--text-dim);
    margin: 16px 6px 6px;
  }
  .tool {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 9px 10px;
    border-radius: 8px;
    font-size: 13px;
    color: var(--text);
    cursor: pointer;
    user-select: none;
  }
  .tool:hover { background: var(--panel-2); }
  .tool.active { background: var(--panel-2); outline: 1px solid var(--accent); }
  .tool .ico { width: 16px; text-align: center; opacity: 0.8; }
  .tool .ico i { font-size: 16px; line-height: 1; vertical-align: middle; }
  .tool .badge {
    margin-left: auto;
    font-size: 10px;
    color: var(--accent-soft);
  }
  .tool.disabled { opacity: 0.4; cursor: default; }
  .tool.disabled:hover { background: transparent; }

  /* ---------- Canvas area ---------- */
  .stage {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    background:
      repeating-conic-gradient(#171b22 0% 25%, #14181f 0% 50%) 50% / 24px 24px;
    position: relative;
    overflow: hidden;
    cursor: grab;
    touch-action: none;
  }
  .stage.drag-over { outline: 2px dashed var(--accent); outline-offset: -10px; }
  .stage.drag-over::after {
    content: "Drop your image here";
    position: absolute; inset: 0;
    display: flex; align-items: center; justify-content: center;
    font-size: 16px; color: var(--accent);
    background: rgba(79,124,255,0.08);
    pointer-events: none;
  }
  .stage canvas {
    display: block;
    width: 100%;
    height: 100%;
    box-shadow: 0 8px 40px rgba(0,0,0,0.5);
    background: #fff;
  }
  .canvas-wrap {
    position: relative;
    display: inline-block;
    line-height: 0;
  }
  .grid-overlay {
    position: absolute; inset: 0;
    pointer-events: none;
  }
  .grid-line {
    position: absolute;
    background: rgba(255,255,255,0.7);
    box-shadow: 0 0 4px rgba(0,0,0,0.5);
  }
  .grid-line.h { left: 0; right: 0; height: 1px; }
  .grid-line.v { top: 0; bottom: 0; width: 1px; }

  /* テキストレイヤー(canvasに重ねる) */
  .text-layer {
    position: absolute; inset: 0;
    pointer-events: none;
  }
  .text-layer.active { pointer-events: auto; }
  .text-element {
    position: absolute;
    cursor: move;
    padding: 2px 4px;
    white-space: pre;   /* 改行(\n)をそのまま表示。焼き込みと同じ挙動にそろえる */
    user-select: none;
    line-height: 1.2;
    box-sizing: border-box;
  }
  .text-element.selected {
    outline: 2px dashed #4f7cff;
    outline-offset: 2px;
  }
  .text-element.editing {
    cursor: text;
    user-select: text;
    outline: 2px solid #4f7cff;
  }
  .text-element:hover:not(.selected):not(.editing) {
    outline: 1px dashed rgba(79,124,255,0.5);
    outline-offset: 2px;
  }

  /* モザイク等の領域選択オーバーレイ */
  .region-overlay {
    position: absolute; inset: 0;
    cursor: crosshair;
    pointer-events: none;
  }
  .region-overlay.active { pointer-events: auto; }
  .region-rect {
    position: absolute;
    border: 2px dashed #4f7cff;
    background: rgba(79, 124, 255, 0.15);
    box-sizing: border-box;
    pointer-events: none;
  }

  /* 図形レイヤー(SVG) */
  .shape-layer {
    position: absolute; inset: 0;
    width: 100%; height: 100%;
    pointer-events: none;
    overflow: visible;
  }
  .shape-layer.active { pointer-events: auto; }
  .shape-layer .shape { cursor: move; }
  .shape-layer .shape.line { cursor: move; }
  .shape-layer .selection-rect {
    fill: none;
    stroke: #4f7cff;
    stroke-width: 1;
    stroke-dasharray: 4 3;
    pointer-events: none;
    vector-effect: non-scaling-stroke;
  }
  .shape-layer .handle {
    fill: #ffffff;
    stroke: #333;
    stroke-width: 1;
    cursor: pointer;
    vector-effect: non-scaling-stroke;
  }
  .shape-layer .handle[data-h="line-a"], .shape-layer .handle[data-h="line-b"] { cursor: crosshair; }

  /* ---------- 画像を重ねる(オーバーレイ) ---------- */
  .overlay-layer {
    position: absolute; inset: 0;
    width: 100%; height: 100%;
    pointer-events: none;
    overflow: visible;
  }
  .overlay-layer.active { pointer-events: auto; }
  .overlay-layer .ov-image { cursor: move; }
  .overlay-layer .ov-frame {
    fill: none;
    stroke: #4f7cff;
    stroke-width: 1;
    stroke-dasharray: 4 3;
    pointer-events: none;
    vector-effect: non-scaling-stroke;
  }
  .overlay-layer .ov-handle {
    fill: #ffffff;
    stroke: #333;
    stroke-width: 1;
    cursor: pointer;
    vector-effect: non-scaling-stroke;
  }

  /* 四隅ごとに斜めのリサイズ矢印カーソルを出す */
  .overlay-layer .ov-handle[data-h="nw"],
  .overlay-layer .ov-handle[data-h="se"] { cursor: nwse-resize; }
  .overlay-layer .ov-handle[data-h="ne"],
  .overlay-layer .ov-handle[data-h="sw"] { cursor: nesw-resize; }
  /* 回転ハンドルは丸、リサイズ(角)は四角。回転は線でつないで区別する */
  .overlay-layer .ov-rotate {
    fill: #4f7cff;
    stroke: #fff;
    stroke-width: 1;
    cursor: grab;
    vector-effect: non-scaling-stroke;
  }
  .overlay-layer .ov-rotate-stem {
    stroke: #4f7cff;
    stroke-width: 1;
    vector-effect: non-scaling-stroke;
    pointer-events: none;
  }
  /* crop overlay は canvas にぴったり重ねる */
  .crop-overlay {
    position: absolute; inset: 0;
    cursor: crosshair;
  }
  .crop-rect {
    position: absolute;
    border: 1px solid #fff;
    box-shadow:
      0 0 0 9999px rgba(0,0,0,0.5),  /* 選択範囲外を暗く */
      inset 0 0 0 1px rgba(0,0,0,0.4);
    box-sizing: border-box;
    cursor: move;
  }
  /* 三分割グリッド線(horizontal 2本 + vertical 2本)*/
  .crop-rect::before, .crop-rect::after {
    content: ""; position: absolute; inset: 0; pointer-events: none;
  }
  .crop-rect::before {
    background:
      linear-gradient(to right, transparent 33.33%, rgba(255,255,255,0.4) 33.33%, rgba(255,255,255,0.4) calc(33.33% + 1px), transparent calc(33.33% + 1px), transparent 66.66%, rgba(255,255,255,0.4) 66.66%, rgba(255,255,255,0.4) calc(66.66% + 1px), transparent calc(66.66% + 1px));
  }
  .crop-rect::after {
    background:
      linear-gradient(to bottom, transparent 33.33%, rgba(255,255,255,0.4) 33.33%, rgba(255,255,255,0.4) calc(33.33% + 1px), transparent calc(33.33% + 1px), transparent 66.66%, rgba(255,255,255,0.4) 66.66%, rgba(255,255,255,0.4) calc(66.66% + 1px), transparent calc(66.66% + 1px));
  }
  .crop-handle {
    position: absolute;
    box-sizing: border-box;
    background: transparent;
    border: 0 solid #fff;
    z-index: 6;              /* 枠(move)より前面。判定を確実に拾う */
  }
  /* 角より辺(n/s/e/w)を優先。角のL字は面積が広く、辺の判定を食いやすいため */
  .crop-handle[data-h="n"], .crop-handle[data-h="s"],
  .crop-handle[data-h="e"], .crop-handle[data-h="w"] { z-index: 8; }
  /* 掴み判定は crop.js の pickHandleAt() が「最も近いハンドル」を距離で選ぶ。
     そのため CSS 側の透明な当たり判定は不要(::before は四隅の描画に使う)。 */
  /* 四隅: L字ブラケット。border だと線端が角ばるので、丸い棒2本で描く。
     ::before = 横棒 / ::after = 縦棒。どちらも border-radius で端を丸める。 */
  .crop-handle[data-h="nw"], .crop-handle[data-h="ne"],
  .crop-handle[data-h="se"], .crop-handle[data-h="sw"] {
    border: 0;
    filter: drop-shadow(0 0 1px rgba(0,0,0,0.7));
  }
  .crop-handle[data-h="nw"]::before, .crop-handle[data-h="ne"]::before,
  .crop-handle[data-h="se"]::before, .crop-handle[data-h="sw"]::before,
  .crop-handle[data-h="nw"]::after,  .crop-handle[data-h="ne"]::after,
  .crop-handle[data-h="se"]::after,  .crop-handle[data-h="sw"]::after {
    content: "";
    position: absolute;
    inset: auto;
    background: #fff;
    border-radius: 999px;
  }
  /* 横棒: 幅いっぱい・太さ --t */
  .crop-handle[data-h="nw"]::before, .crop-handle[data-h="ne"]::before,
  .crop-handle[data-h="se"]::before, .crop-handle[data-h="sw"]::before {
    left: 0; right: 0; height: var(--t, 3px);
  }
  /* 縦棒: 高さいっぱい・太さ --t */
  .crop-handle[data-h="nw"]::after, .crop-handle[data-h="ne"]::after,
  .crop-handle[data-h="se"]::after, .crop-handle[data-h="sw"]::after {
    top: 0; bottom: 0; width: var(--t, 3px);
  }
  /* 角ごとに棒を寄せる */
  .crop-handle[data-h="nw"]::before { top: 0; }
  .crop-handle[data-h="nw"]::after  { left: 0; }
  .crop-handle[data-h="ne"]::before { top: 0; }
  .crop-handle[data-h="ne"]::after  { right: 0; }
  .crop-handle[data-h="se"]::before { bottom: 0; }
  .crop-handle[data-h="se"]::after  { right: 0; }
  .crop-handle[data-h="sw"]::before { bottom: 0; }
  .crop-handle[data-h="sw"]::after  { left: 0; }
  .crop-handle[data-h="nw"] { cursor: nwse-resize; }
  .crop-handle[data-h="ne"] { cursor: nesw-resize; }
  .crop-handle[data-h="se"] { cursor: nwse-resize; }
  .crop-handle[data-h="sw"] { cursor: nesw-resize; }
  /* 各辺: 中央の白いバー */
  .crop-handle[data-h="n"], .crop-handle[data-h="s"] { cursor: ns-resize; }
  .crop-handle[data-h="e"], .crop-handle[data-h="w"] { cursor: ew-resize; }
  .crop-handle[data-h="n"], .crop-handle[data-h="s"],
  .crop-handle[data-h="e"], .crop-handle[data-h="w"] {
    background: #fff;
    border-radius: 4px;
    box-shadow: 0 0 2px rgba(0,0,0,0.6);
  }
  /* ---------- カット用ガイド線 ---------- */
  .cut-overlay {
    position: absolute; inset: 0;
    pointer-events: none;
  }
  /* Trim のガイド線: 破線(方向ごとに .h/.v でグラデーションの向きを変える) */
  .cut-line {
    position: absolute;
    background: transparent;
    z-index: 5;
    pointer-events: auto;
    filter: drop-shadow(0 0 1px rgba(0,0,0,0.8));   /* 明るい画像でも見えるよう縁取り */
  }
  .cut-line.h {
    background-image: repeating-linear-gradient(
      to right, #ff3b30 0 10px, transparent 10px 18px);
  }
  .cut-line.v {
    background-image: repeating-linear-gradient(
      to bottom, #ff3b30 0 10px, transparent 10px 18px);
  }
  .cut-line.h {
    left: 0; right: 0; height: 3px;
    cursor: ns-resize;
  }
  .cut-line.v {
    top: 0; bottom: 0; width: 3px;
    cursor: ew-resize;
  }
  .cut-line::before {
    content: "";
    position: absolute;
  }
  .cut-line.h::before { left: 0; right: 0; top: 50%; height: var(--cut-hit, 22px); transform: translateY(-50%); }
  .cut-line.v::before { top: 0; bottom: 0; left: 50%; width: var(--cut-hit, 22px); transform: translateX(-50%); }
  .cut-shade {
    position: absolute;
    background: rgba(0,0,0,0.45);
    pointer-events: none;
  }
  /* カットのガイド線の両端マーカー(白い三角) */
  .cut-arrow {
    position: absolute;
    width: 0; height: 0;
    pointer-events: auto;
    cursor: inherit;
  }

  /* 三角の周りに透明なつかみ枠を広げる(線の延長線上もつかめるように) */
  .cut-arrow::before {
    content: "";
    position: absolute;
    width: var(--cut-hit, 40px);
    height: var(--cut-hit, 40px);
    left: 50%;
    top: 50%;
    transform: translate(-50%, -50%);
    pointer-events: auto;
  }
  /* 水平線: 左端に右向き▶、右端に左向き◀(線の外側に出す) */
  .cut-line.h .cut-arrow-a {
    left: 0; top: 50%;
    transform: translate(calc(-100% - 12px), -50%);
    border-top: var(--cut-arrow, 10px) solid transparent;
    border-bottom: var(--cut-arrow, 10px) solid transparent;
    border-left: var(--cut-arrow, 10px) solid #fff;
  }
  .cut-line.h .cut-arrow-b {
    right: 0; top: 50%;
    transform: translate(calc(100% + 12px), -50%);
    border-top: var(--cut-arrow, 10px) solid transparent;
    border-bottom: var(--cut-arrow, 10px) solid transparent;
    border-right: var(--cut-arrow, 10px) solid #fff;
  }
  /* 垂直線: 上端に下向き▼、下端に上向き▲ */
  .cut-line.v .cut-arrow-a {
    top: 0; left: 50%;
    transform: translate(-50%, -100%);
    border-left: var(--cut-arrow, 10px) solid transparent;
    border-right: var(--cut-arrow, 10px) solid transparent;
    border-top: var(--cut-arrow, 10px) solid #fff;
  }
  .cut-line.v .cut-arrow-b {
    bottom: 0; left: 50%;
    transform: translate(-50%, 100%);
    border-left: var(--cut-arrow, 10px) solid transparent;
    border-right: var(--cut-arrow, 10px) solid transparent;
    border-bottom: var(--cut-arrow, 10px) solid #fff;
  }
  .empty {
    color: var(--text-dim);
    font-size: 14px;
    text-align: center;
    line-height: 1.8;
  }
  .empty button {
    margin-top: 12px;
    background: var(--accent);
    border: none;
    color: #fff;
    padding: 8px 18px;
    border-radius: 8px;
    cursor: pointer;
    font-size: 13px;
  }
  .formats-hint {
    margin-top: 18px;
    font-size: 16px;
    color: var(--text-dim);
  }

  /* ---------- Right options panel ---------- */
  .options {
    width: 280px;
    flex: 0 0 280px;
    background: var(--panel);
    border-left: 1px solid var(--border);
    padding: 16px 16px;
    overflow-y: auto;
  }
  .options h3 { font-size: 14px; margin: 0 0 4px; }
  .options .hint { font-size: 12px; color: var(--text-dim); margin: 0 0 16px; }
  .home-lead {
    font-size: 13px; line-height: 1.85;
    color: #fff; margin: 0 0 16px;
  }
  .field { margin-bottom: 14px; }
  .field label { display: block; font-size: 12px; color: var(--text-dim); margin-bottom: 5px; }
  .field input[type="number"] {
    width: 100%;
    background: var(--panel-2);
    border: 1px solid var(--border);
    border-radius: 7px;
    color: var(--text);
    padding: 8px 10px;
    font-size: 13px;
  }
  .row { display: flex; gap: 10px; align-items: flex-end; }
  .row .field { flex: 1; margin-bottom: 0; }
  .lock-row {
    display: flex; align-items: center; gap: 8px;
    font-size: 12px; color: var(--text-dim);
    margin: 12px 0 16px; cursor: pointer; user-select: none;
  }
  .lock-row input { accent-color: var(--accent); }
  .preset-row { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 16px; }
  .preset {
    font-size: 12px; padding: 5px 10px;
    background: var(--panel-2); border: 1px solid var(--border);
    border-radius: 999px; cursor: pointer; color: var(--text);
  }
  .preset:hover { border-color: var(--accent); }
  .options .apply {
    width: 100%; background: var(--accent); color: #fff; border: none;
    padding: 10px; border-radius: 8px; font-size: 13px; cursor: pointer;
    margin-top: 4px;
  }
  .options .apply:hover { background: #3f6ae6; }
  .options .reset {
    width: 100%; background: transparent; color: var(--text-dim);
    border: 1px solid var(--border); padding: 9px; border-radius: 8px;
    font-size: 12px; cursor: pointer; margin-top: 8px;
  }
  .meta { font-size: 12px; color: var(--text-dim); margin-top: 18px; line-height: 1.7; }

  .divider { height: 1px; background: var(--border); margin: 18px 0; }
  .seg { display: flex; gap: 6px; }
  .seg-wrap { flex-wrap: wrap; }
  .seg-wrap .seg-btn { flex: 0 0 calc(33.33% - 4px); }
  .seg-multi { flex-wrap: wrap; }
  .seg-multi .seg-btn { flex: 0 0 calc(33.33% - 4px); }
  .fmt-note {
    font-size: 11px; color: var(--text-dim); line-height: 1.6;
    background: var(--panel-2); border: 1px solid var(--border);
    border-radius: 7px; padding: 8px 10px; margin-bottom: 14px;
  }
  .seg-btn {
    flex: 1; text-align: center; font-size: 12px;
    padding: 7px 0; border-radius: 7px; cursor: pointer;
    background: var(--panel-2); border: 1px solid var(--border); color: var(--text);
    user-select: none;
  }
  .seg-btn:hover { border-color: var(--accent); }
  .seg-btn.active { background: var(--accent); border-color: var(--accent); color: #fff; }
  .options input[type="range"] { width: 100%; accent-color: var(--accent); }
  .size-est { font-size: 12px; color: var(--accent-soft); margin-top: 10px; min-height: 16px; }
  .color-row { display: flex; gap: 6px; align-items: stretch; }
  .color-row input[type="color"] {
    flex: 1; height: 36px;
    border: 1px solid var(--border); border-radius: 7px;
    background: var(--panel-2);
    min-width: 0;
  }
  .eyedrop-btn {
    width: 36px; height: 36px;
    background: var(--accent);
    border: 1px solid var(--accent);
    border-radius: 7px;
    color: #fff;
    cursor: pointer;
    font-size: 16px;
    line-height: 1;
    padding: 0;
    flex-shrink: 0;
  }
  .eyedrop-btn:hover { background: #3f6ae6; }
  .eyedrop-btn.picking { background: var(--accent-soft); color: #000; }

  /* Color Picker カーソルマーカー(5pxの小さな点、マウスに追従) */
  .picker-dot {
    position: fixed;
    pointer-events: none;
    z-index: 9999;
    width: 5px; height: 5px;
    border-radius: 50%;
    background: #fff;
    box-shadow: 0 0 0 1px #000, 0 0 4px rgba(0,0,0,0.6);
    transform: translate(-50%, -50%);
  }
  .picker-sample {
    width: 100%; height: 70px;
    border-radius: 8px;
    border: 1px solid var(--border);
    background: var(--panel-2);
    display: flex; align-items: center; justify-content: center;
    font-size: 12px; color: var(--accent-soft);
    margin-bottom: 12px;
  }
  .picker-sample.active {
    color: #fff;
    text-shadow: 0 1px 2px rgba(0,0,0,0.6);
  }
  .picker-value { margin-bottom: 8px; }
  .picker-row {
    display: flex; align-items: center; gap: 8px;
    background: var(--panel-2);
    border: 1px solid var(--border);
    border-radius: 7px;
    padding: 6px 10px;
  }
  .picker-row label {
    font-size: 11px; color: var(--accent-soft);
    min-width: 40px;
    margin: 0;
  }
  .picker-val {
    flex: 1; font-family: monospace; font-size: 13px;
    color: var(--text);
    word-break: break-all;
  }
  .copy-btn {
    background: var(--accent);
    border: 1px solid var(--accent);
    color: #fff;
    border-radius: 5px;
    padding: 3px 10px;
    font-size: 11px;
    cursor: pointer;
    flex-shrink: 0;
  }
  .copy-btn:hover { background: #3f6ae6; }
  .copy-btn.copied { background: #2eae5a; border-color: #2eae5a; }
  .picker-history-label {
    display: block; font-size: 12px; color: var(--accent-soft);
    margin-bottom: 6px;
  }
  .picker-history {
    display: flex; flex-wrap: wrap; gap: 6px;
    min-height: 28px;
    margin-bottom: 8px;
  }
  .picker-swatch {
    width: 28px; height: 28px;
    border: 2px solid var(--border);
    border-radius: 5px;
    cursor: pointer;
  }
  .picker-swatch:hover { border-color: var(--accent); }
  canvas.picker-active { cursor: crosshair !important; }
  .filename-row { display: flex; align-items: stretch; gap: 0; }
  .filename-row input {
    flex: 1; min-width: 0;
    background: var(--panel-2); border: 1px solid var(--border);
    border-right: none; border-radius: 7px 0 0 7px;
    color: var(--text); padding: 8px 10px; font-size: 13px;
  }
  .ext-tag {
    display: flex; align-items: center; padding: 0 10px;
    background: var(--panel); border: 1px solid var(--border);
    border-radius: 0 7px 7px 0; color: var(--text-dim); font-size: 13px;
    white-space: nowrap;
  }

  /* ---------- Bottom bar ---------- */
  .bottombar {
    height: 70px; flex: 0 0 70px;
    background: var(--panel);
    border-top: 1px solid var(--border);
    display: flex; align-items: center; justify-content: center;
    gap: 14px;
    position: relative;          /* ← 追加(広告の絶対配置の基準) */
  }
  .bottombar button {
    background: transparent; border: none; color: var(--text-dim);
    cursor: pointer; font-size: 16px; padding: 4px 8px;
  }
  .bottombar button:hover { color: var(--text); }
  .bottombar input[type="range"] { width: 160px; accent-color: var(--accent); }
  .bottombar .zoom-val { font-size: 12px; color: var(--text-dim); width: 42px; text-align: right; }
  /* ズーム操作をまとめて、残りスペースの中央に配置 */
  /* ズーム操作をバー全体の中央に配置 */
  .bottombar-zoom {
    display: flex; align-items: center; justify-content: center;
    gap: 14px;
  }
  /* 右端の広告バナー(468×60)。絶対配置にして中央寄せに影響させない */
  .bottombar-ad {
    position: absolute; right: 16px; top: 50%; transform: translateY(-50%);
    line-height: 0;
  }
  /* 狭い画面では中央のズーム操作と重なるので広告を隠す */
  @media (max-width: 1440px) {
    .bottombar-ad { display: none; }
  }
  .bottombar-ad img { width: 468px; height: 60px; display: block; }
  /* 画面が狭いとズーム操作を圧迫するので広告を隠す */
  #btnFit { font-size: 12px !important; padding: 4px 12px !important; border: 1px solid var(--border) !important; border-radius: 6px !important; margin-left: 8px; }

  .hidden { display: none !important; }

  /* ====================================================================
     個別の拡張子変換ページ用(JPG→PNG など)
     通常ページは画面固定(height:100vh)のまま。説明文を表示する変換ページ
     だけ、body に .is-convert-page が付き、ページ全体をスクロール可能にする。

     仕組み: エディタ一式(topbar/見出し/本体/フッター)を .app-shell で囲む。
     ・通常ページ … .app-shell は display:contents で「無い」のと同じ(従来通り)。
     ・変換ページ … .app-shell だけを画面の高さ(100dvh)のフレックス列にし、
       中の .body(flex:1)が余った高さを自動で埋める。見出しが増えても
       フッター(ズームバー)は常に画面の底に出る。説明文は枠の外＝下に続く。
  ==================================================================== */
  .app-shell { display: contents; }   /* 通常ページでは枠を無効化(レイアウト不変) */

  body.is-convert-page {
    display: block;                    /* body自身はただのスクロール領域にする */
    height: auto;
    min-height: 100dvh;
    overflow-y: auto;
  }
  body.is-convert-page .app-shell {
    display: flex;
    flex-direction: column;
    height: 100dvh;                    /* エディタ一式をちょうど1画面に収める */
  }
  /* 本体は枠内で余りを埋める(マジックナンバー不要)。フッターは常に底に残る。 */
  body.is-convert-page .body { flex: 1 1 auto; min-height: 0; }

  /* ページ見出し(ツールの上に1行) */
  .page-h1 {
    margin: 0;
    padding: 12px 16px;
    font-size: 18px;
    font-weight: 700;
    background: var(--panel);
    border-bottom: 1px solid var(--border);
    color: var(--text);
    flex: 0 0 auto;
  }
  /* 説明文(ツールの下) */
  .page-desc {
    max-width: 820px;
    margin: 0 auto;
    padding: 24px 20px 48px;
    color: var(--text-dim);
    font-size: 14px;
    line-height: 1.9;
  }
  .page-desc p { margin: 0 0 14px; }
  .page-desc a { color: var(--accent); }
  @media (max-width: 768px) {
    .page-h1 { font-size: 16px; padding: 10px 14px; }
    .page-desc { padding: 18px 14px 40px; font-size: 14px; }
  }

  /* ====================================================================
     スマートフォン・タブレット対応(幅768px以下)
     既存スタイルはそのまま、ここで縦並び+タッチ向けに上書きする
  ==================================================================== */
  @media (max-width: 768px) {
    body { font-size: 15px; }

    /* 上部バー:2段組み。1段目=ロゴ+ブランド名、2段目=Undo/Redo/クリア */
    .topbar {
      height: auto;
      flex: 0 0 auto;
      flex-wrap: wrap;          /* 折り返しで2段にする */
      padding: 8px 12px;
      gap: 8px 6px;
      row-gap: 8px;
    }
    /* 1段目: ロゴとブランド名(横幅いっぱい使う) */
    .topbar .brand-logo {
      height: 20px;             /* ロゴを小さめに */
      order: 1;
    }
    .topbar .brand { font-size: 13px; order: 2; }
    .topbar-h1 { order: 2; flex: 1 1 auto; border-left: 0; padding-left: 0; font-size: 13px; }
    /* spacer を改行ポイントにして、ここで2段目へ折り返す */
    .topbar .spacer {
      order: 3;
      flex-basis: 100%;
      height: 0;
    }
    /* 2段目: Undo / Redo / クリア を横並びで表示 */
    #btnUndo  { order: 4; padding: 6px 12px; font-size: 18px; min-width: 44px; min-height: 40px; }
    #btnRedo  { order: 5; padding: 6px 12px; font-size: 18px; min-width: 44px; min-height: 40px; }
    #btnClear { order: 6; padding: 8px 16px; font-size: 14px; min-height: 40px; }
    .topbar button {
      padding: 8px 14px;
      font-size: 14px;
      min-height: 40px;
    }

    .topbar .tutorial-link {
      order: 2; font-size: 13px; padding: 7px 12px;
      min-height: 36px; display: inline-flex; align-items: center;
    }

    /* 全体レイアウトを縦並びに */
    .body { flex-direction: column; min-height: 0; }
    /* 変換ページ: スマホでは枠(app-shell)を無効化し、ページを自然にスクロール */
    body.is-convert-page .app-shell { display: contents; height: auto; }

     /* 「メニュー」ボタン(2段目の左端=Undo/Redo/クリアと同じ列) */
    .menu-toggle {
      display: inline-flex;
      align-items: center;
      gap: 6px;
      order: 4;
      margin-right: auto;
      padding: 8px 14px;
      font-size: 14px;
      min-height: 40px;
    }
    .menu-toggle i { font-size: 18px; }

    /* 姉妹サイトリンクはスマホでは隠す(スペース節約) */
    .site-links { display: none; }

    /* 左サイドバー → 「メニュー」で開閉する2列グリッド(既定は閉じる) */
    .sidebar {
      width: 100%;
      flex: 0 0 auto;
      height: auto;
      border-right: none;
      border-bottom: none;
      display: grid;
      grid-template-columns: 1fr 1fr;
      gap: 8px;
      align-content: start;
      max-height: 0;
      overflow: hidden;
      padding: 0 12px;
      opacity: 0;
      transition: max-height 0.3s ease, opacity 0.2s ease, padding 0.3s ease;
    }
    /* 「メニュー」を押して開いた状態 */
    body.menu-open .sidebar {
      max-height: 78vh;
      overflow-y: auto;
      padding: 10px 12px;
      opacity: 1;
      border-bottom: 1px solid var(--border);
      -webkit-overflow-scrolling: touch;
    }
    .sidebar h2 { display: none; }
    .sidebar .group-title {
      grid-column: 1 / -1;
      font-size: 10px;
      color: var(--accent-soft);
      letter-spacing: 0.5px;
      margin: 12px 2px 6px;
    }
    .sidebar .group-title:first-of-type { margin-top: 2px; }
    .sidebar .tool {
      margin: 0;
      gap: 6px;
      padding: 12px 8px;
      font-size: 14px;
      border: 1px solid var(--border);
      border-radius: 8px;
      background: var(--panel-2);
      min-height: 50px;
      justify-content: center;
    }
    .sidebar .tool.active { outline: 1px solid var(--accent); }
    .sidebar .tool .ico { width: auto; }
    .sidebar .tool .ico i { font-size: 18px; }

    /* 中央キャンバスエリア */
    .stage {
      flex: 1 1 auto;
      min-height: 38vh;       /* パネルに高さを譲れるよう、最低高さの縛りを外す */
      padding: 10px;
    }
    .empty { padding: 20px 16px; }
    .empty button { font-size: 15px; padding: 10px 22px; min-height: 44px; }
    .formats-hint { font-size: 13px; margin-top: 14px; }

    /* 右パネル → 下に配置、内容が長ければ内部スクロール */
    .options {
      width: 100%;
      flex: 0 1 auto;      /* 内容ぶんの高さを取りつつ、必要なら縮む */
      max-height: 50vh;
      overflow-y: auto;
      border-left: none;
      border-top: 1px solid var(--border);
      padding: 14px 14px 120px;
      -webkit-overflow-scrolling: touch;
    }
    .options h3 { font-size: 15px; }

    /* タッチ向けにフォームコンポーネントを拡大 */
    .options input[type="text"],
    .options input[type="number"],
    .options select,
    .options textarea {
      font-size: 15px;
      padding: 10px 12px;
      min-height: 42px;
    }
    .seg-btn {
      padding: 9px 12px;
      font-size: 14px;
      min-height: 40px;
    }
    .options button.apply,
    .options button.reset {
      padding: 12px;
      font-size: 15px;
      min-height: 46px;
    }
    .copy-btn { padding: 8px 14px; font-size: 13px; min-height: 36px; }
    .eyedrop-btn { width: 42px; height: 42px; font-size: 18px; }

    /* スライダーつまみを大きく(タッチ用) */
    input[type="range"] {
      height: 32px;
    }
    input[type="range"]::-webkit-slider-thumb {
      width: 22px; height: 22px;
    }
    input[type="range"]::-moz-range-thumb {
      width: 22px; height: 22px;
    }

    /* Crop ハンドルのサイズ・位置は crop.js の updateCropHandleSize が
       ズーム倍率・PC/スマホを見て動的に設定する(タッチ時は自動で拡大)。 */
    .shape-layer .handle { /* SVG ハンドルはCSSサイズ非対応 */ }


    /* 履歴の色サンプル */
    .picker-swatch { width: 36px; height: 36px; }

    /* 下部のズームバー */
    .bottombar {
      padding: 8px 12px;
      gap: 8px;
      flex-wrap: wrap;
    }
    .bottombar button { min-width: 40px; min-height: 38px; font-size: 16px; }
    .bottombar input[type="range"] { width: auto; flex: 1; min-width: 100px; }
    .bottombar-ad { display: none; }
    #btnFit { font-size: 13px !important; padding: 6px 12px !important; }

    /* テキスト/図形パネルのカラー入力行 */
    /* テキスト/図形パネルのカラー入力行 */
    .color-row input[type="color"] { height: 42px; }

    /* スマホは二本指ピンチでズームするため、下部ズームバーは非表示 */
    .bottombar { display: none !important; }

    /* スマホでは三角を画像の内側に表示する(外側だと画面外に隠れるため) */
    .cut-line.h .cut-arrow-a { transform: translate(-1px, -50%); }
    .cut-line.h .cut-arrow-b { transform: translate(1px, -50%); }
    .cut-line.v .cut-arrow-a { transform: translate(-50%, 0); }
    .cut-line.v .cut-arrow-b { transform: translate(-50%, 0); }
  }

  /* タッチデバイス共通:ホバー効果を無効化(タッチでは意味がない) */
  @media (hover: none) {
    .tool:hover { background: transparent; }
    .topbar button:hover { background: var(--panel-2); }
    .seg-btn:hover { background: transparent; }
    .picker-swatch:hover { border-color: var(--border); }
  }
  /* ==================================================================
     Home cover (hero)  — トップ / のときだけ表示。/editor・各ツールでは出ない。
     is-convert-page のスクロール構成に載せ、ヒーローの下に説明文が続く。
  ================================================================== */
  .hero-cover { display: none; }

  body.is-home .hero-cover {
    display: flex; flex-direction: column; flex: 1 1 auto;
    position: relative;
    padding: clamp(20px, 5vw, 56px) clamp(16px, 5vw, 48px) 44px;
    gap: clamp(28px, 5vh, 56px);
  }
  /* カバー時はエディタ本体を隠し、app-shell を伸ばして下の説明文まで通しでスクロール */
  body.is-home .body { display: none; }
  body.is-home .app-shell { height: auto; min-height: 100dvh; }
  /* 画像を読み込んだらカバーを隠してエディタに切替(URL は /editor に書き換わる) */
  body.is-home.has-image .hero-cover { display: none; }
  body.is-home.has-image .body { display: flex; }
  body.is-home.has-image .app-shell { height: 100dvh; min-height: 0; }

  .hero-glow {
    position: absolute; inset: 0; pointer-events: none; z-index: 0;
    background:
      radial-gradient(60% 55% at 18% 12%, color-mix(in srgb, var(--accent) 22%, transparent), transparent 70%),
      radial-gradient(55% 55% at 92% 100%, color-mix(in srgb, var(--accent-soft) 18%, transparent), transparent 70%);
  }
  .hero-main, .hero-features, .hero-foot { position: relative; z-index: 1; }

  .hero-main {
    width: 100%; max-width: 1080px; margin: 0 auto;
    display: grid; grid-template-columns: 1.1fr 0.9fr; gap: clamp(24px, 4vw, 56px);
    align-items: center;
  }
  .hero-copy { min-width: 0; }
  .hero-eyebrow {
    display: inline-flex; align-items: center; gap: 8px;
    font-size: 13px; font-weight: 600;
    color: #aeb6c4; background: var(--panel-2);
    border: 1px solid var(--border); border-radius: 999px;
    padding: 6px 12px; margin-bottom: 18px;
  }
  .hero-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--accent-soft); }
  @media (prefers-reduced-motion: no-preference) {
    .hero-dot { animation: heroPulse 2.4s ease-out infinite; }
    @keyframes heroPulse {
      0%   { box-shadow: 0 0 0 0 color-mix(in srgb, var(--accent-soft) 55%, transparent); }
      70%  { box-shadow: 0 0 0 8px transparent; }
      100% { box-shadow: 0 0 0 0 transparent; }
    }
  }
  .hero-title {
    margin: 0 0 14px; font-weight: 800; line-height: 1.05;
    letter-spacing: -0.02em; font-size: clamp(30px, 4.6vw, 54px); color: var(--text);
  }
  .hero-grad {
    background: linear-gradient(90deg, var(--accent), var(--accent-soft));
    -webkit-background-clip: text; background-clip: text; color: transparent;
  }
  .hero-sub {
    margin: 0 0 26px; max-width: 46ch;
    color: #b7bdc9; font-size: clamp(15px, 1.4vw, 18px); line-height: 1.65;
  }
  .hero-actions { display: flex; align-items: center; gap: 16px; flex-wrap: wrap; }
  .hero-btn {
    display: inline-flex; align-items: center; gap: 9px; cursor: pointer;
    font-size: 16px; font-weight: 700; color: #fff;
    padding: 13px 24px; border-radius: 12px;
    background: linear-gradient(135deg, var(--accent), color-mix(in srgb, var(--accent-soft) 85%, var(--accent)));
    box-shadow: 0 8px 24px color-mix(in srgb, var(--accent) 35%, transparent);
    transition: transform .12s ease, box-shadow .12s ease, filter .12s ease;
  }
  .hero-btn i { font-size: 19px; }
  .hero-btn:hover { transform: translateY(-1px); filter: brightness(1.05); box-shadow: 0 12px 30px color-mix(in srgb, var(--accent) 45%, transparent); }
  .hero-btn:active { transform: translateY(0); }
  .hero-note { color: #8b93a3; font-size: 14px; }

  .hero-drop {
    display: flex; flex-direction: column; align-items: center; justify-content: center;
    gap: 12px; text-align: center; cursor: pointer;
    min-height: clamp(200px, 34vh, 300px);
    padding: 28px; border-radius: 18px;
    border: 2px dashed var(--border);
    background:
      radial-gradient(120% 120% at 50% 0%, color-mix(in srgb, var(--accent) 8%, transparent), transparent 60%),
      var(--panel);
    color: #c7ccd6;
    transition: border-color .15s ease, background .15s ease, transform .15s ease;
  }
  .hero-drop:hover { border-color: color-mix(in srgb, var(--accent) 55%, var(--border)); transform: translateY(-2px); }
  .hero-drop.drag { border-color: var(--accent); background: color-mix(in srgb, var(--accent) 12%, var(--panel)); }
  .hero-drop-ic { font-size: 40px; color: var(--accent-soft); line-height: 1; }
  .hero-drop-title { font-size: 16px; font-weight: 700; color: #e8ebf0; }
  .hero-drop-formats { font-size: 12px; color: #7f8797; }

  .hero-features {
    width: 100%; max-width: 1080px; margin: 0 auto;
    display: grid; grid-template-columns: repeat(4, 1fr); gap: 12px;
  }
  .feat {
    display: flex; align-items: flex-start; gap: 12px;
    padding: 14px 15px; border-radius: 14px;
    background: var(--panel); border: 1px solid var(--border);
    text-decoration: none; color: inherit;
    transition: border-color .12s ease, transform .12s ease, background .12s ease;
  }
  .feat:hover { border-color: color-mix(in srgb, var(--accent) 45%, var(--border)); transform: translateY(-2px); background: var(--panel-2); }
  .feat-ic {
    flex: 0 0 auto; width: 38px; height: 38px; border-radius: 10px;
    display: grid; place-items: center; font-size: 20px;
    color: var(--accent-soft);
    background: color-mix(in srgb, var(--accent) 12%, transparent);
  }
  .feat-tx { display: flex; flex-direction: column; gap: 2px; font-size: 13px; color: #9aa2b1; line-height: 1.4; }
  .feat-tx b { font-size: 14px; font-weight: 700; color: #e6e9ef; }

  .hero-foot {
    width: 100%; max-width: 1080px; margin: 4px auto 0;
    display: flex; align-items: center; justify-content: center; gap: 8px;
    color: #7f8797; font-size: 13px;
  }
  .hero-foot i { color: var(--accent-soft); }

  @media (max-width: 900px) {
    .hero-main { grid-template-columns: 1fr; }
    .hero-features { grid-template-columns: repeat(2, 1fr); }
  }
  @media (max-width: 560px) {
    .hero-features { grid-template-columns: 1fr; }
    .hero-title { font-size: clamp(26px, 8vw, 34px); }
    .hero-btn { width: 100%; justify-content: center; }
  }

  /* ===== Cutout(図形マスク) ===== */
  .cutout-overlay { position: absolute; inset: 0; cursor: crosshair; }
  .cutout-overlay svg { position: absolute; left: 0; top: 0; display: block; }
  /* 枠線は白で統一。中の塗りで Keep(残す)=緑 / Erase(消す)=赤 を区別する。 */
  .cutout-shape {
    fill: rgba(45, 212, 191, 0.18);
    stroke: #fff; stroke-width: 2; stroke-dasharray: 8 6;
    filter: drop-shadow(0 0 1px rgba(0,0,0,0.7));   /* 明るい画像でも枠が見えるよう縁取り */
  }
  .cutout-shape.erase { fill: rgba(255, 99, 99, 0.18); }
  /* 図形選択(6個をグリッド配置) */
  .shape-seg { display: grid; grid-template-columns: repeat(6, 1fr); gap: 4px; }
  .shape-seg .seg-btn { padding: 8px 0; display: grid; place-items: center; font-size: 17px; }

  /* Crop: 画像の外縁を示す破線(crop-overlay=画像領域に一致) */
  .crop-image-bound {
    position: absolute; inset: 0;
    box-sizing: border-box;
    border: 1px dashed rgba(255, 255, 255, 0.6);
    pointer-events: none;
    z-index: 4;
  }
  /* カバーページのフッター(姉妹サイトへのリンク) */
  .hero-links {
    width: 100%; max-width: 1080px; margin: 8px auto 0;
    padding-top: 22px;
    border-top: 1px solid var(--border);
    display: flex; align-items: center; justify-content: center;
    flex-wrap: wrap; gap: 10px 20px;
    position: relative; z-index: 1;
  }
  .hero-links-label { color: #6f7787; font-size: 12px; letter-spacing: 0.04em; text-transform: uppercase; }
  .hero-links nav { display: flex; flex-wrap: wrap; gap: 8px; }
  .hero-links a {
    display: inline-flex; align-items: center; gap: 7px;
    color: #b7bdc9; text-decoration: none; font-size: 14px;
    padding: 7px 14px; border-radius: 999px;
    border: 1px solid var(--border); background: var(--panel);
    transition: color .12s ease, border-color .12s ease, background .12s ease;
  }
  .hero-links a:hover {
    color: #fff;
    border-color: color-mix(in srgb, var(--accent) 50%, var(--border));
    background: var(--panel-2);
  }
  .hero-links a i { color: var(--accent-soft); font-size: 16px; }