/* 阿吽合戦 — 画面（§11.5）。文字は DOM・PixelMplus12 を 24px 固定。
   角丸なし・CSS transition/ease・半透明の重ね・box-shadow は使わない（演出は Canvas の離散ステップ）。 */

@font-face {
  font-family: 'PixelMplus12';
  src: url('assets/fonts/PixelMplus12-Regular.ttf') format('truetype');
  font-weight: normal;
  font-display: block;
}
@font-face {
  font-family: 'PixelMplus12';
  src: url('assets/fonts/PixelMplus12-Bold.ttf') format('truetype');
  font-weight: bold;
  font-display: block;
}

:root {
  /* 和色（content/palette.json と同じ値） */
  --sumi: #1B1B1B;
  --sumi2: #35323F;
  --ai: #1C2B60;
  --ai1: #3E5DAA;
  --ai2: #8CA8D8;
  --w0: #F6F1E7;
  --w1: #D9D3C5;
  --shu: #C9321D;
  --shu2: #8F1B10;
  --k0: #FFF4B8;
  --k1: #F3D66C;
  --k2: #C89B2F;
  --h1: #DDBE7E;
  --g0: #8B8F95;
  --g1: #5C6067;
  --fs: 24px;
  --lh: 32px;
  color-scheme: dark;
}

*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  border-radius: 0;
  transition: none !important;
  animation: none !important;
}
[hidden] { display: none !important; }

html, body {
  background: var(--sumi);
  color: var(--w0);
  font-family: 'PixelMplus12', monospace;
  font-size: var(--fs);
  line-height: var(--lh);
  -webkit-font-smoothing: none;
  -moz-osx-font-smoothing: unset;
  font-smooth: never;
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
}
body { min-height: 100dvh; overflow-x: hidden; }
#app {
  min-height: 100dvh;
  display: flex;
  justify-content: center;
  align-items: flex-start;
  padding: 16px;
}
.loading { padding: 32px; text-align: center; }

h1, h2 { font-weight: bold; font-size: var(--fs); line-height: var(--lh); }
p { margin: 0; }

/* ---------- 窓・ボタン ---------- */
.panel {
  background: var(--ai);
  border: 2px solid var(--w0);
  outline: 2px solid var(--sumi);
  padding: 16px;
  width: 100%;
  max-width: 760px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}
.btn {
  font: inherit;
  color: var(--w0);
  background: var(--sumi2);
  border: 2px solid var(--w0);
  padding: 6px 16px;
  min-height: 48px;
  cursor: pointer;
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  touch-action: manipulation;
}
.btn:hover:not(:disabled) { background: var(--ai1); }
.btn.primary { background: var(--shu); }
.btn.primary:hover:not(:disabled) { background: var(--shu2); }
.btn.ghost { background: var(--ai); }
.btn:disabled { color: var(--g0); border-color: var(--g1); cursor: default; }
.btn:focus-visible, .card:focus-visible, .opt:focus-visible { outline: 2px solid var(--k1); outline-offset: 2px; }
.row { display: flex; gap: 12px; flex-wrap: wrap; justify-content: flex-end; }
.small { color: var(--w1); }
.note { color: var(--w1); }

/* ---------- タイトル ---------- */
.title-panel { margin-top: 2vh; align-items: center; text-align: center; gap: 16px; max-width: 1000px; }
.logo-text { font-size: 72px; line-height: 80px; letter-spacing: 8px; color: var(--w0); }
.logo-canvas { width: 512px; max-width: 100%; image-rendering: pixelated; }
.title-scene-wrap { line-height: 0; border: 2px solid var(--w0); outline: 2px solid var(--sumi); background: var(--sumi); max-width: 100%; }
.title-scene { display: block; max-width: 100%; height: auto; image-rendering: pixelated; image-rendering: crisp-edges; }
.yomi { color: var(--k1); }
.title-panel .btn.primary { min-width: 240px; }

/* ---------- メニュー・設定 ---------- */
.menu-panel { margin-top: 6vh; max-width: 520px; }
.menu-panel .btn { width: 100%; }
.setup-panel { margin-top: 4vh; }
.opt-row { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 16px; }
.opt-label { min-width: 96px; color: var(--k1); }
.opt-btns { display: flex; flex-wrap: wrap; gap: 8px; }
.opt {
  font: inherit; color: var(--w0); background: var(--sumi2);
  border: 2px solid var(--w0); min-height: 48px; padding: 6px 12px; cursor: pointer;
  touch-action: manipulation;
}
.opt[aria-pressed="true"] { background: var(--k1); color: var(--sumi); }

