:root {
  --bg: #f3e7cf;
  --ink: #3a2418;
  --accent: #b43b2a;
  --blue: #1a4a9c;
  --paper: #fffaf0;
  --line: #d8c5a3;
  --shadow: 0 10px 28px rgba(70, 40, 10, 0.12);
  --safe-b: env(safe-area-inset-bottom, 0px);
  --font: "Yu Gothic", "YuGothic", "Hiragino Sans", "Hiragino Kaku Gothic ProN", Meiryo, sans-serif;
}

* { box-sizing: border-box; }
button, .file-btn, .tab, .chip, .tpl-card, .ink-swatch, .deco-item, .cam-tpl, .cam-shutter,
.quick-actions button, .start-btn, .save-kind button, .dlg-actions button {
  touch-action: manipulation;
}
html, body {
  margin: 0;
  padding: 0;
  width: 100%;
  max-width: 100%;
  overflow-x: hidden;
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
}
[hidden] {
  display: none !important;
}
[hidden] {
  display: none !important;
}
html { height: 100%; }
body.app-shell {
  font-family: var(--font);
  color: var(--ink);
  background:
    radial-gradient(circle at 12% 8%, #f7edda 0, transparent 42%),
    repeating-linear-gradient(0deg, rgba(140,100,40,0.03) 0 2px, transparent 2px 7px),
    var(--bg);
  height: 100dvh;
  max-height: 100dvh;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  padding-bottom: var(--safe-b);
}
img, canvas, video, table, pre, svg {
  max-width: 100%;
}

.app-header {
  flex: 0 0 auto;
  padding: 6px 12px 4px;
  display: flex;
  flex-direction: column;
  gap: 4px;
  max-width: 100%;
}
.app-header-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
  min-height: 40px;
}
.header-main {
  flex: 1 1 auto;
  min-width: 0;
  display: flex;
  align-items: center;
  gap: 8px;
}
.dev-env-badge {
  flex: 0 0 auto;
  display: inline-block;
  padding: 2px 8px;
  border-radius: 999px;
  background: #b45309;
  color: #fff;
  font-size: 11px;
  font-weight: 800;
  letter-spacing: 0.06em;
  line-height: 1.4;
  vertical-align: middle;
}
.header-back {
  flex: 0 0 auto;
  min-width: 56px;
  width: auto;
  min-height: 40px;
  height: 40px;
  padding: 0 12px;
  border: 2px solid var(--line);
  border-radius: 10px;
  background: #fffaf0;
  color: var(--ink);
  font-size: 14px;
  font-weight: 800;
  letter-spacing: 0.04em;
  line-height: 1;
  cursor: pointer;
  touch-action: manipulation;
}
.header-thumb {
  flex: 0 0 auto;
  padding: 0;
  border: 2px solid var(--line);
  background: #f6ecd6;
  border-radius: 10px;
  min-height: 0;
  width: 40px;
  height: 40px;
  overflow: hidden;
  touch-action: manipulation;
}
.header-thumb[hidden] { display: none !important; }
.header-thumb img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}
.kicker {
  margin: 0;
  font-size: 11px;
  letter-spacing: 0.12em;
  color: var(--accent);
}
h1 {
  margin: 0;
  font-size: 18px;
  font-weight: 800;
  letter-spacing: 0.04em;
  line-height: 1.2;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.layout {
  flex: 1 1 auto;
  min-height: 0;
  display: flex;
  flex-direction: column;
  padding: 0 12px 8px;
  max-width: 100%;
}

.main-tabs {
  flex: 0 0 auto;
  display: flex;
  gap: 6px;
  padding: 4px 12px 0;
  max-width: 100%;
}
.main-tab {
  flex: 1 1 0;
  min-height: 40px;
  border-radius: 12px;
  border: 1px solid var(--line);
  background: #fff8ee;
  font-weight: 800;
  font-size: 14px;
}
.main-tab.is-active {
  background: #1a4a9c;
  color: #fff;
  border-color: #1a4a9c;
}

.mode-pane {
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: 18px;
  box-shadow: var(--shadow);
  padding: 8px 10px 10px;
  margin-top: 6px;
  max-width: 100%;
  min-width: 0;
}
.mode-pane.workspace {
  flex: 1 1 auto;
  min-height: 0;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
.mode-pane.mode-list {
  flex: 1 1 auto;
  min-height: 0;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}
.mode-pane[hidden] { display: none !important; }

.stamp-name-row {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  gap: 6px;
  margin: 1px 0 2px;
  font-size: 12px;
  font-weight: 700;
  white-space: nowrap;
}
.stamp-name-row input {
  flex: 1 1 auto;
  min-width: 0;
  width: auto;
  min-height: 36px;
  margin-top: 0;
  border-radius: 10px;
  border: 1px solid #d7c4a4;
  font-size: 16px;
  padding: 4px 8px;
}

.sub-tabs {
  flex: 0 0 auto;
  display: flex;
  gap: 4px;
  margin: 0;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}
.sub-tab {
  flex: 1 1 0;
  min-height: 36px;
  border-radius: 10px;
  border: 1px solid var(--line);
  background: #fff;
  color: var(--ink);
  font-weight: 700;
  font-size: 13px;
  white-space: nowrap;
  padding: 6px 4px;
}
#createSubTabs .sub-tab.is-active,
#editSubTabs .sub-tab.is-active,
.sub-tab.is-active {
  background: #1a4a9c !important;
  border-color: #1a4a9c !important;
  color: #fff !important;
}

.sub-pane { display: none; min-width: 0; max-width: 100%; box-sizing: border-box; }
.sub-pane.is-active {
  display: block;
  max-width: 100%;
  overflow-x: hidden;
  box-sizing: border-box;
}
.sub-pane[data-edit-pane="items"] {
  padding-inline: 12px;
  box-sizing: border-box;
}
/* スタイルペインは内部スクロールしない */
.sub-pane.no-scroll { overflow: visible; }

.preview-fixed {
  flex: 0 0 auto;
  min-height: 0;
  display: flex;
  justify-content: center;
  max-height: 44dvh;
}
.edit-dock {
  flex: 1 1 auto;
  min-height: 0;
  overflow-x: hidden;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding-bottom: max(16px, env(safe-area-inset-bottom, 0px));
}
#modeCreate[data-create-sub="tpl"] .edit-dock {
  overflow-x: hidden;
  overflow-y: auto;
  padding-bottom: max(20px, env(safe-area-inset-bottom, 0px));
}
#modeCreate[data-create-sub="tpl"] .start-actions {
  margin-top: 6px;
  gap: 6px;
}
#modeCreate[data-create-sub="tpl"] .start-actions .start-btn {
  height: 48px;
  min-height: 48px;
  max-height: 48px;
}
#modeCreate[data-create-sub="tpl"] .style-actions-row {
  gap: 6px;
  margin: 2px 0 0;
}
#modeCreate[data-create-sub="tpl"] .style-actions-row .style-pick {
  min-height: 40px;
  font-size: 12px;
  padding: 6px 4px;
}
#modeCreate[data-create-sub="tpl"] .save-main-btn {
  margin-top: 6px;
  min-height: 42px;
}
#modeCreate[data-create-sub="placeDate"] .photo-ops,
#modeCreate[data-create-sub="placeDate"] .stamp-name-row,
#modeCreate[data-create-sub="placeDate"] [data-create-pane],
#modeCreate[data-create-sub="placeDate"] #saveBtn,
#modeCreate[data-create-sub="placeDate"] #saveStatus {
  display: none !important;
}
#modeCreate[data-create-sub="pos"] .photo-ops,
#modeCreate[data-create-sub="color"] .photo-ops {
  display: none !important;
}
#modeCreate[data-create-sub="pos"] .save-main-btn {
  margin-top: 6px;
  min-height: 42px;
}
#modeCreate[data-create-sub="pos"] .save-status {
  margin: 2px 0 0;
  min-height: 0;
}
#modeCreate[data-create-sub="color"] .edit-dock {
  display: flex;
  flex-direction: column;
  overflow-x: hidden;
  overflow-y: auto;
  padding-bottom: max(12px, env(safe-area-inset-bottom, 0px));
}
#modeCreate[data-create-sub="color"] [data-create-pane="color"] {
  flex: 1 1 auto;
  min-height: 0;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
