/* 昭和のデパートのクリスマスポスターを下敷きにした配色と書体 */
:root {
  --pine: #0e4a3a;
  --pine-deep: #0a3429;
  --pine-line: #2c6a58;
  --red: #d3213a;
  --red-deep: #a81429;
  --gold: #f6b90d;
  --paper: #fff8e7;
  --ink: #1b1a17;
  --display: "Dela Gothic One", "Hiragino Sans", sans-serif;
  --body: "Zen Maru Gothic", "Hiragino Maru Gothic ProN", "Hiragino Sans", sans-serif;
  --gutter: 16px;
  --candy: repeating-linear-gradient(
    -45deg,
    var(--red) 0 22px,
    var(--paper) 22px 44px
  );
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  background: var(--pine);
  color: var(--paper);
  font-family: var(--body);
  font-weight: 500;
  font-size: 16px;
  line-height: 1.6;
  -webkit-text-size-adjust: 100%;
}

h1,
h2,
h3,
p,
ul {
  margin: 0;
  padding: 0;
}

ul {
  list-style: none;
}

button,
input {
  font: inherit;
  color: inherit;
}

button {
  cursor: pointer;
  border: 0;
  background: none;
  touch-action: manipulation;
}

button:disabled {
  cursor: default;
  opacity: 0.55;
}

:focus-visible {
  outline: 3px solid var(--gold);
  outline-offset: 2px;
}

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip-path: inset(50%);
}

/* キャンディの帯。再生中はこれが全画面に広がる */
.stripe {
  height: 12px;
  background: var(--candy);
}

.hint {
  font-size: 0.875rem;
  opacity: 0.8;
}

.error {
  margin-top: 12px;
  padding: 10px 12px;
  background: var(--paper);
  color: var(--red-deep);
  font-weight: 700;
  border-left: 6px solid var(--red);
}

.button-primary {
  display: block;
  width: 100%;
  min-height: 60px;
  padding: 12px;
  background: var(--red);
  color: var(--paper);
  font-family: var(--display);
  font-size: 1.25rem;
  border-radius: 6px;
  box-shadow: 0 5px 0 var(--red-deep);
}

.button-primary:active:not(:disabled) {
  transform: translateY(4px);
  box-shadow: 0 1px 0 var(--red-deep);
}

.button-secondary {
  display: block;
  width: 100%;
  min-height: 48px;
  margin-top: 12px;
  border: 2px solid var(--paper);
  border-radius: 6px;
  font-weight: 700;
}

.button-quiet {
  min-height: 44px;
  padding: 4px 10px;
  text-decoration: underline;
  text-underline-offset: 3px;
}

.button-danger {
  min-height: 44px;
  padding: 6px 14px;
  background: var(--paper);
  color: var(--red-deep);
  font-weight: 700;
  border-radius: 6px;
}

/* ── ログイン ───────────────── */
.login {
  min-height: 100dvh;
}

.login-title {
  padding: 40px var(--gutter) 28px;
  font-family: var(--display);
  font-weight: 400;
  font-size: clamp(4.5rem, 26vw, 7.5rem);
  line-height: 0.98;
  color: var(--gold);
}

.login-form,
.login-names {
  max-width: 480px;
  padding: 0 var(--gutter);
}

.login > .error {
  max-width: 448px;
  margin: 16px var(--gutter) 0;
}

.login-form label {
  display: block;
  margin-bottom: 6px;
  font-weight: 700;
}

.login-form input {
  display: block;
  width: 100%;
  min-height: 56px;
  margin-bottom: 18px;
  padding: 8px 14px;
  background: var(--paper);
  color: var(--ink);
  border: 0;
  border-radius: 6px;
  font-size: 1.25rem;
}

.login-names h2 {
  font-size: 1.25rem;
  font-weight: 700;
}

.name-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 10px;
  margin-top: 16px;
}

.name-grid button {
  min-height: 72px;
  background: var(--paper);
  color: var(--ink);
  font-family: var(--display);
  font-size: 1.375rem;
  border-radius: 6px;
}

/* ── 全体の枠 ───────────────── */
.party {
  min-height: 100dvh;
  padding-bottom: calc(72px + env(safe-area-inset-bottom));
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 8px var(--gutter);
}

.brand {
  font-family: var(--display);
  font-size: 1.125rem;
  color: var(--gold);
  white-space: nowrap;
}

.topbar-user {
  min-height: 44px;
  font-size: 0.8125rem;
  text-decoration: underline;
  text-underline-offset: 3px;
  text-align: right;
}

.content {
  max-width: 480px;
  margin: 0 auto;
  padding: 0 var(--gutter) 24px;
}

.loading {
  padding-top: 64px;
  text-align: center;
}

