@charset "UTF-8";

/* ============ 配色 ============ */
:root {
  --bg: #f2eee3;
  --panel: #fffdf8;
  --panel-2: #faf6ec;
  --line: #d9cfba;
  --line-soft: #e9e1d1;
  --die-line: #c0b299;
  --ink: #3b3529;
  --ink-2: #6b6354;
  --dim: #a49b87;

  --amber: #f0b429;
  --amber-line: #d29a14;
  --amber-soft: #fdf2d6;
  --amber-deep: #8a6408;

  --cpu: #5b9bd5;
  --cpu-line: #3a6f9e;
  --cpu-face: #eaf4fc;
  --cpu-ink: #2f4858;
  --cpu-soft: #e9f2fa;

  --good: #4e9268;
  --bad: #c4604f;

  --shadow: 0 1px 0 rgba(0,0,0,.05), 0 2px 6px rgba(90,74,40,.07);
  --radius: 12px;
}

/* ダークの色。OSの設定（明示指定が無いとき）と、閲覧側の明示指定の両方に対応する */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #1c1a17;
    --panel: #2a2723;
    --panel-2: #242119;
    --line: #453f35;
    --line-soft: #38332c;
    --die-line: #5b5245;
    --ink: #ece5d6;
    --ink-2: #bdb4a1;
    --dim: #857d6e;

    --amber: #f0b429;
    --amber-line: #c99513;
    --amber-soft: #3f3318;
    --amber-deep: #f4cb6a;

    --cpu: #4b86bd;
    --cpu-line: #2d5c86;
    --cpu-face: #d7e8f5;
    --cpu-ink: #23384a;
    --cpu-soft: #22303b;

    --good: #6fb98a;
    --bad: #e07f6d;

    --shadow: 0 1px 0 rgba(0,0,0,.2), 0 2px 8px rgba(0,0,0,.28);}
}

:root[data-theme="dark"] {
  --bg: #1c1a17;
  --panel: #2a2723;
  --panel-2: #242119;
  --line: #453f35;
  --line-soft: #38332c;
  --die-line: #5b5245;
  --ink: #ece5d6;
  --ink-2: #bdb4a1;
  --dim: #857d6e;

  --amber: #f0b429;
  --amber-line: #c99513;
  --amber-soft: #3f3318;
  --amber-deep: #f4cb6a;

  --cpu: #4b86bd;
  --cpu-line: #2d5c86;
  --cpu-face: #d7e8f5;
  --cpu-ink: #23384a;
  --cpu-soft: #22303b;

  --good: #6fb98a;
  --bad: #e07f6d;

  --shadow: 0 1px 0 rgba(0,0,0,.2), 0 2px 8px rgba(0,0,0,.28);}


/* ============ CPUの色（難易度ごと） ============
   アイコンは自分の data-diff を見る。対戦中はシートのCPU列も選んだ難易度の色になる。 */
.av-cpu[data-diff="easy"],
body[data-diff="easy"] {
  --cpu: #5aa06f;
  --cpu-line: #3c7a4f;
  --cpu-face: #e9f5ec;
  --cpu-ink: #22402d;
  --cpu-soft: #edf6f0;
}
.av-cpu[data-diff="normal"],
body[data-diff="normal"] {
  --cpu: #5b9bd5;
  --cpu-line: #3a6f9e;
  --cpu-face: #eaf4fc;
  --cpu-ink: #2f4858;
  --cpu-soft: #e9f2fa;
}
.av-cpu[data-diff="hard"],
body[data-diff="hard"] {
  --cpu: #8a72c4;
  --cpu-line: #63509b;
  --cpu-face: #f0ecf9;
  --cpu-ink: #342853;
  --cpu-soft: #f2eefa;
}

