* {
  box-sizing: border-box;
}

/* iPhoneは連打(ダブルタップ)をズーム操作と解釈することがある。
   manipulationにすると、ピンチズームは残したままダブルタップズームだけ止められる。 */
html {
  touch-action: manipulation;
}

:root {
  --font-brush: "Yuji Syuku", serif;
  --font-body: "Zen Maru Gothic", -apple-system, "Hiragino Sans", "Yu Gothic", sans-serif;

  --felt: #7a1f1f;
  --felt-dark: #5c1414;
  --felt-darker: #3a0d0d;
  --black: #201414;
  --gold: #d4af37;
  --gold-pale: #f4e3a1;
  --gold-dark: #a5822a;
  --cream: #fff8e7;
  --win: #2e7d5b;
  --win-pale: #d9f2e6;
  --lose: #b23a3a;
  --lose-pale: #fbe0e0;
  --text: #2c1b1b;
  --text-muted: #8a7060;
}

body {
  margin: 0;
  font-family: var(--font-body);
  color: var(--cream);
  font-size: 16px;
  background:
    radial-gradient(circle at 50% -10%, rgba(212, 175, 55, 0.15), transparent 55%),
    linear-gradient(160deg, var(--felt-darker) 0%, var(--felt-dark) 45%, var(--felt) 100%);
  min-height: 100vh;
  min-height: 100dvh;
}

.screen {
  min-height: 100vh;
  min-height: 100dvh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px 16px 90px;
}

.hidden {
  display: none !important;
}

.panel {
  background: linear-gradient(160deg, #2a1414 0%, var(--black) 100%);
  border-radius: 20px;
  padding: 32px;
  max-width: 440px;
  width: 100%;
  border: 2px solid var(--gold-dark);
  box-shadow: 0 10px 34px rgba(0, 0, 0, 0.5), inset 0 0 0 1px rgba(212, 175, 55, 0.15);
}

.title-illustration {
  display: block;
  width: 100%;
  max-width: 140px;
  height: auto;
  margin: 0 auto 6px;
}

.panel h1 {
  margin: 0 0 10px;
  font-family: var(--font-brush);
  font-size: 32px;
  font-weight: 400;
  color: var(--gold-pale);
  text-align: center;
  letter-spacing: 0.06em;
  text-shadow: 0 2px 8px rgba(0, 0, 0, 0.5);
}

.hint {
  color: var(--cream);
  opacity: 0.85;
  font-size: 13px;
  text-align: center;
  line-height: 1.6;
}

.disclaimer {
  margin-top: 18px;
  color: var(--text-muted);
  font-size: 11px;
  text-align: center;
  line-height: 1.6;
}

.link-row {
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  margin: 14px 0 0;
}

.rules-link {
  display: inline-flex;
  align-items: center;
  padding: 6px 16px;
  border-radius: 999px;
  background: rgba(212, 175, 55, 0.12);
  border: 2px solid var(--gold-dark);
  color: var(--gold-pale);
  font-weight: 700;
  font-size: 13px;
  text-decoration: none;
}

.rules-link:hover {
  background: var(--gold-dark);
  color: var(--black);
}

.link-row .home-link {
  display: inline-flex;
  align-items: center;
  padding: 6px 14px;
  border-radius: 999px;
  background: rgba(212, 175, 55, 0.12);
  border: 2px solid var(--gold-dark);
  color: var(--gold-pale);
  font-weight: 700;
  font-size: 12px;
  text-decoration: none;
}

.link-row .home-link:hover {
  background: var(--gold-dark);
  color: var(--black);
}

/* できるだけ場所を取らないよう、1個だけの小さなピルボタンにしている(src/share.js)。 */
.share-button {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 6px 14px;
  border-radius: 999px;
  background: rgba(212, 175, 55, 0.12);
  border: 2px solid var(--gold-dark);
  color: var(--gold-pale);
  font-size: 12px;
  font-weight: 700;
  font-family: inherit;
}

.share-button:hover {
  background: var(--gold-dark);
  color: var(--black);
}

/* どの画面でも下に固定して出す、フッター一式(その他リンク・規約類・バージョン・
   著作権・音源クレジット)。以前は参加画面(join-screen)だけに置いていたため、
   他の画面(勝負中など)からは一度タイトルに戻らないと開けなかった。
   z-indexは結果画面より上、音量パネル・規約モーダルより下にする。
   縦に積むと小さい画面でボタンに重なるため、2行に折りたたんでいる。 */
.site-footer {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 55;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  padding: 6px 12px;
  font-size: 10px;
  color: var(--text-muted);
  text-align: center;
  background: rgba(32, 20, 20, 0.92);
  border-top: 1px solid var(--gold-dark);
  backdrop-filter: blur(2px);
}

.site-footer a {
  color: var(--text-muted);
  text-decoration: underline;
  font-weight: 500;
}

.site-footer a:hover {
  color: var(--gold-pale);
}

.site-footer span {
  color: var(--text-muted);
}

.footer-links,
.footer-meta {
  margin: 0;
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  align-items: center;
  gap: 2px 6px;
}

.copyright {
  color: var(--text-muted);
}

.sound-credit {
  color: var(--text-muted);
}

.sound-controls {
  position: fixed;
  top: 16px;
  right: 16px;
  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(--black);
  border: 2px solid var(--gold-dark);
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.35);
}

