:root {
  --teal: #12d9c8;
  --teal-dark: #0ab3a6;
  --ink: #0f3d3e;
  --white: #ffffff;
  --pink: #f04e98;
  --yellow: #ffd93a;
  --error: #c4453f;
  --radius: 18px;
  --shadow: 0 6px 0 rgba(0, 0, 0, 0.12);
  --c0: #018d50;
  --c1: #0178c2;
  --c2: #fd8016;
  --c3: #c4453f;
  --c4: #714a9b;
  --c5: #c031a5;
}

* { box-sizing: border-box; }
/* display を指定している要素(.dialog-backdrop, .judge など)でも hidden 属性を効かせる */
[hidden] { display: none !important; }

html, body {
  margin: 0;
  padding: 0;
  min-height: 100%;
  background: var(--teal);
  color: var(--ink);
  font-family: "M PLUS Rounded 1c", "Hiragino Maru Gothic ProN", "Rounded Mplus 1c", "Yu Gothic", sans-serif;
  font-weight: 700;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
}

#app {
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 24px 16px 40px;
}

/* ---------- 画面切り替え ---------- */
.screen {
  display: none;
  width: 100%;
  max-width: 560px;
  flex-direction: column;
  align-items: center;
  gap: 18px;
  animation: fadein 0.25s ease;
}
.screen.active { display: flex; }
.screen-wide { max-width: 760px; }
@keyframes fadein { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }

/* ---------- 見出し・テキスト ---------- */
.heading {
  margin: 8px 0 0;
  font-size: clamp(24px, 6vw, 36px);
  font-weight: 900;
  text-align: center;
  line-height: 1.3;
  color: var(--ink);
  text-shadow: 0 2px 0 rgba(255, 255, 255, 0.5);
}
.heading-xl { font-size: clamp(28px, 8vw, 44px); }
.heading-dark {
  background: var(--ink);
  color: var(--white);
  padding: 10px 22px;
  border-radius: 14px;
  text-shadow: none;
}
.subheading {
  margin: 0;
  font-size: clamp(18px, 4.5vw, 26px);
  font-weight: 900;
  color: var(--white);
  text-shadow: 0 2px 0 rgba(0, 0, 0, 0.15);
  text-align: center;
}
.note, .hint, .message { margin: 0; text-align: center; }
.note { color: var(--ink); opacity: 0.85; }
.hint {
  background: var(--ink);
  color: var(--white);
  font-size: 13px;
  padding: 6px 14px;
  border-radius: 999px;
}
.hint-sub { background: transparent; color: var(--ink); opacity: 0.8; padding: 0; }
.message { font-size: 18px; font-weight: 900; color: var(--white); text-shadow: 0 2px 0 rgba(0,0,0,0.15); min-height: 1.5em; }
.error { margin: 0; color: var(--white); background: var(--error); padding: 6px 12px; border-radius: 10px; font-size: 14px; text-align: center; }

/* ---------- ボタン・入力 ---------- */
.stack { display: flex; flex-direction: column; gap: 12px; width: 100%; max-width: 360px; align-items: stretch; }
.btn {
  appearance: none;
  border: 0;
  font: inherit;
  font-weight: 900;
  cursor: pointer;
  border-radius: 999px;
  padding: 12px 24px;
  font-size: 18px;
  color: var(--ink);
  background: var(--white);
  box-shadow: var(--shadow);
  transition: transform 0.08s ease, box-shadow 0.08s ease, opacity 0.15s;
}
.btn:active { transform: translateY(4px); box-shadow: 0 2px 0 rgba(0,0,0,0.12); }
.btn:disabled { opacity: 0.45; cursor: default; transform: none; }
.btn-primary { background: var(--pink); color: var(--white); border: 4px solid var(--yellow); }
.btn-lg { font-size: 22px; padding: 14px 28px; }
.btn-small { font-size: 14px; padding: 8px 16px; }
.btn-ghost { background: rgba(255, 255, 255, 0.55); }
.btn-link { background: transparent; box-shadow: none; text-decoration: underline; font-size: 15px; }
.btn-link:active { transform: none; }