#modeCreate[data-create-sub="color"] .color-nav,
#modeCreate[data-create-sub="color"] .color-panel {
  flex: 1 1 auto;
  min-height: 0;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
#modeCreate[data-create-sub="color"] .color-nav {
  overflow-y: auto;
}
#modeCreate[data-create-sub="color"] .save-main-btn {
  flex: 0 0 auto;
  margin-top: 4px;
  min-height: 40px;
}
#modeCreate[data-create-sub="color"] .save-status {
  flex: 0 0 auto;
  margin: 0;
  min-height: 0;
}
#modeTemplate .sub-pane[data-edit-pane="color"] {
  display: none;
  flex-direction: column;
  min-height: 0;
  overflow: hidden;
  height: 100%;
}
#modeTemplate .sub-pane[data-edit-pane="color"].is-active {
  display: flex;
}
#modeTemplate .sub-pane[data-edit-pane="color"] .color-nav,
#modeTemplate .sub-pane[data-edit-pane="color"] .color-panel {
  flex: 1 1 auto;
  min-height: 0;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
#modeTemplate[data-tpl-view="editor"] .edit-dock {
  display: flex;
  flex-direction: column;
}

#modeCreate[data-create-sub="pos"] .stamp-name-row,
#modeCreate[data-create-sub="color"] .stamp-name-row {
  display: none !important;
}

.selected-label {
  flex: 0 0 auto;
  font-weight: 800;
  font-size: 13px;
  margin: 2px 0 4px;
  color: var(--accent);
}

.save-main-btn {
  width: 100%;
  margin-top: 8px;
  min-height: 46px;
  font-size: 16px;
}

/* テンプレ編集プレビューは読み取り専用（直接操作禁止） */
#editPreviewStage {
  touch-action: pan-y;
  cursor: default;
  pointer-events: none;
}
#editPreviewCanvas {
  pointer-events: none;
}

.preview-panel, .editor-panel {
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: 18px;
  box-shadow: var(--shadow);
  max-width: 100%;
  min-width: 0;
  overflow-x: hidden;
}

.preview-panel { padding: 12px; }

.preview-stage {
  position: relative;
  touch-action: pan-y;
  background:
    linear-gradient(45deg, #ece2c8 25%, transparent 25%) 0 0 / 18px 18px,
    linear-gradient(-45deg, #ece2c8 25%, transparent 25%) 0 9px / 18px 18px,
    #f7f1e2;
  border-radius: 16px;
  overflow: hidden;
  display: flex;
  justify-content: center;
  align-items: center;
  width: min(100%, 46dvh);
  aspect-ratio: 1 / 1;
  min-height: 0;
  max-width: 100%;
  max-height: 46dvh;
}
#previewCanvas,
#editPreviewCanvas {
  width: 100%;
  height: 100%;
  max-width: 100%;
  max-height: 100%;
  object-fit: contain;
  display: block;
  cursor: default;
}
.preview-stage.is-readonly #previewCanvas {
  pointer-events: none;
}
.preview-hint {
  position: absolute;
  left: 8px;
  right: 8px;
  bottom: 8px;
  text-align: center;
  font-size: 11px;
  color: #5c4a36;
  background: rgba(255,250,240,0.78);
  border-radius: 999px;
  padding: 6px 10px;
  pointer-events: none;
}

