* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; overflow: hidden; background: #0a0e16; color: #e6ebf5;
  font-family: system-ui, -apple-system, "Segoe UI", "Hiragino Sans", "Noto Sans JP", sans-serif; }
[hidden] { display: none !important; }
canvas { position: fixed; inset: 0; display: block; }
button { font: inherit; cursor: pointer; border: 0; border-radius: 10px; color: #fff; }
button:disabled { opacity: 0.35; cursor: default; }

.panel { position: fixed; background: rgba(14, 20, 32, 0.82); border: 1px solid rgba(255,255,255,0.08);
  border-radius: 12px; backdrop-filter: blur(6px); }

/* ランキング */
#lb { top: 12px; left: 12px; width: 250px; padding: 8px 12px; font-size: 13px; }
#lb h3 { margin: 0 0 4px; font-size: 12px; color: #8a96ad; font-weight: 600; letter-spacing: .05em; }
#lb ol { list-style: none; margin: 0; padding: 0; }
#lb.all ol { max-height: 55vh; overflow-y: auto; }
#lb li { display: flex; justify-content: space-between; gap: 8px; padding: 2px 0; white-space: nowrap; }
#lb li span:first-child { overflow: hidden; text-overflow: ellipsis; }
#lb li.me { color: #6fc3ff; font-weight: 700; }
#lb li.gap { justify-content: center; color: #5f6b82; padding: 0; line-height: 10px; }
#lbToggle { width: 100%; margin-top: 6px; padding: 4px 0; font-size: 12px; background: #1d2638; color: #aeb8cc; }

/* 部屋の様子 */
#crowd { top: 12px; left: 50%; transform: translateX(-50%); width: min(360px, calc(100% - 300px)); padding: 6px 12px;
  font-size: 12px; pointer-events: none; text-align: center; }
#crowdHead { font-size: 13px; font-weight: 600; margin-bottom: 4px; }
#crowdHead small { color: #8a96ad; font-weight: 400; }
#crowd .bar { display: flex; height: 6px; border-radius: 3px; overflow: hidden; background: #39425a; }
#barLong { background: #22d39a; transition: width .5s; }
#barShort { background: #ff5c6c; transition: width .5s; margin-left: auto; }
#crowdText { margin-top: 3px; color: #aeb8cc; display: flex; justify-content: space-between; }
.count { margin: -8px 0 14px; font-size: 13px; color: #22d39a; }
#lb .near { color: #f5c542; margin-right: 6px; font-size: 11px; }
.ai { display: inline-block; margin-left: 4px; padding: 0 4px; border-radius: 4px; font-size: 10px;
  line-height: 15px; background: #39425a; color: #b8c2d8; vertical-align: 1px; }

/* お知らせ */
#feed { position: fixed; left: 12px; bottom: 230px; display: flex; flex-direction: column; gap: 4px;
  pointer-events: none; font-size: 13px; }
#feed div { background: rgba(14, 20, 32, 0.8); padding: 4px 10px; border-radius: 8px; width: fit-content; }
#feed .bankrupt { color: #ff8c97; }
#feed .king { color: #f5c542; }
#feed .kill { color: #ffb38a; }
#feed .kill b { color: #fff; }
#feed .bounty { color: #7dffc4; font-weight: bold; border: 1px solid rgba(125, 255, 196, 0.5); }
#info.threat { color: #ff5c6c; font-weight: bold; animation: blink 0.6s steps(2) infinite; }
@keyframes blink { 50% { opacity: 0.45; } }
#deadkiller { color: #ffb38a; font-size: 13px; line-height: 1.6; margin-bottom: 12px; }
#deadkiller b { color: #fff; font-size: 16px; }

/* 操作パネル */
#hud { position: fixed; left: 50%; bottom: 10px; transform: translateX(-50%); width: min(720px, calc(100% - 16px));
  background: rgba(14, 20, 32, 0.9); border: 1px solid rgba(255,255,255,0.08); border-radius: 14px; padding: 10px 12px; }