.input {
  width: 100%;
  font: inherit;
  font-weight: 700;
  font-size: 20px;
  padding: 12px 16px;
  border-radius: 14px;
  border: 3px solid var(--white);
  background: var(--white);
  color: var(--ink);
  outline: none;
  text-align: center;
}
.input:focus { border-color: var(--pink); }
.input-mono { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; letter-spacing: 0.15em; }
.field { display: flex; flex-direction: column; gap: 6px; }
.field > span { font-size: 14px; color: var(--ink); padding-left: 4px; }
select.input { text-align: left; }

/* ---------- タイトル・ホーム ---------- */
.title-logo { width: min(80%, 420px); margin-top: 24px; filter: drop-shadow(0 6px 0 rgba(0,0,0,0.15)); }
.title-logo img { width: 100%; display: block; }
.title-sub { margin: 0; color: var(--ink); font-size: 18px; }
.title-mochi { display: flex; gap: 12px; margin-top: 16px; }
.title-mochi img { width: 90px; height: 90px; object-fit: contain; }
.home-hello { font-size: 20px; margin-top: 12px; }

/* ---------- 待機部屋 ---------- */
.room-id-box {
  background: var(--white);
  border-radius: var(--radius);
  padding: 16px 24px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  box-shadow: var(--shadow);
  width: 100%;
  max-width: 360px;
}
.room-id-label { font-size: 13px; opacity: 0.7; }
.room-id { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 36px; letter-spacing: 0.15em; font-weight: 900; }
.copied { font-size: 13px; color: var(--pink); }
.subscribers { font-size: 26px; font-weight: 900; color: var(--white); text-shadow: 0 2px 0 rgba(0,0,0,0.15); }

/* ---------- 数字の確認 ---------- */
.cardcheck-row { display: flex; align-items: center; justify-content: center; gap: 12px; width: 100%; margin-top: 12px; }
.cardcheck-side { display: flex; flex-direction: column; align-items: center; gap: 6px; width: 120px; }
.cardcheck-side img { width: 90px; }
.bubble-text { font-size: 11px; background: var(--white); padding: 4px 8px; border-radius: 10px; text-align: center; }
.big-number {
  background: var(--white);
  border-radius: 28px;
  min-width: 180px;
  padding: 24px 12px;
  text-align: center;
  font-size: 84px;
  font-weight: 900;
  line-height: 1;
  box-shadow: var(--shadow);
}
/* スマホ幅では数字を上に、キャラ 2 人をその下に横並びにする(以前は隠していた) */
@media (max-width: 480px) {
  .cardcheck-row { flex-wrap: wrap; row-gap: 20px; }
  .big-number { order: -1; flex-basis: 100%; margin: 0 24px; }
  .cardcheck-side { width: 156px; }
  .bubble-text { white-space: nowrap; }
}

/* ---------- お題バー ---------- */
.theme-bar {
  display: flex;
  width: 100%;
  border-radius: 14px;
  overflow: hidden;
  box-shadow: var(--shadow);
  background: var(--white);
}
.theme-label { background: var(--ink); color: var(--white); padding: 10px 16px; font-size: 20px; font-weight: 900; white-space: nowrap; }
.theme-text { padding: 10px 16px; font-size: clamp(16px, 4vw, 24px); font-weight: 900; flex: 1; }

