/* ============================================================
   もじぷる — 文字GIFメーカー
   駄菓子屋ステッカー風:クリーム紙地 × シールカード × ポップ配色
   ============================================================ */

:root {
  --paper:  #fbf1dd;
  --dots:   #ecdec3;
  --card:   #fffdf6;
  --ink:    #33302b;
  --ink-soft: rgba(51, 48, 43, .55);
  --coral:  #ff6257;
  --coral-deep: #e0413a;
  --blue:   #4d7fde;
  --yellow: #ffc531;
  --mint:   #43b98c;
  --pink:   #ff7eb3;
  --shadow: 5px 6px 0 rgba(51, 48, 43, .14);
  --border: 3px solid var(--ink);
  --radius: 22px;
  --font-display: "Hachi Maru Pop", "Zen Maru Gothic", sans-serif;
  --font-body: "Zen Maru Gothic", "M PLUS Rounded 1c", sans-serif;
}

* { box-sizing: border-box; }

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

body {
  margin: 0;
  color: var(--ink);
  font-family: var(--font-body);
  font-weight: 500;
  background-color: var(--paper);
  background-image: radial-gradient(var(--dots) 1.6px, transparent 1.7px);
  background-size: 24px 24px;
  min-height: 100vh;
}

/* ---------------- ヘッダー ---------------- */

.site-head {
  text-align: center;
  padding: 44px 16px 8px;
}

.logo {
  margin: 0;
  font-family: var(--font-display);
  font-size: clamp(34px, 6vw, 52px);
  line-height: 1;
  letter-spacing: 2px;
}

.logo-chip {
  display: inline-block;
  padding: .18em .22em .1em;
  margin: 0 3px;
  color: #fff;
  border: var(--border);
  border-radius: .3em;
  text-shadow: 2px 2px 0 rgba(51, 48, 43, .35);
  animation: chip-hop 2.4s ease-in-out infinite;
}
.logo-chip:nth-child(1) { animation-delay: 0s;   transform: rotate(-5deg); }
.logo-chip:nth-child(2) { animation-delay: .15s; transform: rotate(3deg); }
.logo-chip:nth-child(3) { animation-delay: .3s;  transform: rotate(-3deg); }
.logo-chip:nth-child(4) { animation-delay: .45s; transform: rotate(5deg); }

@keyframes chip-hop {
  0%, 55%, 100% { translate: 0 0; }
  40%           { translate: 0 -7px; }
}

.c-coral  { background: var(--coral); }
.c-blue   { background: var(--blue); }
.c-yellow { background: var(--yellow); }
.c-mint   { background: var(--mint); }

.subtitle {
  margin: 12px 0 0;
  font-family: var(--font-display);
  font-size: 15px;
  letter-spacing: .35em;
}

.tagline {
  margin: 6px 0 0;
  font-size: 13px;
  color: var(--ink-soft);
}

/* ---------------- レイアウト ---------------- */

.layout {
  display: grid;
  grid-template-columns: 350px 1fr;
  gap: 24px;
  align-items: start;
  max-width: 1040px;
  margin: 26px auto 0;
  padding: 0 18px;
}

.controls {
  display: flex;
  flex-direction: column;
  gap: 24px;
}

@media (max-width: 900px) {
  .layout { grid-template-columns: 1fr; }
}

/* ---------------- カード(シール) ---------------- */

.card {
  background: var(--card);
  border: var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 20px 22px 22px;
}

.preview-card {
  position: sticky;
  top: 18px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 14px;
}

.card h2, .card h3 { margin: 0; align-self: flex-start; }

.tag {
  display: inline-block;
  font-family: var(--font-display);
  font-size: 14px;
  color: #fff;
  padding: 4px 14px 2px;
  border: 2.5px solid var(--ink);
  border-radius: 999px;
  text-shadow: 1px 1px 0 rgba(51, 48, 43, .4);
  transform: rotate(-2deg);
}
.t-coral  { background: var(--coral); }
.t-blue   { background: var(--blue); }
.t-yellow { background: var(--yellow); }
.t-mint   { background: var(--mint); }
.t-pink   { background: var(--pink); }

.card h2 { margin-bottom: 14px; }

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