/* ---------- 試合 ---------- */
[data-scene="match"] { touch-action: none; }
.match-screen {
  width: 100%;
  max-width: 1100px;
  display: grid;
  gap: 12px;
  grid-template-columns: 1fr auto 1fr;
  grid-template-areas:
    "status stage actions"
    "band band band"
    "cards cards cards";
  align-items: start;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
  touch-action: none;
}
.status {
  grid-area: status;
  justify-self: end;
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 8px;
  min-width: 0;
}
.st-name { color: var(--k1); font-weight: bold; }
.st-badge { padding: 0 8px; border: 2px solid currentColor; }
.st-badge.knot { color: var(--h1); }
.st-badge.reach { color: var(--w0); background: var(--shu); border-color: var(--shu); }
.stage-wrap {
  grid-area: stage;
  position: relative;
  justify-self: center;
  border: 2px solid var(--w0);
  outline: 2px solid var(--sumi);
  line-height: 0;
  background: var(--sumi);
}
.stage-canvas {
  display: block;
  image-rendering: pixelated;
  image-rendering: crisp-edges;
}
.actions {
  grid-area: actions;
  justify-self: start;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.btn.act { min-width: 216px; white-space: nowrap; }
.btn.gamble.armed { background: var(--shu); color: var(--w0); }
.qband {
  grid-area: band;
  background: var(--ai);
  border: 2px solid var(--w0);
  padding: 8px 12px;
  min-height: calc(var(--lh) * 2 + 20px);
  word-break: normal;
  overflow-wrap: anywhere;
  line-break: strict;
}
.qno { color: var(--k1); }
.hint { color: var(--w1); }
.ans { color: var(--sumi); background: var(--k1); padding: 0 4px; }
.years { color: var(--k1); font-weight: bold; }
.verdict.ok { color: var(--k1); }
.verdict.ng { color: var(--shu); background: var(--w0); padding: 0 4px; margin-left: 8px; }
.cards {
  grid-area: cards;
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}
.card {
  font: inherit;
  display: flex;
  align-items: center;
  gap: 12px;
  min-height: 56px;
  padding: 4px 8px;
  text-align: left;
  color: var(--w0);
  background: var(--ai);
  border: 2px solid var(--w0);
  cursor: pointer;
  touch-action: none;
}
.card:hover { background: var(--ai1); }
.card .key {
  flex: none;
  min-width: 36px;
  padding: 0 4px;
  text-align: center;
  color: var(--ai);
  background: var(--w0);
}
.card .ctext { flex: 1; min-width: 0; }
.card .mark {
  flex: none;
  min-width: 40px;
  text-align: center;
  color: var(--shu);
  background: var(--w0);
  border: 2px solid var(--shu);
  font-weight: bold;
}
.card .mark:empty { visibility: hidden; }
.card.picked { background: var(--ai1); }
.card.facedown { background: var(--sumi2); }
.card.facedown .ctext, .card.facedown .key { visibility: hidden; }
.card.facedown .mark:empty::after { content: '決定'; }
.card.facedown .mark { visibility: visible; color: var(--w0); background: var(--shu); border-color: var(--shu); min-width: 64px; }
.card.gold { background: var(--k1); color: var(--sumi); border-color: var(--k2); }
.card.gold .key { background: var(--sumi); color: var(--k1); min-width: 64px; }
.card.gold .mark { color: var(--k1); background: var(--sumi); border-color: var(--k2); visibility: visible; }
.card.wrong { border-color: var(--shu); background: var(--sumi2); }
.card.wrong .mark { color: var(--sumi); border-color: var(--sumi); }

/* 朱印（画像が無いときの代わり）。誤は墨印。像に重ねないよう外側の端に寄せる（render.js sealPos と同じ側） */
.seal {
  position: absolute;
  left: 2%;
  top: 10%;
  font-weight: bold;
  font-size: 48px;
  line-height: 52px;
  padding: 6px 4px;
  writing-mode: vertical-rl;
  color: var(--shu);
  background: var(--w0);
  border: 4px solid var(--shu);
  pointer-events: none;
}
.seal[data-side="right"] { left: auto; right: 2%; }
.seal[data-kind="go"] { color: var(--sumi); border-color: var(--sumi); }
.seal[data-kind="kokuho"] { color: var(--w0); background: var(--shu); border-color: var(--k1); }
.seal.inline { position: static; display: inline-block; font-size: var(--fs); line-height: var(--lh); padding: 2px 4px; margin-left: 12px; writing-mode: horizontal-tb; border-width: 2px; }

.pause {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--sumi);
  z-index: 10;
}
.pause .panel { max-width: 360px; align-items: stretch; text-align: center; }

