:root {
  --bg: #0f3d2e;
  --fg: #f2efe6;
  --muted: #b8c4bc;
  --panel: #14513c;
  --link: #ffd77a;
}

* { box-sizing: border-box; }

/* iPhone の Safari が、横向きにしたときに文字を勝手に大きくするのを止める */
html {
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--fg);
  font-family: system-ui, -apple-system, "Hiragino Sans", "Noto Sans JP", sans-serif;
  line-height: 1.7;
}

a { color: var(--link); }

header, footer, main.text {
  max-width: 720px;
  margin: 0 auto;
  padding: 8px 16px;
}

header {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
}
header h1 { font-size: 1.1rem; margin: 0; }
header h1 a { color: var(--fg); text-decoration: none; }
header nav a { margin-left: 12px; font-size: 0.9rem; }

footer {
  font-size: 0.8rem;
  color: var(--muted);
  text-align: center;
  padding-bottom: 24px;
}
footer a { margin: 0 8px; }

/* 遊ぶページは、1画面に収める。ページ自体はスクロールさせない。
   大きい画面では、この幅と高さで頭打ちにする */
html:has(body.home) {
  height: 100dvh;
  background: var(--bg);
  display: grid;
  place-items: center;
}
body.home {
  width: 100%;
  max-width: 880px;
  height: 100%;
  max-height: 580px;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  line-height: 1.4;
}
body.home header,
body.home footer {
  max-width: none;
  width: 100%;
  flex: none;
}
body.home header { padding: 2px 12px; }
body.home header h1 { font-size: 0.95rem; }
body.home footer {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: center;
  column-gap: 12px;
  row-gap: 0;
  padding: 2px 12px 4px;
}
body.home footer p { margin: 0; }

/* 下の帯の文字の広告。ステマ規制のため「PR」を必ず付ける。広告のリンクが無いあいだは出さない */
.ad-text {
  display: inline-flex;
  align-items: baseline;
  gap: 6px;
  min-width: 0;
  max-width: 100%;
  white-space: nowrap;
  overflow: hidden;
}
.ad-text:not(:has(a)) { display: none; }
.ad-text .pr {
  flex: none;
  padding: 0 4px;
  border: 1px solid var(--muted);
  border-radius: 3px;
  font-size: 0.65rem;
  line-height: 1.3;
  color: var(--muted);
}
.ad-text a {
  margin: 0;
  overflow: hidden;
  text-overflow: ellipsis;
}
/* 広告ブロックで広告が止められた枠は、「PR」ごと隠す（site/ads.js の hideIfBlocked） */
.ad-blocked { display: none !important; }
/* A8.net の計測用の 1×1 の画像は、場所を取らせない */
.ad-text img[width="1"],
.ad img[width="1"] { position: absolute; width: 1px; height: 1px; }
/* 横向きでは、帯を1行のままにする（2行になると盤面が低くなる）。入りきらない広告の文は「…」で切る */
@media (orientation: landscape) {
  body.home footer { flex-wrap: nowrap; }
  body.home footer > * { flex: none; }
  body.home footer .ad-text { flex: 0 1 auto; }
}

/* ゲームは残りの全面。広告は右。仮の枠も本広告も無いあいだは幅を取らない */
.play {
  display: flex;
  flex-direction: row;
  align-items: stretch;
  flex: 1 1 auto;
  min-height: 0;
  width: 100%;
  gap: 8px;
  padding: 0 8px 4px;
}
.game {
  flex: 1 1 0;
  width: 100%;
  max-width: none;
  height: 100%;
  min-width: 0;
  min-height: 0;
  border: 0;
  display: block;
  background: #000;
}

/* 広告枠。ステマ規制のため「PR」の表示を必ず付ける */
.ad {
  flex: 0 0 300px;
  width: 300px;
  max-width: 336px;
  max-height: 100%;
  overflow: auto;
  align-self: stretch;
  text-align: center;
  /* 300×250 のバナーがちょうど収まるよう、左右の余白は付けない */
  padding: 0;
}
/* バナーの画像の下に、文字の行の分のすき間を作らない */
.ad a img { display: block; margin: 0 auto; }
/* 仮の枠も、リンク・画像・広告タグも無いあいだは盤面を狭めない（広告を入れる <script> だけの枠も隠す）。
   枠を出すときは盤面を 880px のままにし、右へ 300px 足す（合わせて 1200px）。
   それより狭い窓では枠を出さず、盤面だけにする */