@media (prefers-color-scheme: dark) {
:root:not([data-theme="light"]) .av-cpu[data-diff="easy"],
:root:not([data-theme="light"]) body[data-diff="easy"] {
  --cpu: #4c8a60;
  --cpu-line: #2f6340;
  --cpu-face: #d6ecdd;
  --cpu-ink: #1c3526;
  --cpu-soft: #22322a;
}
:root:not([data-theme="light"]) .av-cpu[data-diff="normal"],
:root:not([data-theme="light"]) body[data-diff="normal"] {
  --cpu: #4b86bd;
  --cpu-line: #2d5c86;
  --cpu-face: #d7e8f5;
  --cpu-ink: #23384a;
  --cpu-soft: #22303b;
}
:root:not([data-theme="light"]) .av-cpu[data-diff="hard"],
:root:not([data-theme="light"]) body[data-diff="hard"] {
  --cpu: #7761ad;
  --cpu-line: #4c3c7d;
  --cpu-face: #e5ddf3;
  --cpu-ink: #2a2044;
  --cpu-soft: #2b2639;
}
}

:root[data-theme="dark"] .av-cpu[data-diff="easy"],
:root[data-theme="dark"] body[data-diff="easy"] {
  --cpu: #4c8a60;
  --cpu-line: #2f6340;
  --cpu-face: #d6ecdd;
  --cpu-ink: #1c3526;
  --cpu-soft: #22322a;
}
:root[data-theme="dark"] .av-cpu[data-diff="normal"],
:root[data-theme="dark"] body[data-diff="normal"] {
  --cpu: #4b86bd;
  --cpu-line: #2d5c86;
  --cpu-face: #d7e8f5;
  --cpu-ink: #23384a;
  --cpu-soft: #22303b;
}
:root[data-theme="dark"] .av-cpu[data-diff="hard"],
:root[data-theme="dark"] body[data-diff="hard"] {
  --cpu: #7761ad;
  --cpu-line: #4c3c7d;
  --cpu-face: #e5ddf3;
  --cpu-ink: #2a2044;
  --cpu-soft: #2b2639;
}

/* ============ 土台 ============ */
* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
}

body {
  background: var(--bg);
  color: var(--ink);
  font-family: -apple-system, BlinkMacSystemFont, "Hiragino Sans", "Hiragino Kaku Gothic ProN",
               "Noto Sans JP", "Yu Gothic", Meiryo, sans-serif;
  font-size: 15px;
  line-height: 1.5;
  -webkit-text-size-adjust: 100%;
  overscroll-behavior: none;
}

button {
  font: inherit;
  color: inherit;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}

.app {
  height: 100dvh;
  max-width: 900px;
  margin: 0 auto;
  position: relative;
}

.screen { display: none; height: 100%; flex-direction: column; }
.screen.on { display: flex; }

/* ============ 共通パーツ ============ */
.primary {
  display: block;
  width: 100%;
  padding: 13px 16px;
  border: 2px solid var(--amber-line);
  border-radius: var(--radius);
  background: var(--amber);
  color: #3b2c05;
  font-size: 17px;
  font-weight: 700;
  letter-spacing: .04em;
  box-shadow: var(--shadow);
  transition: transform .08s, filter .12s;
}
.primary:active { transform: translateY(1px); }
.primary:disabled {
  background: var(--line-soft);
  border-color: var(--line);
  color: var(--dim);
  box-shadow: none;
  cursor: default;
}

.ghost {
  padding: 9px 14px;
  border: 1.5px solid var(--line);
  border-radius: 999px;
  background: var(--panel);
  color: var(--ink-2);
  font-size: 13px;
}
.ghost:active { background: var(--panel-2); }

.icon-btn {
  width: 34px;
  height: 34px;
  display: grid;
  place-items: center;
  border: 1.5px solid var(--line);
  border-radius: 10px;
  background: var(--panel);
  font-size: 15px;
  line-height: 1;
  padding: 0;
}
.icon-btn[aria-pressed="true"] { background: var(--amber-soft); border-color: var(--amber-line); }

.avatar { width: 100%; height: 100%; display: block; }

