:root {
    --bg-color: #fdf5e6;
    --main-color: #ff7f50;
    --main-hover: #ff6347;
    --panel-bg: #fffbf0;
    --border-color: #e0d0b0;
    --text-color: #5c4033;
    --card-shadow: 0 6px 12px rgba(92, 64, 51, 0.15);
  }

  * {
    box-sizing: border-box;
    user-select: none;
    -webkit-user-select: none;
  }

  body {
    margin: 0;
    padding: 0;
    overflow: hidden;
    background-color: var(--bg-color);
    color: var(--text-color);
    font-family: 'Comic Sans MS', 'Hiragino Maru Gothic ProN', 'Arial Rounded MT Bold', sans-serif;
    display: flex;
    justify-content: center;
    align-items: center;
    width: 100vw;
    height: 100dvh;
  }

  /* ====== 全体コンテナ ====== */
  #app-container {
    width: 100%;
    height: 100%;
    max-width: 480px; /* スマホ縦持ちサイズに最適化 */
    background: #fffdf9;
    border-left: 4px solid var(--border-color);
    border-right: 4px solid var(--border-color);
    display: flex;
    flex-direction: column;
    position: relative;
    box-shadow: 0 0 20px rgba(0,0,0,0.08);
    padding-top: env(safe-area-inset-top, 12px);
  }

  /* ====== スクリーン管理 ====== */
  .screen {
    position: absolute;
    top: 0; left: 0;
    width: 100%; height: 100%;
    display: none;
    flex-direction: column;
  }
  .screen.active {
    display: flex;
  }

  /* ====== タイトル画面 ====== */
  #title-screen {
    background: radial-gradient(circle at 50% 40%, #fff6e0 0%, #faecd0 100%);
    align-items: center;
    justify-content: center;
    text-align: center;
    padding: 20px;
  }
  .title-logo {
    font-size: 38px;
    font-weight: bold;
    color: var(--main-color);
    text-shadow: 3px 3px 0 #ffffff, -3px -3px 0 #ffffff, 3px -3px 0 #ffffff, -3px 3px 0 #ffffff, 0 8px 12px rgba(255,127,80,0.25);
    margin-bottom: 5px;
    line-height: 1.3;
  }
  .title-sub {
    font-size: 16px;
    color: #8b7355;
    margin-bottom: 25px;
    font-weight: bold;
  }
  .title-illustration {
    font-size: 100px;
    margin-bottom: 30px;
    animation: bounce 2s infinite ease-in-out;
  }

  @keyframes bounce {
    0%, 100% { transform: translateY(0) scale(1); }
    50% { transform: translateY(-15px) scale(1.03); }
  }

  /* ボタン共通 */
  .btn-big {
    padding: 16px 45px;
    font-size: 26px;
    font-weight: bold;
    color: #fff;
    background: linear-gradient(to bottom, #ff8f66, #ff6347);
    border: 4px solid #fff;
    border-radius: 40px;
    cursor: pointer;
    box-shadow: 0 8px 0 #cc4e33, 0 10px 15px rgba(0,0,0,0.15);
    transition: transform 0.05s, box-shadow 0.05s;
    outline: none;
  }
  .btn-big:active {
    transform: translateY(6px);
    box-shadow: 0 2px 0 #cc4e33, 0 4px 6px rgba(0,0,0,0.15);
  }

  /* ミュートトグル */
  .mute-toggle {
    position: absolute;
    top: 15px;
    width: 54px;
    height: 54px;
    background: #fff;
    border: 3px solid var(--border-color);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 24px;
    cursor: pointer;
    box-shadow: 0 4px 6px rgba(0,0,0,0.06);
    z-index: 100;
  }
  #hud-bgm-btn:active, #hud-se-btn:active {
    transform: scale(0.9);
  }

  /* ====== ゲーム画面 ====== */
  #game-screen {
    justify-content: space-between;
    background-color: #faf5eb;
  }

  /* ヘッダー */
  #game-header {
    height: 60px;
    background: #fff;
    border-bottom: 3px solid var(--border-color);
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0 12px;
    z-index: 10;
  }
  .header-title {
    font-size: 19px;
    font-weight: bold;
    color: var(--text-color);
    display: flex;
    align-items: center;
    gap: 6px;
  }

  /* 操作・補助ボタン */
  .action-btn {
    min-height: 48px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    box-sizing: border-box;
    padding: 8px 16px;
    font-size: 15px;
    font-weight: bold;
    color: #fff;
    border: 3px solid #fff;
    border-radius: 20px;
    cursor: pointer;
    box-shadow: 0 4px 0 rgba(0,0,0,0.2);
    transition: transform 0.05s;
  }
  .action-btn:active {
    transform: translateY(3px);
    box-shadow: 0 1px 0 rgba(0,0,0,0.2);
  }
  .action-btn.orange { background: linear-gradient(to bottom, #ff9f43, #ff6b6b); }
  .action-btn.green { background: linear-gradient(to bottom, #2ecc71, #27ae60); }
  .action-btn.blue { background: linear-gradient(to bottom, #3498db, #2980b9); }
  .action-btn.gray { background: linear-gradient(to bottom, #bdc3c7, #95a5a6); }

  /* キャンバスエリア */
  #canvas-container {
    flex: 1;
    position: relative;
    background: #fffdfa;
    display: flex;
    justify-content: center;
    align-items: center;
    overflow: hidden;
  }
  #main-canvas {
    display: block;
    background: #fffdf6;
    touch-action: none;
  }

  /* コントロール・パレット */
  #control-panel {
    background: var(--panel-bg);
    border-top: 4px solid var(--border-color);
    display: flex;
    flex-direction: column;
    padding: 10px;
    gap: 8px;
    box-shadow: 0 -4px 10px rgba(92, 64, 51, 0.05);
    z-index: 10;
  }

  /* パレットタブとエリア */
  .palette-label {
    font-size: 13px;
    font-weight: bold;
    color: #8b7355;
    margin-left: 4px;
  }
  .tab-btn {
    font-size: 12px;
    font-weight: bold;
    padding: 4px 10px;
    background: #fff;
    border: 2px solid var(--border-color);
    border-bottom: none;
    border-radius: 8px 8px 0 0;
    cursor: pointer;
    color: #8b7355;
    margin-bottom: -4px;
  }
  .tab-btn.selected {
    background: var(--panel-bg);
    color: var(--main-color);
    padding-bottom: 6px;
    z-index: 2;
    position: relative;
  }
  .palette-container {
    display: flex;
    gap: 4px;
    width: 100%;
    padding: 4px 0 6px 0;
    border-top: 2px solid var(--border-color);
  }
  .palette-btn {
    flex: 0 0 58px;
    min-height: 68px;
    height: auto;
    background: #fff;
    border: 3px solid var(--border-color);
    border-radius: 10px;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    box-shadow: 0 3px 0 var(--border-color);
    transition: transform 0.08s, box-shadow 0.08s;
    padding: 2px;
  }
  .palette-btn.selected {
    border-color: var(--main-color);
    background: #fff2eb;
    box-shadow: 0 3px 0 var(--main-color);
    transform: translateY(-2px);
  }
  .palette-btn:active {
    transform: translateY(2px);
    box-shadow: 0 1px 0 var(--border-color);
  }
  .palette-btn.selected:active {
    box-shadow: 0 1px 0 var(--main-color);
  }
  .palette-name {
    font-size: 10px;
    font-weight: bold;
    margin-top: 2px;
    color: var(--text-color);
    text-align: center;
    line-height: 1.1;
    word-break: break-all;
  }

  /* 下部ログ / コントロール */
  .panel-bottom-row {
    display: flex;
    gap: 8px;
    align-items: center;
  }
  #log-board {
    flex: 1;
    height: 52px;
    background: #eeddbb;
    border: 2px solid #ddccaa;
    border-radius: 12px;
    padding: 6px 10px;
    font-size: 11px;
    font-weight: bold;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 2px;
  }
  .log-line {
    animation: fadein 0.2s ease-out;
  }
  @keyframes fadein {
    from { opacity: 0; transform: translateY(3px); }
    to { opacity: 1; transform: translateY(0); }
  }

  /* 長押しガイドポップアップ */
  #guide-bubble {
    position: absolute;
    bottom: 12px;
    background: rgba(92, 64, 51, 0.85);
    color: #fff;
    padding: 6px 14px;
    border-radius: 20px;
    font-size: 12px;
    font-weight: bold;
    pointer-events: none;
    animation: pulse 1.8s infinite;
    z-index: 100;
  }
  @keyframes pulse {
    0%, 100% { transform: scale(1); opacity: 0.9; }
    50% { transform: scale(1.05); opacity: 1; }
  }


  #parts-palette {
    scrollbar-width: auto;
    scrollbar-color: #ff8f66 #eeddbb;
  }
  #parts-palette::-webkit-scrollbar {
    height: 10px;
    display: block;
  }
  #parts-palette::-webkit-scrollbar-track {
    background: #eeddbb;
    border-radius: 5px;
  }
  #parts-palette::-webkit-scrollbar-thumb {
    background-color: #ff8f66;
    border-radius: 5px;
    border: 2px solid #eeddbb;
  }