.ad:not(:has(a, iframe, img, ins, .ad-pending)) { display: none; }
@media (min-width: 1200px) {
  body.home { max-width: 1200px; }
  /* 右に広告の列が出ているときは、下の帯を盤面の真ん中にそろえる（ページ全体の真ん中だと、右に寄って見える）。
     右に足す余白は、広告の列の幅（300px）と盤面との間（8px） */
  body.home:has(.play > .ad:not(.ad-mobile, .ad-blocked) :is(a, iframe, img, ins, .ad-pending)) footer {
    padding-right: calc(12px + 300px + 8px);
  }
}
@media (max-width: 1199px) {
  .play .ad { display: none; }
}
/* スマホを縦にしたときは、盤面の下に横長の枠（.ad-mobile。320×50・320×100）を出す。
   右の枠の 300×250 は、ここでは出さない（上の max-width: 1199px で隠れる）。
   合う広告が無いとき（a8Ad("mobile") が何も入れないとき）は枠ごと出さず、盤面に高さを回す */
.play .ad-mobile { display: none; }
@media (max-width: 1199px) and (orientation: portrait) {
  body.home { max-height: none; }
  .play { flex-direction: column; }
  .play .ad.ad-mobile {
    display: block;
    flex: none;
    width: 100%;
    max-width: none;
    max-height: none;
    overflow: visible;
  }
  .play .ad.ad-mobile .pr { text-align: center; }
  .play .ad.ad-mobile:not(:has(a, iframe, img, ins)) { display: none; }
}
/* PC で縦に余裕があるときは、下の帯のさらに下に横長の枠（.ad-wide。728×90・468×60）を出す。
   枠の高さは決めておき（出る広告で盤面の大きさが変わらないように）、そのぶんページの高さの上限も伸ばす。
   縦に余裕の無い画面（ノート PC の低い窓など）では出さず、盤面を縮めない */
.ad-wide { display: none; }
@media (min-width: 800px) and (min-height: 720px) and (orientation: landscape) {
  body.home:has(.ad-wide:not(.ad-blocked) :is(a, img)) { max-height: calc(580px + 112px); }
  body.home .ad.ad-wide {
    display: block;
    flex: none;
    width: 100%;
    max-width: none;
    height: 112px;
    max-height: none;
    overflow: hidden;
    padding-bottom: 4px;
  }
  body.home .ad.ad-wide:not(:has(a, img)) { display: none; }
  body.home .ad.ad-wide .pr { text-align: center; }
}
@media (min-width: 1200px) and (min-height: 720px) and (orientation: landscape) {
  /* 右に広告の列が出ているときは、下の帯と同じく盤面の真ん中にそろえる */
  body.home:has(.play > .ad:not(.ad-mobile, .ad-blocked) :is(a, iframe, img, ins, .ad-pending)) .ad.ad-wide {
    padding-right: calc(300px + 8px);
  }
}
/* 遊び方などの読むページでは、本文の下に枠（300×250）を出す。画面の幅によらない */
main.text .ad {
  width: auto;
  max-width: none;
  max-height: none;
  overflow: visible;
  margin: 24px auto 8px;
  padding: 0;
}
main.text .ad .pr { text-align: center; }
.ad .pr {
  display: block;
  font-size: 0.7rem;
  color: var(--muted);
  text-align: left;
}
.ad-pending {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 300px;
  max-width: 100%;
  height: 250px;
  max-height: calc(100% - 1.4rem);
  margin: 4px auto 0;
  border: 1px dashed rgba(242, 239, 230, 0.4);
  border-radius: 8px;
  background: rgba(0, 0, 0, 0.15);
  color: var(--muted);
  font-size: 0.85rem;
}
.ad:empty, .ad[hidden] { display: none; }

