:root {
  --bg: #120e0c;
  --panel: #1b1613;
  --panel-2: #241d19;
  --line: #3a2e27;
  --text: #f3e9df;
  --muted: #b9a89a;
  --accent: #f07a22;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; overflow: hidden; background: #000; color: var(--text); font: 15px/1.45 system-ui, sans-serif; }

#game { position: fixed; inset: 0; width: 100%; height: 100%; touch-action: none; outline: none; }
.hud { position: fixed; right: 8px; bottom: 8px; background: rgba(27,22,19,.85); border-radius: 8px; padding: 4px 8px; color: var(--muted); font: 12px ui-monospace, monospace; pointer-events: none; }
.hud:empty { display: none; }

#start { position: fixed; inset: 0; display: grid; place-items: center; padding: 16px; overflow: auto;
  background: radial-gradient(ellipse at top, rgba(240,122,34,.18), transparent 60%), rgba(10,8,7,.94); }
#start[hidden] { display: none; }
.panel { width: min(440px, 100%); background: var(--panel); border: 1px solid var(--line); border-radius: 14px; padding: 20px; }
h1 { margin: 0 0 14px; font-size: 26px; }
h1 small { color: var(--accent); font-size: 14px; font-weight: 600; text-transform: uppercase; letter-spacing: .06em; margin-left: 6px; }
.field { display: flex; flex-direction: column; gap: 6px; color: var(--muted); font-size: 13px; }
.field input { background: #0f0c0a; color: var(--text); border: 1px solid var(--line); border-radius: 8px; padding: 10px 12px; font: inherit; }
.field input:focus { outline: 2px solid var(--accent); outline-offset: 1px; }
.label { margin: 14px 0 6px; color: var(--muted); font-size: 13px; }
.clans { display: grid; grid-template-columns: repeat(auto-fill, minmax(88px, 1fr)); gap: 8px; }
.clan { display: flex; flex-direction: column; align-items: center; gap: 2px; background: var(--panel-2); color: var(--text); border: 1px solid var(--line); border-radius: 10px; padding: 6px 4px; font: inherit; font-size: 13px; font-weight: 600; cursor: pointer; }
.clan canvas { width: 64px; height: 64px; image-rendering: pixelated; }
.clan[aria-pressed="true"] { border-color: var(--accent); box-shadow: 0 0 0 1px var(--accent) inset; }
.primary { width: 100%; margin-top: 16px; background: var(--accent); color: #1a0f08; border: 0; border-radius: 10px; padding: 12px; font: inherit; font-weight: 700; cursor: pointer; }
.primary:disabled { opacity: .5; cursor: default; }
.status { min-height: 1.4em; margin: 10px 0 0; color: #ffb27a; }
.hint { margin: 6px 0 0; color: var(--muted); font-size: 13px; }

/* ---------- In-game HUD ---------- */
#hud[hidden] { display: none; }
.bars { position: fixed; left: max(8px, env(safe-area-inset-left)); top: max(8px, env(safe-area-inset-top)); width: min(240px, 46vw); display: grid; gap: 4px; pointer-events: none; }
.bar { position: relative; height: 16px; background: rgba(0,0,0,.6); border: 1px solid rgba(255,255,255,.18); border-radius: 5px; overflow: hidden; }
.bar i { position: absolute; inset: 0 auto 0 0; width: 100%; transition: width .2s; }
.bar span { position: relative; display: block; text-align: center; font: 600 11px/16px system-ui, sans-serif; text-shadow: 0 1px 2px #000; }
.bar.hp i { background: linear-gradient(#e2483c, #a92318); }
.bar.ck i { background: linear-gradient(#3d8be2, #1f5aa8); }
.bar.ex { height: 6px; }
.bar.ex i { background: #f0c03a; }
.level { color: var(--muted); font-size: 12px; font-weight: 600; text-shadow: 0 1px 2px #000; }

.jutsus { position: fixed; right: max(12px, env(safe-area-inset-right)); bottom: max(40px, calc(env(safe-area-inset-bottom) + 28px));
  width: 196px; height: 196px; pointer-events: none; }
.jutsu { position: absolute; width: 66px; height: 66px; border-radius: 50%; border: 2px solid rgba(255,255,255,.35);
  background: radial-gradient(circle at 35% 30%, rgba(80,60,50,.95), rgba(25,18,14,.95)); color: var(--text);
  font: 700 11px/1.1 system-ui, sans-serif; display: grid; place-items: center; padding: 4px; pointer-events: auto;
  touch-action: none; user-select: none; -webkit-user-select: none; overflow: hidden; cursor: pointer; }
.jutsu .jn { position: relative; text-align: center; text-shadow: 0 1px 2px #000; }
.jutsu .cd { position: absolute; inset: 0; background: conic-gradient(rgba(0,0,0,.72) var(--p, 0%), transparent 0); }
.jutsu kbd { position: absolute; top: 4px; right: 50%; transform: translateX(50%); font: 600 9px system-ui; color: var(--muted); }
.jutsu.aiming { border-color: var(--accent); box-shadow: 0 0 0 3px rgba(240,122,34,.45); overflow: visible; }
.jutsu .knob { position: absolute; left: 50%; top: 50%; width: 26px; height: 26px; margin: -13px 0 0 -13px; border-radius: 50%;
  background: rgba(240,122,34,.85); box-shadow: 0 0 0 2px rgba(255,255,255,.5); opacity: 0; pointer-events: none; }
.jutsu.aiming .knob { opacity: 1; }
.cancel { position: fixed; right: max(12px, env(safe-area-inset-right)); bottom: calc(max(40px, calc(env(safe-area-inset-bottom) + 28px)) + 214px);
  width: 196px; padding: 10px; border-radius: 12px; text-align: center; font-weight: 700; color: #ffd0c8;
  background: rgba(60,10,10,.75); border: 2px dashed rgba(255,120,100,.6); pointer-events: none; }
.cancel.hot { background: rgba(170,30,20,.9); border-style: solid; }
.cancel[hidden] { display: none; }
.jutsu.nochakra { border-color: #3d8be2; opacity: .6; }
.jutsu-0 { right: 0; bottom: 0; width: 86px; height: 86px; font-size: 13px; }
.jutsu-1 { right: 96px; bottom: 0; }
.jutsu-2 { right: 74px; bottom: 74px; }
.jutsu-3 { right: 0; bottom: 98px; }
.jutsu-4 { right: 130px; bottom: 84px; }
@media (hover: none) { .jutsu kbd { display: none; } }

.toast { position: fixed; left: 50%; top: 18%; transform: translateX(-50%); margin: 0; background: rgba(27,22,19,.92);
  border: 1px solid var(--line); border-radius: 10px; padding: 8px 14px; font-weight: 600; pointer-events: none; max-width: 90vw; text-align: center; }
.dead { position: fixed; inset: 0; margin: 0; display: grid; place-items: center; background: rgba(60,0,0,.45);
  font: 700 28px system-ui, sans-serif; color: #ffd0c8; text-shadow: 0 2px 6px #000; pointer-events: none; }
.dead[hidden], .toast[hidden] { display: none; }
#pos { bottom: max(8px, env(safe-area-inset-bottom)); left: 50%; right: auto; transform: translateX(-50%); }

/* ---------- Account and characters ---------- */
.panel[hidden], #characters[hidden] { display: none; }
.hint a { color: var(--accent); }
.char-list { display: grid; gap: 8px; margin-bottom: 14px; }
.char-list:empty { display: none; }
.char { display: flex; align-items: center; gap: 10px; width: 100%; background: var(--panel-2); color: var(--text); border: 1px solid var(--line);
  border-radius: 10px; padding: 6px 10px; font: inherit; text-align: left; cursor: pointer; }
.char:hover, .char:focus-visible { border-color: var(--accent); outline: none; }
.char canvas { width: 48px; height: 48px; image-rendering: pixelated; }
.char b { display: block; }
.char span { color: var(--muted); font-size: 13px; }
.create { border-top: 1px solid var(--line); padding-top: 4px; }

/* ---------- Equipment ---------- */
.top-buttons { position: fixed; right: max(12px, env(safe-area-inset-right)); top: max(8px, env(safe-area-inset-top)); display: flex; gap: 6px; }
.top-buttons button { width: 46px; height: 46px; border-radius: 12px; border: 1px solid var(--line); background: rgba(27,22,19,.9);
  color: var(--text); font-size: 22px; cursor: pointer; }
.secondary { width: 100%; margin-top: 8px; background: var(--panel-2); color: var(--text); border: 1px solid var(--line); border-radius: 10px;
  padding: 10px; font: inherit; font-weight: 700; cursor: pointer; }
.secondary[hidden] { display: none; }
.tip { transform: none; pointer-events: none; z-index: 12; }
.tip .hint { margin: 0; font-size: 11px; }
.inv { position: fixed; z-index: 10; right: max(8px, env(safe-area-inset-right)); top: max(8px, env(safe-area-inset-top));
  width: min(360px, calc(100vw - 16px)); max-height: calc(100vh - 16px); overflow: auto; background: rgba(27,22,19,.97);
  border: 1px solid var(--line); border-radius: 14px; padding: 10px 12px 14px; }
.inv[hidden], .item-card[hidden] { display: none; }
.inv header { display: flex; justify-content: space-between; align-items: center; }
.inv h2 { margin: 0; font-size: 18px; }
.inv h3 { margin: 12px 0 6px; font-size: 14px; color: var(--muted); }
.x { background: none; border: 0; color: var(--muted); font-size: 26px; line-height: 1; cursor: pointer; }
.equip { display: grid; grid-template-columns: repeat(3, 64px); grid-template-rows: repeat(4, 64px); gap: 6px; justify-content: center;
  grid-template-areas: ". head accessory" "weapon body ." ". legs ." ". feet ."; margin-top: 8px; padding: 8px 0;
  /* a faint figure behind the slots: each piece sits where it is worn */
  background: radial-gradient(ellipse 34px 30px at 50% 11%, rgba(255,255,255,.06) 98%, transparent),
    radial-gradient(ellipse 46px 70px at 50% 38%, rgba(255,255,255,.05) 98%, transparent),
    radial-gradient(ellipse 36px 70px at 50% 72%, rgba(255,255,255,.04) 98%, transparent); }
.equip .slot-head { grid-area: head; } .equip .slot-body { grid-area: body; } .equip .slot-legs { grid-area: legs; }
.equip .slot-feet { grid-area: feet; } .equip .slot-weapon { grid-area: weapon; } .equip .slot-accessory { grid-area: accessory; }
.bag { display: grid; grid-template-columns: repeat(5, 1fr); gap: 6px; }
.slot { position: relative; aspect-ratio: 1; display: grid; place-items: center; background: #0f0c0a; border: 2px solid #3a2e27;
  border-radius: 8px; cursor: pointer; padding: 0; }
.slot img { width: 80%; height: 80%; object-fit: contain; image-rendering: pixelated; }
.slot .slot-name { position: absolute; bottom: 2px; left: 0; right: 0; text-align: center; font-size: 10px; color: var(--muted); pointer-events: none; }
.slot.r0 { border-color: #8d877f; } .slot.r1 { border-color: #4fd16a; } .slot.r2 { border-color: #b874ff; box-shadow: 0 0 8px rgba(184,116,255,.45); }
.slot.r3 { border-color: #ff9a2e; box-shadow: 0 0 10px rgba(255,154,46,.6); }
.slot.unusable img { opacity: .45; }
.gear { margin: 8px 0 0; color: var(--muted); font-size: 12px; line-height: 1.5; }
.item-card { position: fixed; z-index: 11; left: 50%; top: 50%; transform: translate(-50%, -50%); width: min(320px, calc(100vw - 24px));
  background: rgba(20,16,13,.98); border: 2px solid var(--line); border-radius: 12px; padding: 12px 14px; }
.item-card h3 { margin: 0 0 2px; font-size: 16px; }
.item-card .sub { margin: 0 0 8px; color: var(--muted); font-size: 12px; }
.item-card ul { margin: 0 0 10px; padding-left: 18px; font-size: 14px; }
.item-card .req.bad { color: #ff7b6b; }
.item-card .cmp { color: var(--muted); font-size: 12px; margin: -4px 0 10px; }
.item-card .actions { display: flex; gap: 8px; }
.item-card .actions button { flex: 1; padding: 9px; border-radius: 8px; border: 1px solid var(--line); background: var(--panel-2); color: var(--text); font: inherit; font-weight: 700; cursor: pointer; }
.item-card .actions .main-action { background: var(--accent); color: #1a0f08; border-color: var(--accent); }
.jutsu.locked { filter: grayscale(1); opacity: .55; }
.jutsu.locked .jn::after { content: attr(data-lock); display: block; font-size: 10px; font-weight: 600; color: #ffb27a; }

/* ---------- Modes ---------- */
.mode-list { display: grid; gap: 8px; margin-top: 8px; }
.mode { --aura: var(--accent); display: flex; gap: 10px; align-items: center; background: var(--panel-2); border: 1px solid var(--line);
  border-left: 4px solid var(--aura); border-radius: 10px; padding: 8px 10px; }
.mode b { display: block; }
.mode p { margin: 2px 0; font-size: 12px; color: var(--muted); }
.mode span { font-size: 11px; color: var(--muted); }
.mode button { margin-left: auto; flex: none; padding: 8px 10px; border-radius: 8px; border: 1px solid var(--aura); background: transparent;
  color: var(--text); font: inherit; font-weight: 700; cursor: pointer; }
.mode button:disabled { opacity: .5; cursor: default; }
.mode.active { box-shadow: 0 0 0 1px var(--aura) inset, 0 0 14px color-mix(in srgb, var(--aura) 40%, transparent); }
.mode.active button { background: var(--aura); color: #120e0c; }
.mode.locked { opacity: .6; }

/* ---------- Chat, party, invitations, duels ---------- */
.chat { position: fixed; left: max(8px, env(safe-area-inset-left)); bottom: max(34px, calc(env(safe-area-inset-bottom) + 30px));
  width: min(380px, calc(100vw - 230px)); min-width: 220px; pointer-events: none; }
.chat-log { max-height: 30vh; overflow: hidden; display: flex; flex-direction: column; justify-content: flex-end; }
.chat-line { margin: 1px 0; font: 600 13px/1.35 system-ui, sans-serif; text-shadow: 0 1px 2px #000, 0 0 3px #000; word-break: break-word;
  transition: opacity .3s; }
.chat-form { display: none; margin-top: 6px; pointer-events: auto; }
.chat.open .chat-log { overflow-y: auto; pointer-events: auto; background: rgba(15,12,10,.7); border-radius: 8px; padding: 4px 6px; max-height: 38vh; }
.chat.open .chat-form { display: block; }
.chat-tabs { display: flex; gap: 4px; margin-bottom: 4px; }
.chat-tabs button { flex: 1; padding: 5px; border-radius: 6px; border: 1px solid var(--line); background: rgba(27,22,19,.92); color: var(--muted); font: 600 12px system-ui; cursor: pointer; }
.chat-tabs button[aria-pressed="true"] { color: #1a0f08; background: var(--accent); border-color: var(--accent); }
.chat-form input { width: 100%; padding: 9px 10px; border-radius: 8px; border: 1px solid var(--line); background: rgba(15,12,10,.95); color: var(--text); font: inherit; }
.party { display: grid; gap: 4px; margin-top: 6px; pointer-events: auto; }
.party[hidden] { display: none; }
.party-member { position: relative; background: rgba(0,0,0,.55); border-radius: 5px; overflow: hidden; height: 18px; }
.party-member span { position: relative; z-index: 1; display: block; padding: 0 6px; font: 600 11px/18px system-ui; text-shadow: 0 1px 2px #000; }
.party-member i { position: absolute; inset: 0 auto 0 0; background: linear-gradient(#3fae3f, #2a7a2a); transition: width .3s; }
.party button { justify-self: start; padding: 3px 8px; border-radius: 6px; border: 1px solid var(--line); background: rgba(27,22,19,.9); color: var(--muted); font: 600 11px system-ui; cursor: pointer; }
.duel-banner { position: fixed; left: 50%; top: max(60px, calc(env(safe-area-inset-top) + 56px)); transform: translateX(-50%); margin: 0;
  padding: 6px 14px; border-radius: 10px; background: rgba(120,20,15,.9); border: 1px solid #ff6a4a; font-weight: 800; pointer-events: none; }
.duel-banner[hidden], .invite[hidden], .pmenu[hidden], .profile[hidden] { display: none; }
.invite { position: fixed; z-index: 13; left: 50%; bottom: max(150px, 22vh); transform: translateX(-50%); width: min(320px, calc(100vw - 24px));
  background: rgba(20,16,13,.97); border: 2px solid var(--accent); border-radius: 12px; padding: 10px 12px; display: flex; flex-wrap: wrap; gap: 8px; }
.invite p { flex-basis: 100%; margin: 0 0 4px; font-weight: 700; }
.invite button, .pmenu button, .profile button { flex: 1; padding: 9px; border-radius: 8px; border: 1px solid var(--line); background: var(--panel-2);
  color: var(--text); font: inherit; font-weight: 700; cursor: pointer; }
.invite .main-action { background: var(--accent); color: #1a0f08; border-color: var(--accent); }
.pmenu { position: fixed; z-index: 13; left: 50%; top: 50%; transform: translate(-50%, -50%); width: min(260px, calc(100vw - 24px));
  background: rgba(20,16,13,.97); border: 1px solid var(--line); border-radius: 12px; padding: 10px 12px; display: grid; gap: 6px; }
.pmenu h3 { margin: 0 0 4px; }
.profile-gear { display: grid; grid-template-columns: repeat(6, 1fr); gap: 6px; margin: 4px 0 10px; color: var(--muted); font-size: 13px; }

/* ---------- Jutsu book ---------- */
.book-bar { display: flex; gap: 6px; flex-wrap: wrap; }
.bar-slot { flex: 1 1 70px; min-height: 44px; padding: 6px; border-radius: 10px; border: 2px solid var(--line); background: #0f0c0a; color: var(--text);
  font: 700 12px/1.2 system-ui; display: grid; place-items: center; text-align: center; cursor: pointer; }
.bar-slot.fixed { color: var(--muted); border-style: dashed; cursor: default; }
.bar-slot.picked, .book-jutsu.picked { border-color: var(--accent); box-shadow: 0 0 0 2px rgba(240,122,34,.4); }
.book-list { display: grid; gap: 6px; }
.book-jutsu { background: var(--panel-2); border: 2px solid var(--line); border-radius: 10px; padding: 6px 10px; cursor: pointer; }
.book-jutsu b { display: block; font-size: 14px; }
.book-jutsu p { margin: 2px 0 0; font-size: 12px; color: var(--muted); }
.book-jutsu.equipped { border-left: 4px solid var(--accent); }
.book-jutsu.locked { opacity: .5; cursor: default; }

/* ---------- Trials ---------- */
.trial-banner { position: fixed; left: 50%; top: max(60px, calc(env(safe-area-inset-top) + 56px)); transform: translateX(-50%);
  display: flex; gap: 10px; align-items: center; padding: 6px 8px 6px 14px; border-radius: 10px; background: rgba(60,40,10,.92);
  border: 1px solid #ffd23a; font-weight: 800; }
.trial-banner[hidden], .trial-offer[hidden] { display: none; }
.trial-banner button { padding: 5px 10px; border-radius: 8px; border: 1px solid var(--line); background: var(--panel-2); color: var(--text); font: 600 12px system-ui; cursor: pointer; }
.trial-offer { width: min(360px, calc(100vw - 24px)); max-height: 80vh; overflow: auto; }
.trial-row { background: var(--panel-2); border-radius: 10px; padding: 8px 10px; display: grid; gap: 6px; }
.trial-row p { margin: 0; font-size: 13px; color: var(--muted); }
.trial-row .why { color: #ffb27a; }
.trial-offer .main-action { background: var(--accent); color: #1a0f08; border-color: var(--accent); }

/* ---------- Economy ---------- */
.ryo { color: #ffd23a; }
.pills { position: fixed; right: max(218px, calc(env(safe-area-inset-right) + 218px)); bottom: max(40px, calc(env(safe-area-inset-bottom) + 28px));
  display: grid; gap: 6px; }
.pills { grid-template-columns: repeat(2, 48px); }
.pills button { width: 48px; height: 48px; border-radius: 50%; border: 2px solid rgba(255,255,255,.3); background: rgba(27,22,19,.92);
  font-size: 20px; position: relative; cursor: pointer; touch-action: none; }
.pills b { position: absolute; right: -2px; bottom: -2px; min-width: 18px; padding: 0 3px; border-radius: 9px; background: #1a120d;
  color: var(--text); font: 700 11px/18px system-ui; }
.inv header span { display: flex; gap: 6px; align-items: center; }
.small { padding: 4px 8px; border-radius: 6px; border: 1px solid var(--line); background: var(--panel-2); color: var(--text); font: 600 12px system-ui; cursor: pointer; }
.slot .lock { position: absolute; top: 1px; right: 2px; font-size: 10px; }
.npc[hidden] { display: none; }
.npc-body { display: grid; gap: 6px; margin-top: 8px; }
.npc-row { display: flex; gap: 8px; align-items: center; background: var(--panel-2); border-radius: 8px; padding: 6px 8px; }
.npc-row .item-name { flex: 1; font-size: 13px; font-weight: 700; }
.npc-row .price { color: #ffd23a; font-size: 12px; white-space: nowrap; }
.npc-row button, .npc-body > button { padding: 6px 10px; border-radius: 8px; border: 1px solid var(--line); background: #0f0c0a; color: var(--text);
  font: 700 12px system-ui; cursor: pointer; }
.npc-row button:disabled { opacity: .45; cursor: default; }
.npc-body .main-action { background: var(--accent); color: #1a0f08; border-color: var(--accent); }
.npc-body .wide { width: 100%; padding: 10px; }
.mini-icon { width: 28px; height: 28px; object-fit: contain; image-rendering: pixelated; }
.big-icon { font-size: 22px; }
.rank-badge { min-width: 24px; text-align: center; padding: 2px 6px; border-radius: 6px; background: var(--accent); color: #1a0f08; font-weight: 800; }
.npc h3 { margin: 8px 0 2px; font-size: 13px; color: var(--muted); }

.pills .empty { opacity: .45; }
.pills .active { border-color: #7ee07e; box-shadow: 0 0 10px rgba(126,224,126,.6); }
.pet-pick { display: flex; flex-wrap: wrap; gap: 6px; }
.pet-pick button { padding: 6px 10px; border-radius: 8px; border: 1px solid var(--line); background: var(--panel-2); color: var(--text); font: 600 12px system-ui; cursor: pointer; }
.pet-pick button[aria-pressed="true"] { background: var(--accent); color: #1a0f08; border-color: var(--accent); }

/* ---------- Boss bar ---------- */
.boss-bar { position: fixed; left: 50%; top: max(104px, calc(env(safe-area-inset-top) + 100px)); transform: translateX(-50%); width: min(420px, 70vw);
  text-align: center; pointer-events: none; }
.boss-bar[hidden] { display: none; }
.boss-bar span { font: 800 14px system-ui; text-shadow: 0 1px 3px #000; color: #ffb4a8; }
.boss-bar div { margin-top: 3px; height: 12px; border-radius: 6px; background: rgba(0,0,0,.7); border: 1px solid #7a1a12; overflow: hidden; }
.boss-bar i { display: block; height: 100%; background: linear-gradient(#e2483c, #8f1a10); transition: width .25s; }

/* ---------- Loot bags ---------- */
.lootbag { left: 50%; right: auto; top: auto; bottom: max(150px, 20vh); transform: translateX(-50%); width: min(400px, calc(100vw - 16px));
  max-height: 60vh; }
.lootbag[hidden] { display: none; }
.bag-item { display: flex; gap: 10px; align-items: center; margin-top: 8px; padding: 8px; background: var(--panel-2); border: 1px solid; border-left-width: 4px; border-radius: 10px; }
.bag-item img { width: 40px; height: 40px; object-fit: contain; image-rendering: pixelated; flex: none; }
.bag-item > div { flex: 1; min-width: 0; }
.bag-item b { font-size: 14px; }
.bag-item p { margin: 2px 0 0; font-size: 12px; }
.bag-item .sub { color: var(--muted); }
.bag-item .sub.bad { color: #ff7b6b; }
.bag-item .lines { color: var(--text); }
.bag-item .cmp { color: var(--muted); }
.lootbag button.main-action { padding: 8px 12px; border-radius: 8px; border: 0; background: var(--accent); color: #1a0f08; font: 700 13px system-ui; cursor: pointer; }
.lootbag .wide { width: 100%; margin-top: 10px; padding: 10px; }

/* ---------- Phone held upright ---------- */
@media (orientation: portrait) and (max-width: 700px) {
  /* menu buttons in a column on the right edge, so the bars get the whole top */
  .top-buttons { flex-direction: column; gap: 6px; top: max(8px, env(safe-area-inset-top)); right: max(8px, env(safe-area-inset-right)); }
  .top-buttons button { width: 42px; height: 42px; font-size: 20px; border-radius: 10px; }
  .bars { width: calc(100vw - 72px); }
  .bar { height: 15px; }
  .bar span { line-height: 15px; }
  /* consumables in a row at the bottom left, jutsus at the bottom right */
  .pills { left: max(8px, env(safe-area-inset-left)); right: auto; bottom: max(16px, calc(env(safe-area-inset-bottom) + 12px));
    grid-template-columns: repeat(4, 42px); gap: 5px; }
  .pills button { width: 42px; height: 42px; font-size: 18px; }
  .jutsus { right: max(8px, env(safe-area-inset-right)); bottom: max(16px, calc(env(safe-area-inset-bottom) + 12px)); }
  /* the chat sits above the consumables and leaves room for the jutsus */
  .chat { bottom: max(70px, calc(env(safe-area-inset-bottom) + 66px)); width: calc(100vw - 230px); min-width: 150px; }
  .chat.open { width: calc(100vw - 16px); bottom: max(250px, calc(env(safe-area-inset-bottom) + 246px)); z-index: 14; }
  .chat-line { font-size: 12px; }
  /* coordinates are for testing; on a phone they only get in the way */
  #pos { display: none; }
  .duel-banner, .trial-banner { top: auto; bottom: max(260px, 32vh); }
  .boss-bar { top: max(76px, calc(env(safe-area-inset-top) + 72px)); width: calc(100vw - 80px); left: 8px; transform: none; }
  .party { max-width: calc(100vw - 72px); }
}

/* ---------- Minimap and world map ---------- */
.minimap { position: fixed; right: max(12px, env(safe-area-inset-right)); top: calc(max(8px, env(safe-area-inset-top)) + 54px);
  width: 150px; height: 150px; border-radius: 12px; border: 2px solid var(--line); background: #0c0a09; cursor: pointer; }
#hud[hidden] .minimap { display: none; }
.worldmap { position: fixed; inset: 0; z-index: 20; background: #0c0a09; }
.worldmap[hidden] { display: none; }
.worldmap canvas { position: absolute; inset: 0; width: 100%; height: 100%; touch-action: none; cursor: grab; }
.wm-tools { position: absolute; top: max(8px, env(safe-area-inset-top)); right: max(8px, env(safe-area-inset-right)); display: flex; gap: 6px; align-items: center; }
.wm-tools button, .wm-tools span { background: rgba(27,22,19,.92); color: var(--text); border: 1px solid var(--line); border-radius: 8px; padding: 6px 10px; font: 600 13px system-ui; }
.wm-tools button { cursor: pointer; }
.wm-tools button[hidden] { display: none; }
.wm-list { position: absolute; left: max(8px, env(safe-area-inset-left)); top: max(8px, env(safe-area-inset-top)); bottom: 8px; width: min(280px, 46vw);
  overflow: auto; background: rgba(20,16,13,.9); border: 1px solid var(--line); border-radius: 12px; padding: 6px 8px; }
.wm-list h3 { margin: 8px 2px 4px; font-size: 12px; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; }
.wm-list button { display: grid; grid-template-columns: 26px 1fr; text-align: left; width: 100%; padding: 6px; margin-bottom: 4px; border-radius: 8px;
  border: 1px solid var(--line); background: var(--panel-2); color: var(--text); cursor: pointer; }
.wm-list button span { grid-row: span 2; font-size: 18px; align-self: center; }
.wm-list button b { font-size: 13px; }
.wm-list button small { color: var(--muted); font-size: 11px; }
.wm-hint { position: absolute; left: 50%; bottom: max(10px, env(safe-area-inset-bottom)); transform: translateX(-50%); margin: 0;
  background: rgba(27,22,19,.9); padding: 6px 12px; border-radius: 8px; color: var(--muted); font-size: 12px; pointer-events: none; }
@media (orientation: portrait) and (max-width: 700px) {
  .minimap { right: auto; left: max(8px, env(safe-area-inset-left)); top: calc(max(8px, env(safe-area-inset-top)) + 80px); width: 110px; height: 110px; }
  .wm-list { top: auto; bottom: 46px; width: auto; right: 8px; height: 34vh; }
  .wm-hint { display: none; }
}

/* ---------- Continue playing ---------- */
.char-continue { display: grid; grid-template-columns: 96px 1fr; gap: 6px 12px; align-items: center; padding: 10px;
  background: var(--panel-2); border: 1px solid var(--accent); border-radius: 12px; margin-bottom: 12px; }
.char-continue[hidden], .create[hidden], #create-toggle[hidden], #others-title[hidden], #resume-btn[hidden] { display: none; }
.char-continue canvas { width: 96px; height: 96px; image-rendering: pixelated; grid-row: span 2; }
.char-continue b { font-size: 20px; display: block; }
.char-continue span { color: var(--muted); font-size: 13px; }
.char-continue .primary { margin: 0; grid-column: 2; }
.link { display: block; margin: 12px auto 0; background: none; border: 0; color: var(--muted); text-decoration: underline; font: inherit; font-size: 13px; cursor: pointer; }
.reconnecting { position: fixed; z-index: 30; left: 50%; top: 40%; transform: translateX(-50%); margin: 0; padding: 10px 18px; border-radius: 12px;
  background: rgba(20,16,13,.95); border: 1px solid var(--accent); font-weight: 700; }
.reconnecting[hidden] { display: none; }

/* ---------- Training ---------- */
.learn-offer { position: fixed; z-index: 9; left: 50%; bottom: max(150px, calc(env(safe-area-inset-bottom) + 150px)); transform: translateX(-50%);
  width: min(360px, calc(100vw - 32px)); background: rgba(27,22,19,.97); border: 2px solid var(--accent); border-radius: 14px; padding: 10px 12px; }
.learn-offer[hidden] { display: none; }
.learn-offer h3 { margin: 0 0 8px; font-size: 15px; color: var(--accent); }
.learn-row { display: flex; gap: 8px; align-items: center; justify-content: space-between; margin-bottom: 6px; }
.learn-row b { font-size: 14px; }
.learn-offer .main-action, .book-jutsu .main-action { padding: 8px 12px; border-radius: 8px; border: 1px solid var(--accent); background: var(--accent);
  color: #1a0f08; font: inherit; font-weight: 700; cursor: pointer; white-space: nowrap; }
.book-jutsu.learnable { border-left: 4px solid #ffd23a; }
.book-jutsu .main-action { margin-top: 6px; }
.cc-box p { margin: 0 0 4px; font-size: 13px; color: var(--muted); }
.cc-box .secondary:disabled { opacity: .6; cursor: default; }
.train { position: fixed; inset: 0; z-index: 20; display: grid; place-items: center; background: rgba(0,0,0,.55); }
.train-card { background: rgba(27,22,19,.98); border: 1px solid var(--line); border-radius: 14px; padding: 10px 12px 12px; max-width: calc(100vw - 16px); }
.train-card header { display: flex; justify-content: space-between; align-items: center; gap: 12px; margin-bottom: 8px; }
.train-card h2 { margin: 0; font-size: 17px; }
.train-card canvas { display: block; border-radius: 10px; touch-action: none; user-select: none; -webkit-user-select: none; }
.train-hint { margin: 8px 0 0; font-size: 12px; color: var(--muted); max-width: 560px; }
