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

:root {
  --green: #06C755;
  --green-dark: #05a847;
  --radius: 16px;
  --shadow: 0 2px 12px rgba(0,0,0,0.10);
}

html, body {
  min-height: 100%;
  background: #f0f0f0;
  font-family: -apple-system, BlinkMacSystemFont, 'Hiragino Kaku Gothic ProN', 'Noto Sans JP', sans-serif;
  -webkit-tap-highlight-color: transparent;
  -webkit-text-size-adjust: 100%;
}

/* ─── レイアウト ─── */
.app-wrap {
  max-width: 420px;
  min-height: 100vh;
  margin: 0 auto;
  background: #f8f8f8;
  position: relative;
  overflow-x: hidden;
}

.hidden { display: none !important; }

/* ─── ヘッダー ─── */
.app-header {
  background: var(--green);
  color: #fff;
  padding: 20px 16px 18px;
  text-align: center;
}
.app-header .sub { font-size: 12px; opacity: 0.85; margin-bottom: 4px; }
.app-header h1 { font-size: 22px; font-weight: 700; letter-spacing: 0.03em; }
.app-header .note { font-size: 12px; opacity: 0.85; margin-top: 6px; }

.header-with-back {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 14px 16px;
  background: var(--green);
  color: #fff;
}
.header-with-back h2 { font-size: 17px; font-weight: 700; flex: 1; text-align: center; }
.btn-back {
  background: rgba(255,255,255,0.25);
  border: none;
  color: #fff;
  border-radius: 8px;
  padding: 6px 12px;
  font-size: 14px;
  cursor: pointer;
  white-space: nowrap;
}

/* ─── 作成モード ─── */
.create-body { padding: 16px; display: flex; flex-direction: column; gap: 16px; }

