:root {
  --cream: #FBF7EF;
  --cream-deep: #F3ECDD;
  --ink: #3A2E2A;
  --blue: #3D5A80;
  --blue-soft: #DCE6F0;
  --apricot: #F4A259;
  --apricot-soft: #FCE6CC;
  --green: #8FB996;
  --green-soft: #E4EFE2;
  --white: #FFFFFF;
  --shadow: 0 10px 30px rgba(61, 90, 128, 0.12);
  --radius-lg: 28px;
  --radius-md: 18px;
  --radius-sm: 12px;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--cream);
  color: var(--ink);
  font-family: "M PLUS Rounded 1c", "Zen Maru Gothic", sans-serif;
  min-height: 100%;
}

body {
  position: relative;
  overflow-x: hidden;
}

/* 背景の浮遊デコ */
.bg-deco {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 0;
  overflow: hidden;
}
.deco {
  position: absolute;
  font-size: 48px;
  opacity: 0.18;
  animation: float 14s ease-in-out infinite;
}
.deco-1 { top: 8%; left: 4%; animation-delay: 0s; }
.deco-2 { top: 18%; right: 6%; animation-delay: 2s; font-size: 38px; }
.deco-3 { bottom: 12%; left: 8%; animation-delay: 4s; font-size: 42px; }
.deco-4 { bottom: 22%; right: 10%; animation-delay: 1s; font-size: 56px; }

@keyframes float {
  0%, 100% { transform: translateY(0) rotate(0deg); }
  50% { transform: translateY(-22px) rotate(6deg); }
}

@media (prefers-reduced-motion: reduce) {
  .deco { animation: none; }
}

/* ヘッダー */
.app-header {
  position: relative;
  z-index: 1;
  background: var(--white);
  border-bottom: 3px dashed var(--apricot-soft);
}
.header-inner {
  max-width: 1080px;
  margin: 0 auto;
  padding: 22px 28px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  flex-wrap: wrap;
}
.brand {
  display: flex;
  align-items: center;
  gap: 14px;
}
.brand-mark {
  font-size: 40px;
  line-height: 1;
}
.brand-text h1 {
  margin: 0;
  font-size: 24px;
  font-weight: 800;
  color: var(--blue);
  letter-spacing: 0.02em;
}
.brand-text p {
  margin: 4px 0 0;
  font-size: 13px;
  color: #6b6058;
}
.badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: var(--green-soft);
  color: #3f6b48;
  font-size: 12.5px;
  font-weight: 700;
  padding: 8px 14px;
  border-radius: 999px;
}

/* レイアウト */
.layout {
  position: relative;
  z-index: 1;
  max-width: 1080px;
  margin: 0 auto;
  padding: 28px 20px 60px;
  display: flex;
  flex-direction: column;
  gap: 26px;
}

.panel {
  background: var(--white);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow);
  padding: 28px;
}

.panel-head {
  display: flex;
  align-items: center;
  gap: 14px;
  margin-bottom: 20px;
  flex-wrap: wrap;
}
.panel-head h2 {
  margin: 0;
  font-size: 20px;
  font-weight: 800;
  color: var(--ink);
}
.step-chip {
  background: var(--blue);
  color: var(--white);
  font-size: 12.5px;
  font-weight: 700;
  padding: 6px 14px;
  border-radius: 999px;
  letter-spacing: 0.04em;
}
.step-chip-done {
  background: var(--green);
}
.btn-text {
  margin-left: auto;
  background: none;
  border: none;
  color: var(--blue);
  font-weight: 700;
  font-size: 13.5px;
  cursor: pointer;
  text-decoration: underline;
  font-family: inherit;
  padding: 4px;
}
.btn-text:hover { opacity: 0.7; }

/* アップロード */
.dropzone {
  display: block;
  cursor: pointer;
  border: 3px dashed var(--blue-soft);
  border-radius: var(--radius-md);
  background: var(--cream);
  padding: 56px 24px;
  text-align: center;
  transition: border-color 0.2s ease, background 0.2s ease, transform 0.15s ease;
}
.dropzone:hover, .dropzone.drag-over {
  border-color: var(--apricot);
  background: var(--apricot-soft);
  transform: scale(1.005);
}
.dropzone-emoji {
  font-size: 56px;
  display: block;
  margin-bottom: 14px;
}
.dropzone-title {
  margin: 0;
  font-size: 18px;
  font-weight: 800;
  color: var(--blue);
}
.dropzone-sub {
  margin: 6px 0 0;
  font-size: 13px;
  color: #8a8079;
}

/* ステージ */
.stage-wrap {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 260px;
  gap: 24px;
  align-items: start;
}
@media (max-width: 800px) {
  .stage-wrap { grid-template-columns: 1fr; }
}

.canvas-card {
  background: var(--cream);
  border-radius: var(--radius-md);
  padding: 16px;
  position: relative;
}
.canvas-stack {
  position: relative;
  width: 100%;
  border-radius: var(--radius-sm);
  overflow: hidden;
  background: #efe9da;
  line-height: 0;
}
.canvas-stack canvas {
  width: 100%;
  display: block;
}
#overlayCanvas {
  position: absolute;
  top: 0; left: 0;
  cursor: crosshair;
}
.canvas-status {
  display: flex;
  align-items: center;
  gap: 10px;
  justify-content: center;
  margin-top: 14px;
  font-size: 14px;
  font-weight: 700;
  color: var(--blue);
}
.canvas-status[hidden] { display: none; }
.spinner {
  width: 16px; height: 16px;
  border: 3px solid var(--blue-soft);
  border-top-color: var(--blue);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.manual-hint {
  margin-top: 10px;
  font-size: 12.5px;
  color: #8a8079;
  text-align: center;
}

/* サイドコントロール */
.side-controls {
  display: flex;
  flex-direction: column;
  gap: 16px;
}
.control-card {
  background: var(--cream);
  border-radius: var(--radius-md);
  padding: 16px;
}
.control-card h3 {
  margin: 0 0 12px;
  font-size: 14px;
  font-weight: 800;
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--ink);
}
.ctrl-icon { font-size: 16px; }

