/* PING PONG DUEL — レトロなインディーゲーム風（太い黒フチ・ぼかしのない影・少ない色） */
:root {
  --ink: #000; --night: #1D2B53; --plum: #7E2553; --forest: #008751; --brown: #AB5236;
  --slate: #5F574F; --silver: #C2C3C7; --paper: #FFF1E8; --red: #FF004D; --orange: #FFA300;
  --yellow: #FFEC27; --green: #00E436; --sky: #29ADFF; --lavender: #83769C; --pink: #FF77A8;
  --peach: #FFCCAA;
  --pixel: "Press Start 2P", "DotGothic16", monospace;
  --jp: "DotGothic16", "Hiragino Sans", "Noto Sans JP", sans-serif;
  --sat: env(safe-area-inset-top, 0px);
  --sab: env(safe-area-inset-bottom, 0px);
  --sal: env(safe-area-inset-left, 0px);
  --sar: env(safe-area-inset-right, 0px);
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body {
  margin: 0; height: 100%; overflow: hidden;
  background: var(--night); color: var(--paper);
  font-family: var(--jp);
  -webkit-text-size-adjust: 100%;
  overscroll-behavior: none;
  -webkit-user-select: none; user-select: none;
  -webkit-touch-callout: none;
}
button { font: inherit; color: inherit; cursor: pointer; }
button:disabled { cursor: default; }
[hidden] { display: none !important; }

#app { position: fixed; inset: 0; }

/* 市松模様の床 */
.screen {
  position: absolute; inset: 0; display: none;
  background-color: var(--night);
  background-image:
    linear-gradient(45deg, rgba(131,118,156,.16) 25%, transparent 25%, transparent 75%, rgba(131,118,156,.16) 75%),
    linear-gradient(45deg, rgba(131,118,156,.16) 25%, transparent 25%, transparent 75%, rgba(131,118,156,.16) 75%);
  background-size: 48px 48px;
  background-position: 0 0, 24px 24px;
}
.screen.active { display: block; }
.scroll {
  position: absolute; inset: 0; overflow-y: auto; -webkit-overflow-scrolling: touch;
  padding: calc(var(--sat) + 16px) calc(var(--sar) + 16px) calc(var(--sab) + 16px) calc(var(--sal) + 16px);
}

/* ---- 色付きのドット箱 ---- */
.c-yellow { --bg: var(--yellow); --fg: var(--ink); }
.c-green  { --bg: var(--green);  --fg: var(--ink); }
.c-orange { --bg: var(--orange); --fg: var(--ink); }
.c-pink   { --bg: var(--pink);   --fg: var(--ink); }
.c-sky    { --bg: var(--sky);    --fg: var(--ink); }
.c-red    { --bg: var(--red);    --fg: var(--paper); }
.c-silver { --bg: var(--silver); --fg: var(--ink); }
.c-lavender { --bg: var(--lavender); --fg: var(--ink); }
.c-peach  { --bg: var(--peach);  --fg: var(--ink); }

.tile, .sq, .wide, .card, .score, .panel-btn {
  background: var(--bg); color: var(--fg);
  border: 3px solid var(--ink);
  box-shadow: inset 0 4px 0 rgba(255,255,255,.28), 0 5px 0 var(--ink);
  border-radius: 0;
}
.tile, .sq, .wide, .panel-btn { transition: transform .05s, box-shadow .05s; touch-action: manipulation; }
.tile:active, .sq:active, .wide:active, .panel-btn:active,
.tile.pressed, .sq.pressed, .wide.pressed {
  transform: translateY(4px);
  box-shadow: inset 0 4px 0 rgba(255,255,255,.28), 0 1px 0 var(--ink);
}
.wide:disabled, .panel-btn:disabled { opacity: .5; transform: none; }
.ico { width: 1em; height: 1em; fill: currentColor; shape-rendering: crispEdges; display: block; }

/* ---- タイトル ---- */
.menu-inner, .sub-inner { max-width: 460px; margin: 0 auto; }
.logo {
  position: relative; margin: 12px 0 6px; text-align: center;
  font-family: var(--pixel); font-weight: normal; line-height: 1.15;
}
.logo .l1, .logo .l2 {
  display: block; font-size: clamp(34px, 12vw, 54px); color: var(--yellow);
  text-shadow: 4px 4px 0 var(--ink), -2px -2px 0 var(--ink), 2px -2px 0 var(--ink), -2px 2px 0 var(--ink);
}
.logo .l2 { color: var(--red); }
.logo .l3 {
  display: inline-block; margin-top: 10px; padding: 8px 12px 6px;
  font-size: 14px; letter-spacing: 6px; color: var(--ink); background: var(--sky);
  border: 3px solid var(--ink); box-shadow: 0 4px 0 var(--ink);
}
.logo-ball {
  position: absolute; width: 18px; height: 18px; right: 14%; top: 0;
  background: var(--paper); border: 3px solid var(--ink); border-radius: 50%;
  animation: hop 1.1s infinite cubic-bezier(.3,0,.7,1) alternate;
}
@keyframes hop { from { transform: translateY(0); } to { transform: translateY(-14px); } }
.tagline { text-align: center; margin: 12px 0 20px; font-size: 15px; color: var(--silver); }

.tiles { display: grid; grid-template-columns: 1fr 1fr; gap: 14px 12px; }
.tile {
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 8px;
  min-height: 118px; padding: 14px 6px 12px;
}
.tile .ico { font-size: 30px; }
.tile b { font-family: var(--pixel); font-weight: normal; font-size: 14px; }
.tile span { font-size: 13px; line-height: 1.2; }

.options { display: flex; align-items: flex-end; gap: 10px; margin-top: 22px; }
.opt { flex: 1; min-width: 0; }
.opt-label { display: block; font-family: var(--pixel); font-size: 9px; color: var(--silver); margin: 0 0 6px 2px; }
.seg { display: flex; border: 3px solid var(--ink); box-shadow: 0 4px 0 var(--ink); background: var(--slate); }
.seg button {
  flex: 1; min-width: 0; padding: 10px 0 8px; border: 0; background: transparent; color: var(--silver);
  font-family: var(--pixel); font-size: 11px; white-space: nowrap; touch-action: manipulation;
}
.seg button + button { border-left: 3px solid var(--ink); }
.seg button[aria-checked="true"] { background: var(--yellow); color: var(--ink); }
.sq { width: 52px; height: 48px; padding: 0; display: grid; place-items: center; flex: none; }
.sq .ico { font-size: 22px; }
#btnSound .off { display: none; }
#btnSound.muted .on { display: none; }
#btnSound.muted .off { display: block; }

.foot {
  display: flex; justify-content: space-between; margin: 34px 2px 4px;
  font-size: 13px; color: var(--lavender);
}
.foot { gap: 12px; flex-wrap: wrap; }
.foot a { color: var(--silver); text-decoration: none; }

/* 広告: 操作ボタンから十分に離し（誤タップ防止）、内容と区別できるようにラベルを付ける */
.ad-wrap { margin: 120px 0 8px; padding-top: 12px; border-top: 2px dashed rgba(194,195,199,.3); min-height: 100px; }
.ad-label { margin: 0 0 6px; font-size: 11px; color: var(--lavender); text-align: center; }
.ad-wrap:has(ins[data-ad-status="unfilled"]) { display: none; }

/* ---- サブ画面 ---- */
.sub-head { display: flex; align-items: center; gap: 14px; margin: 4px 0 22px; }
.sub-head h2 { margin: 0; font-family: var(--pixel); font-weight: normal; font-size: 20px; color: var(--yellow); text-shadow: 3px 3px 0 var(--ink); }

.wide {
  display: block; width: 100%; padding: 16px 10px 14px; margin: 0 0 18px;
  font-size: 18px; font-family: var(--jp);
}
.or { text-align: center; color: var(--lavender); margin: 2px 0 14px; }
.joinbox { background: rgba(0,0,0,.3); border: 3px solid var(--ink); padding: 14px 14px 0; }
.joinbox label { display: block; margin-bottom: 10px; color: var(--silver); font-size: 14px; }
#codeInput {
  display: block; width: 100%; margin: 0 0 14px; padding: 12px 0 8px;
  font-family: var(--pixel); font-size: 32px; letter-spacing: 14px; text-align: center; text-indent: 14px;
  color: var(--ink); background: var(--paper); border: 3px solid var(--ink); border-radius: 0;
  -webkit-user-select: text; user-select: text; outline: none;
}
#codeInput:focus { background: #fff; box-shadow: 0 0 0 3px var(--yellow); }
.note { color: var(--silver); font-size: 14px; line-height: 1.7; margin: 16px 2px; }
.center { text-align: center; }
.label { text-align: center; color: var(--silver); margin: 0 0 8px; }
.code {
  font-family: var(--pixel); font-size: 54px; letter-spacing: 10px; text-indent: 10px; text-align: center;
  color: var(--yellow); text-shadow: 4px 4px 0 var(--ink);
  padding: 22px 0 18px; background: rgba(0,0,0,.35); border: 3px solid var(--ink);
}
.waiting { text-align: center; color: var(--paper); margin: 6px 0 22px; }
.waiting.big { font-size: 18px; margin: 40px 0 30px; }
.dots { display: inline-flex; gap: 5px; margin-left: 8px; vertical-align: middle; }
.dots i { width: 7px; height: 7px; background: var(--yellow); animation: blink 1s infinite steps(1); }
.dots i:nth-child(2) { animation-delay: .33s; }
.dots i:nth-child(3) { animation-delay: .66s; }
@keyframes blink { 50% { opacity: .15; } }
.msg { min-height: 1.5em; color: var(--pink); line-height: 1.6; font-size: 15px; text-align: center; }