.checker {
  background: repeating-conic-gradient(#eae2d0 0% 25%, #ffffff 0% 50%) 0 0 / 16px 16px;
  border: var(--border);
  border-radius: 16px;
  overflow: hidden;
  display: grid;
  place-items: center;
}

/* 市松の枠はキャンバス実寸にぴったり合わせる */
.pv-wrap { width: fit-content; height: fit-content; }

.meta-info { margin: 0; font-size: 12px; color: var(--ink-soft); text-align: center; }

/* ---------------- ボタン ---------------- */

.btn-primary {
  font-family: var(--font-display);
  font-size: 18px;
  color: #fff;
  text-align: center;
  text-decoration: none;
  background: var(--coral);
  border: var(--border);
  border-radius: 999px;
  padding: 12px 34px 9px;
  cursor: pointer;
  box-shadow: 0 5px 0 var(--coral-deep), 3px 8px 0 rgba(51, 48, 43, .15);
  transition: translate .08s ease, box-shadow .08s ease;
  text-shadow: 1px 1px 0 rgba(51, 48, 43, .35);
}

.btn-primary:hover { translate: 0 -2px; box-shadow: 0 7px 0 var(--coral-deep), 3px 10px 0 rgba(51,48,43,.15); }
.btn-primary:active { translate: 0 3px; box-shadow: 0 2px 0 var(--coral-deep); }
.btn-primary:disabled { opacity: .55; cursor: wait; translate: 0 0; }

/* ---------------- 生成の進捗と結果 ---------------- */

.progress {
  width: 100%;
  height: 16px;
  border: 2.5px solid var(--ink);
  border-radius: 999px;
  background: #fff;
  overflow: hidden;
}

.progress-bar {
  height: 100%;
  width: 0%;
  background: repeating-linear-gradient(-45deg, var(--yellow) 0 8px, #ffd873 8px 16px);
  transition: width .12s linear;
}

.hidden { display: none !important; }

/* ---------------- 入力まわり ---------------- */

.text-input {
  width: 100%;
  font-family: var(--font-body);
  font-weight: 700;
  font-size: 22px;
  color: var(--ink);
  background: #fff;
  border: var(--border);
  border-radius: 14px;
  padding: 10px 16px;
  outline: none;
}
.text-input:focus { box-shadow: 0 0 0 4px rgba(255, 197, 49, .55); }

.hint {
  margin: 8px 2px 0;
  font-size: 12px;
  color: var(--ink-soft);
}

.field { display: block; margin-top: 14px; flex: 1; min-width: 0; }
.field:first-child { margin-top: 0; }

.field-label {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  font-size: 13px;
  font-weight: 700;
  margin-bottom: 6px;
}

.field-label output { font-weight: 500; font-size: 12px; color: var(--ink-soft); }

.field-row {
  display: flex;
  gap: 18px;
  align-items: end;
  margin-top: 14px;
  flex-wrap: wrap;
}

.color-row { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }

input[type="color"] {
  appearance: none;
  -webkit-appearance: none;
  width: 44px;
  height: 36px;
  padding: 2px;
  background: #fff;
  border: 2.5px solid var(--ink);
  border-radius: 10px;
  cursor: pointer;
  flex: none;
}
input[type="color"]::-webkit-color-swatch-wrapper { padding: 2px; }
input[type="color"]::-webkit-color-swatch { border: none; border-radius: 6px; }
input[type="color"]:disabled { opacity: .35; cursor: not-allowed; }

/* スウォッチ */
.swatches { display: flex; gap: 6px; flex-wrap: wrap; }

.swatch {
  width: 24px;
  height: 24px;
  border: 2px solid var(--ink);
  border-radius: 50%;
  cursor: pointer;
  padding: 0;
  transition: translate .08s ease;
}
.swatch:hover { translate: 0 -2px; }

/* スライダー */
input[type="range"] {
  appearance: none;
  -webkit-appearance: none;
  width: 100%;
  min-width: 120px;
  height: 10px;
  background: #fff;
  border: 2px solid var(--ink);
  border-radius: 999px;
  outline: none;
  cursor: pointer;
}
input[type="range"]::-webkit-slider-thumb {
  appearance: none;
  -webkit-appearance: none;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  background: var(--yellow);
  border: 2.5px solid var(--ink);
  box-shadow: 1px 2px 0 rgba(51, 48, 43, .3);
}
input[type="range"]::-moz-range-thumb {
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: var(--yellow);
  border: 2.5px solid var(--ink);
}

/* チェックボックス */
.check {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
  font-weight: 700;
  cursor: pointer;
  padding-bottom: 4px;
}
.check input {
  appearance: none;
  -webkit-appearance: none;
  width: 22px;
  height: 22px;
  border: 2.5px solid var(--ink);
  border-radius: 7px;
  background: #fff;
  cursor: pointer;
  display: grid;
  place-items: center;
  flex: none;
}
.check input:checked { background: var(--mint); }
.check input:checked::after {
  content: "✓";
  color: #fff;
  font-size: 14px;
  font-weight: 900;
  line-height: 1;
}

/* 1文字ずつ色をかえる */
.fill-per {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 10px;
}

.char-colors { display: flex; flex-wrap: wrap; gap: 8px; }

.char-color-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 3px;
  cursor: pointer;
}

.cc-char {
  font-weight: 900;
  font-size: 20px;
  line-height: 1;
  text-shadow:
    1px 0 0 rgba(51, 48, 43, .18), -1px 0 0 rgba(51, 48, 43, .18),
    0 1px 0 rgba(51, 48, 43, .18), 0 -1px 0 rgba(51, 48, 43, .18);
}

.char-color-item input[type="color"] { width: 34px; height: 28px; }

.mini-btn {
  font-family: var(--font-body);
  font-weight: 700;
  font-size: 12px;
  color: var(--ink);
  background: #fff;
  border: 2.5px solid var(--ink);
  border-radius: 999px;
  padding: 6px 14px 4px;
  cursor: pointer;
  box-shadow: 2px 3px 0 rgba(51, 48, 43, .2);
  transition: translate .08s ease;
}
.mini-btn:hover { translate: 0 -2px; }
.mini-btn:active { translate: 0 1px; box-shadow: 1px 1px 0 rgba(51, 48, 43, .2); }

/* セグメント切替 */
.segmented {
  display: inline-flex;
  border: 2.5px solid var(--ink);
  border-radius: 999px;
  background: #fff;
  overflow: hidden;
}
.segmented button {
  font-family: var(--font-body);
  font-weight: 700;
  font-size: 13px;
  color: var(--ink);
  background: transparent;
  border: none;
  padding: 8px 16px 6px;
  cursor: pointer;
  border-right: 2px solid rgba(51, 48, 43, .18);
}
.segmented button:last-child { border-right: none; }
.segmented button.on {
  background: var(--yellow);
  box-shadow: inset 2px 2px 0 rgba(51, 48, 43, .18);
}

.seg-mini { border-width: 2px; }
.seg-mini button { font-size: 11px; padding: 4px 10px 3px; }

/* ---------------- フォント選択 ---------------- */

.font-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(118px, 1fr));
  gap: 10px;
}

