/* === Reset & Base === */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --primary: #2a8175;
  --primary-dark: #226b60;
  --danger: #b95050;
  --bg: #f1f6f6;
  --surface: #ffffff;
  --text: #29363b;
  --text-muted: #64787d;
  --border: #e2ebea;
  --radius: 14px;
  --shadow: 0 1px 3px rgba(35,50,55,.05), 0 10px 30px rgba(35,50,55,.08);
  --accent-soft: #d9efec;
  --accent-ink: #23756b;
  --share-green: #3f7a54;
  --solo-blue: #4a7aa8;
  --amber: #e59413;
  --shadow-btn: 0 4px 14px rgba(42,129,117,.30);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

html {
  font-size: 16px;
  -webkit-text-size-adjust: 100%;
}

body {
  font-family: 'Noto Sans JP', -apple-system, BlinkMacSystemFont, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.6;
  min-height: 100dvh;
  overscroll-behavior: none;
}

/* === Layout === */
.page {
  max-width: 480px;
  margin: 0 auto;
  padding: 16px;
  min-height: 100dvh;
}

.page-wide {
  max-width: 960px;
}

/* === Header === */
.header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 0;
  margin-bottom: 16px;
  border-bottom: 1px solid var(--border);
}

.header h1 {
  font-size: 1.1rem;
  font-weight: 700;
}

.header-actions {
  display: flex;
  gap: 8px;
}

.btn-back {
  display: flex;
  align-items: center;
  gap: 4px;
  color: var(--primary);
  text-decoration: none;
  font-size: 0.9rem;
  background: none;
  border: none;
  cursor: pointer;
}

/* === Buttons === */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 10px 20px;
  border: none;
  border-radius: 999px;
  font-size: 0.95rem;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s, transform 0.1s;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
}

.btn:active {
  transform: scale(0.97);
}

.btn-primary {
  background: linear-gradient(160deg,#319082,#27786d);
  color: #fff;
  box-shadow: var(--shadow-btn);
}
.btn-primary:hover { background: #226b60; }

.btn-secondary {
  background: #e7efee;
  color: var(--text);
}

.btn-danger {
  background: var(--danger);
  color: #fff;
}

.btn-sm {
  padding: 6px 12px;
  font-size: 0.85rem;
}

.btn-icon {
  width: 40px;
  height: 40px;
  padding: 0;
  border-radius: 50%;
  font-size: 1.2rem;
}

.btn-block {
  display: flex;
  width: 100%;
}

/* === Cards === */
.card {
  background: var(--surface);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 20px;
  margin-bottom: 12px;
}

/* === Template Cards === */
.template-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 12px;
}

.template-card {
  background: var(--surface);
  border: 2px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  text-align: center;
  cursor: pointer;
  transition: border-color 0.15s, transform 0.1s;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
}

.template-card:active {
  transform: scale(0.98);
}

.template-card:hover,
.template-card.selected {
  border-color: var(--primary);
}

.template-card h3 {
  font-size: 1.1rem;
  margin-bottom: 4px;
}

/* トップ画面の横型テンプレ行 (S007: 縦積みは間延びし保存済みボタンが沈む) */
.tcard-row {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 12px 16px;
  text-align: left;
}

.tcard-preview {
  width: 76px;
  height: 56px;
  flex: none;
  display: flex;
  align-items: center;
  justify-content: center;
}

.template-card .size {
  color: var(--text-muted);
  font-size: 0.85rem;
}

.template-preview {
  width: 100%;
  max-width: 200px;
  margin: 12px auto;
  aspect-ratio: auto;
  background: #fff;
  border: 1px solid var(--border);
}

/* === Form === */
.form-group {
  margin-bottom: 16px;
}

.form-group label {
  display: block;
  font-weight: 600;
  margin-bottom: 6px;
  font-size: 0.9rem;
}

.form-input {
  width: 100%;
  padding: 12px 16px;
  border: 2px solid var(--border);
  border-radius: var(--radius);
  font-size: 1rem;
  font-family: inherit;
  outline: none;
  transition: border-color 0.15s;
  -webkit-appearance: none;
}

.form-input:focus {
  border-color: var(--primary);
}

.form-select {
  width: 100%;
  padding: 10px 14px;
  border: 2px solid var(--border);
  border-radius: var(--radius);
  font-size: 0.95rem;
  font-family: inherit;
  background: var(--surface);
  cursor: pointer;
}

/* === Editor Layout === */
.editor-container {
  display: flex;
  flex-direction: column;
  width: 100%;
  height: 100dvh;
  overflow: hidden;
}

.editor-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 12px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

.editor-header h1 {
  font-size: 1rem;
  font-weight: 700;
  /* 参加者名は長い場合がある: 折り返さず省略(S007 縦 UI 点検) */
  flex: 1;
  min-width: 0;
  margin: 0 8px;
  text-align: center;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

#autosave-status:not(:empty) {
  background: var(--accent-soft);
  color: var(--accent-ink);
  padding: 3px 10px;
  border-radius: 999px;
  font-weight: 700;
}

.canvas-wrapper {
  flex: 1;
  width: 100%;
  background: linear-gradient(180deg,#e6efef,#dfe9e9);
  overflow: hidden;
  position: relative;
  min-height: 0;
  touch-action: none;
}

/* 編集モード切替時の再センタリングをなめらかに */
.canvas-wrapper .canvas-container {
  transition: margin 0.25s ease;
}


.palette-container {
  flex-shrink: 0;
  background: var(--surface);
  border-top: 1px solid var(--border);
  padding-bottom: var(--safe-bottom);
  position: relative; /* スクロールヒントの基準 */
}

/* タブ内に隠れた続きがある時だけ出す案内(表示制御は editor.js) */
#scroll-more-hint {
  position: absolute;
  bottom: calc(8px + var(--safe-bottom));
  left: 50%;
  background: var(--text);
  color: #fff;
  font-size: 0.68rem;
  font-weight: 700;
  padding: 4px 13px;
  border-radius: 999px;
  opacity: 0.75;
  pointer-events: none;
  z-index: 5;
  animation: hint-bob 1.1s ease-in-out infinite alternate;
}

@keyframes hint-bob {
  from { transform: translate(-50%, 0); }
  to   { transform: translate(-50%, 4px); }
}

/* スマホ横持ちガード: 横向き×低背(=スマホ)の時だけ全画面表示 */
#rotate-notice { display: none; }

@media (orientation: landscape) and (max-height: 499px) {
  #rotate-notice {
    display: flex;
    position: fixed;
    inset: 0;
    z-index: 9999;
    background: var(--bg);
    align-items: center;
    justify-content: center;
    text-align: center;
    font-size: 1rem;
    font-weight: 700;
    color: var(--text);
    line-height: 1.8;
  }
}