.tabs {
  position: fixed;
  z-index: 10;
  inset: auto 0 0;
  display: grid;
  grid-template-columns: 1fr 1fr;
  background: var(--pine-deep);
  padding-bottom: env(safe-area-inset-bottom);
}

.tabs button {
  min-height: 60px;
  font-weight: 700;
  border-top: 5px solid transparent;
}

.tabs button[aria-current="page"] {
  color: var(--gold);
  border-top-color: var(--gold);
}

/* ── ビンゴ ─────────────────── */
.called {
  display: flex;
  align-items: baseline;
  justify-content: center;
  gap: 10px;
  min-height: 96px;
  padding: 2px 0 8px;
  font-family: var(--display);
}

.called-letter {
  font-size: 2rem;
  color: var(--gold);
}

.called-number {
  font-size: 4.75rem;
  line-height: 1.15;
}

.called-count {
  font-family: var(--body);
  font-size: 0.875rem;
}

.called-empty {
  align-self: center;
  font-family: var(--body);
  font-weight: 700;
  font-size: 1.125rem;
}

.card {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  background: var(--paper);
  color: var(--ink);
  border: 4px solid var(--paper);
  border-radius: 6px;
  box-shadow: 0 8px 0 var(--pine-deep);
}

.card-head {
  padding: 4px 0;
  background: var(--red);
  color: var(--paper);
  font-family: var(--display);
  font-size: 1.375rem;
  text-align: center;
}

.cell {
  position: relative;
  display: grid;
  place-items: center;
  aspect-ratio: 1;
  border: 1px solid rgb(27 26 23 / 0.28);
  font-family: var(--display);
  font-size: clamp(1.25rem, 6.2vw, 1.75rem);
}

.cell span {
  position: relative;
  z-index: 1;
}

/* インクのスタンプ */
.cell-open::before {
  content: "";
  position: absolute;
  inset: 6%;
  background: var(--red);
  border-radius: 48% 52% 50% 50% / 52% 48% 52% 48%;
  transform: rotate(var(--tilt));
  animation: stamp 0.28s cubic-bezier(0.2, 1.6, 0.4, 1);
}

.cell-open {
  color: var(--paper);
}

.cell-line::before {
  background: var(--gold);
}

.cell-line {
  color: var(--ink);
}

/* これが出たらビンゴになるマス */
.cell-reach {
  box-shadow: inset 0 0 0 4px var(--gold);
  background: rgb(246 185 13 / 0.22);
}

.card .cell:nth-child(18) {
  font-size: 0.875rem;
}

@keyframes stamp {
  from {
    transform: rotate(var(--tilt)) scale(1.7);
    opacity: 0;
  }
}

.draw-button {
  margin-top: 26px;
}

.players,
.history,
.reset {
  margin-top: 28px;
}

.players h2,
.history h2 {
  margin-bottom: 8px;
  font-size: 1rem;
  font-weight: 700;
  color: var(--gold);
}

.players li {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  padding: 8px 0;
  border-bottom: 1px solid var(--pine-line);
}

.player-status {
  font-weight: 700;
  color: var(--gold);
}

.player-won {
  font-weight: 700;
}

.history p {
  overflow-wrap: anywhere;
}

.reset {
  text-align: center;
}

.reset-confirm {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: center;
  gap: 8px;
}

.reset-confirm p {
  width: 100%;
}

.roll-screen,
.win-screen,
.stop-screen {
  position: fixed;
  z-index: 20;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  width: 100%;
  padding: var(--gutter);
  text-align: center;
}

.roll-screen {
  background: var(--pine-deep);
}

.roll-number {
  font-family: var(--display);
  font-size: min(58vw, 16rem);
  line-height: 1;
  color: var(--gold);
}

.roll-letter {
  font-family: var(--display);
  font-size: min(20vw, 5.5rem);
  line-height: 1.1;
  color: var(--paper);
}

.roll-number-final {
  animation: stop-hit 0.22s cubic-bezier(0.2, 1.5, 0.4, 1);
}

.roll-name {
  font-family: var(--display);
  font-size: min(22vw, 7rem);
  line-height: 1.1;
  color: var(--gold);
}

.win-screen {
  background: var(--gold);
  color: var(--ink);
}

.win-names {
  font-family: var(--display);
  font-size: clamp(2.25rem, 12vw, 4rem);
  line-height: 1.2;
}

.win-title {
  font-family: var(--display);
  font-size: min(21vw, 7.5rem);
  line-height: 1.2;
  color: var(--red-deep);
}

.win-close,
.stop-close {
  position: absolute;
  bottom: calc(24px + env(safe-area-inset-bottom));
  font-size: 0.875rem;
}