main.text h2 { font-size: 1.35rem; margin: 0.2em 0 0.6em; }
main.text h3 { font-size: 1.05rem; margin: 1.5em 0 0.4em; }
main.text p { margin: 0.6em 0; }
main.text ul, main.text ol { margin: 0.4em 0 0.8em; padding-left: 1.3em; }
main.text li { margin: 0.25em 0; }
main.text .lead { margin-top: 0; }
main.text nav.toc ol {
  list-style: none;
  display: flex;
  flex-wrap: wrap;
  gap: 2px 14px;
  padding-left: 0;
  margin: 0.2em 0 0.8em;
}
main.text nav.toc li { margin: 0; }
main.text nav.toc a[aria-current="page"] {
  color: var(--fg);
  font-weight: 700;
  text-decoration: none;
}
main.text .pane {
  margin: 0.2em 0 0.6em;
  padding: 4px 16px 12px;
  background: var(--panel);
  border-radius: 12px;
}
main.text .pane h3:first-child { margin-top: 0.5em; }
main.text h4 { font-size: 1rem; margin: 1.2em 0 0.3em; }
html.howto-split .pane section { display: none; }
html.howto-split .pane section.is-on { display: block; }
@media (prefers-reduced-motion: no-preference) {
  html.howto-split .pane section.is-on { animation: flow-in 0.35s ease; }
}
@keyframes flow-in {
  from { opacity: 0; transform: translateY(-12px); }
  to { opacity: 1; transform: none; }
}
main.text nav.pager {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  margin: 0.4em 0 0.2em;
  padding-top: 0.8em;
  border-top: 1px solid rgba(242, 239, 230, 0.18);
  font-size: 0.92rem;
}
main.text nav.pager a { text-decoration: none; padding: 4px 0; }
main.text nav.pager a:hover { text-decoration: underline; }
main.text nav.pager .next { margin-left: auto; text-align: right; }
main.text nav.pager .dir {
  display: block;
  color: var(--muted);
  font-size: 0.75rem;
}
main.text .table-wrap { overflow-x: auto; margin: 0.6em 0 1em; }
#play th:first-child,
#play td:first-child,
#level th:first-child,
#level td:first-child {
  white-space: nowrap;
  min-width: 7.5em;
}
main.text table { width: 100%; border-collapse: collapse; font-size: 0.92rem; }
main.text th, main.text td {
  border-bottom: 1px solid rgba(242, 239, 230, 0.18);
  padding: 6px 8px;
  text-align: left;
  vertical-align: top;
}
main.text th { color: var(--muted); font-weight: 600; font-size: 0.8rem; }
main.text td.num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
#showdown td.num { text-align: left; white-space: normal; }
#showdown .life-note { font-weight: 400; color: var(--fg); }
main.text .plus { color: #9ed9b0; font-weight: 700; }
main.text .minus { color: #f0b0a8; font-weight: 700; }
main.text .note { color: var(--muted); font-size: 0.92rem; }

/* 役の表の「例」ボタンと、押すと出る例の窓 */
#hands td.hand-name { white-space: nowrap; }
button.ex {
  margin-left: 6px;
  padding: 0 7px;
  border: 1px solid var(--link);
  border-radius: 999px;
  background: transparent;
  color: var(--link);
  font: inherit;
  font-size: 0.75rem;
  line-height: 1.6;
  vertical-align: 1px;
  cursor: pointer;
}
button.ex:hover, button.ex:focus-visible { background: rgba(255, 215, 122, 0.15); }
#hand-example {
  width: min(420px, calc(100vw - 32px));
  padding: 14px 16px 12px;
  border: 1px solid rgba(242, 239, 230, 0.25);
  border-radius: 12px;
  background: var(--panel);
  color: var(--fg);
}
#hand-example::backdrop { background: rgba(0, 0, 0, 0.55); }
#hand-example h4 { margin: 0 0 8px; }
#hand-example p { margin: 6px 0; }
#hand-example .ex-cap { font-weight: 700; }
#hand-example .ex-sub {
  margin-top: 14px;
  padding-top: 10px;
  border-top: 1px solid rgba(242, 239, 230, 0.18);
  color: var(--muted);
  font-size: 0.8rem;
}
#hand-example .ex-why, #hand-example .ex-legend { font-size: 0.9rem; }
#hand-example .ex-legend { color: var(--muted); font-size: 0.8rem; }
.ex-line { display: flex; align-items: center; gap: 8px; margin: 6px 0; }
.ex-tag {
  flex: none;
  width: 3em;
  font-size: 0.8rem;
  font-weight: 700;
  text-align: center;
}
.ex-tag.win { color: #9ed9b0; }
.ex-tag.lose { color: #f0b0a8; }
.mini-row { display: inline-flex; gap: 4px; }
.mini {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 2.1em;
  height: 2.9em;
  border-radius: 5px;
  background: #f6f3ea;
  color: #1d2a24;
  font-weight: 800;
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.35);
}
.mini.kick { opacity: 0.45; }
.ex-close {
  display: block;
  margin: 10px 0 0 auto;
  padding: 6px 18px;
  border: none;
  border-radius: 999px;
  background: var(--link);
  color: #1d2a24;
  font: inherit;
  font-weight: 700;
  cursor: pointer;
}

/* スマホを横にしたときの案内。スマホは縦向きだけで遊ぶ。
   指で操作する端末で、横長かつ低い画面（スマホの横向き）のときだけ、ページ全体を覆う。
   タブレットや PC の横向きは高さがあるので出ない */
.rotate { display: none; }
@media (orientation: landscape) and (max-height: 500px) and (pointer: coarse) {
  .rotate {
    position: fixed;
    inset: 0;
    z-index: 100;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 12px;
    background: var(--bg);
    color: var(--fg);
    text-align: center;
    padding: 16px;
  }
  .rotate p { margin: 0; font-weight: 700; }
  html:has(.rotate) body { overflow: hidden; }
}
/* 縦長のスマホの形。回るように動かして、縦に戻すことを伝える */
.rotate-icon {
  width: 36px;
  height: 60px;
  border: 3px solid var(--fg);
  border-radius: 8px;
}
@media (prefers-reduced-motion: no-preference) {
  .rotate-icon { animation: rotate-back 2s ease-in-out infinite; }
}
@keyframes rotate-back {
  0%, 20% { transform: rotate(-90deg); }
  60%, 100% { transform: rotate(0deg); }
}
