:root {
  --bg: #1c1c1e;
  --bg2: #2a2a2d;
  --gold: #f4c430;
  --ink: #f2f2f2;
  --muted: #9a9a9e;
  --red: #d33;
}
* {
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
}
body {
  margin: 0;
  font-family: "Hiragino Kaku Gothic ProN", "Yu Gothic", "Meiryo", system-ui, sans-serif;
  background: var(--bg);
  color: var(--ink);
  min-height: 100vh;
}
.app {
  max-width: 480px;
  margin: 0 auto;
  padding: 10px 16px 28px;
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}
.app.shake {
  animation: shake 0.5s cubic-bezier(0.36, 0.07, 0.19, 0.97) both;
}
@keyframes shake {
  10%, 90% { transform: translateX(-3px); }
  20%, 80% { transform: translateX(5px); }
  30%, 50%, 70% { transform: translateX(-8px); }
  40%, 60% { transform: translateX(8px); }
}

/* トップバー */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 6px 2px 2px;
}
.topbar .title {
  font-size: 1.15rem;
  font-weight: bold;
  letter-spacing: 0.08em;
}
.icon-btn {
  background: var(--bg2);
  color: var(--ink);
  border: 1px solid #3a3a3d;
  border-radius: 999px;
  padding: 7px 16px;
  font-weight: bold;
  font-size: 0.9rem;
  cursor: pointer;
}
.icon-btn:disabled {
  opacity: 0.45;
}
.top-right {
  display: flex;
  gap: 8px;
  align-items: center;
}
#settingsBtn {
  padding: 7px 12px;
  font-size: 1rem;
}

/* 結果タイトル */
.result-title {
  text-align: center;
  font-size: 1.9rem;
  font-weight: 800;
  letter-spacing: 0.05em;
  min-height: 2.2rem;
  margin: 10px 0 4px;
}
.result-title.rolling {
  color: var(--muted);
  font-size: 1.3rem;
}
.result-title.win {
  color: var(--gold);
}
.result-title.lose {
  color: #ff6b6b;
}
.result-title.sd {
  color: #c08be0;
}

/* 振り直しドット */
.roll-dots {
  display: flex;
  gap: 14px;
  justify-content: center;
  margin: 6px 0 10px;
  min-height: 14px;
}
.roll-dots .dot {
  width: 11px;
  height: 11px;
  border-radius: 50%;
  border: 2px solid #6a6a6e;
}
.roll-dots .dot.on {
  background: #fff;
  border-color: #fff;
}

/* 鉢 */
.bowl {
  position: relative;
  width: min(82vw, 340px);
  aspect-ratio: 1 / 1;
  border-radius: 50%;
  margin: 4px auto 8px;
  background: radial-gradient(
    circle at 50% 42%,
    #fcfbf6 0%,
    #f2f0e7 42%,
    #e2dfd2 70%,
    #cbc7b6 88%,
    #d8d4c5 100%
  );
  box-shadow: inset 0 10px 34px rgba(0, 0, 0, 0.22),
    inset 0 -14px 30px rgba(0, 0, 0, 0.16),
    inset 0 0 0 3px rgba(255, 255, 255, 0.5), 0 22px 44px rgba(0, 0, 0, 0.55);
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  cursor: pointer;
}
.bowl.chonbo-fly {
  overflow: visible;
}
.dice-wrap {
  display: flex;
  align-items: center;
  justify-content: center;
}
.dice-wrap.idle {
  gap: 14px;
}
.dice-wrap.settled {
  gap: 8px;
}

/* サイコロ */
.die {
  background: #fff;
  border-radius: 12px;
  box-shadow: inset 0 -3px 0 rgba(0, 0, 0, 0.1), 0 3px 6px rgba(0, 0, 0, 0.25);
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  grid-template-rows: repeat(3, 1fr);
  padding: 7px;
  will-change: transform;
}
.dice-wrap.idle .die {
  width: 62px;
  height: 62px;
}
.dice-wrap.settled .die {
  width: 42px;
  height: 42px;
  padding: 5px;
}
.die span {
  width: 8px;
  height: 8px;
  align-self: center;
  justify-self: center;
}
.dice-wrap.settled .die span {
  width: 6px;
  height: 6px;
}
.die .pip {
  background: #222;
  border-radius: 50%;
}
.die .pip.red {
  background: var(--red);
}
.die.pop {
  animation: pop 0.2s ease-out;
}
@keyframes pop {
  0% {
    filter: brightness(1.5);
  }
  100% {
    filter: brightness(1);
  }
}

