/* ことばの迷い猫 — 絵本の紙・クレヨンの色 */
:root {
  --bg: #f4ecdb; --surface: #fffaf0; --surface-2: #f1e6cd; --text: #3d2c20; --text-sub: #7a6553; --line: #e2d3b4;
  --accent: #c2412d; --accent-ink: #fffaf0; --accent-soft: #f8e1d6;
  --paper: #fbf4e2; --paper-2: #f3e8cc; --paper-grid: rgba(150, 120, 80, .14);
  --slip: #fffaf0; --slip-edge: #d6c39c; --ink: #4a3424; --ink-is: #2f5f8f; --ink-prop: #c2412d; --glow: #ffd25e;
  --gold: #e0a419;
  --font-tale: "Hiragino Mincho ProN", "Yu Mincho", "Noto Serif JP", serif;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #1d1a24; --surface: #29243a; --surface-2: #332c45; --text: #f2eadb; --text-sub: #bdb0a0; --line: #41395a;
    --accent: #ff8a6b; --accent-ink: #1d1a24; --accent-soft: #3d2a33;
    --paper: #e9dcc0; --paper-2: #ddcfae; --paper-grid: rgba(110, 85, 50, .18);
    --slip: #fbf3e2; --slip-edge: #c2ad84; --glow: #ffcf4d; --gold: #ffcc4d;
  }
}
:root[data-theme="dark"] {
  --bg: #1d1a24; --surface: #29243a; --surface-2: #332c45; --text: #f2eadb; --text-sub: #bdb0a0; --line: #41395a;
  --accent: #ff8a6b; --accent-ink: #1d1a24; --accent-soft: #3d2a33;
  --paper: #e9dcc0; --paper-2: #ddcfae; --paper-grid: rgba(110, 85, 50, .18);
  --slip: #fbf3e2; --slip-edge: #c2ad84; --glow: #ffcf4d; --gold: #ffcc4d;
}
body { background: var(--bg) radial-gradient(circle at 20% 0%, rgba(255, 255, 255, .25), transparent 60%) no-repeat; }

