:root {
  --night: #0b1030;
  --night2: #1b1f5c;
  --ink: #f4f1ff;
  --muted: #b9b6e0;
  --gold: #ffd84d;
  --pink: #ff8fb1;
  --card: rgba(255, 255, 255, 0.08);
  --line: rgba(255, 255, 255, 0.18);
  color-scheme: dark;
}
* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  min-height: 100dvh;
  background: var(--night);
  color: var(--ink);
  font-family: "Hiragino Maru Gothic ProN", "M PLUS Rounded 1c", "Hiragino Sans", "Noto Sans JP", system-ui, sans-serif;
  line-height: 1.7;
  -webkit-tap-highlight-color: transparent;
}
.bg {
  position: fixed; inset: 0; z-index: -1;
  background:
    radial-gradient(1200px 600px at 80% -10%, #3b2b7a 0%, transparent 60%),
    radial-gradient(900px 500px at -10% 110%, #1d4a7a 0%, transparent 60%),
    linear-gradient(var(--night), var(--night2));
}
main { max-width: 560px; margin: 0 auto; padding: 16px 16px 8px; }
.view { animation: fade .4s ease; }
@keyframes fade { from { opacity: 0; transform: translateY(6px); } }
.logo { font-size: 2.2rem; margin: 24px 0 8px; letter-spacing: .08em; text-align: center; }
.logo span { color: var(--gold); }
.lead { text-align: center; color: var(--muted); margin: 0 0 16px; }
.power { text-align: center; margin: 8px 0 16px; color: var(--muted); }
.power strong { color: var(--gold); font-size: 1.6rem; margin: 0 4px; }
.actions { display: flex; gap: 12px; justify-content: center; flex-wrap: wrap; margin: 12px 0; }
.btn {
  appearance: none; border: 1px solid var(--line); background: var(--card); color: var(--ink);
  font: inherit; font-weight: 700; padding: 12px 20px; border-radius: 999px; cursor: pointer; min-height: 48px;
}
.btn:hover { background: rgba(255,255,255,.14); }
.btn:focus-visible, .back:focus-visible, textarea:focus-visible, input:focus-visible, .chip:focus-visible { outline: 3px solid var(--gold); outline-offset: 2px; }
.btn.primary { background: linear-gradient(135deg, var(--gold), #ffb44d); color: #2a1d00; border: none; }
.btn.primary:disabled { opacity: .45; cursor: not-allowed; }
.btn.ghost { background: transparent; border: none; color: var(--muted); display: block; margin: 0 auto; }
.btn.wide { width: 100%; }
.bar { display: flex; align-items: center; gap: 8px; }
.bar h2 { font-size: 1.25rem; margin: 8px 0; }
.back { background: none; border: none; color: var(--ink); font-size: 2rem; line-height: 1; padding: 0 8px; cursor: pointer; min-width: 44px; min-height: 44px; }
.hint { color: var(--muted); margin: 4px 0 10px; min-height: 1.7em; }
.hint b { color: var(--gold); }
.sky-wrap { width: min(100%, 52dvh); margin: 0 auto; border-radius: 20px; overflow: hidden; border: 1px solid var(--line); background: radial-gradient(circle at 50% 40%, #1a2262, #070a22 75%); }
.sky { display: block; width: 100%; height: auto; touch-action: manipulation; user-select: none; -webkit-user-select: none; cursor: pointer; }
/* なぞっている間だけ画面のスクロールを止める（それ以外は夜空の上でも指でスクロールできる） */
.sky.tracing { touch-action: none; }
.sky .dust { fill: #fff; opacity: .35; animation: tw 3s ease-in-out infinite alternate; }
@keyframes tw { to { opacity: .08; } }
.sky .star { transition: opacity .4s, transform .4s; transform-box: fill-box; transform-origin: center; }
.sky .star.dim { opacity: .35; }
.sky .star.next { animation: pulse 1.1s ease-in-out infinite; opacity: 1; }
@keyframes pulse { 50% { transform: scale(1.35); } }
.sky .num { fill: #fff; font-size: 26px; font-weight: 700; text-anchor: middle; pointer-events: none; opacity: .85; }
.sky .link { stroke: rgba(255, 240, 200, .85); stroke-width: 4; stroke-linecap: round; }
.sky .slot { fill: none; stroke: var(--gold); stroke-width: 4; stroke-dasharray: 10 10; animation: spin 6s linear infinite, pulse 1.1s ease-in-out infinite; transform-box: fill-box; transform-origin: center; }
@keyframes spin { to { stroke-dashoffset: -200; } }
.sky .born { animation: born 1s ease-out; transform-box: fill-box; transform-origin: center; }
@keyframes born { from { transform: scale(0); opacity: 0; } 60% { transform: scale(1.8); } }
.sky.done .link { animation: glow 1.4s ease-in-out infinite alternate; }
@keyframes glow { to { stroke: #fff; filter: drop-shadow(0 0 6px var(--gold)); } }
.colors { display: flex; gap: 12px; justify-content: center; margin: 12px 0; }
.chip { width: 40px; height: 40px; border-radius: 50%; border: 3px solid transparent; cursor: pointer; position: relative; }
.chip[aria-checked="true"] { border-color: #fff; box-shadow: 0 0 0 3px rgba(255,255,255,.25); }
.chip span { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }
.field { display: block; margin: 12px 0; color: var(--muted); font-size: .95rem; }
textarea, input {
  display: block; width: 100%; margin-top: 6px; font: inherit; font-size: 16px; color: var(--ink);
  background: rgba(0,0,0,.25); border: 1px solid var(--line); border-radius: 12px; padding: 10px 12px;
}
.result, .letter, .broken { margin-top: 16px; background: var(--card); border: 1px solid var(--line); border-radius: 20px; padding: 16px; animation: fade .6s ease; }
.letter { text-align: center; }
.letter .msg { font-size: 1.3rem; white-space: pre-wrap; word-break: break-word; margin: 8px 0; }
.letter .from { color: var(--muted); }
.letter .nth { color: var(--gold); font-weight: 700; margin: 0; }
.note { color: var(--muted); font-size: .9rem; text-align: center; }
.toast { color: var(--gold); text-align: center; min-height: 1.5em; margin: 0; }
.foot { text-align: center; color: var(--muted); font-size: .8rem; padding: 16px; }
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}
[hidden] { display: none !important; }
.sky .num { stroke: #070a22; stroke-width: 6px; paint-order: stroke; }
.note.caution { text-align: left; margin: -4px 0 0; }
.lock { background: var(--card); border: 1px solid var(--line); border-radius: 16px; padding: 10px 14px; margin: 12px 0; }
.switch { display: flex; gap: 8px; align-items: center; cursor: pointer; }
.switch input { width: 22px; height: 22px; margin: 0; display: inline-block; flex: none; }
.switch b { display: block; }
.switch small { display: block; color: var(--muted); font-size: .8rem; }
::placeholder { color: #8f8cc0; opacity: 1; }
.note.warn { color: #ffb4a8; text-align: left; min-height: 0; margin: 0; }
.unlock-hint, .note.warn { overflow-wrap: anywhere; }
.toast.error { color: #ffb4a8; }
input[aria-invalid="true"] { border-color: #ffb4a8; }
.unlock { margin-top: 16px; background: var(--card); border: 1px solid var(--line); border-radius: 20px; padding: 16px; text-align: center; }
.foot a { color: var(--muted); }
.doc h1 { font-size: 1.5rem; margin: 8px 0 16px; }
.doc h2 { font-size: 1.1rem; color: var(--gold); margin: 24px 0 4px; }
.doc p, .doc li { color: var(--ink); }
.doc a { color: var(--gold); }

/* ---------- v3: わかりやすい動線 ---------- */
.catch { text-align: center; color: var(--gold); font-weight: 700; margin: 0 0 4px; }
.btn.big { display: block; margin: 16px auto; font-size: 1.15rem; padding: 16px 32px; min-height: 56px; box-shadow: 0 6px 24px rgba(255, 200, 80, .25); }
.btn.link { background: none; border: none; color: var(--muted); text-decoration: underline; text-underline-offset: 4px; font-weight: 400; padding: 8px 12px; }
.btn.small { min-height: 36px; padding: 4px 14px; font-size: .85rem; }
.btn.off { opacity: .5; }
.links { display: flex; flex-wrap: wrap; justify-content: center; gap: 4px 12px; margin: 4px 0; }
.steps { list-style: none; padding: 0; margin: 20px 0 8px; display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.steps li { background: var(--card); border: 1px solid var(--line); border-radius: 16px; padding: 10px 6px; text-align: center; display: flex; flex-direction: column; align-items: center; }
.steps .step-ico { font-size: 1.6rem; line-height: 1.2; }
.steps b { display: block; }
.steps small { color: var(--muted); font-size: .75rem; line-height: 1.4; }
.relay-card { background: linear-gradient(135deg, rgba(255, 216, 77, .16), rgba(255, 143, 177, .16)); border: 1px solid rgba(255, 216, 77, .5); border-radius: 16px; padding: 12px 14px; margin: 12px 0; text-align: center; }
.relay-card p { margin: 0 0 8px; }
.step-title { display: flex; gap: 8px; align-items: center; font-size: 1rem; margin: 16px 0 8px; font-weight: 700; }
.step-title > span { flex: none; width: 26px; height: 26px; border-radius: 50%; background: var(--gold); color: #2a1d00; display: grid; place-items: center; font-weight: 800; }
.step-title em { font-style: normal; }
.pick-label { margin: 12px 0 6px; }
.pic-slots { display: flex; align-items: center; gap: 8px; justify-content: center; margin: 8px 0; min-height: 56px; flex-wrap: wrap; }
.slot-box { width: 52px; height: 52px; border-radius: 14px; background: rgba(255, 255, 255, .92); display: grid; place-items: center; border: 2px solid var(--gold); }
.slot-box.empty { background: transparent; border: 2px dashed var(--line); color: var(--muted); font-weight: 700; }
.pic-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(64px, 1fr)); gap: 6px; }
.pic { appearance: none; border: 2px solid transparent; background: rgba(255, 255, 255, .9); border-radius: 14px; padding: 4px 2px 2px; display: flex; flex-direction: column; align-items: center; cursor: pointer; font: inherit; color: #4a3550; min-height: 64px; }
.pic small { font-size: .62rem; line-height: 1.3; white-space: nowrap; }
.pic:active { transform: scale(.94); }
.pic:focus-visible { outline: 3px solid var(--gold); outline-offset: 2px; }
.pic-grid.full .pic { opacity: .45; }
.pic-art { display: block; line-height: 0; }
.share-preview { background: rgba(0, 0, 0, .25); border: 1px solid var(--line); border-radius: 12px; padding: 10px 12px; margin: 8px 0; text-align: left; user-select: text; -webkit-user-select: text; }
.share-preview p { margin: 0; }
.share-url { color: var(--gold); overflow-wrap: anywhere; margin-top: 4px !important; }
.result-title { font-size: 1.2rem; font-weight: 800; text-align: center; margin: 0; }
.envelope { margin: 24px 0; background: linear-gradient(160deg, rgba(255, 255, 255, .12), rgba(255, 255, 255, .04)); border: 1px solid var(--line); border-radius: 24px; padding: 24px 18px; text-align: center; animation: fade .6s ease; }
.env-art { font-size: 4rem; line-height: 1; animation: float 2.4s ease-in-out infinite alternate; }
@keyframes float { to { transform: translateY(-8px); } }
.env-from { font-size: 1.2rem; font-weight: 700; margin: 12px 0 0; overflow-wrap: anywhere; }
.env-title { font-size: 1.35rem; font-weight: 800; color: var(--gold); margin: 0 0 12px; }
.env-how { color: var(--ink); margin: 0 0 8px; }
.env-how b { color: var(--gold); }
.env-lock { color: var(--muted); font-size: .9rem; margin: 0; }
.about { margin-top: 12px; color: var(--muted); font-size: .9rem; text-align: left; }
.about summary { text-align: center; cursor: pointer; text-decoration: underline; text-underline-offset: 4px; }
.loading { text-align: center; color: var(--muted); margin: 48px 0; }
.big-hint { font-size: 1.05rem; min-height: 3.4em; margin-bottom: 4px; }
.progress { display: flex; gap: 6px; justify-content: center; margin: 0 0 8px; }
.progress span { width: 10px; height: 10px; border-radius: 50%; background: var(--line); }
.progress span.on { background: var(--gold); }
.tracing-wrap { width: min(100%, 60dvh); }
.sky .guide-line { stroke: rgba(255, 216, 77, .7); stroke-width: 4; stroke-dasharray: 4 14; stroke-linecap: round; animation: march 1s linear infinite; }
@keyframes march { to { stroke-dashoffset: -36; } }
.sky .ring { fill: none; stroke: rgba(255, 216, 77, .8); stroke-width: 4; animation: ring 1.4s ease-out infinite; transform-box: fill-box; transform-origin: center; }
@keyframes ring { from { transform: scale(.5); opacity: 1; } to { transform: scale(1.4); opacity: 0; } }
.sky .finger { animation: tap 1.4s ease-in-out infinite; pointer-events: none; }
@keyframes tap { 0%, 100% { transform: translate(0, 0); } 50% { transform: translate(-6px, -14px); } }
.sky .ring, .sky .slot { pointer-events: none; }
.unlock-title { font-weight: 700; }
.env-chain { color: var(--pink); font-size: .95rem; margin: 0 0 8px; }
.relay-why { color: var(--gold); margin: 12px 0 0; font-weight: 700; }
.pic small { font-size: .72rem; color: #3a2840; font-weight: 700; }
#unlock-btn:disabled { opacity: 1; background: rgba(255, 255, 255, .12); color: var(--muted); }
#unlock-msg { min-height: 0; margin: 4px 0; }

/* ---------- ありがとう星座 ---------- */
.step-sub { color: var(--muted); margin: -4px 0 8px; font-size: .9rem; }
.shapes { display: grid; grid-template-columns: repeat(7, 1fr); gap: 4px; margin: 0 0 10px; }
.shape { appearance: none; border: 2px solid var(--line); background: var(--card); color: var(--ink); border-radius: 12px; padding: 6px 0 2px; display: flex; flex-direction: column; align-items: center; gap: 2px; cursor: pointer; font: inherit; min-height: 56px; font-size: 1.1rem; line-height: 28px; }
.shape small { font-size: .62rem; line-height: 1.3; white-space: nowrap; }
.shape[aria-checked="true"] { border-color: var(--gold); background: rgba(255, 216, 77, .16); }
.shape:focus-visible { outline: 3px solid var(--gold); outline-offset: 2px; }
.shape-icon { fill: none; stroke: var(--gold); stroke-width: 70; stroke-linejoin: round; }
.sky .ghost-line { fill: none; stroke: rgba(255, 255, 255, .22); stroke-width: 4; stroke-dasharray: 6 14; stroke-linecap: round; }
.sky .ghost { fill: rgba(255, 255, 255, .12); stroke: rgba(255, 255, 255, .5); stroke-width: 3; stroke-dasharray: 6 6; }
.sky .ghost.next { stroke: var(--gold); animation: pulse 1.1s ease-in-out infinite; transform-box: fill-box; transform-origin: center; }
.sky .ghost-num { fill: rgba(255, 255, 255, .55); font-size: 24px; text-anchor: middle; pointer-events: none; }
.sky .link.close { stroke-dasharray: 2 12; }
.sky.formed .link { animation: glow 1.4s ease-in-out infinite alternate; }
.sky.formed .link.close { stroke-dasharray: none; }
.sky .word-pop { fill: #fff; font-size: 44px; font-weight: 800; text-anchor: middle; stroke: #070a22; stroke-width: 10px; paint-order: stroke; pointer-events: none; animation: wordpop 1.6s ease-out forwards; }
@keyframes wordpop { from { opacity: 0; transform: translateY(16px); } 15% { opacity: 1; transform: none; } 75% { opacity: 1; } to { opacity: 0; transform: translateY(-20px); } }
.sky-tools { display: flex; align-items: center; justify-content: center; gap: 12px; margin: 8px 0 0; min-height: 36px; }
.star-count { color: var(--gold); font-weight: 700; }
.word-fields { list-style: none; padding: 0; margin: 8px 0; display: grid; gap: 6px; }
.word-fields label { display: flex; align-items: center; gap: 8px; }
.word-fields input { margin: 0; }
.word-fields .note.empty { text-align: left; }
.wstar, .wnum { flex: none; font-weight: 800; min-width: 2.4em; }
.words { list-style: none; padding: 0; margin: 10px 0 0; display: grid; gap: 6px; }
.words li { background: var(--card); border: 1px solid var(--line); border-radius: 12px; padding: 6px 12px; display: flex; gap: 8px; align-items: baseline; font-size: 1.05rem; overflow-wrap: anywhere; }
.words li.pop { animation: fade .6s ease; }
.letter .cname { font-size: 1.5rem; font-weight: 800; color: var(--gold); margin: 0 0 4px; overflow-wrap: anywhere; }
.btn.link.inline { padding: 0 2px; min-height: 0; color: var(--gold); }
.book { list-style: none; padding: 0; margin: 8px 0; display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 10px; }
.book-card { background: var(--card); border: 1px solid var(--line); border-radius: 16px; padding: 8px; text-align: center; }
.mini-sky { display: block; width: 100%; height: auto; border-radius: 12px; background: radial-gradient(circle at 50% 40%, #1a2262, #070a22 75%); }
.mini-sky .link { stroke: rgba(255, 240, 200, .85); stroke-width: 10; stroke-linecap: round; }
.mini-sky .link.close { stroke-dasharray: none; }
.mini-sky .mine-link { stroke-dasharray: 14 18; }
.book-name { font-weight: 800; color: var(--gold); margin: 6px 0 0; overflow-wrap: anywhere; }
.book-meta { color: var(--muted); font-size: .8rem; margin: 0 0 4px; overflow-wrap: anywhere; }
.book-acts { display: flex; flex-direction: column; align-items: center; gap: 2px; }
a.btn { display: inline-flex; align-items: center; text-decoration: none; }
@media (max-width: 400px) { .shapes { grid-template-columns: repeat(4, 1fr); } }

/* ---------- 便箋の柄（きゅーぶると同じデザインセット。id は papers.js と同じ） ---------- */
.papers-box { margin: 4px 0 8px; text-align: center; }
.papers-label { color: var(--muted); font-size: .9rem; margin: 0 0 4px; }
.papers { display: flex; gap: 8px; justify-content: center; flex-wrap: wrap; }
.paper-opt { appearance: none; border: 2px solid var(--line); background: var(--card); color: var(--ink); border-radius: 14px; padding: 6px 10px 4px; display: flex; flex-direction: column; align-items: center; gap: 4px; cursor: pointer; font: inherit; font-size: .8rem; min-height: 48px; min-width: 84px; }
.paper-opt[aria-checked="true"] { border-color: var(--gold); background: rgba(255, 216, 77, .16); }
.paper-opt:focus-visible, .paper-name:focus-visible { outline: 3px solid var(--gold); outline-offset: 2px; }
.paper-swatch { display: block; width: 56px; height: 28px; border-radius: 8px; border: 1px solid var(--line); background: radial-gradient(circle at 50% 40%, #1a2262, #070a22 75%); }
.paper-tag { margin-top: 16px; padding-top: 10px; border-top: 1px dashed var(--line); }
.paper-name { appearance: none; background: none; border: none; color: var(--muted); font: inherit; font-size: .85rem; cursor: pointer; text-decoration: underline; text-underline-offset: 4px; padding: 6px 8px; min-height: 36px; }
.paper-about { font-size: .9rem; color: var(--muted); }
.paper-about p { margin: 4px 0; }

/* ゆうぐれ（無料）：夕やけ色から夜へ。文字が読めるように、下のほうも暗めにしておく */
body.paper-yuugure .bg {
  background:
    radial-gradient(900px 420px at 50% 115%, rgba(255, 150, 120, .55) 0%, transparent 60%),
    radial-gradient(900px 500px at 85% -10%, #6b3f9a 0%, transparent 60%),
    linear-gradient(#22184f, #4a2a6a 70%, #6a3560);
}
body.paper-yuugure .sky-wrap, .paper-swatch.paper-yuugure {
  background: radial-gradient(120% 70% at 50% 110%, #ff9e7a 0%, #c0608f 30%, transparent 62%), linear-gradient(#1d1850, #3d2a72 55%, #6a3a7a);
}

/* 冬の星空（240円の予定）：深い青。雪の結晶は夜空の中だけ（文字の後ろはすっきりさせる） */
body.paper-fuyu .bg {
  background:
    url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='220' height='220'%3E%3Cg fill='%23ffffff'%3E%3Ccircle cx='110' cy='40' r='1.4'/%3E%3Ccircle cx='200' cy='60' r='1'/%3E%3Ccircle cx='80' cy='150' r='1.2'/%3E%3Ccircle cx='20' cy='190' r='1.5'/%3E%3Ccircle cx='140' cy='200' r='1'/%3E%3C/g%3E%3C/svg%3E") 0 0/220px 220px,
    radial-gradient(1000px 520px at 50% -10%, #2f5e9e 0%, transparent 60%),
    linear-gradient(#071a3a, #0e2f5c 70%, #16406e);
}
body.paper-fuyu .sky-wrap, .paper-swatch.paper-fuyu {
  background:
    url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='160' height='160'%3E%3Cg fill='none' stroke='%23e8f7ff' stroke-width='1.4' stroke-linecap='round' opacity='.4'%3E%3Cpath d='M30 20v20M21 25l18 10M21 35l18-10'/%3E%3Cpath d='M120 100v14M114 104l12 6M114 110l12-6'/%3E%3C/g%3E%3C/svg%3E") 0 0/160px 160px,
    radial-gradient(circle at 50% 30%, #1f4f8a, #06142e 78%);
}

.paper-price { font-size: .72rem; color: var(--gold); font-weight: 700; }
.buy { background: var(--card); border: 1px solid rgba(255, 216, 77, .5); border-radius: 16px; padding: 12px 14px; margin: 8px 0 12px; text-align: center; }
.buy p { margin: 4px 0; }
.buy .note.caution { margin: 6px 0; }
.buy-title { font-weight: 800; font-size: 1.1rem; color: var(--gold); }
.buy .switch { justify-content: center; margin: 8px 0; }
#paper-msg { min-height: 0; margin: 4px 0 0; }
