/* ================================================================
   ちびドットアイコンジェネレータ – スタイルシート
   ================================================================ */

/* ── リセット & 変数 ─────────────────────────────────────────── */
:root {
  --orange:      #E8740A;
  --orange-dark: #C55E00;
  --orange-bg:   #F59030;
  --brown-dark:  #7A4E10;
  --panel-bg:    #C07818;
  --part-bg:     #D08828;
  --part-sel:    #F0A030;
  --border:      #9A6010;
  --text-light:  #FFF5E0;
  --text-dark:   #3A2000;
  --radius:      10px;
  --gap:         8px;
  --nav-h:       40px;  /* nav.css と同値 */
}

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

html, body {
  height: 100%;
  font-family: 'Hiragino Sans', 'Meiryo', 'Yu Gothic', sans-serif;
  background: var(--orange-bg);
  color: var(--text-light);
  font-size: 13px;
}

/* ── レイアウト ─────────────────────────────────────────────── */
#app {
  display: flex;
  gap: var(--gap);
  height: calc(100vh - var(--nav-h));
  max-height: calc(100dvh - var(--nav-h));
  padding: var(--gap);
  overflow: hidden;
}

/* ── 左パネル ────────────────────────────────────────────────── */
#left-panel {
  flex: 0 0 172px;
  display: flex;
  flex-direction: column;
  gap: var(--gap);
  align-items: center;
}

#left-sticky {
  display: flex;
  flex-direction: column;
  gap: var(--gap);
  align-items: center;
  width: 100%;
}

#app-title {
  font-size: 0.95rem;
  font-weight: bold;
  text-align: center;
  line-height: 1.3;
  color: var(--text-dark);
  text-shadow: none;
}

/* プレビューキャンバス */
#canvas-wrap {
  flex: none;       /* 幅変化に連動してサイズが変わらないよう固定 */
  align-self: center;
  background: #fff;
  border: 3px solid var(--brown-dark);
  border-radius: var(--radius);
  padding: 6px;
  box-shadow: inset 0 2px 6px rgba(0,0,0,0.3);
}

#preview-canvas {
  display: block;
  width: 144px;
  height: 144px;
  image-rendering: pixelated;
  image-rendering: crisp-edges;
}

/* 保存セクション */
#save-section {
  width: 100%;
  display: flex;
  flex-direction: column;
  gap: 5px;
}

.save-row {
  display: flex;
  gap: 4px;
}

.save-col {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.save-label {
  font-size: 0.68rem;
  color: var(--brown-dark);
  opacity: 1;
  text-align: center;
}

.save-row select {
  flex: 1;
  padding: 3px 4px;
  border-radius: 6px;
  border: 1.5px solid rgba(255, 255, 255, 0.5);
  background: var(--part-bg);
  color: var(--text-light);
  font-size: 0.75rem;
  cursor: pointer;
}

/* 保存ボタン群（画像を保存 + コピー → 横並び、投稿 → 全幅で次行） */
.save-btns {
  display: flex;
  flex-wrap: wrap;
  gap: 5px;
}
.save-btns .btn-orange {
  flex: 1;                 /* 保存・コピーを横に均等幅 */
}
.save-btns .btn-submit {
  flex: 1 1 100%;          /* ギャラリーに投稿は全幅で次の行 */
}

/* ランダム / リセット */
#random-reset-row {
  width: 100%;
  display: flex;
  flex-direction: row;   /* 常に横並び */
  gap: 5px;
}
#random-reset-row .btn-orange {
  flex: 1;               /* 均等幅 */
}

/* ── オレンジボタン共通 ─────────────────────────────────────── */
.btn-orange {
  background: var(--orange);
  color: var(--text-light);
  border: 2px solid rgba(255, 255, 255, 0.55);
  border-radius: var(--radius);
  padding: 7px 10px;
  font-size: 0.82rem;
  font-weight: bold;
  cursor: pointer;
  box-shadow: 0 3px 0 var(--orange-dark);
  transition: box-shadow 0.1s, transform 0.1s;
  text-align: center;
  user-select: none;
  -webkit-user-select: none;
}
.btn-orange:active {
  box-shadow: none;
  transform: translateY(2px);
}
.btn-orange.wide { width: 100%; }