.palette-tabs {
  display: flex;
  border-bottom: 1px solid var(--border);
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}

.palette-tab {
  position: relative;
  flex: 1;
  min-width: 0;
  padding: 6px 0 7px;
  border: none;
  background: none;
  font-size: 0.65rem;
  font-weight: 700;
  color: var(--text-muted);
  cursor: pointer;
  white-space: nowrap;
  border-bottom: 3px solid transparent;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
}

.tab-ico {
  font-size: 1.15rem;
  line-height: 1.2;
}

.tab-ico-moji {
  font-weight: 800;
  font-size: 1.05rem;
}

.palette-tab.active {
  color: var(--accent-ink);
  border-bottom-color: transparent;
  background: var(--accent-soft);
}

.palette-tab.active::after {
  content: ""; position: absolute; left: 22%; right: 22%; bottom: 2px;
  height: 3px; border-radius: 99px; background: var(--primary);
}

.palette-content {
  height: 220px;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding: 8px;
  overscroll-behavior: contain;
}

/* stamps tab */
#tab-stamps {
  display: flex !important;
  flex-direction: column !important;
  padding: 0 !important;
  overflow: hidden !important;
}
#tab-stamps.hidden {
  display: none !important;
}

.stamp-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(52px, 1fr));
  gap: 6px;
}

.stamp-item {
  width: 46px;
  height: 46px;
  display: flex;
  align-items: center;
  justify-content: center;
  border: 1px solid var(--border);
  border-radius: 8px;
  cursor: pointer;
  background: var(--surface);
  padding: 6px;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
  transition: border-color 0.1s, transform 0.1s;
}

/* スキャンの絵は「自分のもの」を見分ける必要があるので、スタンプより大きく出す
   (S006 user 指摘: 46px では判別できない)。枠は縦長 3:4 — スキャン原稿は
   縦長のメモ用紙が多く、横長枠だと contain 縮小で小さく見える(同指摘 2 回目) */
