:root {
  --bg1: #0d1117;
  --bg2: #1a1f3a;
  --panel: rgba(255,255,255,0.06);
  --panel-border: rgba(255,255,255,0.1);
  --accent: #e94560;
  --gold: #fbbf24;
  --green: #34d399;
  --blue: #60a5fa;
  --purple: #a78bfa;
  --text: #e2e8f0;
  --dim: #64748b;
  --stone: #78716c;
}

* { margin:0; padding:0; box-sizing:border-box; -webkit-tap-highlight-color:transparent; }

html, body {
  height: 100%;
  overflow: hidden;
}

body {
  font-family: 'Hiragino Sans', 'Noto Sans JP', system-ui, sans-serif;
  background: radial-gradient(ellipse at top, var(--bg2), var(--bg1));
  color: var(--text);
  touch-action: manipulation;
}

#app {
  display: flex;
  flex-direction: column;
  height: 100vh;
  max-width: 500px;
  margin: 0 auto;
  position: relative;
}

/* === トップバー === */
#topbar {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 6px 10px;
  flex-shrink: 0;
}

#players-strip {
  display: flex;
  gap: 6px;
  flex: 1;
}

.p-chip {
  flex: 1;
  background: var(--panel);
  border: 1px solid var(--panel-border);
  border-radius: 10px;
  padding: 5px 8px;
  display: flex;
  flex-direction: column;
  align-items: center;
  transition: all 0.3s;
  min-width: 0;
}
.p-chip.active {
  border-color: var(--gold);
  background: rgba(251,191,36,0.1);
  box-shadow: 0 0 12px rgba(251,191,36,0.25);
}
.p-name {
  font-size: 0.7rem;
  font-weight: bold;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 100%;
}
.p-score {
  font-size: 1.1rem;
  font-weight: 900;
  color: var(--gold);
  line-height: 1.1;
}
.p-score .unit { font-size: 0.6rem; color: var(--dim); }
.p-sub {
  font-size: 0.55rem;
  color: var(--dim);
  display: flex;
  gap: 3px;
}
.daibutsu-mark {
  color: var(--accent);
  font-size: 0.6rem;
}

#help-btn {
  background: var(--panel);
  border: 1px solid var(--panel-border);
  color: var(--text);
  border-radius: 10px;
  padding: 8px 10px;
  font-size: 1rem;
  cursor: pointer;
  flex-shrink: 0;
}
#speed-btn {
  background: var(--panel);
  border: 1px solid var(--panel-border);
  color: var(--text);
  border-radius: 10px;
  padding: 8px 8px;
  font-size: 0.7rem;
  font-weight: 700;
  cursor: pointer;
  flex-shrink: 0;
  white-space: nowrap;
}
#speed-btn:active { transform: scale(0.93); }

/* === リソース情報バー === */
#info-bar {
  display: flex;
  gap: 8px;
  padding: 4px 10px;
  background: var(--bg1);
  border-bottom: 1px solid rgba(255,255,255,0.05);
  flex-shrink: 0;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}
.info-item {
  font-size: 0.65rem;
  color: var(--dim);
  white-space: nowrap;
}
.info-item b {
  color: var(--gold);
  font-size: 0.75rem;
}

/* === ステージ === */
#stage {
  flex: 1;
  position: relative;
  overflow: hidden;
}

.scene {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 16px;
  animation: fadeIn 0.3s;
}
@keyframes fadeIn {
  from { opacity: 0; transform: scale(0.95); }
  to { opacity: 1; transform: scale(1); }
}

/* === IDLE === */
.idle-content { text-align: center; }

.turn-banner {
  font-size: 1.3rem;
  font-weight: bold;
  margin-bottom: 24px;
  animation: pulseGlow 2s infinite;
}
@keyframes pulseGlow {
  0%, 100% { opacity: 1; text-shadow: 0 0 20px rgba(251,191,36,0.3); }
  50% { opacity: 0.8; text-shadow: 0 0 30px rgba(251,191,36,0.6); }
}

.auto-roll-hint {
  font-size: 0.9rem;
  color: var(--dim);
  animation: blink 1.5s infinite;
}
@keyframes blink {
  0%, 100% { opacity: 0.5; }
  50% { opacity: 1; }
}