/* ── 画像を保存（深緑）──────────────────────────────────────── */
#btn-save {
  background: #7D8531;
  box-shadow: 0 3px 0 #5C6224;
}
#btn-save:hover:not(:disabled) { background: #8E9638; }
#btn-save:active { box-shadow: none; }

/* ── SNSでシェア ────────────────────────────────────────────── */
#btn-share {
  background: #6E7687;
  box-shadow: 0 3px 0 #515866;
}
#btn-share:hover:not(:disabled) { background: #7D8799; }
#btn-share:active { box-shadow: none; }

/* ── アンドゥ / リドゥ ──────────────────────────────────────── */
#undo-redo-row {
  display: flex;
  gap: 5px;
  width: 100%;
}
.btn-undo-redo {
  flex: 1;
  background: var(--part-bg);
  color: var(--text-light);
  border: 2px solid rgba(255, 255, 255, 0.45);
  border-radius: var(--radius);
  padding: 5px 6px;
  font-size: 0.78rem;
  font-weight: bold;
  cursor: pointer;
  transition: background 0.1s, opacity 0.1s;
  user-select: none;
  -webkit-user-select: none;
}
.btn-undo-redo:hover:not(:disabled) { background: var(--panel-bg); }
.btn-undo-redo:disabled {
  opacity: 0.35;
  cursor: default;
}

/* ── 投稿アニメーション（上へ飛ぶ） ──────────────────────────── */
@keyframes submit-fly-off {
  0%   { transform: translate(-50%, -50%) scale(1)    rotate(0deg);  opacity: 1; }
  20%  { transform: translate(-50%, -65%) scale(1.35) rotate(-6deg); opacity: 1; }
  100% { transform: translate(-30%, -200%) scale(0.1) rotate(20deg); opacity: 0; }
}

/* ── 保存アニメーション（下へ落ちる） ────────────────────────── */
@keyframes save-drop-down {
  0%   { transform: translate(-50%, -50%) scale(1);    opacity: 1; }
  30%  { transform: translate(-50%, -40%) scale(1.08); opacity: 1; }
  100% { transform: translate(-50%, 230%) scale(0.85); opacity: 0; }
}

/* ── 投稿確認モーダル ───────────────────────────────────────── */
.submit-modal-backdrop {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.6);
  align-items: center;
  justify-content: center;
  z-index: 9999;
}
.submit-modal-backdrop.active { display: flex; }

.submit-modal-box {
  background: #FFF5E0;
  color: #3A2000;
  border-radius: 12px;
  padding: 28px 24px 24px;
  max-width: 340px;
  width: calc(100% - 32px);
  display: flex;
  flex-direction: column;
  gap: 16px;
  box-shadow: 0 8px 32px rgba(0,0,0,0.45);
}
.submit-modal-title {
  font-size: 1rem;
  font-weight: bold;
  color: #3A2000;
}
.submit-modal-list {
  margin: 0 0 0 1.3em;
  display: flex;
  flex-direction: column;
  gap: 8px;
  font-size: 0.88rem;
  line-height: 1.7;
  color: #4A2800;
}
.submit-modal-btns {
  display: flex;
  gap: 10px;
}
.submit-modal-yes {
  flex: 1;
  background: #E8740A;
  color: #FFF5E0;
  border: none;
  border-radius: 8px;
  padding: 10px;
  font-weight: bold;
  font-size: 0.9rem;
  cursor: pointer;
  transition: background 0.15s;
}
.submit-modal-yes:hover { background: #C55E00; }
.submit-modal-no {
  flex: 1;
  background: #ccc;
  color: #333;
  border: none;
  border-radius: 8px;
  padding: 10px;
  font-weight: bold;
  font-size: 0.9rem;
  cursor: pointer;
  transition: background 0.15s;
}
.submit-modal-no:hover { background: #aaa; }

/* ── 投稿ボタン ─────────────────────────────────────────────── */
.btn-submit {
  background: var(--brown-dark);
  color: var(--text-light);
  border: 2px solid rgba(255, 255, 255, 0.45);
  border-radius: var(--radius);
  padding: 7px 10px;
  font-size: 0.82rem;
  font-weight: bold;
  cursor: pointer;
  transition: background 0.15s;
  text-align: center;
  user-select: none;
  -webkit-user-select: none;
}
.btn-submit:hover:not(:disabled) { background: var(--panel-bg); }
.btn-submit:disabled {
  opacity: 0.6;
  cursor: default;
}

/* ── 右パネル ────────────────────────────────────────────────── */
#right-panel {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: var(--gap);
  overflow: hidden;
}

/* ── タブナビ ────────────────────────────────────────────────── */
#tab-nav-wrap {
  display: flex;
  align-items: flex-end;  /* タブが複数行でも大⇔小ボタンをパーツ枠に寄せる */
  gap: 4px;
}