.cards { display: grid; grid-template-columns: 1fr 1fr; gap: 14px 12px; }
.card { display: flex; flex-direction: column; align-items: center; gap: 8px; padding: 14px 6px 12px; text-align: center; }
.card b { font-family: var(--pixel); font-weight: normal; font-size: 12px; }
.card span { font-size: 13px; line-height: 1.35; }
.card small { font-size: 11px; opacity: .75; }
.spins { display: flex; justify-content: center; gap: 16px; margin: 22px 0 6px; font-size: 14px; }
.spins i { display: inline-block; width: 12px; height: 12px; margin-right: 6px; border: 2px solid var(--ink); vertical-align: -1px; }
.howto-text h3 { font-family: var(--pixel); font-weight: normal; font-size: 12px; color: var(--yellow); margin: 24px 0 8px; }
.howto-text p { margin: 0; color: var(--paper); line-height: 1.75; font-size: 14px; }

/* ---- 試合 ---- */
#game { background: var(--night); }
#cv { position: absolute; inset: 0; width: 100%; height: 100%; display: block; touch-action: none; }
#hud {
  position: absolute; left: 0; right: 0; top: 0; display: flex; align-items: flex-start; gap: 10px;
  padding: calc(var(--sat) + 8px) calc(var(--sar) + 16px) 0 calc(var(--sal) + 16px);
  pointer-events: none; max-width: 640px; margin: 0 auto;
}
#hud > * { pointer-events: auto; }
#hud .sq { height: 56px; width: 50px; }
.score { flex: 1; min-width: 0; height: 56px; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 6px; pointer-events: none !important; }
.score .pts { display: flex; align-items: center; gap: 6px; }
.score .srv { width: 8px; height: 8px; background: transparent; }
.score.serving .srv { background: var(--yellow); outline: 2px solid var(--ink); }
.score b { font-family: var(--pixel); font-weight: normal; font-size: 22px; color: var(--ink); }
.score .pips { display: flex; gap: 4px; }
.score .pips i { width: 10px; height: 6px; background: rgba(0,0,0,.25); }
.score .pips i.on { background: var(--yellow); outline: 1px solid var(--ink); }
.ping { width: 26px; height: 56px; display: grid; place-items: center; }
.ping svg { width: 18px; height: 18px; fill: currentColor; shape-rendering: crispEdges; }
.ping.good { color: var(--green); } .ping.mid { color: var(--yellow); } .ping.bad { color: var(--red); }

