:root {
  --bg: #fdf6ee;
  --dot: #f6e4d6;
  --card: #ffffff;
  --ink: #5b403a;
  --sub: #9a857b;
  --accent: #ef8a8a;
  --accent-ink: #ffffff;
  --line: #f1e1d4;
  --soft: #fff3ea;
  --c1: #f3a3a3; --c2: #f6c26b; --c3: #8fcfb4; --c4: #8db8e8; --c5: #c3a6e6;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #262331; --dot: #312d40; --card: #2f2b3c; --ink: #f4ece2; --sub: #b7aab8;
    --accent: #f59b9b; --accent-ink: #2b2230; --line: #433d52; --soft: #383348;
  }
}
:root[data-theme="dark"] {
  --bg: #262331; --dot: #312d40; --card: #2f2b3c; --ink: #f4ece2; --sub: #b7aab8;
  --accent: #f59b9b; --accent-ink: #2b2230; --line: #433d52; --soft: #383348;
}

* { box-sizing: border-box; }
body {
  margin: 0; color: var(--ink);
  background-color: var(--bg);
  background-image: radial-gradient(var(--dot) 2.5px, transparent 2.6px);
  background-size: 26px 26px;
  font-family: "Zen Maru Gothic", "Hiragino Maru Gothic ProN", "Yu Gothic", sans-serif;
  font-weight: 500; line-height: 1.75; -webkit-text-size-adjust: 100%;
}
button, select, input { font: inherit; color: inherit; }
a { color: var(--accent); font-weight: 700; }
strong { font-weight: 700; }

/* ---------- 見出し ---------- */
.hero { position: relative; max-width: 720px; margin: 0 auto; padding: 44px 16px 6px; text-align: center; }
.title { font-size: clamp(30px, 8.5vw, 46px); margin: 0 0 6px; font-weight: 700; letter-spacing: .02em; }
.title span { display: inline-block; animation: bob 3.2s ease-in-out infinite; }
.title span:nth-child(5n+1) { color: var(--c1); }
.title span:nth-child(5n+2) { color: var(--c2); animation-delay: .2s; }
.title span:nth-child(5n+3) { color: var(--c3); animation-delay: .4s; }
.title span:nth-child(5n+4) { color: var(--c4); animation-delay: .6s; }
.title span:nth-child(5n+5) { color: var(--c5); animation-delay: .8s; }
.title span:nth-child(odd) { transform: rotate(-4deg); }
.title span:nth-child(even) { transform: rotate(4deg); }
@keyframes bob { 0%, 100% { translate: 0 0; } 50% { translate: 0 -4px; } }
@media (prefers-reduced-motion: reduce) { .title span { animation: none; } }
.hero p { margin: 4px 0; }
.sp { display: none; }
@media (max-width: 480px) { .sp { display: inline; } }
.safe { display: inline-block; margin-top: 14px !important; font-size: 13px; background: var(--card); border: 2px dashed var(--line); border-radius: 16px; padding: 8px 14px; }
.safe::before { content: "🔒 "; }

.sparkle i { position: absolute; width: 14px; height: 14px; border-radius: 50%; opacity: .8; }
.sparkle i:nth-child(1) { background: var(--c1); top: 26px; left: 8%; }
.sparkle i:nth-child(2) { background: var(--c2); top: 70px; left: 2%; width: 9px; height: 9px; }
.sparkle i:nth-child(3) { background: var(--c3); top: 20px; right: 10%; width: 10px; height: 10px; }
.sparkle i:nth-child(4) { background: var(--c4); top: 78px; right: 3%; }
.sparkle i:nth-child(5) { background: var(--c5); top: 120px; left: 12%; width: 7px; height: 7px; }
.sparkle i:nth-child(6) { background: var(--c2); top: 124px; right: 14%; width: 8px; height: 8px; }