.big-btn {
  font-size: 1.4rem;
  font-weight: bold;
  background: linear-gradient(135deg, var(--accent), #c0392b);
  color: #fff;
  border: none;
  border-radius: 24px;
  padding: 28px 56px;
  cursor: pointer;
  box-shadow: 0 8px 32px rgba(233,69,96,0.4);
  transition: all 0.2s;
  animation: float 3s ease-in-out infinite;
}
.big-btn:active { transform: scale(0.95); }
.big-btn span { font-size: 0.95rem; }
@keyframes float {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(-6px); }
}

.big-btn-sm {
  font-size: 1rem;
  font-weight: bold;
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: 16px;
  padding: 14px 32px;
  cursor: pointer;
  margin-top: 16px;
  box-shadow: 0 4px 16px rgba(233,69,96,0.3);
  transition: all 0.15s;
}
.big-btn-sm:active { transform: scale(0.95); }

/* === ダイス === */
.dice-stage {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 20px;
}

#dice-grid, #dice-grid-select {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  justify-content: center;
  max-width: 380px;
}

.die {
  width: 64px;
  height: 64px;
  border-radius: 14px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  font-weight: bold;
  position: relative;
  transition: transform 0.2s;
  cursor: default;
}
.die.rolling {
  animation: tumble 0.4s ease-out;
}
@keyframes tumble {
  0% { transform: rotate(0) scale(1); }
  25% { transform: rotate(180deg) scale(0.8); }
  50% { transform: rotate(360deg) scale(1.1); }
  75% { transform: rotate(540deg) scale(0.9); }
  100% { transform: rotate(720deg) scale(1); }
}
.die.settai-auto {
  animation: settaiPulse 0.5s;
}
@keyframes settaiPulse {
  0% { transform: scale(1); box-shadow: 0 0 0 rgba(233,69,96,0); }
  50% { transform: scale(1.2); box-shadow: 0 0 20px rgba(233,69,96,0.6); }
  100% { transform: scale(1); box-shadow: 0 0 0 rgba(233,69,96,0); }
}
.die.selectable {
  cursor: pointer;
  border: 3px solid transparent;
}
.die.selectable:hover {
  border-color: rgba(255,255,255,0.4);
}
.die.selectable:active { transform: scale(0.9); }
.die-icon { font-size: 1.8rem; line-height: 1; }
.die-label { font-size: 0.6rem; margin-top: 2px; }