#hud .row { display: flex; align-items: center; justify-content: space-between; gap: 10px; flex-wrap: wrap; }
#eq { font-size: 15px; }
#eq b { font-size: 20px; }
#eq .rank { margin-left: 8px; color: #8a96ad; }
#pos { font-size: 13px; color: #c7cfe0; }
#info { min-height: 18px; font-size: 12px; color: #f5c542; margin: 4px 0; }
.up { color: #22d39a; }
.down { color: #ff5c6c; }
.sel { display: flex; align-items: center; gap: 4px; font-size: 12px; color: #8a96ad; }
.sel span { margin-right: 4px; }
.sel button { background: #1d2638; padding: 6px 10px; font-size: 13px; }
.sel button.on { background: #3b6df0; }
.actions { margin-top: 8px; }
.actions button { flex: 1; padding: 14px 0; font-size: 18px; font-weight: 800; }
.buy { background: #13a876; }
.sell { background: #d6394b; }
.close { background: #3a4458; flex: 0.6 !important; }
.tools { margin-top: 6px; justify-content: flex-start !important; gap: 6px !important; }
.tools button { background: #1d2638; padding: 6px 10px; font-size: 12px; color: #c7cfe0; }
.tools button.on { background: #3a3150; color: #fff; box-shadow: inset 0 0 0 1px #8f7dff; }
#stopBtn.on { background: #4a3418; box-shadow: inset 0 0 0 1px #ffaa3c; }
#skillBtn.active { background: #13506a; box-shadow: inset 0 0 0 1px #3ad6ff; color: #fff; }
.skills { display: flex; gap: 6px; margin: 12px 0 0; }
.skills button { flex: 1; background: #1d2638; padding: 8px 4px; font-size: 12px; line-height: 1.4; color: #aeb8cc; }
.skills button b { display: block; font-size: 14px; color: #fff; }
.skills button.on { background: #24305a; box-shadow: inset 0 0 0 2px #6f8cff; }
#feed .stop { color: #ffaa3c; }
#feed .bountyOn { color: #7dffc4; }
#feed .skill { color: #3ad6ff; }
.keys { margin-top: 6px; font-size: 11px; color: #5f6b82; text-align: center; }

/* ロビーと破産画面 */
.overlay { position: fixed; inset: 0; display: flex; align-items: center; justify-content: center;
  background: rgba(5, 8, 14, 0.55); }
.card { width: min(460px, calc(100% - 24px)); background: rgba(14, 20, 32, 0.95); border: 1px solid rgba(255,255,255,0.1);
  border-radius: 16px; padding: 24px; text-align: center; }
.card h1 { margin: 0; font-size: 40px; letter-spacing: -0.02em; }
.card h2 { margin: 0 0 12px; font-size: 32px; color: #ff5c6c; }
.tagline { margin: 6px 0 16px; color: #c7cfe0; }
.join { display: flex; gap: 8px; }
.join input { flex: 1; min-width: 0; padding: 12px; font-size: 16px; border-radius: 10px; border: 1px solid #2c364a;
  background: #0f1522; color: #fff; }
.join button, #again { padding: 12px 22px; font-size: 18px; font-weight: 800; background: #13a876; }
.how { text-align: left; font-size: 13px; color: #aeb8cc; padding-left: 18px; margin: 16px 0 8px; line-height: 1.6; }
.disclaimer { font-size: 11px; color: #5f6b82; margin: 8px 0 0; }
#deadstats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin-bottom: 16px; }
#deadstats div { background: #111827; border-radius: 10px; padding: 10px 4px; font-size: 12px; color: #8a96ad; }
#deadstats b { display: block; margin-top: 4px; font-size: 18px; color: #fff; }
#again { width: 100%; }

#status { position: fixed; top: 12px; left: 50%; transform: translateX(-50%); background: #3a4458; padding: 6px 14px;
  border-radius: 8px; font-size: 13px; }

/* スマホ */
@media (max-width: 640px) {
  #lb { width: 170px; font-size: 11px; padding: 6px 8px; }
  #lb:not(.all) li:nth-child(n+6):not(.me) { display: none; }
  #crowd { left: auto; right: 8px; transform: none; width: calc(100% - 196px); font-size: 10px; padding: 5px 8px; }
  #crowdHead { font-size: 11px; }
  #feed { bottom: 250px; font-size: 11px; }
  .keys { display: none; }
  #pos { font-size: 12px; }
  .sel button { padding: 6px 8px; }
}

/* ---- 一人プレイ: 残りの相手・勝ち画面・顔の絵 ---- */
img.av, .cast img, #foes img { image-rendering: pixelated; }
#lb img.av { width: 20px; height: 20px; vertical-align: -5px; margin-right: 3px; }
#foes { top: 12px; right: 76px; width: 250px; padding: 8px 10px; font-size: 12px; }
#foes .foeHead { display: flex; justify-content: space-between; gap: 6px; color: #aeb8cc; margin-bottom: 4px; }
#foes .foeHead b { color: #fff; font-size: 13px; }
#foes .foeHead .storm { color: #7fd8ff; font-weight: 700; }
#foes .chips { display: flex; flex-wrap: wrap; gap: 2px; }
#foes .foe { position: relative; width: 26px; height: 26px; }
#foes .foe img { width: 26px; height: 26px; }
#foes .foe.dead img { filter: grayscale(1) brightness(.45); }
#foes .foe b { position: absolute; inset: 0; display: grid; place-items: center; color: #ff5c6c; font-size: 18px; }
#foes .foe.dead.you b { color: #f5c542; }
.cast { display: flex; justify-content: center; align-items: center; gap: 4px; margin-bottom: 6px; }
.cast img { width: 48px; height: 48px; }
.cast img.big { width: 96px; height: 96px; }
.cast span { font-weight: 900; color: #ff5c6c; margin: 0 6px; }
#winstats div, .foesWere { display: flex; justify-content: space-between; gap: 20px; padding: 3px 0; }
.foesWere { color: #ffb38a; justify-content: center; margin-top: 6px; }
#win h2 { color: #f5c542; }
#foes { width: 276px; }
/* 一人プレイでは「何人がプレイ中」を出さず、買い・売りの偏りだけ見せる */
body.solo #crowdHead { display: none; }
@media (max-width: 700px) {
  /* スマホ: 上の真ん中（買い売りの偏り）の代わりに、残りの相手を出す */
  body.solo #crowd { display: none; }
  #foes { top: 12px; right: 8px; width: calc(100% - 196px); padding: 6px 8px; }
  #foes .foeHead { flex-wrap: wrap; font-size: 11px; }
  #foes .foe, #foes .foe img { width: 20px; height: 20px; }
}

/* ---- 演出: 相手の破産・賞金・嵐・資産の増減・吹き出し・見出しの文字 ---- */
@font-face { font-family: 'DotGothic16'; src: url('fonts/DotGothic16-sub.woff2') format('woff2'); font-display: swap; }
h1, h2, .bust div, .flyGold, #foes .foeHead b { font-family: 'DotGothic16', system-ui, sans-serif; letter-spacing: .02em; }
body { font-variant-numeric: tabular-nums; }
.bust { position: fixed; left: 50%; top: 38%; transform: translate(-50%, -50%); text-align: center; pointer-events: none; z-index: 20;
  animation: bustIn 1.7s ease-out forwards; }
.bust img { width: 128px; height: 128px; image-rendering: pixelated; animation: bustShatter 1.7s ease-in forwards; }
.bust div { font-size: 26px; color: #ff8c97; text-shadow: 0 2px 8px #000; }
.bust small { display: block; color: #f5c542; font-size: 16px; font-weight: 800; }
.bust.you div { color: #f5c542; }
@keyframes bustIn { 0% { opacity: 0; transform: translate(-50%, -50%) scale(.6); } 12% { opacity: 1; transform: translate(-50%, -50%) scale(1.1); }
  20% { transform: translate(-50%, -50%) scale(1); } 75% { opacity: 1; } 100% { opacity: 0; transform: translate(-50%, -60%); } }
@keyframes bustShatter { 0%, 30% { filter: none; transform: none; } 34% { transform: translateX(-6px) rotate(-4deg); } 38% { transform: translateX(6px) rotate(4deg); }
  42% { transform: translateX(-4px); } 60% { filter: grayscale(1) brightness(.6); transform: scale(1.05); }
  100% { filter: grayscale(1) brightness(.3) blur(2px); transform: scale(1.4) rotate(8deg); opacity: 0; } }
.flyGold { position: fixed; left: 50%; bottom: 220px; transform: translateX(-50%); color: #f5c542; font-size: 30px; font-weight: 900;
  text-shadow: 0 2px 10px #000; pointer-events: none; z-index: 21; animation: flyGold 1.4s ease-in forwards; }
@keyframes flyGold { 0% { opacity: 0; transform: translate(-50%, 30px) scale(.7); } 20% { opacity: 1; transform: translate(-50%, 0) scale(1.15); }
  70% { opacity: 1; } 100% { opacity: 0; transform: translate(-120%, 160px) scale(.6); } }
#stormFx { position: fixed; inset: 0; pointer-events: none; opacity: 0; z-index: 5; transition: opacity 1s;
  box-shadow: inset 0 0 120px 30px rgba(60, 150, 255, .55); animation: stormPulse 2.2s ease-in-out infinite; }
@keyframes stormPulse { 50% { box-shadow: inset 0 0 160px 50px rgba(80, 170, 255, .75); } }
#eq b.flashUp { animation: flashUp .6s; }
#eq b.flashDown { animation: flashDown .6s; }
@keyframes flashUp { 0% { color: #22d39a; text-shadow: 0 0 12px #22d39a; } 100% { color: inherit; } }
@keyframes flashDown { 0% { color: #ff5c6c; text-shadow: 0 0 12px #ff5c6c; } 100% { color: inherit; } }
#tip { position: fixed; left: 50%; bottom: 250px; transform: translateX(-50%); background: #f5f7fb; color: #0b0f17; font-weight: 700;
  padding: 10px 16px; border-radius: 12px; font-size: 14px; z-index: 15; max-width: min(520px, calc(100% - 24px)); text-align: center;
  box-shadow: 0 6px 20px rgba(0,0,0,.5); animation: tipBob 1.2s ease-in-out infinite; pointer-events: none; }
#tip::after { content: ''; position: absolute; left: 50%; bottom: -8px; margin-left: -8px; border: 8px solid transparent; border-bottom: 0; border-top-color: #f5f7fb; }
@keyframes tipBob { 50% { transform: translate(-50%, -4px); } }
@media (pointer: coarse) { #hud .keys { display: none; } }
@media (max-width: 640px) {
  /* スマホ: ランキングは上位3人と自分だけ */
  #lb:not(.all) li:nth-child(n+4):not(.me):not(.gap) { display: none; }
  #tip { bottom: 300px; font-size: 13px; }
  .bust img { width: 96px; height: 96px; }
}