.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(--black);
  border: 2px solid var(--gold-dark);
  border-radius: 16px;
  box-shadow: 0 8px 20px rgba(0, 0, 0, 0.4);
  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(--cream);
  width: 34px;
  flex: 0 0 auto;
}

.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(--felt-dark);
  border: 2px solid var(--gold-dark);
  flex: 0 0 auto;
}

.sound-volume {
  flex: 1 1 auto;
  min-width: 0;
  accent-color: var(--gold);
}

.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(--gold-dark);
}

.legal-modal-close {
  position: absolute;
  top: 10px;
  right: 10px;
  z-index: 1;
  width: 36px;
  height: 36px;
  padding: 0;
  border-radius: 50%;
  background: #ffffff;
  border: 2px solid var(--gold-dark);
  color: var(--text);
  font-size: 15px;
  line-height: 1;
}

.legal-modal-frame {
  width: 100%;
  height: 100%;
  border: none;
  display: block;
}

label {
  display: block;
  font-size: 13px;
  font-weight: 700;
  color: var(--gold-pale);
  margin: 20px 0 8px;
}

input[type="text"],
input[type="number"] {
  width: 100%;
  height: 46px;
  border-radius: 10px;
  border: 2px solid var(--gold-dark);
  background: var(--cream);
  padding: 0 16px;
  font-family: var(--font-body);
  font-size: 16px;
  font-weight: 700;
  color: var(--text);
  outline: none;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

input[type="text"]:focus,
input[type="number"]:focus {
  border-color: var(--gold);
  box-shadow: 0 0 0 4px rgba(212, 175, 55, 0.25);
}

button {
  cursor: pointer;
  border-radius: 12px;
  border: 2px solid var(--gold-dark);
  background: #3a2424;
  color: var(--cream);
  padding: 10px 18px;
  font-family: var(--font-body);
  font-size: 15px;
  font-weight: 700;
  transition: transform 0.12s ease, box-shadow 0.12s ease, background 0.15s ease, opacity 0.15s ease;
}

button:hover {
  transform: translateY(-2px);
  box-shadow: 0 6px 14px rgba(0, 0, 0, 0.35);
}

button:active {
  transform: translateY(0) scale(0.97);
  box-shadow: none;
}

button:disabled {
  opacity: 0.4;
  cursor: not-allowed;
  transform: none;
  box-shadow: none;
}

button.primary {
  background: linear-gradient(135deg, var(--gold) 0%, var(--gold-dark) 100%);
  border-color: var(--gold-dark);
  color: #241505;
}

#join-button {
  width: 100%;
  margin-top: 22px;
  height: 50px;
  font-size: 17px;
}