#scan-grid {
  grid-template-columns: repeat(auto-fill, minmax(100px, 1fr));
}
#scan-grid .stamp-item {
  width: 100%;
  height: auto;
  aspect-ratio: 3 / 4;
}
@media (min-width: 640px) {
  /* PC は横に余裕があるので列をさらに大きく */
  #scan-grid {
    grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
  }
}
/* 「あなたの スキャン」枠は横並び 1 段。パレット領域は全デバイス 220px 固定
   (S005) なので、ボタン+見出しを引いた残りに収まる固定高にする — %指定は
   レイアウト連鎖で解決されず見切れた (S006)。多い時は横スクロール */
#scan-mine-grid {
  display: flex;
  flex-wrap: nowrap;
  gap: 6px;
  overflow-x: auto;
  overflow-y: hidden;
  align-items: flex-start;
}
#scan-mine-grid .stamp-item {
  flex: 0 0 auto;
  height: 128px;
  width: auto;
  aspect-ratio: 3 / 4;
}

.stamp-item:active {
  transform: scale(0.92);
  border-color: var(--primary);
}

.stamp-item svg,
.stamp-item img {
  width: 100%;
  height: 100%;
  object-fit: contain;
}

/* Edit-mode bottom bar (shown instead of the palette while an object is selected) */
#edit-done-bar {
  flex-shrink: 0;
  background: var(--surface);
  border-top: 1px solid var(--border);
  padding: 8px 10px calc(8px + var(--safe-bottom));
}

#edit-done-bar .edit-tools {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 8px;
}

/* flex-basis 40% = 2×2 折り返し: ボタン 4 個(テキスト選択時)が 360px 級で
   「大きさ・回転」の文字幅を下回り nowrap がはみ出すため(S007 縦 UI 点検) */
#edit-done-bar .edit-tools button {
  flex: 1 1 40%;
  height: 48px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--surface);
  color: var(--text);
  font-size: 0.85rem;
  font-weight: 600;
  white-space: nowrap;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
}

#edit-done-bar .edit-tools button.btn-del {
  background: var(--danger);
  color: #fff;
  border-color: var(--danger);
}

#edit-done-bar .edit-tools #btn-resize.active,
#edit-done-bar .edit-tools #btn-order.active {
  background: var(--amber);
  color: #fff;
  border-color: var(--amber);
}

#edit-done-bar .edit-done-btn {
  display: block;
  width: 100%;
  height: 48px;
  border: none;
  border-radius: 10px;
  background: var(--primary);
  color: #fff;
  font-size: 0.95rem;
  font-weight: 700;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
}

/* Pen tab (phone-first: big tap targets, visual presets)
   S007: 文字タブと同じ作法に統一 — 主ボタンは全幅ピル、他は同一チップ、
   幅が足りない時は折り返し(サイドバー 284px で 5 個目がはみ出す実測対策) */
.pen-row {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-bottom: 6px;
}

/* 太さ・線種は常に 1 行の固定列グリッド: 折り返しの全幅孤立で
   グループの境目が消える(S007 実測)のを防ぐ */
.pen-grid-4 { display: grid; grid-template-columns: repeat(4, 1fr); }
/* 線種は横長サンプルの縦 5 段(S007 user 指定 — 小さい四角の横並びより判別しやすい) */
.pen-grid-5 { display: grid; grid-template-columns: 1fr; }

.pen-group-label {
  font-size: 0.68rem;
  font-weight: 700;
  color: var(--text-muted);
  margin: 4px 2px 4px;
}


.pen-big {
  flex: 1 1 100%;
  height: 48px;
  font-size: 0.95rem;
  font-weight: 700;
  border-radius: 999px;
  border: none;
  background: var(--primary);
  color: #fff;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
}

.pen-big.drawing {
  background: #d9663a;
}

.pen-sub {
  flex: 1 1 40%;
  height: 44px;
  font-size: 0.85rem;
  font-weight: 600;
  border-radius: 10px;
  border: 2px solid var(--border);
  background: var(--surface);
  color: var(--text);
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
}

.pen-sub.on {
  background: var(--danger);
  border-color: var(--danger);
  color: #fff;
}

.pen-w {
  flex: 1 1 72px;
  height: 52px;
  border: 2px solid var(--border);
  border-radius: 10px;
  background: var(--surface);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 3px;
  font-size: 0.62rem;
  color: #475569;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
}

.pen-dot {
  border-radius: 50%;
  background: #1e293b;
}

.pen-ls {
  flex: 1 1 56px;
  height: 40px;
  border: 2px solid var(--border);
  border-radius: 10px;
  background: var(--surface);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
}

