* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; background: #14141f; color: #1b1b28; font-family: "Segoe UI", system-ui, -apple-system, sans-serif; overflow: hidden; }
html, body { touch-action: manipulation; -webkit-user-select: none; user-select: none; -webkit-tap-highlight-color: transparent; overscroll-behavior: none; }
#stage { position: absolute; left: 0; top: 0; width: 960px; height: 720px; transform-origin: 0 0; background: #0b0b12; border-radius: 10px; overflow: hidden; box-shadow: 0 0 0 4px #2d2d44, 0 12px 40px rgba(0, 0, 0, .6); }
#screen { position: absolute; left: 0; top: 0; width: 960px; height: 720px; display: block; image-rendering: pixelated; image-rendering: crisp-edges; cursor: pointer; touch-action: none; }
.hidden { display: none !important; }
button { font: inherit; cursor: pointer; }
kbd { font: 12px ui-monospace, Consolas, monospace; background: rgba(0, 0, 0, .18); border-radius: 4px; padding: 1px 6px; margin-left: 6px; }
.cite { font: 13px ui-monospace, Consolas, monospace; color: #4a5578; margin: 6px 0 0; }
.note { color: #5c6378; font-size: 14px; line-height: 1.45; }

/* HUD */
#hud { position: absolute; top: 0; left: 0; right: 0; display: flex; justify-content: space-between; align-items: center; padding: 8px 14px; background: linear-gradient(rgba(20, 20, 31, .88), rgba(20, 20, 31, .6)); color: #fff; font-size: 15px; }
#hud:empty { display: none; }
.hud-l b { font-size: 18px; margin-right: 10px; color: #ffe08a; }
.hud-l span { opacity: .85; }
.hud-l { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; margin-right: 12px; }
.hud-r { display: flex; gap: 12px; align-items: center; flex: none; white-space: nowrap; }
.hud-r button, #homeBtn { background: #ffe08a; color: #1b1b28; border: 0; border-radius: 6px; padding: 4px 12px; font-weight: 600; }
#homeBtn { display: inline-flex; align-items: center; gap: 5px; text-decoration: none; background: none; color: #ffe08a; border: 2px solid #ffe08a; padding: 2px 10px; }
#homeBtn:hover { background: rgba(255, 224, 138, .2); }
.h-short { display: none; }
.bar { display: inline-block; width: 110px; height: 10px; background: #3a3a52; border-radius: 6px; overflow: hidden; }
.bar i { display: block; height: 100%; background: #5fd068; transition: width .3s; }
.bar i.mid { background: #f2c14e; }
.bar i.low { background: #e5534b; }

#toast { position: absolute; top: 58px; left: 50%; transform: translateX(-50%); background: rgba(20, 20, 31, .9); color: #ffe08a; padding: 8px 20px; border-radius: 20px; font-size: 17px; font-weight: 600; opacity: 0; transition: opacity .4s; pointer-events: none; white-space: nowrap; }
#toast.show { opacity: 1; }
#fade { position: absolute; inset: 0; background: #000; opacity: 0; transition: opacity .25s; pointer-events: none; }
#fade.flash { animation: flash .5s steps(1) 1; }
@keyframes flash { 0% { opacity: 1; background: #fff; } 25% { opacity: 0; } 50% { opacity: 1; background: #fff; } 75% { opacity: 0; } 100% { opacity: 1; background: #000; } }

/* Dialog */
#dialog { position: absolute; left: 24px; right: 24px; bottom: 20px; min-height: 170px; background: #fdf8ea; border: 4px solid #2d2d44; border-radius: 12px; padding: 16px 22px 30px; box-shadow: 0 6px 0 rgba(0, 0, 0, .35); cursor: pointer; }
.d-head { display: flex; gap: 10px; align-items: center; margin-bottom: 8px; flex-wrap: wrap; }
.d-head:empty { display: none; }
.d-name { font-weight: 700; font-size: 17px; background: #2d2d44; color: #ffe08a; padding: 2px 12px; border-radius: 6px; }
.d-tag { font: 700 12px ui-monospace, Consolas, monospace; letter-spacing: 1px; padding: 3px 8px; border-radius: 4px; color: #fff; background: #3d7fc8; }
.d-tag.history { background: #a0692b; }
.d-tag.case { background: #a33b4a; }
.d-title { font-weight: 600; color: #4a5578; }
.d-text { font-size: 21px; line-height: 1.42; }
.d-more { position: absolute; right: 16px; bottom: 8px; font-size: 13px; color: #7a8099; animation: bob 1s infinite; }
@keyframes bob { 50% { transform: translateY(3px); } }
.d-opts { display: flex; gap: 12px; margin-top: 14px; }
.d-opts button { padding: 8px 20px; border: 3px solid #2d2d44; border-radius: 8px; background: #fff; font-size: 18px; }
.d-opts button.sel, .d-opts button:hover { background: #ffe08a; }

/* Battle */
#battle { position: absolute; inset: 0; background: #fdf8ea; display: flex; flex-direction: column; }
.b-scene { position: relative; height: 196px; flex: none; background: linear-gradient(#bfe6ff 0 52%, #9fd67a 52% 100%); border-bottom: 4px solid #2d2d44; overflow: hidden; }
#battle.boss .b-scene { background: linear-gradient(#d9d0f0 0 52%, #c9b37e 52% 100%); }
.b-enemy, .b-player { position: absolute; width: 144px; height: 144px; image-rendering: pixelated; image-rendering: crisp-edges; }
.b-enemy { right: 50px; top: 6px; width: 120px; height: 120px; }
.b-player { left: 60px; bottom: -30px; width: 150px; height: 150px; }
.b-enemy.hit, .b-player.hit { animation: hit .4s; }
@keyframes hit { 0%, 100% { transform: translateX(0); opacity: 1; } 20% { transform: translateX(-10px); opacity: .3; } 40% { transform: translateX(10px); opacity: 1; } 60% { transform: translateX(-6px); opacity: .3; } 80% { transform: translateX(6px); } }
.b-info { position: absolute; background: #fdf8ea; border: 3px solid #2d2d44; border-radius: 10px; padding: 8px 14px; width: 290px; font-size: 17px; }
.b-info > div:first-child { display: flex; justify-content: space-between; gap: 10px; margin-bottom: 6px; }
.b-info .bar { width: 100%; height: 12px; display: block; }
.b-einfo { left: 240px; top: 14px; }
.b-pinfo { right: 200px; bottom: 10px; }
.hpnum { text-align: right; font-size: 14px; margin-top: 3px; color: #4a5578; }
.b-panel { flex: 1; overflow-y: auto; padding: 14px 28px 16px; }
.b-msg { font-size: 21px; line-height: 1.45; margin-top: 12px; }
.b-stem { font-size: 19px; line-height: 1.42; margin-bottom: 12px; }
.b-opts { display: flex; flex-direction: column; gap: 8px; }
.b-opts button { display: flex; gap: 12px; align-items: baseline; text-align: left; padding: 9px 14px; font-size: 17px; line-height: 1.3; background: #fff; border: 3px solid #2d2d44; border-radius: 9px; color: #1b1b28; }
.b-opts button b { flex: none; width: 26px; height: 26px; line-height: 26px; text-align: center; border-radius: 50%; background: #2d2d44; color: #ffe08a; font-size: 14px; }
.b-opts button:hover:not(:disabled) { background: #fff3c9; }
.b-opts button:disabled { cursor: default; opacity: .6; }
.b-opts button.right { background: #d3f5d6; border-color: #2c8a3c; opacity: 1; }
.b-opts button.wrong { background: #fbd5d2; border-color: #b93a32; opacity: 1; }
.b-run { margin-top: 10px; display: flex; justify-content: space-between; align-items: center; gap: 10px; }
.b-run span { font-size: 13px; color: #7a8099; }
.b-run button { background: none; border: 2px solid #9aa0b5; border-radius: 7px; padding: 4px 14px; color: #4a5578; font-size: 14px; }
.b-fb { margin-top: 12px; padding: 10px 14px; border-radius: 9px; font-size: 16px; line-height: 1.42; border-left: 6px solid #2c8a3c; background: #eaf8ec; }
.b-fb.bad { border-left-color: #b93a32; background: #fdecea; }
.b-fb p { margin: 6px 0 0; }
.b-card { margin-top: 8px; display: inline-block; background: #ffe08a; border: 2px solid #2d2d44; border-radius: 7px; padding: 3px 12px; font-weight: 700; }
.b-foot { margin-top: 12px; text-align: right; }
.b-foot button, button.big { background: #2d2d44; color: #ffe08a; border: 0; border-radius: 9px; padding: 9px 22px; font-size: 17px; font-weight: 600; }

/* Overlay: title + menu */
#overlay { position: absolute; inset: 0; background: rgba(20, 20, 31, .82); display: flex; overflow-y: auto; }
#overlay > * { margin: auto; }
.title { text-align: center; color: #fff; max-width: 760px; padding: 20px; }
.title h1 { font-size: 78px; margin: 0; color: #ffe08a; letter-spacing: 2px; text-shadow: 5px 5px 0 #a33b4a; }
.title .sub { font-size: 21px; margin: 8px 0 26px; }
#titleArt { width: 630px; max-width: 100%; height: auto; image-rendering: pixelated; image-rendering: crisp-edges; }
.tbtns { display: flex; gap: 16px; justify-content: center; flex-wrap: wrap; margin: 26px 0 18px; }
.tbtns button { background: #ffe08a; border: 0; border-radius: 10px; padding: 12px 32px; font-size: 21px; font-weight: 700; color: #1b1b28; }
.tbtns button:hover { background: #fff; }
.title .keys { font-size: 15px; opacity: .9; line-height: 1.6; }
.title .keys small { opacity: .75; }
.title .fine { font-size: 13px; line-height: 1.5; opacity: .7; margin-top: 18px; }

.menu { width: 900px; height: 660px; max-width: 100%; max-height: 100%; flex: none; background: #fdf8ea; border: 4px solid #2d2d44; border-radius: 12px; display: flex; flex-direction: column; overflow: hidden; }
.tabs { display: flex; background: #2d2d44; padding: 8px 8px 0; gap: 4px; flex: none; }
.tabs button { border: 0; background: #4a4a68; color: #fff; padding: 8px 18px; border-radius: 8px 8px 0 0; font-size: 16px; }
.tabs button.on { background: #fdf8ea; color: #1b1b28; font-weight: 700; }
.tabs .x { margin-left: auto; background: none; color: #ffe08a; }
.pane { flex: 1; overflow-y: auto; padding: 18px 22px; font-size: 16px; }
.pane h2 { margin: 0 0 10px; }
.stat-top { display: flex; gap: 26px; font-size: 17px; margin-bottom: 14px; }
table.stat { width: 100%; border-collapse: collapse; font-size: 15px; }
table.stat th, table.stat td { text-align: left; padding: 7px 8px; border-bottom: 1px solid #ddd3b8; }
table.stat th { font-size: 13px; text-transform: uppercase; letter-spacing: .5px; color: #5c6378; }
table.stat tr.here td { background: #fff3c9; }
.townpick { display: grid; grid-template-columns: repeat(4, 1fr); gap: 6px; }
.townpick button { border: 2px solid #2d2d44; background: #fff; border-radius: 8px; padding: 6px 8px; font-size: 14px; text-align: left; display: flex; justify-content: space-between; gap: 6px; }
.townpick button.on { background: #ffe08a; font-weight: 700; }
.townpick small { color: #5c6378; }
.cardbar { display: flex; gap: 10px; align-items: center; margin: 12px 0; font-size: 13px; color: #5c6378; }
.cardbar button { background: #2d2d44; color: #ffe08a; border: 0; border-radius: 7px; padding: 6px 14px; font-size: 14px; flex: none; }
.cardgrid { display: grid; grid-template-columns: repeat(6, 1fr); gap: 8px; }
.card { min-height: 78px; border: 2px dashed #b9ae90; border-radius: 8px; display: flex; align-items: center; justify-content: center; color: #b9ae90; font-size: 14px; padding: 6px; text-align: center; background: none; }
.card.own { border: 2px solid #2d2d44; background: linear-gradient(#fff, #fff3c9); color: #1b1b28; flex-direction: column; gap: 3px; font-weight: 600; line-height: 1.2; box-shadow: 2px 3px 0 rgba(45, 45, 68, .35); }
.card.own small { font: 11px ui-monospace, Consolas, monospace; color: #a33b4a; }
.card.own.on, .card.own:hover { background: #ffe08a; }
.flash { margin-top: 14px; border: 3px solid #2d2d44; border-radius: 10px; background: #fff; padding: 14px 18px; }
.flash.big { min-height: 300px; padding: 26px 30px; }
.f-front { font-size: 19px; font-weight: 700; margin-bottom: 10px; }
.flash.big .f-front { font-size: 26px; margin-bottom: 20px; }
.f-back { font-size: 17px; line-height: 1.45; }
.flash.big .f-back { font-size: 21px; }
.f-hide { color: #9aa0b5; font-style: italic; font-size: 18px; }
.r-head { font-size: 14px; color: #5c6378; margin-bottom: 8px; }
.r-btns { display: flex; justify-content: space-between; margin-top: 16px; }
.r-btns button:not(.big) { background: none; border: 2px solid #9aa0b5; border-radius: 8px; padding: 6px 16px; color: #4a5578; }
.trow { display: flex; justify-content: space-between; align-items: center; padding: 9px 12px; border-bottom: 1px solid #ddd3b8; }
.trow.here { background: #fff3c9; }
.trow small, .trow span { color: #5c6378; }
.trow button { background: #2d2d44; color: #ffe08a; border: 0; border-radius: 7px; padding: 6px 18px; }
.exam-intro p { font-size: 17px; line-height: 1.5; max-width: 720px; }
.miss { border-left: 6px solid #b93a32; background: #fff; border-radius: 8px; padding: 10px 14px; margin: 10px 0; font-size: 15px; line-height: 1.4; }
.miss p { margin: 6px 0 0; }
.m-stem { font-weight: 600; margin-bottom: 6px; }
.m-you { color: #b93a32; }
.m-ans { color: #2c8a3c; font-weight: 600; }
.opts { display: flex; flex-direction: column; gap: 12px; align-items: flex-start; }
.opts button { background: #2d2d44; color: #ffe08a; border: 0; border-radius: 8px; padding: 9px 20px; }

/* ---------- Controls: device-specific hints, on-screen pad, controller cursor ---------- */
.m-kb, .m-touch, .m-pad { display: none; }
#stage.in-kb .m-kb, #stage.in-touch .m-touch, #stage.in-pad .m-pad { display: inline; }
#stage.in-pad .nav { outline: 4px solid #ff7a3d; outline-offset: 2px; box-shadow: 0 0 0 7px rgba(255, 122, 61, .35); }
#stage.in-pad .d-opts button.sel:not(.nav) { background: #fff; }

#hint { position: absolute; left: 50%; bottom: 10px; transform: translateX(-50%); display: none; background: rgba(20, 20, 31, .78); color: #fff; font-size: 14px; padding: 6px 18px; border-radius: 18px; white-space: nowrap; pointer-events: none; }
#stage.world:not(.in-touch) #hint { display: block; }
#hint kbd { background: rgba(255, 255, 255, .22); margin: 0 1px 0 4px; }

#pad { position: absolute; inset: 0; display: none; pointer-events: none; }
#stage.world.in-touch #pad { display: block; }
#dpad, #btnA, #btnMenu { position: absolute; pointer-events: auto; touch-action: none; color: #fff; background: rgba(20, 20, 31, .5); border: 3px solid rgba(255, 255, 255, .6); }
#dpad { left: 22px; bottom: 30px; width: 176px; height: 176px; border-radius: 50%; }
#dpad i { position: absolute; width: 58px; height: 58px; display: flex; align-items: center; justify-content: center; font-style: normal; font-size: 26px; border-radius: 14px; pointer-events: none; }
#dpad .up { left: 56px; top: 3px; } #dpad .down { left: 56px; bottom: 3px; } #dpad .left { left: 3px; top: 56px; } #dpad .right { right: 3px; top: 56px; }
#dpad span { position: absolute; left: 0; right: 0; top: 76px; text-align: center; font-size: 12px; letter-spacing: 1px; text-transform: uppercase; opacity: .8; pointer-events: none; }
#dpad[data-dir="up"] .up, #dpad[data-dir="down"] .down, #dpad[data-dir="left"] .left, #dpad[data-dir="right"] .right { background: #ffe08a; color: #1b1b28; }
#btnA { right: 26px; bottom: 56px; width: 112px; height: 112px; border-radius: 50%; font-size: 38px; font-weight: 700; line-height: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; }
#btnA small { font-size: 12px; font-weight: 600; margin-top: 4px; opacity: .9; }
#btnA:active { background: #ffe08a; color: #1b1b28; }
#btnMenu { right: 154px; bottom: 34px; border-radius: 22px; padding: 9px 20px; font-size: 16px; font-weight: 600; }

/* ---------- Compact layout: phones and small windows (the stage fills the window) ---------- */
#stage.compact { border-radius: 0; box-shadow: none; }
.compact #hud { padding: 6px 10px; font-size: 13px; gap: 8px; }
.compact .hud-l b { font-size: 15px; margin-right: 0; }
.compact .hud-l span { display: none; }
.compact .hud-r { gap: 8px; }
.compact .hud-r .bar { width: 56px; }
.compact .hud-r button { padding: 6px 14px; font-size: 15px; }
.compact .hud-l { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.compact .hud-r { flex: none; }
.compact .h-full { display: none; }
.compact .h-short { display: inline; }
.compact #homeBtn { padding: 5px 9px; }
.compact .tlinks { gap: 8px; }
.compact .tlinks a { font-size: 15px; padding: 9px 14px; }
.compact .title .pitch { font-size: 13px; }
.compact .d-opts a.patreon { font-size: 16px; }
.compact #toast { top: 50px; white-space: normal; width: 92%; text-align: center; font-size: 15px; }
.compact #hint { white-space: normal; width: 94%; text-align: center; line-height: 1.7; }
.compact #dialog { left: 8px; right: 8px; bottom: 10px; padding: 12px 14px 28px; min-height: 150px; }
.compact .d-text { font-size: 18px; }
.compact .d-opts { flex-wrap: wrap; }
.compact .b-scene { height: 196px; }
.compact .b-info { width: 190px; padding: 6px 10px; font-size: 14px; }
.compact .b-einfo { left: 8px; top: 8px; }
.compact .b-pinfo { right: 8px; bottom: 8px; }
.compact .b-enemy { right: 20px; top: 4px; width: 104px; height: 104px; }
.compact .b-player { left: 12px; bottom: -28px; width: 128px; height: 128px; }
.compact .b-panel { padding: 10px 12px 14px; }
.compact .b-msg { font-size: 18px; margin-top: 6px; }
.compact .b-stem { font-size: 17px; }
.compact .b-opts button { font-size: 16px; padding: 10px 10px; gap: 9px; }
.compact .b-run button { padding: 8px 16px; }
.compact .b-foot button, .compact button.big { padding: 11px 24px; }
.land #battle { flex-direction: row; }
.land .b-scene { width: 350px; height: auto; border-bottom: 0; border-right: 4px solid #2d2d44; }
.land .b-info { width: 180px; }
.land .b-player { left: 4px; }
.compact .title { padding: 14px; }
.compact .title h1 { font-size: 50px; text-shadow: 4px 4px 0 #a33b4a; }
.compact .title .sub { font-size: 17px; margin: 6px 0 14px; }
.compact .tbtns { margin: 16px 0 12px; }
.compact .title .keys { font-size: 13px; }
.compact .title .fine { font-size: 12px; margin-top: 10px; }
.land .title h1 { font-size: 40px; }
.land #titleArt { width: 400px; }
.compact .menu { width: 100%; height: 100%; border-width: 0; border-radius: 0; }
.compact .tabs { flex-wrap: wrap; padding: 6px 6px 0; }
.compact .tabs button { padding: 9px 11px; font-size: 14px; }
.compact .pane { padding: 12px; font-size: 15px; }
.compact .stat-top { flex-wrap: wrap; gap: 6px 18px; font-size: 15px; }
.compact table.stat { font-size: 13px; }
.compact table.stat th, .compact table.stat td { padding: 6px 4px; }
.port table.stat.wide th:nth-child(2), .port table.stat.wide td:nth-child(2), .port table.stat.wide th:nth-child(3), .port table.stat.wide td:nth-child(3) { display: none; }
.port .townpick { grid-template-columns: repeat(2, 1fr); }
.port .cardgrid { grid-template-columns: repeat(3, 1fr); }
.compact .cardbar { flex-wrap: wrap; }
.compact .cardbar button { padding: 9px 14px; }
.compact .flash.big { min-height: 220px; padding: 16px; }
.compact .flash.big .f-front { font-size: 21px; margin-bottom: 14px; }
.compact .flash.big .f-back { font-size: 18px; }
.compact .trow button { padding: 9px 18px; }

/* ---------- Support / home links ---------- */
a.patreon { display: inline-block; background: #e8503f; color: #fff; font-weight: 700; text-decoration: none; border-radius: 10px; padding: 10px 22px; white-space: nowrap; }
a.patreon:hover { background: #f26a5a; }
a.homelink { display: inline-block; color: #fff; font-weight: 600; text-decoration: none; border: 2px solid rgba(255, 255, 255, .65); border-radius: 10px; padding: 8px 20px; }
a.homelink:hover { background: rgba(255, 255, 255, .15); }
a.homelink.dark { color: #2d2d44; border-color: #2d2d44; }
a.homelink.dark:hover { background: #fff3c9; }
.tlinks { display: flex; gap: 14px; justify-content: center; flex-wrap: wrap; margin: 0 0 8px; font-size: 17px; }
.title .pitch { font-size: 14px; opacity: .9; margin: 0 0 16px; }
.d-opts { align-items: center; flex-wrap: wrap; }
.d-opts a.patreon { font-size: 18px; padding: 9px 20px; border: 3px solid #2d2d44; border-radius: 8px; }
.supportbox { display: flex; gap: 14px; align-items: center; justify-content: space-between; flex-wrap: wrap; border: 3px solid #e8503f; background: #fff4f1; border-radius: 10px; padding: 12px 16px; margin: 14px 0; font-size: 15px; line-height: 1.45; }
.supportbox span { flex: 1 1 260px; }
