:root {
  --bg: #1a1410;
  --panel: rgba(24, 17, 12, 0.93);
  --panel-2: rgba(48, 34, 22, 0.9);
  --line: rgba(224, 179, 90, 0.35);
  --gold: #e0b35a;
  --gold-2: #f6d98f;
  --text: #f1e6d0;
  --muted: #b5a48a;
  --red: #c23b2b;
  --green: #4caf6a;
  --blue: #4a8fe0;
  --common: #c9c3b8;
  --rare: #4a9fff;
  --epic: #b46cff;
  --legendary: #ff9a2e;
  --font: 'Kurale', Georgia, 'Times New Roman', serif;
  --title: 'Ruslan Display', 'Kurale', Georgia, serif;
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; overflow: hidden; background: var(--bg); color: var(--text); font-family: var(--font); user-select: none; -webkit-user-select: none; touch-action: none; overscroll-behavior: none; }
canvas#c { position: fixed; inset: 0; width: 100%; height: 100%; display: block; }
.hidden { display: none !important; }
button { font-family: inherit; color: inherit; cursor: pointer; }
input { font-family: inherit; }

/* ---------- Кнопки ---------- */
.btn {
  display: block; width: 100%; padding: 12px 16px; margin: 6px 0;
  background: linear-gradient(180deg, #4a3422, #2c1e14); border: 1px solid var(--line); border-radius: 8px;
  font-size: 17px; letter-spacing: .3px; text-align: center; box-shadow: inset 0 1px 0 rgba(255,255,255,.08), 0 3px 10px rgba(0,0,0,.4);
  transition: transform .08s, filter .15s;
}
.btn:active { transform: scale(.97); filter: brightness(1.2); }
.btn.primary { background: linear-gradient(180deg, #c8892d, #8a4f16); border-color: var(--gold-2); color: #fff8e6; text-shadow: 0 1px 2px rgba(0,0,0,.6); }
.btn.big { font-size: 22px; padding: 16px; }
.btn.small { padding: 8px 12px; font-size: 14px; width: auto; display: inline-block; }
.btn.danger { background: linear-gradient(180deg, #7a2418, #4a140c); }
.btn:disabled { opacity: .45; }

/* ---------- Экраны ---------- */
.screen { position: fixed; z-index: 10; }
#menu { inset: 0; pointer-events: none; }
#menu > * { pointer-events: auto; }
.topbar { position: absolute; top: max(12px, env(safe-area-inset-top)); left: max(14px, env(safe-area-inset-left)); right: max(14px, env(safe-area-inset-right)); display: flex; justify-content: space-between; align-items: flex-start; gap: 12px; pointer-events: none; }
.topbar > * { pointer-events: auto; }
.hero-card { background: var(--panel); border: 1px solid var(--line); border-radius: 10px; padding: 10px 14px; min-width: 210px; }
.hero-name { font-size: 20px; color: var(--gold-2); }
.hero-sub { font-size: 14px; color: var(--muted); margin: 2px 0 6px; }
.xpbar { position: relative; height: 14px; background: #120c08; border-radius: 7px; overflow: hidden; border: 1px solid rgba(0,0,0,.6); }
.xpbar > div { height: 100%; background: linear-gradient(90deg, #6b3fd0, #a77bff); width: 0; transition: width .4s; }
.xpbar span { position: absolute; inset: 0; font-size: 10px; line-height: 13px; text-align: center; color: #fff; text-shadow: 0 1px 1px #000; }
.gold { background: var(--panel); border: 1px solid var(--line); border-radius: 10px; padding: 8px 14px; font-size: 18px; color: var(--gold-2); }
.gold.small { font-size: 14px; padding: 3px 10px; margin-left: 8px; vertical-align: middle; }
.menu-side { position: absolute; right: max(24px, env(safe-area-inset-right)); top: 50%; transform: translateY(-46%); width: min(330px, 42vw); }
.logo { font-family: var(--title); font-weight: normal; font-size: clamp(30px, 6vw, 52px); line-height: 1; margin: 0 0 16px; text-align: center; color: var(--gold-2); text-shadow: 0 2px 0 #5a2a10, 0 0 24px rgba(255,140,40,.45), 0 4px 12px rgba(0,0,0,.8); }
.hint { font-size: 13px; color: var(--muted); text-align: center; margin-top: 8px; }
.hint.warn { color: var(--gold-2); }

.panel { right: 0; top: 0; bottom: 0; width: min(440px, 58vw); background: var(--panel); border-left: 1px solid var(--line); padding: max(16px, env(safe-area-inset-top)) max(18px, env(safe-area-inset-right)) 18px 18px; overflow-y: auto; touch-action: pan-y; box-shadow: -10px 0 40px rgba(0,0,0,.5); }
.panel h2 { font-family: var(--title); font-weight: normal; color: var(--gold-2); margin: 4px 0 14px; font-size: 26px; }
.close { position: absolute; top: max(12px, env(safe-area-inset-top)); right: 14px; width: 38px; height: 38px; border-radius: 50%; border: 1px solid var(--line); background: var(--panel-2); font-size: 18px; }
.label { color: var(--gold); font-size: 14px; margin: 14px 0 6px; text-transform: uppercase; letter-spacing: 1px; }
.field { display: block; color: var(--gold); font-size: 14px; }
.field input, .row input { display: block; width: 100%; margin-top: 6px; padding: 10px 12px; font-size: 18px; color: var(--text); background: #120c08; border: 1px solid var(--line); border-radius: 8px; user-select: text; -webkit-user-select: text; }
.race-grid { display: grid; grid-template-columns: repeat(5, 1fr); gap: 6px; }
.race { padding: 8px 2px; background: var(--panel-2); border: 1px solid transparent; border-radius: 8px; text-align: center; font-size: 12px; }
.race .ic { font-size: 22px; display: block; margin-bottom: 2px; }
.race.on { border-color: var(--gold); background: linear-gradient(180deg, #6a4524, #3a2616); box-shadow: 0 0 12px rgba(224,179,90,.35); }
.race-desc { font-size: 14px; color: var(--muted); margin: 8px 0 12px; min-height: 36px; }
.attrs .attr { display: flex; align-items: center; gap: 10px; padding: 8px 10px; background: var(--panel-2); border-radius: 8px; margin-bottom: 6px; }
.attr .nm { flex: 1; }
.attr .nm small { display: block; color: var(--muted); font-size: 12px; }
.attr .val { font-size: 20px; color: var(--gold-2); min-width: 28px; text-align: center; }
.attr button { width: 36px; height: 36px; border-radius: 50%; border: 1px solid var(--gold); background: #6a4524; font-size: 20px; line-height: 1; }
.attr button:disabled { opacity: .3; }
.stats { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; }
.stats div { background: var(--panel-2); border-radius: 6px; padding: 6px 10px; font-size: 14px; display: flex; justify-content: space-between; }
.stats b { color: var(--gold-2); font-weight: normal; }
.tabs { display: flex; gap: 6px; margin-bottom: 10px; }
.tabs button { flex: 1; padding: 9px; border-radius: 8px; border: 1px solid var(--line); background: var(--panel-2); font-size: 15px; }
.tabs button.on { background: linear-gradient(180deg, #6a4524, #3a2616); border-color: var(--gold); }
.item { display: flex; gap: 10px; align-items: center; padding: 10px; background: var(--panel-2); border-radius: 10px; margin-bottom: 8px; border-left: 4px solid var(--common); }
.item.rare { border-left-color: var(--rare); } .item.epic { border-left-color: var(--epic); } .item.legendary { border-left-color: var(--legendary); }
.item .info { flex: 1; min-width: 0; }
.item .nm { font-size: 16px; }
.item.rare .nm { color: #8cc2ff; } .item.epic .nm { color: #cfa2ff; } .item.legendary .nm { color: #ffbe6e; }
.item .desc { font-size: 12px; color: var(--muted); margin-top: 2px; }
.item .act-btn { padding: 8px 12px; border-radius: 8px; border: 1px solid var(--line); background: #3a2616; font-size: 14px; white-space: nowrap; }
.item .act-btn.buy { background: linear-gradient(180deg, #c8892d, #8a4f16); border-color: var(--gold-2); }
.item .act-btn.eq { background: #2a4a2a; border-color: #5c9a5c; }
.item .act-btn:disabled { opacity: .5; }
.row { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin: 12px 0; }
.row input { width: 55%; margin: 0; }
.seg { display: flex; border: 1px solid var(--line); border-radius: 8px; overflow: hidden; }
.seg button { padding: 8px 14px; background: var(--panel-2); border: 0; font-size: 14px; }
.seg button.on { background: #8a4f16; color: #fff; }

/* ---------- HUD ---------- */
#hud { position: fixed; inset: 0; z-index: 5; pointer-events: none; }
#hud button, #hud .botctl { pointer-events: auto; }
.hud-tl { position: absolute; top: max(10px, env(safe-area-inset-top)); left: max(10px, env(safe-area-inset-left)); display: flex; gap: 10px; align-items: flex-start; }
.iconbtn { width: 38px; height: 38px; border-radius: 50%; border: 1px solid var(--line); background: var(--panel); font-size: 16px; }
.selfbars { width: min(260px, 34vw); }
.selfname { font-size: 14px; color: var(--gold-2); text-shadow: 0 1px 2px #000; margin-bottom: 3px; }
.bar { position: relative; height: 16px; background: rgba(10,6,4,.8); border: 1px solid rgba(0,0,0,.7); border-radius: 4px; overflow: hidden; margin-bottom: 4px; }
.bar > div { height: 100%; transition: width .15s; }
.bar.hp > div { background: linear-gradient(180deg, #e0503a, #8e1f12); }
.bar.st { height: 7px; }
.bar.st > div { background: linear-gradient(180deg, #f2d06a, #b08a20); }
.bar span { position: absolute; inset: 0; font-size: 11px; text-align: center; line-height: 15px; text-shadow: 0 1px 1px #000; }
.hud-top { position: absolute; top: max(8px, env(safe-area-inset-top)); left: 50%; transform: translateX(-50%); text-align: center; }
#timer { font-size: 26px; color: var(--gold-2); text-shadow: 0 2px 4px #000; font-variant-numeric: tabular-nums; }
#myScore { font-size: 14px; text-shadow: 0 1px 2px #000; }
.hud-tr { position: absolute; top: max(10px, env(safe-area-inset-top)); right: max(10px, env(safe-area-inset-right)); width: min(220px, 30vw); display: flex; flex-direction: column; align-items: flex-end; gap: 6px; }
#board { background: rgba(20,14,10,.6); border-radius: 8px; padding: 6px 10px; font-size: 12px; width: 100%; }
#board .r { display: flex; justify-content: space-between; gap: 6px; }
#board .r.me { color: var(--gold-2); }
#board .r span:first-child { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.botctl { display: flex; gap: 4px; }
.botctl button { padding: 4px 9px; font-size: 12px; border-radius: 6px; border: 1px solid var(--line); background: var(--panel); }
#feed { font-size: 12px; text-align: right; }
#feed div { background: rgba(20,14,10,.65); padding: 3px 8px; border-radius: 5px; margin-bottom: 3px; animation: fadein .2s; }
#feed .k { color: #ff9a7a; } #feed .me { color: var(--gold-2); }
@keyframes fadein { from { opacity: 0; transform: translateX(20px); } }

#joyBase { position: absolute; width: 130px; height: 130px; margin: -65px 0 0 -65px; border-radius: 50%; background: radial-gradient(circle, rgba(255,255,255,.06), rgba(255,255,255,.12)); border: 2px solid rgba(255,255,255,.25); display: none; }
#joyKnob { position: absolute; left: 50%; top: 50%; width: 56px; height: 56px; margin: -28px 0 0 -28px; border-radius: 50%; background: radial-gradient(circle at 35% 35%, rgba(255,240,200,.75), rgba(200,140,60,.55)); box-shadow: 0 2px 10px rgba(0,0,0,.5); }
.actions { position: absolute; right: max(20px, env(safe-area-inset-right)); bottom: max(20px, env(safe-area-inset-bottom)); width: 230px; height: 210px; }
.act { position: absolute; border-radius: 50%; border: 2px solid rgba(255,230,180,.45); background: radial-gradient(circle at 40% 35%, rgba(110,70,40,.85), rgba(40,24,14,.85)); font-size: 26px; display: flex; align-items: center; justify-content: center; box-shadow: 0 4px 14px rgba(0,0,0,.5); touch-action: none; overflow: hidden; }
.act.pressed { filter: brightness(1.5); transform: scale(.93); }
.act.attack { width: 96px; height: 96px; right: 0; bottom: 0; font-size: 40px; background: radial-gradient(circle at 40% 35%, rgba(200,80,50,.9), rgba(100,25,15,.9)); }
.act.skill { width: 66px; height: 66px; right: 108px; bottom: 8px; background: radial-gradient(circle at 40% 35%, rgba(90,110,200,.9), rgba(30,35,90,.9)); }
.act.dodge { width: 60px; height: 60px; right: 96px; bottom: 92px; }
.act.block { width: 60px; height: 60px; right: 18px; bottom: 112px; }
.act .cd { position: absolute; inset: 0; border-radius: 50%; background: conic-gradient(rgba(0,0,0,.7) var(--p, 0%), transparent 0); pointer-events: none; }
#skillName { position: absolute; right: max(20px, env(safe-area-inset-right)); bottom: calc(max(20px, env(safe-area-inset-bottom)) + 216px); font-size: 12px; color: var(--muted); text-shadow: 0 1px 2px #000; }
#death { position: absolute; inset: 0; display: flex; flex-direction: column; align-items: center; justify-content: center; background: radial-gradient(circle, rgba(80,0,0,.25), rgba(40,0,0,.6)); }
#death .big { font-family: var(--title); font-size: 48px; color: #ff7a5a; text-shadow: 0 3px 8px #000; }
#death #deathText { font-size: 18px; margin-top: 6px; }
#connecting { position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; font-size: 22px; background: rgba(0,0,0,.6); pointer-events: auto; }

#labels, #ftexts { position: fixed; inset: 0; pointer-events: none; z-index: 4; overflow: hidden; }
.plate { position: absolute; left: 0; top: 0; text-align: center; transform-origin: center bottom; white-space: nowrap; will-change: transform; }
.plate .n { font-size: 12px; text-shadow: 0 1px 2px #000, 0 0 3px #000; }
.plate .n i { font-style: normal; color: var(--gold); }
.plate .hb { width: 64px; height: 6px; margin: 2px auto 0; background: rgba(0,0,0,.7); border-radius: 3px; overflow: hidden; border: 1px solid rgba(0,0,0,.8); }
.plate .hb div { height: 100%; background: #e04a32; }
.plate.me .hb div { background: #4caf6a; }
.ftext { position: absolute; left: 0; top: 0; font-size: 20px; font-weight: bold; color: #fff; text-shadow: 0 2px 3px #000, 0 0 2px #000; will-change: transform; }
.ftext.crit { color: #ffcf40; font-size: 28px; }
.ftext.me { color: #ff5a4a; }
.ftext.block { color: #9fc7ff; font-size: 16px; }
.ftext.heal { color: #6aff8a; }

#results { position: fixed; inset: 0; z-index: 20; display: flex; align-items: center; justify-content: center; background: rgba(0,0,0,.55); }
.res-box { background: var(--panel); border: 1px solid var(--line); border-radius: 12px; padding: 18px 22px; width: min(460px, 92vw); max-height: 92vh; overflow: auto; text-align: center; }
.res-box h2 { font-family: var(--title); font-weight: normal; color: var(--gold-2); margin: 0 0 10px; }
#resTable { width: 100%; border-collapse: collapse; font-size: 14px; margin-bottom: 10px; }
#resTable td, #resTable th { padding: 5px 6px; border-bottom: 1px solid rgba(224,179,90,.15); }
#resTable th { color: var(--gold); font-weight: normal; }
#resTable tr.me td { color: var(--gold-2); }
#resRewards { font-size: 16px; color: #cfa2ff; margin: 6px 0; }
#resNext { font-size: 14px; color: var(--muted); margin-bottom: 8px; }

#rotate { position: fixed; inset: 0; z-index: 50; background: var(--bg); display: flex; flex-direction: column; align-items: center; justify-content: center; font-size: 20px; gap: 12px; text-align: center; padding: 20px; }
#rotate div { font-size: 64px; animation: spin 2s infinite ease-in-out; }
@keyframes spin { 50% { transform: rotate(90deg); } }

#toasts { position: fixed; left: 50%; top: 22%; transform: translateX(-50%); z-index: 30; pointer-events: none; display: flex; flex-direction: column; align-items: center; gap: 6px; }
.toast { background: var(--panel); border: 1px solid var(--gold); color: var(--gold-2); padding: 8px 16px; border-radius: 20px; font-size: 16px; animation: toast 2.6s forwards; white-space: nowrap; }
.toast.lvl { font-size: 24px; font-family: var(--title); padding: 12px 26px; background: linear-gradient(180deg, #6a3fd0, #3a1f80); border-color: #c9a8ff; color: #fff; }
@keyframes toast { 0% { opacity: 0; transform: translateY(10px) scale(.9); } 10% { opacity: 1; transform: none; } 80% { opacity: 1; } 100% { opacity: 0; transform: translateY(-14px); } }

/* Портретная ориентация меню: панель снизу */
@media (orientation: portrait) {
  .menu-side { right: 50%; transform: translateX(50%); top: auto; bottom: max(24px, env(safe-area-inset-bottom)); width: min(340px, 88vw); }
  .logo { font-size: 36px; margin-bottom: 8px; }
  .panel { left: 0; right: 0; top: auto; width: auto; height: 62vh; border-left: 0; border-top: 1px solid var(--line); border-radius: 16px 16px 0 0; }
  .race-grid { grid-template-columns: repeat(5, 1fr); }
}
@media (max-height: 430px) and (orientation: landscape) {
  .btn { padding: 9px 14px; margin: 4px 0; font-size: 15px; }
  .btn.big { font-size: 19px; padding: 12px; }
  .logo { font-size: 32px; margin-bottom: 8px; }
  .panel { padding-top: 10px; }
  .panel h2 { font-size: 22px; margin-bottom: 8px; }
  .label { margin: 8px 0 4px; }
}