/* ============ タイトル画面 ============ */
#s-title {
  justify-content: center;
  padding: 24px 16px calc(24px + env(safe-area-inset-bottom));
  overflow-y: auto;
}
.title-box {
  width: 100%;
  max-width: 400px;
  margin: auto;
  text-align: center;
}
.logo {
  margin: 0;
  font-size: 44px;
  letter-spacing: .22em;
  text-indent: .22em;
  font-weight: 800;
  color: var(--ink);
}
.tagline { margin: 2px 0 18px; color: var(--dim); font-size: 13px; }

.vs-row {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 18px;
  margin-bottom: 22px;
}
.vs-row .ava { width: 62px; height: 62px; }
.vs-row .vs { font-weight: 800; color: var(--dim); font-size: 15px; letter-spacing: .08em; }

.lbl {
  margin: 0 0 8px;
  font-size: 12px;
  font-weight: 700;
  letter-spacing: .12em;
  color: var(--dim);
}

.diff-row { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin-bottom: 20px; }
.diff {
  padding: 10px 4px 11px;
  border: 2px solid var(--line);
  border-radius: var(--radius);
  background: var(--panel);
  display: grid;
  justify-items: center;
  gap: 4px;
}
.diff .ava { width: 34px; height: 34px; }
.diff .nm { font-size: 13px; font-weight: 700; }
.diff .ds { font-size: 10px; color: var(--dim); line-height: 1.3; }
.diff[aria-pressed="true"] {
  border-color: var(--amber-line);
  background: var(--amber-soft);
}
.diff[aria-pressed="true"] .ds { color: var(--amber-deep); }

.sub-row { display: flex; gap: 8px; justify-content: center; margin-top: 14px; flex-wrap: wrap; }

/* ============ 対戦画面 ============ */
#s-game { padding: 0 8px; }

.hd {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 8px 2px;
  padding-top: calc(8px + env(safe-area-inset-top));
}
.turn { font-size: 14px; font-weight: 700; letter-spacing: .04em; }
.turn b { font-size: 20px; }
.turn span { color: var(--dim); font-size: 13px; }
.hd-btns { display: flex; gap: 6px; }

