@font-face {
  font-family: 'PixelRus';
  src: url('assets/PixelRus.woff') format('woff');
  font-display: block;
}

:root {
  --fs: 16.5px;            /* replaced at runtime by a whole-device-pixel multiple of 11 */
  --fs-big: 22px;
  --px: 2px;               /* one "art pixel" for UI borders */
  --ink: #ece2c8;
  --muted: #a99a86;
  --bg: #1b1622;
  --bg2: #2a2a3a;
  --wood: #5c3a2a;
  --wood-l: #a5713f;
  --gold: #e0b13a;
  --good: #8cc152;
  --bad: #e47a52;
  --blue: #6cc0e0;
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-t: env(safe-area-inset-top, 0px);
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--ink); overflow: hidden; overscroll-behavior: none; }
body {
  font-family: 'PixelRus', monospace;
  font-size: var(--fs);
  line-height: 1.2;
  -webkit-font-smoothing: none;
  font-smooth: never;
  user-select: none;
  -webkit-user-select: none;
  touch-action: manipulation;
}
img { image-rendering: pixelated; }
canvas { image-rendering: pixelated; display: block; touch-action: none; }
button, input { font: inherit; color: inherit; }
.hidden { display: none !important; }
.muted { color: var(--muted); }
.small { font-size: calc(var(--fs) * 0.999); opacity: .9; }
.good { color: var(--good); }
.bad { color: var(--bad); }
.center { text-align: center; }
.grow { flex: 1; min-width: 0; }
.row { display: flex; align-items: center; }
.row.between { justify-content: space-between; margin: 0 0 .5em; }
.row.gap { gap: .5em; }
.row.wrap { flex-wrap: wrap; }
p { margin: .4em 0; }

#app { position: fixed; inset: 0; display: flex; flex-direction: column; max-width: 560px; margin: 0 auto; }
.screen { flex: 1; display: flex; flex-direction: column; min-height: 0; }

/* ---------- framed panels (9-slice wood) ---------- */
.panel {
  border-style: solid;
  border-width: calc(var(--px) * 4);
  border-image: url('assets/ui/ui_panel.png') 8 fill / calc(var(--px) * 8) stretch;
  image-rendering: pixelated;
  background-clip: padding-box;
}

