:root {
  --bg: #080706;
  --stone: #14110d;
  --stone-2: #1e1912;
  --panel: rgba(18, 14, 10, 0.92);
  --panel-deep: rgba(9, 8, 7, 0.96);
  --border: #5d4522;
  --border-bright: #a77b32;
  --text: #eadfbd;
  --muted: #9f9273;
  --gold: #d9a547;
  --teal: #70c7a3;
  --blue: #4d8ac8;
  --red: #b9423a;
  --green: #6ebd62;
  --violet: #8f6fc6;
  --shadow: rgba(0, 0, 0, 0.58);
  --ui-panel-frame: url("./assets/ui-v4/panel-frame.png?v=20260601h");
  --ui-panel-frame-active: url("./assets/ui-v4/panel-frame-active.png?v=20260601h");
  --ui-panel-body: url("./assets/ui-v4/panel-body.png?v=20260601h");
  --ui-button-frame: url("./assets/ui-v4/button-frame.png?v=20260601h");
  --ui-button-frame-hover: url("./assets/ui-v4/button-frame-hover.png?v=20260601h");
  --ui-button-frame-active: url("./assets/ui-v4/button-frame-active.png?v=20260601h");
  --ui-button-frame-disabled: url("./assets/ui-v4/button-frame-disabled.png?v=20260601h");
  --ui-input-frame: url("./assets/ui-v4/input-frame.png?v=20260601h");
  --ui-meter-frame: url("./assets/ui-v4/meter-frame.png?v=20260601h");
  --ui-minimap-frame: url("./assets/ui-v4/minimap-frame.png?v=20260601h");
  --ui-row-frame: url("./assets/ui-v4/row-frame.png?v=20260601h");
  --ui-slot-frame: url("./assets/ui-v4/slot-frame.png?v=20260601h");
  --ui-slot-frame-active: url("./assets/ui-v4/slot-frame-active.png?v=20260601h");
  --ui-section-grip: url("./assets/ui-v4/section-grip.png?v=20260601h");
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

html,
body {
  width: 100%;
  min-height: 100%;
}

body {
  margin: 0;
  color: var(--text);
  font-family: Georgia, "Times New Roman", serif;
  background:
    linear-gradient(90deg, rgba(217, 165, 71, 0.05) 1px, transparent 1px),
    linear-gradient(0deg, rgba(112, 199, 163, 0.035) 1px, transparent 1px),
    linear-gradient(180deg, #050504 0%, #100c08 54%, #060706 100%);
  background-size: 38px 38px, 38px 38px, 100% 100%;
  overflow: hidden;
}

button,
input {
  font: inherit;
}

button {
  cursor: pointer;
}

input {
  min-width: 0;
}

.app-shell {
  width: min(1680px, calc(100% - 24px));
  height: calc(100dvh - 24px);
  margin: 12px auto;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  gap: 10px;
}

.topbar,
.stage-panel,
.side-panel,
.panel-section {
  border: 1px solid var(--border);
  background:
    linear-gradient(180deg, rgba(40, 30, 18, 0.72), rgba(9, 8, 7, 0.92)),
    var(--ui-panel-body),
    var(--panel);
  background-size: auto, 64px 64px, auto;
  box-shadow: 0 16px 36px var(--shadow), inset 0 0 0 1px rgba(217, 165, 71, 0.08);
}

.topbar {
  min-height: 74px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  padding: 10px 12px;
  border-radius: 6px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 0;
}

.brand-mark {
  width: 48px;
  height: 48px;
  display: grid;
  place-items: center;
  border: 2px solid var(--gold);
  border-radius: 6px;
  color: #090705;
  background: linear-gradient(135deg, var(--gold), #745022);
  box-shadow: inset 0 0 0 2px rgba(0, 0, 0, 0.36), 0 0 18px rgba(217, 165, 71, 0.18);
  font-size: 1.65rem;
  font-weight: 800;
}

.brand-copy {
  min-width: 0;
}

.brand-copy h1,
.section-head h2 {
  margin: 0;
  font-size: 1.1rem;
  line-height: 1.1;
  text-transform: uppercase;
}

.brand-copy p {
  margin: 5px 0 0;
  color: var(--muted);
  font-size: 0.88rem;
}

.topbar-controls {
  display: flex;
  align-items: end;
  justify-content: flex-end;
  gap: 9px;
  flex-wrap: wrap;
}

.name-field {
  display: grid;
  gap: 4px;
  width: 188px;
  color: var(--muted);
  font-size: 0.78rem;
}

.name-field input,
.chat-form input {
  width: 100%;
  border: 8px solid transparent;
  border-image: var(--ui-input-frame) 16 fill / 8px stretch;
  border-radius: 4px;
  color: var(--text);
  background: #090807;
  padding: 3px 6px;
  outline: none;
  box-shadow: inset 0 0 0 1px rgba(217, 165, 71, 0.06);
}

.name-field input:focus,
.chat-form input:focus {
  border-color: var(--border-bright);
  box-shadow: 0 0 0 3px rgba(217, 165, 71, 0.12);
}

.metal-button {
  min-height: 36px;
  border: 8px solid transparent;
  border-image: var(--ui-button-frame) 16 fill / 8px stretch;
  border-radius: 4px;
  color: var(--text);
  background: #14100b;
  padding: 4px 8px;
  box-shadow: inset 0 0 0 1px rgba(255, 231, 170, 0.08);
}

.metal-button:hover,
.metal-button:focus-visible,
.metal-button.is-active {
  border-image-source: var(--ui-button-frame-hover);
  background: #19120a;
  outline: none;
}

.metal-button:active,
.metal-button.is-active {
  border-image-source: var(--ui-button-frame-active);
}

.status-pill {
  min-height: 36px;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  border: 7px solid transparent;
  border-image: var(--ui-button-frame) 16 fill / 7px stretch;
  border-radius: 4px;
  background: #090807;
  padding: 2px 5px;
  color: var(--muted);
  white-space: nowrap;
}

.status-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--gold);
  box-shadow: 0 0 10px rgba(217, 165, 71, 0.42);
}

body[data-status="online"] .status-dot {
  background: var(--teal);
  box-shadow: 0 0 10px rgba(112, 199, 163, 0.45);
}

body[data-status="offline"] .status-dot {
  background: var(--red);
  box-shadow: 0 0 10px rgba(185, 66, 58, 0.42);
}

.game-layout {
  position: relative;
  min-height: 0;
  display: grid;
  grid-template-columns: minmax(0, 1fr);
}

.stage-panel {
  min-width: 0;
  min-height: 0;
  border-radius: 6px;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto;
  overflow: hidden;
}

.meter-row {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px;
  padding: 10px;
  background: rgba(0, 0, 0, 0.22);
  border-bottom: 1px solid var(--border);
}

.meter-block {
  display: grid;
  gap: 4px;
}

.meter-block span {
  color: var(--muted);
  font-size: 0.78rem;
}

.meter {
  height: 18px;
  border: 5px solid transparent;
  border-image: var(--ui-meter-frame) 8 fill / 5px stretch;
  border-radius: 2px;
  background: #080706;
  overflow: hidden;
}

.meter i {
  display: block;
  width: 50%;
  height: 100%;
  background: linear-gradient(90deg, #741f1c, var(--red));
  box-shadow: inset 0 1px 0 rgba(255, 231, 170, 0.28);
}

.meter.mana i {
  background: linear-gradient(90deg, #1b477a, var(--blue));
}

.meter.xp i {
  background: linear-gradient(90deg, #745022, var(--gold));
}

.canvas-wrap {
  position: relative;
  min-height: 0;
  background: #050504;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
}

#worldCanvas {
  display: block;
  width: 100%;
  height: 100%;
  min-height: 420px;
  outline: none;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
}

.minimap {
  position: absolute;
  right: clamp(384px, 28vw, 448px);
  top: 12px;
  width: 180px;
  height: 130px;
  border: 10px solid transparent;
  border-image: var(--ui-minimap-frame) 24 fill / 10px stretch;
  border-radius: 4px;
  background: #090807;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.42);
  overflow: hidden;
}

.minimap canvas {
  width: 100%;
  height: 100%;
  display: block;
}

.floating-log {
  position: absolute;
  left: 12px;
  bottom: 12px;
  width: min(520px, calc(100% - 220px));
  display: grid;
  gap: 5px;
  pointer-events: none;
}

.floating-log div {
  width: fit-content;
  max-width: 100%;
  border: 1px solid rgba(217, 165, 71, 0.32);
  border-radius: 6px;
  background: rgba(8, 7, 6, 0.82);
  color: var(--text);
  padding: 6px 8px;
  font-size: 0.86rem;
}

.touch-pad {
  display: none;
}

.action-bar {
  display: flex;
  gap: 8px;
  align-items: center;
  flex-wrap: wrap;
  padding: 10px;
  border-top: 1px solid var(--border);
  background: rgba(0, 0, 0, 0.25);
}

.action-bar .metal-button {
  min-width: 72px;
}

#interactButton {
  margin-left: auto;
}

.side-panel {
  --right-panel: clamp(296px, 24vw, 354px);
  --left-panel: clamp(300px, 25vw, 382px);
  position: absolute;
  inset: 60px 12px 62px;
  z-index: 6;
  min-width: 0;
  min-height: 0;
  border: 0;
  border-image: none;
  background: transparent;
  background-image: none;
  box-shadow: none;
  pointer-events: none;
}

.panel-section {
  position: absolute;
  min-height: 0;
  border: 10px solid transparent;
  border-image: var(--ui-panel-frame) 24 fill / 10px stretch;
  border-radius: 4px;
  padding: 8px;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  pointer-events: auto;
  backdrop-filter: blur(1px);
}

.panel-section::before {
  content: "";
  position: absolute;
  inset: 3px;
  border: 1px solid rgba(217, 165, 71, 0.12);
  border-radius: 4px;
  pointer-events: none;
}

.roster-section,
.quest-section,
.inventory-section {
  right: 0;
  width: var(--right-panel);
}

.roster-section {
  top: 0;
  height: 126px;
}

.quest-section {
  top: 136px;
  height: 158px;
}

.inventory-section {
  bottom: 0;
  height: 194px;
}

.lore-section,
.chat-section {
  left: 0;
  width: var(--left-panel);
}

.lore-section {
  top: 0;
  height: 172px;
}

.chat-section {
  bottom: 0;
  height: 204px;
}

.section-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding-bottom: 8px;
  margin-bottom: 8px;
  border-bottom: 1px solid rgba(217, 165, 71, 0.24);
}

.section-head::after {
  content: "";
  width: 48px;
  height: 16px;
  flex: 0 0 auto;
  background: var(--ui-section-grip) center / 48px 16px no-repeat;
  opacity: 0.75;
}

.section-head h2 {
  font-size: 0.94rem;
}

.section-head span {
  color: var(--muted);
  font-size: 0.82rem;
}

.roster,
.quest-list,
.messages {
  flex: 1;
  min-height: 0;
  overflow: auto;
  display: grid;
  gap: 7px;
  padding-right: 2px;
  scrollbar-color: var(--gold2, #7a521e) #080706;
  scrollbar-width: thin;
}

.roster::-webkit-scrollbar,
.quest-list::-webkit-scrollbar,
.messages::-webkit-scrollbar,
.lore-panel::-webkit-scrollbar,
.sheet-preview::-webkit-scrollbar {
  width: 10px;
}

.roster::-webkit-scrollbar-track,
.quest-list::-webkit-scrollbar-track,
.messages::-webkit-scrollbar-track,
.lore-panel::-webkit-scrollbar-track,
.sheet-preview::-webkit-scrollbar-track {
  background: #080706;
}

.roster::-webkit-scrollbar-thumb,
.quest-list::-webkit-scrollbar-thumb,
.messages::-webkit-scrollbar-thumb,
.lore-panel::-webkit-scrollbar-thumb,
.sheet-preview::-webkit-scrollbar-thumb {
  border: 2px solid #080706;
  background: #7a521e;
}

.roster-item,
.quest-item,
.message,
.lore-panel {
  border: 7px solid transparent;
  border-image: var(--ui-row-frame) 18 fill / 7px stretch;
  border-radius: 4px;
  background: rgba(5, 5, 4, 0.62);
  padding: 5px;
}

.roster-item {
  display: flex;
  align-items: center;
  gap: 8px;
}

.avatar-dot {
  width: 14px;
  height: 14px;
  border-radius: 50%;
  border: 1px solid rgba(255, 231, 170, 0.42);
  flex: 0 0 auto;
}

.roster-copy {
  min-width: 0;
  flex: 1;
}

.roster-name,
.message-name {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-weight: 700;
}

.roster-meta,
.message-text,
.quest-meta,
.lore-panel p {
  color: var(--muted);
  font-size: 0.82rem;
  line-height: 1.32;
}

.quest-item.is-done {
  box-shadow: 0 0 0 1px rgba(112, 199, 163, 0.44), inset 0 0 18px rgba(112, 199, 163, 0.08);
}

.quest-title {
  display: flex;
  justify-content: space-between;
  gap: 8px;
  font-weight: 700;
}

.quest-bar {
  height: 13px;
  border: 4px solid transparent;
  border-image: var(--ui-meter-frame) 8 fill / 4px stretch;
  border-radius: 2px;
  background: #080706;
  margin-top: 7px;
  overflow: hidden;
}

.quest-bar i {
  display: block;
  height: 100%;
  width: 0;
  background: linear-gradient(90deg, var(--teal), var(--gold));
}

.inventory-grid {
  flex: 1;
  min-height: 0;
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  grid-auto-rows: minmax(42px, 1fr);
  gap: 6px;
}

.slot {
  min-height: 42px;
  border: 0;
  border-radius: 4px;
  background:
    var(--ui-slot-frame) center / 100% 100% no-repeat,
    linear-gradient(135deg, rgba(217, 165, 71, 0.09), transparent 46%),
    #090807;
  display: grid;
  place-items: center;
  position: relative;
  overflow: hidden;
}

.slot .item-sprite {
  width: 28px;
  height: 28px;
  display: grid;
  place-items: center;
  border-radius: 4px;
  border: 1px solid rgba(217, 165, 71, 0.42);
  color: var(--text);
  background: rgba(217, 165, 71, 0.12);
  background-repeat: no-repeat;
  image-rendering: pixelated;
  font-size: 0.88rem;
}

.slot small {
  position: absolute;
  right: 4px;
  bottom: 2px;
  color: var(--muted);
  font-size: 0.72rem;
}

.lore-panel {
  overflow: auto;
}

.lore-panel strong {
  display: block;
  margin-bottom: 6px;
}

.sheet-preview {
  min-height: 0;
  margin-top: 8px;
  border: 7px solid transparent;
  border-image: var(--ui-row-frame) 18 fill / 7px stretch;
  border-radius: 4px;
  overflow: auto;
  background: #050504;
}

.sheet-preview img {
  display: block;
  width: 100%;
  height: auto;
}

.message {
  display: grid;
  gap: 3px;
}

.message.system .message-name {
  color: var(--gold);
}

.message.mine {
  border-color: rgba(112, 199, 163, 0.44);
}

.chat-form {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 7px;
  margin-top: 8px;
}

body[data-panel="players"] .tab-button[data-tab="players"],
body[data-panel="quests"] .tab-button[data-tab="quests"],
body[data-panel="inventory"] .tab-button[data-tab="inventory"],
body[data-panel="lore"] .tab-button[data-tab="lore"] {
  border-image-source: var(--ui-button-frame-active);
  background: #19120a;
}

body[data-panel="players"] .roster-section,
body[data-panel="quests"] .quest-section,
body[data-panel="inventory"] .inventory-section,
body[data-panel="lore"] .lore-section {
  z-index: 2;
  border-image-source: var(--ui-panel-frame-active);
  box-shadow: 0 18px 42px rgba(0, 0, 0, 0.68), 0 0 0 1px rgba(217, 165, 71, 0.28), inset 0 0 0 1px rgba(217, 165, 71, 0.1);
}

@media (max-width: 1120px) {
  body {
    overflow: auto;
  }

  .app-shell {
    height: auto;
    min-height: calc(100dvh - 20px);
    width: min(100% - 16px, 920px);
    margin: 8px auto;
  }

  .topbar {
    align-items: stretch;
    flex-direction: column;
  }

  .topbar-controls {
    justify-content: stretch;
  }

  .name-field {
    flex: 1 1 180px;
    width: auto;
  }

  .game-layout {
    grid-template-columns: 1fr;
    gap: 10px;
  }

  .stage-panel {
    min-height: 620px;
  }

  .minimap {
    right: 12px;
  }

  .side-panel {
    position: static;
    display: grid;
    grid-template-rows: repeat(5, minmax(130px, auto));
    gap: 8px;
    min-height: 760px;
    padding: 0;
    pointer-events: auto;
  }

  .panel-section {
    position: relative;
    inset: auto;
    width: auto;
    height: auto;
  }
}

@media (max-width: 680px) {
  .meter-row {
    grid-template-columns: 1fr;
  }

  #worldCanvas {
    min-height: 460px;
  }

  .minimap {
    right: 12px;
    width: 132px;
    height: 96px;
  }

  .floating-log {
    width: calc(100% - 24px);
    bottom: 88px;
  }

  .action-bar .metal-button {
    flex: 1 1 72px;
  }

  #interactButton {
    margin-left: 0;
  }
}

@media (pointer: coarse) {
  .touch-pad {
    position: absolute;
    right: 12px;
    bottom: 12px;
    width: 144px;
    display: grid;
    grid-template-columns: repeat(3, 44px);
    grid-template-rows: repeat(2, 44px);
    gap: 6px;
    pointer-events: auto;
  }

  .touch-pad button {
    border: 1px solid rgba(217, 165, 71, 0.46);
    border-radius: 6px;
    color: var(--text);
    background: rgba(8, 7, 6, 0.78);
  }

  .touch-pad [data-key="up"] {
    grid-column: 2;
  }

  .touch-pad [data-key="left"] {
    grid-column: 1;
    grid-row: 2;
  }

  .touch-pad [data-key="down"] {
    grid-column: 2;
    grid-row: 2;
  }

  .touch-pad [data-key="right"] {
    grid-column: 3;
    grid-row: 2;
  }

  .touch-pad [data-key="attack"] {
    grid-column: 3;
    grid-row: 1;
  }
}