#tab-nav {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  flex: 1;
  min-width: 0;
}

/* スクロール矢印ボタン */
.tab-scroll-btn {
  flex: none;
  background: var(--orange);
  color: #fff;
  border: none;
  border-radius: 8px;
  padding: 4px 7px;
  font-size: 0.75rem;
  cursor: pointer;
  box-shadow: 0 2px 0 var(--orange-dark);
  transition: opacity 0.15s;
  user-select: none;
  -webkit-user-select: none;
  line-height: 1;
}
.tab-scroll-btn[hidden] { display: none; }

/* サムネイルサイズ切り替えトグル */
#btn-thumb-size {
  flex: none;
  display: flex;
  align-items: center;
  gap: 2px;
  background: rgba(0,0,0,0.25);
  border: 1px solid var(--border);
  border-radius: 20px;
  color: var(--text-light);
  cursor: pointer;
  font-size: 0.72rem;
  padding: 3px 8px;
  white-space: nowrap;
  user-select: none;
  -webkit-user-select: none;
  transition: background 0.15s;
}
#btn-thumb-size:hover { background: rgba(0,0,0,0.4); }
#btn-thumb-size .ts-lbl  { font-weight: bold; line-height: 1; }
#btn-thumb-size .ts-on   { opacity: 1; }
#btn-thumb-size .ts-off  { opacity: 0.4; }
#btn-thumb-size .ts-arrow { opacity: 0.6; font-size: 0.65rem; }

/* サムネイル小モード（48px） */
#right-panel.thumb-sm .part-thumb,
#right-panel.thumb-sm .skin-swatch-btn {
  flex-shrink: 0;
  width: 48px;
  height: 48px;
}

.tab-btn {
  background: var(--part-bg);
  color: var(--text-light);
  border: 2px solid var(--border);
  border-radius: 8px;
  padding: 4px 10px;
  font-size: 0.78rem;
  cursor: pointer;
  white-space: nowrap;
  transition: background 0.1s;
}
.tab-btn:hover { background: var(--part-sel); }
.tab-btn.active {
  background: var(--text-dark);
  color: #FFD060;
  border-color: #FFD060;
}

/* ── パーツエリア ─────────────────────────────────────────────── */
#parts-area {
  flex: 1;
  min-height: 0;
  background: var(--panel-bg);
  border-radius: var(--radius);
  border: 2px solid var(--border);
  padding: var(--gap);
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 16px;
  position: relative;
}