/* ── 開始待ちとGM ───────────── */
.lobby-title {
  padding-top: 12px;
  font-family: var(--display);
  font-weight: 400;
  font-size: clamp(3rem, 16vw, 4.5rem);
  line-height: 1.15;
  color: var(--gold);
}

.lobby-lead {
  margin: 10px 0 22px;
}

.lobby-count {
  margin-top: 12px;
  text-align: center;
  font-weight: 700;
}

.lobby-escape {
  margin-top: 8px;
  text-align: center;
}

.gm-banner {
  margin-bottom: 10px;
  padding: 8px 12px;
  background: var(--paper);
  color: var(--ink);
  font-weight: 700;
  text-align: center;
  border-radius: 6px;
}

.gm-banner-me {
  background: var(--gold);
}

.absent {
  margin: 24px 0;
  text-align: center;
  font-weight: 700;
}

.win-label {
  font-family: var(--display);
  font-size: clamp(1.75rem, 9vw, 3rem);
}

/* ── プレゼント交換 ──────────── */
.music-title {
  padding-top: 12px;
  font-family: var(--display);
  font-weight: 400;
  font-size: clamp(2rem, 10vw, 2.75rem);
  line-height: 1.2;
  color: var(--gold);
}

.music-lead {
  margin: 10px 0 22px;
}

.play-button {
  display: block;
  width: 100%;
  min-height: 124px;
  margin-bottom: 14px;
  background: var(--candy);
  border: 6px solid var(--paper);
  border-radius: 6px;
  color: var(--ink);
  font-family: var(--display);
  font-size: 1.75rem;
}

.play-button:not(:disabled) {
  text-shadow:
    0 0 6px var(--paper),
    0 0 6px var(--paper),
    0 0 10px var(--paper),
    0 0 14px var(--paper);
}

.play-button:active:not(:disabled) {
  transform: scale(0.98);
}

.music-section {
  margin-top: 32px;
}

.music-section h3 {
  margin-bottom: 10px;
  font-size: 1rem;
  font-weight: 700;
  color: var(--gold);
}

.tracks li {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 4px 0;
  border-bottom: 1px solid var(--pine-line);
}

.tracks label {
  display: flex;
  flex: 1;
  align-items: center;
  gap: 10px;
  min-height: 44px;
  min-width: 0;
  overflow-wrap: anywhere;
}

.tracks input {
  flex: none;
  width: 22px;
  height: 22px;
  accent-color: var(--gold);
}

.track-actions {
  display: flex;
  flex: none;
  align-items: center;
  gap: 4px;
}

.signed-in {
  margin-top: 32px;
  font-size: 0.875rem;
  text-align: center;
  opacity: 0.8;
}

/* 再生中: 帯が全画面に広がって流れ続ける */
.party-spinning .stripe,
.party-spinning .topbar {
  visibility: hidden;
}

.spin-screen {
  position: fixed;
  z-index: 5;
  inset: 0 0 calc(60px + env(safe-area-inset-bottom));
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: var(--gutter);
  overflow: hidden;
  isolation: isolate;
  color: var(--ink);
  text-align: center;
}

/* 背景を画面より大きく描き、縞1周期ぶん動かして継ぎ目なく流す */
.spin-screen::before {
  content: "";
  position: absolute;
  z-index: -1;
  inset: 0 -125px 0 -125px;
  background: repeating-linear-gradient(
    -45deg,
    var(--red) 0 44px,
    var(--paper) 44px 88px
  );
  animation: candy-flow 2.4s linear infinite;
}

/* 88px × √2 = 124.45px が水平方向の1周期 */
@keyframes candy-flow {
  to {
    transform: translateX(124.45px);
  }
}

.spin-title {
  padding: 18px 26px;
  background: var(--pine);
  color: var(--gold);
  font-family: var(--display);
  font-size: min(16vw, 5.5rem);
  line-height: 1.15;
}

.spin-host {
  margin-top: 16px;
  padding: 4px 12px;
  background: var(--paper);
  font-weight: 700;
}

.spin-stop {
  min-height: 48px;
  margin-top: 16px;
  padding: 6px 18px;
  background: var(--pine-deep);
  color: var(--paper);
  border-radius: 6px;
  font-weight: 700;
}

.stop-screen {
  background: var(--red);
  color: var(--paper);
}

.stop-title {
  font-family: var(--display);
  font-size: min(19vw, 8rem);
  line-height: 1.1;
  animation: stop-hit 0.22s cubic-bezier(0.2, 1.5, 0.4, 1);
}

.stop-sub {
  margin-top: 12px;
  font-size: 1.125rem;
  font-weight: 700;
}

@keyframes stop-hit {
  from {
    transform: scale(1.8);
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before {
    animation: none !important;
    transition: none !important;
  }
}
