:root {
  --gold: #d8b45a;
  --gold2: #f1d68a;
  --ink: #120a06;
  --paper: #f0e2c0;
  --red: #c8102e;
  --sl: env(safe-area-inset-left, 0px);
  --sr: env(safe-area-inset-right, 0px);
  --brush: "HGGyoshotai", "HG行書体", "HGS行書体", "Klee", "Yu Mincho", "YuMincho", "Hiragino Mincho ProN", "Noto Serif CJK JP", "Noto Serif JP", "Songti TC", "Songti SC", "SimSun", serif;
  --ol: 0 0 3px #000, 2px 2px 0 #0a0503, -1px -1px 0 #0a0503, 1px -1px 0 #0a0503, -1px 1px 0 #0a0503, 0 2px 8px rgba(0,0,0,.8);
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body {
  margin: 0; width: 100%; height: 100%; background: #000; overflow: hidden;
  touch-action: none; user-select: none; -webkit-user-select: none; -webkit-touch-callout: none;
  color: var(--paper);
}
#game { position: fixed; left: 0; top: 0; width: 100vw; height: 100vh; display: block; outline: none; z-index: 0; }
body.fight #game { cursor: crosshair; }
button { font: inherit; color: inherit; }
.ol { text-shadow: var(--ol); }
.hide { display: none !important; }

/* ---------------- HUD ---------------- */
#hud { position: fixed; inset: 0; pointer-events: none; z-index: 10; transition: opacity .35s; }
#hud.off { opacity: 0; visibility: hidden; }
#pBox { position: absolute; left: calc(14px + var(--sl)); top: 12px; width: clamp(170px, 25vw, 330px); }
.bar {
  position: relative; height: clamp(9px, 1.6vh, 13px); background: rgba(8,4,3,.72);
  border: 1px solid rgba(216,180,90,.6); box-shadow: 0 0 0 1px #000, 0 2px 8px rgba(0,0,0,.7); overflow: hidden;
}
.bar .fill, .bar .lag { position: absolute; inset: 0; transform-origin: left center; will-change: transform; }
.bar .lag { background: #ecd9a8; opacity: .9; }
.bar .fill { background: linear-gradient(#ef6a6a, #b01a26 45%, #6e0a14); }
.bar.flash .fill { filter: brightness(2.2); }
.pbar {
  position: relative; height: clamp(6px, 1.1vh, 9px); margin-top: 5px; background: rgba(8,4,3,.6);
  border: 1px solid rgba(216,180,90,.45); overflow: visible; transition: opacity .3s;
}
.pbar .fill { position: absolute; inset: 0; transform-origin: center; transform: scaleX(0); background: linear-gradient(90deg, #f08a24, #ffe08a, #f08a24); will-change: transform; }
.pbar.hot .fill { background: linear-gradient(90deg, #ff2a10, #ffa040, #ff2a10); box-shadow: 0 0 10px #ff4020, 0 0 3px #ffb070; }
.pbar.idle { opacity: .35; }
.pbar::after { content: ""; position: absolute; left: 50%; top: -3px; bottom: -3px; width: 2px; margin-left: -1px; background: rgba(240,226,192,.55); }
#pItems { display: flex; gap: 8px; margin-top: 8px; align-items: center; }
.cnt { display: flex; align-items: center; gap: 2px; height: 44px; font-weight: 900; font-size: 18px; text-shadow: var(--ol); }
.cnt svg { width: 26px; height: 26px; filter: drop-shadow(0 1px 2px #000); }
.hbtn {
  pointer-events: auto; position: relative; width: 46px; height: 46px; border-radius: 50%; padding: 0; cursor: pointer;
  border: 2px solid rgba(216,180,90,.75); background: radial-gradient(circle at 40% 35%, rgba(70,46,26,.92), rgba(10,6,4,.92));
  box-shadow: 0 2px 8px rgba(0,0,0,.7), inset 0 0 8px rgba(0,0,0,.8); display: flex; align-items: center; justify-content: center;
  transition: transform .12s;
}
.hbtn:active { transform: scale(.9); }
.hbtn img { width: 78%; height: 78%; object-fit: contain; pointer-events: none; }
.hbtn .k { font-family: var(--brush); font-size: 24px; font-weight: 900; color: var(--gold2); text-shadow: var(--ol); pointer-events: none; }
.hbtn .key, .hbtn .cost {
  position: absolute; bottom: -6px; font-size: 11px; font-style: normal; line-height: 15px; padding: 0 4px; border-radius: 4px;
  background: #120a06; border: 1px solid var(--gold); color: var(--paper); pointer-events: none; white-space: nowrap;
}
.hbtn .key { right: -8px; }
.hbtn .cost { left: -6px; color: #ffe6e6; border-color: #a04040; }
.hbtn .cost:empty { display: none; }
body.touch .hbtn .key { display: none; }
.hbtn.pulse { animation: hpulse .35s ease-out; }
@keyframes hpulse { 0% { transform: scale(1.25); box-shadow: 0 0 18px var(--gold); } 100% { transform: scale(1); } }

#bBox { position: absolute; left: 50%; top: 8px; width: clamp(250px, 40vw, 560px); transform: translateX(-50%); text-align: center; transition: opacity .3s; }
#bBox.off { opacity: 0; }
#bStage { font-size: 12px; color: var(--gold); letter-spacing: .25em; text-shadow: var(--ol); line-height: 14px; }
#bName { font-size: clamp(16px, 2.6vh, 22px); font-weight: 900; letter-spacing: .12em; text-shadow: var(--ol); line-height: 1.2; }
#bBeads { display: flex; gap: 7px; justify-content: center; margin: 3px 0 4px; height: 12px; }
.bead {
  width: 12px; height: 12px; border-radius: 50%; border: 1px solid #000;
  background: radial-gradient(circle at 35% 35%, #ffa0a0, #c0101e 55%, #400008); box-shadow: 0 0 7px rgba(255,40,40,.75);
  transition: all .4s;
}
.bead.gone { background: rgba(50,24,22,.75); box-shadow: none; transform: scale(.8); }
.bead.pop { animation: beadpop .6s ease-out; }
@keyframes beadpop { 0% { transform: scale(2.2); box-shadow: 0 0 30px #ff2020; } 100% { transform: scale(.8); } }
#bBox .pbar { margin: 6px auto 0; width: 70%; }

#goldBox {
  position: absolute; top: 14px; right: calc(66px + var(--sr)); display: flex; align-items: center; gap: 4px;
  font-weight: 900; font-size: 17px; text-shadow: var(--ol); padding: 2px 10px 2px 4px; border-radius: 16px;
  background: rgba(10,6,4,.55); border: 1px solid rgba(216,180,90,.5);
}
#goldBox img { width: 26px; height: 26px; object-fit: contain; }
#goldBox .gain { position: absolute; right: 6px; top: 30px; color: var(--gold2); font-size: 15px; animation: gup 1.2s ease-out forwards; }
@keyframes gup { 0% { opacity: 0; transform: translateY(6px); } 20% { opacity: 1; } 100% { opacity: 0; transform: translateY(-10px); } }

.tcol { position: absolute; display: none; flex-direction: column; gap: 8px; }
body.touch.fight .tcol { display: flex; }
#tR { right: calc(12px + var(--sr)); top: 64px; }
#tL { left: calc(12px + var(--sl)); top: 118px; }
.tbtn {
  pointer-events: auto; width: 46px; height: 46px; border-radius: 50%; padding: 0; position: relative;
  border: 2px solid rgba(216,180,90,.85); background: rgba(12,8,6,.62); color: var(--gold);
  display: flex; align-items: center; justify-content: center; box-shadow: 0 2px 8px rgba(0,0,0,.6);
  transition: transform .1s, background .1s;
}
.tbtn svg { width: 62%; height: 62%; pointer-events: none; }
.tbtn img { width: 72%; height: 72%; object-fit: contain; pointer-events: none; }
.tbtn .k { font-family: var(--brush); font-size: 22px; font-weight: 900; color: var(--gold2); text-shadow: var(--ol); pointer-events: none; }
.tbtn.held { transform: scale(.88); background: rgba(216,180,90,.38); }

#danger { position: absolute; left: 50%; top: 30%; width: 0; height: 0; }
#danger span {
  position: absolute; left: 0; top: 0; transform: translate(-50%, -50%); font-family: var(--brush); font-weight: 900;
  font-size: clamp(54px, 12vh, 104px); color: #e3132e; opacity: 0; white-space: nowrap;
  text-shadow: 0 0 22px rgba(255,0,30,.9), 0 0 6px #000, 3px 3px 0 #200;
}
#danger.show span { animation: dpop .85s ease-out forwards; }
@keyframes dpop {
  0% { opacity: 0; transform: translate(-50%, -50%) scale(2.2); }
  15% { opacity: 1; transform: translate(-50%, -50%) scale(.92); }
  25% { transform: translate(-50%, -50%) scale(1); }
  70% { opacity: 1; }
  100% { opacity: 0; transform: translate(-50%, -50%) scale(1.08); }
}

#kanji { position: absolute; left: 50%; top: 40%; transform: translate(-50%, -50%); text-align: center; opacity: 0; white-space: nowrap; }
#kanji.show { animation: kpop 1.15s ease-out forwards; }
#kanji .kj {
  font-family: var(--brush); font-weight: 900; font-size: clamp(64px, 15vh, 140px); line-height: 1.05; color: #efe2c4;
  text-shadow: 0 0 18px rgba(0,0,0,.9), 4px 4px 0 #0a0503, -1px -1px 0 #0a0503;
}
#kanji.red .kj { color: #d8122c; text-shadow: 0 0 26px rgba(200,0,20,.75), 4px 4px 0 #1a0002, -1px -1px 0 #1a0002; }
#kanji.gold .kj { color: #f3cf6a; text-shadow: 0 0 24px rgba(255,190,60,.6), 4px 4px 0 #2a1600; }
#kanji.blue .kj { color: #9fd8ff; text-shadow: 0 0 24px rgba(80,170,255,.8), 4px 4px 0 #001428; }
#kanji.big .kj { font-size: clamp(90px, 24vh, 220px); }
#kanji .kc { font-size: clamp(14px, 2.4vh, 20px); letter-spacing: .18em; text-shadow: var(--ol); margin-top: 2px; }
@keyframes kpop {
  0% { opacity: 0; transform: translate(-50%, -50%) scale(1.9); filter: blur(8px); }
  12% { opacity: 1; transform: translate(-50%, -50%) scale(.94); filter: blur(0); }
  22% { transform: translate(-50%, -50%) scale(1); }
  72% { opacity: 1; }
  100% { opacity: 0; transform: translate(-50%, -50%) scale(1.05); }
}

#banner { position: absolute; left: 0; right: 0; top: 55%; text-align: center; opacity: 0; }
#banner.show { animation: bann 3.4s ease forwards; }
#banner .bs { font-size: clamp(13px, 2.2vh, 17px); color: var(--gold); letter-spacing: .5em; text-shadow: var(--ol); }
#banner .bt { font-size: clamp(14px, 2.5vh, 20px); color: var(--paper); letter-spacing: .35em; text-shadow: var(--ol); margin-top: 2px; }
#banner .bn { font-family: var(--brush); font-size: clamp(38px, 9vh, 76px); font-weight: 900; letter-spacing: .12em; text-shadow: 0 0 20px rgba(0,0,0,.9), 4px 4px 0 #0a0503; line-height: 1.15; }
#banner .line { width: min(46vw, 520px); height: 3px; margin: 4px auto 0; background: linear-gradient(90deg, transparent, #b01020 20%, #ff3a3a 50%, #b01020 80%, transparent); transform-origin: center; }
#banner.show .line { animation: bline 3.4s ease forwards; }
@keyframes bann { 0% { opacity: 0; transform: translateY(14px); } 12% { opacity: 1; transform: none; } 80% { opacity: 1; } 100% { opacity: 0; } }
@keyframes bline { 0% { transform: scaleX(0); } 20% { transform: scaleX(1); } 100% { transform: scaleX(1); } }

#toast {
  position: absolute; left: 50%; top: 23%; transform: translateX(-50%); padding: 6px 18px; font-size: 16px; white-space: nowrap;
  background: linear-gradient(90deg, transparent, rgba(0,0,0,.7) 15%, rgba(0,0,0,.7) 85%, transparent); text-shadow: var(--ol);
  opacity: 0; transition: opacity .25s;
}
#toast.on { opacity: 1; }
#sub {
  position: absolute; left: 50%; top: 67%; transform: translateX(-50%); max-width: 50vw; text-align: center; padding: 5px 22px;
  font-size: clamp(15px, 2.8vh, 22px); line-height: 1.35; text-shadow: var(--ol);
  background: linear-gradient(90deg, transparent, rgba(0,0,0,.6) 14%, rgba(0,0,0,.6) 86%, transparent);
  opacity: 0; transition: opacity .3s;
}
#sub.on { opacity: 1; }
#hurt { position: absolute; inset: 0; background: radial-gradient(ellipse at center, transparent 50%, rgba(170,0,10,.6) 100%); opacity: 0; }
#hurt.on { animation: hurt .5s ease-out; }
@keyframes hurt { 0% { opacity: 1; } 100% { opacity: 0; } }

/* ---------------- Title ---------------- */
#title { position: fixed; inset: 0; z-index: 20; background: #000 url(../assets/title-bg.webp) center / cover no-repeat; overflow: hidden; cursor: pointer; }
#title.off { display: none; }
#title .mist {
  position: absolute; inset: -20%; pointer-events: none;
  background: radial-gradient(ellipse at 25% 75%, rgba(255,250,240,.10), transparent 45%), radial-gradient(ellipse at 75% 85%, rgba(255,235,210,.08), transparent 40%);
  animation: mist 16s ease-in-out infinite alternate;
}
#title .shade { position: absolute; inset: 0; pointer-events: none; background: linear-gradient(rgba(0,0,0,.25), transparent 30%, transparent 70%, rgba(0,0,0,.55)); }
@keyframes mist { 0% { transform: translate(-3%, 0) scale(1); } 100% { transform: translate(3%, -2%) scale(1.08); } }
#logo {
  position: absolute; left: 50%; top: 5%; max-width: 76vw; max-height: 32vh; transform: translateX(-50%); pointer-events: none;
  filter: drop-shadow(0 4px 14px rgba(0,0,0,.75)); animation: logoIn .75s cubic-bezier(.2, 1.5, .4, 1) both, logoFloat 6s ease-in-out .8s infinite;
}
@keyframes logoIn { 0% { opacity: 0; transform: translateX(-50%) scale(1.3); filter: blur(10px); } 100% { opacity: 1; transform: translateX(-50%) scale(1); } }
@keyframes logoFloat { 0%, 100% { transform: translateX(-50%) translateY(0); } 50% { transform: translateX(-50%) translateY(-6px); } }
#logoText {
  position: absolute; left: 50%; top: 8%; transform: translateX(-50%) rotate(-4deg); font-family: var(--brush); font-weight: 900;
  font-size: clamp(42px, 12vh, 110px); white-space: nowrap; color: #f2e4c4; text-shadow: 0 0 20px rgba(0,0,0,.9), 5px 5px 0 #6a0a12, 7px 7px 0 #0a0503;
}
#startPrompt {
  position: absolute; left: 0; right: 0; bottom: 9%; text-align: center; font-size: clamp(16px, 3.2vh, 26px); font-weight: 700;
  letter-spacing: .22em; text-shadow: var(--ol); animation: pulse 2.2s ease-in-out infinite; pointer-events: none;
}
#startPrompt::before, #startPrompt::after { content: "—"; color: var(--gold); margin: 0 .6em; opacity: .8; }
@keyframes pulse { 0%, 100% { opacity: .55; } 50% { opacity: 1; } }
.cornerBtn {
  position: absolute; top: 12px; width: 48px; height: 48px; border-radius: 50%; padding: 0; cursor: pointer;
  background: rgba(14,8,5,.55); border: 2px solid rgba(216,180,90,.65); color: var(--gold);
  display: flex; align-items: center; justify-content: center; box-shadow: 0 2px 10px rgba(0,0,0,.6); transition: transform .12s, background .12s;
}
.cornerBtn:hover { background: rgba(60,38,20,.7); transform: scale(1.06); }
.cornerBtn:active { transform: scale(.92); }
.cornerBtn svg, .cornerBtn img { width: 58%; height: 58%; object-fit: contain; pointer-events: none; }
#btnBoard { right: calc(12px + var(--sr)); }
#btnShopT { left: calc(12px + var(--sl)); }
#boardKey { position: absolute; top: 26px; right: calc(66px + var(--sr)); font-size: 12px; padding: 0 5px; border: 1px solid var(--gold); border-radius: 4px; background: rgba(10,6,4,.6); pointer-events: none; }
body.touch #boardKey { display: none; }

/* ---------------- Intro ---------------- */
#intro { position: fixed; inset: 0; z-index: 30; background: #000 url(../assets/title-bg.webp) center / cover no-repeat; display: none; }
#intro.show { display: block; }
#introVid { width: 100%; height: 100%; object-fit: cover; display: block; background: transparent; }
#skipBtn { position: absolute; top: 12px; right: calc(12px + var(--sr)); min-width: 96px; height: 46px; z-index: 2; }
#introSub {
  position: absolute; left: 50%; bottom: 8%; transform: translateX(-50%); max-width: 70vw; text-align: center; padding: 6px 24px;
  font-size: clamp(16px, 3vh, 24px); text-shadow: var(--ol); background: linear-gradient(90deg, transparent, rgba(0,0,0,.6) 14%, rgba(0,0,0,.6) 86%, transparent);
  opacity: 0; transition: opacity .4s;
}
#introSub.on { opacity: 1; }

#fade { position: fixed; inset: 0; z-index: 45; background: #000; opacity: 0; pointer-events: none; transition: opacity .38s ease; }
#fade.on { opacity: 1; }

/* ---------------- Panels, buttons, modals ---------------- */
.panel {
  border-style: solid; border-width: 24px; border-color: transparent;
  border-image: url(../assets/ui-panel.webp) 14% fill / 24px stretch;
}
.btn {
  pointer-events: auto; cursor: pointer; min-height: 52px; padding: 0 22px; font-weight: 900; font-size: clamp(16px, 2.8vh, 21px);
  letter-spacing: .12em; color: var(--paper); text-shadow: var(--ol); background: transparent;
  border-style: solid; border-width: 12px 18px; border-color: transparent;
  border-image: url(../assets/ui-button.webp) 30% 14% fill / 12px 18px stretch;
  transition: transform .12s, filter .12s;
}
.btn.focus { transform: scale(1.07); filter: brightness(1.3) drop-shadow(0 0 10px rgba(216,180,90,.75)); color: #fff6dc; }
.btn:active, .btn.chosen { transform: scale(.94); }
.modal {
  position: fixed; inset: 0; z-index: 40; display: none; align-items: center; justify-content: center; flex-direction: column;
  background: radial-gradient(ellipse at center, rgba(14,6,3,.45), rgba(0,0,0,.86)); padding: 12px calc(16px + var(--sr)) 12px calc(16px + var(--sl));
}
.modal.show { display: flex; animation: mfade .25s ease-out; }
@keyframes mfade { 0% { opacity: 0; } 100% { opacity: 1; } }

#reward .rtitle { font-family: var(--brush); font-size: clamp(22px, 5vh, 40px); font-weight: 900; letter-spacing: .14em; text-shadow: var(--ol); animation: drop .4s cubic-bezier(.2,1.5,.4,1) both; }
#reward .rgain { font-size: clamp(14px, 2.4vh, 18px); color: var(--gold2); text-shadow: var(--ol); margin: 2px 0 1.6vh; letter-spacing: .1em; }
#reward .cards { display: flex; gap: 2.2vw; align-items: stretch; }
.card {
  pointer-events: auto; cursor: pointer; width: min(27vw, 280px); height: min(58vh, 400px); padding: 0; background: transparent;
  display: flex; flex-direction: column; align-items: center; justify-content: flex-start; text-align: center; color: var(--paper);
  transition: transform .15s, filter .15s; animation: cardIn .45s cubic-bezier(.2,1.4,.4,1) both;
}
.card:nth-child(2) { animation-delay: .07s; }
.card:nth-child(3) { animation-delay: .14s; }
.card.focus { transform: translateY(-6px) scale(1.05); filter: brightness(1.18) drop-shadow(0 0 16px rgba(216,180,90,.7)); }
.card.chosen { transform: scale(1.12); filter: brightness(1.5) drop-shadow(0 0 26px rgba(255,220,140,.9)); }
.card .ico {
  width: 44%; aspect-ratio: 1; margin-top: 4%; border-radius: 50%; display: flex; align-items: center; justify-content: center;
  background: radial-gradient(circle at 40% 35%, rgba(80,52,28,.9), rgba(12,7,4,.95)); border: 2px solid rgba(216,180,90,.7);
  box-shadow: 0 0 18px rgba(0,0,0,.8), inset 0 0 12px rgba(0,0,0,.9);
}
.card .ico img { width: 80%; height: 80%; object-fit: contain; }
.card .ico .glyph { font-family: var(--brush); font-weight: 900; font-size: clamp(30px, 7vh, 60px); color: var(--gold2); text-shadow: var(--ol); }
.card .kind { margin-top: 6%; font-size: 12px; color: var(--gold); letter-spacing: .2em; }
.card .nm { margin-top: 2px; font-size: clamp(16px, 3vh, 24px); font-weight: 900; text-shadow: var(--ol); line-height: 1.2; }
.card .ds { margin-top: 6px; font-size: clamp(12px, 2.1vh, 15px); line-height: 1.45; opacity: .92; padding: 0 2px; }
@keyframes cardIn { 0% { opacity: 0; transform: translateY(30px) scale(.9); } 100% { opacity: 1; transform: none; } }
@keyframes drop { 0% { opacity: 0; transform: translateY(-24px) scale(1.2); } 100% { opacity: 1; transform: none; } }

#death { background: radial-gradient(ellipse at center, rgba(60,0,4,.35), rgba(0,0,0,.88)); }
#death .dk {
  font-family: var(--brush); font-weight: 900; font-size: clamp(100px, 30vh, 250px); line-height: 1; color: #b80c24;
  text-shadow: 0 0 40px rgba(160,0,20,.7), 5px 5px 0 #0a0002; animation: dk 1.1s ease-out both;
}
@keyframes dk { 0% { opacity: 0; transform: scale(1.6); filter: blur(12px); } 60% { opacity: 1; filter: blur(0); } 100% { transform: scale(1); } }
#death .btns { display: flex; gap: 16px; flex-wrap: wrap; justify-content: center; margin-top: 3vh; animation: mfade .5s .6s both; }
#death .btn { min-width: 160px; }

#help .hpanel { width: min(92vw, 860px); max-height: 94vh; display: flex; flex-direction: column; align-items: center; padding: 0 6px; }
#help .htitle { font-family: var(--brush); font-size: clamp(20px, 4.4vh, 34px); font-weight: 900; letter-spacing: .14em; }
#help .hgrid { display: grid; grid-template-columns: 1fr 1fr; gap: 3px 28px; width: 100%; margin: 1.2vh 0; }
#help .hrow { display: flex; justify-content: space-between; gap: 10px; font-size: clamp(13px, 2.2vh, 16px); border-bottom: 1px solid rgba(216,180,90,.2); padding: 2px 0; }
#help .hrow b { color: var(--gold2); font-weight: 700; white-space: nowrap; }
#help .htips { font-size: clamp(12px, 2vh, 15px); line-height: 1.45; opacity: .92; width: 100%; }
#help .htips div::before { content: "◆ "; color: #c0283a; }
#help .hclose { margin-top: 1.2vh; min-width: 150px; }

@media (max-height: 500px) {
  .panel { border-width: 16px; border-image-width: 16px; }
  .card { height: min(64vh, 400px); }
  .card .ds { font-size: 12px; line-height: 1.35; }
  #help .hgrid { gap: 1px 18px; margin: 4px 0; }
  #help .hrow { font-size: 13px; padding: 1px 0; }
  #help .htips { font-size: 12px; line-height: 1.3; }
  #death .btn { min-width: 130px; }
}