/* タイトル */
.km-hero-wrap { background: var(--surface-2); border-radius: 20px; padding: 14px; box-shadow: inset 0 0 0 1px var(--line); transform: rotate(-1deg); }
.km-hero { display: block; width: 100%; height: auto; }
.km-daily-btn { justify-content: space-between; }
.km-daily-btn small { font-weight: 700; color: var(--text-sub); }
.km-row2 { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.km-row-between { display: flex; justify-content: space-between; align-items: center; gap: 8px; }
.km-row-between h2 { margin: 0; }

/* プレイ画面 */
.km-play { display: flex; flex-direction: column; gap: 8px; }
.km-top { display: flex; align-items: center; gap: 8px; }
.km-top-t { flex: 1; min-width: 0; line-height: 1.3; }
.km-top-t small { display: block; font-size: 12px; color: var(--text-sub); font-weight: 700; }
.km-top-t b { display: block; font-size: 17px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.km-top-m { text-align: right; line-height: 1.2; }
.km-moves { display: block; font-size: 22px; font-weight: 900; color: var(--accent); font-variant-numeric: tabular-nums; }
.km-top-m small { font-size: 11px; color: var(--text-sub); white-space: nowrap; }
.km-ibtn { flex: none; width: 44px; height: 44px; border-radius: 12px; border: 1px solid var(--line); background: var(--surface); font-size: 19px; cursor: pointer; touch-action: manipulation; }
.km-rules { display: flex; flex-wrap: nowrap; gap: 5px; align-items: center; min-height: 30px; overflow-x: auto; scrollbar-width: none; margin: 0 -16px; padding: 2px 16px 4px; -webkit-mask-image: linear-gradient(90deg, transparent 0, #000 14px, #000 calc(100% - 18px), transparent); mask-image: linear-gradient(90deg, transparent 0, #000 14px, #000 calc(100% - 18px), transparent); }
.km-rules::-webkit-scrollbar { display: none; }
.km-rule, .km-rules-h { flex: none; }
.km-rules-h { font-size: 11px; font-weight: 800; color: var(--text-sub); margin-right: 2px; letter-spacing: .05em; }
.km-rule { display: inline-flex; align-items: baseline; gap: 2px; font-size: 13px; padding: 2px 9px; border-radius: 6px; background: var(--slip); color: #4a3424; border: 1px solid var(--slip-edge); box-shadow: 0 1px 0 rgba(60, 40, 20, .15); white-space: nowrap; }
.km-rule b { font-weight: 900; }
.km-rule i { font-style: normal; font-weight: 900; color: #c2412d; }
.km-rule.is-noun i { color: #4a3424; text-decoration: underline; text-decoration-color: rgba(74, 52, 36, .4); }
.km-rule.is-none { color: var(--text-sub); background: transparent; border-style: dashed; }
.km-board-wrap { display: flex; justify-content: center; margin: 0 -12px; }
.km-board { display: block; touch-action: none; user-select: none; -webkit-user-select: none; border-radius: 12px; }
.km-msg { min-height: 1.6em; margin: 0; font-size: 14px; text-align: center; color: var(--text-sub); font-weight: 700; line-height: 1.5; }
.km-msg.is-warn { color: var(--accent); }
.km-ctrl { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 2px 4px 0; }
.km-side { display: flex; flex-direction: column; gap: 10px; }
.km-act { width: 84px; height: 58px; border-radius: 14px; border: 1px solid var(--line); background: var(--surface); cursor: pointer; display: flex; flex-direction: column; align-items: center; justify-content: center; line-height: 1.1; touch-action: manipulation; box-shadow: 0 2px 0 var(--line); }
.km-act span { font-size: 22px; font-weight: 900; }
.km-act small { font-size: 11px; font-weight: 800; color: var(--text-sub); }
.km-act:active, .km-pad:active { transform: translateY(2px); box-shadow: none; }
.km-dpad { display: grid; grid-template-columns: repeat(3, 64px); grid-template-rows: repeat(3, 56px); gap: 4px; }
.km-pad { border-radius: 16px; border: 1px solid var(--line); background: var(--surface); font-size: 26px; font-weight: 900; color: var(--text); cursor: pointer; touch-action: manipulation; box-shadow: 0 3px 0 var(--line); -webkit-tap-highlight-color: transparent; user-select: none; -webkit-user-select: none; }
.km-pad.is-u { grid-column: 2; grid-row: 1; }
.km-pad.is-l { grid-column: 1; grid-row: 2; }
.km-pad.is-r { grid-column: 3; grid-row: 2; }
.km-pad.is-d { grid-column: 2; grid-row: 3; }
.km-keys { text-align: center; margin: 4px 0 0; }
@media (hover: none) { .km-keys { display: none; } }
@media (min-width: 700px) {
  .km-board-wrap { margin: 0; }
}
@media (min-width: 900px) {
  .mn-app.km-playing { max-width: 920px; }
  .km-play { display: grid; grid-template-columns: 1fr 250px; grid-template-areas: "top top" "rules rules" "board under" "keys keys"; column-gap: 20px; align-items: center; }
  .km-top { grid-area: top; } .km-rules { grid-area: rules; flex-wrap: wrap; overflow: visible; margin: 0; padding: 0; -webkit-mask-image: none; mask-image: none; }
  .km-board-wrap { grid-area: board; } .km-under { grid-area: under; display: flex; flex-direction: column; gap: 16px; }
  .km-keys { grid-area: keys; }
  .km-under .km-ctrl { flex-direction: column-reverse; gap: 16px; }
  .km-under .km-side { flex-direction: row; }
  .km-msg { min-height: 4.5em; }
}

/* ヒント・ことば帳 */
.km-hint { background: var(--surface-2); border-radius: 12px; padding: 10px 12px; }
.km-hint b { display: block; font-size: 14px; }
.km-hint p { margin: 4px 0 0; }
.km-arrows { font-size: 26px; font-weight: 900; letter-spacing: .1em; color: var(--accent); }
.km-book { display: flex; flex-wrap: wrap; gap: 6px; }
.km-bk { font-size: 13px; padding: 4px 10px; border-radius: 6px; border: 1px dashed var(--line); color: var(--text-sub); }
.km-bk.on { background: var(--slip); color: #4a3424; border: 1px solid var(--slip-edge); font-weight: 800; }
.km-bk.is-extra { border-color: var(--gold); }

/* クリア */
.km-clear-t { font-size: 26px; text-align: center; margin: 0; }
.km-clear .mn-kicker, .km-ending .mn-kicker { text-align: center; }
.km-stars { display: flex; justify-content: center; gap: 6px; font-size: 54px; line-height: 1; color: var(--line); }
.km-stars .on { color: var(--gold); text-shadow: 0 2px 0 rgba(150, 100, 0, .25); animation: km-star .5s cubic-bezier(.2, 1.6, .4, 1) both; }
@keyframes km-star { from { transform: scale(0) rotate(-40deg); } to { transform: none; } }
.km-clear-m { text-align: center; font-size: 18px; margin: 0; }
.km-clear-m b { font-size: 46px; font-weight: 900; color: var(--accent); margin-right: 2px; }
.km-clear-m small { display: block; font-size: 13px; color: var(--text-sub); }
.km-note { margin: 4px 0; background: var(--paper); color: #4a3424; border-radius: 4px 14px 14px 4px; padding: 14px 16px 12px 22px; box-shadow: 0 2px 8px rgba(60, 40, 20, .12); position: relative; border-left: 4px solid #d9b98a; }
.km-note figcaption { font-size: 11px; font-weight: 800; color: #8a7158; letter-spacing: .08em; }
.km-note p { font-family: var(--font-tale); font-size: 17px; margin: 4px 0 0; line-height: 1.8; }
.km-share { margin-top: 6px; }
.km-share-btn { background: #2b2140; color: #fff; border-color: #2b2140; }
.km-streak { display: flex; justify-content: center; flex-wrap: wrap; gap: 4px 12px; font-size: 14px; color: var(--text-sub); }
.km-streak b { font-variant-numeric: tabular-nums; color: var(--text); }

/* 物語 */
.km-story h2, .km-ending h2 { text-align: center; }
.km-tale { background: var(--paper); color: #3d2c20; border-radius: 14px; padding: 16px 18px; font-family: var(--font-tale); font-size: 17px; line-height: 1.95; box-shadow: 0 2px 10px rgba(60, 40, 20, .1); }
.km-tale p { margin: 0 0 .6em; }
.km-tale p:last-child { margin: 0; }
.km-ending-lines { font-family: var(--font-tale); font-size: 17px; line-height: 1.95; }
.km-ending-lines p { margin: 0 0 .8em; }
.km-endart { display: block; width: 100%; height: auto; border-radius: 16px; }

/* 章えらび */
.km-ch { background: var(--surface); border: 1px solid var(--line); border-radius: 16px; padding: 12px; }
.km-ch.is-locked { opacity: .6; }
.km-ch-h { display: flex; align-items: baseline; gap: 8px; margin-bottom: 8px; flex-wrap: wrap; }
.km-ch-h small { color: var(--accent); font-weight: 800; font-size: 12px; }
.km-ch-h b { font-size: 17px; flex: 1; }
.km-link { border: 0; background: none; color: var(--accent); font-size: 13px; font-weight: 700; cursor: pointer; padding: 8px 4px; min-height: 36px; text-decoration: underline; }
.km-pages { display: grid; grid-template-columns: repeat(2, 1fr); gap: 8px; }
.km-page { display: grid; grid-template-columns: auto 1fr; grid-template-rows: auto auto; column-gap: 8px; align-items: center; text-align: left; min-height: 58px; padding: 8px 10px; border-radius: 12px; border: 1px solid var(--line); background: var(--surface-2); cursor: pointer; touch-action: manipulation; }
.km-page-n { grid-row: 1 / 3; width: 30px; height: 30px; border-radius: 50%; background: var(--slip); color: #4a3424; display: flex; align-items: center; justify-content: center; font-weight: 900; border: 1px solid var(--slip-edge); font-size: 14px; }
.km-page-t { font-weight: 800; font-size: 14px; line-height: 1.3; }
.km-page-s { font-size: 12px; color: var(--gold); letter-spacing: .05em; }
.km-page.is-done { border-color: var(--gold); }
.km-page.is-locked { cursor: default; }
.km-page.is-locked .km-page-s { color: var(--text-sub); }
@media (min-width: 560px) { .km-pages { grid-template-columns: repeat(4, 1fr); } }

@media (prefers-reduced-motion: reduce) { .km-hero-wrap { transform: none; } }

/* お知らせは上に（十字ボタンにかぶらないように） */
.mn-toast { bottom: auto; top: 72px; }

/* 生成画像（assets/）があるときの見せ方 */
.km-hero-media { display: block; width: 100%; height: auto; aspect-ratio: 16 / 9; object-fit: cover; border-radius: 12px; background: var(--paper); }
.km-scene { display: block; width: 100%; height: auto; aspect-ratio: 16 / 9; object-fit: cover; border-radius: 14px; box-shadow: 0 2px 10px rgba(60, 40, 20, .15); background: var(--paper); }
.km-scene.is-square { aspect-ratio: 1 / 1; max-width: 320px; margin-left: auto; margin-right: auto; }
img.km-endart { aspect-ratio: 16 / 9; object-fit: cover; }
.km-note[style*="background-image"] { background-size: cover; }