/* --- プレイヤー2枚 --- */
.players { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-bottom: 8px; }
.pcard {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 9px;
  border: 2px solid var(--line-soft);
  border-radius: var(--radius);
  background: var(--panel);
  min-width: 0;
}
.pcard .ava { width: 30px; height: 30px; flex: none; }
.pcard .info { min-width: 0; flex: 1; }
.pcard .nm {
  font-size: 11px;
  color: var(--dim);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.pcard .pt { font-size: 19px; font-weight: 800; line-height: 1.1; font-variant-numeric: tabular-nums; }
.pcard.active { border-color: var(--amber-line); background: var(--amber-soft); }
.pcard.active .nm { color: var(--amber-deep); }
.pcard .turn-dot {
  width: 7px; height: 7px; border-radius: 50%;
  background: var(--amber-line); flex: none;
  visibility: hidden;
}
.pcard.active .turn-dot { visibility: visible; }

/* --- スコアシート（上段／下段の横2カラム） --- */
.sheet-wrap {
  flex: 0 1 auto;
  min-height: 0;
  overflow-y: auto;
  border: 2px solid var(--line);
  border-radius: var(--radius);
  background: var(--panel);
  box-shadow: var(--shadow);
}
.sheet {
  width: 100%;
  border-collapse: collapse;
  table-layout: fixed;
  font-variant-numeric: tabular-nums;
}
.sheet col.cn { width: 29%; }
.sheet col.cs { width: 10.5%; }

.sheet thead th {
  position: sticky;
  top: 0;
  z-index: 2;
  padding: 5px 2px;
  white-space: nowrap;
  font-size: 10px;
  font-weight: 700;
  color: var(--dim);
  background: var(--panel-2);
  border-bottom: 1.5px solid var(--line);
  letter-spacing: .02em;
}
.sheet thead th.cn { text-align: left; padding-left: 8px; }
.sheet tbody th {
  text-align: left;
  padding: 0 4px 0 8px;
  font-size: 11.5px;
  font-weight: 600;
  color: var(--ink-2);
  letter-spacing: -.03em;
  white-space: nowrap;
}
/* 役名の左の小さなアイコン */
.ricon {
  width: 16px;
  height: 16px;
  vertical-align: -3px;
  margin-right: 4px;
  color: var(--ink-2);
  opacity: .62;
}
.rules-table .ricon { width: 18px; height: 18px; margin-right: 6px; opacity: .75; }
.rules-table th:not([data-cat]) { padding-left: 24px; }  /* アイコンが無い行も文字位置をそろえる */

.sheet tbody tr + tr th, .sheet tbody tr + tr td { border-top: 1px solid var(--line-soft); }
.sheet .mid { border-left: 2px solid var(--line); }
.sheet td { padding: 3px 2px; height: clamp(40px, 6.1vh, 54px); text-align: center; }

/* セル：未記入（選べる） */
.pick {
  display: block;
  width: 100%;
  height: 100%;
  min-height: 34px;
  padding: 0;
  border: 1.5px solid var(--amber-line);
  border-radius: 7px;
  background: var(--amber-soft);
  font-size: 15px;
  font-weight: 700;
  color: var(--amber-deep);
}
.pick:active { background: var(--amber); }
.pick:disabled { cursor: default; }
/* セル：未記入だが0点（捨て札） */
.pick.zero {
  color: var(--dim);
  font-weight: 500;
  border-style: dashed;
  border-color: var(--line);
  background: transparent;
}
.pick.zero:active { background: var(--line-soft); }

/* セル：記入済み */
.done {
  display: grid;
  place-items: center;
  height: 100%;
  min-height: 34px;
  font-size: 15px;
  font-weight: 700;
  color: var(--ink);
}
.done.z { color: var(--dim); font-weight: 500; }
td.filled { background: var(--panel-2); }
td.cpu-col { background: color-mix(in srgb, var(--cpu-soft) 55%, transparent); }
td.just-in { animation: flash 1s ease-out; }
@keyframes flash {
  0%, 40% { background: var(--amber); }
  100% { background: transparent; }
}

/* 小計・ボーナス */
/* 小計・ボーナスは、シートがスクロールしても常に見えるようにする */
.sheet tfoot th, .sheet tfoot td {
  position: sticky;
  bottom: 0;
  z-index: 2;
  height: 30px;
  border-top: 2px solid var(--line);
  background: var(--panel-2);
  height: 30px;
  font-size: 11px;
}
.sheet tfoot th { text-align: left; padding-left: 8px; color: var(--dim); font-weight: 700; }
.sheet tfoot td { text-align: center; font-weight: 700; font-size: 12px; }
.sheet tfoot td.hit { color: var(--good); }

/* --- 下部の操作エリア --- */
.dock {
  flex: none;
  margin-top: auto;          /* 画面が高いときは余白を上に寄せ、操作系は下に固定 */
  padding: 10px 2px calc(10px + env(safe-area-inset-bottom));
}
.msg {
  margin: 0 0 6px;
  min-height: 19px;
  text-align: center;
  font-size: 12.5px;
  color: var(--ink-2);
  font-weight: 600;
}
.msg.warn { color: var(--amber-deep); }
.msg.flash { animation: msgflash .3s ease; }
@keyframes msgflash {
  0% { transform: scale(1); }
  35% { transform: scale(1.07); }
  100% { transform: scale(1); }
}

.dice { display: flex; justify-content: center; gap: 7px; margin-bottom: 9px; }
.die {
  width: 58px;
  height: 58px;
  padding: 0;
  border: 0;
  background: none;
  position: relative;
  transition: transform .14s ease;
}
.die svg { width: 100%; height: 100%; display: block; }
.die .die-body {
  fill: var(--panel);
  stroke: var(--die-line);
  stroke-width: 4;
}
.die .pip { fill: var(--ink); }
.die .die-q { fill: var(--dim); font-size: 34px; font-weight: 700; font-family: inherit; }

/* のこす状態：色だけでなく位置と枠でも示す */
.die[aria-pressed="true"] { transform: translateY(-7px); }
.die[aria-pressed="true"] .die-body { stroke: var(--amber-line); stroke-width: 7; fill: var(--amber-soft); }
.die[aria-pressed="true"]::after {
  content: "のこす";
  position: absolute;
  left: 50%;
  bottom: -14px;
  transform: translateX(-50%);
  font-size: 9.5px;
  font-weight: 700;
  color: var(--amber-deep);
  white-space: nowrap;
}
.die.locked { cursor: default; opacity: .72; }        /* 振り終わり・CPUの番 */
.die.rolling { animation: tumble .32s ease; }
@keyframes tumble {
  0% { transform: translateY(0) rotate(0); }
  40% { transform: translateY(-11px) rotate(-13deg); }
  70% { transform: translateY(-4px) rotate(9deg); }
  100% { transform: translateY(0) rotate(0); }
}

/* ============ 結果・成績 ============ */
.sheetpad {
  flex: 1;
  overflow-y: auto;
  padding: 20px 16px calc(20px + env(safe-area-inset-bottom));
}
/* 結果画面はタイトル画面と同じく上下中央に。成績画面は可変長リストのため上揃えのまま。 */
#s-result .sheetpad {
  display: flex;
  flex-direction: column;
  justify-content: center;
}
.card {
  max-width: 400px;
  margin: 0 auto;
  background: var(--panel);
  border: 2px solid var(--line);
  border-radius: 16px;
  padding: 20px 16px;
  box-shadow: var(--shadow);
}
.verdict { text-align: center; font-size: 30px; font-weight: 800; letter-spacing: .12em; margin: 0 0 4px; }
.verdict.win { color: var(--good); }
.verdict.lose { color: var(--bad); }
.verdict.draw { color: var(--ink-2); }
.verdict-sub { text-align: center; font-size: 12px; color: var(--dim); margin: 0 0 16px; }

