:root {
  --bg: #e9e4da;
  --fg: #1d1a17;
  --ink: #1d1a17;
  --sub: #5d564d;
  --paper: #faf8f3;
  --line: #ddd6c8;
  --font: "Zen Maru Gothic", "Hiragino Maru Gothic ProN", "Hiragino Sans", "Yu Gothic", "Meiryo", "Noto Sans CJK JP", "IPAGothic", sans-serif;
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--paper); color: var(--ink);
  font-family: var(--font); font-weight: 500; line-height: 1.6;
  overflow-wrap: anywhere;
}
main { max-width: 520px; margin: 0 auto; }
[hidden] { display: none !important; }

/* 今の時代（背景と絵文字）に、あなたの「第N人目」と役名 */
.hero {
  background: var(--bg); color: var(--fg);
  padding: 0 20px 28px; text-align: center;
  min-height: 62svh; display: flex; flex-direction: column; align-items: center; justify-content: center;
  transition: background-color .6s, color .6s;
}
.hero-friend, .hero-name, .hero-badge, .hero-note, .hero-next { word-break: auto-phrase; text-wrap: balance; }
.hero-friend { margin: 0 0 16px; max-width: 21em; font-size: 15px; font-weight: 700; line-height: 1.55; text-wrap: balance; }
.kicker { margin: 0; font-size: 17px; font-weight: 700; letter-spacing: .08em; }
.hero-sub { margin: 2px 0 0; font-size: 13px; opacity: .85; min-height: 1.6em; }
/* 世界の絵巻（ボクセルの箱庭）。文字は絵の下に置く */
.world {
  position: relative; align-self: stretch; margin: 0 -20px 18px; height: clamp(280px, 46svh, 540px);
  overflow: hidden; touch-action: pan-y; user-select: none; -webkit-user-select: none; cursor: grab;
  background: #cfe9f2;
}
.world:active { cursor: grabbing; }
.w-canvas { position: absolute; inset: 0; width: 100%; height: 100%; display: block; }
.w-floor { position: absolute; inset: 0; pointer-events: none; background: var(--bg); transition: background-color .6s; clip-path: polygon(0 var(--fl, 100%), 100% var(--fr, 100%), 100% 100%, 0 100%); }
.w-fog {
  position: absolute; left: 0; top: 0; bottom: 0; width: 1400px; pointer-events: none; will-change: transform;
  background: linear-gradient(to right, rgba(250,248,243,0), rgba(250,248,243,.94) 40px, #faf8f3 64px);
}
.w-sketch { position: absolute; left: 36px; top: 0; height: 100%; width: 300px; }
.w-nobody { position: absolute; left: 52px; top: 9%; margin: 0; padding: 4px 11px; text-align: left; font-size: 13px; font-weight: 700; line-height: 1.5; color: #7d7667; background: rgba(250,248,243,.9); border-radius: 12px; }
.w-mark {
  position: absolute; left: 0; top: 0; pointer-events: none; white-space: nowrap; margin-top: -7px;
  background: #fffdf7; color: #1d1a17; border: 1.5px solid #1d1a17; border-radius: 999px;
  font-size: 12px; font-weight: 900; line-height: 1.3; padding: 1px 9px;
}
.w-mark::after { content: ""; position: absolute; left: 50%; top: 100%; margin-left: -5px; border: 5px solid transparent; border-top-color: #1d1a17; }
.w-label {
  position: absolute; left: 10px; top: 10px; max-width: calc(100% - 20px); pointer-events: none;
  background: #fffdf7; color: #1d1a17; border-radius: 999px; font-size: 12px; font-weight: 700; line-height: 1.4; padding: 3px 12px;
}
.w-back {
  position: absolute; right: 10px; bottom: 10px; border: 0; border-radius: 999px; cursor: pointer;
  background: #1d1a17; color: #fff; font: inherit; font-size: 13px; font-weight: 700; line-height: 1.4; padding: 7px 14px;
}
.hero-nth { margin: 4px 0 0; font-size: clamp(26px, 8vw, 34px); font-weight: 900; line-height: 1.2; }
.hero-nth b { display: inline-block; font-size: clamp(48px, 16vw, 72px); font-weight: 900; line-height: 1.05; margin: 0 .06em; font-variant-numeric: tabular-nums; }
.hero-nth b.pop { animation: pop .5s cubic-bezier(.2, .9, .3, 1.3) both; }
@keyframes pop { 0% { transform: scale(1); } 40% { transform: scale(1.35); } 100% { transform: scale(1); } }
.hero-name { margin: 6px 0 0; max-width: 16em; font-size: clamp(30px, 9.5vw, 46px); font-weight: 900; line-height: 1.2; text-wrap: balance; }
.hero-name.is-role { font-size: clamp(23px, 7vw, 30px); line-height: 1.3; }
.hero-badge { margin: 12px 0 0; max-width: 20em; font-size: 17px; font-weight: 900; line-height: 1.4; text-wrap: balance; }
.hero-note { margin: 8px 0 0; font-size: 14px; font-weight: 700; line-height: 1.5; }
.hero-note.fade { animation: fadein .5s ease both; }
@keyframes fadein { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }
.pre { visibility: hidden; }
.hero-count { margin: 16px 0 0; font-size: 14px; opacity: .85; }
.hero-count b { font-size: 20px; font-weight: 900; }
.hero-next { margin: 2px 0 0; font-size: 15px; font-weight: 700; }

/* 自分の役 */
.me { padding: 36px 20px 8px; }
.me-n { margin: 0 0 16px; font-size: 15px; color: var(--sub); text-align: center; }
.card-wrap { max-width: 400px; margin: 0 auto; }
#card { display: block; width: 100%; height: auto; aspect-ratio: 1080 / 1350; }
.name-field { display: block; max-width: 400px; margin: 24px auto 0; }
.name-field span { display: block; font-size: 13px; color: var(--sub); margin-bottom: 6px; }
.name-field input {
  width: 100%; height: 48px; padding: 0 14px; font: inherit; font-size: 16px; color: var(--ink);
  background: #fff; border: 1px solid var(--line); border-radius: 12px;
}
.name-field input:focus { outline: 2px solid var(--ink); outline-offset: 1px; }
.actions { max-width: 400px; margin: 16px auto 0; display: grid; gap: 10px; }
.btn {
  display: flex; align-items: center; justify-content: center; height: 52px; padding: 0 16px;
  font: inherit; font-size: 16px; font-weight: 700; color: var(--ink); text-decoration: none;
  background: #ece6d9; border: 0; border-radius: 14px; cursor: pointer;
}
.btn.primary { background: var(--ink); color: #fff; }
.btn:active { opacity: .8; }
/* 画像を保存: X のアプリ内ブラウザ（Chrome の簡易タブを含む）ではダウンロードが止められるので、画像を出して長押しでも保存できるようにする */
.saveview { position: fixed; inset: 0; z-index: 30; background: rgba(29,26,23,.82); display: flex; align-items: center; justify-content: center; padding: 20px; }
.saveview-inner { width: 100%; max-width: 400px; display: grid; gap: 12px; text-align: center; }
.saveview-hint { margin: 0; color: #fff; font-size: 15px; font-weight: 700; }
.saveview-img { width: 100%; height: auto; border-radius: 12px; -webkit-touch-callout: default; user-select: auto; }
.dock {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 5;
  padding: 10px 20px calc(10px + env(safe-area-inset-bottom)); background: var(--paper); border-top: 1px solid var(--line);
}
.dock .btn { max-width: 400px; margin: 0 auto; }
body.has-dock { padding-bottom: calc(84px + env(safe-area-inset-bottom)); }
body.has-dock .hero { min-height: calc(100svh - 84px - env(safe-area-inset-bottom)); justify-content: flex-start; } /* 最初の画面は、文字パネルが下のボタンまで続く */
.notice { max-width: 400px; margin: 12px auto 0; font-size: 13px; color: var(--sub); text-align: center; }

/* 年表 */
.timeline-wrap { padding: 40px 20px 56px; }
.timeline-wrap h2 { margin: 0 0 12px; font-size: 18px; font-weight: 900; }
.timeline { list-style: none; margin: 0; padding: 0; }
.timeline li {
  display: grid; grid-template-columns: 32px 1fr auto; align-items: center; column-gap: 10px;
  min-height: 40px; padding: 4px 12px; border-radius: 10px; font-size: 15px;
}
.timeline .t-emoji { font-size: 20px; text-align: center; font-family: "Noto Color Emoji", "Apple Color Emoji", "Segoe UI Emoji", sans-serif; }
.timeline .t-at { font-size: 12px; opacity: .8; font-variant-numeric: tabular-nums; }
.timeline li.past { color: var(--sub); }
.timeline li.dots { color: #9a9286; }
.timeline li.future { color: #9a9286; }
.timeline li.now { font-weight: 900; padding-top: 10px; padding-bottom: 10px; margin: 4px 0; }
.foot { margin: 20px 0 0; font-size: 12px; color: var(--sub); }

/* 時代が変わる演出 */
.flash {
  position: fixed; inset: 0; z-index: 10; display: none; align-items: center; justify-content: center;
  text-align: center; pointer-events: none; background: var(--flash-bg, #000); color: var(--flash-fg, #fff);
}
.flash.show { display: flex; animation: flashbg 1.5s ease both; }
.flash-inner { padding: 0 20px; animation: flashin 1.5s cubic-bezier(.2,.8,.2,1) both; }
.flash-kicker { margin: 0; font-size: 14px; letter-spacing: .3em; }
.flash-emoji { font-size: clamp(120px, 42vw, 200px); line-height: 1.2; font-family: "Noto Color Emoji", "Apple Color Emoji", "Segoe UI Emoji", sans-serif; }
.flash-name { margin: 0; font-size: clamp(34px, 11vw, 56px); font-weight: 900; line-height: 1.2; }
@keyframes flashbg { 0% { opacity: 0; } 15% { opacity: 1; } 80% { opacity: 1; } 100% { opacity: 0; } }
@keyframes flashin { 0% { transform: scale(.7); } 30% { transform: scale(1.05); } 45% { transform: scale(1); } 100% { transform: scale(1); } }

@media (prefers-reduced-motion: reduce) {
  .flash-inner { animation: none; }
  .hero-nth b.pop, .hero-note.fade { animation: none; }
}
@media (max-height: 600px) {
  .hero { min-height: 0; padding-bottom: 24px; }
  .hero-friend { margin-bottom: 10px; font-size: 14px; }
  .hero-count { margin-top: 10px; }
}
@media (max-width: 360px) { .w-nobody { font-size: 12px; padding: 3px 9px; } }

/* 時代を始めた人: 「第一号」の判子と紙吹雪（全面カードのあと） */
.founder { position: fixed; inset: 0; z-index: 25; display: flex; align-items: center; justify-content: center; overflow: hidden; background: var(--fd-bg, #4aa3e0); color: var(--fd-fg, #1d1a17); animation: fadein .25s ease both; cursor: pointer; }
.founder-inner { position: relative; text-align: center; padding: 0 24px; }
.founder-stamp { display: inline-block; margin: 0 0 18px; padding: 10px 26px; font-size: clamp(48px, 16vw, 76px); font-weight: 900; line-height: 1.1; color: #c9302c; border: 6px solid #c9302c; border-radius: 14px; background: rgba(255,253,247,.92); transform: rotate(-8deg); animation: stamp .45s cubic-bezier(.2,.9,.3,1.4) .15s both; }
.founder-kicker { margin: 0; font-size: 17px; font-weight: 700; animation: fadein .3s ease .5s both; }
.founder-name { margin: 6px 0 0; font-size: clamp(28px, 9vw, 40px); font-weight: 900; line-height: 1.25; word-break: auto-phrase; text-wrap: balance; animation: fadein .3s ease .6s both; }
.founder-tap { margin: 22px 0 0; font-size: 12px; opacity: .7; animation: fadein .3s ease 1.2s both; }
.founder-confetti { position: absolute; inset: 0; pointer-events: none; }
.founder-confetti i { position: absolute; top: -20px; width: 12px; height: 12px; animation: confetti 2.2s ease-in both; }
@keyframes stamp { from { opacity: 0; transform: rotate(-8deg) scale(2.6); } to { opacity: 1; transform: rotate(-8deg) scale(1); } }
@keyframes confetti { from { transform: translate(0, 0) rotate(0); opacity: 1; } to { transform: translate(var(--dx, 0), 110vh) rotate(540deg); opacity: .9; } }
@media (prefers-reduced-motion: reduce) { .founder, .founder-stamp, .founder-kicker, .founder-name, .founder-tap { animation: none; } .founder-confetti { display: none; } }

/* 年表に名前を残す欄 */
.founder-box { max-width: 400px; margin: 20px auto 0; padding: 16px; border: 3px solid #e9b93a; border-radius: 16px; background: #fff8e1; text-align: left; }
.founder-box-title { margin: 0; font-size: 16px; font-weight: 900; }
.founder-box-sub { margin: 4px 0 10px; font-size: 13px; opacity: .8; }
.founder-row { display: flex; gap: 8px; }
.founder-row input { flex: 1; min-width: 0; height: 48px; padding: 0 12px; font: inherit; font-size: 16px; border: 1px solid var(--line); border-radius: 12px; background: #fff; }
.founder-row .btn { height: 48px; flex: none; }
.founder-msg { margin: 8px 0 0; font-size: 13px; min-height: 1.4em; }
.timeline .t-founder { display: block; font-size: 11px; font-weight: 700; opacity: .8; }

/* 1日1回、人類を進めるボタン（時代の色の上に置く） */
.btn.push { width: 100%; max-width: 360px; margin: 16px auto 0; background: var(--fg); color: var(--bg); }
.push-done { margin: 12px 0 0; font-size: 13px; opacity: .8; }

/* 作った人の紹介（カードの下）。押すと X のプロフィール */
.maker { display: flex; align-items: center; gap: 12px; max-width: 400px; margin: 24px auto 0; padding: 14px; border: 1px solid var(--line); border-radius: 16px; background: #fff; color: var(--ink); text-decoration: none; text-align: left; }
.maker-icon { flex: none; width: 56px; height: 56px; border-radius: 50%; background: #dceefa; display: flex; align-items: center; justify-content: center; font-size: 30px; overflow: hidden; font-family: "Noto Color Emoji", "Apple Color Emoji", "Segoe UI Emoji", sans-serif; }
.maker-icon img { width: 100%; height: 100%; object-fit: cover; }
.maker-text { flex: 1; min-width: 0; display: grid; gap: 2px; }
.maker-text small { font-size: 11px; color: var(--sub); }
.maker-text b { font-size: 14px; font-weight: 900; line-height: 1.35; }
.maker-text span { font-size: 11px; color: var(--sub); line-height: 1.4; word-break: auto-phrase; text-wrap: balance; }
.maker-follow { flex: none; padding: 8px 14px; border-radius: 999px; background: var(--ink); color: #fff; font-size: 13px; font-weight: 700; }
