@font-face {
  font-family: Cinzel;
  font-style: normal;
  font-weight: 600;
  font-display: swap;
  src: url("/fonts/cinzel-600.woff2") format("woff2");
}
@font-face {
  font-family: Cinzel;
  font-style: normal;
  font-weight: 700;
  font-display: swap;
  src: url("/fonts/cinzel-700.woff2") format("woff2");
}
@font-face {
  font-family: "Source Sans 3";
  font-style: normal;
  font-weight: 400;
  font-display: swap;
  src: url("/fonts/sourcesans-400.woff2") format("woff2");
}
@font-face {
  font-family: "Source Sans 3";
  font-style: normal;
  font-weight: 600;
  font-display: swap;
  src: url("/fonts/sourcesans-600.woff2") format("woff2");
}
@font-face {
  font-family: "Source Sans 3";
  font-style: normal;
  font-weight: 700;
  font-display: swap;
  src: url("/fonts/sourcesans-700.woff2") format("woff2");
}

:root {
  --bg: #090807;
  --panel: rgba(16, 13, 10, 0.92);
  --panel-2: #1a1612;
  --line: rgba(196, 165, 116, 0.28);
  --gold: #c4a574;
  --gold-2: #e6c98a;
  --text: #ece4d6;
  --muted: #9a8f80;
  --danger: #b5463a;
  --hp: #a33b32;
  --stam: #c4a04a;
  --hun: #6b8f4a;
  --thi: #4a8aa0;
  --shadow: rgba(0, 0, 0, 0.55);
  --safe-t: env(safe-area-inset-top, 0px);
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-l: env(safe-area-inset-left, 0px);
  --safe-r: env(safe-area-inset-right, 0px);
}

*, *::before, *::after { box-sizing: border-box; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--text); overflow: hidden; touch-action: none; user-select: none; -webkit-user-select: none; }
body { font-family: "Source Sans 3", "Segoe UI", sans-serif; font-size: 15px; }
button, input { font-family: inherit; }
img { display: block; max-width: 100%; }
h1, h2, h3 { font-family: Cinzel, "Times New Roman", serif; font-weight: 700; letter-spacing: 0.14em; margin: 0; }

#app, #game, #overlay { position: fixed; inset: 0; width: 100%; height: 100%; }
#game { display: block; background: #0b0a09; cursor: crosshair; }
#overlay { pointer-events: none; z-index: 5; }
.fs-btn {
  pointer-events: auto;
  position: absolute;
  top: calc(12px + var(--safe-t));
  right: calc(12px + var(--safe-r));
  z-index: 26;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
  width: 48px; height: 48px;
  border: 1px solid var(--line);
  background: rgba(16, 13, 10, 0.82);
  color: var(--gold-2);
  letter-spacing: 0.1em; text-transform: uppercase;
  font-size: 9px; font-weight: 700;
  cursor: pointer;
}
.fs-btn i { display: block; line-height: 0; pointer-events: none; color: var(--gold); }
.fs-btn:hover, .fs-btn.on { border-color: var(--gold); }
body.playing .fs-btn { display: none; }
#overlay .screen,
#overlay .sheet,
#overlay .menu-btn,
#overlay button,
#overlay input {
  pointer-events: auto;
}

.screen { position: absolute; inset: 0; display: none; align-items: center; justify-content: center; }
.screen.active { display: flex; z-index: 20; }
.screen.sub { background: rgba(6, 5, 4, 0.72); backdrop-filter: blur(8px); }

.menu-bg {
  position: absolute; inset: -4%;
  background: url("/assets/backgrounds/menu_bg.jpg") center / cover no-repeat;
  animation: ken 42s ease-in-out infinite alternate;
  filter: saturate(0.92) contrast(1.05);
}
.menu-dim {
  position: absolute; inset: 0;
  background:
    radial-gradient(ellipse at 50% 40%, rgba(8, 7, 6, 0.15), rgba(8, 7, 6, 0.78) 70%),
    linear-gradient(180deg, rgba(8,7,6,0.35), rgba(8,7,6,0.82));
}
.menu-grain {
  position: absolute; inset: 0; opacity: 0.08; pointer-events: none;
  background-image: repeating-linear-gradient(0deg, transparent, transparent 2px, rgba(0,0,0,0.35) 3px);
  mix-blend-mode: overlay;
}
@keyframes ken {
  from { transform: scale(1.04) translate3d(-1%, 0, 0); }
  to { transform: scale(1.12) translate3d(1.4%, -1%, 0); }
}

