:root {
  --bg: #efe4d4;
  --paper: #fffaf3;
  --ink: #221c16;
  --muted: #5c5148;
  --line: #e4d3bf;
  --green: #145c40;
  --green-ink: #0e3d2b;
  --green-soft: #e3f3ea;
  --amber: #7a4e0d;
  --amber-soft: #fff1d4;
  --clay: #8c341f;
  --clay-soft: #fde7df;
  --blue: #1d4e6e;
  --blue-soft: #e5f1f8;
  --shadow: 0 10px 30px rgba(60, 36, 12, 0.08);
  --radius: 18px;
  font-family: "Hiragino Sans", "Hiragino Kaku Gothic ProN", "Yu Gothic", "Noto Sans CJK JP", "Noto Sans JP", sans-serif;
  color: var(--ink);
  background: var(--bg);
  font-size: 18px;
  line-height: 1.7;
}

* { box-sizing: border-box; }

html { scroll-behavior: auto; }

body {
  margin: 0;
  min-height: 100vh;
  background:
    radial-gradient(1200px 400px at 10% -10%, #f7efe4 0%, transparent 60%),
    var(--bg);
}

.skip {
  position: absolute;
  left: 12px;
  top: -60px;
  background: #fff;
  color: var(--ink);
  padding: 10px 14px;
  z-index: 20;
}

.skip:focus { top: 12px; }

.top {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  flex-direction: column;
  max-height: 100vh;
  background: rgba(255, 250, 243, 0.96);
  border-bottom: 1px solid var(--line);
  backdrop-filter: blur(8px);
}

.top-inner {
  flex: 0 0 auto;
  padding: 14px 16px 12px;
}

.top-inner, .wrap {
  max-width: 920px;
  margin: 0 auto;
}

.kicker {
  margin: 0;
  color: var(--clay);
  font-weight: 700;
  letter-spacing: 0.04em;
  font-size: 0.95rem;
}

h1 {
  margin: 2px 0 4px;
  font-size: 1.55rem;
  line-height: 1.35;
}

.lede {
  margin: 0;
  color: var(--muted);
  font-size: 1rem;
}

.tools {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 12px;
  align-items: center;
}

button, .toc a {
  font: inherit;
  color: inherit;
}

button {
  touch-action: manipulation;
  cursor: pointer;
  border-radius: 14px;
  border: 2px solid transparent;
  min-height: 56px;
  padding: 10px 16px;
}

button:focus-visible, a:focus-visible, summary:focus-visible {
  outline: 3px solid var(--green);
  outline-offset: 2px;
}

.primary {
  background: var(--green);
  color: #fff;
  font-weight: 700;
  flex: 1 1 200px;
}

.primary[aria-expanded="true"] {
  background: var(--green-ink);
}

.ghost {
  background: #fff;
  border-color: var(--line);
  flex: 1 1 140px;
}

.progress {
  font-weight: 700;
  color: var(--green-ink);
  background: var(--green-soft);
  border-radius: 999px;
  padding: 8px 14px;
  min-height: 56px;
  display: inline-flex;
  align-items: center;
}

.phrases:not([hidden]) {
  display: block;
  flex: 1 1 auto;
  min-height: 0;
  overflow: auto;
  background: #fffdf8;
  border-top: 1px solid var(--line);
  padding: 12px 16px 8px;
}

.phrases h2, .phrases .hint, .phrases .grid {
  max-width: 920px;
  margin-left: auto;
  margin-right: auto;
}

.phrases h2 {
  margin: 0 0 8px;
  font-size: 1.15rem;
}

.phrases .grid {
  display: grid;
  gap: 10px;
}

main {
  padding: 8px 16px 64px;
}

.rules, .scene, .toc, .bulk {
  max-width: 920px;
  margin: 12px auto;
}

.rules {
  background: var(--clay-soft);
  border: 1px solid #f0c7ba;
  border-radius: var(--radius);
  padding: 14px 16px;
}

.rules h2, .scene h3, .maybe h3, .fork h3, .pick h3 {
  margin: 0 0 8px;
  font-size: 1.05rem;
}

.rules ul, .maybe ul {
  margin: 0;
  padding-left: 1.2em;
}

.rules li + li, .maybe li + li { margin-top: 4px; }

.toc {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.toc a {
  text-decoration: none;
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 8px 12px;
  min-height: 44px;
  display: inline-flex;
  align-items: center;
}

.toc a:hover { border-color: var(--green); }

.bulk {
  display: flex;
  gap: 8px;
}

.bulk button { flex: 1; background: #fff; border: 1px solid var(--line); }

.scene {
  background: var(--paper);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  border: 1px solid rgba(228, 211, 191, 0.9);
}

summary {
  list-style: none;
  cursor: pointer;
  display: grid;
  grid-template-columns: 36px minmax(0, 1fr) 18px;
  grid-template-areas:
    "sn title chev"
    "sn meta chev";
  column-gap: 10px;
  row-gap: 2px;
  align-items: center;
  padding: 12px 14px;
  min-height: 72px;
  touch-action: manipulation;
}

summary::-webkit-details-marker { display: none; }

.sn {
  grid-area: sn;
  width: 36px;
  height: 36px;
  border-radius: 50%;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: var(--green);
  color: #fff;
  font-weight: 700;
}

.st {
  grid-area: title;
  font-weight: 700;
  font-size: 1.15rem;
  line-height: 1.35;
}

.meta {
  grid-area: meta;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
  min-width: 0;
}

.when {
  color: var(--muted);
  font-size: 0.92rem;
  font-weight: 500;
}

.scene-count {
  font-weight: 700;
  background: #f6efe6;
  border-radius: 999px;
  padding: 4px 10px;
  white-space: nowrap;
}

.scene.scene-done .scene-count {
  background: var(--green-soft);
  color: var(--green-ink);
}

.scene.scene-done .scene-count::before { content: "済 "; }

.chev {
  grid-area: chev;
  justify-self: end;
  width: 12px;
  height: 12px;
  border-right: 3px solid var(--ink);
  border-bottom: 3px solid var(--ink);
  transform: rotate(45deg);
  margin-top: -4px;
}

details[open] .chev {
  transform: rotate(225deg);
  margin-top: 6px;
}

.scene-body { padding: 0 14px 16px; }

.maybe {
  background: #fff7ea;
  border: 1px dashed #e2c48a;
  border-radius: 14px;
  padding: 12px 14px;
  margin-bottom: 14px;
}

.maybe h3::after {
  content: "（参考。コピーしません）";
  font-weight: 500;
  color: var(--muted);
  margin-left: 6px;
  font-size: 0.9rem;
}

.block-label {
  margin: 16px 0 8px;
  font-size: 1.05rem;
}

.line {
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 12px;
  margin: 8px 0;
  display: grid;
  gap: 10px;
}

.say {
  margin: 0;
  font-size: 1.18rem;
  line-height: 1.75;
  overflow-wrap: anywhere;
}

.line.is-copied {
  background: var(--green-soft);
  border-color: #9dcfb6;
}

.line.is-copied .say::before {
  content: "済";
  display: inline-block;
  margin-right: 8px;
  font-weight: 700;
  color: var(--green-ink);
  background: #fff;
  border-radius: 999px;
  padding: 0 8px;
  border: 1px solid #9dcfb6;
}

.copy {
  background: var(--green);
  color: #fff;
  font-weight: 700;
  min-height: 56px;
  width: 100%;
}

.line.is-copied .copy {
  background: #fff;
  color: var(--green-ink);
  border-color: var(--green);
}

.hint {
  margin: 6px 2px 10px;
  color: var(--muted);
  font-size: 0.98rem;
}

.fork, .pick {
  margin: 12px 0;
  display: grid;
  gap: 10px;
}

.fork-col, .pick-col {
  border-radius: 16px;
  padding: 10px 12px 12px;
}

.fork-yes { background: var(--green-soft); }
.fork-no { background: var(--amber-soft); }
.fork-mid { background: #f6f3ee; }
.pick-col { background: var(--blue-soft); }

.fork h3, .pick h3 { font-size: 1rem; }
.fork-yes h3 { color: var(--green-ink); }
.fork-no h3 { color: var(--amber); }
.pick h3, .pick-head { color: var(--blue); }

.pick-head {
  margin: 0;
  font-weight: 700;
}

.ask {
  margin-top: 8px;
}

.foot {
  max-width: 920px;
  margin: 8px auto 0;
  color: var(--muted);
  font-size: 0.98rem;
}

.toast {
  position: fixed;
  left: 50%;
  bottom: 18px;
  transform: translateX(-50%) translateY(12px);
  background: var(--ink);
  color: #fff;
  padding: 14px 18px;
  border-radius: 999px;
  font-weight: 700;
  font-size: 1.1rem;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s ease, transform 0.2s ease;
  z-index: 30;
  max-width: calc(100% - 32px);
  text-align: center;
}

.toast.show {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

dialog {
  border: none;
  border-radius: 18px;
  padding: 20px;
  max-width: min(440px, calc(100% - 32px));
  box-shadow: var(--shadow);
}

dialog::backdrop { background: rgba(34, 28, 22, 0.45); }

dialog p { margin: 0 0 16px; font-size: 1.15rem; }

.dialog-actions { display: flex; gap: 8px; }

.dialog-actions button { flex: 1; }

#reset-do { background: var(--clay); color: #fff; font-weight: 700; }
#reset-cancel { background: #fff; border: 1px solid var(--line); }

@media (min-width: 800px) {
  h1 { font-size: 1.8rem; }
  .line {
    grid-template-columns: 1fr auto;
    align-items: center;
  }
  .copy { width: auto; min-width: 188px; }
  .fork { grid-template-columns: 1fr 1fr; align-items: start; }
  .fork.three, .fork .fork { grid-template-columns: 1fr; }
}

@media (prefers-reduced-motion: reduce) {
  .toast { transition: none; }
}