.die-修行 { background: var(--purple); color: #fff; }
.die-接待赤 { background: #dc2626; color: #fff; }
.die-接待黒 { background: #292524; color: #fff; }
.die-お参り { background: var(--green); color: #1a1a2e; }
.die-荘厳 { background: var(--blue); color: #fff; }
.die-催し { background: var(--gold); color: #1a1a2e; }
.die-大仏 { background: #78716c; color: #fff; }

.rolling-text {
  font-size: 0.9rem;
  color: var(--dim);
  animation: blink 1s infinite;
}
@keyframes blink { 50% { opacity: 0.3; } }

/* === SELECT === */
.select-prompt {
  font-size: 1rem;
  font-weight: bold;
  margin-bottom: 20px;
  color: var(--gold);
}

.locked-summary {
  margin-top: 20px;
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  justify-content: center;
  min-height: 36px;
}
.locked-pill {
  background: var(--panel);
  border: 1px solid var(--panel-border);
  border-radius: 10px;
  padding: 4px 10px;
  font-size: 0.8rem;
  display: flex;
  align-items: center;
  gap: 4px;
  animation: popIn 0.3s;
}
@keyframes popIn {
  from { transform: scale(0); }
  to { transform: scale(1); }
}
.locked-pill .count { font-weight: 900; color: var(--gold); }

/* === RESOLVE === */
.resolve-content {
  text-align: center;
  max-width: 400px;
}
.resolve-title {
  font-size: 1.2rem;
  font-weight: bold;
  margin-bottom: 12px;
}
.resolve-items {
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.resolve-item {
  background: var(--panel);
  border: 1px solid var(--panel-border);
  border-radius: 12px;
  padding: 12px 16px;
  font-size: 0.95rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  animation: slideUp 0.4s;
}
@keyframes slideUp {
  from { opacity: 0; transform: translateY(20px); }
  to { opacity: 1; transform: translateY(0); }
}
.resolve-item .icon { font-size: 1.5rem; }
.resolve-item .val { font-weight: 900; font-size: 1.2rem; }

/* === SHOP === */
.shop-prompt {
  font-size: 0.95rem;
  font-weight: bold;
  margin-bottom: 8px;
}
.resource-bar {
  font-size: 0.85rem;
  margin-bottom: 12px;
  display: flex;
  gap: 12px;
  justify-content: center;
}
.resource-bar .res {
  background: var(--panel);
  border: 1px solid var(--panel-border);
  border-radius: 8px;
  padding: 4px 12px;
}
.shop-grid {
  display: flex;
  flex-direction: column;
  gap: 10px;
  width: 100%;
  max-width: 420px;
  overflow-y: auto;
  max-height: 45vh;
}

.shop-section-title {
  font-size: 0.8rem;
  color: var(--dim);
  margin-bottom: 4px;
}

.shop-card {
  background: var(--panel);
  border: 1px solid var(--panel-border);
  border-radius: 12px;
  padding: 10px 12px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  transition: all 0.2s;
}
.shop-card.disabled { opacity: 0.35; }
.shop-card:not(.disabled):active { transform: scale(0.97); }

.shop-card-info { flex: 1; }
.shop-card-name { font-weight: bold; font-size: 0.9rem; }
.shop-card-cost { font-size: 0.72rem; color: var(--dim); }
.shop-card-desc { font-size: 0.7rem; color: #94a3b8; }

.shop-buy {
  background: var(--gold);
  color: #1a1a2e;
  border: none;
  border-radius: 10px;
  padding: 8px 14px;
  font-size: 0.82rem;
  font-weight: 900;
  cursor: pointer;
  white-space: nowrap;
}
.shop-buy.disabled {
  background: var(--panel);
  color: var(--dim);
}

/* === CPU THINKING === */
.cpu-thinking {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 16px;
}
.cpu-avatar {
  font-size: 4rem;
  animation: cpuBob 1s ease-in-out infinite;
}
@keyframes cpuBob {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(-10px); }
}
.cpu-pick {
  font-size: 1.1rem;
  font-weight: bold;
  color: var(--gold);
  background: rgba(251,191,36,0.15);
  border: 1px solid rgba(251,191,36,0.3);
  border-radius: 12px;
  padding: 8px 16px;
  animation: fadeIn 0.3s;
}
.thinking-label {
  font-size: 0.9rem;
  color: var(--dim);
}
.thinking-dots {
  display: flex;
  gap: 6px;
}
.thinking-dots span {
  width: 10px; height: 10px;
  border-radius: 50%;
  background: var(--blue);
  animation: dotBounce 1.4s infinite;
}
.thinking-dots span:nth-child(2) { animation-delay: 0.2s; }
.thinking-dots span:nth-child(3) { animation-delay: 0.4s; }
@keyframes dotBounce {
  0%, 80%, 100% { transform: scale(0.6); opacity: 0.5; }
  40% { transform: scale(1.2); opacity: 1; }
}

/* === トースト === */
#toast-container {
  position: fixed;
  top: 70px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 200;
  display: flex;
  flex-direction: column;
  gap: 4px;
  align-items: center;
  pointer-events: none;
}
.toast {
  background: rgba(0,0,0,0.85);
  border: 1px solid var(--panel-border);
  border-radius: 12px;
  padding: 8px 16px;
  font-size: 0.82rem;
  animation: toastIn 0.3s, toastOut 0.3s 2.5s forwards;
}
@keyframes toastIn { from { opacity:0; transform: translateY(-10px); } }
@keyframes toastOut { to { opacity:0; transform: translateY(-10px); } }

/* === フルスクリーン演出 === */
#effect-overlay {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 300;
  pointer-events: none;
  background: rgba(0,0,0,0.4);
  animation: ovFade 0.3s;
}
@keyframes ovFade { from { opacity: 0; } }
#effect-content {
  text-align: center;
  animation: bigPop 0.5s;
}
@keyframes bigPop {
  0% { transform: scale(0) rotate(-20deg); opacity: 0; }
  60% { transform: scale(1.2) rotate(5deg); }
  100% { transform: scale(1) rotate(0); opacity: 1; }
}
.effect-big {
  font-size: 5rem;
  line-height: 1;
}
.effect-title {
  font-size: 1.6rem;
  font-weight: 900;
  margin-top: 8px;
  text-shadow: 0 2px 20px rgba(0,0,0,0.5);
}
.effect-sub {
  font-size: 1rem;
  margin-top: 4px;
  opacity: 0.8;
}

/* === ログドロワー === */
#log-drawer {
  position: fixed;
  bottom: 0;
  left: 50%;
  transform: translateX(-50%);
  width: 100%;
  max-width: 500px;
  z-index: 50;
}
#log-toggle {
  width: 100%;
  background: var(--bg1);
  border-top: 1px solid var(--panel-border);
  color: var(--text);
  padding: 6px 12px;
  font-size: 0.78rem;
  cursor: pointer;
  text-align: left;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
#log-latest { color: var(--dim); }
#log-panel {
  background: var(--bg1);
  border-top: 1px solid var(--panel-border);
  max-height: 200px;
  overflow-y: auto;
  padding: 8px 12px;
  font-size: 0.75rem;
  line-height: 1.5;
}
.log-entry { margin: 2px 0; }

/* === モーダル === */
.modal {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.8);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 500;
  padding: 16px;
}
.modal-box {
  background: var(--bg2);
  border-radius: 20px;
  padding: 24px;
  max-width: 440px;
  width: 100%;
  max-height: 80vh;
  overflow-y: auto;
  text-align: center;
}
.modal-box h2 { margin-bottom: 12px; }
.modal-box button { margin-top: 16px; }
#end-body { text-align: left; font-size: 0.9rem; line-height: 1.6; }
#end-body .winner {
  font-size: 1.3rem; font-weight: 900; color: var(--gold);
  text-align: center; margin-bottom: 8px;
}
#end-body .rank { margin: 4px 0; }
#help-body { text-align: left; font-size: 0.85rem; line-height: 1.6; }
#help-body h3 { margin: 10px 0 4px; }
#help-body ul { margin-left: 20px; }

/* === プレイヤー詳細モーダル === */
#detail-body { text-align: left; }
.detail-header {
  display: flex; align-items: center; gap: 8px;
  margin-bottom: 12px; flex-wrap: wrap;
}
.detail-emoji { font-size: 2rem; }
.detail-name { font-size: 1.2rem; font-weight: 900; }
.detail-daibutsu {
  font-size: 0.75rem; background: rgba(120,113,108,0.3);
  border: 1px solid var(--stone); border-radius: 8px;
  padding: 2px 8px; color: var(--gold);
}
.detail-stats {
  display: flex; gap: 8px; margin-bottom: 16px;
}
.detail-stat {
  flex: 1; text-align: center; background: var(--bg1);
  border-radius: 12px; padding: 8px 4px;
  border: 1px solid rgba(255,255,255,0.05);
}
.ds-val { font-size: 1.4rem; font-weight: 900; color: var(--gold); }
.ds-label { font-size: 0.7rem; color: var(--dim); }

.detail-section { margin-bottom: 12px; }
.detail-section-title {
  font-size: 0.8rem; font-weight: 700; color: var(--dim);
  margin-bottom: 4px;
}
.detail-cards { display: flex; flex-direction: column; gap: 4px; }
.detail-card {
  background: var(--bg1); border-radius: 8px;
  padding: 6px 10px; font-size: 0.8rem;
  border-left: 3px solid var(--blue);
}
.dc-name { font-weight: 700; }
.dc-desc { display: block; font-size: 0.7rem; color: var(--dim); margin-top: 2px; }
.detail-empty { font-size: 0.8rem; color: var(--dim); }
.detail-ofuse { display: flex; flex-wrap: wrap; gap: 4px; }
.ofuse-chip {
  width: 32px; height: 32px; display: flex; align-items: center; justify-content: center;
  border-radius: 6px; font-size: 0.9rem; font-weight: 700;
}
.ofuse-1 { background: var(--green); color: #1a1a2e; }
.ofuse-2 { background: var(--blue); color: #fff; }
.ofuse-3 { background: var(--purple); color: #fff; }
.detail-bonus {
  background: var(--bg1); border-radius: 8px; padding: 8px 10px;
  border: 1px solid rgba(251,191,36,0.2);
}
.bonus-line { font-size: 0.8rem; }
.bonus-total {
  font-size: 0.9rem; font-weight: 900; color: var(--gold);
  margin-top: 4px; padding-top: 4px; border-top: 1px solid rgba(255,255,255,0.1);
}

/* プレイヤーチップをタップ可能に */
.p-chip { cursor: pointer; transition: transform 0.15s; }
.p-chip:active { transform: scale(0.96); }

/* 特殊アクションボタン */
.special-btn {
  display: block; width: 100%; margin-top: 8px;
  padding: 12px 16px; border: none; border-radius: 12px;
  font-size: 0.9rem; font-weight: 700;
  background: linear-gradient(135deg, var(--blue), #4f46e5);
  color: #fff; cursor: pointer;
  transition: transform 0.15s;
}
.special-btn:active { transform: scale(0.96); }
.special-btn.boom {
  background: linear-gradient(135deg, var(--accent), #b91c1c);
}