.join-error,
.bet-error {
  margin-top: 12px;
  padding: 10px 14px;
  border-radius: 10px;
  background: var(--lose-pale);
  border: 2px solid var(--lose);
  color: var(--lose);
  font-size: 13px;
  font-weight: 700;
  text-align: center;
  animation: wobble 0.4s ease;
}

@keyframes wobble {
  0% { transform: translateX(0); }
  25% { transform: translateX(-4px); }
  50% { transform: translateX(4px); }
  75% { transform: translateX(-2px); }
  100% { transform: translateX(0); }
}

.disconnect-banner {
  position: fixed;
  inset: 0;
  z-index: 200;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  background: rgba(0, 0, 0, 0.65);
}

.disconnect-box {
  width: 100%;
  max-width: 380px;
  background: var(--black);
  border-radius: 20px;
  border: 2px solid var(--gold-dark);
  box-shadow: 0 16px 40px rgba(0, 0, 0, 0.5);
  padding: 28px 24px;
  text-align: center;
}

.disconnect-title {
  font-size: 17px;
  font-weight: 800;
  color: var(--gold-pale);
  margin: 0 0 8px;
}

.disconnect-box #reload-button {
  width: 100%;
  height: 46px;
  margin-top: 10px;
}

/* ---- 参加画面: ランキング ---- */

.ranking-groups {
  display: flex;
  flex-wrap: wrap;
  gap: 14px;
  margin-top: 22px;
}

.ranking-group {
  flex: 1 1 160px;
  min-width: 0;
}

.ranking-group-title {
  font-size: 12px;
  font-weight: 700;
  color: var(--gold-pale);
  text-align: center;
  margin-bottom: 8px;
}

.ranking {
  font-size: 13px;
}

.ranking-entry {
  display: flex;
  justify-content: space-between;
  gap: 6px;
  padding: 6px 12px;
  margin-bottom: 6px;
  border-radius: 999px;
  background: rgba(212, 175, 55, 0.1);
  border: 1px solid var(--gold-dark);
  font-size: 12px;
  color: var(--cream);
}

/* ---- ゲーム画面 ---- */

#game-screen {
  flex-direction: column;
  gap: 0;
}

.game-panel {
  max-width: 460px;
}

.hud-top {
  display: flex;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 18px;
}

.stat-pill {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  background: rgba(212, 175, 55, 0.12);
  border: 2px solid var(--gold-dark);
  border-radius: 999px;
  padding: 6px 14px;
  font-weight: 700;
  font-size: 13px;
  color: var(--gold-pale);
}

.balance-pill strong {
  color: var(--gold);
}

.dice-wrap {
  position: relative; /* .announcements をこの中に絶対配置で重ねるための基準 */
  display: flex;
  flex-direction: column;
  align-items: center;
  margin-bottom: 14px;
  padding-top: 8px;
  background: radial-gradient(circle, rgba(212, 175, 55, 0.08) 0%, transparent 70%);
  border-radius: 16px;
}

.quokka-dealer {
  display: block;
  width: 88px;
  height: auto;
  margin-bottom: -6px; /* 壺(つぼ)がサイコロの近くに来るよう、下のdice-areaと少し重ねる */
  filter: drop-shadow(0 4px 10px rgba(0, 0, 0, 0.4));
}

.quokka-dealer.shaking {
  animation: quokkaShake 0.14s ease-in-out infinite;
}

@keyframes quokkaShake {
  0% { transform: rotate(-5deg) translateY(0); }
  50% { transform: rotate(5deg) translateY(-4px); }
  100% { transform: rotate(-5deg) translateY(0); }
}

.dice-area {
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 20px;
  padding: 12px 0 28px;
}

.announcements {
  position: absolute;
  top: 4px;
  left: 50%;
  transform: translateX(-50%);
  width: calc(100% - 16px);
  z-index: 5;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  pointer-events: none;
}

.announcement-bubble {
  max-width: 100%;
  background: linear-gradient(135deg, var(--gold) 0%, var(--gold-dark) 100%);
  color: #241505;
  font-weight: 700;
  font-size: 12px;
  text-align: center;
  padding: 6px 14px;
  border-radius: 999px;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.35);
  animation: announceIn 0.25s ease;
}