.preview-actions, .quick-actions, .save-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 10px;
  max-width: 100%;
}
.quick-actions {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 4px;
}
.quick-actions.edit-actions {
  display: grid;
  grid-template-columns: 1fr 1fr 1.15fr;
  gap: 6px;
  margin-top: 10px;
  position: sticky;
  bottom: 0;
  background: var(--paper);
  padding-top: 6px;
}
.quick-actions button,
.quick-actions.edit-actions button,
#saveTplBtn {
  min-width: 0;
  width: 100%;
  min-height: 44px;
  padding: 8px 6px;
  font-size: 13px;
  border-radius: 12px;
  white-space: nowrap;
  overflow: visible;
  text-overflow: clip;
  margin: 0;
}

button, .file-btn {
  appearance: none;
  border: 1px solid #c7b090;
  background: #fff;
  color: var(--ink);
  border-radius: 999px;
  min-height: 44px;
  padding: 8px 14px;
  font-size: 14px;
  font-weight: 700;
  font-family: inherit;
  cursor: pointer;
}
.file-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: var(--blue);
  color: #fff;
  border-color: var(--blue);
}
.file-btn input { display: none; }
button.primary, #downloadBtn {
  background: var(--accent);
  color: #fff;
  border-color: var(--accent);
}
button:active { transform: translateY(1px); }

input[type="range"] {
  width: 100%;
  height: 40px;
  margin-top: 0;
  accent-color: var(--blue);
  background: transparent;
  -webkit-appearance: none;
  appearance: none;
}

:root {
  --range-track-h: 8px;
  --range-thumb: 24px;
  --slider-label-w: 72px;
}

.slider-row {
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 2px 0;
  min-height: 40px;
  min-width: 0;
  max-width: 100%;
  overflow: hidden;
}
.slider-row .slider-label {
  flex: 0 0 var(--slider-label-w);
  width: var(--slider-label-w);
  font-size: 13px;
  font-weight: 700;
  white-space: nowrap;
  line-height: 1.2;
}
.slider-row input[type="range"] {
  flex: 1 1 auto;
  min-width: 0;
  width: auto;
  margin: 0;
  height: 40px;
}
.slider-row-center {
  gap: 6px;
}
.slider-track-wrap {
  position: relative;
  flex: 1 1 auto;
  min-width: 0;
  display: flex;
  align-items: center;
}
.slider-track-wrap input[type="range"] {
  width: 100%;
  flex: 1 1 auto;
  position: relative;
  z-index: 1;
}
.slider-center-mark {
  position: absolute;
  left: 50%;
  top: 6px;
  bottom: 6px;
  width: 0;
  border-left: 2px solid rgba(25, 53, 46, 0.35);
  pointer-events: none;
  transform: translateX(-50%);
  z-index: 0;
}
.slider-center-caption {
  flex: 0 0 auto;
  font-size: 11px;
  font-weight: 700;
  color: var(--muted, #65756f);
  line-height: 1;
}
@media (max-width: 390px) {
  .slider-center-caption { display: none; }
}

/* 位置調整: 行高だけ詰め、thumbは維持 */
#modeCreate[data-create-sub="pos"] .slider-row,
#modeTemplate .sub-pane[data-edit-pane="photo"] .slider-row,
#modeTemplate .sub-pane[data-edit-pane="icon"] .slider-row {
  margin: 1px 0;
  min-height: 38px;
}

input[type="range"]::-webkit-slider-runnable-track {
  height: var(--range-track-h);
  border-radius: 999px;
  background: #e4d4b4;
}

input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: var(--range-thumb);
  height: var(--range-thumb);
  border-radius: 50%;
  background: #1a4a9c;
  border: 2px solid #fff;
  box-shadow: 0 1px 4px rgba(0,0,0,0.25);
  margin-top: calc((var(--range-track-h) - var(--range-thumb)) / 2);
}

input[type="range"]::-moz-range-track {
  height: var(--range-track-h);
  border-radius: 999px;
  background: #e4d4b4;
}

input[type="range"]::-moz-range-thumb {
  width: var(--range-thumb);
  height: var(--range-thumb);
  border-radius: 50%;
  background: #1a4a9c;
  border: 2px solid #fff;
  box-shadow: 0 1px 4px rgba(0,0,0,0.25);
}

.tabs {
  display: flex;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  border-bottom: 1px solid var(--line);
  padding: 6px;
  gap: 6px;
}
.tab {
  flex: 0 0 auto;
  border-radius: 12px;
  min-width: 72px;
  background: transparent;
  border: 0;
}
.tab.is-active {
  background: #1a4a9c;
  color: #fff;
}

.tab-body { display: none; padding: 12px 14px 18px; }
.tab-body.is-active { display: block; }
h2 {
  font-size: 13px;
  letter-spacing: 0.08em;
  margin: 16px 0 8px;
  color: var(--accent);
}
.tab-body h2:first-child { margin-top: 4px; }

label {
  display: block;
  font-size: 13px;
  font-weight: 700;
  margin: 10px 0;
}