#btnLocalMenu { position: absolute; width: 44px; height: 42px; display: none; }
#btnLocalMenu .ico { font-size: 18px; }
#game.local #hud { display: none; }
#game.local #btnLocalMenu { display: grid; }
#game.local #btnLocalMenu { left: calc(var(--sal) + 10px); top: calc(var(--sat) + 10px); }

.overlay {
  position: absolute; inset: 0; display: grid; place-items: center; padding: 20px;
  background: rgba(0,0,0,.35);
}
.overlay.passive { pointer-events: none; background: transparent; }
.panel {
  width: min(400px, 100%); max-height: 100%; overflow-y: auto;
  background: var(--panel, var(--night)); color: var(--paper);
  border: 3px solid var(--ink); box-shadow: inset 0 4px 0 rgba(255,255,255,.2), 0 6px 0 var(--ink);
  padding: 22px 18px 20px; text-align: center;
  animation: pop .22s cubic-bezier(.3,1.6,.6,1);
}
@keyframes pop { from { transform: scale(.6); opacity: 0; } }
.panel h3 {
  margin: 4px 0 14px; font-family: var(--pixel); font-weight: normal; font-size: 30px;
  color: var(--yellow); text-shadow: 3px 3px 0 var(--ink);
}
.panel h3.small { font-size: 20px; }
.panel h3.lose { color: var(--silver); }
.panel p { margin: 6px 0 14px; line-height: 1.6; }
.panel .row { display: flex; gap: 12px; margin-top: 16px; }
.panel-btn { flex: 1; height: 62px; display: grid; place-items: center; padding: 0; }
.panel-btn .ico { font-size: 26px; }
.panel .gp { display: flex; justify-content: center; align-items: center; gap: 18px; margin: 4px 0 12px; font-family: var(--pixel); }
.panel .gp span { display: flex; gap: 6px; }
.panel .gp i { width: 18px; height: 18px; border: 2px solid var(--ink); background: rgba(0,0,0,.4); }
.stats { width: 100%; border-collapse: collapse; background: rgba(0,0,0,.35); margin: 6px 0 4px; font-size: 13px; }
.stats td { padding: 6px 8px; text-align: left; }
.stats td:first-child { color: var(--silver); width: 42%; white-space: nowrap; }
.stats td.p0 { color: var(--red); font-family: var(--pixel); font-size: 10px; }
.stats td.p1 { color: var(--sky); font-family: var(--pixel); font-size: 10px; }
.stats tr.head td { font-family: var(--pixel); font-size: 9px; padding-top: 10px; }
.panel .wait { color: var(--silver); font-size: 14px; }

.toast {
  position: fixed; left: 50%; bottom: calc(var(--sab) + 28px); transform: translate(-50%, 20px);
  background: var(--ink); color: var(--paper); border: 3px solid var(--paper);
  padding: 10px 16px 8px; font-size: 14px; opacity: 0; pointer-events: none;
  transition: opacity .2s, transform .2s; z-index: 10; max-width: 90vw; text-align: center;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }
.noscript { position: fixed; inset: 40% 20px auto; text-align: center; }

@media (min-width: 700px) {
  .tile { min-height: 132px; }
}
