*{box-sizing:border-box;margin:0;padding:0}
:root{
  --bg:#0d0f14; --panel:#161a22; --line:#2a2f3a;
  --text:#e8ecf2; --muted:#9aa3b2; --accent:#ff4d5a; --accent2:#4db8ff;
}
html,body{height:100%}
body{
  background:var(--bg); color:var(--text);
  font-family:"Segoe UI","Hiragino Kaku Gothic ProN","Yu Gothic",Meiryo,sans-serif;
  display:flex; align-items:center; justify-content:center;
  overflow:hidden; touch-action:none; user-select:none;
}
#wrap{width:100%; max-width:820px; padding:10px}

#hud{
  display:flex; align-items:center; gap:14px; flex-wrap:wrap;
  padding:8px 10px; background:var(--panel);
  border:1px solid var(--line); border-radius:10px 10px 0 0;
  font-size:13px;
}
.hud-title{font-weight:800; letter-spacing:1px; color:var(--accent)}
.hud-item b{color:var(--accent2); font-size:15px}
#btn-reset{margin-left:auto}

button{
  background:var(--accent); color:#fff; border:0; border-radius:8px;
  padding:8px 16px; font-weight:700; font-size:14px; cursor:pointer;
  font-family:inherit;
}
button:hover{filter:brightness(1.1)}
#btn-reset,#btn-log{background:#2a2f3a; padding:6px 12px; font-size:12px}

#stage-area{position:relative; width:100%; aspect-ratio:800/480; background:#000;
  border-left:1px solid var(--line); border-right:1px solid var(--line)}
#game{display:block; width:100%; height:100%; image-rendering:pixelated}

.overlay{
  position:absolute; inset:0; display:flex; align-items:center; justify-content:center;
  background:rgba(6,8,12,.86); backdrop-filter:blur(2px); padding:16px; z-index:5;
}
.overlay.hidden{display:none}
.panel{
  background:var(--panel); border:1px solid var(--line); border-radius:14px;
  padding:22px 24px; max-width:460px; width:100%; text-align:center;
}
.panel h1{font-size:26px; margin-bottom:10px; color:var(--accent)}
.panel h2{font-size:20px; margin-bottom:12px}
.lead{color:var(--text); margin-bottom:14px; line-height:1.6}
.controls{list-style:none; text-align:left; display:inline-block; margin:6px auto 14px; color:var(--muted); line-height:1.9; font-size:13px}
.controls b{color:var(--text)}
.warn{color:var(--accent); font-size:13px; margin-bottom:16px; line-height:1.6}
.rotate-hint{color:var(--accent2); font-size:13px; margin-bottom:14px}
.rotate-hint b{color:var(--text)}
.panel button{width:100%; padding:12px}

.log-panel{max-width:520px}
#log-body{text-align:left; max-height:50vh; overflow:auto; margin-bottom:14px; font-size:13px; line-height:1.6}
#log-body h3{font-size:14px; color:var(--accent2); margin:12px 0 4px}
#log-body ul{margin-left:18px; color:var(--muted)}

#touch{display:none; gap:10px; margin-top:8px}
#touch .pad{
  flex:1; background:var(--panel); border:1px solid var(--line);
  color:var(--text); font-size:20px; padding:18px 0; border-radius:12px;
}
#touch .pad-jump{flex:1.4; background:var(--accent); color:#fff}
#touch .pad:active{filter:brightness(1.4)}

#foot{
  display:flex; align-items:center; gap:12px; justify-content:space-between;
  padding:8px 10px; background:var(--panel);
  border:1px solid var(--line); border-radius:0 0 10px 10px;
  font-size:12px; color:var(--muted);
}

@media (hover:none) and (pointer:coarse){
  #touch{display:flex}
}

/* ---- portrait / small screens ---- */
@media (max-width:640px){
  body{align-items:stretch}
  #wrap{
    padding:0;
    display:flex; flex-direction:column;
    height:100%; height:100dvh;
  }
  #hud{
    border-radius:0; border-left:0; border-right:0; border-top:0;
    gap:10px; font-size:12px; padding:7px 10px;
    flex-wrap:nowrap; overflow-x:auto;
  }
  .hud-title{display:none}
  #btn-reset{padding:6px 10px; font-size:11px; white-space:nowrap}

  #stage-area{
    flex:1 1 auto;             /* game fills the space above the controls */
    min-height:0;
    aspect-ratio:auto;
    border-left:0; border-right:0;
  }
  #game{width:100%; height:100%; display:block; object-fit:contain}

  #touch{
    display:flex; gap:8px; margin:0;
    flex:0 0 auto; height:150px; align-items:stretch;
    padding:10px 10px calc(10px + env(safe-area-inset-bottom));
    background:var(--panel); border-top:1px solid var(--line);
  }
  #touch .pad{
    display:flex; align-items:center; justify-content:center;
    padding:0; font-size:24px; border-radius:16px;
    -webkit-user-select:none; user-select:none;
  }
  #touch .pad-jump{flex:1.5}

  #foot{
    border-radius:0; border-left:0; border-right:0; border-bottom:0;
    padding:6px 10px; font-size:11px;
  }

  .panel{padding:18px 18px}
  .panel h1{font-size:21px}
  .lead{font-size:14px}
}

/* landscape phone: keep the 5:3 canvas, controls overlaid at the sides */
@media (max-width:900px) and (orientation:landscape) and (pointer:coarse){
  #wrap{padding:0; height:100dvh; display:flex; flex-direction:column}
  #hud{border-radius:0; padding:5px 10px; font-size:11px}
  #stage-area{flex:1 1 auto; aspect-ratio:auto; min-height:0}
  #game{width:100%; height:100%; object-fit:contain}
  #touch{
    display:flex; position:absolute; left:0; right:0; bottom:0;
    background:transparent; border:0; padding:0 10px 10px; gap:14px;
    pointer-events:none;
  }
  #touch .pad{
    pointer-events:auto; opacity:.85; max-width:110px; padding:16px 0;
    font-size:20px;
  }
  #touch .pad-jump{margin-left:auto; max-width:150px}
  #foot{display:none}
}