/* 1画面化のためのモード別マージン調整 */
#modeCreate[data-create-sub="pos"] .slider-row,
#modeCreate[data-create-sub="color"] label,
#modeTemplate .sub-pane[data-edit-pane="photo"] .slider-row,
#modeTemplate .sub-pane[data-edit-pane="frame"] label {
  margin: 2px 0;
}
#modeCreate[data-create-sub="pos"] .slider-row input[type="range"],
#modeTemplate .sub-pane[data-edit-pane="photo"] .slider-row input[type="range"] {
  height: 38px;
}
input[type="text"], select, input[type="search"], textarea {
  box-sizing: border-box;
  width: 100%;
  min-width: 0;
  max-width: 100%;
  min-height: 44px;
  margin-top: 6px;
  border-radius: 12px;
  border: 1px solid #d7c4a4;
  background: #fff;
  font-family: inherit;
  font-size: 16px;
  padding: 8px 10px;
}
input[type="color"] {
  width: 100%;
  min-height: 44px;
  margin-top: 6px;
  border-radius: 12px;
  border: 1px solid #d7c4a4;
  background: #fff;
  font-family: inherit;
  padding: 8px 10px;
  max-width: 100%;
}
.edit-dock,
.sub-pane,
#textEditMode,
#itemsListMode,
#placeDateEditor,
.manage-save-section,
.cam-subform {
  min-width: 0;
}
#textEditMode label,
#placeDateEditor label,
.manage-name-label,
.cam-subform label,
.field-label {
  display: block;
  min-width: 0;
  max-width: 100%;
  box-sizing: border-box;
  margin-inline: 0;
  padding-inline: 0;
}
#textEditMode,
#iconEditMode,
#placeDateEditor,
.cam-subform {
  max-width: 100%;
  overflow-x: hidden;
  box-sizing: border-box;
}
.field-input,
input.field-input,
textarea.field-input,
select.field-input {
  display: block;
  width: 100%;
  max-width: 100%;
  box-sizing: border-box;
  margin-inline: 0;
  min-width: 0;
}
#textEditMode .field-input,
#partTextInput {
  width: calc(100% - 8px);
  margin-inline: 4px;
}
.field-input:focus,
.field-input:focus-visible,
#textEditMode select:focus,
#textEditMode select:focus-visible {
  outline: none;
  border-color: var(--blue);
  box-shadow: inset 0 0 0 1px var(--blue);
  background: #eef3fb;
}
.orient-row,
.toggle-2btn,
.curve-dir-row {
  min-width: 0;
  max-width: 100%;
}
@media (min-width: 960px) {
  .layout {
    display: block;
    overflow: auto;
  }
  body.app-shell {
    height: auto;
    max-height: none;
    overflow: auto;
  }
  .mode-pane.workspace {
    display: grid;
    grid-template-columns: minmax(280px, 1fr) minmax(280px, 1fr);
    grid-template-rows: auto auto 1fr;
    align-items: stretch;
    overflow: hidden;
    max-height: calc(100dvh - 90px);
  }
  #modeCreate .sub-tabs,
  #modeTemplate .sub-tabs,
  #modeCreate .stamp-name-row,
  #modeTemplate .selected-label,
  #modeTemplate #tplBackToHub,
  #modeTemplate #tplHub {
    grid-column: 1 / -1;
  }
  .preview-fixed {
    max-height: none;
    grid-row: 3;
    grid-column: 1;
  }
  .preview-stage {
    width: min(100%, 520px);
    max-height: min(70dvh, 520px);
  }
  .edit-dock {
    grid-row: 3;
    grid-column: 2;
  }
  .chip-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .template-grid { grid-template-columns: 1fr 1fr; }
}
.help { font-size: 12px; color: #6d5840; margin: 0 0 8px; }
.toggle-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 6px;
}
.check {
  display: flex;
  align-items: center;
  gap: 8px;
  min-height: 42px;
  font-weight: 700;
  background: #f7f0e2;
  border-radius: 12px;
  padding: 6px 10px;
}
.check input { width: 20px; height: 20px; }

.chip-grid, .template-grid, .color-presets, .deco-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 6px;
}
.template-grid { grid-template-columns: 1fr; }
.chip, .tpl-card, .ink-swatch, .deco-item {
  border: 1px solid #d7c4a4;
  background: #fff;
  border-radius: 14px;
  min-height: 44px;
  padding: 10px 12px;
  text-align: left;
  font-family: inherit;
  cursor: pointer;
}
.chip.is-active, .tpl-card.is-active, .ink-swatch.is-active, .deco-item.is-active {
  border-color: var(--blue);
  box-shadow: inset 0 0 0 2px var(--blue);
  background: #eef3fb;
}
.tpl-card small { display: block; color: #6d5840; font-weight: 500; margin-top: 4px; }
.ink-swatch {
  display: flex;
  align-items: center;
  gap: 8px;
}
.ink-swatch i {
  width: 22px;
  height: 22px;
  border-radius: 50%;
  display: inline-block;
  border: 1px solid rgba(0,0,0,.15);
}
.deco-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); }

.size-now {
  font-size: 20px;
  font-weight: 800;
  margin: 12px 0;
}
.size-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
  margin-bottom: 12px;
}
.size-table th, .size-table td {
  border-bottom: 1px solid var(--line);
  padding: 8px 4px;
  text-align: left;
}
.size-table td:last-child, .size-table th:last-child { text-align: right; }
.meta-box {
  background: #2b2118;
  color: #f4e7cc;
  border-radius: 12px;
  padding: 12px;
  overflow: auto;
  font-size: 12px;
  line-height: 1.55;
  white-space: pre-wrap;
}