/* 線種見本は横長にボタン幅いっぱい近くまで伸ばす(viewBox 200×8・縦横比維持) */
.pen-ls svg {
  width: 88%;
  max-width: 320px;
  height: auto;
  display: block;
}

.pen-w.sel, .pen-ls.sel {
  border-color: var(--primary);
  background: var(--accent-soft);
}

.pen-w.sel {
  font-weight: 700;
  color: var(--primary);
}

/* Text tab */
#font-grid, #text-edit-fonts {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 6px;
}

.font-chip {
  padding: 9px 6px;
  border: 2px solid var(--border);
  border-radius: 10px;
  background: var(--surface);
  font-size: 1rem;
  color: var(--text);
  text-align: center;
  cursor: pointer;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
}

.font-chip.sel {
  border-color: var(--primary);
  background: var(--accent-soft);
}

.text-controls {
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 4px 0;
}

/* === Gallery === */
.gallery-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
  gap: 12px;
}

.gallery-item {
  position: relative;
  background: var(--surface);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow: hidden;
  cursor: pointer;
  transition: transform 0.1s;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
}

.gallery-item:active {
  transform: scale(0.97);
}

.gallery-item.processed {
  opacity: 0.6;
}

.processed-badge {
  position: absolute;
  top: 8px;
  right: 8px;
  background: var(--share-green);
  color: #fff;
  font-size: 0.65rem;
  font-weight: 700;
  padding: 2px 6px;
  border-radius: 4px;
  z-index: 1;
}

.gallery-item img {
  width: 100%;
  aspect-ratio: 4/3;
  object-fit: contain;
  background: #fff;
  border-bottom: 1px solid var(--border);
}

.gallery-item .info {
  padding: 8px 10px;
}

.gallery-item .name {
  font-size: 0.85rem;
  font-weight: 600;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.gallery-item .template-label {
  font-size: 0.75rem;
  color: var(--text-muted);
}

/* === Modal === */
.modal-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.5);
  z-index: 1000;
  align-items: flex-end;
  justify-content: center;
}

.modal-overlay.open {
  display: flex;
}

.modal {
  background: var(--surface);
  border-radius: 20px 20px 0 0;
  padding: 24px 20px calc(20px + var(--safe-bottom));
  width: 100%;
  max-width: 480px;
  max-height: 70dvh;
  overflow-y: auto;
}

.modal h2 {
  font-size: 1.1rem;
  margin-bottom: 16px;
}

.modal-actions {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-top: 16px;
}

/* === Toast === */
.toast {
  position: fixed;
  bottom: 80px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--text);
  color: #fff;
  padding: 10px 20px;
  border-radius: 999px;
  font-size: 0.85rem;
  z-index: 2000;
  opacity: 0;
  transition: opacity 0.3s;
  pointer-events: none;
}

.toast.show {
  opacity: 1;
}


/* Canvas toolbar (between header and canvas) */
.canvas-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-evenly;
  padding: 5px 8px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

.canvas-toolbar button {
  padding: 6px 14px;
  border-radius: 8px;
  /* 元に戻す/やり直すを視認させる (S009 user 要望): テーマのミント淡色 */
  border: 1px solid var(--primary);
  background: var(--accent-soft);
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--accent-ink);
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
}

.canvas-toolbar button:disabled {
  opacity: 0.3;
}

.order-btn {
  padding: 6px 14px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--surface);
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--text);
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
}

.order-btn:active {
  background: var(--primary);
  color: #fff;
}

/* === Admin tables === */
.admin-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.85rem;
}

.admin-table th, .admin-table td {
  padding: 8px 10px;
  text-align: left;
  border-bottom: 1px solid var(--border);
}

.admin-table th {
  font-weight: 600;
  background: var(--bg);
}

/* === Filter bar === */
.filter-bar {
  display: flex;
  gap: 8px;
  margin-bottom: 16px;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  padding-bottom: 4px;
}

.filter-chip {
  padding: 6px 14px;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--surface);
  font-size: 0.8rem;
  white-space: nowrap;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
}

.filter-chip.active {
  background: var(--primary);
  color: #fff;
  border-color: var(--primary);
}

/* === Utility === */
.text-center { text-align: center; }
.mt-8 { margin-top: 8px; }
.mt-16 { margin-top: 16px; }
.mt-24 { margin-top: 24px; }
.mb-8 { margin-bottom: 8px; }
.mb-16 { margin-bottom: 16px; }
.gap-8 { gap: 8px; }
.flex { display: flex; }
.flex-col { flex-direction: column; }
.items-center { align-items: center; }
.justify-center { justify-content: center; }
.hidden { display: none !important; }
.empty-state {
  text-align: center;
  padding: 40px 20px;
  color: var(--text-muted);
}

