:root {
  --sand: #f5ecdd;
  --cream: #fffaf0;
  --brown: #8a6a4b;
  --brown-dark: #5c4530;
  --accent: #ef8354;
  --accent-dark: #d96a3a;
  --good: #6fa96f;
  --line: #e3d5b8;
}

* { box-sizing: border-box; }

/* iPhone対策: 連打をSafariがダブルタップズームと誤解釈しないようにする(ピンチズームは残す) */
html { touch-action: manipulation; }

.hidden { display: none !important; }

body {
  margin: 0;
  font-family: "Zen Maru Gothic", "Hiragino Maru Gothic ProN", sans-serif;
  background: var(--sand);
  color: var(--brown-dark);
}

#app {
  max-width: 900px;
  margin: 0 auto;
  padding: 16px;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

.screen { flex: 1; display: flex; flex-direction: column; align-items: center; }
.screen[hidden] { display: none; }

.card {
  background: var(--cream);
  border-radius: 24px;
  padding: 28px;
  box-shadow: 0 4px 16px rgba(140, 110, 70, 0.15);
  width: 100%;
  max-width: 560px;
  text-align: center;
}

/* 右上固定の音量ボタン(.sound-controls)のぶん、タイトルが重ならないよう右余白を確保する */
h1 { font-size: 1.6rem; margin: 0 0 8px; padding-right: max(44px, calc(env(safe-area-inset-right) + 40px)); }
h2 { margin: 0 0 12px; }
.lead { color: var(--brown); margin: 0 0 20px; }

.link-row { display: flex; justify-content: center; align-items: center; gap: 8px; flex-wrap: wrap; margin: 0 0 18px; }
.link-row a, .share-button {
  display: inline-flex; align-items: center; padding: 6px 14px; border-radius: 999px;
  background: rgba(239, 131, 84, 0.12); border: 2px solid var(--accent-dark); color: var(--accent-dark);
  font-weight: 700; font-size: 12px; text-decoration: none; font-family: inherit; cursor: pointer;
}
.link-row a:hover, .share-button:hover { background: var(--accent-dark); color: var(--cream); }

label { display: block; text-align: left; font-size: 0.9rem; color: var(--brown); margin-bottom: 4px; }

input {
  width: 100%;
  padding: 12px 16px;
  border-radius: 999px;
  border: 2px solid var(--line);
  background: #fff;
  font-size: 1rem;
  margin-bottom: 16px;
  font-family: inherit;
}

button {
  font-family: inherit;
  cursor: pointer;
  border: none;
  border-radius: 999px;
  padding: 12px 24px;
  font-size: 1rem;
  font-weight: 700;
}