.acc-item {
  border: 1px solid var(--line);
  border-radius: 12px;
  background: #fff;
  margin-bottom: 6px;
}
.acc-item summary {
  list-style: none;
  min-height: 44px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 12px;
  font-weight: 800;
  cursor: pointer;
}
.acc-item summary::-webkit-details-marker { display: none; }
.acc-item summary::after { content: "▶"; font-size: 11px; color: #8a7050; }
.acc-item[open] summary::after { content: "▼"; }
.acc-body { padding: 0 10px 10px; }
.scroll-chips {
  max-height: none;
  overflow: visible;
}

.color-nav {
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.color-nav-item {
  border-radius: 12px !important;
  text-align: left;
  padding-left: 12px !important;
  padding-right: 12px !important;
}

/* 色パネルヘッダー（カテゴリ名 + 戻るボタン） */
.color-panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 6px;
  flex: 0 0 auto;
}
.color-cat-label {
  font-size: 14px;
  font-weight: 800;
  color: var(--ink);
}
.color-back-btn {
  min-height: 36px;
  font-size: 12px;
  border-radius: 12px !important;
  background: #fff8ee;
  border-color: var(--line) !important;
  padding: 4px 10px;
  white-space: nowrap;
}

/* 旧: color-back (後方互換) */
.color-back {
  width: 100%;
  border-radius: 12px !important;
  background: #fff8ee;
  border-color: var(--line) !important;
  text-align: center;
}

.color-panel-choice {
  flex: 1 1 auto;
  min-height: 0;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding-bottom: 4px;
}

/* 枠グリッド（2列×4行） */
.frame-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 6px;
  margin-bottom: 10px;
}
.frame-grid button {
  width: 100%;
  min-height: 44px;
  border-radius: 12px;
  text-align: center;
  font-size: 14px;
}
.frame-grid button.is-active {
  background: #eef3fb;
  border-color: var(--blue);
  box-shadow: inset 0 0 0 2px var(--blue);
}

/* パーツ一覧モードヘッダー */
.part-list-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 6px;
}
.part-list-title {
  font-size: 13px;
  font-weight: 800;
  color: var(--accent);
}
.items-add-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  margin: 0 0 8px;
}
.add-part-btn {
  min-height: 40px;
  font-size: 13px;
  font-weight: 800;
  border-radius: 12px !important;
  padding: 4px 10px;
}
.items-order-hint {
  margin: 0 0 6px;
  font-size: 11px;
}
.part-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex: 0 0 auto;
  min-width: 22px;
  height: 20px;
  margin-right: 6px;
  padding: 0 4px;
  border-radius: 6px;
  font-size: 11px;
  font-weight: 800;
  line-height: 1;
}
.part-badge.is-text {
  background: #dce8f6;
  color: #1a4a9c;
}
.part-badge.is-icon {
  background: #efe4d4;
  color: #6b3e24;
}
.part-row-name {
  display: flex;
  align-items: center;
}
.part-row-label {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
}
.pick-sheet-list {
  display: grid;
  gap: 6px;
  margin: 8px 0 12px;
}

/* 編集モードヘッダー */
.edit-mode-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 8px;
  padding-bottom: 6px;
  border-bottom: 1px solid var(--line);
}
.edit-mode-title {
  font-size: 14px;
  font-weight: 800;
  color: var(--ink);
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.copy-btn {
  min-height: 32px;
  font-size: 12px;
  border-radius: 10px !important;
  padding: 4px 10px;
  flex: 0 0 auto;
}
.edit-mode-footer {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  margin-top: 12px;
  padding-top: 8px;
  border-top: 1px solid var(--line);
}
.edit-mode-footer button {
  width: 100%;
  min-height: 44px;
}
.danger-btn {
  background: #fff0ee;
  border-color: #c94040 !important;
  color: #c94040;
}

/* 向き選択（横書き/縦書き） */
.orient-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 6px;
  margin: 6px 0;
}

/* フォント / サイズ / 太さ */
.font-row {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin: 4px 0;
  align-items: start;
  min-width: 0;
}
.font-row .font-label,
.font-row .weight-label,
.font-label, .weight-label {
  flex: 1 1 30%;
  min-width: 90px;
  margin: 4px 0 0;
  font-size: 12px;
  font-weight: 700;
}
.font-row select {
  width: 100%;
  margin-top: 2px;
  min-height: 36px;
}

/* 装飾2択ボタン */
.toggle-2btn {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 6px;
  margin: 4px 0 8px;
}

/* 曲線方向4択 */
.curve-dir-row {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 6px;
  margin: 4px 0 8px;
}

/* セクションラベル */
.section-label {
  font-size: 12px;
  font-weight: 800;
  color: var(--accent);
  margin: 10px 0 4px;
}

/* アイコンパレット */
.icon-palette-wrap {
  margin-top: 8px;
}
.palette-close-btn {
  width: 100%;
  margin-top: 6px;
  min-height: 40px;
  border-radius: 12px;
  background: #fff8ee;
}