/* ---------- カード ---------- */
main { max-width: 720px; margin: 0 auto; padding: 8px 16px 24px; }
.card { background: var(--card); border: 2px solid var(--line); border-radius: 28px; padding: 22px 18px 26px; margin: 20px 0; box-shadow: 0 6px 0 var(--line); }
h2 { margin: 0 0 14px; font-size: 21px; display: flex; align-items: center; gap: 10px; font-weight: 700; }
h3 { font-size: 16px; margin: 26px 0 8px; font-weight: 700; }
h3 small { color: var(--sub); font-weight: 500; font-size: 13px; }
.num { display: inline-grid; place-items: center; width: 36px; height: 36px; border-radius: 50%; background: var(--c1); color: #fff; font-size: 18px; transform: rotate(-6deg); }
section:nth-of-type(2) .num { background: var(--c4); transform: rotate(6deg); }
.hint { color: var(--sub); font-size: 14px; margin: 8px 0; }
.status { font-size: 14px; min-height: 1.5em; }

.tabs { display: flex; gap: 6px; background: var(--soft); padding: 5px; border-radius: 999px; margin-bottom: 14px; }
.tabs button { flex: 1; border: 0; background: transparent; padding: 9px 6px; border-radius: 999px; cursor: pointer; font-size: 14px; }
.tabs button[aria-selected="true"] { background: var(--card); box-shadow: 0 2px 0 var(--line); font-weight: 700; }

.steps { padding-left: 1.4em; margin: 0; }
.steps li { margin: 6px 0; }
.steps li::marker { color: var(--accent); font-weight: 700; }
.file { display: inline-block; margin: 6px 0 0 4px; padding: 8px 18px; border-radius: 999px; background: var(--c3); color: #fff; cursor: pointer; font-size: 14px; font-weight: 700; box-shadow: 0 3px 0 rgba(0,0,0,.08); }
.file input { display: none; }

button { cursor: pointer; border: 2px solid var(--line); background: var(--card); border-radius: 999px; padding: 8px 16px; transition: transform .1s; }
button:active { transform: translateY(2px); }
button.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); font-weight: 700; box-shadow: 0 4px 0 color-mix(in srgb, var(--accent) 70%, #000 30%); }
button.big { display: block; width: 100%; padding: 14px; font-size: 18px; margin-top: 16px; }
button.big::before { content: "⬇ "; }
button.ghost { border: 0; background: none; color: var(--sub); text-decoration: underline; padding: 4px 0; font-size: 13px; box-shadow: none; }
.row { display: flex; gap: 8px; justify-content: center; margin-top: 12px; }

#adjust canvas { display: block; width: 100%; height: auto; touch-action: none; border-radius: 16px; background: #000; margin: 6px 0 12px; }
#adjust .primary { width: 100%; padding: 12px; }

.pad-head { display: flex; align-items: center; justify-content: space-between; color: var(--sub); font-size: 14px; }
.pad-char { font-size: 18px; color: var(--ink); font-weight: 700; }
.pad-box { position: relative; width: min(100%, 340px); aspect-ratio: 1; margin: 6px auto 0; }
.pad-box canvas { position: absolute; inset: 0; width: 100%; height: 100%; touch-action: none; background: #fff; border-radius: 24px; border: 3px dashed var(--c2); }

.glyph-grid { display: grid; grid-template-columns: repeat(5, 1fr); gap: 8px; }
.glyph { position: relative; aspect-ratio: 1; border: 2px solid var(--line); border-radius: 18px; background: #fff; padding: 0; overflow: hidden; }
.glyph:nth-child(5n+1) { border-color: var(--c1); }
.glyph:nth-child(5n+2) { border-color: var(--c2); }
.glyph:nth-child(5n+3) { border-color: var(--c3); }
.glyph:nth-child(5n+4) { border-color: var(--c4); }
.glyph:nth-child(5n+5) { border-color: var(--c5); }
.glyph canvas { width: 100%; height: 100%; display: block; }
.glyph span { position: absolute; left: 7px; top: 2px; font-size: 11px; color: #b5a89f; }
.glyph.empty::after { content: "まだ"; position: absolute; inset: 0; display: grid; place-items: center; color: #cbbfb6; font-size: 12px; }

.controls { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 10px 16px; }
.controls label { display: flex; flex-direction: column; font-size: 13px; color: var(--sub); gap: 4px; }
.controls label:first-child { grid-column: 1 / -1; }
.controls label.check { flex-direction: row; align-items: center; color: var(--ink); font-size: 14px; }
.controls select { padding: 8px 12px; border-radius: 14px; border: 2px solid var(--line); background: var(--card); font-size: 15px; }
.ym { display: flex; gap: 6px; align-items: center; }
.ym select { flex: 1; min-width: 0; }
.ym button { padding: 6px 13px; }

.themes { display: flex; flex-wrap: wrap; gap: 8px; margin: 16px 0; }
.themes button { display: flex; align-items: center; gap: 6px; font-size: 14px; padding: 5px 12px 5px 6px; }
.themes button i { width: 24px; height: 24px; border-radius: 50%; border: 4px solid; display: inline-block; }
.themes button[aria-pressed="true"] { border-color: var(--accent); font-weight: 700; background: var(--soft); }

.preview { background: var(--soft); border-radius: 22px; padding: 16px; text-align: center; min-height: 80px; }
.preview img:not([src]) { display: none; }
.preview:has(img:not([src]))::before { content: "つくっています…"; color: var(--sub); font-size: 14px; }
.preview img { max-width: 100%; max-height: 70vh; box-shadow: 0 6px 20px rgba(90,60,40,.18); border-radius: 10px; }

footer { max-width: 720px; margin: 0 auto; padding: 0 16px 40px; font-size: 12px; color: var(--sub); }

/* ---------- 白い紙の書き方の例・よみとり結果 ---------- */
.example { display: flex; width: fit-content; flex-direction: column; gap: 2px; margin: 8px 0 2px; padding: 10px 18px; background: #fff; color: #222; border-radius: 6px; box-shadow: 0 2px 8px rgba(0,0,0,.08); font-size: 22px; font-weight: 700; letter-spacing: .3em; line-height: 1.3; transform: rotate(-1.5deg); }
#found { margin-top: 10px; }
.found-grid { display: grid; grid-template-columns: repeat(5, 1fr); gap: 8px; margin: 8px 0 14px; }
.found { display: flex; flex-direction: column; gap: 4px; }
.found canvas { width: 100%; aspect-ratio: 1; background: #fff; border-radius: 14px; border: 2px solid var(--line); }
.found select { width: 100%; padding: 4px 2px; border-radius: 10px; border: 2px solid var(--line); background: var(--card); font-size: 14px; text-align: center; }
#found-ok { width: 100%; padding: 12px; }

/* ---------- スライダー ---------- */
.controls input[type="range"] { width: 100%; accent-color: var(--accent); margin: 6px 0 0; }
.range-ends { display: flex; justify-content: space-between; font-size: 11px; }