.menu-wrap {
  position: relative; z-index: 2; width: min(420px, calc(100% - 32px));
  padding: 28px 22px 18px; text-align: center;
}
.brand h1 { font-size: clamp(34px, 9vw, 56px); color: var(--gold-2); text-shadow: 0 2px 24px rgba(0,0,0,0.8); }
.tag { margin: 8px 0 22px; color: var(--muted); letter-spacing: 0.28em; text-transform: uppercase; font-size: 11px; }
.brand-mark {
  width: 42px; height: 42px; margin: 0 auto 12px;
  background: url("/assets/svg/mark.svg") center / contain no-repeat;
  filter: drop-shadow(0 2px 8px rgba(0,0,0,0.6));
}
.brand-mark.sm { width: 32px; height: 32px; }

.menu-nav { display: flex; flex-direction: column; gap: 8px; }
.menu-btn {
  appearance: none; border: 1px solid var(--line); background: rgba(20, 16, 12, 0.72);
  color: var(--text); padding: 12px 16px; letter-spacing: 0.16em; text-transform: uppercase;
  font-size: 12px; font-weight: 600; cursor: pointer; transition: 0.15s ease;
}
.menu-btn:hover:not(:disabled), .menu-btn:focus-visible { border-color: var(--gold); color: var(--gold-2); background: rgba(36, 28, 20, 0.88); }
.menu-btn.primary { background: linear-gradient(180deg, #3a2e22, #241c16); border-color: rgba(196,165,116,0.5); }
.menu-btn.danger { border-color: rgba(181,70,58,0.5); color: #e8b0a8; }
.menu-btn:disabled { opacity: 0.38; cursor: default; }
.menu-foot { margin-top: 18px; color: var(--muted); font-size: 12px; letter-spacing: 0.06em; }

.panel {
  width: min(560px, calc(100% - 24px)); max-height: calc(100% - 24px);
  overflow: auto; background: var(--panel); border: 1px solid var(--line);
  box-shadow: 0 18px 60px var(--shadow); padding: 16px 16px 20px;
}
.panel-h { display: flex; align-items: center; justify-content: space-between; margin-bottom: 14px; gap: 12px; }
.panel-h h2 { font-size: 16px; color: var(--gold); letter-spacing: 0.18em; }
.icon-btn {
  border: 1px solid var(--line); background: transparent; color: var(--muted);
  padding: 6px 10px; font-size: 11px; letter-spacing: 0.12em; text-transform: uppercase; cursor: pointer;
}
.icon-btn:hover { color: var(--text); border-color: var(--gold); }
.stack { display: flex; flex-direction: column; gap: 12px; }
.field { display: flex; flex-direction: column; gap: 6px; text-align: left; font-size: 12px; letter-spacing: 0.12em; text-transform: uppercase; color: var(--muted); margin: 10px 0; }
.field input {
  background: #0e0c0a; border: 1px solid var(--line); color: var(--text); padding: 10px 12px; font-size: 15px; letter-spacing: 0.04em;
}
.code-in { text-transform: uppercase; letter-spacing: 0.4em; text-align: center; font-size: 22px !important; }
.row { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.slider { width: 140px; accent-color: var(--gold); }
.seg { display: flex; border: 1px solid var(--line); }
.seg button { flex: 1; background: transparent; border: 0; color: var(--muted); padding: 8px; cursor: pointer; }
.seg button.on { background: #2a241c; color: var(--gold-2); }
.muted { color: var(--muted); }
.err { color: #e08a80; min-height: 1.2em; font-size: 13px; }
.hidden { display: none !important; }
.host-info { margin-top: 14px; text-align: left; background: #110e0c; border: 1px solid var(--line); padding: 12px; }
.host-code { font-size: 36px; letter-spacing: 0.28em; color: var(--gold-2); font-family: Cinzel, serif; }
.controls-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 8px 16px; text-align: left; font-size: 14px; }
.controls-grid b { color: var(--gold); font-weight: 600; }
.about-copy p { line-height: 1.55; color: var(--text); }
#screen-loading .menu-bg {
  background-image: url("/assets/backgrounds/loading_bg.jpg");
}
.load-box { position: relative; z-index: 2; text-align: center; width: min(360px, 86%); }
.load-box h2 { color: var(--gold-2); letter-spacing: 0.22em; margin: 8px 0; }
.bar { height: 4px; background: #1c1814; border: 1px solid var(--line); overflow: hidden; }
.bar i { display: block; height: 100%; width: 0%; background: linear-gradient(90deg, #8a6a3a, var(--gold-2)); }
.load-pct { color: var(--muted); font-size: 12px; letter-spacing: 0.16em; }

#hud { position: absolute; inset: 0; pointer-events: none; }
#hud button, #hud #quick-slots, #hud #minimap { pointer-events: auto; }
#hud-left {
  position: absolute; top: calc(10px + var(--safe-t)); left: calc(12px + var(--safe-l));
  width: min(280px, 46vw);
}
.vitals { display: flex; flex-direction: column; gap: 4px; }
.vital { display: flex; align-items: center; gap: 6px; }
.vital-ic { width: 14px; height: 14px; flex: 0 0 14px; opacity: 0.9; }
.vbar { flex: 1; height: 8px; background: rgba(0,0,0,0.45); border: 1px solid rgba(255,255,255,0.08); overflow: hidden; }
.vbar i { display: block; height: 100%; width: 100%; transform-origin: left center; }
.vital.hp .vbar i { background: linear-gradient(90deg, #6e2420, var(--hp)); }
.vital.stam .vbar i { background: linear-gradient(90deg, #7a6228, var(--stam)); }
.vital.hun .vbar i { background: linear-gradient(90deg, #3e5a2c, var(--hun)); }
.vital.thi .vbar i { background: linear-gradient(90deg, #2a5a6a, var(--thi)); }
.clock { margin-top: 6px; font-size: 11px; letter-spacing: 0.14em; color: var(--gold); text-shadow: 0 1px 4px #000; }

#hud-right {
  position: absolute; top: calc(10px + var(--safe-t)); right: calc(12px + var(--safe-r));
  display: flex; gap: 6px; flex-wrap: wrap; justify-content: flex-end; max-width: 52vw;
}
.hud-btn {
  border: 1px solid var(--line); background: rgba(12,10,8,0.7); color: var(--text);
  padding: 8px 10px; font-size: 11px; letter-spacing: 0.1em; text-transform: uppercase; cursor: pointer;
}
.hud-btn:hover { border-color: var(--gold); color: var(--gold-2); }

#quick-slots {
  position: absolute; left: 50%; transform: translateX(-50%);
  bottom: calc(14px + var(--safe-b)); display: flex; gap: 6px;
}
.qslot {
  width: 48px; height: 48px; border: 1px solid var(--line); background: rgba(10,8,7,0.72);
  position: relative; padding: 4px; cursor: pointer;
}
.qslot img { width: 100%; height: 100%; object-fit: contain; }
.qslot .n { position: absolute; right: 3px; bottom: 2px; font-size: 10px; color: var(--gold-2); }
.qslot.on { border-color: var(--gold); box-shadow: 0 0 0 1px rgba(196,165,116,0.35); }
.qslot kbd { position: absolute; left: 3px; top: 2px; font-size: 9px; color: var(--muted); }

#weapon-chip {
  position: absolute; left: calc(12px + var(--safe-l)); bottom: calc(14px + var(--safe-b));
  display: flex; gap: 8px; align-items: center; background: rgba(10,8,7,0.7);
  border: 1px solid var(--line); padding: 6px 10px 6px 6px; min-width: 140px; max-width: 42vw;
}
#weapon-chip img { width: 36px; height: 36px; object-fit: contain; }
#weapon-chip b { display: block; font-size: 12px; letter-spacing: 0.08em; }
#weapon-chip small { color: var(--muted); font-size: 11px; }

#interact-prompt {
  position: absolute; left: 50%; top: 42%; transform: translate(-50%, -50%);
  display: flex; align-items: center; gap: 8px; background: rgba(10,8,7,0.82);
  border: 1px solid var(--line); padding: 8px 12px; letter-spacing: 0.12em; text-transform: uppercase; font-size: 12px;
}
#hint {
  position: absolute; left: 50%; top: calc(72px + var(--safe-t)); transform: translateX(-50%);
  max-width: min(520px, 90vw); text-align: center; background: rgba(10,8,7,0.78);
  border: 1px solid var(--line); padding: 10px 14px; font-size: 14px; color: var(--text);
}
#mp-badge {
  position: absolute; top: calc(44px + var(--safe-t)); left: calc(12px + var(--safe-l));
  font-size: 11px; letter-spacing: 0.12em; color: var(--gold); text-shadow: 0 1px 4px #000;
}
#minimap {
  position: absolute; right: calc(12px + var(--safe-r)); bottom: calc(14px + var(--safe-b));
  width: 120px; height: 120px; border: 1px solid var(--line); background: rgba(0,0,0,0.5);
  image-rendering: auto;
}

.sheet {
  position: absolute; left: 50%; top: 50%; transform: translate(-50%, -50%);
  width: min(860px, calc(100% - 16px)); max-height: calc(100% - 20px);
  overflow: auto; background: var(--panel); border: 1px solid var(--line);
  box-shadow: 0 24px 80px var(--shadow); padding: 14px;
  z-index: 12;
  pointer-events: auto;
}
.sheet.sm { width: min(380px, calc(100% - 16px)); display: flex; flex-direction: column; gap: 8px; }
.inv-layout { display: grid; grid-template-columns: 92px 1fr min(220px, 32%); gap: 12px; }
.inv-grid { display: grid; grid-template-columns: repeat(6, 1fr); gap: 4px; }
.cell {
  aspect-ratio: 1; border: 1px solid rgba(196,165,116,0.18); background: #120f0c;
  position: relative; cursor: pointer; padding: 3px;
}
.cell img { width: 100%; height: 100%; object-fit: contain; pointer-events: none; }
.cell .n { position: absolute; right: 3px; bottom: 2px; font-size: 10px; color: var(--gold-2); }
.cell.sel { outline: 1px solid var(--gold); }
.cell.drag { opacity: 0.45; }
.equip-col { display: flex; flex-direction: column; gap: 6px; }
.equip { border: 1px solid var(--line); background: #120f0c; min-height: 64px; padding: 4px; text-align: center; cursor: pointer; }
.equip img { width: 48px; height: 48px; object-fit: contain; margin: 0 auto; }
.equip small { display: block; font-size: 10px; color: var(--muted); letter-spacing: 0.08em; text-transform: uppercase; }
.inv-detail { background: #110e0c; border: 1px solid rgba(196,165,116,0.16); padding: 10px; font-size: 13px; }
.inv-detail h3 { font-size: 14px; letter-spacing: 0.12em; color: var(--gold-2); margin-bottom: 6px; }
.rarity-common { color: #c8c0b4; }
.rarity-uncommon { color: #7dae6a; }
.rarity-rare { color: #6aa4d4; }
.rarity-epic { color: #b07ad4; }
.rarity-legendary { color: #d4a44a; }
.tabs { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 10px; }
.tab { border: 1px solid var(--line); background: transparent; color: var(--muted); padding: 6px 10px; font-size: 11px; letter-spacing: 0.1em; text-transform: uppercase; cursor: pointer; }
.tab.on { color: var(--gold-2); border-color: var(--gold); }
.craft-list { display: flex; flex-direction: column; gap: 6px; }
.recipe {
  display: grid; grid-template-columns: 48px 1fr auto; gap: 10px; align-items: center;
  border: 1px solid rgba(196,165,116,0.16); padding: 8px; background: #120f0c; cursor: pointer;
}
.recipe img { width: 48px; height: 48px; object-fit: contain; }
.recipe.locked { opacity: 0.4; cursor: default; }
.recipe .need { color: var(--muted); font-size: 12px; }
.recipe.can { border-color: rgba(107,143,74,0.5); }
.build-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(92px, 1fr)); gap: 8px; }
.build-card { border: 1px solid var(--line); background: #120f0c; padding: 8px; text-align: center; cursor: pointer; font-size: 12px; }
.build-card img { width: 64px; height: 64px; object-fit: contain; margin: 0 auto 6px; }
.build-card.on { border-color: var(--gold); }
.loot-list { display: flex; flex-direction: column; gap: 6px; margin-bottom: 8px; }
.loot-row { display: flex; align-items: center; gap: 8px; border: 1px solid rgba(196,165,116,0.16); padding: 6px; cursor: pointer; background: #120f0c; }
.loot-row img { width: 36px; height: 36px; object-fit: contain; }
.dead-title { color: var(--danger); letter-spacing: 0.2em; text-align: center; margin: 8px 0; }
.pad { padding: 0 4px 10px; }

#touch { position: absolute; inset: 0; pointer-events: none; z-index: 6; }
#joy-zone {
  pointer-events: auto;
  position: absolute;
  left: 0; bottom: 0;
  width: 46%;
  height: 62%;
  touch-action: none;
}
#joy-wrap {
  pointer-events: none;
  position: absolute;
  left: calc(18px + var(--safe-l));
  bottom: calc(18px + var(--safe-b));
  width: 168px; height: 168px;
  opacity: 0.92;
  transition: opacity 0.15s ease;
}
#joy-wrap.floating { opacity: 1; z-index: 7; }
#joy { width: 100%; height: 100%; touch-action: none; }
.joy-hint {
  position: absolute; left: 50%; bottom: 6px; transform: translateX(-50%);
  font-size: 10px; letter-spacing: 0.14em; text-transform: uppercase; color: rgba(230,201,138,0.45);
  pointer-events: none;
}
#touch-btns {
  pointer-events: none;
  position: absolute;
  right: calc(10px + var(--safe-r));
  bottom: calc(10px + var(--safe-b));
  width: 240px; height: 230px;
}
.tbtn {
  pointer-events: auto;
  position: absolute;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
  border-radius: 50%;
  border: 1.5px solid rgba(196,165,116,0.4);
  background: radial-gradient(circle at 35% 30%, rgba(50,40,30,0.55), rgba(12,10,8,0.72));
  color: var(--gold-2);
  letter-spacing: 0.08em; text-transform: uppercase;
  font-size: 9px; font-weight: 700;
  box-shadow: 0 6px 16px rgba(0,0,0,0.45), inset 0 1px 0 rgba(255,255,255,0.08);
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
}
.tbtn i { display: block; line-height: 0; pointer-events: none; }
.tbtn span { pointer-events: none; font-size: 8px; opacity: 0.85; }
.tbtn:active, .tbtn.held {
  transform: scale(0.94);
  border-color: var(--gold);
  background: radial-gradient(circle at 35% 30%, rgba(90,70,40,0.7), rgba(20,14,10,0.8));
}
.tbtn.attack {
  right: 8px; bottom: 14px;
  width: 92px; height: 92px;
  background: radial-gradient(circle at 35% 30%, rgba(140,50,40,0.55), rgba(50,16,12,0.78));
  border-color: rgba(180,80,60,0.55);
  font-size: 11px;
}
.tbtn.attack span { font-size: 10px; }
.tbtn.dodge { right: 112px; bottom: 10px; width: 68px; height: 68px; }
.tbtn.heavy { right: 108px; bottom: 86px; width: 62px; height: 62px; }
.tbtn.interact { right: 22px; bottom: 118px; width: 60px; height: 60px; opacity: 0.55; }
.tbtn.interact.ready {
  opacity: 1;
  border-color: var(--gold);
  box-shadow: 0 0 14px rgba(196,165,116,0.45);
}
.tbtn.lock { right: 176px; bottom: 78px; width: 50px; height: 50px; }
.tbtn.heal { right: 176px; bottom: 18px; width: 50px; height: 50px; }
.tbtn.light { right: 18px; bottom: 186px; width: 44px; height: 44px; }
.tbtn.sprint {
  left: calc(36px + var(--safe-l));
  bottom: calc(196px + var(--safe-b));
  width: 58px; height: 58px;
  pointer-events: auto;
}
.tbtn.sprint.held { border-color: var(--stam); color: var(--stam); }

#toasts { position: absolute; right: calc(12px + var(--safe-r)); top: calc(86px + var(--safe-t)); display: flex; flex-direction: column; gap: 6px; width: min(260px, 48vw); pointer-events: none; }
.toast { background: rgba(12,10,8,0.88); border: 1px solid var(--line); padding: 8px 10px; font-size: 13px; animation: in 0.25s ease; }
@keyframes in { from { opacity: 0; transform: translateX(8px); } to { opacity: 1; transform: none; } }

#map-canvas { width: 100%; height: auto; background: #0c0b0a; border: 1px solid var(--line); }

body.touch-ui #weapon-chip { display: none; }
body.touch-ui #minimap {
  top: calc(78px + var(--safe-t));
  right: auto;
  left: calc(12px + var(--safe-l));
  bottom: auto;
  width: 76px; height: 76px;
}
@media (pointer: fine) and (hover: hover) {
  body:not(.touch-ui) #touch { display: none !important; }
}
body.touch-ui #quick-slots {
  left: 50%;
  transform: translateX(-50%);
  bottom: calc(248px + var(--safe-b));
}
body.touch-ui .qslot { width: 42px; height: 42px; }
body.touch-ui #hud-right { max-width: 58vw; }
body.touch-ui .hud-btn { padding: 8px 9px; min-height: 36px; }
body.touch-ui #interact-prompt { top: 36%; }

@media (max-width: 720px) {
  .inv-layout { grid-template-columns: 1fr; }
  .equip-col { flex-direction: row; overflow: auto; }
  .equip { min-width: 72px; }
  .controls-grid { grid-template-columns: 1fr; }
  #weapon-chip { display: none; }
  #hud-left { width: min(200px, 48vw); }
  .hud-btn { padding: 7px 8px; font-size: 10px; }
  .sheet { width: min(860px, calc(100% - 10px)); max-height: calc(100% - 12px); }
}
@media (max-width: 400px) {
  .menu-wrap { padding: 18px 10px; }
  .sheet { padding: 10px; }
  .inv-grid { grid-template-columns: repeat(5, 1fr); }
  #joy-wrap { width: 140px; height: 140px; }
  .tbtn.attack { width: 82px; height: 82px; }
  #touch-btns { width: 210px; height: 210px; }
}
@media (orientation: portrait) {
  #joy-zone { width: 50%; height: 48%; }
  #joy-wrap { width: 150px; height: 150px; bottom: calc(12px + var(--safe-b)); }
  .tbtn.sprint { bottom: calc(170px + var(--safe-b)); }
  body.touch-ui #quick-slots { bottom: calc(250px + var(--safe-b)); }
  #touch-btns { width: 220px; height: 220px; }
}
@media (orientation: landscape) and (max-height: 430px) {
  .brand h1 { font-size: 28px; }
  .menu-btn { padding: 8px; }
  #joy-wrap { width: 128px; height: 128px; }
  .tbtn.attack { width: 74px; height: 74px; bottom: 8px; }
  .tbtn.dodge { width: 56px; height: 56px; }
  .tbtn.heavy { bottom: 70px; width: 52px; height: 52px; }
  .tbtn.interact { bottom: 96px; }
  .tbtn.sprint { bottom: calc(148px + var(--safe-b)); width: 48px; height: 48px; }
  .tbtn.light { display: none; }
  body.touch-ui #quick-slots { bottom: calc(168px + var(--safe-b)); }
  body.touch-ui #minimap { width: 72px; height: 72px; }
  #touch-btns { height: 170px; width: 210px; }
}