.finals { display: grid; grid-template-columns: 1fr auto 1fr; align-items: center; gap: 10px; margin-bottom: 16px; }
.finals .side { text-align: center; }
.finals .ava { width: 44px; height: 44px; margin: 0 auto 4px; }
.finals .nm { font-size: 11px; color: var(--dim); }
.finals .pt { font-size: 30px; font-weight: 800; line-height: 1.1; font-variant-numeric: tabular-nums; }
.finals .dash { color: var(--dim); font-weight: 700; }

.badges { display: flex; flex-wrap: wrap; gap: 6px; justify-content: center; margin-bottom: 16px; }
.badge {
  font-size: 11px;
  font-weight: 700;
  padding: 5px 10px;
  border-radius: 999px;
  background: var(--amber-soft);
  color: var(--amber-deep);
  border: 1.5px solid var(--amber-line);
}
.badge.g { background: color-mix(in srgb, var(--good) 15%, transparent); color: var(--good); border-color: var(--good); }

.btn-row { display: grid; gap: 8px; margin-top: 4px; }

/* 成績 */
.tabs { display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px; margin-bottom: 14px; }
.tab {
  padding: 8px 4px;
  border: 1.5px solid var(--line);
  border-radius: 9px;
  background: var(--panel);
  font-size: 13px;
  font-weight: 600;
}
.tab[aria-pressed="true"] { background: var(--amber-soft); border-color: var(--amber-line); color: var(--amber-deep); }

.stat-list { border-top: 1px solid var(--line-soft); margin-bottom: 16px; }
.stat-list div {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  padding: 9px 2px;
  border-bottom: 1px solid var(--line-soft);
  font-size: 13px;
}
.stat-list dt { color: var(--dim); }
.stat-list dd { margin: 0; font-weight: 700; font-size: 15px; font-variant-numeric: tabular-nums; }
.stat-list .empty { color: var(--dim); justify-content: center; padding: 24px 0; font-size: 13px; }