/* ── スタート画面オーバーレイ ──────────────────────────────── */
#start-screen {
  position: fixed;
  inset: 0;
  z-index: 500;
  background: rgba(0, 0, 0, 0.6);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  transition: opacity 0.4s ease;
}
#start-screen.fade-out {
  opacity: 0;
  pointer-events: none;
}
#start-card {
  background: var(--panel-bg);
  border: 4px solid var(--orange-bg);
  border-radius: 16px;
  padding: 24px 28px;
  max-width: 440px;
  width: 100%;
  display: flex;
  flex-direction: column;
  gap: 16px;
  box-shadow: 0 8px 40px rgba(0, 0, 0, 0.5);
  color: var(--text-light);
}
#start-card h2 {
  font-size: 1.5rem;
  text-align: center;
  margin: 0;
  line-height: 1.4;
  text-shadow: 0 2px 4px rgba(0, 0, 0, 0.3);
}
#start-sample-img {
  width: 100%;
  height: auto;
  display: block;
  image-rendering: pixelated;
  image-rendering: crisp-edges;
  border-radius: 6px;
}
#start-desc {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
}
#start-desc li {
  padding: 8px 4px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.2);
  font-size: 0.88rem;
  line-height: 1.5;
}
#start-desc li:first-child {
  border-top: 1px solid rgba(255, 255, 255, 0.2);
  font-weight: bold;
}
#start-progress-wrap {
  height: 6px;
  background: rgba(0, 0, 0, 0.35);
  border-radius: 3px;
  overflow: hidden;
}
#start-progress-bar {
  height: 100%;
  width: 0%;
  background: #FFE066;
  border-radius: 3px;
  transition: width 0.25s ease;
}
#btn-start {
  background: linear-gradient(180deg, var(--orange-bg) 0%, var(--orange) 100%);
  color: var(--text-dark);
  border: 3px solid rgba(255, 255, 255, 0.5);
  border-radius: var(--radius);
  padding: 14px 28px;
  font-size: 1.25rem;
  font-weight: bold;
  cursor: pointer;
  box-shadow: 0 4px 0 var(--brown-dark);
  transition: transform 0.1s, box-shadow 0.1s, opacity 0.2s;
  align-self: center;
  min-width: 180px;
  font-family: inherit;
}
#btn-start:hover:not(:disabled) {
  transform: translateY(-2px);
  box-shadow: 0 6px 0 var(--brown-dark);
}
#btn-start:active:not(:disabled) {
  transform: translateY(2px);
  box-shadow: 0 2px 0 var(--brown-dark);
}
#btn-start:disabled {
  opacity: 0.75;
  cursor: wait;
}
@media (max-width: 480px) {
  #start-card { padding: 18px 16px; gap: 12px; }
  #start-card h2 { font-size: 1.25rem; }
  #btn-start { font-size: 1.1rem; padding: 12px 20px; }
}

