@charset "UTF-8";

/* ============================================================================
   card-editor.css — shared chrome for every card/postcard product.
   White base, light grey surfaces, a New Year red accent, generous hit areas.
   Clarity over flourish: every control keeps its Japanese label.
   ========================================================================== */

.ce-app {
  --ce-red: #d0342c;
  --ce-red-dark: #b02a23;
  --ce-red-soft: #fdeceb;
  --ce-gold: #c9a227;
  --ce-ink: #2f2a26;
  --ce-muted: #6b6560;
  --ce-line: #e6e2dd;
  --ce-bg: #f6f4f1;
  --ce-radius: 12px;

  display: grid;
  grid-template-columns: 296px minmax(0, 1fr) 348px;
  grid-template-rows: minmax(0, 1fr) auto;
  grid-template-areas:
    "left main right"
    "actions actions actions";
  gap: 14px;
  padding: 14px;
  background: var(--ce-bg);
  /* JS replaces this with the exact remaining viewport height; the calc is the
     pre-script fallback so the first paint is not wildly off. */
  height: calc(100vh - 196px);
  min-height: 560px;
  color: var(--ce-ink);
  box-sizing: border-box;
}

.ce-app *,
.ce-app *::before,
.ce-app *::after { box-sizing: border-box; }

/* Class-level `display` beats the UA rule for [hidden], which would otherwise
   leave hidden buttons and notes on screen. */
.ce-app [hidden] { display: none !important; }

/* ---------------------------------------------------------------- panels */

.ce-panel {
  background: #fff;
  border: 1px solid var(--ce-line);
  border-radius: var(--ce-radius);
  overflow-y: auto;
  overscroll-behavior: contain;
}

.ce-panel-left { grid-area: left; padding: 14px; }
.ce-panel-right { grid-area: right; padding: 4px 0 14px; }

.ce-section { padding: 16px 16px 4px; }
.ce-section + .ce-section { border-top: 1px solid var(--ce-line); margin-top: 10px; padding-top: 16px; }

.ce-section-title {
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 0 0 12px;
  font-size: 1.02rem;
  font-weight: 700;
  color: var(--ce-ink);
}

.ce-section-title .ce-section-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 26px;
  height: 26px;
  border-radius: 7px;
  background: var(--ce-red-soft);
  color: var(--ce-red);
  font-size: 0.9rem;
}

.ce-field { display: grid; grid-template-columns: 74px minmax(0, 1fr); gap: 10px; align-items: start; margin-bottom: 12px; }
.ce-field > label { font-size: 0.88rem; font-weight: 600; color: #4a443f; padding-top: 9px; }
.ce-field-wide { grid-template-columns: 1fr; }
.ce-field-wide > label { padding-top: 0; }

.ce-input,
.ce-textarea,
.ce-select {
  width: 100%;
  padding: 9px 11px;
  border: 1.5px solid var(--ce-line);
  border-radius: 9px;
  font-size: 0.95rem;
  font-family: inherit;
  color: var(--ce-ink);
  background: #fff;
  transition: border-color .15s;
}

.ce-textarea { min-height: 92px; line-height: 1.65; resize: vertical; }
.ce-textarea-short { min-height: 56px; }

.ce-input:focus,
.ce-textarea:focus,
.ce-select:focus {
  outline: none;
  border-color: var(--ce-red);
  box-shadow: 0 0 0 3px var(--ce-red-soft);
}

.ce-hint { margin: 2px 0 12px; font-size: 0.78rem; color: var(--ce-muted); line-height: 1.6; }

/* --------------------------------------------------------------- buttons */

.ce-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  padding: 10px 16px;
  min-height: 42px;
  border: 1.5px solid var(--ce-line);
  border-radius: 9px;
  background: #fff;
  color: var(--ce-ink);
  font-size: 0.93rem;
  font-weight: 600;
  font-family: inherit;
  cursor: pointer;
  transition: border-color .15s, background .15s, color .15s;
}

