:root {
  --ink: #0b0614;
  --paper: #f3ead8;
  --red: #c8102e;
  --gold: #ffd76a;
  --glow: #8fd8ff;
  --ui: "Zen Kaku Gothic New", system-ui, sans-serif;
  --brush: "Yuji Syuku", "Yu Mincho", "Hiragino Mincho ProN", "Noto Serif JP", serif;
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; overflow: hidden; background: var(--ink); color: #fff; font-family: var(--ui); }
canvas { display: block; position: fixed; inset: 0; touch-action: none; cursor: crosshair; }
button { font: inherit; color: inherit; }

#ui { position: fixed; inset: 0; pointer-events: none; }
.screen {
  position: absolute; inset: 0; display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 18px; padding: 24px 16px calc(24px + env(safe-area-inset-bottom)); pointer-events: auto; text-align: center;
  animation: fadeIn .35s ease both;
}
.hidden { display: none !important; }
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }

/* ---------- title ---------- */
#title { background: radial-gradient(ellipse at 50% 40%, rgba(6,3,14,0) 0%, rgba(6,3,14,.55) 70%); }
.logo { position: relative; display: flex; flex-direction: column; align-items: center; line-height: 1; user-select: none; }
.logo .kanji {
  font-family: var(--brush); font-size: clamp(92px, 24vw, 190px); color: #fff;
  text-shadow: 0 0 30px rgba(143,216,255,.45), 0 6px 0 rgba(0,0,0,.35);
  animation: logoIn 1.1s cubic-bezier(.2,.9,.2,1) both .15s;
}
.logo .latin {
  font-weight: 900; letter-spacing: .6em; margin-left: .6em; font-size: clamp(16px, 3.6vw, 24px); color: var(--gold);
  animation: fadeIn .8s ease both .9s;
}
.logo-slash {
  position: absolute; left: -12%; right: -12%; top: 42%; height: 4px;
  background: linear-gradient(90deg, transparent, #fff 30%, #fff 70%, transparent);
  box-shadow: 0 0 18px 4px var(--glow); transform: rotate(-14deg) scaleX(0); transform-origin: left;
  animation: slash 1.1s cubic-bezier(.7,0,.2,1) both .05s;
}
@keyframes logoIn {
  0% { clip-path: inset(-30% 100% -30% -30%); transform: translateX(-12px); opacity: .6; }
  45% { clip-path: inset(-30% -30% -30% -30%); transform: none; opacity: 1; }
  52% { transform: translate(6px, -2px); }
  60%, 100% { clip-path: inset(-30% -30% -30% -30%); transform: none; }
}
@keyframes slash {
  0% { transform: rotate(-14deg) scaleX(0); opacity: 1; }
  40% { transform: rotate(-14deg) scaleX(1); opacity: 1; }
  100% { transform: rotate(-14deg) scaleX(1); opacity: 0; }
}
.tag { margin: -6px 0 4px; color: rgba(255,255,255,.75); font-weight: 500; letter-spacing: .04em; animation: fadeIn .8s ease both 1s; }

.menu { display: flex; flex-direction: column; gap: 10px; width: min(300px, 86vw); animation: fadeIn .6s ease both 1.1s; }
.menu.row { flex-direction: row; width: auto; }
.btn {
  position: relative; border: 1px solid rgba(255,255,255,.25); background: rgba(12,6,24,.55); backdrop-filter: blur(4px);
  padding: 13px 20px; font-weight: 900; font-size: 17px; letter-spacing: .12em; text-transform: uppercase; cursor: pointer;
  clip-path: polygon(10px 0, 100% 0, calc(100% - 10px) 100%, 0 100%); transition: background .15s, transform .15s, color .15s;
  overflow: hidden;
}
.btn small { font-weight: 500; letter-spacing: .04em; text-transform: none; opacity: .65; margin-left: 6px; font-size: 12px; }
.btn::after {
  content: ""; position: absolute; top: 0; bottom: 0; width: 40%; left: -60%;
  background: linear-gradient(100deg, transparent, rgba(255,255,255,.35), transparent); transform: skewX(-20deg);
}
.btn:hover::after, .btn:focus-visible::after { left: 130%; transition: left .45s ease; }
.btn:hover, .btn:focus-visible { background: rgba(255,255,255,.12); transform: translateX(3px); outline: none; }
.btn:active { transform: scale(.97); }
.btn.primary { background: var(--red); border-color: #ff4a5e; box-shadow: 0 0 24px rgba(200,16,46,.45); }
.btn.primary:hover { background: #e01836; }
.btn.ghost { background: transparent; }

.stats { display: flex; gap: 18px; flex-wrap: wrap; justify-content: center; font-size: 13px; color: rgba(255,255,255,.65); animation: fadeIn .6s ease both 1.2s; }
.stats b { color: #fff; margin-left: 4px; }
.howto {
  display: flex; flex-wrap: wrap; justify-content: center; gap: 6px 14px; max-width: 520px; font-size: 12.5px; color: rgba(255,255,255,.6);
  animation: fadeIn .6s ease both 1.3s;
}
.howto b { color: var(--gold); font-weight: 700; }
.howto .keys { width: 100%; opacity: .7; }
@media (hover: none) { .howto .keys { display: none; } }

.icon-btn {
  position: absolute; width: 42px; height: 42px; border-radius: 50%; border: 1px solid rgba(255,255,255,.3);
  background: rgba(10,5,20,.5); cursor: pointer; pointer-events: auto; font-size: 15px; display: grid; place-items: center;
}
.icon-btn:hover { background: rgba(255,255,255,.15); }
#pauseBtn { top: calc(14px + env(safe-area-inset-top)); left: 50%; transform: translateX(-50%); font-size: 11px; letter-spacing: -1px; opacity: .7; }

/* ---------- headings ---------- */
.screen h2 { margin: 0; font-weight: 900; letter-spacing: .14em; text-transform: uppercase; font-size: 18px; display: flex; flex-direction: column; align-items: center; gap: 4px; }
.screen h2 span { font-family: var(--brush); font-size: 58px; letter-spacing: 0; text-transform: none; color: var(--gold); text-shadow: 0 0 20px rgba(255,215,106,.35); }
.hint { margin: 0; font-size: 13px; color: rgba(255,255,255,.6); }

/* ---------- relic draft ---------- */
#draft { background: rgba(6,3,14,.6); backdrop-filter: blur(2px); }
.cards { display: flex; gap: 14px; flex-wrap: wrap; justify-content: center; max-width: 820px; }
.card {
  position: relative; width: min(220px, 28vw); min-width: 150px; min-height: 250px; padding: 22px 16px 18px;
  display: flex; flex-direction: column; align-items: center; gap: 10px; cursor: pointer;
  background: linear-gradient(180deg, #f6eedd, #e6d8bb); color: #1a0e0e; border: none;
  box-shadow: 0 10px 40px rgba(0,0,0,.5), inset 0 0 0 2px rgba(120,20,30,.25), inset 0 0 0 6px #f6eedd, inset 0 0 0 7px rgba(120,20,30,.4);
  animation: cardIn .5s cubic-bezier(.2,1.2,.3,1) both;
  transition: transform .18s, box-shadow .18s;
}
.card:hover, .card:focus-visible { transform: translateY(-8px) rotate(-1deg); outline: none; box-shadow: 0 16px 50px rgba(0,0,0,.6), 0 0 0 3px var(--gold), inset 0 0 0 6px #f6eedd, inset 0 0 0 7px rgba(120,20,30,.4); }
.card .k { font-family: var(--brush); font-size: 74px; line-height: 1; color: var(--red); }
.card .n { font-weight: 900; font-size: 16px; letter-spacing: .06em; text-transform: uppercase; }
.card .n em { font-style: normal; background: var(--red); color: #fff; padding: 0 6px; margin-left: 4px; font-size: 12px; }
.card .d { font-size: 13.5px; line-height: 1.45; color: #4a3434; }
.card .key { position: absolute; top: 8px; right: 12px; font-weight: 900; font-size: 12px; color: rgba(90,20,30,.45); }
.card.picked { animation: picked .3s ease forwards; }
.card.picked::after {
  content: ""; position: absolute; left: -10%; right: -10%; top: 50%; height: 4px; background: #fff;
  box-shadow: 0 0 20px 6px var(--gold); transform: rotate(-24deg);
}
@keyframes cardIn { from { opacity: 0; transform: translateY(60px) rotate(4deg) scale(.9); } to { opacity: 1; transform: none; } }
@keyframes picked { 0% { transform: scale(1.04); } 100% { transform: scale(1.12); opacity: 0; filter: brightness(2); } }

/* ---------- pause ---------- */
#pause { background: rgba(6,3,14,.65); backdrop-filter: blur(3px); }
.relics { display: flex; flex-wrap: wrap; gap: 8px; justify-content: center; max-width: 520px; }
.relics span { font-family: var(--brush); font-size: 26px; color: var(--gold); background: rgba(255,255,255,.06); padding: 6px 10px; display: flex; align-items: center; gap: 6px; }
.relics small { font-family: var(--ui); font-size: 12px; color: rgba(255,255,255,.75); }
.relics .none { font-family: var(--ui); font-size: 13px; color: rgba(255,255,255,.6); background: none; }

/* ---------- results ---------- */
#dead { background: radial-gradient(ellipse at 50% 50%, rgba(6,3,14,.55), rgba(6,3,14,.9)); }
.result {
  width: min(420px, 92vw); padding: 26px 22px 22px; display: flex; flex-direction: column; align-items: center; gap: 10px;
  background: linear-gradient(180deg, rgba(20,10,34,.92), rgba(10,5,18,.95)); border: 1px solid rgba(255,255,255,.15);
  box-shadow: 0 20px 60px rgba(0,0,0,.6); animation: cardIn .55s cubic-bezier(.2,1.1,.3,1) both;
  position: relative; overflow: hidden;
}
.result::before {
  content: ""; position: absolute; left: -20%; right: -20%; top: 70px; height: 2px; background: #fff; opacity: .0;
  box-shadow: 0 0 16px 4px var(--red); transform: rotate(-8deg); animation: resSlash .7s ease .1s both;
}
@keyframes resSlash { 0% { opacity: 1; transform: rotate(-8deg) scaleX(0); transform-origin: left; } 50% { opacity: 1; transform: rotate(-8deg) scaleX(1); } 100% { opacity: 0; transform: rotate(-8deg) scaleX(1); } }
.r-k { font-family: var(--brush); font-size: 84px; line-height: 1; color: var(--red); text-shadow: 0 0 24px rgba(200,16,46,.5); }
.r-cause { font-size: 13px; letter-spacing: .2em; text-transform: uppercase; color: rgba(255,255,255,.6); }
.badge { background: var(--gold); color: #1a0e0e; font-weight: 900; font-size: 12px; letter-spacing: .2em; text-transform: uppercase; padding: 4px 10px; animation: pulse 1s ease infinite alternate; }
@keyframes pulse { to { transform: scale(1.08); box-shadow: 0 0 20px rgba(255,215,106,.6); } }
.r-height { font-size: 22px; font-weight: 700; color: rgba(255,255,255,.75); }
.r-height b { font-size: 64px; font-weight: 900; color: #fff; }
.r-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; width: 100%; }
.r-grid span { background: rgba(255,255,255,.05); padding: 10px; font-size: 11px; letter-spacing: .14em; text-transform: uppercase; color: rgba(255,255,255,.55); display: flex; flex-direction: column; gap: 2px; }
.r-grid b { font-size: 22px; color: #fff; letter-spacing: 0; }
.r-relics { font-family: var(--brush); font-size: 28px; color: var(--gold); letter-spacing: .2em; }
.r-daily { font-size: 12px; color: rgba(255,255,255,.55); }
.unlock { font-size: 14px; padding: 8px 12px; background: rgba(255,255,255,.07); animation: pulse 1s ease infinite alternate; }
.result .menu { animation: none; margin-top: 6px; }

@media (max-width: 560px) {
  .cards { flex-direction: column; align-items: center; gap: 10px; }
  .card { width: min(340px, 88vw); min-height: 0; flex-direction: row; text-align: left; padding: 14px 16px; gap: 14px; }
  .card .k { font-size: 52px; }
  .card .n, .card .d { display: block; }
  .card > .n { position: absolute; left: 86px; top: 14px; }
  .card > .d { margin-top: 24px; }
  .screen h2 span { font-size: 46px; }
}
@media (max-height: 600px) {
  .howto { display: none; }
  .logo .kanji { font-size: 84px; }
}
.credit { font-size: 11px; color: rgba(255,255,255,.4); margin-top: 10px; }

.btn-slash { position: fixed; width: 3px; pointer-events: none; z-index: 70; transform-origin: center top;
  background: linear-gradient(180deg, transparent, #fff 15%, #fff 85%, transparent);
  box-shadow: 0 0 12px 3px rgba(143,216,255,.9), 0 0 28px 8px rgba(143,216,255,.45);
  clip-path: inset(0 0 100% 0); animation: btnSlash .16s ease-out forwards; }
@keyframes btnSlash { 0% { clip-path: inset(0 0 100% 0); opacity: 1; } 60% { clip-path: inset(0 0 0 0); opacity: 1; } 100% { clip-path: inset(0 0 0 0); opacity: 0; } }

.vol { pointer-events: auto; position: fixed; right: 12px; bottom: calc(12px + env(safe-area-inset-bottom)); z-index: 50; display: flex; align-items: center; gap: 10px;
  padding: 6px 10px; border-radius: 22px; background: rgba(10,5,20,.55); border: 1px solid rgba(255,255,255,.2); font-size: 11px; color: rgba(255,255,255,.75); }
.vol label { display: flex; align-items: center; gap: 6px; }
.vol input[type=range] { width: 70px; accent-color: #ff4a5e; }
.vbtn { width: 28px; height: 28px; border-radius: 50%; border: 1px solid rgba(255,255,255,.3); background: transparent; color: #fff; cursor: pointer; }
.vbtn.off { opacity: .45; }
@media (max-width: 420px) { .vol input[type=range] { width: 52px; } }

/* ---------- gauntlet ---------- */
#levels { background: rgba(6,3,14,.72); backdrop-filter: blur(3px); }
#levels .hint { max-width: 520px; }
.level-list { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 8px; width: min(640px, 94vw); max-height: 62vh; overflow-y: auto; padding: 2px; }
.level {
  border: 1px solid rgba(255,255,255,.2); background: rgba(255,255,255,.04); padding: 10px 6px 8px; cursor: pointer; color: #fff;
  display: flex; flex-direction: column; align-items: center; gap: 3px; font: inherit; position: relative; overflow: hidden;
}
.level:hover { background: rgba(255,255,255,.1); }
.level .lk { font-family: var(--brush); font-size: 30px; line-height: 1.1; color: var(--gold); }
.level .ln { font-weight: 900; font-size: 12px; letter-spacing: .04em; }
.level .lt { font-size: 10px; letter-spacing: .14em; text-transform: uppercase; padding: 1px 6px; }
.level .lt.time { background: rgba(95,208,255,.18); color: #9fe2ff; }
.level .lt.slash { background: rgba(255,59,74,.2); color: #ffb0b8; }
.level .ls i, .r-stars i { font-style: normal; color: rgba(255,255,255,.18); }
.level .ls i.on, .r-stars i.on { color: var(--gold); text-shadow: 0 0 8px rgba(255,215,106,.7); }
.level small { font-size: 10px; color: rgba(255,255,255,.5); }
.level.locked { opacity: .35; cursor: default; }
.level.done { border-color: rgba(255,215,106,.45); }
.r-stars { font-size: 40px; letter-spacing: .1em; }
.r-k.win { color: var(--gold); text-shadow: 0 0 24px rgba(255,215,106,.5); font-size: 64px; }
.r-targets { font-size: 12px; color: rgba(255,255,255,.6); letter-spacing: .04em; }
@media (max-width: 560px) { .level-list { grid-template-columns: repeat(3, minmax(0, 1fr)); } }

/* ================= Hyakki additions ================= */
.screen { overflow-y: auto; justify-content: safe center; }
#pauseBtn { left: auto; right: calc(12px + env(safe-area-inset-right)); top: calc(16px + env(safe-area-inset-top)); transform: none; }
.menu.row { flex-direction: row; justify-content: center; width: min(420px, 92vw); }
.menu.row .btn { flex: 1; }
.btn.small { padding: 8px 14px; font-size: 13px; letter-spacing: .08em; }
.btn.dim { opacity: .45; }
.gold { color: var(--gold); }
#title .logo .kanji { font-size: clamp(88px, 22vw, 180px); }
#title .logo .latin { letter-spacing: .45em; }

/* toasts */
#toasts { position: fixed; top: calc(70px + env(safe-area-inset-top)); left: 50%; transform: translateX(-50%); display: flex; flex-direction: column; gap: 6px; z-index: 80; pointer-events: none; }
.toast { background: rgba(12,6,24,.9); border: 1px solid var(--gold); color: #fff; padding: 9px 16px; font-weight: 700; font-size: 14px; animation: toast 3.6s ease both; white-space: nowrap; }
@keyframes toast { 0% { opacity: 0; transform: translateY(-14px); } 10%, 85% { opacity: 1; transform: none; } 100% { opacity: 0; } }

/* characters */
#chars, #biomes, #shop, #ach { background: rgba(6,3,14,.72); backdrop-filter: blur(3px); }
.char-list { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; width: min(760px, 94vw); }
.char {
  position: relative; text-align: left; border: 1px solid rgba(255,255,255,.18); background: rgba(255,255,255,.04); padding: 14px 14px 12px 86px;
  min-height: 118px; cursor: pointer; display: flex; flex-direction: column; gap: 4px; transition: border-color .15s, background .15s;
}
.char:hover { background: rgba(255,255,255,.08); }
.char.on { border-color: var(--g); box-shadow: 0 0 0 1px var(--g), 0 0 26px rgba(255,255,255,.08); background: rgba(255,255,255,.08); }
.char .ck { position: absolute; left: 14px; top: 12px; font-family: var(--brush); font-size: 58px; line-height: 1; color: var(--g); text-shadow: 0 0 18px var(--g); }
.char .cn { font-weight: 900; font-size: 17px; letter-spacing: .08em; text-transform: uppercase; }
.char .cn em { font-style: normal; font-size: 11px; color: #1a0e0e; padding: 1px 6px; margin-left: 6px; letter-spacing: .04em; vertical-align: middle; }
.char .cd { font-size: 13px; line-height: 1.4; color: rgba(255,255,255,.8); }
.char .cp { font-size: 11.5px; color: rgba(255,255,255,.55); }
.char .cp b { color: #fff; }
.char.locked { opacity: .5; cursor: default; }
.char.locked .ck { color: rgba(255,255,255,.4); text-shadow: none; }

/* biomes */
.biome-list { display: flex; flex-direction: column; gap: 8px; width: min(520px, 94vw); }
.biome {
  position: relative; display: grid; grid-template-columns: 56px 1fr auto; grid-template-rows: auto auto; column-gap: 12px; align-items: center; text-align: left;
  padding: 10px 14px; border: 1px solid rgba(255,255,255,.18); cursor: pointer;
  background: linear-gradient(90deg, var(--b0), rgba(12,6,24,.6) 70%);
}
.biome .bk { grid-row: span 2; font-family: var(--brush); font-size: 44px; color: var(--g); text-shadow: 0 0 16px var(--g); text-align: center; }
.biome .bn { font-weight: 900; letter-spacing: .06em; font-size: 15px; }
.biome .bn i { font-style: normal; color: var(--gold); }
.biome .bd { font-size: 12px; color: rgba(255,255,255,.65); grid-column: 2; }
.biome .bdiff { grid-row: 1 / span 2; grid-column: 3; color: var(--g); font-size: 10px; letter-spacing: 2px; }
.biome.on { border-color: var(--g); box-shadow: 0 0 0 1px var(--g); }
.biome.locked { opacity: .4; cursor: default; filter: grayscale(.8); }
.mode-row { display: flex; gap: 0; width: min(520px, 94vw); }
.seg { flex: 1; padding: 10px; border: 1px solid rgba(255,255,255,.25); background: transparent; font-weight: 900; letter-spacing: .08em; cursor: pointer; }
.seg.on { background: var(--red); border-color: #ff4a5e; }
.seg.locked { opacity: .45; cursor: default; }

/* shop */
.shop-list { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 8px; width: min(720px, 94vw); }
.item { display: flex; flex-direction: column; align-items: center; gap: 5px; padding: 12px 8px; border: 1px solid rgba(255,255,255,.16); background: rgba(255,255,255,.04); }
.item .ik { font-family: var(--brush); font-size: 34px; color: var(--gold); line-height: 1; }
.item .in { font-weight: 900; font-size: 13px; letter-spacing: .08em; text-transform: uppercase; }
.item .ip { display: flex; gap: 3px; }
.item .ip i { width: 10px; height: 4px; background: rgba(255,255,255,.2); }
.item .ip i.on { background: var(--gold); }
.item .idsc { font-size: 11.5px; color: rgba(255,255,255,.65); min-height: 2.6em; text-align: center; }

/* achievements */
.ach-list { display: flex; flex-direction: column; gap: 6px; width: min(520px, 94vw); }
.ach { display: grid; grid-template-columns: 1fr auto; text-align: left; padding: 9px 12px; background: rgba(255,255,255,.04); border-left: 3px solid rgba(255,255,255,.2); }
.ach b { font-size: 14px; }
.ach span { grid-column: 1; font-size: 12px; color: rgba(255,255,255,.65); }
.ach small { grid-row: 1 / span 2; grid-column: 2; align-self: center; font-size: 11px; color: var(--gold); }
.ach.done { border-left-color: var(--gold); background: rgba(255,215,106,.08); }

/* draft cards */
.card .tag { position: absolute; top: 8px; left: 10px; font-family: var(--brush); font-size: 15px; color: #1a0e0e; width: 24px; height: 24px; display: grid; place-items: center; }
.card .sub { font-size: 11px; color: rgba(74,52,52,.7); margin-top: auto; }
.card .affl { position: absolute; bottom: -1px; left: 50%; transform: translateX(-50%); background: var(--red); color: #fff; font-size: 10px; font-weight: 900; letter-spacing: .1em; padding: 2px 8px; text-transform: uppercase; white-space: nowrap; }
.card.passive { background: linear-gradient(180deg, #ece6f4, #d8cfe6); }
.card.passive .k { color: #5a2cb0; }
.card.evo { background: linear-gradient(180deg, #fff3c4, #f0c860); box-shadow: 0 0 40px rgba(255,215,106,.6), inset 0 0 0 2px rgba(120,60,10,.4), inset 0 0 0 6px #fff3c4, inset 0 0 0 7px rgba(120,60,10,.5); }
.card.evo .k { color: #8a1a24; text-shadow: 0 0 14px rgba(255,255,255,.9); font-size: 56px; }
.card.banish { filter: grayscale(.6); outline: 2px dashed #ff4a5e; }
.draft-tools { display: flex; gap: 10px; }
@media (hover: none) { .keys-hint { display: none; } }
#results .relics, #pause .relics { max-width: 560px; }
.relics span.ev { color: #fff; background: rgba(255,215,106,.25); }
.relics span.pa { color: #c9a8ff; }

@media (max-width: 560px) {
  .char-list { grid-template-columns: 1fr; }
  .char { min-height: 0; padding-left: 74px; }
  .char .ck { font-size: 46px; }
  .shop-list { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .card .tag { top: 6px; left: auto; right: 34px; }
  .card .sub, .card .affl { display: none; }
  .card .d { font-size: 12.5px; }
  .card.evo .k { font-size: 40px; }
}
/* list screens: compact headers so the buttons stay on screen */
#chars, #biomes, #shop, #ach { gap: 12px; }
#chars h2 span, #biomes h2 span, #shop h2 span, #ach h2 span { font-size: 40px; }
.screen:not(#title) .menu { animation: none; }
.biome { padding: 7px 12px; }
.biome .bk { font-size: 34px; }