/* ローディングオーバーレイ */
#loading-overlay {
  position: absolute;
  inset: 0;
  background: rgba(0,0,0,0.5);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  border-radius: var(--radius);
  z-index: 10;
  gap: 10px;
}
.spinner {
  width: 32px;
  height: 32px;
  border: 3px solid rgba(255,255,255,0.3);
  border-top-color: #fff;
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ── スロットグループ ─────────────────────────────────────────── */
.slot-group {
  display: none;
  flex-direction: column;
  gap: 8px;
}
.slot-group.active {
  display: flex;
  background: rgba(0, 0, 0, 0.18);
  border-radius: 8px;
  padding: 8px;
}

.slot-label {
  font-size: 0.9rem;
  font-weight: bold;
  color: var(--text-light);
  border-bottom: 1px solid rgba(255, 255, 255, 0.3);
  padding-bottom: 5px;
}

/* スロットヘッダー（ラベル＋コントロール）をスクロールエリア上部に固定 */
.slot-header-sticky {
  position: sticky;
  top: 0;
  z-index: 5;
  background: var(--part-bg);
  border-radius: 6px;
  padding: 6px;
  margin-bottom: 4px;
  box-shadow: 0 2px 6px rgba(0,0,0,0.3);
}

/* コントロールバー（位置＋色） */
.slot-controls {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-wrap: wrap;
}

/* 位置ラベル */
.move-label {
  font-size: 0.75rem;
  background: var(--part-bg);
  border-radius: 6px;
  padding: 2px 7px;
  font-weight: bold;
}

/* 位置調整ボタン */
.move-btn {
  width: 30px;
  height: 30px;
  background: var(--orange);
  color: #fff;
  border: none;
  border-radius: 6px;
  font-size: 1rem;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 2px 0 var(--orange-dark);
  transition: box-shadow 0.1s, transform 0.1s;
  user-select: none;
  -webkit-user-select: none;
}
.move-btn:active {
  box-shadow: none;
  transform: translateY(2px);
}

/* 色変更ボタン */
.color-ctrl {
  display: flex;
  align-items: center;
  gap: 4px;
  margin-left: auto;
}
.color-ctrl-label {
  font-size: 0.72rem;
  white-space: nowrap;
}
.color-btn {
  background: var(--part-bg);
  border: 2px solid var(--brown-dark);
  border-radius: 6px;
  padding: 2px;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 4px;
  font-size: 0.72rem;
  color: var(--text-light);
  transition: border-color 0.1s;
}
.color-btn:hover { border-color: #FFD060; }
.color-swatch {
  display: inline-block;
  width: 20px;
  height: 20px;
  border-radius: 3px;
  border: 1px solid rgba(0,0,0,0.3);
  vertical-align: middle;
}
.color-swatch.large {
  width: 32px;
  height: 32px;
}

/* パーツサムネイルグリッド */
.parts-grid {
  display: flex;
  flex-wrap: wrap;
  gap: 5px;
}

/* サムネイルボタン
   border を使うと border-box でコンテンツ幅が削れてキャンバスが
   非整数倍率になりジャギるため、box-shadow で枠を表現する */
.part-thumb {
  flex-shrink: 0; /* flexレイアウトでも縮まないよう固定 */
  width: 96px;
  height: 96px;
  background: var(--part-bg);
  border: none;
  border-radius: 8px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  box-shadow: 0 0 0 2px var(--border);
  transition: box-shadow 0.1s, background 0.1s;
  position: relative;
}
.part-thumb:hover { box-shadow: 0 0 0 2px #FFD060; }
.part-thumb.selected {
  background: var(--part-sel);
  box-shadow: 0 0 0 3px #FFD060;
}
.part-thumb img {
  width: 100%;
  height: 100%;
  object-fit: contain;
  image-rendering: pixelated;
  image-rendering: crisp-edges;
}
.thumb-canvas {
  display: block;
  flex-shrink: 0; /* flex親（.part-thumb）に縮められないよう固定 → 非整数縮小でジャギ防止 */
  /* width/height は JS（thumbPx変数）でインライン設定 → CSS グリッド端数を回避 */
  image-rendering: pixelated;
  image-rendering: crisp-edges;
}
.part-thumb.none-thumb {
  font-size: 0.82rem;
  font-weight: bold;
  color: #fff;
  text-shadow: 0 1px 3px rgba(0,0,0,0.6);
}

/* 肌色プリセットグリッド（体タブ専用） */
#skin-preset-grid {
  display: flex;
  flex-wrap: wrap;
  gap: 5px;
}
.skin-swatch-btn {
  flex-shrink: 0; /* flexレイアウトでも縮まないよう固定 */
  width: 96px;
  height: 96px;
  border: 3px solid transparent;
  border-radius: 8px;
  cursor: pointer;
  transition: border-color 0.1s, transform 0.1s;
}
.skin-swatch-btn:hover { border-color: #FFD060; transform: scale(1.05); }
.skin-swatch-btn.selected { border-color: #fff; }

/* オッドアイ / 左右別色ポップアップ */
#odd-eye-popup,
#lr-color-popup {
  position: fixed;
  right: 12px;
  top: 50%;
  transform: translateY(-50%);
  background: var(--part-bg);
  border: 2px solid var(--border);
  border-radius: var(--radius);
  padding: 10px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  z-index: 50;
  box-shadow: 0 4px 16px rgba(0,0,0,0.5);
  min-width: 150px;
}
#odd-eye-popup[hidden],
#lr-color-popup[hidden] { display: none; }
.odd-eye-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  font-size: 0.78rem;
  font-weight: bold;
}
#odd-eye-close,
#lr-color-close {
  background: none;
  border: none;
  color: var(--text-light);
  cursor: pointer;
  font-size: 1rem;
  line-height: 1;
  padding: 0;
}
.odd-eye-row {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 0.78rem;
}

/* 左右表示トグル（しわ等） */
.lr-toggle-wrap {
  display: flex;
  gap: 6px;
  align-items: center;
}
.lr-toggle-label {
  display: flex;
  align-items: center;
  gap: 3px;
  font-size: 0.75rem;
  cursor: pointer;
  color: var(--text-light);
  user-select: none;
}
.lr-toggle-label input[type="checkbox"] {
  cursor: pointer;
  accent-color: var(--orange);
  width: 14px;
  height: 14px;
  flex-shrink: 0;
}

/* グローバルコントロール */
#global-controls {
  border-top: 1px solid var(--border);
  padding-top: 8px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.global-ctrl-row {
  display: flex;
  align-items: center;
  gap: 8px;
}
.ctrl-label { font-size: 0.78rem; }

/* ── カラーピッカー タブ ────────────────────────────────────── */
#picker-tabs {
  display: flex;
  gap: 4px;
}
.picker-tab {
  flex: 1;
  background: rgba(0,0,0,0.35);
  color: var(--text-light);
  border: 1.5px solid rgba(255,255,255,0.25);
  border-radius: 6px;
  padding: 4px 8px;
  font-size: 0.75rem;
  font-weight: bold;
  cursor: pointer;
  transition: background 0.1s;
}
.picker-tab.active {
  background: var(--orange);
  border-color: rgba(255,255,255,0.55);
}
.picker-tab:hover:not(.active) { background: rgba(0,0,0,0.5); }