.pagehead {
  display: flex; align-items: center; justify-content: space-between;
  padding: 10px 16px; padding-top: calc(10px + env(safe-area-inset-top));
}
.pagehead h2 { margin: 0; font-size: 17px; letter-spacing: .1em; }

/* ============ ダイアログ ============ */
dialog {
  border: 2px solid var(--line);
  border-radius: 16px;
  background: var(--panel);
  color: var(--ink);
  padding: 0;
  max-width: 360px;
  width: calc(100% - 32px);
  box-shadow: 0 10px 40px rgba(0,0,0,.25);
}
dialog::backdrop { background: rgba(30,24,10,.45); }
.dlg-body { padding: 18px 18px 14px; }
.dlg-body h3 { margin: 0 0 10px; font-size: 16px; }
.dlg-body p { margin: 0 0 14px; font-size: 14px; line-height: 1.6; }
.dlg-btns { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.dlg-scroll { max-height: min(70vh, 520px); overflow-y: auto; }

.rules-table { width: 100%; border-collapse: collapse; font-size: 12.5px; margin: 6px 0 14px; }
.rules-table th, .rules-table td { padding: 5px 4px; border-bottom: 1px solid var(--line-soft); text-align: left; }
.rules-table td:last-child { text-align: right; white-space: nowrap; color: var(--ink-2); }
.rules-table caption { text-align: left; font-size: 12px; font-weight: 700; color: var(--dim); padding: 8px 0 2px; }
.steps { margin: 0 0 14px; padding-left: 1.3em; font-size: 13.5px; line-height: 1.7; }

/* ============ 画面が広いとき（768px〜）：参考画像どおりの左右2カラム ============ */
@media (min-width: 768px) {
  /* セレクタに .on を付けること。#s-game だけだと .screen{display:none} に勝ってしまい、
     対戦画面が隠れず、結果画面がその下に押し出される。 */
  #s-game.on {
    padding: 0 16px 16px;
    display: grid;
    grid-template-columns: 1fr 300px;
    grid-template-rows: auto auto 1fr;
    gap: 0 20px;
  }
  .hd { grid-column: 1 / -1; grid-row: 1; }
  .players { grid-column: 1; grid-row: 2; }
  .sheet-wrap { grid-column: 1; grid-row: 3; align-self: start; }
  .dock { grid-column: 2; grid-row: 2 / 4; align-self: start; margin-top: 0; padding-top: 0; }
  .dock .die { width: 54px; height: 54px; }
  .sheet td { height: 46px; }
  .side-help { margin-top: 18px; font-size: 12.5px; color: var(--ink-2); }
  .side-help h3 { font-size: 12px; color: var(--dim); letter-spacing: .1em; margin: 0 0 6px; }
  .side-help ol { margin: 0; padding-left: 1.2em; line-height: 1.8; }
}
@media (max-width: 767px) { .side-help { display: none; } }

/* 360px 未満：2カラムのまま、文字と余白を詰めて収める */
@media (max-width: 359px) {
  .sheet col.cn { width: 31%; }
  .sheet col.cs { width: 9.5%; }
  .sheet tbody th { font-size: 10.5px; padding-left: 5px; letter-spacing: -.06em; }
  .ricon { width: 14px; height: 14px; margin-right: 3px; vertical-align: -2.5px; }
  .sheet thead th { font-size: 9px; letter-spacing: -.04em; }
  .sheet thead th.cn { padding-left: 5px; }
  .sheet td { padding: 3px 1px; height: clamp(38px, 6vh, 46px); }
  .pick, .done { min-height: 32px; font-size: 14px; }
  .die { width: 52px; height: 52px; }
  .dice { gap: 5px; }
}

/* ============ アニメーションを控える設定 ============ */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .001s !important; transition-duration: .001s !important; }
}
body.no-anim *, body.no-anim *::before, body.no-anim *::after {
  animation-duration: .001s !important;
  transition-duration: .001s !important;
}

/* スクリーンリーダー専用 */
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