.emoji-grid {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 8px;
}
.emoji-btn {
  font-size: 22px;
  background: var(--white);
  border: 2px solid transparent;
  border-radius: 10px;
  padding: 8px 0;
  cursor: pointer;
  transition: transform 0.12s ease, border-color 0.12s ease;
}
.emoji-btn:hover { transform: scale(1.1); }
.emoji-btn.active {
  border-color: var(--apricot);
  background: var(--apricot-soft);
}

input[type="range"] {
  width: 100%;
  accent-color: var(--apricot);
}
.range-labels {
  display: flex;
  justify-content: space-between;
  font-size: 11.5px;
  color: #8a8079;
  margin-top: 4px;
}

.face-count {
  margin: 0 0 10px;
  font-size: 22px;
  font-weight: 800;
  color: var(--apricot);
}

/* ボタン */
.btn-primary {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  background: var(--apricot);
  color: var(--white);
  font-family: inherit;
  font-size: 16px;
  font-weight: 800;
  border: none;
  border-radius: 999px;
  padding: 14px 34px;
  cursor: pointer;
  box-shadow: 0 8px 20px rgba(244, 162, 89, 0.4);
  transition: transform 0.15s ease, box-shadow 0.15s ease;
  text-decoration: none;
}
.btn-primary:hover {
  transform: translateY(-2px);
  box-shadow: 0 12px 24px rgba(244, 162, 89, 0.5);
}
.btn-primary:active { transform: translateY(0); }
.btn-primary:disabled {
  background: #cfc7bb;
  box-shadow: none;
  cursor: not-allowed;
  transform: none;
}
.btn-primary-emoji { font-size: 18px; }

.btn-secondary {
  width: 100%;
  background: var(--white);
  color: var(--blue);
  border: 2px solid var(--blue-soft);
  font-family: inherit;
  font-size: 13.5px;
  font-weight: 700;
  border-radius: 999px;
  padding: 10px 16px;
  cursor: pointer;
  margin-top: 8px;
  transition: background 0.15s ease;
}
.btn-secondary:hover { background: var(--blue-soft); }

.action-row {
  display: flex;
  justify-content: center;
  margin-top: 26px;
}

/* 結果 */
.result-card {
  background: var(--cream);
  border-radius: var(--radius-md);
  padding: 16px;
  text-align: center;
}
.result-card img {
  max-width: 100%;
  border-radius: var(--radius-sm);
  display: block;
  margin: 0 auto;
}
.auto-saved-note {
  text-align: center;
  margin: 18px auto 0;
  font-size: 14px;
  font-weight: 700;
  color: #3f6b48;
  background: var(--green-soft);
  border-radius: 999px;
  padding: 10px 18px;
  display: table;
}
.result-card { text-align: center; }
.result-actions {
  display: flex;
  justify-content: center;
  gap: 12px;
  flex-wrap: wrap;
  margin-top: 22px;
}
.result-actions .btn-secondary {
  width: auto;
  margin-top: 0;
  padding: 12px 22px;
}

/* フッター */
.app-footer {
  position: relative;
  z-index: 1;
  text-align: center;
  padding: 24px;
  font-size: 12px;
  color: #a39a8f;
}

/* スタンプの着地アニメーション */
@keyframes stampLand {
  0% { transform: scale(0); opacity: 0; }
  60% { transform: scale(1.25); opacity: 1; }
  80% { transform: scale(0.92); }
  100% { transform: scale(1); }
}
.stamp-pop {
  animation: stampLand 0.45s cubic-bezier(.34,1.56,.64,1);
}

/* ヘッダーの常設インストールボタン */
.header-note {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}
.btn-install-header {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: var(--blue);
  color: var(--white);
  font-family: inherit;
  font-size: 12.5px;
  font-weight: 700;
  border: none;
  border-radius: 999px;
  padding: 8px 16px;
  cursor: pointer;
  transition: transform 0.15s ease, opacity 0.15s ease;
}
.btn-install-header:hover {
  transform: translateY(-1px);
  opacity: 0.92;
}
.btn-install-header[hidden] {
  display: none;
}

/* ホーム画面追加モーダル */
.install-modal-overlay {
  position: fixed;
  inset: 0;
  z-index: 100;
  background: rgba(58, 46, 42, 0.45);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
}
.install-modal-overlay[hidden] {
  display: none;
}
.install-modal {
  background: var(--white);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow);
  padding: 32px 28px;
  max-width: 380px;
  width: 100%;
  text-align: center;
}
.install-modal-icon {
  font-size: 44px;
  display: block;
  margin-bottom: 12px;
}
.install-modal h2 {
  margin: 0 0 12px;
  font-size: 19px;
  font-weight: 800;
  color: var(--ink);
}
.install-modal p {
  margin: 0 0 18px;
  font-size: 13.5px;
  line-height: 1.7;
  color: #6b6058;
}
.install-modal-steps {
  text-align: left;
  margin: 0 0 20px;
  padding-left: 20px;
  font-size: 13.5px;
  line-height: 2;
  color: var(--ink);
}
.install-modal-steps li { margin-bottom: 4px; }
.ios-share-icon { font-size: 14px; }
.install-modal-actions {
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.install-modal-actions .btn-primary,
.install-modal-actions .btn-secondary {
  width: 100%;
}
.install-modal-actions .btn-secondary { margin-top: 0; }
