:root {
  --wood: #4a2c17;
  --wood-dark: #2e1a0c;
  --paper: #fbf6e9;
  --paper-edge: #e8dcc0;
  --ink: #1f1a14;
  --ink-soft: #4d4237;
  --navy: #1d2b4f;
  --navy-soft: #e6ebf5;
  --gold: #d4af37;
  --gold-dark: #7a5c00;
  --red: #b3261e;
  --red-soft: #fbe9e7;
  --green: #1e6b3a;
  --green-soft: #e3f2e7;
  --focus: #0b5fff;
  --radius: 10px;
  --serif: "Hiragino Mincho ProN", "Yu Mincho", "YuMincho", "BIZ UDMincho", "MS PMincho", serif;
  --sans: "Hiragino Kaku Gothic ProN", "Hiragino Sans", "BIZ UDPGothic", "Yu Gothic UI", "Yu Gothic", "Meiryo", sans-serif;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  font-family: var(--sans);
  font-size: 17px;
  line-height: 1.7;
  color: var(--ink);
  background:
    repeating-linear-gradient(90deg, rgba(0,0,0,.035) 0 2px, transparent 2px 64px),
    #efe4cc;
  min-height: 100vh;
}
.app { max-width: 860px; margin: 0 auto; padding: 0 16px 24px; }
h1, h2, h3 { font-family: var(--serif); line-height: 1.35; }
:focus-visible { outline: 3px solid var(--focus); outline-offset: 2px; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

/* ---------- 画面切り替え ---------- */
.screen { display: none; }
.app[data-screen="intro"] .screen-intro,
.app[data-screen="court"] .screen-court,
.app[data-screen="result"] .screen-result { display: block; }

/* ---------- ヘッダー ---------- */
.court-header {
  position: relative;
  margin: 0 -16px;
  padding: 18px 16px 16px;
  text-align: center;
  color: #fff8e6;
  background: linear-gradient(180deg, var(--wood) 0%, var(--wood-dark) 100%);
  border-bottom: 6px solid var(--gold);
  overflow: hidden;
}
.pillars {
  position: absolute; inset: 0;
  background: repeating-linear-gradient(90deg, rgba(255,255,255,.06) 0 14px, transparent 14px 28px);
  pointer-events: none;
}
.court-name { position: relative; margin: 0; font-size: .85rem; letter-spacing: .3em; color: #f3dfa2; }
.title { position: relative; margin: 2px 0 0; font-size: clamp(2rem, 7vw, 3rem); letter-spacing: .12em; text-shadow: 0 3px 0 #000; }
.title .scale { display: inline-block; margin-right: .2em; color: var(--gold); }
.subtitle { position: relative; margin: 0; font-family: var(--serif); color: #f3dfa2; }

.demo-banner {
  margin: 12px 0;
  padding: 8px 12px;
  font-size: .9rem;
  background: #fff;
  border: 2px dashed var(--gold-dark);
  border-radius: var(--radius);
  color: var(--ink);
}

/* ---------- 紙 ---------- */
.paper {
  background: var(--paper);
  border: 1px solid var(--paper-edge);
  border-radius: var(--radius);
  box-shadow: 0 6px 0 var(--paper-edge), 0 10px 24px rgba(46, 26, 12, .18);
  padding: 20px;
}
.case-no { margin: 0 0 12px; font-size: 1.05rem; color: var(--ink-soft); border-bottom: 2px double var(--ink-soft); padding-bottom: 6px; }
.tag {
  display: inline-block;
  margin-right: 8px;
  padding: 0 10px;
  font-size: .8rem;
  font-weight: bold;
  color: #fff;
  background: var(--navy);
  border-radius: 999px;
  vertical-align: middle;
}
.topic-box, .kw-box { margin: 12px 0; padding: 12px; background: #fff; border-left: 6px solid var(--navy); border-radius: 6px; }
.topic-box p { margin: 6px 0 0; font-size: 1.1rem; }
.rules { padding-left: 1.2em; }
.rules li { margin: 4px 0; }

/* ---------- 指定ワード ---------- */
.kw-list { display: flex; flex-wrap: wrap; gap: 8px; margin: 6px 0 0; padding: 0; list-style: none; }
.kw {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 4px 10px 4px 12px;
  border: 2px dashed var(--ink-soft);
  border-radius: 999px;
  background: #fff;
}
.kw-word { font-family: var(--serif); font-weight: bold; font-size: 1.25rem; }
.kw-state { font-size: .78rem; padding: 0 6px; border-radius: 999px; background: #eee6d6; color: var(--ink-soft); }
.kw[data-state="won"] { border-style: solid; border-color: var(--green); background: var(--green-soft); }
.kw[data-state="won"] .kw-state { background: var(--green); color: #fff; }
.kw[data-state="won"] .kw-state::before { content: "✓ "; }
.kw-list-intro .kw-state { display: none; }
.kw-list-intro .kw-word { font-size: 1.6rem; }

/* ---------- 難易度・ワード抽選 ---------- */
.difficulty { margin: 12px 0; padding: 12px; background: #fff; border: 0; border-left: 6px solid var(--navy); border-radius: 6px; }
.difficulty legend { float: left; margin-bottom: 8px; }
.diff-options { clear: both; display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 8px; }
.diff-option { position: relative; display: block; cursor: pointer; }
.diff-option input { position: absolute; opacity: 0; inset: 0; margin: 0; cursor: pointer; }
.diff-label {
  display: block; min-height: 44px; padding: 8px 6px; text-align: center;
  font-family: var(--serif); font-weight: bold; font-size: 1.15rem; line-height: 1.3;
  border: 2px solid var(--ink-soft); border-radius: 8px; background: var(--paper);
}
.diff-label small { display: block; font-family: var(--sans); font-weight: normal; font-size: .78rem; color: var(--ink-soft); }
.diff-option input:checked + .diff-label { background: var(--navy); border-color: var(--navy); color: #fff; }
.diff-option input:checked + .diff-label small { color: #dfe5f2; }
.diff-option input:checked + .diff-label::before { content: "✓ "; }
.diff-option input:focus-visible + .diff-label { outline: 3px solid var(--focus); outline-offset: 2px; }
.diff-option input:disabled + .diff-label { opacity: .6; cursor: not-allowed; }
.diff-note, .kw-note { margin: 8px 0 0; font-size: .85rem; color: var(--ink-soft); }
.kw-box-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; flex-wrap: wrap; }
.btn-reroll { min-height: 40px; padding: 4px 12px; font-size: .9rem; }

/* ---------- ボタン ---------- */
.btn {
  font: inherit;
  font-weight: bold;
  min-height: 44px;
  padding: 8px 18px;
  border-radius: 8px;
  border: 2px solid var(--wood-dark);
  cursor: pointer;
}
.btn:disabled { cursor: not-allowed; opacity: .55; }
.btn-primary { color: #fff; background: var(--red); border-color: #7a1712; box-shadow: 0 4px 0 #7a1712; }
.btn-primary:not(:disabled):active { transform: translateY(3px); box-shadow: 0 1px 0 #7a1712; }
.btn-ghost { color: var(--ink); background: #fff; }
.btn-link { background: none; border: none; color: var(--navy); text-decoration: underline; font-weight: normal; min-height: 0; padding: 4px; }
.btn-start { display: block; width: 100%; margin-top: 16px; font-family: var(--serif); font-size: 1.4rem; letter-spacing: .3em; padding: 12px; }

/* ---------- 法廷：ステータス ---------- */
.status-bar {
  position: sticky; top: 0; z-index: 5;
  margin: 0 -16px;
  padding: 8px 16px 8px;
  background: var(--paper);
  border-bottom: 3px solid var(--wood);
  box-shadow: 0 4px 10px rgba(0,0,0,.08);
}
.status-row { display: flex; align-items: center; justify-content: space-between; gap: 8px; flex-wrap: wrap; }
.round-label, .score-label { margin: 0; font-family: var(--serif); font-weight: bold; }
.round-label b, .score-label b { font-size: 1.35rem; color: var(--navy); }
.diff-now { margin: 0; padding: 0 10px; font-size: .85rem; font-weight: bold; color: #fff; background: var(--navy); border-radius: 999px; }
.kw-court { min-width: 0; flex: 1 1 260px; }
.kw-count { margin: 0; font-size: .8rem; font-weight: bold; color: var(--ink-soft); }
.kw-list-court { gap: 6px; margin-top: 2px; }
.kw-list-court .kw { padding: 2px 8px 2px 10px; }
.kw-list-court .kw-word { font-size: 1.05rem; }
.timer { display: flex; align-items: baseline; gap: 6px; font-weight: bold; }
.timer-label { font-size: .8rem; color: var(--ink-soft); }
.timer-num { font-family: var(--serif); font-size: 1.9rem; font-variant-numeric: tabular-nums; min-width: 4.2em; text-align: right; color: var(--navy); }
.timer-note { font-size: .8rem; color: var(--ink-soft); }
.timer[data-state="warn"] .timer-num { color: var(--gold-dark); }
.timer[data-state="danger"] .timer-num { color: var(--red); }
.timer[data-state="danger"] .timer-label::after { content: "（急いで！）"; color: var(--red); }
.timer-bar { height: 8px; margin: 6px 0; background: #e2d6bc; border-radius: 99px; overflow: hidden; }
.timer-bar i { display: block; height: 100%; background: var(--navy); transform-origin: left; transition: transform .1s linear; }
.timer-bar[data-state="warn"] i { background: var(--gold-dark); }
.timer-bar[data-state="danger"] i { background: var(--red); }
.topic-line { margin: 0; font-size: .92rem; }

/* ---------- 発言履歴 ---------- */
.log { list-style: none; margin: 16px 0; padding: 0; display: flex; flex-direction: column; gap: 14px; }
.msg { display: flex; flex-direction: column; max-width: 88%; scroll-margin-bottom: 220px; scroll-margin-top: 150px; }
.who { font-size: .82rem; font-weight: bold; color: var(--ink-soft); margin-bottom: 2px; }
.who small { margin-left: 6px; font-weight: normal; }
.bubble { margin: 0; padding: 10px 14px; border-radius: 12px; white-space: pre-wrap; overflow-wrap: anywhere; min-height: 1.7em; }
.msg-prosecutor { align-self: flex-start; }
.msg-prosecutor .bubble { background: var(--navy); color: #fff; border-top-left-radius: 2px; font-family: var(--serif); font-size: 1.05rem; }
.msg-prosecutor.msg-reaction .bubble { background: var(--navy-soft); color: var(--navy); border: 2px solid var(--navy); }
.msg-defendant { align-self: flex-end; align-items: flex-end; }
.msg-defendant .bubble { background: #fff; border: 2px solid var(--wood); border-top-right-radius: 2px; }
.msg-timeout .bubble { background: #eee6d6; color: var(--ink-soft); border-style: dashed; }

/* ---------- 入力 ---------- */
.answer-form {
  position: sticky; bottom: 0; z-index: 5;
  margin: 0 -16px;
  padding: 10px 16px 12px;
  background: var(--wood);
  color: #fff8e6;
  border-top: 4px solid var(--gold);
}
.form-head { display: flex; justify-content: space-between; align-items: baseline; }
.answer-label { font-weight: bold; font-family: var(--serif); font-size: 1.05rem; }
.counter { font-size: .9rem; font-variant-numeric: tabular-nums; padding: 0 8px; border-radius: 6px; background: rgba(0,0,0,.25); }
.counter[data-state="low"] { color: #ffe08a; }
.counter[data-state="full"] { color: #fff; background: var(--red); }
.form-body { display: flex; gap: 8px; margin-top: 4px; }
.answer-input {
  flex: 1; min-width: 0;
  font: inherit; font-size: 1.05rem; line-height: 1.5;
  padding: 8px 10px;
  border: 3px solid var(--gold);
  border-radius: 8px;
  color: var(--ink);
  background: #fff;
  resize: none;
}
.answer-input:disabled { background: #d9cfbd; color: #3b3127; border-color: #a99b7f; }
.answer-input::placeholder { color: #6b5e50; }
.btn-submit { flex: none; align-self: stretch; }
.hint { margin: 4px 0 0; font-size: .8rem; color: #f3dfa2; }
.form-msg { margin: 4px 0 0; font-weight: bold; color: #ffd2cc; min-height: 0; }
.form-msg:empty { display: none; }
.btn-skip { margin-top: 6px; width: 100%; }
.court-foot { text-align: right; margin: 8px 0 0; }

/* ---------- 異議あり！ ---------- */
.objection {
  position: fixed; left: 50%; top: 40%; z-index: 20;
  transform: translate(-50%, -50%) scale(0) rotate(-8deg);
  padding: 10px 28px;
  font-family: var(--serif); font-weight: bold; font-size: clamp(2.2rem, 10vw, 4rem);
  color: #fff; background: var(--red);
  border: 6px solid #fff; border-radius: 14px;
  box-shadow: 0 10px 30px rgba(0,0,0,.4);
  pointer-events: none; opacity: 0;
}
.objection.show { animation: objection 1.4s ease-out forwards; }
@keyframes objection {
  0% { opacity: 0; transform: translate(-50%, -50%) scale(.2) rotate(-8deg); }
  15% { opacity: 1; transform: translate(-50%, -50%) scale(1.15) rotate(-8deg); }
  25%, 80% { opacity: 1; transform: translate(-50%, -50%) scale(1) rotate(-8deg); }
  100% { opacity: 0; transform: translate(-50%, -50%) scale(1) rotate(-8deg); }
}

/* ---------- 結果 ---------- */
.screen-result { padding-top: 8px; }
.result-paper:focus { outline: none; }
.result-title { text-align: center; font-size: 2rem; letter-spacing: .5em; margin: 0 0 8px; }
.stamp { display: flex; justify-content: center; margin: 0 0 4px; padding: 16px 0; overflow: hidden; }
.stamp span {
  display: inline-block;
  padding: 6px 28px;
  font-family: var(--serif); font-weight: bold; font-size: clamp(3rem, 16vw, 5rem); letter-spacing: .15em;
  border: 8px double currentColor; border-radius: 12px;
  transform: rotate(-6deg);
  animation: stamp .5s cubic-bezier(.2, 1.6, .4, 1) both;
}
.stamp-guilty { color: var(--red); }
.stamp-innocent { color: var(--green); }
@keyframes stamp { from { transform: rotate(-6deg) scale(2.4); opacity: 0; } to { transform: rotate(-6deg) scale(1); opacity: 1; } }
.headline { text-align: center; font-family: var(--serif); font-size: 1.15rem; font-weight: bold; }
.conditions { list-style: none; padding: 0; margin: 0; }
.cond { display: flex; gap: 10px; align-items: flex-start; padding: 8px 10px; margin: 6px 0; border-radius: 8px; }
.cond small { display: block; color: var(--ink-soft); }
.cond .mark { font-weight: bold; font-size: 1.3rem; line-height: 1.3; }
.cond-ok { background: var(--green-soft); }
.cond-ok .mark { color: var(--green); }
.cond-ng { background: var(--red-soft); }
.cond-ng .mark { color: var(--red); }
h3 small { font-family: var(--sans); font-size: .8rem; font-weight: normal; color: var(--ink-soft); }

.total-box { text-align: center; margin: 20px 0; padding: 14px; background: var(--navy); color: #fff; border-radius: var(--radius); }
.total-box p { margin: 0; }
.total-num b { font-family: var(--serif); font-size: 3rem; color: var(--gold); }
.rank { font-family: var(--serif); font-size: 1.15rem; }
.total-box .note { font-size: .85rem; color: #dfe5f2; }
.total-num small { margin-left: 6px; font-size: .95rem; color: #dfe5f2; }
.setup-box { margin: 12px 0; padding: 12px 14px; background: #fff; border-left: 6px solid var(--navy); border-radius: 6px; }
.setup-box h3 { margin: 0 0 6px; }
.setup-dl { display: grid; grid-template-columns: auto minmax(0, 1fr); gap: 4px 12px; margin: 0; align-items: center; }
.setup-dl dt { font-weight: bold; color: var(--ink-soft); }
.setup-dl dd { margin: 0; }
.kw-list-result { margin: 0; }
.kw { white-space: nowrap; max-width: 100%; }
.kw-word { overflow-wrap: anywhere; white-space: normal; }
.setup-dl dd:last-child, .setup-dl dt:nth-last-child(2) { grid-column: 1 / -1; }

.round-card { margin: 10px 0; background: #fff; border: 1px solid var(--paper-edge); border-radius: var(--radius); }
.round-card summary { display: flex; justify-content: space-between; padding: 10px 14px; cursor: pointer; font-weight: bold; font-family: var(--serif); background: #f4ecda; border-radius: var(--radius); }
.plus { color: var(--green); }
.minus { color: var(--red); }
.zero { color: var(--ink-soft); }
.qa { display: grid; grid-template-columns: auto minmax(0, 1fr); gap: 2px 10px; margin: 10px 14px; font-size: .95rem; }
.qa dt { font-weight: bold; color: var(--ink-soft); }
.qa dd { margin: 0; overflow-wrap: anywhere; }
.items { list-style: none; margin: 0; padding: 0 14px 10px; }
.item { display: flex; gap: 10px; padding: 8px 0; border-top: 1px dashed var(--paper-edge); }
.item .pts { flex: none; width: 3.6em; font-weight: bold; font-variant-numeric: tabular-nums; text-align: right; font-size: 1.05rem; }
.item.zero .pts { color: var(--ink-soft); }
.item > div { flex: 1; min-width: 0; }
.item p { margin: 0; }
.cond > span:last-child { min-width: 0; }
.headline, .result-paper { overflow-wrap: anywhere; }
.item-label { font-weight: bold; color: var(--ink); }
.item-reason { font-size: .92rem; color: var(--ink); }
.item-evidence { font-size: .88rem; color: var(--ink-soft); overflow-wrap: anywhere; }
mark { background: #ffe58a; color: var(--ink); padding: 0 2px; border-radius: 3px; }
.limits { margin-top: 18px; padding: 12px 14px; font-size: .92rem; background: #fff; border-left: 6px solid var(--gold-dark); border-radius: 6px; }
.limits h3 { margin-top: 0; }
.limits ul { padding-left: 1.2em; margin-bottom: 0; }
.share-box { margin-top: 18px; padding: 12px 14px; display: flex; flex-direction: column; align-items: center; gap: 4px;
  background: var(--navy-soft); border: 2px dashed var(--navy); border-radius: var(--radius); text-align: center; }
.btn-copy { width: 100%; max-width: 360px; min-height: 48px; color: var(--navy); background: #fff; border-color: var(--navy); box-shadow: 0 3px 0 var(--navy); }
.btn-copy:active { transform: translateY(2px); box-shadow: 0 1px 0 var(--navy); }
.share-box small { font-size: .82rem; color: var(--ink-soft); }
.copy-status { margin: 0; min-height: 1.7em; font-weight: bold; }
.copy-status[data-state="ok"] { color: var(--green); }
.copy-status[data-state="ng"] { color: var(--red); }
.copy-fallback { display: block; width: 100%; max-width: 480px; padding: 8px 10px; font: inherit; font-size: 16px; line-height: 1.6;
  color: var(--ink); background: #fff; border: 2px solid var(--navy); border-radius: 6px; resize: none; }
.copy-fallback[hidden] { display: none; }
.result-actions { display: flex; flex-wrap: wrap; gap: 10px; margin-top: 18px; }
.result-action { flex: 1 1 220px; display: flex; flex-direction: column; gap: 4px; }
.result-action .btn { width: 100%; }
.result-action small { font-size: .82rem; color: var(--ink-soft); text-align: center; }

/* ---------- スマホ ---------- */
@media (max-width: 560px) {
  body { font-size: 16px; }
  .paper { padding: 14px; }
  .court-header { padding: 12px 16px 10px; }
  .timer-num { font-size: 1.6rem; min-width: 3.8em; }
  .msg { max-width: 94%; }
  .form-body { flex-direction: column; }
  .btn-submit { width: 100%; }
  .hint { display: none; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; transition: none !important; }
}