/* ---------- 鑑定 ---------- */
.kantei-panel { flex-direction: row; flex-wrap: wrap; align-items: flex-start; max-width: 900px; gap: 24px; }
.kantei-art { line-height: 0; border: 2px solid var(--w0); }
.kantei-canvas { image-rendering: pixelated; image-rendering: crisp-edges; display: block; }
.kantei-info { flex: 1; min-width: 260px; display: flex; flex-direction: column; gap: 8px; }
.rank { display: flex; align-items: center; }
.rank-name { font-size: 48px; line-height: 56px; font-weight: bold; color: var(--k1); }
.comment { color: var(--w1); }
.newbest { color: var(--sumi); background: var(--k1); padding: 0 8px; align-self: flex-start; }

/* ---------- 結果 ---------- */
.result-panel { max-width: 900px; }
.review { padding-left: 0; list-style: none; display: flex; flex-direction: column; gap: 12px; }
.review li { border: 2px solid var(--w1); padding: 8px 12px; background: var(--sumi2); display: flex; flex-direction: column; gap: 4px; }
.qid { color: var(--k1); }
.era { color: var(--ai2); }
.ra { color: var(--k1); }
.ry { color: var(--w1); }
.re { color: var(--w0); }
.btn.report { align-self: flex-start; min-height: 44px; background: var(--ai); }
.license { color: var(--g0); text-align: right; }

/* ---------- ギャラリー ---------- */
.gallery-panel { max-width: 1000px; align-items: flex-start; }
.gallery-panel .stage-wrap { justify-self: start; }

/* ---------- スマホ（幅<900）：舞台／問題帯／札縦積み ---------- */
@media (max-width: 899px) {
  #app { padding: 16px; }
  .match-screen {
    grid-template-columns: minmax(0, 1fr);
    grid-template-areas: "status" "stage" "band" "cards" "actions";
    gap: 8px;
  }
  .status {
    justify-self: stretch;
    flex-direction: row;
    flex-wrap: wrap;
    align-items: center;
    gap: 4px 12px;
  }
  .st-q { margin-left: auto; }
  .cards { grid-template-columns: minmax(0, 1fr); }
  .actions { justify-self: stretch; flex-direction: row; }
  /* 高さ固定・1行：文言が変わっても（一刀彫り→宣言中）行が伸びて札を押し下げない */
  .actions .btn { flex: 1; min-width: 0; padding: 6px 8px; height: 48px; white-space: nowrap; overflow: hidden; }
  .logo-text { font-size: 48px; line-height: 56px; letter-spacing: 4px; }
  .kantei-panel { flex-direction: column; align-items: center; }
  .kantei-info { min-width: 0; width: 100%; }
}
@media (max-width: 899px) {
  .result-panel .row, .setup-panel .row { flex-direction: column-reverse; }
  .result-panel .row .btn, .setup-panel .row .btn { width: 100%; }
}

/* ======================================================================
   ふたりで対戦（オンライン・P2）§11.5
   ====================================================================== */
.online-panel, .lobby-panel { margin-top: 4vh; max-width: 760px; }
.text-in {
  font: inherit; color: var(--sumi); background: var(--w0);
  border: 2px solid var(--w0); outline: 2px solid var(--sumi);
  min-height: 48px; padding: 4px 12px; width: 100%; min-width: 0;
}
.text-in:focus-visible { outline: 2px solid var(--k1); outline-offset: 2px; }
.field { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 16px; }
.field .text-in { flex: 1; min-width: 200px; }
.join-row { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 12px; }
.join-row .code-in { width: 160px; flex: none; text-transform: uppercase; letter-spacing: 6px; text-align: center; }
.online-msg { color: var(--k1); min-height: var(--lh); }
.online-msg:empty { min-height: 0; }
.online-panel > .btn, .online-panel .row .btn { min-width: 200px; }
.row.left { justify-content: flex-start; align-items: center; }