/* ── HSVピッカー ─────────────────────────────────────────────── */
#picker-panel-wheel {
  display: flex;
  flex-direction: column;
  gap: 6px;
}
#hsv-sv-canvas {
  display: block;
  width: 100%;
  height: 150px;
  border-radius: 6px;
  cursor: crosshair;
  touch-action: none;
  border: 1px solid var(--border);
}
#hsv-hue-canvas {
  display: block;
  width: 100%;
  height: 18px;
  border-radius: 9px;
  cursor: pointer;
  touch-action: none;
}

/* ── カラーピッカー ────────────────────────────────────────── */
#color-picker-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.4);
  z-index: 100;
}
#color-picker-backdrop[hidden] { display: none; }

#color-picker-popup {
  position: fixed;
  top: 50%;   /* 初期値（開くたびに positionPicker() がJS上書き） */
  left: 50%;
  transform: translate(-50%, -50%);
  background: #3A2800;
  border: 3px solid var(--orange);
  border-radius: var(--radius);
  padding: 12px;
  z-index: 101;
  display: flex;
  flex-direction: column;
  gap: 8px;
  min-width: 220px;
}
#color-picker-popup[hidden] { display: none; }

#color-picker-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
}
#color-picker-title { font-size: 0.85rem; font-weight: bold; }
#color-picker-close {
  background: none;
  border: none;
  color: var(--text-light);
  cursor: pointer;
  font-size: 1rem;
  line-height: 1;
}

#color-palette-grid {
  display: grid;
  grid-template-columns: repeat(12, 1fr);
  gap: 2px;
  width: 100%;
  border-radius: 4px;
  border: 1px solid var(--border);
  padding: 4px;
  background: #2A1800;
}
.palette-swatch {
  aspect-ratio: 1;
  border-radius: 2px;
  cursor: pointer;
  border: 1px solid rgba(0,0,0,0.25);
  position: relative;
  transition: transform 0.1s, box-shadow 0.1s;
}
.palette-swatch:hover {
  transform: scale(1.3);
  box-shadow: 0 0 0 2px #FFD060;
  z-index: 2;
}

#hex-row {
  display: flex;
  align-items: center;
  gap: 5px;
}
#btn-apply-color {
  font-size: 0.7rem;
  padding: 4px 8px;
  white-space: nowrap;
}
#hex-input {
  flex: 1;
  background: #1A1000;
  color: #FFD060;
  border: 1px solid var(--border);
  border-radius: 5px;
  padding: 4px 6px;
  font-family: monospace;
  font-size: 0.9rem;
}

#color-preview-row {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 0.78rem;
}

/* ── スマホ縦向き：タイトルを1行に ──────────────────────────── */
@media (max-width: 600px) and (orientation: portrait) {
  #app-title br { display: none; }
  #app-title { font-size: 0.82rem; }
}

