:root {
  --bg: #fff8ec;
  --paper: #ffffff;
  --ink: #3d3229;
  --muted: #8a7d70;
  --line: #efe4d2;
  --primary: #1fa396;
  --primary-dark: #15857a;
  --star: #ffc53d;
  --shadow: 0 4px 0 rgba(120, 90, 50, .12), 0 8px 24px rgba(120, 90, 50, .08);
  --radius: 22px;
  --safe-t: env(safe-area-inset-top, 0px);
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-l: env(safe-area-inset-left, 0px);
  --safe-r: env(safe-area-inset-right, 0px);
  color-scheme: light;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

/* ---- 画面をタッチで動かさない ---- */
html, body {
  position: fixed;
  top: 0; right: 0; bottom: 0; left: 0;
  margin: 0;
  overflow: hidden;
  overscroll-behavior: none;
  touch-action: none;
  -webkit-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
  -webkit-text-size-adjust: 100%;
}
body {
  background: var(--bg);
  color: var(--ink);
  font-family: 'Zen Maru Gothic', 'Hiragino Maru Gothic ProN', 'Hiragino Sans', sans-serif;
  font-weight: 700;
}
img { -webkit-user-drag: none; pointer-events: none; }
button { font: inherit; color: inherit; border: 0; background: none; padding: 0; cursor: pointer; touch-action: manipulation; }
.scroll { overflow-y: auto; overflow-x: hidden; overscroll-behavior: contain; touch-action: pan-y; -webkit-overflow-scrolling: touch; }
.scroll-x { overflow-x: auto; overflow-y: hidden; overscroll-behavior: contain; touch-action: pan-x; scrollbar-width: none; }
.scroll-x::-webkit-scrollbar { display: none; }

#app { position: fixed; top: 0; right: 0; bottom: 0; left: 0; }
[hidden] { display: none !important; }
.screen {
  position: absolute;
  top: 0; right: 0; bottom: 0; left: 0;
  padding: calc(var(--safe-t) + 14px) calc(var(--safe-r) + 20px) calc(var(--safe-b) + 14px) calc(var(--safe-l) + 20px);
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.stars { display: inline-flex; gap: 2px; font-size: 18px; line-height: 1; }
.stars i { font-style: normal; color: #e6dccb; }
.stars i.on { color: var(--star); text-shadow: 0 1px 0 #d9971a; }

.icon-btn {
  width: 56px; height: 56px; border-radius: 50%;
  background: var(--paper); box-shadow: var(--shadow);
  font-size: 30px; display: grid; place-items: center; flex: none;
}
.icon-btn:active, .chip:active, .big-btn:active, .tile:active, .tool:active, .cat:active { transform: translateY(3px) scale(.98); box-shadow: 0 1px 0 rgba(120,90,50,.12); }
.back { font-size: 44px; line-height: 1; padding-bottom: 6px; color: var(--primary); }

/* ---- ヘッダー ---- */
.topbar { display: flex; align-items: center; gap: 14px; flex: none; }
.logo { display: flex; align-items: center; gap: 10px; margin-right: auto; }
.logo b { font-size: 24px; display: block; font-weight: 900; letter-spacing: .02em; }
.logo small { color: var(--primary); font-size: 14px; }
.logo-a {
  width: 54px; height: 54px; border-radius: 16px; background: var(--primary); color: #fff;
  display: grid; place-items: center; font-size: 32px; font-weight: 900; box-shadow: 0 4px 0 var(--primary-dark);
}
.logo-a.sm { width: 46px; height: 46px; font-size: 26px; border-radius: 14px; }
.top-actions { display: flex; gap: 10px; align-items: center; }
.chip {
  height: 56px; padding: 0 18px; border-radius: 28px; background: var(--paper); box-shadow: var(--shadow);
  display: flex; align-items: center; gap: 8px; font-size: 18px; white-space: nowrap; flex: none;
}
.chip b { font-size: 22px; color: var(--primary); }
.chip b small { font-size: 13px; color: var(--muted); }
.chip-icon { font-size: 24px; }
.dots { display: flex; gap: 4px; }
.dots i { width: 16px; height: 16px; border-radius: 50%; background: #f0e6d6; }
.dots i.on { background: #ff8fb1; box-shadow: inset 0 -2px 0 rgba(0,0,0,.12); }
.parent-btn { font-size: 26px; color: var(--muted); position: relative; overflow: hidden; }
.parent-btn.holding::after {
  content: ''; position: absolute; top: 0; right: 0; bottom: 0; left: 0; border-radius: 50%;
  background: conic-gradient(rgba(31,163,150,.35) var(--p, 0%), transparent 0);
  animation: hold 1.5s linear forwards;
}
@property --p { syntax: '<percentage>'; inherits: false; initial-value: 0%; }
@keyframes hold { to { --p: 100%; } }

/* ---- カテゴリ ---- */
.cats { display: flex; gap: 10px; flex: none; padding: 4px 2px 10px; margin: 0 -20px; padding-left: 20px; padding-right: 20px; }
.cat {
  flex: none; display: flex; align-items: center; gap: 8px; height: 60px; padding: 0 16px 0 8px;
  border-radius: 30px; background: var(--paper); box-shadow: var(--shadow); font-size: 18px; white-space: nowrap;
}
.cat img { width: 44px; height: 44px; }
.cat small { font-size: 12px; color: var(--muted); }
.cat.active { background: var(--cat); color: #fff; box-shadow: 0 4px 0 color-mix(in srgb, var(--cat) 70%, #000); }
.cat.active small { color: rgba(255,255,255,.85); }

/* ---- カード一覧 ---- */
.grid-wrap { flex: 1; min-height: 0; margin: 0 -20px; padding: 0 20px 20px; }
.ask { font-size: 30px; margin: 4px 0 0; font-weight: 900; }
.sub { margin: 2px 0 14px; color: var(--muted); font-size: 16px; }
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(168px, 1fr)); gap: 16px; }
.grid.small { grid-template-columns: repeat(auto-fill, minmax(120px, 1fr)); gap: 12px; }
.tile {
  position: relative; background: var(--paper); border-radius: var(--radius); box-shadow: var(--shadow);
  padding: 12px 10px 12px; display: flex; flex-direction: column; align-items: center; gap: 4px;
  border-top: 6px solid var(--cat); overflow: hidden;
}
.tile-img { position: relative; width: 100%; aspect-ratio: 1.25; display: grid; place-items: center; }
.tile-img img { width: 78%; height: 100%; object-fit: contain; filter: drop-shadow(0 6px 6px rgba(0,0,0,.12)); }
.tile-word { font-size: 21px; letter-spacing: .04em; white-space: nowrap; }
.tile-word.long { font-size: 17px; letter-spacing: 0; }
.tile.small .tile-word.long { font-size: 12px; }
.tile .got { position: absolute; top: 8px; left: 8px; background: var(--cat); color: #fff; font-size: 11px; padding: 3px 8px; border-radius: 10px; }
.tile.small { padding: 8px 6px; border-top-width: 5px; border-radius: 18px; }
.tile.small .tile-word { font-size: 15px; }
.tile.small .stars { font-size: 13px; }
.tile.small .got { display: none; }
.tile.hidden .tile-img img { filter: brightness(0); opacity: .08; }
.tile.hidden .tile-img b { position: absolute; font-size: 44px; color: #d7c9b3; }
.tile.hidden .tile-word { color: #c3b59f; font-size: 14px; }
.tile.small.hidden .tile-img b { font-size: 32px; }

/* なまえカード */
.tile.name-empty { border: 3px dashed #f0719b; border-top: 6px solid var(--cat); }
.tile.name-empty .tile-img img { opacity: .35; }
.tile.name-empty .tile-img b { position: absolute; font-size: 64px; color: #f0719b; }
.tile.name-empty .tile-word { font-size: 16px; color: #d4557f; }
.me-badge { position: absolute; top: 8px; right: 8px; background: #f0719b; color: #fff; font-size: 11px; padding: 3px 8px; border-radius: 10px; }
.name-change { float: right; margin-top: -34px; background: var(--paper); box-shadow: var(--shadow); border-radius: 18px; padding: 8px 14px; font-size: 15px; color: #d4557f; }
.name-modal p { font-size: 15px; }
.name-form { width: 100%; display: flex; flex-direction: column; gap: 12px; align-items: stretch; }
.gender-row { display: flex; gap: 12px; justify-content: center; }
.gender { flex: 1; max-width: 180px; display: flex; flex-direction: column; align-items: center; padding: 10px; border-radius: 22px; border: 4px solid var(--line); background: #fff; }
.gender input { position: absolute; opacity: 0; pointer-events: none; }
.gender img { width: 100px; height: 100px; }
.gender.on { border-color: #f0719b; background: #fff2f6; }
.name-input {
  font: inherit; font-size: 30px; text-align: center; padding: 12px; border-radius: 18px; border: 3px solid var(--line);
  -webkit-user-select: text; user-select: text; letter-spacing: .08em;
}
.name-input:focus { outline: none; border-color: var(--primary); }
.name-error { color: #c93a3a !important; font-size: 15px !important; margin: 0; }

/* キラキラ */
.kira { position: relative; }
.kira::after {
  content: ''; position: absolute; top: 0; right: 0; bottom: 0; left: 0; pointer-events: none; border-radius: inherit;
  background: linear-gradient(115deg, transparent 20%, rgba(255,255,255,.75) 40%, rgba(255,230,120,.35) 48%, rgba(160,220,255,.35) 56%, transparent 70%);
  background-size: 250% 100%;
  animation: shine 2.8s ease-in-out infinite;
  mix-blend-mode: soft-light;
}
.tile.kira { background: linear-gradient(160deg, #fffdf2, #fff3c9 55%, #ffe0f0); border-top-color: #e9b21c; }
@keyframes shine { 0% { background-position: 150% 0; } 60%, 100% { background-position: -100% 0; } }

/* ---- 下のボタン ---- */
.bottombar { display: flex; gap: 14px; flex: none; }
.big-btn {
  min-height: 64px; padding: 10px 22px; border-radius: 22px; background: var(--paper); box-shadow: var(--shadow);
  font-size: 20px; display: flex; align-items: center; justify-content: center; gap: 12px;
}
.big-btn small { display: block; font-size: 12px; color: var(--muted); font-weight: 500; }
.big-btn.primary { background: var(--primary); color: #fff; box-shadow: 0 5px 0 var(--primary-dark); }
.big-btn.primary .stars i { color: rgba(255,255,255,.4); }
.big-btn.primary .stars i.on { color: #ffe27a; text-shadow: none; }
.big-btn.danger { background: #fff0f0; color: #c93a3a; }
.bottombar .big-btn { flex: 1; justify-content: flex-start; text-align: left; }
.dice { font-size: 36px; }

/* ---- なぞる画面 ---- */
.trace {
  display: grid;
  grid-template-columns: minmax(200px, 25%) 1fr 96px;
  grid-template-rows: auto minmax(0, 1fr);
  grid-template-areas: 'top top top' 'card board tools';
  gap: 14px 20px;
}
.trace-top { grid-area: top; display: flex; align-items: center; gap: 14px; }
.trace-title { margin-right: auto; }
.trace-title small { display: block; color: var(--primary); font-size: 14px; }
.trace-title b { font-size: 26px; font-weight: 900; }
.level-tabs { display: flex; background: #f3eadb; border-radius: 20px; padding: 5px; gap: 4px; }
.level-tab {
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
  min-width: 108px; height: 60px; padding: 0 10px; border-radius: 16px; font-size: 16px; color: var(--muted);
}
.level-tab .stars { font-size: 14px; }
.level-tab.active { background: var(--primary); color: #fff; box-shadow: 0 3px 0 var(--primary-dark); }
.level-tab.active .stars i { color: rgba(255,255,255,.4); text-shadow: none; }
.level-tab.active .stars i.on { color: #ffe27a; }
.level-tab.locked { opacity: .55; }

.card-panel { grid-area: card; display: flex; flex-direction: column; gap: 14px; min-height: 0; }
.big-card {
  background: var(--paper); border-radius: 26px; box-shadow: var(--shadow); padding: 16px 12px 14px;
  display: flex; flex-direction: column; align-items: center; gap: 6px; border-top: 8px solid var(--cat); overflow: hidden;
}
.big-card img { width: 72%; max-width: 190px; aspect-ratio: 1; object-fit: contain; filter: drop-shadow(0 8px 8px rgba(0,0,0,.14)); }
.big-card.kira { background: linear-gradient(160deg, #fffdf2, #fff3c9 55%, #ffe0f0); }
.big-word { font-size: 28px; letter-spacing: .06em; }
.big-card.moji { border-top-color: #e07b39; }
.moji-char { font-size: 120px; line-height: 1.1; font-weight: 700; color: var(--ink); }
.char-chips { display: flex; flex-wrap: wrap; gap: 8px; justify-content: center; }
.char-chip {
  min-width: 52px; height: 52px; padding: 0 6px; border-radius: 16px; background: var(--paper); box-shadow: var(--shadow);
  font-size: 28px; color: var(--muted);
}
.char-chip.current { background: var(--primary); color: #fff; box-shadow: 0 4px 0 var(--primary-dark); }
.char-chip.done { background: #fff3c4; color: #b07a00; }
.char-chip.done::after { content: '✓'; font-size: 13px; vertical-align: top; margin-left: 1px; }
.char-chip.pop { animation: pop .45s cubic-bezier(.3,1.8,.5,1); }
@keyframes pop { 0% { transform: scale(1); } 40% { transform: scale(1.35); } 100% { transform: scale(1); } }
.hint { margin: 0; text-align: center; color: var(--muted); font-size: 15px; }
.related { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.related button { background: var(--paper); border-radius: 14px; box-shadow: var(--shadow); padding: 6px 2px; font-size: 12px; display: flex; flex-direction: column; align-items: center; }
.related img { width: 44px; height: 44px; }

.board { grid-area: board; position: relative; display: flex; align-items: center; justify-content: center; min-height: 0; min-width: 0; overflow: hidden; }
.paper {
  position: relative; flex: none; width: 480px; height: 480px;
  background: var(--paper); border-radius: 32px; box-shadow: var(--shadow);
  touch-action: none;
}
.paper-count { position: absolute; top: 14px; left: 18px; font-size: 15px; color: var(--muted); background: #f7f1e7; padding: 4px 12px; border-radius: 12px; }
.trace-svg { position: absolute; top: 4%; right: 4%; bottom: 4%; left: 4%; width: 92%; height: 92%; touch-action: none; overflow: visible; --ink: #3b7dd8; }
.trace-svg .grid line { stroke: #eadfcd; stroke-width: .5; stroke-dasharray: 2 2; }
.trace-svg .guide-body { fill: none; stroke: #e9e4da; stroke-width: 12; stroke-linecap: round; stroke-linejoin: round; }
.trace-svg .guide-dash { fill: none; stroke: #fff; stroke-width: 1.1; stroke-dasharray: 2.2 2.4; stroke-linecap: round; }
.trace-svg .user-ink { fill: none; stroke-width: 8.5; stroke-linecap: round; stroke-linejoin: round; }
.trace-svg .user-ink.stray { stroke-width: 7; opacity: .7; }
.trace-svg.complete .user-ink { animation: glow .6s ease-out; }
@keyframes glow { 50% { stroke-width: 12; } }
.trace-svg .demo-path { fill: none; stroke: #ff9f43; stroke-width: 6; stroke-linecap: round; stroke-linejoin: round; opacity: .85; }
.trace-svg .marker { pointer-events: none; }
.trace-svg .start-halo { fill: var(--ink); opacity: .18; transform-box: fill-box; transform-origin: center; animation: halo 1.4s ease-out infinite; }
.trace-svg .start-dot { fill: var(--ink); stroke: #fff; stroke-width: 1.1; }
.trace-svg .start-num { fill: #fff; font-size: 6px; font-weight: 900; text-anchor: middle; dominant-baseline: central; font-family: sans-serif; }
.trace-svg .arrow path { fill: none; stroke: var(--ink); stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; opacity: .8; }
.trace-svg .arrow { animation: nudge 1s ease-in-out infinite; }
.trace-svg .start.wiggle { animation: wiggle .45s ease; }
@keyframes halo { 0% { transform: scale(.7); opacity: .35; } 100% { transform: scale(1.7); opacity: 0; } }
@keyframes nudge { 50% { opacity: .35; } }
@keyframes wiggle { 20% { opacity: .4; } 40% { opacity: 1; } 60% { opacity: .4; } 80% { opacity: 1; } }
.praise {
  position: absolute; left: 0; right: 0; top: 36%; text-align: center; font-size: 64px; font-weight: 900;
  color: #ff8a3d; -webkit-text-stroke: 3px #fff; paint-order: stroke; opacity: 0; pointer-events: none; white-space: nowrap;
}
.praise.show { animation: praise .9s ease-out; }
@keyframes praise { 0% { opacity: 0; transform: scale(.4); } 25% { opacity: 1; transform: scale(1.15); } 70% { opacity: 1; transform: scale(1); } 100% { opacity: 0; transform: translateY(-40px); } }

.tools { grid-area: tools; display: flex; flex-direction: column; gap: 12px; justify-content: center; }
.tool {
  width: 96px; height: 88px; border-radius: 22px; background: var(--paper); box-shadow: var(--shadow);
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 4px; font-size: 14px; color: var(--muted);
}
.tool .ti { font-size: 30px; color: var(--primary); line-height: 1; }
.pen-swatch { width: 32px; height: 32px; border-radius: 50%; box-shadow: inset 0 -3px 0 rgba(0,0,0,.15); }

/* たて向き */
@media (orientation: portrait) {
  .trace {
    grid-template-columns: 1fr;
    grid-template-rows: auto auto minmax(0, 1fr) auto;
    grid-template-areas: 'top' 'card' 'board' 'tools';
  }
  .trace-top { flex-wrap: wrap; }
  .card-panel { flex-direction: row; align-items: center; gap: 16px; }
  .big-card { flex-direction: row; padding: 8px 18px 8px 8px; border-top: 0; border-left: 8px solid var(--cat); }
  .big-card img { width: 84px; }
  .big-card .stars { display: none; }
  .big-word { font-size: 24px; }
  .moji-char { font-size: 64px; padding: 0 14px; }
  .card-panel .hint, .related { display: none; }
  .card-panel .model-char { flex: none; width: 170px; height: 170px; max-height: none; order: 2; margin-left: auto; padding: 8px; }
  .card-panel .model-char small { font-size: 11px; top: 4px; left: 8px; }
  .char-chips { justify-content: flex-start; }
  .tools { flex-direction: row; justify-content: center; }
  .tool { width: 110px; height: 76px; }
}

/* じゆうちょう */
.tool.done-btn { background: #ff8a3d; color: #fff; box-shadow: 0 5px 0 #d9672a; order: 9; }
.tool.done-btn .ti { color: #fff; font-size: 34px; }
.tool.done-btn:disabled { background: #efe7da; color: #b3a592; box-shadow: 0 4px 0 #ddd2c0; }
.tool.done-btn:disabled .ti { color: #c9bca8; }
.tool.done-btn:not(:disabled) { animation: breathe 1.6s ease-in-out infinite; }
@keyframes breathe { 50% { transform: scale(1.06); } }

/* じぶんで かく：左の みほん */
.model-char {
  position: relative; flex: 1; min-height: 0; max-height: 360px; width: 100%;
  background: var(--paper); border-radius: 26px; box-shadow: var(--shadow); padding: 10px;
  display: flex; align-items: center; justify-content: center; border: 4px solid #ffd9a8;
}
.model-char small { position: absolute; top: 8px; left: 12px; font-size: 14px; color: #e07b39; }
.model-char svg { height: 100%; max-width: 100%; aspect-ratio: 1; }
.model-char line { stroke: #efe4d2; stroke-width: .8; stroke-dasharray: 2 2; }
.model-char path { fill: none; stroke: var(--ink); stroke-width: 6.5; stroke-linecap: round; stroke-linejoin: round; }
.big-card.compact { flex-direction: row; justify-content: center; gap: 10px; padding: 8px 12px; border-top-width: 6px; }
.big-card.compact img { width: 64px; max-width: none; }
.big-card.compact .big-word { font-size: 22px; }
.big-card.compact .stars { display: none; }

/* 手書きの きろく */
.modal { overflow-y: auto; }
.reward.has-writing .flip-card { width: 180px; }
.writing-row { display: flex; flex-wrap: wrap; gap: 6px; justify-content: center; }
.writing-svg { width: 64px; height: 64px; background: #fff; border: 2px solid var(--line); border-radius: 12px; }
.writing-svg line { stroke: #efe4d2; stroke-width: 1; stroke-dasharray: 3 3; }
.writing-svg path { fill: none; stroke-width: 8.5; stroke-linecap: round; stroke-linejoin: round; }
.writing-svg g { stroke-width: 8.5; }
.writing-row.big .writing-svg { width: 150px; height: 150px; }
.small-note { font-size: 14px !important; }
.kiroku main { flex: 1; min-height: 0; margin: 0 -20px; padding: 0 20px 24px; }
.kiroku-item { display: flex; align-items: center; gap: 16px; background: var(--paper); border-radius: 22px; box-shadow: var(--shadow); padding: 12px 16px; margin-bottom: 12px; }
.kiroku-card { display: flex; flex-direction: column; align-items: center; width: 110px; flex: none; }
.kiroku-card img { width: 64px; height: 64px; }
.kiroku-card b { font-size: 16px; }
.kiroku-card small { font-size: 12px; color: var(--muted); }
.kiroku-moji { font-size: 44px; line-height: 64px; }
.kiroku-item .writing-row { justify-content: flex-start; }
.kiroku-item .writing-svg { width: 96px; height: 96px; }
.empty { text-align: center; color: var(--muted); padding: 60px 20px; }
.empty span { font-size: 64px; }

/* ---- ずかん・もじ ---- */
.zukan-head { flex: 1; }
.zukan-head b { font-size: 26px; font-weight: 900; }
.zukan-head small { display: block; color: var(--muted); font-size: 14px; }
.meter { height: 14px; background: #f0e6d6; border-radius: 7px; overflow: hidden; margin-top: 6px; max-width: 420px; }
.meter i { display: block; height: 100%; background: linear-gradient(90deg, #ffc53d, #ff8a3d); border-radius: 7px; }
.zukan-count { text-align: right; font-size: 16px; }
.zukan-count b { font-size: 34px; color: var(--primary); }
.zukan-count small { display: block; color: #d49a00; }
.zukan main, .moji main { flex: 1; min-height: 0; margin: 0 -20px; padding: 0 20px 24px; }
.zukan-sec { margin-bottom: 22px; }
.zukan-sec h2 { display: flex; align-items: baseline; gap: 10px; font-size: 20px; margin: 8px 0 10px; }
.zukan-sec h2 span { background: var(--cat); color: #fff; padding: 4px 14px; border-radius: 14px; }
.zukan-sec h2 small { color: var(--muted); font-size: 15px; }
.zukan-sec h2 em { font-style: normal; color: #e08a00; font-size: 16px; }

.gojuon { display: flex; flex-direction: column; gap: 10px; max-width: 760px; margin: 6px auto 0; }
.gojuon-row { display: grid; grid-template-columns: repeat(5, 1fr); gap: 10px; }
.moji-cell, .blank { height: 76px; border-radius: 20px; }
.moji-cell { position: relative; background: var(--paper); box-shadow: var(--shadow); font-size: 40px; font-weight: 700; }
.moji-cell.done { background: #fff6d6; }
.moji-cell small { position: absolute; top: 5px; right: 8px; font-size: 12px; color: #d49a00; }

/* ---- モーダル ---- */
#overlay { position: fixed; top: 0; right: 0; bottom: 0; left: 0; pointer-events: none; z-index: 20; }
#overlay.open { pointer-events: auto; }
.backdrop {
  position: absolute; top: 0; right: 0; bottom: 0; left: 0; background: rgba(60, 45, 30, .45); display: grid; place-items: center;
  padding: calc(var(--safe-t) + 16px) 16px calc(var(--safe-b) + 16px); animation: fade .2s ease;
}
@keyframes fade { from { opacity: 0; } }
.modal {
  width: min(520px, 100%); max-height: 100%; background: var(--paper); border-radius: 32px; padding: 26px 28px;
  box-shadow: 0 20px 60px rgba(0,0,0,.25); text-align: center; animation: rise .35s cubic-bezier(.3,1.4,.5,1);
  display: flex; flex-direction: column; align-items: center; gap: 12px;
}
@keyframes rise { from { transform: translateY(40px) scale(.9); opacity: 0; } }
.modal h2 { margin: 0; font-size: 30px; font-weight: 900; }
.modal p { margin: 0; font-size: 18px; color: var(--muted); }
.modal-actions { display: flex; flex-direction: column; gap: 10px; width: 100%; margin-top: 6px; }
.modal-actions .row { display: flex; gap: 10px; }
.modal-actions .row .big-btn { flex: 1; font-size: 18px; }
.reward-title span { color: var(--star); margin: 0 8px; display: inline-block; animation: twinkle 1.2s ease-in-out infinite; }
@keyframes twinkle { 50% { transform: scale(1.3) rotate(20deg); } }
.reward-msg { font-size: 17px !important; }

.flip-card { width: 230px; aspect-ratio: .78; perspective: 900px; }
.flip-inner { position: relative; width: 100%; height: 100%; transition: transform .7s cubic-bezier(.3,1.3,.5,1); transform-style: preserve-3d; transform: rotateY(180deg); }
.flip-card.flipped .flip-inner { transform: rotateY(0deg); }
.flip-front, .flip-back {
  position: absolute; top: 0; right: 0; bottom: 0; left: 0; border-radius: 24px; backface-visibility: hidden; -webkit-backface-visibility: hidden;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 6px;
}
.flip-front { background: #fff; border: 6px solid var(--cat); box-shadow: 0 10px 30px rgba(0,0,0,.15); overflow: hidden; }
.flip-front img { width: 70%; aspect-ratio: 1; object-fit: contain; filter: drop-shadow(0 8px 8px rgba(0,0,0,.15)); }
.flip-front b { font-size: 28px; letter-spacing: .05em; }
.flip-back { transform: rotateY(180deg); background: var(--cat); background: repeating-linear-gradient(45deg, var(--cat), var(--cat) 14px, color-mix(in srgb, var(--cat) 80%, #fff) 14px 28px); color: #fff; font-size: 80px; }
.flip-card.kira .flip-front { background: linear-gradient(160deg, #fffdf2, #fff1b8 50%, #ffd9ec); border-color: #e9b21c; }
.flip-card.kira .flip-front::after {
  content: ''; position: absolute; top: 0; right: 0; bottom: 0; left: 0; pointer-events: none;
  background: linear-gradient(115deg, transparent 25%, rgba(255,255,255,.9) 42%, rgba(255,220,120,.4) 50%, rgba(150,210,255,.4) 58%, transparent 72%);
  background-size: 250% 100%; animation: shine 2.4s ease-in-out infinite; mix-blend-mode: soft-light;
}
.moji-done { font-size: 130px; line-height: 1.1; }

.stamp-row { display: flex; gap: 10px; align-items: center; margin: 10px 0; flex-wrap: wrap; justify-content: center; }
.stamp-slot {
  width: 68px; height: 68px; border-radius: 50%; border: 3px dashed #eadcc5; display: grid; place-items: center;
  font-size: 22px; color: #d5c6ae;
}
.stamp-slot.on { border: 0; background: #ffe3ec; font-size: 40px; }
.stamp-slot.fresh span { animation: stamp .5s cubic-bezier(.3,1.6,.5,1) .3s both; }
@keyframes stamp { from { transform: scale(3) rotate(-30deg); opacity: 0; } }
.stamp-goal { font-size: 48px; margin-left: 4px; }

.treasure { font-size: 130px; line-height: 1; display: flex; flex-direction: column; align-items: center; animation: shake 1.2s ease-in-out infinite; }
.treasure small { font-size: 18px; color: var(--muted); margin-top: 6px; }
@keyframes shake { 0%, 60%, 100% { transform: rotate(0); } 70% { transform: rotate(-8deg); } 80% { transform: rotate(8deg); } 90% { transform: rotate(-5deg); } }

.pen-row, .pens-grid { display: flex; flex-wrap: wrap; gap: 12px; justify-content: center; align-items: center; }
.pen-row { flex-direction: column; gap: 6px; font-size: 22px; }
.pen-row .pen-big { width: 96px; height: 96px; }
.pens-grid { display: grid; grid-template-columns: repeat(4, 1fr); width: 100%; }
.pen-big { width: 64px; height: 64px; border-radius: 50%; display: grid; place-items: center; font-size: 22px; box-shadow: inset 0 -4px 0 rgba(0,0,0,.15); }
.pen-choice { display: flex; flex-direction: column; align-items: center; gap: 4px; padding: 10px 4px; border-radius: 18px; font-size: 15px; }
.pen-choice small { font-size: 11px; color: var(--muted); }
.pen-choice.active { background: #e6f6f4; outline: 3px solid var(--primary); }
.pen-choice.locked .pen-big { filter: grayscale(1) opacity(.35); }

.detail-modal p b { font-size: 26px; color: var(--primary); }

.parent-modal { text-align: left; align-items: stretch; width: min(640px, 100%); font-weight: 500; touch-action: pan-y; }
.parent-modal h2 { text-align: center; font-size: 24px; }
.parent-modal section { border-top: 1px solid var(--line); padding-top: 12px; }
.parent-modal h3 { margin: 0 0 8px; font-size: 17px; }
.parent-modal .note { font-size: 14px; color: var(--muted); margin: 0 0 8px; line-height: 1.7; padding-left: 0; }
.parent-modal ul.note { padding-left: 1.2em; }
.parent-modal a { color: var(--primary); }
.switch { display: flex; align-items: center; gap: 10px; min-height: 44px; font-size: 16px; }
.switch input { width: 26px; height: 26px; accent-color: var(--primary); }
.code-box { background: #f7f1e7; border-radius: 14px; padding: 12px; text-align: center; margin-bottom: 10px; }
.code { font-size: 30px; letter-spacing: .15em; font-family: ui-monospace, monospace; }
.muted { color: var(--muted); font-size: 14px; }
.restore { display: flex; gap: 8px; }
.restore input {
  flex: 1; min-width: 0; font: inherit; font-size: 20px; padding: 0 14px; border-radius: 14px; border: 2px solid var(--line);
  -webkit-user-select: text; user-select: text; text-transform: uppercase; letter-spacing: .1em;
}
.restore .big-btn { min-height: 52px; font-size: 16px; }

/* ---- 紙ふぶき・トースト ---- */
.confetti { position: fixed; top: 0; right: 0; bottom: 0; left: 0; pointer-events: none; z-index: 30; overflow: hidden; }
.confetti i { position: absolute; top: 0; width: 12px; height: 16px; border-radius: 3px; }
.toast {
  position: fixed; left: 0; right: 0; margin: 0 auto; width: max-content; bottom: calc(var(--safe-b) + 110px); z-index: 40;
  background: rgba(61, 50, 41, .92); color: #fff; padding: 14px 26px; border-radius: 24px; font-size: 20px;
  animation: toast 1.4s ease forwards; pointer-events: none; white-space: nowrap;
}
@keyframes toast { 0% { opacity: 0; transform: translateY(20px); } 15%, 80% { opacity: 1; transform: none; } 100% { opacity: 0; } }

/* 小さめのタブレット・スマホ横 */
@media (max-width: 900px) and (orientation: landscape) {
  .trace { grid-template-columns: minmax(160px, 22%) 1fr 84px; }
  .tool { width: 84px; height: 72px; }
  .level-tab { min-width: 84px; }
}
@media (max-width: 700px) {
  .logo > div, .chip-label, .kiroku-chip > span:not(.chip-icon) { display: none; }
  .logo b { font-size: 18px; }
  .grid { grid-template-columns: repeat(auto-fill, minmax(130px, 1fr)); gap: 12px; }
  .bottombar .big-btn small { display: none; }
  .level-tab { min-width: 0; font-size: 13px; }
  .trace-title b { font-size: 20px; }
}
@media (max-width: 520px) {
  .screen { padding-left: calc(var(--safe-l) + 12px); padding-right: calc(var(--safe-r) + 12px); }
  .logo > div, .zukan-chip > span:not(.chip-icon) { display: none; }
  .top-actions { gap: 6px; }
  .chip { padding: 0 12px; }
  .grid { grid-template-columns: repeat(2, 1fr); }
  .bottombar .big-btn { font-size: 16px; padding: 8px 12px; }
}