.ce-btn:hover:not(:disabled) { border-color: var(--ce-red); color: var(--ce-red); }
.ce-btn:disabled { opacity: .45; cursor: not-allowed; }
.ce-btn-block { width: 100%; }
.ce-btn-small { min-height: 34px; padding: 6px 12px; font-size: 0.84rem; }
.ce-btn-quiet { color: var(--ce-muted); }
.ce-btn-quiet:hover:not(:disabled) { border-color: #d9534f; color: #d9534f; }

.ce-btn-primary {
  background: var(--ce-red);
  border-color: var(--ce-red);
  color: #fff;
}
.ce-btn-primary:hover:not(:disabled) { background: var(--ce-red-dark); border-color: var(--ce-red-dark); color: #fff; }

/* ------------------------------------------------------- template列（左） */

.ce-template-search {
  display: flex;
  gap: 8px;
  margin-bottom: 12px;
}

.ce-template-search .ce-input { padding-left: 34px; background: #fff url("data:image/svg+xml;charset=utf-8,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 16 16' fill='none' stroke='%23999' stroke-width='1.6'%3E%3Ccircle cx='7' cy='7' r='4.6'/%3E%3Cpath d='M10.4 10.4 14 14'/%3E%3C/svg%3E") no-repeat 10px 50%; }

.ce-categories { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 14px; }

.ce-cat {
  padding: 6px 13px;
  border: 1.5px solid var(--ce-line);
  border-radius: 999px;
  background: #fff;
  color: #57514c;
  font-size: 0.85rem;
  font-weight: 600;
  font-family: inherit;
  cursor: pointer;
  transition: all .15s;
}
.ce-cat:hover { border-color: var(--ce-red); color: var(--ce-red); }
.ce-cat.is-active { background: var(--ce-red); border-color: var(--ce-red); color: #fff; }

.ce-template-list {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
}

.ce-template {
  position: relative;
  display: block;
  padding: 5px 5px 6px;
  border: 2px solid var(--ce-line);
  border-radius: 10px;
  background: #fff;
  cursor: pointer;
  font-family: inherit;
  text-align: center;
  transition: border-color .15s, box-shadow .15s;
}
.ce-template:hover { border-color: #f0b6b2; box-shadow: 0 3px 10px rgba(0,0,0,.07); }
.ce-template.is-active { border-color: var(--ce-red); box-shadow: 0 0 0 3px var(--ce-red-soft); }

.ce-template-thumb {
  display: block;
  width: 100%;
  overflow: hidden;
  border-radius: 5px;
  background: #f3f1ee;
}
.ce-template-thumb > div { transform-origin: 0 0; }

.ce-template-name {
  display: block;
  margin-top: 5px;
  font-size: 0.74rem;
  color: #57514c;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.ce-template-check {
  position: absolute;
  top: -7px;
  right: -7px;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  background: var(--ce-red);
  color: #fff;
  font-size: 0.76rem;
  line-height: 22px;
  opacity: 0;
  transform: scale(.6);
  transition: opacity .15s, transform .15s;
}
.ce-template.is-active .ce-template-check { opacity: 1; transform: scale(1); }

.ce-template-empty { padding: 20px 4px; color: var(--ce-muted); font-size: 0.85rem; text-align: center; }
.ce-template-more { width: 100%; margin-top: 12px; }

/* ------------------------------------------------------------ 中央プレビュー */

.ce-main {
  grid-area: main;
  display: flex;
  align-items: center;
  justify-content: center;
  min-width: 0;
  min-height: 0;
  padding: 8px;
  background: linear-gradient(180deg, #fbfaf8, #f1eeea);
  border: 1px solid var(--ce-line);
  border-radius: var(--ce-radius);
}

.ce-stage {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  height: 100%;
  min-height: 0;
  outline: none;
}

.ce-surface-holder {
  position: relative;
  border-radius: 4px;
  box-shadow: 0 10px 30px rgba(60, 44, 30, .18), 0 2px 6px rgba(60, 44, 30, .1);
}

.ce-surface {
  position: relative;
  overflow: hidden;
  transform-origin: 0 0;
  border-radius: 4px;
  -webkit-print-color-adjust: exact;
  print-color-adjust: exact;
}

.ce-layer {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  user-select: none;
}

.ce-photo-frame {
  position: absolute;
  overflow: hidden;
  background: #ece8e2;
}

.ce-photo-frame.is-draggable { cursor: grab; }
.ce-photo-frame.is-dragging { cursor: grabbing; }
.ce-surface.is-interactive .ce-photo-frame.is-draggable:hover { outline: 2px dashed rgba(208, 52, 44, .55); outline-offset: -2px; }

.ce-photo { position: absolute; user-select: none; }

.ce-photo-empty {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 4px;
  width: 100%;
  height: 100%;
  color: #a49c93;
  cursor: pointer;
  background: repeating-linear-gradient(45deg, #eeeae4 0 8px, #e7e2db 8px 16px);
}
.ce-photo-empty-icon { font-size: 22px; }
.ce-photo-empty-label { font-size: 11px; font-weight: 600; }

.ce-text { position: absolute; white-space: pre; pointer-events: none; }
.ce-line { white-space: pre; }

.ce-stamp { position: absolute; }
.ce-surface.is-interactive .ce-stamp { cursor: move; touch-action: none; }
.ce-stamp-img { width: 100%; height: 100%; display: block; user-select: none; pointer-events: none; }

.ce-stamp-delete,
.ce-stamp-resize {
  position: absolute;
  width: 18px;
  height: 18px;
  padding: 0;
  border: 1.5px solid #fff;
  border-radius: 50%;
  background: var(--ce-red);
  color: #fff;
  font-size: 11px;
  line-height: 1;
  cursor: pointer;
  opacity: 0;
  transition: opacity .12s;
}
.ce-stamp-delete { top: -9px; right: -9px; }
.ce-stamp-resize { bottom: -9px; right: -9px; background: #59534d; cursor: nwse-resize; }

.ce-stamp:hover .ce-stamp-delete,
.ce-stamp:hover .ce-stamp-resize,
.ce-stamp:focus-within .ce-stamp-delete,
.ce-stamp:focus-within .ce-stamp-resize,
.ce-stamp.is-selected .ce-stamp-delete,
.ce-stamp.is-selected .ce-stamp-resize { opacity: 1; }

.ce-stamp.is-selected { outline: 1.5px dashed var(--ce-red); outline-offset: 2px; }

/* ------------------------------------------------------------- 右パネル */

.ce-swatches { display: flex; flex-wrap: wrap; gap: 8px; }

.ce-swatch {
  width: 32px;
  height: 32px;
  border: 2px solid #d8d3cd;
  border-radius: 50%;
  cursor: pointer;
  padding: 0;
  transition: transform .12s, border-color .12s;
}
.ce-swatch:hover { transform: scale(1.08); }
.ce-swatch.is-active { border-color: var(--ce-red); box-shadow: 0 0 0 3px var(--ce-red-soft); }

.ce-color-row { display: flex; align-items: center; gap: 10px; }
.ce-color-input {
  width: 42px;
  height: 34px;
  padding: 2px;
  border: 1.5px solid var(--ce-line);
  border-radius: 8px;
  background: #fff;
  cursor: pointer;
}

.ce-zoom-row { display: flex; align-items: center; gap: 10px; }
.ce-zoom-row input[type="range"] {
  flex: 1;
  -webkit-appearance: none;
  appearance: none;
  height: 6px;
  border-radius: 3px;
  background: #e2ddd7;
  outline: none;
  cursor: pointer;
}
.ce-zoom-row input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  background: var(--ce-red);
  border: 3px solid #fff;
  box-shadow: 0 1px 4px rgba(0,0,0,.3);
  cursor: pointer;
}
.ce-zoom-row input[type="range"]::-moz-range-thumb {
  width: 16px; height: 16px; border-radius: 50%;
  background: var(--ce-red); border: 3px solid #fff; cursor: pointer;
}
.ce-zoom-btn { width: 34px; min-height: 34px; padding: 0; font-size: 1.05rem; }

.ce-stamp-grid { display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); gap: 7px; }

.ce-stamp-pick {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  padding: 6px 2px 4px;
  border: 1.5px solid var(--ce-line);
  border-radius: 9px;
  background: #fff;
  cursor: pointer;
  font-family: inherit;
  transition: border-color .15s, transform .12s;
}
.ce-stamp-pick:hover { border-color: var(--ce-red); transform: translateY(-1px); }
.ce-stamp-pick img { width: 26px; height: 26px; }
.ce-stamp-pick span { font-size: 0.68rem; color: var(--ce-muted); }

.ce-panel-note {
  margin: 6px 0 0;
  padding: 9px 11px;
  border-radius: 9px;
  background: #fbf7ef;
  border: 1px solid #f0e6d2;
  font-size: 0.78rem;
  color: #7a6a4d;
  line-height: 1.6;
}

.ce-section.is-disabled { opacity: .55; }

/* ------------------------------------------------------------- 下部アクション */

.ce-actions {
  grid-area: actions;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  flex-wrap: wrap;
  padding: 12px 16px;
  background: #fff;
  border: 1px solid var(--ce-line);
  border-radius: var(--ce-radius);
}

.ce-action-btn {
  min-width: 168px;
  min-height: 52px;
  font-size: 1rem;
  border-width: 2px;
}

.ce-action-btn.ce-btn-primary { min-width: 200px; font-size: 1.06rem; }

.ce-actions-info {
  margin-left: 6px;
  font-size: 0.76rem;
  color: var(--ce-muted);
  line-height: 1.5;
}

/* ------------------------------------------------------------------ 保存 */

.ce-saved-dialog {
  width: min(480px, 92vw);
  padding: 0;
  border: none;
  border-radius: 14px;
  box-shadow: 0 18px 50px rgba(0,0,0,.25);
}
.ce-saved-dialog::backdrop { background: rgba(40, 32, 26, .45); }
.ce-saved-head { display: flex; align-items: center; justify-content: space-between; padding: 16px 18px; border-bottom: 1px solid var(--ce-line); }
.ce-saved-head h2 { margin: 0; font-size: 1.05rem; }
.ce-saved-body { padding: 16px 18px; max-height: 60vh; overflow-y: auto; }
.ce-saved-form { display: flex; gap: 8px; margin-bottom: 16px; }
.ce-saved-item { display: flex; align-items: center; gap: 8px; padding: 10px 0; border-top: 1px solid var(--ce-line); }
.ce-saved-info { flex: 1; min-width: 0; }
.ce-saved-name { font-size: 0.9rem; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ce-saved-date { font-size: 0.75rem; color: var(--ce-muted); }
.ce-saved-empty { color: var(--ce-muted); font-size: 0.86rem; }

/* ------------------------------------------------------------------ toast */

.ce-toast {
  position: fixed;
  left: 50%;
  bottom: 26px;
  transform: translateX(-50%) translateY(14px);
  padding: 11px 20px;
  border-radius: 999px;
  background: rgba(47, 42, 38, .94);
  color: #fff;
  font-size: 0.88rem;
  opacity: 0;
  pointer-events: none;
  transition: opacity .2s, transform .2s;
  z-index: 60;
}
.ce-toast.is-visible { opacity: 1; transform: translateX(-50%) translateY(0); }
.ce-toast.is-error { background: #b3261e; }

/* -------------------------------------------------------------- 印刷用 */

#ce-print-root { display: none; }

@media print {
  body > *:not(#ce-print-root) { display: none !important; }

  #ce-print-root {
    display: block;
    margin: 0;
    padding: 0;
  }

  #ce-print-root .ce-surface {
    transform: none !important;
    border-radius: 0;
    box-shadow: none;
  }

  @page { size: 100mm 148mm; margin: 0; }
  html, body { margin: 0; padding: 0; background: #fff; }
}

/* --------------------------------------------------------- レスポンシブ */

@media (max-width: 1180px) {
  .ce-app { grid-template-columns: 254px minmax(0, 1fr) 310px; }
  .ce-action-btn { min-width: 140px; }
}

/* タブレット: テンプレート一覧を横スクロールの帯に落とす */
@media (max-width: 1000px) {
  .ce-app {
    grid-template-columns: minmax(0, 1fr) 320px;
    grid-template-rows: auto minmax(0, 1fr) auto;
    grid-template-areas:
      "left left"
      "main right"
      "actions actions";
    height: auto;
  }
  .ce-panel-left { max-height: none; }
  .ce-template-list { grid-template-columns: repeat(auto-fill, minmax(112px, 1fr)); }
  /* align-self keeps the preview from stretching to the edit panel's height,
     which would blow the card up to fill a whole screen. */
  .ce-main { height: 62vh; min-height: 420px; align-self: start; }
}

/* スマートフォン: 完全な編集環境ではなく「選ぶ・書く・写真・保存」に絞る */
@media (max-width: 720px) {
  .ce-app {
    grid-template-columns: minmax(0, 1fr);
    grid-template-rows: auto auto auto auto;
    grid-template-areas: "main" "right" "left" "actions";
    gap: 10px;
    padding: 10px;
    height: auto;
  }
  .ce-main { height: 58vh; min-height: 360px; align-self: start; padding: 12px 4px; }
  .ce-panel { overflow: visible; }
  .ce-template-list { grid-template-columns: repeat(auto-fill, minmax(96px, 1fr)); }
  .ce-field { grid-template-columns: 1fr; gap: 4px; }
  .ce-field > label { padding-top: 0; }
  .ce-stamp-grid { grid-template-columns: repeat(5, minmax(0, 1fr)); }
  .ce-actions {
    position: sticky;
    bottom: 0;
    gap: 8px;
    padding: 10px;
    z-index: 20;
    box-shadow: 0 -4px 14px rgba(0,0,0,.08);
  }
  .ce-action-btn { flex: 1; min-width: 0; padding: 10px 6px; font-size: 0.92rem; }
  .ce-action-btn.ce-btn-primary { min-width: 0; font-size: 0.96rem; }
  .ce-actions-info { flex-basis: 100%; margin: 0; text-align: center; }
}