/* ── レスポンシブ（スマホ縦） ────────────────────────────────── */
@media (max-width: 600px) {
  /* フロー要素をすべて潰す（fixed 要素のみ表示） */
  #app      { height: 0; overflow: visible; }
  #left-panel { flex: 0 0 0; overflow: visible; }
  #right-panel { flex: 0 0 0; height: 0; overflow: visible; padding-top: 0; }

  /* ── プレビュー＋ボタン群: fixed 固定 ─────────────────────── */
  #left-sticky {
    position: fixed;
    top: var(--nav-h);
    left: 0;
    right: 0;
    z-index: 30;
    display: flex;
    flex-direction: row;
    flex-wrap: wrap;
    background: var(--orange-bg);
    box-shadow: 0 3px 8px rgba(0,0,0,0.3);
    justify-content: center;
    align-items: flex-start;
    gap: var(--gap);
    padding: var(--gap) var(--gap) 4px;
  }
  #app-title { width: 100%; }
  #canvas-wrap { flex: 0 0 auto; }
  #save-section { flex: 1; width: auto; min-width: 0; }
  /* スマホ縦: ボタンを2列グリッド（保存+コピー / ギャラリー+SNS） */
  .save-btns { flex-direction: row; flex-wrap: wrap; }
  .save-btns .btn-submit { flex: 1; }   /* 全幅を解除して隣に並ぶ */
  .save-btns .btn-orange,
  .save-btns .btn-submit { font-size: 0.68rem; padding: 5px 4px; }

  /* ── タブナビ: left-sticky 直下に fixed 固定 ─────────────── */
  #tab-nav-wrap {
    position: fixed;
    top: calc(var(--nav-h) + var(--left-sticky-h, 200px));
    left: 0;
    right: 0;
    z-index: 29;
    background: var(--orange-bg);
    padding: 4px var(--gap);
    box-shadow: 0 2px 4px rgba(0,0,0,0.15);
  }

  /* ── パーツエリア: タブナビ直下〜画面下端まで fixed ─────── */
  #parts-area {
    position: fixed;
    top: calc(var(--nav-h) + var(--left-sticky-h, 200px) + var(--tab-nav-h, 44px));
    bottom: 0;
    left: 0;
    right: 0;
    border-radius: 0;
    overflow-y: auto;
    flex: none;
    min-height: 0;
  }

  /* タブナビを1行横スクロールに */
  #tab-nav {
    flex-wrap: nowrap;
    overflow-x: auto;
    scrollbar-width: none;
    -ms-overflow-style: none;
  }
  #tab-nav::-webkit-scrollbar { display: none; }
}

@media (max-width: 400px) {
  /* 極狭画面でもキャンバスと横並びを維持。キャンバスを少し縮小して右側を確保 */
  #preview-canvas { width: 112px; height: 112px; }
}


/* ── 不透明度ドットセレクター（不透明度 ○─○─●─○─○） ──── */
.opacity-steps {
  display: flex;
  align-items: center;
  gap: 3px;
  margin-left: auto;
}
.opacity-steps-label {
  font-size: 0.65rem;
  color: var(--text-light);
  opacity: 0.85;
  white-space: nowrap;
  margin-right: 2px;
}
.opacity-step-dot {
  width: 11px;
  height: 11px;
  border-radius: 50%;
  border: 1.5px solid rgba(255, 255, 255, 0.8);
  background: transparent;
  cursor: pointer;
  padding: 0;
  flex-shrink: 0;
  transition: background 0.1s, border-color 0.1s;
}
.opacity-step-dot.active {
  background: rgba(255, 255, 255, 0.9);
  border-color: #fff;
}
.opacity-step-dot:hover:not(.active) {
  background: rgba(255, 255, 255, 0.3);
}
.opacity-step-line {
  display: block;
  width: 7px;
  height: 1.5px;
  background: rgba(255, 255, 255, 0.45);
  flex-shrink: 0;
  border-radius: 1px;
}

/* ── スクロールバー ─────────────────────────────────────────── */
#parts-area::-webkit-scrollbar { width: 6px; }
#parts-area::-webkit-scrollbar-thumb {
  background: var(--brown-dark);
  border-radius: 3px;
}

