@import url('https://fonts.googleapis.com/css2?family=Rajdhani:wght@600;700&display=swap');

* { box-sizing: border-box; }
html, body {
  margin: 0; padding: 0; width: 100%; height: 100%;
  background: #0a0c14; color: #eef1f8;
  font-family: 'Segoe UI', 'Hiragino Kaku Gothic ProN', 'Yu Gothic', sans-serif;
  overflow-x: hidden;
}

.screen { display: none; min-height: 100vh; position: relative; }
.screen.active { display: block; }

button { cursor: pointer; font-family: inherit; }

/* ============ タイトル ============ */
#screen-title { display: none; }
#screen-title.active { display: flex; align-items: center; justify-content: center; }
.title-bg {
  position: absolute; inset: 0;
  background:
    radial-gradient(1200px 600px at 20% -10%, rgba(80,140,255,0.35), transparent 60%),
    radial-gradient(1000px 700px at 90% 110%, rgba(255,90,60,0.28), transparent 60%),
    linear-gradient(160deg, #090b13, #10131f 60%, #0a0c14);
  animation: bgshift 14s ease-in-out infinite alternate;
}
@keyframes bgshift { from { filter: hue-rotate(0deg); } to { filter: hue-rotate(18deg); } }
.title-wrap { position: relative; z-index: 2; text-align: center; padding: 40px 20px; }
.logo { font-family: 'Rajdhani', 'Segoe UI', sans-serif; font-size: 5.2rem; margin: 0; line-height: 0.95; letter-spacing: 2px; }
.logo-s { display: block; color: #fff; text-shadow: 0 0 24px rgba(120,170,255,0.7), 0 4px 0 #1a2a55; }
.logo-d { display: block; color: #ffcf3d; text-shadow: 0 0 24px rgba(255,180,50,0.6), 0 4px 0 #6b3d00; font-size: 3.4rem; }
.subtitle { color: #b7c1da; margin: 18px 0 30px; font-size: 1.05rem; }
.title-menu { display: flex; flex-direction: column; gap: 14px; align-items: center; }
.version { color: #566; margin-top: 30px; font-size: 0.8rem; }

.btn-main {
  background: linear-gradient(180deg, #ff8a3d, #ff5a1a);
  border: none; color: #fff; font-weight: 700; font-size: 1.3rem;
  padding: 16px 46px; border-radius: 50px; box-shadow: 0 8px 0 #a63c0a, 0 10px 20px rgba(0,0,0,0.4);
  transition: transform 0.12s;
}
.btn-main:hover:not(:disabled) { transform: translateY(-2px); }
.btn-main:active:not(:disabled) { transform: translateY(4px); box-shadow: 0 4px 0 #a63c0a; }
.btn-main:disabled { background: #444a5a; box-shadow: 0 8px 0 #262a35; cursor: not-allowed; opacity: 0.6; }
.btn-sub {
  background: rgba(255,255,255,0.08); border: 2px solid rgba(255,255,255,0.25); color: #dfe6f5;
  font-size: 1rem; padding: 10px 30px; border-radius: 40px; transition: 0.15s;
}
.btn-sub:hover { background: rgba(255,255,255,0.18); }

/* ============ 汎用パネル ============ */
.panel-wrap { max-width: 900px; margin: 0 auto; padding: 40px 24px 60px; }
.panel-wrap h2 { text-align: center; font-size: 2rem; margin-bottom: 20px; color: #ffcf3d; }
.controls-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); gap: 16px; margin-bottom: 20px; }
.ctrl-card { background: rgba(255,255,255,0.05); border: 1px solid rgba(255,255,255,0.12); border-radius: 12px; padding: 16px; }
.ctrl-card h3 { margin: 0 0 10px; color: #7cd6ff; font-size: 1rem; }
.ctrl-card table { width: 100%; font-size: 0.88rem; border-collapse: collapse; }
.ctrl-card td { padding: 4px 2px; border-bottom: 1px solid rgba(255,255,255,0.08); }
.ctrl-card td:last-child { text-align: right; color: #ffd479; font-weight: 700; }
.hint { color: #9aa4bd; font-size: 0.85rem; line-height: 1.7; text-align: center; }
.strategy-box { background: rgba(255,207,61,0.07); border: 1px solid rgba(255,207,61,0.3); border-radius: 12px; padding: 14px 18px; margin: 14px 0; }
.strategy-box h3 { margin: 0 0 8px; color: #ffcf3d; font-size: 0.95rem; }
.strategy-box ul { margin: 0; padding-left: 20px; font-size: 0.85rem; line-height: 1.8; color: #dfe6f5; }
.strategy-box b { color: #7cd6ff; }
#screen-controls .btn-sub, #screen-setup .btn-sub { display: block; margin: 20px auto 0; }

/* ============ 設定画面 ============ */
.setup-wrap { max-width: 1180px; margin: 0 auto; padding: 30px 20px 60px; }
.setup-title { text-align: center; color: #ffcf3d; font-size: 1.8rem; margin-bottom: 20px; }
.player-slots { display: grid; grid-template-columns: repeat(4, 1fr); gap: 14px; margin-bottom: 26px; }
.slot-card { background: rgba(255,255,255,0.05); border: 2px solid rgba(255,255,255,0.12); border-radius: 14px; padding: 12px; text-align: center; transition: 0.15s; }
.slot-card.active { border-color: var(--sc, #7cd6ff); box-shadow: 0 0 18px rgba(124,214,255,0.25); }
.slot-card .slot-label { font-weight: 700; color: #b7c1da; font-size: 0.85rem; margin-bottom: 6px; }
.slot-mode-btn { width: 100%; padding: 8px; border-radius: 8px; border: none; background: #232a3d; color: #dfe6f5; font-weight: 700; margin-bottom: 8px; }
.slot-mode-btn.human { background: #2a6bd6; }
.slot-mode-btn.cpu { background: #b0472f; }
.char-picker { display: flex; align-items: center; justify-content: center; gap: 6px; margin-bottom: 8px; }
.char-picker button { width: 28px; height: 28px; border-radius: 50%; border: none; background: rgba(255,255,255,0.12); color: #fff; font-weight: 700; }
.char-portrait { width: 60px; height: 60px; border-radius: 50%; margin: 0 auto 6px; display: flex; align-items: center; justify-content: center; font-weight: 900; font-size: 1.3rem; border: 3px solid #fff3; }
.char-name { font-size: 0.82rem; font-weight: 700; }
.char-title { font-size: 0.68rem; color: #9aa4bd; margin-top: 2px; min-height: 2.4em; }
.slot-empty-note { color: #6a7390; font-size: 0.8rem; padding: 30px 0; }

.setup-row { display: grid; grid-template-columns: 1.4fr 1fr; gap: 24px; align-items: start; }
.setup-col h3 { color: #7cd6ff; font-size: 1rem; margin-bottom: 10px; }
.stage-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
.stage-card { border: 3px solid transparent; border-radius: 12px; padding: 10px; background: rgba(255,255,255,0.05); text-align: center; }
.stage-card.selected { border-color: #ffcf3d; box-shadow: 0 0 16px rgba(255,207,61,0.35); }
.stage-thumb { width: 100%; height: 64px; border-radius: 8px; margin-bottom: 6px; }
.stage-card .stage-name { font-size: 0.82rem; font-weight: 700; }
.setup-options { background: rgba(255,255,255,0.04); border-radius: 14px; padding: 18px; }
.opt-line { display: flex; align-items: center; justify-content: space-between; margin-bottom: 12px; font-size: 0.92rem; }
.opt-line label { display: flex; align-items: center; gap: 6px; }
.btn-fight { width: 100%; margin-top: 10px; }
#btn-setup-back { display: block; width: 100%; margin-top: 10px; }

/* ============ バトル ============ */
#screen-battle.active { display: block; }
.battle-wrap { position: relative; width: 100%; max-width: 1280px; margin: 0 auto; }
#canvas { width: 100%; height: auto; aspect-ratio: 16/9; display: block; background: #000; image-rendering: -webkit-optimize-contrast; }
.pause-btn {
  position: absolute; top: 12px; right: 12px; width: 42px; height: 42px; border-radius: 50%;
  background: rgba(10,12,20,0.6); color: #fff; border: 2px solid rgba(255,255,255,0.35); font-size: 1.1rem; z-index: 9;
}
.online-latency-badge {
  position: absolute; top: 12px; left: 12px; background: rgba(10,12,20,0.6); color: #7cd6ff;
  border: 2px solid rgba(124,214,255,0.4); border-radius: 20px; padding: 5px 12px; font-size: 0.78rem; z-index: 9;
}
.online-latency-badge.hidden { display: none; }
select:disabled, input:disabled { opacity: 0.6; cursor: not-allowed; }

.overlay { position: fixed; inset: 0; background: rgba(4,5,10,0.82); z-index: 50; display: flex; align-items: center; justify-content: center; }
.overlay.hidden { display: none; }
.panel-wrap.small { background: #12141f; border-radius: 18px; border: 1px solid rgba(255,255,255,0.12); padding: 30px 30px 24px; max-width: 380px; }
.panel-wrap.small button { display: block; width: 100%; margin-bottom: 10px; }
.results-panel { max-width: 460px; text-align: center; }
#resultsBody { margin-bottom: 20px; }
.result-row { display: flex; align-items: center; gap: 10px; justify-content: center; padding: 6px 0; font-size: 0.95rem; }
.result-crown { color: #ffcf3d; }

/* ============ 紙吹雪 ============ */
#confettiCanvas { position: fixed; inset: 0; pointer-events: none; z-index: 60; display: none; }

/* ============ 設定・クイックヘルプ ============ */
.gear-btn {
  position: absolute; top: 16px; right: 16px; width: 44px; height: 44px; border-radius: 50%;
  background: rgba(255,255,255,0.08); border: 2px solid rgba(255,255,255,0.25); color: #fff; font-size: 1.2rem; z-index: 3;
}
.btn-quick { background: linear-gradient(180deg, #ffd23d, #e6a300); box-shadow: 0 8px 0 #8a5f00, 0 10px 20px rgba(0,0,0,0.4); }
.settings-row { display: flex; align-items: center; justify-content: space-between; margin-bottom: 16px; font-size: 0.95rem; }
.volume-slider { width: 55%; }
.quickhelp-btn {
  position: absolute; top: 12px; right: 62px; width: 42px; height: 42px; border-radius: 50%;
  background: rgba(10,12,20,0.6); color: #fff; border: 2px solid rgba(255,255,255,0.35); font-size: 1.1rem; z-index: 9;
}
.quickhelp-panel { max-width: 480px; }
#screen-settings, #screen-quickhelp { z-index: 55; }
.qh-grid { display: grid; gap: 10px; margin-bottom: 14px; font-size: 0.85rem; }
.qh-grid div { background: rgba(255,255,255,0.05); border-radius: 10px; padding: 10px 12px; line-height: 1.7; }
.qh-grid b { color: #7cd6ff; }

/* ============ わかりやすさ用の補助スタイル ============ */
.setup-hint { text-align: center; color: #9aa4bd; font-size: 0.85rem; margin: -12px 0 20px; }
.ctrl-note { color: #cfd7ea; font-size: 0.85rem; line-height: 1.7; }
.btn-online { background: linear-gradient(180deg, #3dd6ff, #1a8fd6); box-shadow: 0 8px 0 #0a4d75, 0 10px 20px rgba(0,0,0,0.4); }
.btn-main.small, .btn-sub.small { padding: 8px 20px; font-size: 0.9rem; box-shadow: none; }
.stage-card.readonly { cursor: default; }
.readonly-panel { opacity: 0.72; pointer-events: none; }
.host-tag { font-size: 0.75rem; color: #7cd6ff; font-weight: 400; }

/* ============ オンライン: メニュー ============ */
.online-menu-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); gap: 18px; margin: 24px 0; }
.online-menu-card { background: rgba(255,255,255,0.05); border: 1px solid rgba(255,255,255,0.14); border-radius: 16px; padding: 24px 20px; text-align: center; }
.online-menu-icon { font-size: 2.4rem; margin-bottom: 8px; }
.online-menu-card h3 { margin: 4px 0 8px; color: #ffcf3d; }
.online-menu-card p { color: #9aa4bd; font-size: 0.85rem; min-height: 3em; }
.online-menu-card button { margin-top: 10px; width: 100%; }
.code-input {
  width: 100%; text-align: center; font-size: 1.4rem; letter-spacing: 0.3em; text-transform: uppercase;
  padding: 10px; border-radius: 10px; border: 2px solid rgba(255,255,255,0.25); background: rgba(0,0,0,0.3); color: #fff; margin-bottom: 10px;
}
.online-error { text-align: center; color: #ff8a6b; min-height: 1.4em; font-size: 0.9rem; }

/* ============ オンライン: ロビー ============ */
.online-room-code { text-align: center; margin-bottom: 8px; font-size: 1rem; }
.online-room-code b { font-size: 1.8rem; letter-spacing: 0.3em; color: #ffcf3d; margin: 0 10px; }
.online-status { text-align: center; color: #7cd6ff; margin-bottom: 20px; font-size: 0.95rem; }
.online-players { grid-template-columns: repeat(2, 1fr); max-width: 560px; margin: 0 auto 26px; }
.online-players .slot-card { transition: opacity 0.2s; }
.online-players .slot-card:not(.active) { opacity: 0.55; }
#btn-online-ready.ready-on { background: linear-gradient(180deg, #3ddc7a, #1a9e50); box-shadow: 0 6px 0 #0d5c2c; }

/* ============ タッチ操作 ============ */
.touch-controls { position: absolute; inset: 0; pointer-events: none; z-index: 8; user-select: none; -webkit-user-select: none; touch-action: none; }
.touch-controls.hidden { display: none; }
.tc-stick-zone { position: absolute; left: 4%; bottom: 6%; width: 130px; height: 130px; pointer-events: auto; touch-action: none; }
.tc-stick-base { width: 100%; height: 100%; border-radius: 50%; background: rgba(255,255,255,0.10); border: 2px solid rgba(255,255,255,0.25); display: flex; align-items: center; justify-content: center; }
.tc-stick-knob { width: 56px; height: 56px; border-radius: 50%; background: rgba(255,255,255,0.35); border: 2px solid rgba(255,255,255,0.5); transition: transform 0.03s linear; }
.tc-buttons { position: absolute; right: 3%; bottom: 4%; width: 210px; height: 190px; }
.tc-btn {
  position: absolute; border-radius: 50%; border: 2px solid rgba(255,255,255,0.35); background: rgba(20,24,36,0.55);
  color: #fff; display: flex; flex-direction: column; align-items: center; justify-content: center; font-size: 1.3rem; line-height: 1;
  pointer-events: auto; touch-action: none; gap: 2px;
}
.tc-btn span { font-size: 0.55rem; color: #cfd7ea; }
.tc-btn.active { background: rgba(255,140,60,0.55); border-color: #ffb066; }
.tc-attack { width: 82px; height: 82px; right: 0; bottom: 0; font-size: 1.7rem; }
.tc-jump { width: 62px; height: 62px; right: 78px; bottom: 70px; }
.tc-special { width: 62px; height: 62px; right: 4px; bottom: 108px; }
.tc-shield { width: 54px; height: 54px; right: 130px; bottom: 4px; }
.tc-grab { width: 54px; height: 54px; right: 150px; bottom: 110px; }

@media (max-width: 900px) {
  .setup-row { grid-template-columns: 1fr; }
  .player-slots { grid-template-columns: repeat(2, 1fr); }
  .logo { font-size: 3.4rem; } .logo-d { font-size: 2.2rem; }
}