.announcement-bubble.fade-out {
  animation: announceOut 0.4s ease forwards;
}

@keyframes announceIn {
  from { transform: translateY(-8px); opacity: 0; }
  to { transform: translateY(0); opacity: 1; }
}

@keyframes announceOut {
  to { opacity: 0; transform: translateY(-8px); }
}

.tick-bar-row {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 14px;
}

.tick-bar {
  flex: 1 1 auto;
  min-width: 0;
  height: 8px;
  border-radius: 999px;
  background: rgba(212, 175, 55, 0.15);
  overflow: hidden;
}

.tick-bar-fill {
  height: 100%;
  width: 100%;
  border-radius: 999px;
  background: linear-gradient(90deg, var(--gold-pale) 0%, var(--gold) 100%);
  transition: width 0.05s linear, background 0.2s ease;
}

.tick-bar-fill.critical {
  background: linear-gradient(90deg, var(--lose) 0%, var(--felt-darker) 100%);
  animation: tickPulse 0.3s ease-in-out infinite;
}

@keyframes tickPulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.5; }
}

#countdown {
  flex: 0 0 auto;
  font-weight: 700;
  font-size: 12px;
  color: var(--black);
  background: var(--gold-pale);
  border-radius: 999px;
  padding: 4px 12px;
}

#countdown.urgent {
  background: var(--lose-pale);
  color: var(--lose);
}

.die {
  width: 64px;
  height: 64px;
  background: var(--cream);
  border-radius: 12px;
  box-shadow: 0 6px 16px rgba(0, 0, 0, 0.4), inset 0 0 0 2px var(--gold-dark);
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  grid-template-rows: repeat(3, 1fr);
  padding: 8px;
  transition: transform 0.08s ease;
}

.die.rolling {
  animation: diceShake 0.12s linear infinite;
}

@keyframes diceShake {
  0% { transform: rotate(-6deg) scale(1); }
  50% { transform: rotate(6deg) scale(1.04); }
  100% { transform: rotate(-6deg) scale(1); }
}

.pip {
  border-radius: 50%;
  align-self: center;
  justify-self: center;
  width: 10px;
  height: 10px;
  background: transparent;
}

.pip.active {
  background: var(--lose);
}

.result-panel {
  text-align: center;
  border-radius: 14px;
  padding: 12px 16px;
  margin-bottom: 16px;
  border: 2px solid var(--gold-dark);
  background: rgba(212, 175, 55, 0.08);
  /* 表示/非表示を切り替えず常にこの箱を確保しておくことで、結果が変わるたびに
     下の掛け金・卓の一覧などがガクガク動くのを防ぐ(min-heightで文言の長さ差も吸収)。 */
  min-height: 58px;
  display: flex;
  flex-direction: column;
  justify-content: center;
  transition: background-color 0.15s ease, border-color 0.15s ease;
}

.result-panel.win {
  border-color: var(--win);
  background: var(--win-pale);
}

.result-panel.lose {
  border-color: var(--lose);
  background: var(--lose-pale);
}

.result-panel.spectate {
  opacity: 0.85;
}

.result-text {
  font-weight: 800;
  font-size: 18px;
  color: var(--cream);
}

.result-panel.win .result-text,
.result-panel.win .result-sub {
  color: var(--win);
}

.result-panel.lose .result-text,
.result-panel.lose .result-sub {
  color: var(--lose);
}

.result-sub {
  font-size: 13px;
  font-weight: 700;
  margin-top: 4px;
  color: var(--cream);
}

.bet-row {
  margin-bottom: 16px;
}

.bet-input-row {
  display: flex;
  gap: 8px;
}

.bet-input-row input {
  flex: 1 1 auto;
  min-width: 0;
}

.chip-btn {
  flex: 0 0 auto;
  padding: 0 14px;
  font-size: 13px;
}

.choice-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 14px;
  margin-bottom: 18px;
}

.choice-btn {
  height: 64px;
  font-family: var(--font-brush);
  font-size: 30px;
  font-weight: 400;
  border-radius: 14px;
  letter-spacing: 0.1em;
}