.invite { display: flex; flex-wrap: wrap; gap: 12px 16px; align-items: center; }
.room-code {
  font-size: 72px; line-height: 80px; font-weight: bold; letter-spacing: 12px;
  color: var(--sumi); background: var(--k1); padding: 0 8px 0 20px; border: 2px solid var(--w0);
}
.invite-r { flex: 1; min-width: 240px; display: flex; flex-direction: column; gap: 8px; }
.url-in { color: var(--sumi); }
.plist { list-style: none; padding: 0; display: flex; flex-direction: column; gap: 8px; }
.plist li { display: flex; flex-wrap: wrap; align-items: center; gap: 4px 12px; padding: 8px 12px; background: var(--sumi2); border: 2px solid var(--w1); }
.plist li.me { border-color: var(--k1); }
.plist .role { color: var(--k1); }
.plist .pname.empty { color: var(--g0); }
.plist .pstate { margin-left: auto; color: var(--w1); }
.plist .pstate.ok { color: var(--sumi); background: var(--k1); padding: 0 8px; }
.plist .pstate.off { color: var(--w0); background: var(--shu2); padding: 0 8px; }
.opt:disabled { color: var(--g0); border-color: var(--g1); cursor: default; }
.opt[aria-pressed="true"]:disabled { color: var(--sumi); background: var(--k1); border-color: var(--w0); }
.lobby-status { color: var(--w0); }
.btn.ready-btn { min-width: 240px; }

/* 「あなた」の朱印（名札） */
.you-seal { color: var(--w0); background: var(--shu); border: 2px solid var(--shu2); padding: 0 4px; font-weight: bold; }

/* 接続の帯（画面の下に固定） */
.net-banner {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 20;
  padding: 8px 16px; text-align: center;
  color: var(--sumi); background: var(--k1); border-top: 2px solid var(--sumi);
}

/* ---------- 対戦の試合画面：左右の舞台を合わせて南大門 ---------- */
.match-screen.vs {
  grid-template-columns: 1fr 1fr;
  grid-template-areas:
    "s0 s1"
    "band band"
    "cards cards";
  column-gap: 0;
  row-gap: 8px;
}
/* 名札の高さが左右で違っても、舞台の下端を揃える（門が段違いにならない） */
.vs-side { display: flex; flex-direction: column; gap: 4px; min-width: 0; align-self: end; }
.vs-side.side-0 { grid-area: s0; align-items: flex-end; }
.vs-side.side-1 { grid-area: s1; align-items: flex-start; }
.vs-side .stage-wrap { justify-self: auto; }
/* 中央で門が繋がるよう、内側の枠線を消す */
.vs-side .stage-wrap { outline: 0; }
.vs-side.side-0 .stage-wrap { border-right: 0; }
.vs-side.side-1 .stage-wrap { border-left: 0; }
/* 名札：自分の舞台の外側の端から読む（左＝左寄せ・右＝右寄せ）。中央に区切り線と余白。
   行は3段固定（名前／段・フシ／リーチ・決定などの一時札）なので、札が出入りしても舞台が上下しない */
.vs-status { display: flex; flex-direction: column; justify-content: flex-start; gap: 0; min-height: 108px; min-width: 0; max-width: 100%; }
.vs-status.side-0 { align-items: flex-start; text-align: left; padding: 0 16px 0 4px; border-right: 2px solid var(--g1); }
.vs-status.side-1 { align-items: flex-end; text-align: right; padding: 0 4px 0 16px; border-left: 2px solid var(--g1); }
.st-line { display: flex; flex-wrap: wrap; gap: 0 8px; align-items: center; min-width: 0; max-width: 100%; min-height: 36px; }
.vs-status.side-0 .st-line { justify-content: flex-start; }
.vs-status.side-1 .st-line { justify-content: flex-end; }
.st-badge.blink-off { visibility: hidden; }
.st-stage .stg-short { display: none; }
.st-pname { color: var(--w1); overflow-wrap: anywhere; min-width: 0; }
.vs-status.me .st-pname { color: var(--w0); }
.st-badge.done { color: var(--w0); background: var(--shu); border-color: var(--shu); }
.st-badge.gamble { color: var(--sumi); background: var(--k1); border-color: var(--k1); }
.st-badge.off { color: var(--w0); background: var(--g1); border-color: var(--g1); }
.match-screen.vs .band-row { margin-top: 4px; }
/* 問題帯の右に「やり直し」「一刀彫り」（スマホは帯の下に横並び） */
.band-row { grid-area: band; display: flex; gap: 8px; align-items: stretch; min-width: 0; }
.band-row .qband { flex: 1; min-width: 0; }
.match-screen.vs .actions { flex-direction: column; justify-content: flex-start; }
.match-screen.vs .btn.act { min-width: 232px; }
.match-screen.vs .card.gold .mark:empty { visibility: hidden; }
.vs-verdicts { margin-left: 8px; }
.vs-verdicts .verdict { margin-left: 8px; white-space: nowrap; }
.verdict.ok { color: var(--sumi); background: var(--k1); padding: 0 4px; }
/* 相手が選んだ札の印（運／快） */
.card .omark { flex: none; min-width: 0; text-align: center; color: var(--w0); background: var(--ai1); font-weight: bold; padding: 0 4px; }
.card .omark:empty { display: none; }
.card.gold .omark { background: var(--sumi2); }
.card.facedown .omark { visibility: hidden; }

