* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; overflow: hidden; background: #111; color: #fff;
  font-family: "Segoe UI", "Yu Gothic UI", "Meiryo", "Hiragino Sans", system-ui, sans-serif; user-select: none; }
canvas#game { position: fixed; inset: 0; width: 100%; height: 100%; display: block; }
.hidden { display: none !important; }

/* HUD */
#hud { position: fixed; inset: 0; pointer-events: none; }
#topbar { position: absolute; top: 10px; left: 50%; transform: translateX(-50%); display: flex; gap: 8px; }
.stat { background: rgba(10,14,22,.72); border: 1px solid rgba(255,255,255,.12); border-radius: 8px; padding: 4px 12px;
  font-weight: 700; font-size: 18px; display: flex; gap: 6px; align-items: baseline; }
.stat .k { font-size: 11px; color: #9fb3c8; letter-spacing: .08em; }
.stat small { font-size: 11px; color: #ffd75e; font-weight: 600; }
.stat.yen span:last-child { color: #ffd75e; }
#xpbar { position: absolute; top: 0; left: 0; right: 0; height: 6px; background: rgba(0,0,0,.5); }
#xpfill { height: 100%; width: 0; background: linear-gradient(90deg, #3ec7ff, #7bffb5); transition: width .15s; }
#h-level { position: absolute; left: 10px; top: 10px; font-weight: 800; font-size: 20px; text-shadow: 0 2px 4px #000; }
#bars { position: absolute; left: 16px; bottom: 18px; width: 300px; }
.bar { position: relative; height: 18px; background: rgba(0,0,0,.6); border: 1px solid rgba(255,255,255,.25); border-radius: 5px; overflow: hidden; margin-top: 6px; }
.bar.hp div { height: 100%; background: linear-gradient(#ff5d5d, #c21d2b); width: 100%; }
.bar.st { height: 8px; }
.bar.st div { height: 100%; background: #ffd75e; width: 100%; }
.bar span { position: absolute; inset: 0; text-align: center; font-size: 12px; font-weight: 700; line-height: 18px; }
#slots { position: absolute; left: 16px; bottom: 64px; }
#wslots, #pslots { display: flex; gap: 4px; margin-top: 4px; }
.slot { width: 38px; height: 38px; border-radius: 6px; background: rgba(10,14,22,.75); border: 1px solid rgba(255,255,255,.2);
  display: flex; align-items: center; justify-content: center; font-size: 20px; position: relative; }
.slot b { position: absolute; right: 2px; bottom: 0; font-size: 10px; color: #ffd75e; }
.slot.evo { border-color: #ffd75e; box-shadow: 0 0 8px #ffd75e; }
.slot.empty { opacity: .3; }
#minimap-wrap { position: absolute; right: 14px; bottom: 14px; }
#minimap { width: 200px; height: 200px; border-radius: 12px; border: 2px solid rgba(255,255,255,.3); background: rgba(10,14,22,.7); display: block; }
#floortabs { display: flex; gap: 4px; margin-bottom: 4px; justify-content: flex-end; }
.ftab { background: rgba(10,14,22,.75); border: 1px solid rgba(255,255,255,.25); padding: 1px 8px; border-radius: 4px; font-size: 12px; font-weight: 700; }
.ftab.on { background: #ffd75e; color: #111; }
#bossbar { position: absolute; top: 60px; left: 50%; transform: translateX(-50%); width: 520px; text-align: center; }
#bossname { font-weight: 800; letter-spacing: .06em; text-shadow: 0 2px 4px #000; }
#bossbar .bar { height: 14px; }
#bossfill { height: 100%; background: linear-gradient(90deg, #a020f0, #ff3d7f); width: 100%; }
#prompt { position: absolute; left: 50%; bottom: 28%; transform: translateX(-50%); background: rgba(0,0,0,.75); border: 2px solid #ffd75e;
  padding: 8px 18px; border-radius: 8px; font-weight: 700; font-size: 18px; }
#prompt kbd { background: #ffd75e; color: #111; border-radius: 4px; padding: 0 7px; margin-right: 6px; }
#prompt.tried { border-color: #ff4d4d; }
#lockon { position: absolute; left: 50%; top: 56%; transform: translateX(-50%); color: #ff5d5d; font-weight: 800; font-size: 12px; letter-spacing: .2em; }
#crosshair { position: absolute; left: 50%; top: 50%; width: 6px; height: 6px; margin: -3px; border-radius: 50%; background: rgba(255,255,255,.5); }

#banner { position: fixed; left: 0; right: 0; top: 30%; text-align: center; font-size: 72px; font-weight: 900; letter-spacing: .04em;
  color: #ff4040; text-shadow: 0 4px 0 #000, 0 0 30px rgba(255,0,0,.6); pointer-events: none; animation: pop .35s ease-out; }
#banner.good { color: #7bffb5; text-shadow: 0 4px 0 #000, 0 0 30px rgba(0,255,150,.6); }
#banner.boss { color: #d070ff; }
@keyframes pop { from { transform: scale(1.6); opacity: 0; } to { transform: scale(1); opacity: 1; } }
#pa { position: fixed; left: 50%; top: 80px; transform: translateX(-50%); background: rgba(8,24,60,.9); border: 2px solid #4da3ff;
  border-radius: 10px; padding: 8px 20px; text-align: center; max-width: 720px; pointer-events: none; }
.pa-head { font-size: 11px; color: #9fd0ff; letter-spacing: .08em; }
#pa-jp { font-size: 20px; font-weight: 700; margin-top: 2px; }
#pa-en { font-size: 16px; color: #ffd75e; }
#toast { position: fixed; left: 50%; bottom: 36%; transform: translateX(-50%); background: rgba(0,0,0,.8); padding: 6px 16px; border-radius: 6px;
  font-weight: 700; pointer-events: none; }

/* Screens */
.screen { position: fixed; inset: 0; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 14px; }
.screen.dim { background: rgba(5,8,16,.78); }
#screen-menu { background: linear-gradient(90deg, rgba(5,8,16,.88) 0%, rgba(5,8,16,.55) 45%, rgba(5,8,16,0) 75%); align-items: flex-start; padding-left: 7vw; }
.title-block h1 { font-size: 64px; line-height: .95; margin: 4px 0 8px; font-weight: 900; letter-spacing: .02em; text-shadow: 0 4px 0 #000; }
.title-block h1 span { color: #ffd75e; }
.jp-title { font-size: 22px; color: #9fd0ff; font-weight: 700; letter-spacing: .3em; }
.tag { color: #cfd8e0; margin: 0; }
.menu-buttons { display: flex; flex-direction: column; gap: 8px; min-width: 280px; }
.menu-buttons.row { flex-direction: row; justify-content: center; }
.btn { pointer-events: auto; font: inherit; font-size: 18px; font-weight: 700; padding: 10px 22px; border-radius: 8px; cursor: pointer;
  background: rgba(20,28,44,.9); color: #fff; border: 2px solid rgba(255,255,255,.2); text-align: left; transition: transform .08s; }
.btn small { color: #ffd75e; font-weight: 600; margin-left: 6px; }
.btn:hover, .btn.focus { border-color: #ffd75e; background: rgba(60,50,10,.9); transform: translateX(4px); }
.btn.small { font-size: 14px; padding: 6px 14px; }
.btn:disabled { opacity: .4; cursor: default; }
.foot { color: #9fb3c8; font-size: 13px; }
h2 { font-size: 44px; margin: 0; font-weight: 900; text-shadow: 0 3px 0 #000; }
h2 small { font-size: 16px; color: #9fd0ff; }
#choice-sub { margin: 0; color: #cfd8e0; }
#choice-cards { display: flex; gap: 16px; }
.card { pointer-events: auto; width: 220px; min-height: 230px; background: linear-gradient(#1c2840, #121a2a); border: 2px solid rgba(255,255,255,.2); border-radius: 12px;
  padding: 16px; cursor: pointer; text-align: center; transition: transform .1s; font: inherit; color: #fff; }
.card:hover, .card.focus { border-color: #ffd75e; transform: translateY(-6px); }
.card .ic { font-size: 48px; }
.card .nm { font-weight: 800; font-size: 18px; margin: 6px 0 2px; }
.card .lv { color: #ffd75e; font-size: 13px; font-weight: 700; }
.card .ds { color: #cfd8e0; font-size: 13px; margin-top: 8px; }
.card.evo { border-color: #ffd75e; background: linear-gradient(#4a3a10, #1c1608); }
.card.item { border-color: #4da3ff; }
#end-stats { display: grid; grid-template-columns: auto auto; gap: 4px 30px; font-size: 18px; background: rgba(0,0,0,.4); padding: 14px 26px; border-radius: 10px; }
#end-stats b { color: #ffd75e; text-align: right; }
#end-title.lose { color: #ff4d4d; }
#end-title.win { color: #7bffb5; }
.howto { max-width: 720px; background: rgba(0,0,0,.4); padding: 16px 26px; border-radius: 10px; line-height: 1.45; font-size: 15px; max-height: 64vh; overflow: auto; }
.howto table { border-collapse: collapse; width: 100%; margin-top: 8px; }
.howto td, .howto th { padding: 3px 8px; border-bottom: 1px solid rgba(255,255,255,.1); text-align: left; }
.red { color: #ff4d4d; }

/* Konbini store */
.konbini { background: linear-gradient(#f4f7f9 0 60%, #dfe5ea); color: #1a1a1a; }
.konbini-sign { background: #fff; border-radius: 10px; padding: 10px 26px; font-size: 32px; box-shadow: 0 4px 0 #bbb; display: flex; align-items: center; gap: 10px; position: relative; overflow: hidden; }
.konbini-sign b { color: #1a8f3c; font-weight: 900; letter-spacing: .05em; z-index: 1; }
.konbini-sign small { font-size: 14px; color: #555; z-index: 1; }
.stripe { position: absolute; left: 0; right: 0; height: 6px; }
.stripe.s1 { top: 0; background: #1a8f3c; } .stripe.s2 { top: 6px; background: #f39c12; } .stripe.s3 { bottom: 0; background: #2d6cdf; }
.store-yen { font-size: 20px; }
.store-yen b { color: #c0392b; }
#store-grid { display: grid; grid-template-columns: repeat(4, 210px); gap: 10px; }
.shelf { pointer-events: auto; background: #fff; border-radius: 10px; padding: 10px; border: 2px solid #ccd; text-align: left; cursor: pointer; font: inherit; color: #1a1a1a; }
.shelf:hover, .shelf.focus { border-color: #1a8f3c; }
.shelf .top { display: flex; justify-content: space-between; align-items: center; }
.shelf .ic { font-size: 26px; }
.shelf .nm { font-weight: 800; }
.shelf .ds { font-size: 12px; color: #555; }
.shelf .pips { color: #1a8f3c; font-size: 11px; letter-spacing: 1px; }
.shelf .price { display: inline-block; margin-top: 4px; background: #ffd75e; padding: 1px 8px; border-radius: 4px; font-weight: 800; }
.shelf.cant .price { background: #ddd; color: #888; }
.shelf.max .price { background: #1a8f3c; color: #fff; }
.konbini .btn { background: #1a8f3c; border-color: #136b2c; }

/* Map */
.map-layout { display: flex; gap: 16px; align-items: flex-start; }
#bigmap { width: min(70vw, 1000px); aspect-ratio: 10/7; height: auto; background: rgba(10,14,22,.9); border-radius: 12px; border: 2px solid rgba(255,255,255,.3); }
#map-side { width: 280px; background: rgba(0,0,0,.4); border-radius: 10px; padding: 10px 14px; font-size: 13px; }
#map-side h3 { margin: 0 0 6px; font-size: 14px; color: #9fd0ff; }
#clue-list { padding-left: 16px; margin: 0 0 10px; max-height: 50vh; overflow: auto; }
#clue-list li { margin-bottom: 4px; }
.legend { display: flex; gap: 6px; align-items: center; flex-wrap: wrap; }
.lg { width: 12px; height: 12px; border-radius: 3px; display: inline-block; }
.lg.y { background: #ffd75e; } .lg.r { background: #ff4040; } .lg.g { background: #5a6070; }
.hint { color: #9fb3c8; margin: 0; }
#loading { background: #0b0f18; }

/* stairs, floors, fade */
#fade { position: fixed; inset: 0; background: #000; opacity: 0; pointer-events: none; }
#fade.go { animation: fadeblink .6s ease-out; }
@keyframes fadeblink { 0% { opacity: 1; } 100% { opacity: 0; } }
#prompt.stairs { border-color: #3ec7ff; }
#prompt small { color: #9fb3c8; }
#map-floors { display: flex; gap: 6px; }
.btn-tab { pointer-events: auto; cursor: pointer; font: inherit; font-size: 15px; color: #fff; padding: 4px 12px; display: flex; gap: 6px; align-items: baseline; }
.btn-tab small { font-size: 11px; color: #ffd75e; }
.btn-tab.on small { color: #111; }
.btn-tab.here { box-shadow: 0 0 0 2px #3ec7ff; }

/* character select */
#chars-grid { display: grid; grid-template-columns: repeat(5, 210px); grid-auto-rows: minmax(150px, auto); gap: 8px; max-height: 66vh; overflow-y: auto; padding: 4px; }
.char { pointer-events: auto; font: inherit; color: #fff; text-align: left; cursor: pointer; display: flex; gap: 8px; padding: 6px; border-radius: 10px;
  background: linear-gradient(#1c2840, #121a2a); border: 2px solid rgba(255,255,255,.15); height: 100%; align-items: flex-start; }
.char img { width: 72px; height: 90px; border-radius: 6px; flex: none; }
.char .nm { font-weight: 800; font-size: 13px; line-height: 1.15; }
.char .jp { font-size: 11px; color: #9fd0ff; }
.char .ds { font-size: 10.5px; color: #cfd8e0; margin-top: 3px; line-height: 1.25; }
.char .perk { font-size: 11px; color: #ffd75e; margin-top: 3px; }
.char.sel { border-color: #ffd75e; box-shadow: 0 0 12px rgba(255,215,94,.5); }
.char:hover, .char.focus { border-color: #ffd75e; }
.char.locked { cursor: default; opacity: .85; }
.char.locked img { filter: brightness(0) opacity(.55); }
.char.locked .nm { color: #9fb3c8; }
.char.locked .ds { color: #ffb0d8; }

/* ---------- phones and tablets ---------- */
html, body { overscroll-behavior: none; -webkit-touch-callout: none; -webkit-user-select: none; -webkit-tap-highlight-color: transparent; }
canvas#game { touch-action: none; }
#touch { position: fixed; inset: 0; display: none; touch-action: none; }
body.touch.playing #touch { display: block; }
body.touch #crosshair { display: none; }
#t-left { position: absolute; left: 0; top: 0; bottom: 0; width: 45%; }
#t-right { position: absolute; right: 0; top: 0; bottom: 0; width: 55%; }
#t-stick { position: absolute; width: 112px; height: 112px; margin: -56px 0 0 -56px; border-radius: 50%; border: 3px solid rgba(255,255,255,.35);
  background: rgba(10,14,22,.25); display: none; pointer-events: none; }
#t-stick.on { display: block; }
#t-knob { position: absolute; left: 50%; top: 50%; width: 52px; height: 52px; border-radius: 50%; background: rgba(255,215,94,.85); transform: translate(-50%,-50%); }
.tbtn { position: absolute; border-radius: 50%; border: 3px solid rgba(255,255,255,.45); background: rgba(10,14,22,.55); color: #fff; font: inherit;
  font-weight: 800; font-size: 12px; letter-spacing: .04em; touch-action: none; user-select: none; }
.tbtn.down { background: rgba(255,215,94,.8); color: #111; }
#t-dodge { width: 84px; height: 84px; right: calc(24px + env(safe-area-inset-right)); bottom: calc(110px + env(safe-area-inset-bottom)); }
#t-jump { width: 62px; height: 62px; right: calc(118px + env(safe-area-inset-right)); bottom: calc(150px + env(safe-area-inset-bottom)); }
#t-lock { width: 52px; height: 52px; right: calc(34px + env(safe-area-inset-right)); bottom: calc(206px + env(safe-area-inset-bottom)); font-size: 10px; }
#t-map, #t-pause { width: 46px; height: 46px; top: calc(54px + env(safe-area-inset-top)); border-radius: 12px; font-size: 11px; }
#t-map { right: calc(70px + env(safe-area-inset-right)); }
#t-pause { right: calc(16px + env(safe-area-inset-right)); }
body.touch #prompt { pointer-events: auto; cursor: pointer; font-size: 17px; padding: 12px 20px; bottom: 34%; }
#rotate { display: none; position: fixed; inset: 0; z-index: 50; background: rgba(5,8,16,.92); flex-direction: column; align-items: center; justify-content: center; gap: 12px; text-align: center; padding: 24px; }
#rotate .rot-ic { font-size: 54px; }
@media (orientation: portrait) { body.touch.playing:not(.portrait-ok) #rotate { display: flex; } }

/* small screens: phones in landscape (short) or portrait (narrow) */
@media (max-height: 560px), (max-width: 760px) {
  #topbar { top: calc(4px + env(safe-area-inset-top)); gap: 4px; }
  .stat { font-size: 13px; padding: 2px 7px; }
  .stat .k { font-size: 9px; }
  #h-level { font-size: 14px; top: 8px; left: calc(8px + env(safe-area-inset-left)); }
  #bars { width: 170px; left: calc(10px + env(safe-area-inset-left)); bottom: calc(8px + env(safe-area-inset-bottom)); }
  .bar { height: 14px; margin-top: 4px; } .bar span { font-size: 10px; line-height: 14px; }
  #slots { left: calc(10px + env(safe-area-inset-left)); bottom: calc(40px + env(safe-area-inset-bottom)); }
  .slot { width: 26px; height: 26px; font-size: 14px; } .slot b { font-size: 8px; }
  #minimap-wrap { right: calc(8px + env(safe-area-inset-right)); bottom: auto; top: calc(108px + env(safe-area-inset-top)); }
  #minimap { width: 110px; height: 110px; }
  .ftab { font-size: 9px; padding: 0 4px; }
  #floortabs { flex-wrap: wrap; max-width: 110px; }
  #bossbar { width: 60vw; top: 38px; }
  #banner { font-size: 40px; top: 24%; }
  #pa { top: 40px; padding: 4px 12px; max-width: 86vw; } #pa-jp { font-size: 14px; } #pa-en { font-size: 12px; }
  #toast { font-size: 13px; bottom: 44%; max-width: 80vw; text-align: center; }
  #prompt { font-size: 14px; }
  .screen { gap: 8px; padding: 10px calc(10px + env(safe-area-inset-right)) 10px calc(10px + env(safe-area-inset-left)); overflow-y: auto; justify-content: flex-start; }
  .screen > * { flex-shrink: 0; }
  #screen-menu { padding-left: calc(5vw + env(safe-area-inset-left)); justify-content: center; }
  .title-block h1 { font-size: 34px; } .jp-title { font-size: 14px; } .tag { font-size: 12px; }
  .menu-buttons { min-width: 220px; gap: 6px; }
  .btn { font-size: 15px; padding: 8px 16px; }
  h2 { font-size: 26px; }
  #choice-cards { flex-wrap: wrap; justify-content: center; gap: 8px; }
  .card { width: 30vw; max-width: 200px; min-height: 0; padding: 8px; }
  .card .ic { font-size: 30px; } .card .nm { font-size: 14px; } .card .ds { font-size: 11px; }
  #store-grid { grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); width: 94vw; gap: 6px; }
  .shelf { padding: 6px; } .shelf .ic { font-size: 20px; }
  .konbini-sign { font-size: 20px; padding: 6px 14px; }
  #chars-grid { grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); width: 94vw; max-height: none; }
  .howto { font-size: 13px; max-height: none; padding: 10px 14px; }
  #end-stats { font-size: 14px; padding: 8px 14px; }
  .map-layout { flex-direction: column; align-items: center; gap: 8px; }
  #bigmap { width: 92vw; }
  #map-side { width: 92vw; }
  #map-floors { flex-wrap: wrap; justify-content: center; }
  .btn-tab { font-size: 12px; padding: 3px 8px; }
}
@media (max-height: 560px) and (orientation: landscape) {
  .map-layout { flex-direction: row; align-items: flex-start; }
  #bigmap { width: auto; height: 62vh; }
  #map-side { width: 30vw; max-height: 62vh; overflow-y: auto; }
}

body.touch #minimap { pointer-events: auto; }

/* layering: game HUD taps (prompt, minimap) above the touch layer, screens above everything */
#touch { z-index: 4; }
#hud { z-index: 5; }
#pa, #banner, #toast { z-index: 6; }
.screen { z-index: 10; }
#rotate { z-index: 20; }
#fade { z-index: 30; }

/* phone layout while playing with touch: thumbs at the bottom corners, map top-right */
@media (max-height: 560px), (max-width: 760px) {
  body.touch #topbar { left: calc(56px + env(safe-area-inset-left)); transform: none; }
  body.touch #minimap-wrap { top: calc(6px + env(safe-area-inset-top)); right: calc(8px + env(safe-area-inset-right)); bottom: auto; }
  body.touch #minimap { width: 96px; height: 96px; }
  body.touch #floortabs .ftab:not(.on) { display: none; }
  body.touch #t-map { top: calc(22px + env(safe-area-inset-top)); right: calc(112px + env(safe-area-inset-right)); }
  body.touch #t-pause { top: calc(22px + env(safe-area-inset-top)); right: calc(164px + env(safe-area-inset-right)); }
  body.touch #t-dodge { width: 78px; height: 78px; right: calc(16px + env(safe-area-inset-right)); bottom: calc(16px + env(safe-area-inset-bottom)); }
  body.touch #t-jump { width: 58px; height: 58px; right: calc(104px + env(safe-area-inset-right)); bottom: calc(22px + env(safe-area-inset-bottom)); }
  body.touch #t-lock { width: 46px; height: 46px; right: calc(28px + env(safe-area-inset-right)); bottom: calc(104px + env(safe-area-inset-bottom)); }
  body.touch #bossbar { top: 34px; }
}

/* phones: the PA box sits under the stats on the left, clear of the map and pause buttons */
@media (max-height: 560px), (max-width: 760px) {
  body.touch #pa { left: calc(8px + env(safe-area-inset-left)); transform: none; top: calc(38px + env(safe-area-inset-top)); max-width: 52vw; text-align: left; }
  body.touch #pa-jp { font-size: 12px; } body.touch #pa-en { font-size: 11px; } body.touch .pa-head { font-size: 9px; }
}

/* short phone screens: compact title menu and map */
@media (max-height: 560px) {
  #screen-menu { justify-content: center; gap: 6px; }
  .title-block h1 { font-size: 28px; margin: 2px 0 4px; }
  .jp-title { font-size: 12px; letter-spacing: .2em; }
  #screen-menu .menu-buttons { display: grid; grid-template-columns: 1fr 1fr; min-width: 0; width: min(440px, 60vw); }
  #screen-menu .menu-buttons .btn:first-child { grid-column: 1 / -1; background: rgba(60,50,10,.9); border-color: #ffd75e; }
  #screen-menu .btn { font-size: 13px; padding: 7px 12px; }
  .foot { font-size: 11px; }
  #screen-map h2 { font-size: 20px; }
  #screen-map .hint { display: none; }
  #screen-map .menu-buttons { position: fixed; top: calc(8px + env(safe-area-inset-top)); right: calc(10px + env(safe-area-inset-right)); }
}
