:root {
    --bg-app: #f1f5f9;
    --bg-panel: #ffffff;
    --border-color: #e2e8f0;
    --text-main: #0f172a;
    --text-sub: #475569;
    --primary: #2563eb;
    --primary-hover: #1d4ed8;
    --primary-light: #eff6ff;
    --accent: #f59e0b;
    --success: #10b981;
    --danger: #ef4444;
    --radius: 12px;
    --shadow-sm: 0 1px 3px rgba(0,0,0,0.06);
    --shadow-md: 0 8px 24px rgba(15, 23, 42, 0.12);
  }
  
  * {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
    font-family: "Hiragino Kaku Gothic ProN", "Hiragino Sans", "Yu Gothic", "Meiryo", system-ui, -apple-system, sans-serif;
  }
  
  body {
    background-color: var(--bg-app);
    color: var(--text-main);
    display: flex;
    flex-direction: column;
    min-height: 100vh;
    overflow-x: hidden;
  }
  
  /* 1. ヘッダー */
  header {
    position: sticky;
    top: 0;
    background: var(--bg-panel);
    border-bottom: 1px solid var(--border-color);
    padding: 10px 20px;
    display: flex;
    flex-wrap: nowrap;
    align-items: center;
    justify-content: space-between;
    gap: 14px;
    box-shadow: var(--shadow-sm);
    z-index: 50;
  }
  
  .brand {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-shrink: 0;
  }
  
  .brand-logo {
    width: 36px;
    height: 36px;
    border-radius: 10px;
    background: linear-gradient(135deg, #2563eb, #7c3aed);
    color: #fff;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 900;
    font-size: 18px;
    letter-spacing: -1px;
  }
  
  .brand-title h1 {
    font-size: 18px;
    font-weight: 900;
    color: var(--text-main);
    line-height: 1.1;
  }
  
  .brand-title span {
    font-size: 11px;
    color: var(--text-sub);
    display: block;
  }
  
  .chapter-nav {
    display: flex;
    flex-wrap: nowrap;
    align-items: center;
    gap: 5px;
    overflow-x: auto;
    scrollbar-width: none;
  }
  
  .chapter-nav::-webkit-scrollbar {
    display: none;
  }
  
  .chapter-btn {
    border: 1px solid var(--border-color);
    background: #f8fafc;
    color: var(--text-sub);
    padding: 7px 12px;
    border-radius: 999px;
    font-size: 13px;
    font-weight: 700;
    cursor: pointer;
    transition: all 0.15s ease;
    display: flex;
    align-items: center;
    gap: 5px;
    white-space: nowrap;
    flex-shrink: 0;
  }
  
  .chapter-btn:hover {
    background: #e2e8f0;
    color: var(--text-main);
  }
  
  .chapter-btn.active {
    background: var(--primary);
    color: #ffffff;
    border-color: var(--primary);
    box-shadow: 0 2px 8px rgba(37, 99, 235, 0.3);
  }
  
  .chapter-btn .badge-num {
    background: rgba(255,255,255,0.22);
    padding: 1px 6px;
    border-radius: 999px;
    font-size: 10px;
  }
  .chapter-btn:not(.active) .badge-num {
    background: #e2e8f0;
    color: var(--text-sub);
  }
  
  /* 2. 上部バー：ステップ切替＆吹き出しメッセージ風依頼ボックス */
  .client-banner {
    background: linear-gradient(90deg, #1e293b 0%, #0f172a 100%);
    color: #ffffff;
    padding: 12px 20px;
    border-bottom: 3px solid var(--primary);
    transition: border-color 0.2s;
  }
  
  .client-banner.is-sample-mode {
    border-bottom-color: var(--success);
  }
  
  .client-banner.is-practice-mode {
    border-bottom-color: var(--accent);
  }
  
  .client-inner {
    max-width: 1640px;
    margin: 0 auto;
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
  }
  
  .step-tabs {
    display: flex;
    background: rgba(255, 255, 255, 0.12);
    padding: 4px;
    border-radius: 10px;
    gap: 4px;
    flex-shrink: 0;
  }
  
  .step-btn {
    border: none;
    background: transparent;
    color: #cbd5e1;
    padding: 8px 14px;
    border-radius: 8px;
    font-size: 13px;
    font-weight: 800;
    cursor: pointer;
    transition: all 0.15s;
  }
  
  .step-btn:hover {
    color: #ffffff;
    background: rgba(255,255,255,0.08);
  }
  
  .step-btn.active[data-step="1"] {
    background: #10b981;
    color: #ffffff;
    box-shadow: 0 2px 6px rgba(16, 185, 129, 0.4);
  }
  
  .step-btn.active[data-step="2"] {
    background: #f59e0b;
    color: #0f172a;
    box-shadow: 0 2px 6px rgba(245, 158, 11, 0.4);
  }
  
  /* 人物アイコン＋吹き出しコンテナ */
  .client-request-box {
    flex: 1;
    min-width: 300px;
    display: flex;
    align-items: flex-start;
    gap: 16px;
  }
  
  .client-person {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 3px;
    flex-shrink: 0;
  }
  
  .client-avatar {
    width: 46px;
    height: 46px;
    border-radius: 50%;
    background: #fef3c7;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 25px;
    border: 2.5px solid var(--accent);
    box-shadow: 0 3px 10px rgba(0,0,0,0.25);
  }
  
  .client-banner.is-sample-mode .client-avatar {
    background: #d1fae5;
    border-color: var(--success);
  }
  
  .client-role-tag {
    font-size: 10px;
    font-weight: 800;
    color: #fde68a;
    background: rgba(255,255,255,0.12);
    padding: 1px 7px;
    border-radius: 999px;
    white-space: nowrap;
  }
  
  .client-banner.is-sample-mode .client-role-tag {
    color: #6ee7b7;
  }
  
  /* 吹き出し本体（左向き三角しっぽ付き） */
  .speech-bubble {
    position: relative;
    flex: 1;
    background: #ffffff;
    color: #0f172a;
    padding: 10px 16px;
    border-radius: 14px;
    box-shadow: 0 4px 14px rgba(0, 0, 0, 0.22);
    border: 2px solid #fde68a;
  }
  
  .client-banner.is-sample-mode .speech-bubble {
    background: #ecfdf5;
    border-color: #6ee7b7;
  }
  
  .speech-bubble::before {
    content: "";
    position: absolute;
    left: -12px;
    top: 15px;
    border-width: 8px 12px 8px 0;
    border-style: solid;
    border-color: transparent #fde68a transparent transparent;
  }
  
  .speech-bubble::after {
    content: "";
    position: absolute;
    left: -9px;
    top: 16px;
    border-width: 7px 10px 7px 0;
    border-style: solid;
    border-color: transparent #ffffff transparent transparent;
  }
  
  .client-banner.is-sample-mode .speech-bubble::before {
    border-color: transparent #6ee7b7 transparent transparent;
  }
  
  .client-banner.is-sample-mode .speech-bubble::after {
    border-color: transparent #ecfdf5 transparent transparent;
  }
  
  .client-name {
    display: block;
    font-size: 11px;
    font-weight: 900;
    color: #d97706;
    margin-bottom: 3px;
  }
  
  .client-banner.is-sample-mode .client-name {
    color: #059669;
  }
  
  .client-message {
    display: block;
    font-size: 14.5px;
    font-weight: 700;
    color: #0f172a;
    line-height: 1.5;
  }
  

  
  /* 3. メイン3カラムレイアウト（100%表示で110%相当の視認性・密度に最適化） */
  .workspace {
    display: grid;
    grid-template-columns: 360px 1fr 370px;
    gap: 18px;
    padding: 18px 20px;
    flex: 1;
    max-width: 1800px;
    width: 100%;
    margin: 0 auto;
    align-items: start;
  }

  @media (max-width: 1200px) {
    .workspace {
      grid-template-columns: 330px 1fr;
    }
    .panel-right {
      grid-column: 1 / -1;
    }
  }

  @media (max-width: 768px) {
    .workspace {
      grid-template-columns: 1fr;
    }
  }
  
  .panel {
    background: var(--bg-panel);
    border: 1px solid var(--border-color);
    border-radius: var(--radius);
    box-shadow: var(--shadow-sm);
    padding: 14px;
  }
  
/* 左パネル：高さを右パネルと同期し、おしゃれなスクロールバーを適用 */
.panel-left {
  display: flex;
  flex-direction: column;
  max-height: 540px;
  overflow: hidden;
  padding-bottom: 10px;
}

.panel-left::-webkit-scrollbar,
.emoji-grid::-webkit-scrollbar {
  width: 7px;
}

.panel-left::-webkit-scrollbar-track,
.emoji-grid::-webkit-scrollbar-track {
  background: #f1f5f9;
  border-radius: 999px;
  margin: 4px 0;
}

.panel-left::-webkit-scrollbar-thumb,
.emoji-grid::-webkit-scrollbar-thumb {
  background: linear-gradient(180deg, #94a3b8, #64748b);
  border-radius: 999px;
  border: 1.5px solid #f1f5f9;
}

.panel-left::-webkit-scrollbar-thumb:hover,
.emoji-grid::-webkit-scrollbar-thumb:hover {
  background: linear-gradient(180deg, #3b82f6, #2563eb);
}
  
  @media (max-width: 768px) {
    .panel-left {
      max-height: none;
    }
  }
  
  .panel-header {
    font-size: 14px;
    font-weight: 900;
    color: var(--text-main);
    padding-bottom: 10px;
    margin-bottom: 10px;
    border-bottom: 1px solid var(--border-color);
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-shrink: 0;
  }

  #controlsContainer {
    flex: 1;
    min-height: 0;
    overflow-y: auto;
    padding-right: 4px;
    overscroll-behavior: contain;
    scrollbar-width: thin;
    scrollbar-color: #94a3b8 #f1f5f9;
  }
  
  #controlsContainer::-webkit-scrollbar,
  .emoji-grid::-webkit-scrollbar {
    width: 7px;
  }
  
  #controlsContainer::-webkit-scrollbar-track,
  .emoji-grid::-webkit-scrollbar-track {
    background: #f1f5f9;
    border-radius: 999px;
    margin: 2px 0;
  }
  
  #controlsContainer::-webkit-scrollbar-thumb,
  .emoji-grid::-webkit-scrollbar-thumb {
    background: linear-gradient(180deg, #94a3b8, #64748b);
    border-radius: 999px;
    border: 1.5px solid #f1f5f9;
  }
  
  #controlsContainer::-webkit-scrollbar-thumb:hover,
  .emoji-grid::-webkit-scrollbar-thumb:hover {
    background: linear-gradient(180deg, #3b82f6, #2563eb);
  }
  
  @media (max-width: 768px) {
    .panel-left {
      max-height: none;
    }
    #controlsContainer {
      overflow-y: visible;
      padding-right: 0;
    }
  }
  
  .readonly-notice {
    background: #ecfdf5;
    border: 1px solid #a7f3d0;
    color: #065f46;
    padding: 12px;
    border-radius: 10px;
    font-size: 12.5px;
    font-weight: 700;
    line-height: 1.5;
    margin-bottom: 12px;
  }
  
  .readonly-notice button {
    margin-top: 8px;
    width: 100%;
    padding: 8px;
    border: none;
    border-radius: 7px;
    background: #10b981;
    color: #fff;
    font-weight: 800;
    font-size: 12px;
    cursor: pointer;
  }
  
  .controls-locked {
    opacity: 0.45;
    pointer-events: none;
    user-select: none;
  }
  
  /* グループカード（見出しでまとめた枠） */
  .group-card {
    background: #f8fafc;
    border: 1px solid #cbd5e1;
    border-radius: 10px;
    padding: 11px 12px;
    margin-bottom: 12px;
  }
  
  .group-card-title {
    font-size: 13.5px;
    font-weight: 900;
    color: var(--primary);
    margin-bottom: 10px;
    padding-bottom: 6px;
    border-bottom: 1px dashed #cbd5e1;
    display: flex;
    align-items: center;
    justify-content: space-between;
  }

  
  .sub-field {
    margin-bottom: 9px;
  }
  .sub-field:last-child {
    margin-bottom: 0;
  }
  
  .sub-label {
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-size: 12.5px;
    font-weight: 700;
    color: var(--text-sub);
    margin-bottom: 5px;
  }
  

  
  .val-badge {
    font-weight: 800;
    color: var(--primary);
    background: #ffffff;
    border: 1px solid #bfdbfe;
    padding: 0 6px;
    border-radius: 4px;
    font-size: 11px;
  }
  
  input[type="text"], textarea {
    width: 100%;
    padding: 7px 9px;
    border: 1px solid #cbd5e1;
    border-radius: 7px;
    font-size: 13px;
    color: var(--text-main);
    background: #fff;
  }
  
  input[type="text"]:focus, textarea:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 2px rgba(37, 99, 235, 0.15);
  }
  
  textarea {
    resize: vertical;
    min-height: 48px;
  }
  
  .btn-group {
    display: grid;
    grid-auto-flow: column;
    grid-auto-columns: 1fr;
    gap: 4px;
  }
  
  .opt-btn {
    padding: 7px 4px;
    border: 1px solid #cbd5e1;
    background: #ffffff;
    border-radius: 7px;
    font-size: 12px;
    font-weight: 700;
    color: var(--text-sub);
    cursor: pointer;
    text-align: center;
    white-space: nowrap;
    transition: all 0.12s;
  }
  
  .opt-btn.active {
    background: var(--primary);
    border-color: var(--primary);
    color: #ffffff;
  }
  
  .emoji-grid {
    display: grid;
    grid-template-columns: repeat(6, 1fr);
    gap: 4px;
    max-height: 112px;
    overflow-y: auto;
    padding: 4px;
    background: #ffffff;
    border: 1px solid var(--border-color);
    border-radius: 7px;
  }
  
  .emoji-btn {
    aspect-ratio: 1;
    border: 1px solid transparent;
    background: #f8fafc;
    border-radius: 5px;
    font-size: 17px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
  }
  
  .emoji-btn.active {
    border-color: var(--primary);
    background: var(--primary-light);
    box-shadow: 0 0 0 2px rgba(37, 99, 235, 0.25);
  }
  
  .color-row {
    display: flex;
    align-items: center;
    gap: 5px;
    flex-wrap: nowrap;
  }
  
  input[type="color"] {
    width: 28px;
    height: 24px;
    border: 1px solid #cbd5e1;
    border-radius: 5px;
    padding: 1px;
    background: #fff;
    cursor: pointer;
    flex-shrink: 0;
  }
  
  .swatch-list {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 3px;
    flex-wrap: nowrap;
    flex: 1;
  }
  
  .swatch {
    width: 17px;
    height: 17px;
    border-radius: 50%;
    border: 1.5px solid #fff;
    box-shadow: 0 0 0 1px #94a3b8;
    cursor: pointer;
    flex-shrink: 0;
  }
  
  input[type="range"] {
    width: 100%;
    accent-color: var(--primary);
    cursor: pointer;
  }
  
  .toggle-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    background: #ffffff;
    padding: 6px 9px;
    border-radius: 7px;
    border: 1px solid #cbd5e1;
    font-size: 11.5px;
    font-weight: 700;
    color: var(--text-sub);
  }
  
  /* 中央パネル：リアルタイムプレビュー */
  .panel-center {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    min-height: 600px;
    background: #e2e8f0;
    background-image: radial-gradient(#cbd5e1 1px, transparent 1px);
    background-size: 16px 16px;
    padding: 18px;
  }
  
  .canvas-toolbar {
    width: 100%;
    display: flex;
    flex-wrap: wrap;
    justify-content: space-between;
    align-items: center;
    gap: 8px;
    margin-bottom: 12px;
    background: rgba(255,255,255,0.95);
    padding: 8px 12px;
    border-radius: 10px;
    border: 1px solid var(--border-color);
    font-size: 12px;
    font-weight: 700;
    color: var(--text-sub);
  }
  
  .toolbar-actions {
    display: flex;
    align-items: center;
    gap: 10px;
  }
  
  .btn-mini-reset {
    border: 1px solid #cbd5e1;
    background: #f8fafc;
    color: var(--text-main);
    padding: 4px 10px;
    border-radius: 6px;
    font-size: 11.5px;
    font-weight: 700;
    cursor: pointer;
  }
  .btn-mini-reset:hover {
    background: #e2e8f0;
  }
  
  .canvas-wrapper {
    position: relative;
    display: flex;
    align-items: center;
    justify-content: center;
    max-width: 100%;
    box-shadow: var(--shadow-md);
    border-radius: 8px;
    overflow: hidden;
    background: #fff;
  }
  
  canvas#designCanvas {
    display: block;
    max-width: 100%;
    max-height: 68vh;
    width: auto;
    height: auto;
    touch-action: none;
  }
  
  .drag-hint {
    margin-top: 10px;
    font-size: 12px;
    color: var(--text-main);
    background: rgba(255,255,255,0.92);
    padding: 6px 14px;
    border-radius: 999px;
    font-weight: 700;
    box-shadow: var(--shadow-sm);
    text-align: center;
  }
  
  /* 右パネル：リアルタイム採点表＆PNG保存 */
  .panel-right {
    display: flex;
    flex-direction: column;
    gap: 12px;
  }
  
  .score-banner {
    background: linear-gradient(135deg, #eff6ff 0%, #dbeafe 100%);
    border: 1px solid #93c5fd;
    border-radius: 10px;
    padding: 12px 14px;
    display: flex;
    align-items: center;
    justify-content: space-between;
  }
  
  .score-title {
    font-size: 11.5px;
    font-weight: 800;
    color: #1e40af;
  }
  
  .score-num {
    font-size: 30px;
    font-weight: 900;
    color: var(--primary);
    line-height: 1.1;
  }
  
  .score-badge {
    font-size: 12px;
    font-weight: 900;
    padding: 5px 11px;
    border-radius: 999px;
  }
  
  .mission-summary {
    font-size: 12px;
    font-weight: 700;
    color: var(--text-sub);
    background: #f8fafc;
    padding: 8px 10px;
    border-radius: 8px;
    border-left: 4px solid var(--primary);
    line-height: 1.45;
  }
  
  /* リアルタイム採点テーブル（シンプル1行表示） */
  .score-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 13px;
    border: 1px solid var(--border-color);
    border-radius: 8px;
    overflow: hidden;
  }

  .score-table th {
    background: #f1f5f9;
    color: var(--text-sub);
    font-weight: 800;
    text-align: left;
    padding: 9px 10px;
    border-bottom: 1px solid var(--border-color);
    font-size: 12px;
  }

  .score-table td {
    padding: 11px 10px;
    border-bottom: 1px solid var(--border-color);
    vertical-align: middle;
    line-height: 1.4;
  }
  
  .score-table tr:last-child td {
    border-bottom: none;
  }
  
  .score-table tr.row-ok {
    background: #f0fdf4;
  }
  
  .score-table tr.row-ng {
    background: #fef2f2;
  }
  
  .td-item {
    font-weight: 700;
    color: var(--text-main);
  }
  .td-item small {
    display: block;
    font-weight: 600;
    font-size: 10.5px;
    color: var(--text-sub);
    margin-top: 2px;
  }
  
  .td-status {
    text-align: center;
    font-size: 15px;
    width: 42px;
  }
  
  .td-pts {
    text-align: right;
    font-weight: 900;
    width: 54px;
    white-space: nowrap;
  }
  
  .btn-save {
    width: 100%;
    padding: 13px;
    border: none;
    border-radius: 10px;
    background: linear-gradient(135deg, #10b981, #059669);
    color: #ffffff;
    font-size: 14.5px;
    font-weight: 900;
    cursor: pointer;
    box-shadow: 0 4px 12px rgba(16, 185, 129, 0.3);
    transition: transform 0.1s;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
  }
  
  .btn-save:hover {
    transform: translateY(-1px);
  }
  
  /* トースト通知 */
  .toast {
    position: fixed;
    bottom: 20px;
    left: 50%;
    transform: translateX(-50%) translateY(80px);
    background: #0f172a;
    color: #fff;
    padding: 10px 22px;
    border-radius: 999px;
    font-size: 13px;
    font-weight: 700;
    box-shadow: 0 10px 25px rgba(0,0,0,0.25);
    opacity: 0;
    transition: all 0.25s ease;
    z-index: 100;
  }
  
  .toast.show {
    transform: translateX(-50%) translateY(0);
    opacity: 1;
  }

/* クリア済みチャプターの黄色い発光＆薄い黄色ボタン背景 */
.chapter-btn.is-cleared {
  background: #fef9c3;
  color: #854d0e;
  border-color: #facc15;
  box-shadow: 0 0 10px rgba(250, 204, 21, 0.75);
}

.chapter-btn.is-cleared:hover {
  background: #fef08a;
  color: #713f12;
}

.chapter-btn.is-cleared.active {
  background: linear-gradient(135deg, #f59e0b, #d97706);
  color: #ffffff;
  border-color: #facc15;
}

.chapter-btn.is-cleared .badge-num {
  background: linear-gradient(135deg, #fde047, #f59e0b);
  color: #0f172a;
  font-weight: 900;
  box-shadow: 0 0 8px rgba(250, 204, 21, 0.9);
}

/* 総合得点ページボタン */
.btn-total-score {
  width: 100%;
  padding: 11px;
  border: 2px solid #f59e0b;
  border-radius: 10px;
  background: #fffbeb;
  color: #b45309;
  font-size: 13.5px;
  font-weight: 900;
  cursor: pointer;
  transition: all 0.15s;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
}

.btn-total-score:hover {
  background: #fef3c7;
  transform: translateY(-1px);
}

/* 総合得点モーダル */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.65);
  display: none;
  align-items: center;
  justify-content: center;
  padding: 16px;
  z-index: 200;
}

.modal-overlay.show {
  display: flex;
}

.modal-card {
  background: #ffffff;
  border-radius: 16px;
  width: 100%;
  max-width: 520px;
  padding: 20px;
  box-shadow: 0 20px 40px rgba(0, 0, 0, 0.3);
  border: 2px solid #cbd5e1;
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding-bottom: 12px;
  margin-bottom: 14px;
  border-bottom: 1px solid var(--border-color);
}

.modal-header h2 {
  font-size: 18px;
  font-weight: 900;
  color: var(--text-main);
}

.modal-close {
  border: none;
  background: #f1f5f9;
  color: var(--text-sub);
  width: 30px;
  height: 30px;
  border-radius: 50%;
  font-size: 16px;
  font-weight: 900;
  cursor: pointer;
}

.total-hero {
  background: linear-gradient(135deg, #fef3c7 0%, #fde68a 100%);
  border: 2px solid #f59e0b;
  border-radius: 12px;
  padding: 14px;
  text-align: center;
  margin-bottom: 14px;
}

.total-hero-label {
  font-size: 12px;
  font-weight: 800;
  color: #92400e;
}

.total-hero-num {
  font-size: 34px;
  font-weight: 900;
  color: #b45309;
  line-height: 1.15;
}

.summary-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}

.summary-table th {
  background: #f8fafc;
  color: var(--text-sub);
  font-weight: 800;
  padding: 8px 10px;
  border-bottom: 1px solid var(--border-color);
  text-align: left;
}

.summary-table td {
  padding: 8px 10px;
  border-bottom: 1px solid var(--border-color);
  font-weight: 700;
}

.summary-table tr.is-clear-row {
  background: #fefce8;
}