/* ---------- 鑑定の儀（対戦） ---------- */
.judge-panel {
  max-width: 1200px;
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto;
  grid-template-areas: "a0 info a1";
  align-items: start;
  gap: 16px;
  background: var(--sumi);
}
.judge-panel .kantei-art { position: relative; }
.judge-panel .kantei-art.side-0 { grid-area: a0; }
.judge-panel .kantei-art.side-1 { grid-area: a1; }
.judge-info { grid-area: info; display: flex; flex-direction: column; gap: 8px; min-width: 0; }
.judge-scroll { background: var(--w0); color: var(--sumi); border: 2px solid var(--h1); outline: 4px solid var(--shu2); padding: 8px 12px; display: flex; flex-direction: column; gap: 8px; }
.judge-head { font-weight: bold; color: var(--shu2); }
.judge-rows { display: flex; flex-direction: column; gap: 8px; }
.judge-row { border-top: 2px solid var(--w1); padding-top: 4px; }
.judge-row .st-name { color: var(--shu2); font-weight: bold; margin-right: 8px; }
.judge-row .st-pname { color: var(--sumi2); margin-left: 8px; }
.judge-row .rank-name { color: var(--sumi); font-size: 48px; line-height: 56px; }
.judge-row .deki { margin-left: 16px; }
.judge-row .comment, .judge-row .small, .judge-scroll .small { color: var(--sumi2); }
.judge-seals { position: absolute; top: 8px; left: 8px; display: flex; flex-direction: column; gap: 4px; line-height: var(--lh); }
.kantei-art.side-1 .judge-seals { left: auto; right: 8px; }
.review-panel { max-width: 1200px; margin-top: 12px; background: transparent; border: 0; outline: 0; padding: 0; }
.review-panel:has(.review[hidden]) { display: none; }
#app[data-scene="judge"] { flex-direction: column; align-items: center; }

@media (max-width: 899px) {
  .room-code { font-size: 48px; line-height: 56px; letter-spacing: 8px; }
  .match-screen.vs .cards { grid-template-columns: minmax(0, 1fr); }
  .band-row { flex-direction: column; }
  .match-screen.vs .actions { flex-direction: row; }
  .match-screen.vs .actions .btn { flex: 1; min-width: 0; }
  /* スマホ：名札は列いっぱい（舞台とほぼ同じ幅）。名前は1行に独立、段は「段6」の短い形で残す */
  .vs-side .vs-status { align-self: stretch; }
  .vs-status .st-pname { flex-basis: 100%; line-height: 36px; }
  .vs-status.side-1 .st-pname { text-align: right; }
  .vs-status.side-0 { padding: 0 8px 0 2px; }
  .vs-status.side-1 { padding: 0 2px 0 8px; }
  .vs-status .st-badge { padding: 0 4px; }
  .st-stage .stg-long { display: none; }
  .st-stage .stg-short { display: inline; }
  .vs-status { min-height: 144px; } /* 名前2行＋段＋一時札。札を押したとき「決定」が出ても下が動かない高さ */
  .vs-verdicts { display: block; margin-left: 0; }
  .vs-verdicts .verdict:first-child { margin-left: 0; }
  .judge-panel {
    grid-template-columns: 1fr 1fr;
    grid-template-areas: "a0 a1" "info info";
    gap: 8px;
  }
  .judge-panel .kantei-art.side-0 { justify-self: end; }
  .judge-panel .kantei-art.side-1 { justify-self: start; }
  .judge-panel .row { flex-direction: column-reverse; }
  .judge-panel .row .btn { width: 100%; }
  .lobby-panel .row { flex-direction: column-reverse; }
  .lobby-panel .row .btn { width: 100%; }
  .online-panel .row { flex-direction: column-reverse; }
  .online-panel .row .btn, .online-panel > .btn { width: 100%; }
}