/* メインボタン */
.action {
  margin: 6px 0 14px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.action-btn {
  width: 100%;
  background: var(--bg2);
  color: var(--ink);
  border: 1px solid #3a3a3d;
  border-radius: 16px;
  padding: 16px;
  font-size: 1.1rem;
  font-weight: bold;
  cursor: pointer;
}
.action-btn:active {
  transform: translateY(1px);
}
.action-btn.alt {
  background: #34301c;
  border-color: var(--gold);
  color: var(--gold);
}
.action-btn.hidden,
.hidden {
  display: none !important;
}

/* プレイヤータブ */
.players {
  display: flex;
  gap: 8px;
  overflow-x: auto;
  padding-bottom: 4px;
  margin-top: auto;
}
.ptab {
  position: relative;
  flex: 0 0 auto;
  min-width: 84px;
  background: var(--bg2);
  border: 2px solid #3a3a3d;
  border-radius: 12px;
  padding: 8px 10px;
  text-align: center;
}
.ptab.active {
  border-color: var(--gold);
  background: #34301c;
}
.ptab.dim {
  opacity: 0.4;
}
.ptab.add {
  border-style: dashed;
  cursor: pointer;
  color: var(--muted);
}
.ptab .pname {
  font-size: 0.82rem;
  font-weight: bold;
  white-space: nowrap;
}
.ptab .pname.editable {
  cursor: pointer;
  text-decoration: underline dotted;
}
.ptab .pres {
  font-size: 0.72rem;
  color: var(--gold);
  min-height: 1em;
  margin-top: 2px;
}
.ptab .pdel {
  position: absolute;
  top: -8px;
  right: -8px;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  border: none;
  background: #555;
  color: #fff;
  font-size: 0.8rem;
  line-height: 1;
  cursor: pointer;
}

/* 結果オーバーレイ */
.overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.72);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  z-index: 10;
}
.overlay-card {
  background: linear-gradient(180deg, #2e2e31, #232325);
  border: 2px solid var(--gold);
  border-radius: 20px;
  padding: 22px;
  width: 100%;
  max-width: 360px;
  text-align: center;
  animation: pop2 0.45s cubic-bezier(0.2, 1.5, 0.5, 1);
}
@keyframes pop2 {
  0% {
    transform: scale(0.7);
    opacity: 0;
  }
  100% {
    transform: scale(1);
    opacity: 1;
  }
}
.overlay.chonbo .overlay-card {
  border-color: #ff4d4d;
  animation: pop2 0.45s cubic-bezier(0.2, 1.5, 0.5, 1), chonboGlow 1s ease-in-out infinite alternate;
}
@keyframes chonboGlow {
  from { box-shadow: 0 0 0 rgba(255, 77, 77, 0); }
  to { box-shadow: 0 0 26px rgba(255, 77, 77, 0.55); }
}
.overlay.chonbo .ov-winner {
  color: #ff5252;
  font-size: 1.6rem;
}
.ov-winner {
  font-size: 1.05rem;
  font-weight: bold;
  color: var(--gold);
}
.ov-sd {
  color: #c08be0;
  font-weight: bold;
  font-size: 0.9rem;
  min-height: 1em;
  margin-top: 4px;
}
.ov-drink {
  font-size: 2.6rem;
  margin: 6px 0 0;
}
.ov-loser {
  font-size: 1.7rem;
  font-weight: 900;
  color: #ff6b6b;
}
.ov-gulps {
  font-size: 2.4rem;
  font-weight: 900;
  color: #ff5252;
  animation: beat 0.8s ease-in-out infinite;
}
@keyframes beat {
  0%,
  100% {
    transform: scale(1);
  }
  50% {
    transform: scale(1.08);
  }
}
.ov-list {
  list-style: none;
  margin: 14px 0;
  padding: 0;
  font-size: 0.9rem;
}
.ov-list li {
  display: flex;
  justify-content: space-between;
  padding: 5px 4px;
  border-bottom: 1px solid #3a3a3d;
}
.ov-list li.loser {
  color: #ff8080;
  font-weight: bold;
}

/* 設定画面 */
.settings-card {
  border-color: #4a4a4d;
  text-align: left;
  max-height: 88vh;
  overflow-y: auto;
}
.settings-title {
  font-size: 1.2rem;
  font-weight: bold;
  text-align: center;
  margin-bottom: 16px;
}
.settings-sec {
  font-size: 0.8rem;
  color: var(--muted);
  margin: 4px 0 8px;
}
.opt {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  padding: 12px;
  margin-bottom: 8px;
  background: #1f1f22;
  border: 1px solid #3a3a3d;
  border-radius: 12px;
  cursor: pointer;
  line-height: 1.4;
}
.opt input {
  margin-top: 3px;
  width: 18px;
  height: 18px;
  accent-color: var(--gold);
  flex: 0 0 auto;
}
.opt small {
  color: var(--muted);
  font-size: 0.78rem;
}
.opt:has(input:checked) {
  border-color: var(--gold);
  background: #2c2818;
}
.settings-card .action-btn {
  margin-top: 8px;
}

/* セグメント（ボタン群） */
.seg {
  display: flex;
  gap: 6px;
  margin-bottom: 8px;
}
.seg button {
  flex: 1;
  padding: 10px 4px;
  background: #1f1f22;
  border: 1px solid #3a3a3d;
  border-radius: 10px;
  color: var(--ink);
  font-size: 0.85rem;
  font-weight: bold;
  cursor: pointer;
}
.seg button.on {
  border-color: var(--gold);
  background: #34301c;
  color: var(--gold);
}
.seg button:active {
  transform: translateY(1px);
}

/* 音量スライダー */
.vol {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 4px 2px 6px;
}
.vol input[type='range'] {
  flex: 1;
  accent-color: var(--gold);
  height: 22px;
}
