@font-face { font-family: 'PS2P'; src: url('../assets/fonts/PressStart2P-Regular.ttf') format('truetype'); font-display: block; }
@font-face { font-family: 'Nunito'; src: url('../assets/fonts/Nunito.ttf') format('truetype'); font-weight: 200 1000; font-display: swap; }
:root {
  --ink: #6b4a5e; --ink2: #8a6a5c; --cream: #f3eccf; --beige: #e8cfa6; --wood: #a8775a; --wood-d: #754c60;
  --green: #8db15d; --red: #c0636f; --gold: #c99a2c; --s: 3px;
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; overflow: hidden; background: #9bd4c3; overscroll-behavior: none; }
body { font-family: 'Nunito', system-ui, sans-serif; font-weight: 800; color: var(--ink); user-select: none; -webkit-user-select: none;
  cursor: url('../assets/ui/cursor.png') 2 2, auto; }
button, .card, canvas#field { cursor: url('../assets/ui/cursor-point.png') 4 1, pointer; }
#app { position: fixed; inset: 0; }
#field { position: absolute; inset: 0; width: 100%; height: 100%; image-rendering: pixelated; touch-action: none; }
.hidden { display: none !important; }
.muted { opacity: .75; }

/* ---- 9-slice из UI-пака ---- */
.panel { border-style: solid; border-width: 15px; border-image: url('../assets/ui/panel9.png') 5 fill / 15px stretch; image-rendering: pixelated; }
.panel-ui { border-style: solid; border-width: 15px; border-image: url('../assets/ui/big9.png') 6 fill / 15px stretch; image-rendering: pixelated; }
.btn { font-family: 'PS2P', monospace; font-size: 12px; color: var(--ink); background: none; border-style: solid; border-width: 12px 15px;
  border-image: url('../assets/ui/btn9.png') 5 6 6 6 fill / 12px 15px stretch; image-rendering: pixelated; padding: 2px 6px 4px; min-height: 44px;
  display: inline-flex; align-items: center; justify-content: center; gap: 6px; line-height: 1.3; }
.btn:active, .btn.down { border-image-source: url('../assets/ui/btn9-down.png'); transform: translateY(2px); }
.btn:disabled { opacity: .45; filter: grayscale(.6); }
.btn.sm { font-size: 10px; min-height: 38px; border-width: 10px 12px; padding: 0 4px 2px; }
.btn-go { color: #fff8e0; text-shadow: 0 2px 0 #754c60; filter: hue-rotate(-8deg) saturate(1.6) brightness(.95); font-size: 14px; }
.btn b { font-family: 'PS2P'; }

.ico { display: inline-block; width: 16px; height: 16px; background-image: url('../assets/ui/special.png'); image-rendering: pixelated; vertical-align: middle; flex: none; }
.ico.sm { width: 14px; height: 14px; }
.ico-coin { background-position: calc(-96px - 0px) -16px; }
.ico-heart { background-position: -48px -16px; }
.ico-star { background-position: 0 -16px; }
.ico.x2 { width: 32px; height: 32px; background-size: 224px 128px; }
.ico.x2.ico-coin { background-position: -192px -32px; } .ico.x2.ico-heart { background-position: -96px -32px; } .ico.x2.ico-star { background-position: 0 -32px; }
.ico.sm.ico-coin { background-size: 98px 56px; background-position: -84px -14px; }

/* ---- Верхний HUD ---- */
#hud-top { position: absolute; left: 0; right: 0; top: 0; padding: calc(env(safe-area-inset-top) + 8px) 10px 0; display: flex; justify-content: space-between; align-items: flex-start; gap: 8px; pointer-events: none; z-index: 5; }
#hud-top > * { pointer-events: auto; }
#hud-left { display: flex; gap: 8px; align-items: flex-start; }
.frame-wood { width: 64px; height: 64px; background: #e8cfa6; border: 4px solid #a8775a; outline: 3px solid #754c60; box-shadow: inset 0 0 0 3px #c49a6c; border-radius: 3px; display: flex; align-items: center; justify-content: center; }
#portrait canvas { width: 48px; height: 48px; image-rendering: pixelated; }
#hud-stats { display: flex; flex-direction: column; gap: 6px; }
.pill .ico { width: 24px; height: 24px; background-size: 168px 96px; }
.pill .ico-heart { background-position: -72px -24px; } .pill .ico-coin { background-position: -144px -24px; }
.pill { display: flex; align-items: center; gap: 6px; font-family: 'PS2P'; font-size: 12px; padding: 3px 4px; min-height: 30px;
  border-style: solid; border-width: 9px; border-image: url('../assets/ui/big9.png') 6 fill / 9px stretch; image-rendering: pixelated; }
.pill .bar { width: 92px; height: 12px; background: #754c60; border-radius: 3px; padding: 2px; }
#hp-fill { height: 100%; width: 100%; background: linear-gradient(#e78a96, #c0636f); border-radius: 2px; transition: width .3s; }
#income-text { font-size: 9px; }
#hud-right { min-width: 150px; max-width: 260px; font-size: 13px; padding: 0 2px; }
#year-line { font-family: 'PS2P'; font-size: 12px; color: var(--ink); margin-bottom: 4px; }
#enemy-line { font-size: 13px; line-height: 1.15; }
#enemy-line .crown { width: 16px; height: 12px; image-rendering: pixelated; vertical-align: -1px; margin-right: 3px; }
#enemy-units { display: flex; flex-wrap: wrap; gap: 2px 8px; margin-top: 3px; font-family: 'PS2P'; font-size: 9px; align-items: center; }
#enemy-units span { display: inline-flex; align-items: center; gap: 1px; }
#enemy-units canvas { width: 32px; height: 32px; image-rendering: pixelated; margin: -4px -2px -4px -4px; }

/* ---- Нижняя панель ---- */
#hotbar { position: absolute; left: 50%; transform: translateX(-50%); bottom: 0; width: min(100%, 720px); padding: 0 8px calc(env(safe-area-inset-bottom) + 8px); z-index: 5; }
#info-line { margin: 0 auto 6px; width: fit-content; max-width: 100%; text-align: center; font-size: 14px; line-height: 1.25; padding: 0 4px;
  border-style: solid; border-width: 10px; border-image: url('../assets/ui/big9.png') 6 fill / 10px stretch; image-rendering: pixelated; }
#hand { display: flex; gap: 6px; justify-content: center; padding: 8px; background: #a8775a; border: 3px solid #754c60; border-radius: 6px; box-shadow: inset 0 0 0 3px #c49a6c, 0 3px 0 rgba(0,0,0,.15); min-height: 120px; align-items: stretch; }
.card { flex: 1 1 0; max-width: 150px; min-width: 0; position: relative; display: flex; flex-direction: column; align-items: center; padding: 2px 2px 4px;
  border-style: solid; border-width: 12px; border-image: url('../assets/ui/slot9.png') 7 fill / 12px stretch; image-rendering: pixelated; transition: transform .12s; }
.card:hover { border-image-source: url('../assets/ui/slot9-hover.png'); }
.card.sel { transform: translateY(-8px); filter: drop-shadow(0 0 0 #fff) drop-shadow(0 3px 0 #754c60); outline: 3px solid #fff6c8; outline-offset: -3px; border-radius: 6px; }
.card.poor { opacity: .55; }
.card canvas { width: 48px; height: 48px; image-rendering: pixelated; margin-top: -4px; }
.card .nm { font-size: 13px; line-height: 1.05; text-align: center; min-height: 2.1em; display: flex; align-items: center; }
.card .cost { position: absolute; top: -10px; right: -10px; font-family: 'PS2P'; font-size: 11px; display: flex; align-items: center; gap: 1px; background: #fff3cf; border: 2px solid #754c60; border-radius: 10px; padding: 2px 4px 2px 2px; }
.card .kind { position: absolute; top: -9px; left: -9px; font-size: 10px; background: #754c60; color: #fff3cf; border-radius: 6px; padding: 1px 4px; }
.card.unit .kind { background: #c0636f; }
.hand-empty { align-self: center; color: #fff3cf; font-size: 14px; text-align: center; }
#actions { display: flex; gap: 8px; justify-content: center; margin-top: 8px; }
#actions .btn { flex: 1; max-width: 240px; }

/* ---- Битва ---- */
#battlebar { position: absolute; left: 0; right: 0; bottom: 0; display: flex; flex-direction: column; align-items: center; gap: 6px; padding: 0 8px calc(env(safe-area-inset-bottom) + 10px); z-index: 5; }
#battle-info { font-size: 14px; text-align: center; min-width: 200px; }
#battle-btns { display: flex; gap: 8px; }

/* ---- Советник ---- */
#advisor { position: absolute; left: 50%; transform: translateX(-50%); width: min(96%, 560px); display: flex; align-items: flex-end; gap: 4px; z-index: 20; }
#advisor-cv { width: 80px; height: 80px; image-rendering: pixelated; flex: none; }
#advisor-box { flex: 1; font-size: 15px; line-height: 1.3; display: flex; flex-direction: column; gap: 6px; align-items: flex-end;
  border-style: solid; border-width: 15px; border-image: url('../assets/ui/big9.png') 6 fill / 15px stretch; image-rendering: pixelated; padding: 0 2px; box-shadow: 0 4px 0 rgba(0,0,0,.08); }
#advisor-text { align-self: stretch; }

/* ---- Баннер ---- */
#banner { position: absolute; left: 0; right: 0; top: 34%; display: flex; justify-content: center; pointer-events: none; z-index: 15; }
#banner-inner { font-family: 'PS2P'; font-size: 18px; line-height: 1.5; text-align: center; color: #fff8e0; text-shadow: 0 3px 0 #754c60, 3px 0 0 #754c60, -3px 0 0 #754c60, 0 -3px 0 #754c60;
  animation: pop .35s ease-out; padding: 0 12px; }
#banner-inner small { display: block; font-family: 'Nunito'; font-weight: 900; font-size: 18px; margin-top: 6px; }
@keyframes pop { from { transform: scale(.6); opacity: 0; } to { transform: scale(1); opacity: 1; } }

/* ---- Модалки ---- */
#modal { position: absolute; inset: 0; background: rgba(60, 50, 80, .35); display: flex; align-items: center; justify-content: center; z-index: 30; padding: 12px; }
#modal-panel { width: min(100%, 520px); max-height: 100%; overflow-y: auto; padding: 4px 6px; font-size: 15px; line-height: 1.35; text-align: center; }
#modal-panel h1 { font-family: 'PS2P'; font-weight: normal; font-size: 22px; line-height: 1.4; margin: 6px 0 4px; color: #6b4a5e; text-shadow: 0 3px 0 #e8cfa6; }
#modal-panel h2 { font-family: 'PS2P'; font-weight: normal; font-size: 15px; line-height: 1.5; margin: 6px 0; }
#modal-panel p { margin: 6px 0; }
#modal-panel .row { display: flex; gap: 8px; justify-content: center; flex-wrap: wrap; margin-top: 12px; }
#modal-panel .row .btn { min-width: 150px; }
.title-cat { width: 96px; height: 96px; image-rendering: pixelated; }
.stats { display: grid; grid-template-columns: 1fr auto; gap: 2px 12px; text-align: left; max-width: 320px; margin: 8px auto; font-size: 15px; }
.stats b { font-family: 'PS2P'; font-size: 11px; text-align: right; align-self: center; }
.boons { display: flex; flex-direction: column; gap: 8px; margin-top: 8px; }
.boon { text-align: left; display: block; width: 100%; font-family: 'Nunito'; font-weight: 800; font-size: 14px; line-height: 1.25; color: var(--ink); background: none;
  border-style: solid; border-width: 12px; border-image: url('../assets/ui/slot9.png') 7 fill / 12px stretch; image-rendering: pixelated; padding: 0 4px; }
.boon:hover { border-image-source: url('../assets/ui/slot9-hover.png'); }
.boon:active { border-image-source: url('../assets/ui/slot9-dark.png'); }
.boon b { font-family: 'PS2P'; font-size: 11px; font-weight: normal; display: block; margin-bottom: 4px; }
.rules { text-align: left; font-size: 14px; }
.rules h3 { font-family: 'PS2P'; font-size: 11px; font-weight: normal; margin: 12px 0 4px; }
.rules ul { margin: 4px 0; padding-left: 18px; }
.rules li { margin: 2px 0; }
.credit { font-size: 11px; opacity: .7; margin-top: 10px; }

/* ---- онлайн ---- */
#year-line { display: flex; align-items: center; justify-content: space-between; gap: 6px; white-space: nowrap; width: max-content; min-width: 100%; }
#btn-leave { flex-shrink: 0; }
#btn-fight { white-space: nowrap; }
.btn.xs { font-size: 8px; min-height: 26px; border-width: 7px 9px; padding: 0 2px 1px; }
.mp-timer { display: inline-block; min-width: 4ch; margin-left: 6px; padding: 2px 4px; border-radius: 4px; background: rgba(117, 76, 96, .15); }
.mp-timer.warn { color: #fff8e0; background: #c0636f; animation: tick 1s steps(2) infinite; }
@keyframes tick { 50% { opacity: .55; } }
#enemy-line .st { font-family: 'PS2P'; font-size: 8px; padding: 1px 4px; border-radius: 3px; background: #e9d9b8; color: var(--ink); white-space: nowrap; }
#enemy-line .st.ok { background: #9fd06a; }
#enemy-line .st.off { background: #e78a96; color: #fff8e0; }
.opp-hp { display: inline-flex; align-items: center; gap: 4px; }
.opp-hp .bar { width: 70px; height: 10px; background: #754c60; border-radius: 3px; padding: 2px; }
.opp-hp .bar > div { height: 100%; background: linear-gradient(#e78a96, #c0636f); border-radius: 2px; transition: width .3s; }
.opp-army { opacity: .85; }
#netstatus { position: absolute; left: 50%; transform: translateX(-50%); top: 84px; z-index: 30; font-family: 'Nunito'; font-weight: 900; font-size: 14px;
  background: #754c60; color: #fff8e0; padding: 6px 12px; border-radius: 8px; box-shadow: 0 3px 0 rgba(0,0,0,.2); max-width: 92vw; text-align: center; pointer-events: none; }
.wait-time { font-family: 'PS2P'; font-size: 12px; }
p.wait-time { font-size: 16px; margin: 8px 0; }
.room-code { font-family: 'PS2P'; font-size: 30px; letter-spacing: 6px; margin: 6px 0; color: var(--ink); }
.room-link { font-size: 12px; word-break: break-all; opacity: .8; }
.code-row input { font-family: 'PS2P'; font-size: 16px; width: 120px; text-align: center; text-transform: uppercase; padding: 8px; border: 3px solid #754c60; border-radius: 6px; background: #fff8e0; color: var(--ink); }
.code-row input.bad { border-color: #c0636f; background: #ffe4e4; }
.btn.waiting { opacity: .8; filter: none; }
.boon.picked { border-image-source: url('../assets/ui/slot9-dark.png'); }
.boon:disabled { opacity: .6; }
.mp-note { min-height: 1.2em; font-weight: 900; }
button, .card, .boon { touch-action: manipulation; }

/* ---- расы ---- */
#portrait { position: relative; }
#race-flag { position: absolute; right: -10px; bottom: -8px; width: 21px; height: 30px; image-rendering: pixelated; }
.race-tag { font-family: 'Nunito'; font-weight: 900; font-size: 11px; opacity: .8; }
.opp-flag { width: 11px; height: 16px; image-rendering: pixelated; vertical-align: -3px; margin-right: 4px; }
.card .kind.unique { background: #e0a43c; color: #fff8e0; }
.race-tabs { display: flex; gap: 6px; justify-content: center; margin: 8px 0; }
.race-tab { position: relative; display: flex; flex-direction: column; align-items: center; gap: 2px; width: 84px; padding: 4px 2px 6px; background: none; cursor: pointer;
  border-style: solid; border-width: 10px; border-image: url('../assets/ui/slot9.png') 7 fill / 10px stretch; image-rendering: pixelated; font-family: 'Nunito'; font-weight: 900; font-size: 12px; color: var(--ink); touch-action: manipulation; }
.race-tab:hover { border-image-source: url('../assets/ui/slot9-hover.png'); }
.race-tab.sel { border-image-source: url('../assets/ui/slot9-dark.png'); transform: translateY(-2px); }
.race-tab canvas { width: 48px; height: 48px; image-rendering: pixelated; }
.race-tab img { position: absolute; top: 2px; right: 4px; width: 14px; height: 20px; image-rendering: pixelated; }
.race-card { text-align: left; font-size: 14px; line-height: 1.3; min-height: 170px; }
.race-card p { margin: 6px 0; }
.race-head { display: flex; align-items: center; gap: 10px; }
.race-head b { font-family: 'PS2P'; font-size: 13px; font-weight: normal; display: block; }
.race-style { font-weight: 900; font-size: 12px; opacity: .75; }
.race-banner { width: 28px; height: 40px; image-rendering: pixelated; }
.race-uniques { display: flex; flex-direction: column; gap: 8px; width: 100%; }
.race-unique { display: flex; gap: 8px; align-items: center; padding: 6px; border-radius: 6px; background: rgba(117, 76, 96, .1); }
.race-unique canvas { width: 56px; height: 56px; image-rendering: pixelated; flex-shrink: 0; }

@media (max-width: 560px) {
  #hud-top { padding-left: 6px; padding-right: 6px; gap: 4px; }
  .frame-wood { width: 48px; height: 48px; border-width: 3px; }
  #portrait canvas { width: 36px; height: 36px; }
  .pill { font-size: 10px; min-height: 26px; border-width: 8px; gap: 4px; padding: 1px 2px; }
  .pill .bar { width: 56px; height: 10px; }
  #hud-right { min-width: 0; max-width: 54vw; font-size: 12px; border-width: 11px; }
  #year-line { font-size: 10px; }
  #enemy-line { font-size: 12px; }
  #enemy-units canvas { width: 26px; height: 26px; }
  #hand { gap: 4px; padding: 6px 4px; min-height: 108px; }
  .card { border-width: 9px; }
  .card canvas { width: 40px; height: 40px; }
  .card .nm { font-size: 11.5px; }
  .card .cost { font-size: 9px; right: -7px; top: -8px; }
  .card .kind { font-size: 9px; left: -6px; top: -7px; }
  #info-line { font-size: 13px; }
  .btn { font-size: 10px; min-height: 42px; }
  .btn-go { font-size: 12px; }
  #modal-panel h1 { font-size: 17px; }
  #advisor-cv { width: 60px; height: 60px; }
  #advisor-box { font-size: 14px; }
  #banner-inner { font-size: 14px; }
  .opp-hp .bar { width: 46px; }
  .race-tabs { gap: 3px; }
  .race-tab { width: 64px; font-size: 9px; border-width: 6px; letter-spacing: -.2px; }
  .race-tab canvas { width: 40px; height: 40px; }
  .race-card { font-size: 13px; }
  #year-line { font-size: 9px; gap: 3px 4px; width: auto; flex-wrap: wrap; }
  #btn-leave { margin-left: auto; }
  #btn-fight .mp-timer { font-size: 9px; margin-left: 3px; padding: 2px 3px; min-width: 0; }
  #hud-right { max-width: 56vw; }
  .btn.xs { font-size: 7px; min-height: 22px; border-width: 6px 7px; }
  #netstatus { top: 76px; font-size: 12px; }
  .room-code { font-size: 24px; }
}

#btn-map { position: absolute; left: 8px; z-index: 6; }
#btn-sound { position: fixed; z-index: 60; left: 50%; transform: translateX(-50%); top: calc(8px + env(safe-area-inset-top, 0px)); min-height: 0; padding: 0; }
@media (max-width: 560px) { #btn-sound { left: 10px; transform: none; top: calc(66px + env(safe-area-inset-top, 0px)); } }
#btn-sound canvas { width: 24px; height: 24px; display: block; image-rendering: pixelated; }

/* ---- профиль и счётчики сайта ---- */
.site-stats { font-size: 13px; margin: 10px auto 0; opacity: .9; }
.site-stats b { font-family: 'PS2P'; font-size: 10px; }
.profile-cat { width: 112px; height: 112px; image-rendering: pixelated; margin: 0 auto; display: block; }
.cat-name { font-family: 'PS2P'; font-size: 11px; margin: 0 0 8px; }
.nick-row { display: flex; gap: 6px; justify-content: center; align-items: center; margin: 6px auto; max-width: 320px; }
.nick-row input { flex: 1; min-width: 0; font-family: 'Nunito'; font-weight: 800; font-size: 15px; text-align: center;
  color: var(--ink); background: #fff8e0; border: 2px solid #754c60; border-radius: 8px; padding: 6px 8px; }
.hint { font-size: 12px; opacity: .75; min-height: 1em; margin: 2px 0 8px; }
.race-stats { width: min(100%, 320px); margin: 8px auto; border-collapse: collapse; font-size: 13px; }
.race-stats th, .race-stats td { padding: 2px 6px; text-align: center; }
.race-stats th { font-family: 'PS2P'; font-size: 8px; font-weight: normal; }
.race-stats td:first-child, .race-stats th:first-child { text-align: left; }
.claim-box { margin: 10px auto; max-width: 340px; padding: 8px 6px; }
.claim-label { font-family: 'PS2P'; font-size: 8px; margin: 0 0 4px; opacity: .8; }
.claim-code { font-family: 'PS2P'; font-size: 13px; letter-spacing: 1px; margin: 0 0 6px; color: var(--ink); }
.claim-actions { margin-top: 0; }
.claim-actions .btn { min-width: 0; }