.han-btn {
  background: linear-gradient(160deg, #2a4a3d 0%, #163a2c 100%);
  border-color: var(--win);
  color: var(--win-pale);
}

.cho-btn {
  background: linear-gradient(160deg, #5c2424 0%, #3a1414 100%);
  border-color: var(--lose);
  color: var(--lose-pale);
}

.choice-btn.selected {
  box-shadow: 0 0 0 3px var(--gold-pale), 0 6px 16px rgba(0, 0, 0, 0.4);
  transform: translateY(-2px);
}

.bet-status {
  text-align: center;
  font-size: 12px;
  font-weight: 700;
  color: var(--text-muted);
  margin-bottom: 16px;
  min-height: 16px;
}

.bet-status.active {
  color: var(--gold-pale);
}

.table-wrap {
  border-top: 1px solid rgba(212, 175, 55, 0.3);
  padding-top: 12px;
  margin-bottom: 12px;
}

.table-title {
  font-size: 12px;
  font-weight: 700;
  color: var(--gold-pale);
  margin-bottom: 8px;
}

.table-list {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  max-height: 96px;
  overflow-y: auto;
}

.table-list .hint {
  width: 100%;
  margin: 0;
}

.table-chip {
  display: inline-block;
  padding: 4px 10px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 700;
  white-space: nowrap;
  background: rgba(212, 175, 55, 0.1);
  border: 1px solid var(--gold-dark);
  color: var(--cream);
}

.table-chip.bet-han {
  background: rgba(46, 125, 91, 0.25);
  border-color: var(--win);
  color: var(--win-pale);
}

.table-chip.bet-cho {
  background: rgba(178, 58, 58, 0.25);
  border-color: var(--lose);
  color: var(--lose-pale);
}

.table-chip.bankrupt {
  opacity: 0.55;
}

.table-chip.self {
  border-color: var(--gold);
  box-shadow: 0 0 0 2px rgba(212, 175, 55, 0.35);
}

.history-wrap {
  border-top: 1px solid rgba(212, 175, 55, 0.3);
  padding-top: 12px;
}

.history-title {
  font-size: 12px;
  font-weight: 700;
  color: var(--gold-pale);
  margin-bottom: 8px;
}

.history-list {
  display: flex;
  flex-direction: column;
  gap: 6px;
  max-height: 140px;
  overflow-y: auto;
}

.history-entry {
  display: flex;
  justify-content: space-between;
  padding: 6px 12px;
  border-radius: 8px;
  font-size: 12px;
  font-weight: 700;
  background: rgba(212, 175, 55, 0.08);
}

.history-entry.win {
  color: var(--win);
}

.history-entry.lose {
  color: var(--lose-pale);
}

.history-entry.neutral {
  color: var(--text-muted);
}

.gameover-overlay {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  background: rgba(0, 0, 0, 0.75);
}

.gameover-box {
  width: 100%;
  max-width: 360px;
  background: var(--black);
  border-radius: 20px;
  border: 2px solid var(--gold-dark);
  box-shadow: 0 16px 40px rgba(0, 0, 0, 0.5);
  padding: 30px 24px;
  text-align: center;
}

.gameover-title {
  font-family: var(--font-brush);
  font-size: 26px;
  color: var(--gold-pale);
  margin: 0 0 10px;
}

.gameover-box #restart-button {
  width: 100%;
  height: 48px;
  margin-top: 16px;
}

@media (max-width: 480px) {
  .screen {
    padding: 12px;
  }

  .panel {
    padding: 24px 18px;
  }

  .panel h1 {
    font-size: 26px;
  }

  .die {
    width: 54px;
    height: 54px;
  }
}

/* --- バージョン表記 ------------------------------------------------------- */

/* フッターに出す。クリックするとリリースノートがポップアップで開く。
   主導線ではないので、著作権表示と同じくらい控えめにする。 */
.version-link {
  font-size: 10px;
  color: var(--text-muted);
  text-decoration: none;
  border-bottom: 1px dotted currentColor;
}

.version-link:hover {
  color: var(--gold-pale);
}