/* ---------- プレイヤー ---------- */
.players {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 8px 6px;
  width: 100%;
  position: relative;
}
.player {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  width: 112px;
  padding: 6px 2px;
  border-radius: 14px;
  transition: opacity 0.4s, transform 0.4s;
}
.player.selectable { cursor: pointer; }
.player.selected { background: rgba(255, 255, 255, 0.35); }
.player.gone { opacity: 0.15; transform: scale(0.85); }
.player.me .player-name::after { content: " (あなた)"; font-size: 10px; opacity: 0.8; }
.player-avatar { width: 84px; height: 84px; object-fit: contain; }
.player.selectable .player-avatar:active { transform: scale(0.92); }
.player-name {
  font-size: 15px;
  font-weight: 900;
  max-width: 108px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.bubble {
  position: relative;
  background: var(--white);
  border-radius: 12px;
  min-width: 64px;
  height: 44px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 24px;
  font-weight: 900;
  box-shadow: 0 3px 0 rgba(0,0,0,0.1);
}
.bubble::after {
  content: "";
  position: absolute;
  left: 50%;
  bottom: -8px;
  transform: translateX(-50%);
  border: 6px solid transparent;
  border-top-color: var(--white);
  border-bottom: 0;
}
.bubble input {
  width: 64px;
  height: 100%;
  border: 0;
  background: transparent;
  font: inherit;
  font-size: 24px;
  font-weight: 900;
  text-align: center;
  color: inherit;
  outline: none;
  border-radius: 12px;
}
.bubble input::placeholder { color: currentColor; opacity: 0.3; }
.bubble input:focus { box-shadow: inset 0 0 0 3px var(--pink); }
.badge {
  position: absolute;
  top: 40px;
  right: 2px;
  background: var(--yellow);
  color: var(--ink);
  border-radius: 999px;
  font-size: 11px;
  padding: 2px 8px;
  box-shadow: 0 2px 0 rgba(0,0,0,0.12);
}
.badge.big { font-size: 22px; padding: 4px 10px; top: 30px; right: -4px; animation: pop 0.3s ease; }
.badge.minus { background: var(--error); color: var(--white); }
@keyframes pop { from { transform: scale(0.3); } to { transform: scale(1); } }
.checkbox {
  width: 28px;
  height: 28px;
  border-radius: 8px;
  background: var(--white);
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--pink);
  font-size: 22px;
  font-weight: 900;
  box-shadow: 0 2px 0 rgba(0,0,0,0.12);
}
.vote-btn {
  border: 0;
  background: rgba(255, 255, 255, 0.45);
  border-radius: 10px;
  width: 40px;
  height: 40px;
  font-size: 22px;
  cursor: pointer;
  opacity: 0.5;
  transition: transform 0.1s, opacity 0.1s;
}
.vote-btn.on { opacity: 1; background: var(--white); transform: scale(1.15); box-shadow: 0 3px 0 rgba(0,0,0,0.12); }
.vote-row { display: flex; gap: 6px; }
.points { font-size: 22px; font-weight: 900; color: var(--white); text-shadow: 0 2px 0 rgba(0,0,0,0.15); transition: transform 0.2s; }
.points.bump { transform: scale(1.4); }

/* リアクション */
.reactions { position: fixed; inset: 0; pointer-events: none; overflow: hidden; }
.reaction { position: absolute; width: 44px; animation: floatup 2.4s ease-out forwards; }
@keyframes floatup {
  0% { transform: translate(0, 0) scale(0.6); opacity: 0; }
  10% { opacity: 1; transform: translate(0, -10px) scale(1); }
  100% { transform: translate(20px, -220px) scale(1.1); opacity: 0; }
}