/* テンプレ管理 */
.manage-save-section {
  margin-bottom: 12px;
  padding-bottom: 12px;
  border-bottom: 1px solid var(--line);
}
.manage-name-label {
  margin-bottom: 8px;
}
.save-tpl-btn {
  width: 100%;
  min-height: 46px;
  font-size: 15px;
  margin-top: 6px;
}
.custom-tpl-section {
  /* 保存済みが存在する場合のみ内容が入る */
}
.custom-tpl-section h3 {
  font-size: 13px;
  font-weight: 800;
  color: var(--accent);
  margin: 4px 0 8px;
}
.style-pick-label { margin: 2px 0 4px; }
.style-pick {
  width: 100%;
  margin-top: 4px;
  text-align: left;
  border-radius: 12px !important;
  background: #fff;
}
.style-sheet {
  position: fixed;
  inset: 0;
  z-index: 80;
  display: flex;
  align-items: flex-end;
  justify-content: center;
}
.style-sheet[hidden] { display: none !important; pointer-events: none !important; }
.style-sheet-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(40, 24, 10, 0.35);
}
.style-sheet-panel {
  position: relative;
  width: 100%;
  max-width: 520px;
  max-height: 70dvh;
  overflow-y: auto;
  background: #fffaf0;
  border-radius: 18px 18px 0 0;
  padding: 16px;
  box-shadow: 0 -8px 28px rgba(0,0,0,.18);
}
.style-sheet-panel button {
  width: 100%;
  margin: 4px 0;
  border-radius: 12px;
  text-align: left;
}
.used-list {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-bottom: 8px;
}
.used-list > button {
  width: 100%;
  text-align: left;
  border-radius: 12px;
  min-height: 40px;
}
.used-list > button.is-active {
  background: #e8eef8;
  border-color: #1a4a9c;
}

.part-row {
  display: flex;
  align-items: center;
  gap: 4px;
}
.part-row-name {
  flex: 1 1 auto;
  min-width: 0;
  width: auto !important;
  text-align: left;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  border-radius: 10px !important;
  min-height: 40px;
  padding: 6px 8px;
  font-size: 13px;
}
.part-row-act {
  flex: 0 0 40px;
  width: 40px !important;
  min-width: 40px;
  min-height: 40px;
  padding: 0 !important;
  border-radius: 8px !important;
  font-size: 12px;
  font-weight: 700;
  line-height: 1;
  display: inline-flex !important;
  align-items: center;
  justify-content: center;
  text-align: center !important;
}

.style-actions-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  margin: 4px 0;
}
.style-actions-row .style-pick {
  margin-top: 0;
  text-align: center;
  font-size: 13px;
  min-height: 44px;
}

.edit-mode-bar .sub-tab {
  font-size: 13px;
  min-height: 32px;
  padding: 4px 6px;
  line-height: 1.2;
}

.edit-mode-preview {
  flex: 1 1 auto;
  min-width: 0;
  text-align: right;
  font-size: 13px;
  font-weight: 700;
  color: #6d5840;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.tpl-hub {
  flex: 1 1 auto;
  min-height: 0;
  padding: 8px 4px;
}
.tpl-hub-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin-top: 8px;
}
.tpl-hub-grid button {
  min-height: 72px;
  border-radius: 14px;
  font-size: 16px;
}
.tpl-hub-picker {
  margin-top: 12px;
}
.hub-back-btn {
  width: 100%;
  min-height: 40px;
  border-radius: 12px !important;
  background: #fff8ee;
  margin-bottom: 8px;
  font-size: 13px;
}
.tpl-editor-back {
  flex: 0 0 auto;
}

#modeTemplate[data-tpl-view="hub"] .preview-fixed,
#modeTemplate[data-tpl-view="hub"] .edit-dock,
#modeTemplate[data-tpl-view="hub"] #editSubTabs,
#modeTemplate[data-tpl-view="hub"] #partEditBar,
#modeTemplate[data-tpl-view="hub"] #tplBackToHub {
  display: none !important;
}
#modeTemplate[data-tpl-view="editor"] #tplHub {
  display: none !important;
}

@media (min-width: 960px) {
  #modeTemplate[data-tpl-view="hub"] {
    display: flex;
    flex-direction: column;
    grid-template-columns: none;
  }
  #tplHub {
    grid-column: 1 / -1;
  }
}

@media (max-width: 420px) {
  .toggle-row { grid-template-columns: 1fr; }
}

.color-duo {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}
.ink-swatch.big {
  min-height: 44px;
  height: 44px;
  margin: 0 0 6px;
  padding: 4px 10px;
  gap: 8px;
  overflow: hidden;
}
.ink-swatch.big span {
  flex: 0 0 auto;
  font-size: 13px;
  font-weight: 700;
}
.ink-swatch.big i { width: 18px; height: 18px; flex: 0 0 auto; }
.ink-swatch.big input[type="color"] {
  flex: 1 1 auto;
  min-width: 0;
  width: auto;
  min-height: 28px;
  height: 28px;
  margin: 0;
  padding: 0;
  border: 0;
  background: transparent;
}
details.more {
  margin: 14px 0;
  background: #f7f0e2;
  border-radius: 12px;
  padding: 8px 12px;
}
details.more summary {
  font-weight: 800;
  min-height: 44px;
  display: flex;
  align-items: center;
  cursor: pointer;
}
h3 {
  font-size: 12px;
  margin: 14px 0 6px;
  color: #6d5840;
}
.custom-row {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  align-items: center;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 8px;
  margin-bottom: 8px;
}
.custom-row strong { flex: 1 1 120px; }
.part-edit { margin-top: 8px; }
@media (max-width: 700px) {
  .color-duo { grid-template-columns: 1fr; }
}

.start-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  margin-top: 10px;
  max-width: 100%;
  align-items: stretch;
}
.start-actions .start-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  height: 52px;
  min-height: 52px;
  max-height: 52px;
  margin: 0;
  padding: 0 10px;
  font-size: 16px;
  font-weight: 700;
  border-radius: 999px;
  box-sizing: border-box;
  line-height: 1;
  font-family: inherit;
  appearance: none;
  cursor: pointer;
}
.capture-btn {
  background: var(--accent);
  color: #fff;
  border: 1px solid var(--accent);
}
.pick-btn {
  background: var(--blue);
  color: #fff;
  border: 1px solid var(--blue);
}
.aux-actions {
  margin-top: 8px;
}
.aux-actions button {
  background: #fff8ee;
}