.form-card {
  background: #fff;
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}
.form-card h2 { font-size: 15px; font-weight: 700; color: #333; }

.field { display: flex; flex-direction: column; gap: 4px; }
.field label { font-size: 12px; color: #666; font-weight: 600; }
.field input, .field textarea {
  border: 1.5px solid #e0e0e0;
  border-radius: 10px;
  padding: 10px 12px;
  font-size: 15px;
  outline: none;
  transition: border-color 0.15s;
  background: #fafafa;
  width: 100%;
  font-family: inherit;
}
.field input:focus, .field textarea:focus { border-color: var(--green); background: #fff; }
.field.error input, .field.error textarea { border-color: #ef4444; }
.field .err-msg { font-size: 11px; color: #ef4444; display: none; }
.field.error .err-msg { display: block; }
.field textarea { resize: none; height: 60px; }

/* ─── クーポンカード（作成） ─── */
.coupon-item {
  background: #fff;
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 14px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  animation: fadeIn 0.2s ease;
}
.coupon-item-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.coupon-item-header span { font-size: 13px; font-weight: 700; color: #555; }
.btn-remove {
  background: none;
  border: none;
  color: #bbb;
  font-size: 20px;
  cursor: pointer;
  padding: 0 4px;
  line-height: 1;
}
.btn-remove:hover { color: #ef4444; }

/* カラーピッカー */
.color-row { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.color-row label { font-size: 12px; color: #666; font-weight: 600; width: 100%; }
.color-dot {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  cursor: pointer;
  border: 3px solid transparent;
  transition: transform 0.1s, border-color 0.1s;
}
.color-dot:hover { transform: scale(1.12); }
.color-dot.selected { border-color: #333; transform: scale(1.12); }

/* 画像エリア */
.image-area { display: flex; flex-direction: column; gap: 8px; }
.image-area label { font-size: 12px; color: #666; font-weight: 600; }
.btn-img-add {
  background: #f0f0f0;
  border: 1.5px dashed #ccc;
  border-radius: 10px;
  padding: 10px;
  font-size: 13px;
  color: #888;
  cursor: pointer;
  text-align: center;
  width: 100%;
}
.btn-img-add:hover { border-color: var(--green); color: var(--green); background: #f0fff4; }
.img-preview {
  width: 100%;
  max-height: 120px;
  object-fit: cover;
  border-radius: 10px;
  display: none;
}
.img-spinner {
  text-align: center;
  font-size: 12px;
  color: #aaa;
  display: none;
}
.btn-img-remove {
  background: none;
  border: none;
  font-size: 11px;
  color: #ef4444;
  cursor: pointer;
  display: none;
  padding: 0;
}

/* ─── ボタン群 ─── */
.btn-add-coupon {
  background: #fff;
  border: 2px dashed var(--green);
  color: var(--green);
  border-radius: var(--radius);
  padding: 14px;
  font-size: 15px;
  font-weight: 700;
  cursor: pointer;
  width: 100%;
  transition: background 0.15s;
}
.btn-add-coupon:hover { background: #f0fff4; }

.btn-primary {
  background: var(--green);
  color: #fff;
  border: none;
  border-radius: var(--radius);
  padding: 16px;
  font-size: 16px;
  font-weight: 700;
  cursor: pointer;
  width: 100%;
  transition: background 0.15s, transform 0.1s;
  letter-spacing: 0.02em;
}
.btn-primary:hover { background: var(--green-dark); }
.btn-primary:active { transform: scale(0.98); }
.btn-primary:disabled { background: #aaa; cursor: not-allowed; }

.btn-secondary {
  background: #fff;
  color: var(--green);
  border: 2px solid var(--green);
  border-radius: var(--radius);
  padding: 13px;
  font-size: 15px;
  font-weight: 700;
  cursor: pointer;
  width: 100%;
  transition: background 0.15s;
}
.btn-secondary:hover { background: #f0fff4; }

/* URL結果エリア */
.url-result-card {
  background: #fff;
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 20px 16px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  text-align: center;
}
.url-result-card h3 { font-size: 15px; color: #333; font-weight: 700; }
.url-box {
  background: #f5f5f5;
  border-radius: 10px;
  padding: 12px;
  font-size: 14px;
  word-break: break-all;
  color: #333;
  border: 1.5px solid #e0e0e0;
}
.btn-copy {
  background: #f0f0f0;
  border: none;
  border-radius: 10px;
  padding: 10px;
  font-size: 14px;
  cursor: pointer;
  font-weight: 600;
  color: #555;
  transition: background 0.15s;
}
.btn-copy:hover { background: #e0e0e0; }
.btn-copy.copied { color: var(--green); }

.btn-line {
  background: var(--green);
  color: #fff;
  border: none;
  border-radius: var(--radius);
  padding: 15px;
  font-size: 16px;
  font-weight: 700;
  cursor: pointer;
  width: 100%;
  transition: background 0.15s;
  text-decoration: none;
  display: block;
  text-align: center;
}
.btn-line:hover { background: var(--green-dark); }

/* スピナー */
.spinner {
  display: inline-block;
  width: 18px;
  height: 18px;
  border: 2px solid #ddd;
  border-top-color: var(--green);
  border-radius: 50%;
  animation: spin 0.6s linear infinite;
  vertical-align: middle;
  margin-right: 6px;
}
.generating-msg { text-align: center; font-size: 14px; color: #888; padding: 8px 0; }

/* ─── 表示モード：一覧 ─── */
.display-body { padding: 16px; display: flex; flex-direction: column; gap: 10px; }

.coupon-card-view {
  background: #fff;
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 16px 16px 16px 20px;
  display: flex;
  align-items: center;
  gap: 12px;
  cursor: pointer;
  position: relative;
  overflow: hidden;
  transition: transform 0.1s;
  border-left: 5px solid var(--green);
}
.coupon-card-view:active { transform: scale(0.98); }
.coupon-card-view .card-text { flex: 1; }
.coupon-card-view .card-name { font-size: 16px; font-weight: 700; color: #222; }
.coupon-card-view .card-desc { font-size: 13px; color: #777; margin-top: 3px; }
.coupon-card-view .card-arrow { color: #ccc; font-size: 20px; }

.coupon-card-view.used {
  opacity: 0.5;
  cursor: default;
}
.coupon-card-view.used:active { transform: none; }

.used-stamp {
  position: absolute;
  top: 50%;
  right: 16px;
  transform: translateY(-50%) rotate(-12deg);
  background: #ef4444;
  color: #fff;
  font-size: 11px;
  font-weight: 900;
  padding: 3px 8px;
  border-radius: 4px;
  border: 2px solid #ef4444;
  letter-spacing: 0.05em;
  pointer-events: none;
}

.display-footer {
  text-align: center;
  font-size: 13px;
  color: #aaa;
  padding: 16px 0 8px;
}

.make-your-own {
  text-align: center;
  padding: 20px 16px 32px;
  border-top: 1px solid #eee;
  margin: 0 16px;
}
.make-your-own p {
  font-size: 13px;
  color: #888;
  margin-bottom: 12px;
}
.btn-make-your-own {
  display: inline-block;
  background: #06C755;
  color: #fff;
  font-size: 15px;
  font-weight: 700;
  padding: 12px 28px;
  border-radius: 999px;
  text-decoration: none;
  box-shadow: 0 4px 12px rgba(6,199,85,.35);
  transition: opacity .15s;
}
.btn-make-your-own:active { opacity: .75; }

/* ─── 表示モード：詳細 ─── */
.detail-body { padding: 16px; }

.detail-card {
  background: #fff;
  border-radius: 20px;
  box-shadow: var(--shadow);
  overflow: hidden;
  position: relative;
}

.detail-img-area {
  width: 100%;
  height: 200px;
  overflow: hidden;
  position: relative;
}
.detail-img-area img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}
.detail-img-area .detail-img-emoji {
  width: 100%;
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 72px;
}

.detail-badge {
  position: absolute;
  top: 12px;
  left: 12px;
  background: rgba(255,255,255,0.92);
  color: #333;
  font-size: 12px;
  font-weight: 700;
  padding: 5px 10px;
  border-radius: 20px;
  box-shadow: 0 1px 4px rgba(0,0,0,0.15);
}

.detail-info { padding: 20px 20px 8px; }
.detail-info .d-name { font-size: 22px; font-weight: 800; color: #222; line-height: 1.3; }
.detail-info .d-desc { font-size: 15px; color: #666; margin-top: 8px; line-height: 1.5; }

.detail-divider {
  border: none;
  border-top: 2px dashed #ddd;
  margin: 16px 20px;
}

.detail-action { padding: 0 20px 24px; position: relative; }

.btn-use {
  background: var(--green);
  color: #fff;
  border: none;
  border-radius: 14px;
  padding: 16px;
  font-size: 18px;
  font-weight: 800;
  cursor: pointer;
  width: 100%;
  letter-spacing: 0.04em;
  transition: background 0.15s, transform 0.1s;
}
.btn-use:hover { background: var(--green-dark); }
.btn-use:active { transform: scale(0.97); }
.btn-use.used {
  background: #aaa;
  cursor: not-allowed;
}
.btn-use.used:active { transform: none; }

/* 使用済みスタンプ（詳細） */
.detail-stamp {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%) rotate(-15deg) scale(0);
  font-size: 48px;
  font-weight: 900;
  color: #ef4444;
  border: 4px solid #ef4444;
  border-radius: 8px;
  padding: 4px 12px;
  letter-spacing: 0.08em;
  pointer-events: none;
  opacity: 0;
  white-space: nowrap;
}
.detail-stamp.show {
  animation: stampAnim 0.4s cubic-bezier(0.175, 0.885, 0.32, 1.275) forwards;
}
.detail-stamp.visible {
  transform: translate(-50%, -50%) rotate(-15deg) scale(1);
  opacity: 0.85;
}

/* ─── モーダル ─── */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.5);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
  padding: 16px;
}
.modal-box {
  background: #fff;
  border-radius: 20px;
  padding: 28px 24px 20px;
  width: 100%;
  max-width: 320px;
  text-align: center;
  box-shadow: 0 8px 32px rgba(0,0,0,0.2);
  animation: modalFade 0.2s ease;
}
.modal-box h3 { font-size: 18px; font-weight: 800; color: #222; margin-bottom: 8px; }
.modal-box p { font-size: 14px; color: #666; margin-bottom: 20px; line-height: 1.5; }
.modal-btns { display: flex; gap: 10px; }
.modal-btns button { flex: 1; padding: 12px; border-radius: 12px; font-size: 15px; font-weight: 700; cursor: pointer; border: none; }
.btn-modal-ok { background: var(--green); color: #fff; }
.btn-modal-ok:hover { background: var(--green-dark); }
.btn-modal-cancel { background: #f0f0f0; color: #555; }
.btn-modal-cancel:hover { background: #e0e0e0; }

/* ─── エラー画面 ─── */
.error-screen {
  padding: 40px 24px;
  text-align: center;
  color: #888;
}
.error-screen .error-icon { font-size: 48px; margin-bottom: 16px; }
.error-screen p { font-size: 15px; line-height: 1.6; }

/* ─── アニメーション ─── */
@keyframes fadeIn {
  from { opacity: 0; transform: translateY(8px); }
  to   { opacity: 1; transform: translateY(0); }
}
@keyframes spin {
  to { transform: rotate(360deg); }
}
@keyframes stampAnim {
  0%   { transform: translate(-50%, -50%) rotate(-15deg) scale(0);   opacity: 0; }
  60%  { transform: translate(-50%, -50%) rotate(-15deg) scale(1.2); opacity: 1; }
  100% { transform: translate(-50%, -50%) rotate(-15deg) scale(1);   opacity: 0.85; }
}
@keyframes modalFade {
  from { opacity: 0; transform: scale(0.92); }
  to   { opacity: 1; transform: scale(1); }
}

/* ─── プレビュー用オーバーレイ ─── */
.preview-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.6);
  z-index: 50;
  overflow-y: auto;
  padding: 20px 0;
}
.preview-inner {
  max-width: 420px;
  margin: 0 auto;
  background: #f8f8f8;
  min-height: 100%;
  border-radius: 16px;
  overflow: hidden;
}
.preview-close-bar {
  text-align: center;
  padding: 8px;
  background: rgba(0,0,0,0.15);
}
.btn-preview-close {
  background: rgba(255,255,255,0.9);
  border: none;
  border-radius: 20px;
  padding: 8px 20px;
  font-size: 13px;
  font-weight: 700;
  cursor: pointer;
  color: #333;
}

/* ─── ローディングオーバーレイ ─── */
.loading-overlay {
  position: fixed;
  inset: 0;
  background: rgba(255,255,255,0.85);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  z-index: 200;
  gap: 12px;
}
.loading-overlay .spinner { width: 36px; height: 36px; border-width: 3px; }
.loading-overlay p { font-size: 14px; color: #666; }