/* === Responsive: larger screens === */
/* .template-grid はここで 3 カラム化しない (S009): コンテナ .page は max-width
   480px のままなので 1 枚 150px になり、横型 tcard-row(プレビュー76px固定)では
   名前列が幅 0 になって 1 文字ずつ縦に折り返していた(PC のみ発症・S007 の回帰) */
@media (min-width: 640px) {
  .gallery-grid {
    grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
  }
}

/* === Wide layout (S007): PC・タブレット横はパレットを左サイドバーに.
   スマホは縦・横ともこのブロックの対象外で従来レイアウトのまま —
   スマホ横持ちはブラウザ UI に高さを食われ実用にならないと実機で確定
   (S007。iPhone 横=高さ 500px 未満 / iPad 横=744px〜 が判定根拠).
   回転時のキャンバス再スケールは非対応(再読込で復帰・自動保存あり) === */
@media (orientation: landscape) and (min-width: 640px) and (min-height: 500px) {
  .editor-container {
    display: grid;
    /* ノッチ・ラウンド角(iPhone 横持ち)ぶんサイドバー列を広げる — S007 実機で
       左レールがノッチに隠れた対策。中身は padding-left で内側へ寄せる */
    grid-template-columns: calc(360px + env(safe-area-inset-left, 0px)) 1fr;
    grid-template-rows: auto auto 1fr auto auto;
  }
  .palette-container,
  #edit-done-bar {
    grid-column: 1;
    grid-row: 1 / -1;
    border-top: none;
    border-right: 1px solid var(--border);
    min-height: 0;
    display: flex;
    flex-direction: column;
    padding-left: env(safe-area-inset-left, 0px);
    padding-bottom: env(safe-area-inset-bottom, 0px);
  }
  /* .hidden の display:none !important はこの指定より強いので排他表示は現行 JS のまま効く */
  .editor-header { grid-column: 2; grid-row: 1; }
  .canvas-toolbar { grid-column: 2; grid-row: 2; }
  .canvas-wrapper { grid-column: 2; grid-row: 3; min-height: 0; min-width: 0; }
  #size-panel { grid-column: 2; grid-row: 4; }
  #order-panel { grid-column: 2; grid-row: 5; }

  /* タブはサイドバー左端の縦アイコンレールに(デスクトップツールの定石)。
     横 1 段では 7 個が見切れ、2 段折り返しは幅不揃いで乱雑(S007 実測)。
     ホバー展開はタッチ環境(タブレット・スタンド置きスマホ)で使えないため不採用 */
  .palette-container { flex-direction: row; }
  .palette-tabs {
    flex-direction: column;
    justify-content: flex-start;
    width: 78px;
    flex-shrink: 0;
    border-bottom: none;
    border-right: 1px solid var(--border);
    overflow-y: auto;
    overflow-x: hidden;
    background: var(--bg); /* レールを一段沈めて主張を弱める(S007 実機指摘) */
  }
  .palette-tab {
    flex: 0 0 auto;
    padding: 13px 0 12px;
    border-bottom: none;
  }
  /* アクティブ表示はレールでは左端の縦バーに */
  .palette-tab.active::after {
    left: 3px;
    right: auto;
    top: 22%;
    bottom: 22%;
    width: 3.5px;
    height: auto;
  }
  /* スタンプのカテゴリチップは横スクロールでなく折り返しで全見せ */
  #stamp-categories { flex-wrap: wrap; }
  .palette-content {
    height: auto;
    flex: 1;
    min-width: 0;
    min-height: 0;
  }

  /* 編集モードバー: 道具を縦積み・高さ 48px で統一。決定ボタンは道具の直下
     (スマホ縦と同じ並び順 — 最下部固定は道具から遠く位置バラバラ感の元 S007) */
  #edit-done-bar { justify-content: flex-start; }
  #edit-done-bar .edit-tools {
    flex-direction: column;
    margin-bottom: 8px;
  }
  #edit-done-bar .edit-tools button { flex: 0 0 48px; }

  /* ワイド画面ではモーダルを中央表示(下端シートをやめる) */
  .modal-overlay { align-items: center; padding: 20px; }
  .modal { border-radius: 20px; max-height: 85dvh; }
}