.btn {
  border-style: solid;
  border-width: calc(var(--px) * 3) calc(var(--px) * 4) calc(var(--px) * 4);
  border-image: url('assets/ui/ui_btn.png') 5 6 fill / calc(var(--px) * 5) calc(var(--px) * 6) stretch;
  image-rendering: pixelated;
  background: none;
  color: #2b1a12;
  padding: .25em .6em;
  min-height: 2.4em;
  cursor: pointer;
  display: inline-flex; align-items: center; justify-content: center; gap: .3em;
  white-space: nowrap;
}
.btn:active:not(:disabled) { border-image-source: url('assets/ui/ui_btn_down.png'); transform: translateY(var(--px)); }
.btn:disabled { filter: grayscale(.8) brightness(.7); }
.btn.primary { color: #2b1a12; }
.btn.danger { filter: hue-rotate(-28deg) saturate(1.3); }
.btn.danger:disabled { filter: grayscale(.8) brightness(.7); }
.btn.small { min-height: 1.8em; padding: 0 .5em; }
.btn.wide { width: 100%; margin-top: .6em; }

.slot {
  position: relative;
  width: calc(var(--px) * 20 * 1.5); height: calc(var(--px) * 20 * 1.5);
  min-width: 48px; min-height: 48px;
  border-style: solid;
  border-width: calc(var(--px) * 2);
  border-image: url('assets/ui/ui_slot.png') 4 fill / calc(var(--px) * 3) stretch;
  image-rendering: pixelated;
  display: flex; align-items: center; justify-content: center;
  background: none; padding: 0;
}
.slot.big { width: 64px; height: 64px; }
.slot .ico { width: 75%; height: 75%; object-fit: contain; }
.slot .cnt { position: absolute; right: 2px; bottom: 0; color: var(--ink); text-shadow: 1px 1px 0 #000, -1px 0 0 #000; }
.slot.sel { outline: calc(var(--px) * 1.5) solid var(--gold); outline-offset: -2px; }
.ico-s { width: 1em; height: 1em; vertical-align: -0.12em; }

/* ---------- auth ---------- */
#auth { align-items: center; justify-content: flex-start; padding: 16px; overflow-y: auto; -webkit-overflow-scrolling: touch;
  background: radial-gradient(ellipse at 50% 30%, #2c5a35 0%, #1f3a2b 40%, #14302e 70%, #1b1622 100%); }
.auth-box { width: min(100%, 380px); padding: 12px 16px; margin: auto 0; flex: none; }
.auth-foot { text-align: center; }
.logo { font-size: calc(var(--fs-big) * 1.5); text-align: center; color: var(--gold); text-shadow: 0 calc(var(--px)*1.5) 0 #6b4a1a, 0 calc(var(--px)*3) 0 #1b1622; margin: .2em 0; }
.tagline { text-align: center; color: var(--muted); margin-bottom: 1em; }
.auth-form { display: flex; flex-direction: column; gap: .6em; }
.auth-foot { margin-top: 1em; }
.field { display: flex; flex-direction: column; gap: .2em; }
.field input {
  background: #14121c; border: var(--px) solid #45475c; padding: .5em .6em; outline: none; border-radius: 0;
  font-size: max(16px, var(--fs));
}
.field input:focus { border-color: var(--gold); }
#auth-error { min-height: 1.3em; margin-top: .5em; text-align: center; }

.tabs { display: flex; gap: .3em; margin: .3em 0 .6em; }
.tab { flex: 1; background: #14121c; border: var(--px) solid #45475c; padding: .45em; cursor: pointer; }
.tab.on { border-color: var(--gold); color: var(--gold); background: #2a2131; }

/* ---------- HUD ---------- */
#hud { padding: calc(6px + var(--safe-t)) 8px 6px; background: linear-gradient(#1b1622, #221b2b); border-bottom: var(--px) solid #3b2420; }
.hud-row { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.hud-row.bars { margin-top: 4px; }
.hud-row.bars .bar { flex: 1; }
.hud-right { display: flex; gap: .8em; align-items: center; }
.lvl { color: var(--gold); }
.coins { color: var(--gold); white-space: nowrap; }

.bar { position: relative; height: 1.25em; background: #14121c; border: var(--px) solid #0e0b14; overflow: hidden; }
.bar .fill { position: absolute; inset: 0 auto 0 0; transition: width .25s; }
.bar.hp .fill { background: linear-gradient(#e47a52 0 30%, #c44a3d 30% 75%, #8f2e33 75%); }
.bar.xp .fill { background: linear-gradient(#d29ef0 0 30%, #9a5cc0 30% 75%, #6a3a8a 75%); }
.bar.sta .fill { background: linear-gradient(#ffe27a 0 30%, #e0b13a 30% 75%, #a87a24 75%); }
.bar span { position: relative; display: block; text-align: center; line-height: 1.25em; font-size: var(--fs); text-shadow: 1px 1px 0 #000; }

#stage { flex: 1; min-height: 0; display: flex; flex-direction: column; gap: 10px; align-items: center; justify-content: center; position: relative;
  background: #14302e; }
canvas.world { box-shadow: 0 0 0 var(--px) #0e0b14; }
#conn { position: absolute; top: 8px; left: 50%; transform: translateX(-50%); background: #5a1f2a; padding: .3em .8em; border: var(--px) solid #1b1622; z-index: 3; }

#actions { display: grid; grid-template-columns: repeat(6, 1fr); gap: 4px; padding: 6px 8px calc(8px + var(--safe-b)); background: linear-gradient(#221b2b, #1b1622); border-top: var(--px) solid #3b2420; }
.act { position: relative; display: flex; flex-direction: column; align-items: center; gap: 2px; background: #2a2131; border: var(--px) solid #45365a; padding: 6px 2px; cursor: pointer; }
.act img { width: 32px; height: 32px; }
.act:active:not(:disabled) { background: #3e2156; }
.act:disabled { opacity: .45; }
.act.glow { border-color: var(--gold); box-shadow: 0 0 10px #e0b13a66; animation: glow 1.2s infinite alternate; }
@keyframes glow { to { box-shadow: 0 0 2px #e0b13a33; } }
.badge { position: absolute; top: 2px; right: 6px; background: #c44a3d; color: #fff; min-width: 1.2em; padding: 0 .2em; font-weight: normal; }
.badge:empty { display: none; }

/* ---------- battle ---------- */
#battle { background: #14121c; }
.b-head { padding: calc(6px + var(--safe-t)) 8px 6px; background: #1b1622; border-bottom: var(--px) solid #3b2420; }
#b-turn { text-align: center; color: var(--gold); margin-bottom: 4px; }
#b-hero { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; }
#b-stage { flex: 1; min-height: 0; display: flex; align-items: center; justify-content: center; }
#b-log { min-height: 3.8em; padding: 4px 10px; color: var(--muted); font-size: var(--fs); }
#b-log div:last-child { color: var(--ink); }
.b-actions { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 6px; padding: 0 8px 4px; }
.b-help { text-align: center; padding: 0 8px calc(8px + var(--safe-b)); min-height: 1.4em; }

/* ---------- sheets ---------- */
.sheet-wrap { position: fixed; inset: 0; background: #0b0910aa; display: flex; align-items: flex-end; justify-content: center; z-index: 20; opacity: 0; transition: opacity .15s; }
.sheet-wrap.open { opacity: 1; }
.sheet { width: min(100%, 560px); max-height: 86vh; display: flex; flex-direction: column; transform: translateY(20px); transition: transform .15s; margin-bottom: var(--safe-b); }
.sheet-wrap.open .sheet { transform: none; }
.sheet-head { display: flex; align-items: center; justify-content: space-between; padding: 4px 6px 6px; border-bottom: var(--px) solid #45365a; }
.sheet-title { color: var(--gold); font-size: var(--fs-big); }
.icon-btn { background: none; border: none; color: var(--bad); font-size: var(--fs-big); padding: 0 .4em; cursor: pointer; }
.sheet-body { overflow-y: auto; padding: 8px 6px 10px; -webkit-overflow-scrolling: touch; }

.inv-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(56px, 1fr)); gap: 6px; justify-items: center; margin: .3em 0 .8em; }
.inv-grid .slot { width: 56px; height: 56px; cursor: pointer; }
.detail { min-height: 7em; }
.item-card { background: #14121c; border: var(--px) solid #3b2f46; padding: 8px; }
.item-card-head { display: flex; gap: 10px; align-items: center; }
.item-name { font-size: var(--fs-big); }
.item-stats { display: flex; flex-wrap: wrap; gap: 4px; margin: .5em 0 .2em; }
.chip { background: #2a2131; border: var(--px) solid #45365a; padding: 0 .4em; white-space: nowrap; }

.eq-grid { display: grid; grid-template-columns: repeat(5, 1fr); gap: 4px; margin: .8em 0; }
.eq-slot { display: flex; flex-direction: column; align-items: center; gap: 2px; background: none; border: none; text-align: center; cursor: pointer; padding: 0; }
.eq-slot .slot { width: 52px; height: 52px; }
.eq-slot .small { line-height: 1.05; }
.hero-head { display: flex; gap: 10px; align-items: center; }
.hero-head .bar { margin-top: 4px; }
.stats { display: flex; flex-direction: column; gap: 6px; }
.stat-row { display: flex; align-items: center; justify-content: space-between; background: #14121c; border: var(--px) solid #2a2131; padding: 4px 8px; }
.derived { display: flex; flex-wrap: wrap; gap: 4px; margin: .7em 0 .3em; }
.notice { background: #3e2156; border: var(--px) solid #9a5cc0; padding: .4em .6em; margin-bottom: .5em; }

.keeper { display: flex; gap: 10px; align-items: center; margin-bottom: .6em; }
.shop-list { display: flex; flex-direction: column; gap: 6px; }
.shop-row { display: flex; gap: 8px; align-items: center; background: #14121c; border: var(--px) solid #2a2131; padding: 4px 6px; }
.shop-row.rest { border-color: #6b4a1a; }
.shop-row.owned { opacity: .6; }
.shop-row .btn { min-width: 4.4em; }

.reward { display: flex; gap: 6px; flex-wrap: wrap; margin: .3em 0 .7em; }
.loot { display: flex; flex-wrap: wrap; gap: 8px; margin: .4em 0; }
.loot-item { display: flex; flex-direction: column; align-items: center; width: 72px; text-align: center; line-height: 1.05; }
.loot-item.lost { opacity: .4; }
.levelup { display: flex; gap: 8px; align-items: center; background: #3e2156; border: var(--px) solid var(--gold); padding: 6px; margin: .5em 0; }
.levelup img { width: 48px; height: 48px; }
.result-win .sheet-title { color: var(--good); }
.result-lose .sheet-title { color: var(--bad); }
.help p { margin: .5em 0; }

/* ---------- toasts ---------- */
#toasts { position: fixed; top: calc(70px + var(--safe-t)); left: 0; right: 0; display: flex; flex-direction: column; align-items: center; gap: 4px; pointer-events: none; z-index: 30; }
.toast { background: #1b1622ee; border: var(--px) solid #45365a; padding: .35em .7em; max-width: 92%; text-align: center; transition: opacity .4s, transform .4s; animation: tin .2s; }
.toast.good { border-color: #4f9445; }
.toast.bad { border-color: #c44a3d; color: #f2b8b0; }
.toast.loot { border-color: var(--gold); }
.toast.out { opacity: 0; transform: translateY(-6px); }
@keyframes tin { from { opacity: 0; transform: translateY(-6px); } }

#loc-info { text-align: center; padding: 0 12px; }
#loc-name { color: var(--gold); }
#loc-hint { min-height: 2.4em; }
#loc-hint .danger { color: var(--bad); }

/* ---------- appearance picker ---------- */
.look-picker { display: flex; flex-direction: column; gap: 8px; align-items: stretch; background: #14121c; border: var(--px) solid #3b2f46; padding: 6px; }
.look-stage { flex: none; align-self: center; width: 120px; height: 120px; display: flex; align-items: flex-end; justify-content: center;
  background: radial-gradient(circle at 50% 80%, #3f7d3c 0 40%, #2c5a35 41% 60%, transparent 61%); }
.look-preview { width: 120px; height: 120px; }
.look-rows { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 4px; }
.look-row { display: grid; grid-template-columns: 5.5em auto 1fr auto; align-items: center; gap: 4px; }
.look-val { text-align: center; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.look-row .btn.small { min-height: 1.7em; padding: 0 .35em; }
.eq-grid { grid-template-columns: repeat(4, 1fr) !important; }

/* ---------- context button, tracker ---------- */
#btn-place { position: absolute; right: 12px; bottom: 8px; z-index: 2; min-width: 7em; animation: glow 1.2s infinite alternate; }
#tracker { display: flex; flex-direction: column; gap: 2px; margin-top: 4px; }
.trk { color: var(--ink); background: #1b1622aa; border: var(--px) solid #45365a; padding: 1px 6px; cursor: pointer; }
.trk.ready { border-color: var(--gold); color: var(--gold); }
.act span { font-size: var(--fs); }

/* ---------- maps ---------- */
.map-pane { display: flex; flex-direction: column; gap: 8px; align-items: center; }
.map-frame { padding: calc(var(--px) * 2); background: #0e0b14; border: var(--px) solid #45365a; }
.map-canvas { display: block; }
.map-legend { display: flex; gap: 12px; flex-wrap: wrap; justify-content: center; }
.lg { display: inline-block; width: .8em; height: .8em; margin-right: .3em; vertical-align: -.05em; border: 1px solid #1b1622; }
.lg-me { background: #fff; border-radius: 50%; }
.lg-npc { background: #ffe27a; }
.lg-npc2 { background: #e47a52; }
.lg-exit { background: #ece2c8; }
.world-info { align-self: stretch; background: #14121c; border: var(--px) solid #3b2f46; padding: 8px; }
.chip.good { color: var(--good); }

/* ---------- dialogs & quests ---------- */
.dialog-head { display: flex; gap: 10px; align-items: center; margin-bottom: .4em; }
.dialog-text { background: #ece2c8; color: #2b1a12; padding: .6em .7em; border: var(--px) solid #8a7a68; min-height: 3.6em; margin: .4em 0 .6em; }
.dialog-options { display: flex; flex-direction: column; gap: 6px; margin-top: .6em; }
.dialog-options .btn { justify-content: flex-start; white-space: normal; text-align: left; }
.dlg-lore, .dlg-back, .dlg-bye { filter: saturate(.6) brightness(.9); }
.quest-list { display: flex; flex-direction: column; gap: 8px; }
.quest-card { background: #14121c; border: var(--px) solid #45365a; padding: 8px; display: flex; flex-direction: column; gap: 4px; }
.quest-card.ready { border-color: var(--gold); }
.goals { display: flex; flex-direction: column; gap: 2px; }
.goal { display: flex; justify-content: space-between; gap: 8px; }
.goal.ok { color: var(--good); }
.quest-card .btn.small { align-self: flex-end; }

/* ---------- chat & mail ---------- */
.hud-btn { position: relative; background: #2a2131; border: var(--px) solid #45365a; padding: 2px 4px; cursor: pointer; line-height: 0; }
.hud-btn img { width: 24px; height: 24px; }
.hud-btn .badge { top: -6px; right: -6px; }
#chat-ticker { position: absolute; top: 6px; left: 8px; right: 8px; z-index: 2; display: flex; flex-direction: column; gap: 2px; cursor: pointer; }
#chat-ticker .tk { background: #1b1622cc; border: var(--px) solid #45365a; padding: 2px 6px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
#chat-ticker .tk.sys b { color: var(--gold); }
.chat-pane { display: flex; flex-direction: column; gap: 6px; }
.chat-log { height: min(52vh, 420px); overflow-y: auto; background: #14121c; border: var(--px) solid #2a2131; padding: 6px; display: flex; flex-direction: column; gap: 3px; -webkit-user-select: text; user-select: text; }
.chat-msg { line-height: 1.25; word-break: break-word; }
.chat-msg.sys { color: var(--gold); }
.chat-msg.pm { color: #d29ef0; }
.chat-name { background: none; border: none; padding: 0; color: var(--blue); cursor: pointer; }
.chat-name.me { color: var(--good); }
.chat-send { display: flex; gap: 6px; }
.chat-input, .compose input, .compose textarea, .compose select, .field select, .field textarea {
  flex: 1; min-width: 0; background: #14121c; border: var(--px) solid #45365a; color: var(--ink); padding: .5em .6em; font: inherit; font-size: max(16px, var(--fs)); border-radius: 0;
}
.field textarea, .compose textarea { resize: vertical; }
.tab-badge { background: #c44a3d; color: #fff; padding: 0 .3em; margin-left: .3em; font-weight: normal; }
.shop-row.thread, .shop-row.mail { text-align: left; cursor: pointer; width: 100%; }
.shop-row.mail.unread { border-color: var(--gold); }
.letter { display: flex; flex-direction: column; gap: 8px; align-items: flex-start; }
.letter > .quest-card { align-self: stretch; }
.letter-body { white-space: pre-wrap; background: #ece2c8; color: #2b1a12; padding: .6em .7em; border: var(--px) solid #8a7a68; align-self: stretch; -webkit-user-select: text; user-select: text; }
.compose { display: flex; flex-direction: column; gap: 6px; }
.small-grid .slot { width: 44px; height: 44px; min-width: 44px; min-height: 44px; }

/* travel between lands */
.travel-overlay { position: fixed; inset: 0; z-index: 30; background: #0b0910cc; display: flex; align-items: center; justify-content: center; padding: 16px; }
.travel-box { display: flex; flex-direction: column; gap: 10px; align-items: stretch; max-width: 420px; width: 100%; padding: 14px; }
.travel-box .map-frame { align-self: center; }

/* photos */
.photo-strip { display: flex; gap: 6px; overflow-x: auto; padding: 2px 0 6px; }
.photo-thumb { position: relative; flex: 0 0 72px; height: 72px; padding: 0; border: var(--px) solid #45365a; background: #1b1622; cursor: pointer; }
.photo-thumb img { width: 100%; height: 100%; object-fit: cover; display: block; }
.photo-thumb.pending, .photo-cell.pending { border-color: var(--gold); }
.photo-thumb.rejected, .photo-cell.rejected { opacity: .55; }
.photo-st { position: absolute; left: 0; right: 0; bottom: 0; background: #1b1622cc; font-size: 11px; text-align: center; }
.photo-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(130px, 1fr)); gap: 8px; margin: 6px 0; }
.photo-cell { display: flex; flex-direction: column; gap: 4px; border: var(--px) solid #45365a; padding: 4px; background: #221b2b; }
.photo-cell img { width: 100%; aspect-ratio: 1; object-fit: cover; cursor: zoom-in; }
.photo-cell input { width: 100%; }
.gallery { position: fixed; inset: 0; z-index: 40; background: #0b0910f2; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 10px; padding: 16px; }
.gallery-img { max-width: 100%; max-height: calc(100% - 64px); object-fit: contain; touch-action: pan-y; user-select: none; }
.gallery-bar { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; justify-content: center; }
.gallery-cap { color: #ece2c8; min-width: 70px; text-align: center; }
.dot { width: 8px; height: 8px; border-radius: 50%; flex: 0 0 8px; background: #6b5d7a; }
.dot.on { background: #7ad36b; box-shadow: 0 0 4px #7ad36b; }
.col.gap { display: flex; flex-direction: column; gap: 8px; }