button.primary {
  background: var(--accent);
  color: #fff;
  width: 100%;
}
button.primary:hover { background: var(--accent-dark); }
button.primary:disabled { background: #cbb99a; cursor: not-allowed; }

button.secondary {
  background: var(--cream); color: var(--accent-dark); border: 2px solid var(--accent-dark);
  margin-top: 10px;
}
button.secondary:hover { background: rgba(239, 131, 84, 0.12); }
button.secondary:disabled { opacity: .5; cursor: not-allowed; }

.ranking-box { margin-top: 24px; text-align: left; }
.ranking-tabs { display: flex; justify-content: center; gap: 8px; margin-bottom: 8px; }
.ranking-tab {
  background: var(--sand);
  color: var(--brown);
  padding: 6px 16px;
  font-size: 0.85rem;
}
.ranking-tab.active { background: var(--brown); color: #fff; }
.ranking-list { list-style: none; padding: 0; margin: 0; }
.ranking-list li { padding: 6px 10px; border-bottom: 1px solid var(--line); font-size: 0.9rem; }
/* シリーズ共通のランキング行構造(.ranking-row/.ranking-rank/.ranking-name/.ranking-value) */
.ranking-row { display: flex; align-items: center; gap: 8px; }
.ranking-rank { width: 26px; flex-shrink: 0; text-align: center; }
.ranking-name { flex: 1; text-align: left; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ranking-value { font-weight: 800; color: var(--accent-dark); flex-shrink: 0; }

.countdown {
  font-size: 3rem; font-weight: 900; color: var(--accent);
  margin: 12px 0;
}
.lobby-players { list-style: none; padding: 0; }
.lobby-players li {
  background: var(--sand); border-radius: 999px; padding: 8px 16px; margin: 6px 0;
}

/* ラウンドが進むたびに、画面中央に一瞬「ラウンドN」を大きく表示する */
.round-announce {
  position: fixed; inset: 0; display: flex; align-items: center; justify-content: center;
  pointer-events: none; z-index: 50;
}
.round-announce[hidden] { display: none; }
.round-announce span {
  background: var(--brown); color: #fff; font-size: 2rem; font-weight: 900;
  padding: 18px 40px; border-radius: 999px; box-shadow: 0 8px 24px rgba(90, 60, 30, 0.35);
  animation: round-announce-pop 1.2s ease-out forwards;
}
@keyframes round-announce-pop {
  0%   { opacity: 0; transform: scale(0.7); }
  15%  { opacity: 1; transform: scale(1.05); }
  25%  { opacity: 1; transform: scale(1); }
  80%  { opacity: 1; transform: scale(1); }
  100% { opacity: 0; transform: scale(1); }
}

.timer {
  font-size: 1.4rem; font-weight: 900; color: var(--accent-dark);
  background: var(--sand); border-radius: 999px; padding: 4px 16px; flex-shrink: 0;
  /* 残り秒数が2桁→1桁に変わっても幅が動いてサイコロの位置がずれないように、
     等幅数字にしたうえで、2桁ぶんの幅で固定する(paddingを含めた実測値ベース) */
  font-variant-numeric: tabular-nums; width: 56px; text-align: center;
}
.round-label { color: var(--brown); font-weight: 700; font-size: 0.85rem; background: var(--sand); border-radius: 999px; padding: 4px 14px; flex-shrink: 0; white-space: nowrap; }

.dice-area {
  background: var(--cream); border-radius: 24px; padding: 20px; width: 100%;
  margin-bottom: 16px; text-align: center;
}
/* タイマー・サイコロ・ラウンド表示を1行にまとめて、画面上部を詰める */
.dice-row-wrap { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-bottom: 12px; flex-wrap: wrap; }
.dice-row { display: flex; justify-content: center; gap: 14px; flex-wrap: wrap; flex: 1; }
.die {
  width: 56px; height: 56px; border-radius: 14px; background: #fff;
  border: 3px solid var(--line); box-shadow: 0 3px 8px rgba(90, 60, 30, 0.18), inset 0 0 0 1px rgba(255, 255, 255, 0.6);
  display: flex; align-items: center; justify-content: center;
  cursor: pointer; user-select: none;
  transition: transform 0.1s, border-color 0.1s;
}
/* 選んで残す(keep)サイコロは、枠をひときわ目立つ太い色にする */
.die.kept { border-color: var(--accent-dark); border-width: 4px; background: #fff3ea; transform: translateY(-4px); }
.die.disabled { cursor: default; opacity: 0.7; }
/* 役を確定して(turnDone)他の人を待っている間は、全部のサイコロの枠色を変えて
   「この手はもう動かせない」とひと目でわかるようにする */
.die.locked { border-color: var(--brown); opacity: 1; }

/* サイコロの目そのもの(3x3のドット配置)。数字ではなく実物のサイコロらしく見せる */
.die-face {
  width: 88%; height: 88%; display: grid; grid-template-columns: repeat(3, 1fr); grid-template-rows: repeat(3, 1fr);
  gap: 1px; padding: 2px;
}
.pip { border-radius: 50%; background: transparent; align-self: center; justify-self: center; width: 88%; height: 88%; }
.pip.on { background: var(--brown-dark); }

/* ロールの演出(丁半バトルと同じ考え方): 振っている間は小刻みに揺れつづけ(CSS)、
   その間JS側(animateDieRoll)がランダムな目をパラパラ切り替えて「壺の中で転がってる感」を出し、
   最後に本当の目で止める。自分だけでなく、他の卓の人がリロール/確定した瞬間もこれで分かる。 */
@keyframes die-shake {
  0%   { transform: rotate(-7deg) scale(1); }
  50%  { transform: rotate(7deg) scale(1.06); }
  100% { transform: rotate(-7deg) scale(1); }
}
.die.rolling, .mini-die.rolling { animation: die-shake 0.12s linear infinite; }
.dice-controls { display: flex; justify-content: center; align-items: center; gap: 10px; margin-bottom: 8px; flex-wrap: wrap; }
.dice-controls button.primary { width: auto; flex: 1; }
.quit-button {
  background: transparent; color: var(--brown); border: 2px solid var(--line);
  font-size: 0.75rem; padding: 8px 14px; flex-shrink: 0;
}
.quit-button:hover { background: rgba(138, 106, 75, 0.1); border-color: var(--brown); }

.reconnect-banner {
  width: 100%; text-align: center; font-size: 0.85rem; font-weight: 700;
  color: var(--accent-dark); background: rgba(239, 131, 84, 0.12);
  border: 2px dashed var(--accent-dark); border-radius: 14px; padding: 10px 14px;
  margin-bottom: 12px;
}
/* 確定後は中身が空になるが、幅が0にならないようにして「振り直す」ボタンが伸び縮みしないようにする */
.rolls-left { display: flex; align-items: center; gap: 8px; min-width: 72px; flex-shrink: 0; }
.roll-pips { display: flex; gap: 2px; }
.roll-pip { font-size: 1rem; filter: grayscale(1); opacity: 0.35; }
.roll-pip.used { filter: none; opacity: 1; }
.rolls-left-label { color: var(--brown); font-size: 0.9rem; font-weight: 700; }
.hint { color: var(--brown); font-size: 0.82rem; margin: 8px 0 0; }

/* 得点表: 役(カテゴリ)を縦の行、プレイヤーを横の列に並べた1枚の表(紙のヤッツィー用紙と同じ)。
   説明文は持たず、役名と(選べるときは)選んだときの点数だけを見せてコンパクトにする。 */
.scorecards { width: 100%; overflow-x: auto; }
.scoresheet { width: 100%; border-collapse: collapse; font-size: 0.82rem; background: var(--cream); border-radius: 14px; overflow: hidden; }
.scoresheet th, .scoresheet td {
  padding: 5px 8px; text-align: center; border-bottom: 1px solid var(--line); white-space: nowrap;
}
.scoresheet thead th { background: var(--sand); font-size: 0.75rem; padding-top: 8px; padding-bottom: 8px; }
.scoresheet thead th.me { background: var(--accent); color: #fff; }
.seat-dice-row td { background: #fff; padding-top: 6px; padding-bottom: 6px; }
.seat-dice-row td.me { background: rgba(239, 131, 84, 0.12); }
.mini-dice { display: flex; justify-content: center; gap: 3px; }
.mini-die {
  width: 20px; height: 20px; border-radius: 5px; background: var(--sand);
  border: 2px solid var(--line);
  display: flex; align-items: center; justify-content: center;
}
.mini-die .die-face { gap: 1px; padding: 2px; }
.mini-die .pip.on { background: var(--brown-dark); }
/* 状態がひと目でわかるように、枠色をステータスと揃える(選択済=アクセント色、確定済=茶色)。
   枠の太さ(border-width)は常に同じにして、状態が変わってもマスのサイズが動かないようにする */
.mini-die.selected-status { border-color: var(--accent); background: #ffdcc4; }
.mini-die.locked { border-color: var(--brown); background: #ddcbb4; }
.scoresheet .seat-name { display: block; font-weight: 700; }
.scoresheet .seat-status { display: block; font-size: 0.68rem; font-weight: 400; opacity: .85; }
/* selectable/filled/通常のいずれでも padding と border の太さ(border-widthは常に2px、
   色だけ変える)を揃えて、役の状態が変わっても行の高さや列の幅が動かないようにする */
.scoresheet tbody th.cat-name {
  text-align: center; font-weight: 700; background: var(--sand); font-size: 0.78rem;
  padding: 10px; border: 2px solid transparent;
}
/* 選べる役は、押せることがひと目でわかるように: 矢印つき・くっきりした縁取り・広めのタップ範囲。
   矢印は文中に置いて(絶対配置にしない)、役名ごと中央にそろう見た目にする。 */
.scoresheet tbody th.cat-name.selectable {
  cursor: pointer; color: #fff; background: var(--accent);
  border-color: var(--accent-dark);
}
/* 矢印は常に領域を確保しつつ、選べるとき以外は見えなくする(列の幅が状態によって動かないように) */
.scoresheet tbody th.cat-name::before { content: "▶ "; font-size: 0.65rem; visibility: hidden; }
.scoresheet tbody th.cat-name.selectable::before { visibility: visible; }
.scoresheet tbody th.cat-name.selectable:hover,
.scoresheet tbody th.cat-name.selectable:active { background: var(--accent-dark); }
/* 自分がもう選び終えた役は、行の名前ごとはっきり分かるように色を変える(選べる/選べないが一目で分かる) */
.scoresheet tbody th.cat-name.filled { background: var(--brown); color: #fff; }
.scoresheet tbody td { color: var(--brown); }
.scoresheet tbody td.filled { color: var(--brown-dark); font-weight: 700; background: var(--sand); }
/* そのプレイヤーが直近で選んだ役だけ、ひときわ目立つ背景にする(誰が何を選んだか一目でわかるように) */
.scoresheet tbody td.just-picked { background: var(--accent); color: #fff; }
.bonus-row th, .bonus-row td { font-style: italic; }
.bonus-row th, .bonus-row td:not(.filled) { background: rgba(111, 169, 111, 0.12); }
/* 賞与(35点)が付いたら、他の役を確定したときと同じ見た目(td.filled)にする */
.bonus-row td.filled { font-style: normal; }
.scoresheet tbody td.preview { color: var(--accent-dark); font-weight: 700; }
.scoresheet .total-row th, .scoresheet .total-row td {
  border-top: 3px solid var(--brown); border-bottom: 3px solid var(--brown); font-weight: 900;
  font-size: 1.15rem; padding: 10px 8px; color: var(--brown-dark); background: var(--sand);
}
.scoresheet .total-row td.me { color: var(--accent-dark); }

.result-list { list-style: none; padding: 0; text-align: left; }
.result-list li {
  display: flex; justify-content: space-between; align-items: center;
  padding: 10px 14px; border-bottom: 1px solid var(--line);
}
.result-list li.place-1 { font-weight: 900; color: var(--accent-dark); }

/* フッターの表現は他の pokapon シリーズと合わせる: 2行(利用規約など・バージョン+著作権)、
   項目の間は「・」区切り。 */
.site-footer { margin-top: 24px; padding: 12px 0; text-align: center; font-size: 11px; color: var(--brown); line-height: 1.8; }
.site-footer p { margin: 0; }
.footer-links, .footer-meta { display: flex; flex-wrap: wrap; justify-content: center; align-items: center; gap: 4px; }
.site-footer a { color: var(--brown); text-decoration: none; }
.site-footer a:hover { text-decoration: underline; }
.version-link { font-weight: 700; border-bottom: 1px dotted currentColor; }
.version-link:hover { color: var(--accent-dark); }
.copyright { color: #b5a688; }

/* 「遊び方」や利用規約などは他ページへ遷移せず、ポップアップ(iframe)で見せる */
.legal-modal {
  position: fixed; inset: 0; z-index: 100;
  display: flex; align-items: center; justify-content: center; padding: 20px;
}
.legal-modal-backdrop { position: absolute; inset: 0; background: rgba(0, 0, 0, 0.6); }
.legal-modal-box {
  position: relative; width: 100%; max-width: 600px;
  height: min(80vh, 720px); height: min(80dvh, 720px);
  background: var(--cream); border-radius: 20px; overflow: hidden;
  box-shadow: 0 16px 40px rgba(0, 0, 0, 0.5); border: 3px solid var(--accent-dark);
}
.legal-modal-close {
  position: absolute; top: 10px; right: 10px; z-index: 1;
  width: 36px; height: 36px; padding: 0; border-radius: 50%;
  background: #fff; border: 2px solid var(--accent-dark); color: var(--brown-dark); font-size: 15px; line-height: 1;
}
.legal-modal-frame { width: 100%; height: 100%; border: none; display: block; }

/* confirm()/alert()を使わない共通ルールに沿った、画面内の確認モーダル */
.overlay { position: fixed; inset: 0; z-index: 90; display: flex; align-items: center; justify-content: center; background: rgba(60, 45, 35, .45); }
.modal-card { background: var(--cream); border: 3px solid var(--line); border-radius: 18px; padding: 22px 20px; width: min(340px, 90vw); text-align: center; }
.modal-title { font-size: 16px; font-weight: 800; margin-bottom: 16px; color: var(--brown-dark); }
.modal-buttons { display: flex; flex-direction: column; gap: 8px; }
.modal-buttons button { width: 100%; }

/* 右上固定の音量コントロール。他のぽかぽんシリーズと同じ構成
   (🔊=一括ミュート、⚙️=BGM/効果音を個別に調整するパネルを開く)。 */
.sound-controls {
  position: fixed; top: max(16px, env(safe-area-inset-top)); right: max(16px, env(safe-area-inset-right));
  z-index: 50; display: flex; flex-direction: column; align-items: flex-end; gap: 6px;
}
.mute-btn {
  width: 36px; height: 36px; padding: 0; border-radius: 50%; font-size: 16px;
  display: inline-flex; align-items: center; justify-content: center;
  background: var(--cream); border: 2px solid var(--accent-dark); color: var(--brown-dark);
  box-shadow: 0 2px 6px rgba(90, 60, 30, 0.25); cursor: pointer;
}
.settings-btn { width: 28px; height: 28px; font-size: 13px; }
.sound-panel {
  position: absolute; top: calc(100% + 8px); right: 0; z-index: 10; width: 180px;
  background: var(--cream); border: 2px solid var(--accent-dark); border-radius: 16px;
  box-shadow: 0 8px 20px rgba(90, 60, 30, 0.3); padding: 12px 14px;
  display: flex; flex-direction: column; gap: 10px;
}
.sound-row { display: flex; align-items: center; gap: 8px; }
.sound-row-label { font-size: 12px; font-weight: 700; color: var(--brown-dark); min-width: 40px; flex-shrink: 0; white-space: nowrap; }
.sound-mute-btn {
  width: 28px; height: 28px; padding: 0; border-radius: 50%; font-size: 13px;
  display: inline-flex; align-items: center; justify-content: center;
  background: var(--sand); border: 2px solid var(--accent-dark); flex: 0 0 auto; cursor: pointer;
}
.sound-volume { flex: 1 1 auto; min-width: 0; accent-color: var(--accent); }
.sound-credit { color: #b5a688; }

@media (max-width: 480px) {
  .die { width: 46px; height: 46px; font-size: 1.3rem; }
}