.font-chip {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  background: #fff;
  border: 2.5px solid var(--ink);
  border-radius: 14px;
  padding: 10px 6px 8px;
  cursor: pointer;
  transition: translate .08s ease, background .08s ease;
}
.font-chip:hover { translate: 0 -2px; }
.font-chip .sample { font-size: 30px; line-height: 1.15; }
.font-chip .fname { font-size: 10px; color: var(--ink-soft); text-align: center; }
.font-chip .fcat {
  font-size: 9px;
  color: #fff;
  background: var(--blue);
  border-radius: 999px;
  padding: 1px 8px;
  margin-top: 2px;
}
.font-chip[data-cat="手書き"] .fcat { background: var(--mint); }
.font-chip[data-cat="アクセント"] .fcat { background: var(--pink); }

.font-chip.on {
  background: #fff3c8;
  box-shadow: inset 0 0 0 2.5px var(--yellow), 2px 3px 0 rgba(51, 48, 43, .2);
}

/* ---------------- アニメ選択 ---------------- */

.anim-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(96px, 1fr));
  gap: 10px;
  margin-bottom: 6px;
}

.anim-chip {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  font-family: var(--font-body);
  font-weight: 700;
  font-size: 12px;
  color: var(--ink);
  background: #fff;
  border: 2.5px solid var(--ink);
  border-radius: 14px;
  padding: 9px 4px 7px;
  cursor: pointer;
  transition: translate .08s ease, background .08s ease;
}
.anim-chip:hover { translate: 0 -2px; }
.anim-chip .emoji { font-size: 20px; }
.anim-chip.on {
  background: #fff3c8;
  box-shadow: inset 0 0 0 2.5px var(--yellow), 2px 3px 0 rgba(51, 48, 43, .2);
}

/* ---------------- フッター ---------------- */

.site-foot {
  text-align: center;
  padding: 34px 16px 30px;
  font-size: 12px;
  color: var(--ink-soft);
}

/* ---------------- スマホ対応 ----------------
   このブロックはカスケードの都合上、上書きしたい各セレクタの
   基本定義より後ろに置く必要がある(同じ詳細度のため後勝ちになる)。 */
@media (max-width: 900px) {
  /* 1カラムレイアウトでは、プレビューを画面上部に貼り付けたままにすると
     スクロール時に下のカードへ覆いかぶさってしまうので追従させない */
  .preview-card { position: static; }
}

@media (max-width: 560px) {
  .site-head { padding: 32px 14px 6px; }
  .layout { padding: 0 12px; gap: 18px; margin-top: 18px; }
  .card { padding: 16px 16px 18px; border-radius: 18px; }

  /* はやさスライダーとサイズ切替を横並びにすると窮屈で右にはみ出すため縦積みに */
  .field-row { flex-direction: column; align-items: stretch; gap: 14px; }
  .field-row .field { min-width: 0; }
  #segSize, #segBg { width: 100%; }
  #segSize button, #segBg button { flex: 1; text-align: center; }

  .font-grid { grid-template-columns: repeat(auto-fill, minmax(96px, 1fr)); }
  .anim-grid { grid-template-columns: repeat(auto-fill, minmax(84px, 1fr)); }

  .btn-primary { width: 100%; }
}