body.camera-open { overflow: hidden; }
.cam-overlay {
  position: fixed;
  inset: 0;
  z-index: 80;
  background: #16110c;
  color: #f7f0e2;
  display: flex;
  flex-direction: column;
  padding: env(safe-area-inset-top, 0) 0 env(safe-area-inset-bottom, 0);
}
.cam-overlay[hidden] { display: none !important; pointer-events: none !important; }
.cam-pane {
  position: relative;
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
}
.cam-pane[hidden] { display: none !important; }
.cam-bar {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 12px;
  flex: 0 0 auto;
}
.cam-bar button, .cam-tpl {
  background: rgba(255,255,255,0.1);
  color: #fff;
  border-color: rgba(255,255,255,0.25);
}
.cam-tpl {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.cam-tpl-menu {
  position: absolute;
  left: 12px;
  right: 12px;
  top: 58px;
  z-index: 2;
  background: #2a2118;
  border: 1px solid #5a4a36;
  border-radius: 14px;
  padding: 8px;
  max-height: 46vh;
  overflow: auto;
}
.cam-tpl-menu[hidden] { display: none !important; }
.cam-tpl-menu p {
  margin: 8px 4px 4px;
  font-size: 12px;
  color: #cbb98a;
}
.cam-tpl-menu button {
  display: block;
  width: 100%;
  text-align: left;
  margin: 4px 0;
  background: #3a2f24;
  color: #fff;
  border-color: #5a4a36;
}
.cam-note, .cam-error {
  margin: 0 12px 8px;
  font-size: 13px;
  line-height: 1.45;
}
.cam-error {
  color: #ffd0c0;
  background: #5a2418;
  padding: 8px 10px;
  border-radius: 10px;
}
.cam-error[hidden], .cam-note[hidden] { display: none !important; }
.cam-diag {
  margin: 0 12px 8px;
  font-size: 12px;
  color: #cbb98a;
  flex: 0 0 auto;
}
.cam-diag[hidden] { display: none !important; }
.cam-diag summary {
  cursor: pointer;
  min-height: 36px;
  display: flex;
  align-items: center;
}
.cam-diag pre {
  margin: 6px 0 0;
  white-space: pre-wrap;
  word-break: break-all;
  background: #2a2118;
  color: #f7f0e2;
  padding: 8px;
  border-radius: 8px;
  font-size: 11px;
}
.cam-stage {
  position: relative;
  flex: 1 1 auto;
  min-height: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 4px 12px;
  overflow: hidden;
  touch-action: none;
}
#cameraVideo {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  opacity: 0.02;
  pointer-events: none;
}
#cameraPreview {
  position: relative;
  z-index: 1;
  width: auto;
  height: auto;
  max-width: 100%;
  max-height: 100%;
  aspect-ratio: 1 / 1;
  display: block;
  border-radius: 12px;
  background: #2a2118;
}
.cam-zoom {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 12px 0;
  flex: 0 0 auto;
}
.cam-zoom input[type="range"] {
  flex: 1;
  min-width: 0;
  margin: 0;
  min-height: 32px;
}
.cam-zoom button {
  width: 44px;
  min-height: 44px;
  padding: 0;
  border-radius: 50%;
  background: rgba(255,255,255,0.12);
  color: #fff;
  border-color: rgba(255,255,255,0.28);
  font-size: 20px;
  line-height: 1;
  flex: 0 0 auto;
}
#cameraZoomLabel {
  min-width: 3.2em;
  text-align: right;
  font-size: 13px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}
.cam-quick {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 6px 8px;
  padding: 6px 12px 0;
  font-size: 12px;
  flex: 0 0 auto;
}
.cam-quick[hidden] { display: none !important; }
.cam-action-btn {
  min-height: 40px;
  border-radius: 12px;
  background: rgba(255,255,255,0.12);
  color: #fff;
  border-color: rgba(255,255,255,0.28);
  font-weight: 800;
  font-size: 13px;
}
#cameraNamesBtn { grid-column: 1 / -1; }
.cam-opacity-row {
  grid-column: 1 / -1;
  margin: 0;
  color: #f7f0e2;
}
.cam-opacity-row .slider-label { color: #f7f0e2; }
.cam-overlay[data-cam-view="names"] .cam-stage,
.cam-overlay[data-cam-view="color"] .cam-stage {
  flex: 0 0 28dvh;
  max-height: 28dvh;
  padding: 2px 12px;
}
.cam-subform {
  flex: 1 1 auto;
  min-height: 0;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  margin: 8px 12px 12px;
  padding: 10px 12px;
  background: var(--paper);
  color: var(--ink);
  border-radius: 14px;
}
.cam-subform[hidden] { display: none !important; }
.cam-subform label { margin: 6px 0; }
.cam-subform-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  margin-top: 10px;
}
.cam-color-pane {
  flex: 1 1 auto;
  min-height: 0;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  margin: 8px 12px 12px;
  padding: 8px 10px;
  background: var(--paper);
  color: var(--ink);
  border-radius: 14px;
}
.cam-color-pane[hidden] { display: none !important; }
.cam-color-pane .color-panel-choice {
  flex: 1 1 auto;
}
.cam-bottom {
  flex: 0 0 auto;
  min-height: 100px;
  display: flex;
  align-items: center;
  justify-content: center;
}
.cam-shutter-wrap {
  display: flex;
  justify-content: center;
  padding: 10px 0 14px;
  width: 100%;
}
.cam-shutter-wrap[hidden] { display: none !important; }
.cam-shutter {
  width: 76px;
  height: 76px;
  min-height: 76px;
  padding: 0;
  border-radius: 50%;
  border: 6px solid #fff;
  background: var(--accent);
  box-shadow: 0 0 0 4px rgba(255,255,255,0.18);
  touch-action: manipulation;
}
.cam-review-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  justify-content: center;
  padding: 12px;
  width: 100%;
}
.cam-review-actions[hidden] { display: none !important; }
.cam-review-actions button { min-width: 28%; flex: 1 1 28%; touch-action: manipulation; }
#cameraSaveBtn { background: var(--accent); color: #fff; border-color: var(--accent); }

