#kb-wrap, #kb-wrap * { box-sizing: border-box; }
  .kb-wrap {
    overflow: hidden; background: #3a2a1c;
    font-family: "Hiragino Maru Gothic ProN", "BIZ UDPGothic", "Yu Gothic", "Meiryo", sans-serif;
    touch-action: none; -webkit-user-select: none; user-select: none;
  }
  /* 木枠 */
  #kb-wrap {
    position: fixed; inset: 0;
    z-index: 9999; /* Cocoon等のヘッダーより前面に */
    padding: clamp(10px, 2.2vmin, 26px);
    background:
      repeating-linear-gradient(95deg, #8a5a33 0 14px, #92613a 14px 30px, #855531 30px 46px),
      #8a5a33;
    box-shadow: inset 0 0 30px rgba(0,0,0,.45);
  }
  /* WP管理バーが表示されている場合はその高さ分ずらす */
  body.admin-bar #kb-wrap { top: 32px; }
  @media screen and (max-width: 782px) { body.admin-bar #kb-wrap { top: 46px; } }
  #kb-board {
    position: relative; width: 100%; height: 100%;
    border-radius: 6px; overflow: hidden;
    box-shadow: inset 0 0 0 3px rgba(0,0,0,.35), inset 0 6px 24px rgba(0,0,0,.5);
    background: #1f3d33;
  }
  #kb-canvas { display: block; width: 100%; height: 100%; }

  /* チョーク風ボタン */
  #kb-ui {
    position: absolute; top: 10px; right: 10px;
    display: flex; gap: 8px; flex-wrap: wrap; justify-content: flex-end;
    max-width: 72%;
  }
  .kb-btn {
    appearance: none; border: 2px dashed rgba(255,255,250,.75);
    background: rgba(255,255,255,.06); color: rgba(255,255,250,.92);
    border-radius: 12px; padding: 8px 14px;
    font-family: inherit; font-size: clamp(13px, 1.8vmin, 17px); font-weight: 700;
    cursor: pointer; letter-spacing: .05em;
  }
  .kb-btn:active { background: rgba(255,255,255,.18); transform: scale(.96); }
  .kb-btn.kb-gold { border-style: solid; border-color: #f0d27e; color: #f7e6b0; background: rgba(244,214,130,.12); }

  /* チョーク置き場（色えらび＋黒板消し） */
  #kb-tray {
    position: absolute; left: 10px; bottom: 10px;
    display: flex; gap: 10px; align-items: flex-end;
    padding: 8px 12px;
    background: rgba(0,0,0,.25);
    border: 2px solid rgba(255,255,255,.18);
    border-radius: 14px;
  }
  .kb-chalk {
    width: clamp(34px, 6vmin, 48px); height: clamp(20px, 3.2vmin, 26px);
    border-radius: 6px; border: 2px solid rgba(0,0,0,.25);
    cursor: pointer; padding: 0;
    box-shadow: 0 2px 4px rgba(0,0,0,.4);
  }
  .kb-chalk.kb-active { outline: 3px solid #f0d27e; transform: translateY(-6px); }
  #kb-eraser {
    width: clamp(50px, 8vmin, 70px); height: clamp(26px, 4vmin, 34px);
    border-radius: 6px; border: 2px solid rgba(0,0,0,.3);
    background: linear-gradient(#5a4632 0 45%, #2c2c2c 45% 100%);
    color: #f5ead0; font-family: inherit; font-weight: 700;
    font-size: clamp(10px, 1.6vmin, 13px);
    cursor: pointer; box-shadow: 0 2px 4px rgba(0,0,0,.4);
  }
  #kb-eraser.kb-active { outline: 3px solid #f0d27e; transform: translateY(-6px); }

  /* スタート画面・画像選択 */
  .kb-overlay {
    position: absolute; inset: 0; z-index: 10;
    display: flex; align-items: center; justify-content: center;
    background: rgba(10, 25, 20, .72);
  }
  .kb-overlay.kb-hidden { display: none !important; }
  .kb-panel {
    background: #234639; border: 3px dashed rgba(255,255,250,.6);
    border-radius: 18px; padding: 24px 30px; text-align: center;
    color: rgba(255,255,250,.95); max-width: min(88vw, 470px);
    box-shadow: 0 10px 40px rgba(0,0,0,.4);
  }
  .kb-panel h1 { margin: 0 0 10px; font-size: clamp(20px, 4vmin, 30px); letter-spacing: .12em; }
  .kb-panel p  { margin: 6px 0; font-size: clamp(13px, 2vmin, 15px); line-height: 1.7; opacity: .9; }
  .kb-big {
    margin-top: 14px; font-size: clamp(17px, 2.6vmin, 22px); padding: 12px 34px;
    border-style: solid; background: rgba(244, 214, 130, .15);
    border-color: #f0d27e; color: #f7e6b0;
  }
  #kb-file { display: none; }

  /* 修正: こびとお絵かきスタジオ */
  #kb-pup-overlay { z-index: 20; }
  .kb-pup-panel {
    background: #234639; border: 3px dashed rgba(255,255,250,.6);
    border-radius: 18px; padding: 14px 18px;
    color: rgba(255,255,250,.95);
    max-width: 94vw; max-height: 94%;
    overflow-y: auto;
    display: flex; flex-direction: column; align-items: center; gap: 10px;
  }
  .kb-pup-panel h2 { margin: 0; font-size: clamp(17px, 3vmin, 24px); letter-spacing: .1em; }
  .kb-pup-main { display: flex; gap: 14px; align-items: flex-start; flex-wrap: wrap; justify-content: center; }
  /* 修正: 枠切り替えタブ */
  .kb-pup-tabs { display: flex; gap: 8px; justify-content: center; flex-wrap: wrap; }
  .kb-pup-tab {
    font-family: inherit; font-size: clamp(13px, 2.2vmin, 16px); font-weight: 700;
    padding: 7px 16px; border-radius: 999px; cursor: pointer;
    color: #eaf3ee; background: rgba(255,255,255,.08);
    border: 2px solid rgba(255,255,255,.25); letter-spacing: .04em;
    transition: background .12s, border-color .12s, transform .08s;
  }
  .kb-pup-tab:hover { background: rgba(255,255,255,.16); }
  .kb-pup-tab:active { transform: scale(.96); }
  .kb-pup-tab.kb-active {
    background: #f0d27e; color: #2a2316; border-color: #f0d27e;
    box-shadow: 0 0 8px rgba(240,210,126,.5);
  }
  .kb-pup-stage {
    position: relative;
    width: min(56vmin, 330px);
    aspect-ratio: 420 / 520;
    border-radius: 10px; overflow: hidden;
    background: #1b3830;
    box-shadow: inset 0 0 0 2px rgba(255,255,255,.2);
    touch-action: none;
  }
  .kb-pup-stage canvas { position: absolute; inset: 0; width: 100%; height: 100%; }
  .kb-pup-side { display: flex; flex-direction: column; gap: 10px; max-width: 200px; }
  .kb-pup-colors { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
  .kb-pen {
    width: 100%; aspect-ratio: 1; min-width: 34px;
    border-radius: 50%; border: 3px solid rgba(0,0,0,.3);
    cursor: pointer; padding: 0;
  }
  .kb-pen.kb-active { outline: 3px solid #f0d27e; transform: scale(1.12); }
  .kb-tool {
    border: 2px dashed rgba(255,255,250,.7); background: rgba(255,255,255,.06);
    color: rgba(255,255,250,.92); border-radius: 10px; padding: 7px 10px;
    font-family: inherit; font-weight: 700; font-size: 13px; cursor: pointer;
  }
  .kb-tool.kb-active { border-style: solid; border-color: #f0d27e; color: #f7e6b0; background: rgba(244,214,130,.15); }
  .kb-pup-actions { display: flex; gap: 10px; flex-wrap: wrap; justify-content: center; }
  /* 履歴ギャラリー */
  #kb-gallery {
    display: flex; gap: 10px; overflow-x: auto; max-width: 86vw;
    padding: 8px; background: rgba(0,0,0,.2); border-radius: 12px;
    min-height: 40px; align-items: center;
  }
  .kb-gal-item { flex: 0 0 auto; text-align: center; }
  .kb-gal-item img {
    width: 62px; height: 77px; object-fit: contain;
    background: rgba(255,255,255,.08); border-radius: 8px;
    border: 2px solid rgba(255,255,255,.25); cursor: pointer; display: block;
  }
  .kb-gal-item img.kb-active { border-color: #f0d27e; box-shadow: 0 0 8px rgba(240,210,126,.6); }
  .kb-gal-mini { display: flex; gap: 4px; justify-content: center; margin-top: 3px; }
  .kb-gal-mini button {
    border: 1px solid rgba(255,255,255,.4); background: rgba(255,255,255,.08);
    color: #fff; border-radius: 6px; font-size: 10px; padding: 2px 6px;
    cursor: pointer; font-family: inherit;
  }
  .kb-gal-empty { font-size: 12px; opacity: .7; padding: 0 10px; }
  /* 修正: 設定画面の履歴ギャラリー */
  #kb-start-hist { width: 100%; max-width: 460px; }
  #kb-start-gallery {
    display: flex; gap: 10px; overflow-x: auto; max-width: 86vw;
    padding: 8px; background: rgba(0,0,0,.2); border-radius: 12px;
    min-height: 40px; align-items: center; margin-top: 4px;
  }