/* ── 画像の使用について ボタン ─────────────────────────────── */
#terms-btn-wrap {
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 10px;
  padding: 12px 8px 4px;
  flex-wrap: wrap;
}
#btn-terms {
  background: var(--brown-dark);
  border: 2px solid var(--border);
  color: var(--text-light);
  border-radius: 8px;
  padding: 7px 22px;
  font-size: 0.82rem;
  font-weight: bold;
  cursor: pointer;
  opacity: 0.9;
  transition: opacity 0.15s, background 0.15s;
  letter-spacing: 0.03em;
}
#btn-terms:hover { opacity: 1; background: var(--orange-dark); }
#btn-marshmallow {
  display: inline-block;
  background: var(--brown-dark);
  border: 2px solid var(--border);
  color: var(--text-light);
  border-radius: 8px;
  padding: 7px 22px;
  font-size: 0.82rem;
  font-weight: bold;
  cursor: pointer;
  opacity: 0.9;
  text-decoration: none;
  letter-spacing: 0.03em;
  transition: opacity 0.15s, background 0.15s;
}
#btn-marshmallow:hover { opacity: 1; background: var(--orange-dark); }
#btn-gallery-link {
  display: inline-block;
  background: var(--brown-dark);
  border: 2px solid var(--border);
  color: var(--text-light);
  text-decoration: none;
  border-radius: var(--radius);
  padding: 5px 10px;
  font-size: 0.78rem;
  opacity: 0.85;
  letter-spacing: 0.03em;
  transition: opacity 0.15s, background 0.15s;
}
#btn-gallery-link:hover { opacity: 1; background: var(--orange-dark); }
.lang-alt-link {
  font-size: 0.75rem;
  color: var(--text-light);
  opacity: 0.7;
  text-decoration: underline;
  text-underline-offset: 3px;
  transition: opacity 0.15s;
}
.lang-alt-link:hover { opacity: 1; }

/* ── 画像の使用について モーダル ────────────────────────────── */
#terms-modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.55);
  z-index: 80;
}
#terms-modal-backdrop[hidden] { display: none; }

#terms-modal {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 81;
  padding: 16px;
}
#terms-modal[hidden] { display: none; }

#terms-modal-inner {
  background: #FFF5E0;
  border: 2px solid #B8916A;
  border-radius: var(--radius);
  width: 100%;
  max-width: 520px;
  max-height: 85vh;
  display: flex;
  flex-direction: column;
  box-shadow: 0 6px 24px rgba(0,0,0,0.6);
}

#terms-modal-header {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  padding: 8px 10px 4px;
  flex-shrink: 0;
}
#terms-modal-title {
  font-size: 0.85rem;
  font-weight: bold;
  color: #4A2800;
}
#terms-modal-close {
  background: none;
  border: none;
  color: #4A2800;
  cursor: pointer;
  font-size: 1rem;
  line-height: 1;
  padding: 0;
}

#terms-modal-body {
  overflow-y: auto;
  padding: 16px 20px 22px;
  color: #4A2800;
  font-size: 0.92rem;
  line-height: 1.75;
  display: flex;
  flex-direction: column;
  gap: 12px;
}
#terms-modal-body h2 {
  font-size: 1.1rem;
  margin-bottom: 0;
}
#terms-modal-body h3 {
  font-size: 1rem;
  font-weight: bold;
  margin-bottom: 0;
}
.terms-section-title {
  font-weight: bold;
  margin-bottom: -4px;
  color: #8B1A00;
}
.terms-list {
  margin: 0 0 0 1.5em;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 8px;
  color: #8B1A00;
}
/* 禁止事項以外の中立セクション用（モーダル内） */
.terms-section-heading {
  font-weight: bold;
  margin-bottom: -4px;
  color: #5A2E00;
}
.terms-neutral-list {
  margin: 0 0 0 1.5em;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 8px;
  color: #4A2800;
}
.terms-neutral-list a {
  color: #7A3A00;
  text-decoration: underline;
  text-underline-offset: 2px;
}
.terms-neutral-list a:hover { color: #C55E00; }
.terms-author {
  border-top: 1px solid #C8A882;
  padding-top: 12px;
  font-size: 0.88rem;
  opacity: 0.85;
}
.terms-author a {
  color: #4A2800;
  text-underline-offset: 2px;
}

/* ── フッター ───────────────────────────────────────────────── */
#app-footer {
  display: flex;
  justify-content: center;
  align-items: center;
  padding: 20px 8px 24px;
  font-size: 0.72rem;
  color: var(--text-light);
  opacity: 0.75;
  background: var(--orange-bg);
  letter-spacing: 0.02em;
}
/* リンク色：ブラウザデフォルト（青）を明示的に上書き */
#app-footer a,
#app-footer a:link,
#app-footer a:visited {
  color: #FFF5E0;
  text-decoration: underline;
  text-underline-offset: 2px;
}
#app-footer a:hover { opacity: 0.75; }