@media (min-width: 700px) {
  .cam-shutter { width: 72px; height: 72px; min-height: 72px; }
}

.save-kind {
  display: grid;
  gap: 8px;
}
.save-kind button { width: 100%; }
.save-status {
  min-height: 1.4em;
  font-size: 13px;
  font-weight: 700;
  color: #2a6b45;
}
.stamp-list { margin-top: 12px; }
.stamp-card {
  display: grid;
  grid-template-columns: 72px minmax(0, 1fr);
  gap: 10px;
  align-items: center;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 8px;
  margin-bottom: 8px;
}
.stamp-card img {
  width: 72px;
  height: 72px;
  object-fit: cover;
  border-radius: 8px;
  background: #eee;
}
.stamp-card h3 {
  margin: 0 0 4px;
  font-size: 14px;
  color: var(--ink);
  overflow-wrap: anywhere;
}
.stamp-card p { margin: 0; font-size: 11px; color: #6d5840; }
.stamp-card button { margin-top: 6px; min-height: 36px; font-size: 12px; }

.photo-viewer {
  position: fixed;
  inset: 0;
  z-index: 90;
  background: rgba(10, 8, 6, 0.88);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 48px 12px 12px;
  touch-action: pinch-zoom pan-x pan-y;
}
.photo-viewer[hidden] { display: none !important; pointer-events: none !important; }
.photo-viewer img {
  max-width: 100%;
  max-height: 100%;
  object-fit: contain;
  touch-action: pinch-zoom pan-x pan-y;
}
.photo-viewer-close {
  position: absolute;
  top: 10px;
  right: 10px;
  width: 44px;
  min-height: 44px;
  border-radius: 50%;
  background: #fff;
  color: #222;
  font-size: 22px;
  z-index: 2;
}
.dlg {
  position: fixed;
  inset: 0;
  z-index: 95;
  background: rgba(20, 14, 8, 0.55);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
}
.dlg[hidden] { display: none !important; pointer-events: none !important; }
.dlg-card {
  background: var(--paper);
  border-radius: 16px;
  padding: 16px;
  width: min(100%, 420px);
  max-width: 100%;
}
.dlg-actions {
  display: grid;
  gap: 8px;
  margin-top: 12px;
}
.dlg-actions button { width: 100%; }
.dlg-card label {
  display: grid;
  gap: 4px;
  margin-top: 8px;
  font-size: 14px;
}
.dlg-error {
  margin: 8px 0 0;
  color: #b42318;
  font-size: 13px;
}

.legacy-edit-banner {
  margin: 0;
  padding: 6px 10px;
  background: #fff6e8;
  color: #5c3b12;
  font-size: 0.78rem;
  line-height: 1.35;
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
  width: 100%;
}
.legacy-edit-banner[hidden] { display: none !important; }
.legacy-edit-banner button {
  min-height: 36px;
  padding: 4px 10px;
  font-size: 0.8rem;
}

body.save-sheet-open {
  overflow: hidden;
}

.save-sheet {
  position: fixed;
  inset: 0;
  z-index: 90;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  pointer-events: none;
}
.save-sheet[hidden] { display: none !important; pointer-events: none !important; }
.save-sheet-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(20, 14, 8, 0.55);
  pointer-events: auto;
}
.save-sheet-panel {
  position: relative;
  z-index: 1;
  background: var(--paper);
  border-radius: 18px 18px 0 0;
  padding: 16px 16px calc(16px + var(--safe-b));
  width: 100%;
  max-width: 100%;
  pointer-events: auto;
  box-shadow: 0 -8px 32px rgba(70, 40, 10, 0.18);
}
.save-sheet-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 8px;
}
.save-sheet-head h2 {
  margin: 0;
  font-size: 18px;
  color: var(--ink);
  letter-spacing: 0.04em;
}
.save-sheet-close {
  min-height: 44px;
  min-width: 44px;
  padding: 0;
  border-radius: 999px;
  font-size: 22px;
  line-height: 1;
  background: #f6ecd6;
  border-color: var(--line);
}
.save-sheet-cancel {
  width: 100%;
  margin-top: 8px;
  background: #fff8ee;
}
.save-sheet .save-kind {
  display: grid;
  gap: 8px;
  margin-top: 12px;
}
.save-sheet .save-kind button { width: 100%; }
.save-sheet .save-status {
  min-height: 1.2em;
  font-size: 13px;
  font-weight: 700;
  color: var(--accent);
  margin: 4px 0 0;
}

@media (min-width: 700px) {
  .header-thumb {
    width: 72px;
    height: 72px;
    border-radius: 12px;
  }
  .save-sheet {
    align-items: center;
    padding: 16px;
  }
  .save-sheet-panel {
    border-radius: 16px;
    width: min(100%, 420px);
    padding-bottom: 16px;
  }
}

@media (max-width: 959px) {
  h1 { font-size: 18px; }
  .header-thumb {
    width: 52px;
    height: 52px;
  }
}