/* 判定オーバーレイ */
.judge {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 160px;
  font-weight: 900;
  color: var(--white);
  text-shadow: 0 8px 0 rgba(0,0,0,0.2);
  background: rgba(0, 0, 0, 0.15);
  animation: pop 0.25s ease;
  pointer-events: none;
}
.judge.ok { color: #ff5d8f; }
.judge.ng { color: #4b6cff; }

/* ---------- クリア ---------- */
.screen-clear { max-width: 900px; }
.clear-image { width: 100%; border-radius: var(--radius); box-shadow: var(--shadow); }

/* ---------- 最終結果 ---------- */
.ranking { list-style: none; margin: 0; padding: 16px; width: 100%; max-width: 420px; background: rgba(255,255,255,0.5); border-radius: var(--radius); display: flex; flex-direction: column; gap: 8px; }
.rank { display: flex; align-items: center; gap: 12px; background: var(--white); border-radius: 12px; padding: 8px 14px; font-size: 22px; font-weight: 900; opacity: 0; transform: translateY(10px); transition: opacity 0.4s, transform 0.4s; }
.rank.show { opacity: 1; transform: none; }
.rank .rank-no { width: 36px; text-align: center; }
.rank .rank-name { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.rank .rank-pt { font-size: 18px; }

/* ---------- あそびかた ---------- */
.howto { margin: 0; padding: 0 0 0 20px; display: flex; flex-direction: column; gap: 12px; background: var(--white); border-radius: var(--radius); padding: 18px 18px 18px 38px; line-height: 1.6; font-weight: 500; }
.howto b { font-weight: 900; }

/* ---------- ダイアログ・トースト ---------- */
.dialog-backdrop { position: fixed; inset: 0; background: rgba(15, 61, 62, 0.55); display: flex; align-items: center; justify-content: center; padding: 16px; z-index: 50; }
.dialog { background: var(--white); border-radius: var(--radius); padding: 20px; width: 100%; max-width: 520px; max-height: 85dvh; overflow: auto; display: flex; flex-direction: column; gap: 16px; box-shadow: 0 12px 30px rgba(0,0,0,0.25); }
.dialog-body { font-size: 18px; text-align: center; }
.dialog-actions { display: flex; gap: 10px; justify-content: center; flex-wrap: wrap; }
.toast { position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%); background: var(--ink); color: var(--white); padding: 10px 18px; border-radius: 999px; font-size: 14px; z-index: 60; }

/* 数字入力の上下ボタン(スピナー)は出さない。スマホでは元々出ないので PC 向け */
input[type="number"]::-webkit-outer-spin-button,
input[type="number"]::-webkit-inner-spin-button { -webkit-appearance: none; margin: 0; }
input[type="number"] { -moz-appearance: textfield; appearance: textfield; }

/* 予想の確認テーブル */
.predict-table { display: flex; flex-direction: column; gap: 10px; text-align: left; }
.predict-row { display: grid; grid-template-columns: 90px 1fr; align-items: center; gap: 8px; font-size: 14px; }
.predict-row .pname { font-weight: 900; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.predict-bar { position: relative; height: 34px; background: #e6f7f5; border-radius: 8px; }
.predict-bar .actual { position: absolute; top: 0; bottom: 0; width: 3px; background: var(--ink); transform: translateX(-50%); }
.predict-bar .actual-label { position: absolute; top: -14px; transform: translateX(-50%); font-size: 11px; font-weight: 900; }
.predict-bar .chip { position: absolute; top: 50%; width: 18px; height: 18px; border-radius: 50%; transform: translate(-50%, -50%); border: 2px solid var(--white); box-shadow: 0 1px 2px rgba(0,0,0,0.3); }

.spinner { width: 48px; height: 48px; border: 6px solid rgba(255,255,255,0.4); border-top-color: var(--white); border-radius: 50%; animation: spin 0.9s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- 音の ON/OFF ---------- */
.sound-toggle {
  position: fixed;
  top: max(10px, env(safe-area-inset-top));
  right: max(10px, env(safe-area-inset-right));
  z-index: 40;
  width: 44px;
  height: 44px;
  border: 0;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.7);
  box-shadow: 0 3px 0 rgba(0, 0, 0, 0.12);
  font-size: 20px;
  line-height: 1;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}
.sound-toggle:active { transform: translateY(2px); box-shadow: 0 1px 0 rgba(0,0,0,0.12); }
.sound-toggle.is-muted { opacity: 0.6; }
