*,
*::before,
*::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

:root {
  --bg-deep: #0d1117;
  --bg-panel: #161b22;
  --bg-panel-2: #1c2330;
  --border: #30363d;
  --text: #e6edf3;
  --text-muted: #8b949e;
  --accent: #3fb950;
  --accent-hover: #56d364;
  --danger: #f85149;
  --warning: #d29922;
  --info: #58a6ff;
  --shadow: 0 8px 32px rgba(0, 0, 0, 0.45);
  --radius: 10px;
  --font: "Segoe UI", system-ui, -apple-system, sans-serif;
  --ink: #24160b;
  --parchment: #ead7a8;
  --parchment-dark: #d4b984;
  --wood: #4a2e16;
  --wood-dark: #2c180c;
  --gold: #d4b36a;
  --ember: #9c3a1c;
  --font-title: "Cinzel", Palatino, "Palatino Linotype", serif;
  --font-lore: "IM Fell English", Palatino, "Palatino Linotype", Georgia, serif;
}

html,
body {
  width: 100%;
  height: 100%;
  height: 100dvh;
  overflow: hidden;
  background: #140c06;
  color: var(--text);
  font-family: var(--font);
  user-select: none;
  -webkit-user-select: none;
  touch-action: none;
  overscroll-behavior: none;
  -webkit-tap-highlight-color: transparent;
}

#app {
  position: relative;
  width: 100%;
  height: 100%;
}

#game-canvas {
  display: none;
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  background: #1a2e1a;
  cursor: crosshair;
}

#game-canvas.active {
  display: block;
}

#ui-root {
  position: absolute;
  inset: 0;
  z-index: 10;
  pointer-events: none;
}

#ui-root .screen,
#ui-root .modal-overlay,
#ui-root .lobby-toast,
#ui-root .pause-overlay,
#ui-root .death-overlay,
#ui-root .side-panel,
#ui-root .hud-backpack,
#ui-root .hud-pickaxe,
#ui-root .hud-quest,
#ui-root .hud-fullscreen,
#ui-root .hud-action-stack,
#ui-root .hud-minimap,
#ui-root .quest-modal,
#ui-root .shop-modal,
#ui-root .build-tool-panel,
#ui-root .inv-modal,
#ui-root .fishing-card,
#ui-root .mp-screen,
#ui-root .mp-pass-overlay,
#ui-root .mp-room-list,
#ui-root .mc-stick,
#ui-root .mc-btn,
#ui-root .btn,
#ui-root input,
#ui-root select,
#ui-root button,
#ui-root .admin-app,
#ui-root .admin-gate {
  pointer-events: auto;
}

/* ——— Screens / lobby ——— */
.screen {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: flex-start;
  padding: 5vh 5vw;
  font-family: var(--font-lore);
  color: var(--parchment);
  overflow-y: auto;
  background:
    linear-gradient(90deg, rgba(8, 4, 2, 0.72) 0%, rgba(8, 4, 2, 0.42) 42%, rgba(8, 4, 2, 0.22) 100%),
    url("assets/ui/lobby-bg.png") center / cover no-repeat;
}

.screen.hidden {
  display: none;
}

.hidden {
  display: none !important;
}

.lobby-screen {
  padding-top: 110px;
}

.lobby-cluster {
  width: min(420px, 100%);
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

.lobby-cluster-wide {
  width: min(460px, 100%);
}

.lobby-brand h1,
.panel h1,
.modal h2,
.pause-overlay h1 {
  font-family: var(--font-title);
  font-weight: 700;
  letter-spacing: 0.12em;
  text-transform: uppercase;
}

.lobby-brand h1 {
  font-size: clamp(2rem, 4vw, 2.8rem);
  color: #f3e2b6;
  text-shadow: 0 2px 0 #2a1608, 0 10px 24px rgba(0, 0, 0, 0.55);
  margin: 0.1rem 0 0.25rem;
}

.game-kicker {
  margin: 0;
  font-size: 0.85rem;
  letter-spacing: 0.28em;
  text-transform: uppercase;
  color: var(--gold);
}

.lobby-welcome {
  margin: 0;
  color: #e8d3a4;
  font-size: 1.05rem;
}

.lobby-welcome strong {
  color: #fff1c8;
}

.panel {
  width: min(400px, 92vw);
  padding: 1.5rem 1.4rem 1.25rem;
  background: var(--bg-panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

.panel.parchment,
.modal.parchment {
  color: var(--ink);
  background:
    radial-gradient(ellipse at 50% 0%, rgba(255, 236, 190, 0.55), transparent 52%),
    linear-gradient(180deg, #f0ddb4 0%, #e2c58a 100%);
  border: 3px solid #5c3a1c;
  border-radius: 3px;
  box-shadow:
    0 0 0 2px #c9a56a,
    0 18px 40px rgba(0, 0, 0, 0.55),
    inset 0 0 48px rgba(110, 70, 20, 0.12);
}

.lobby-cluster .panel.parchment {
  width: 100%;
}

.panel.parchment h1,
.panel.parchment h2,
.modal.parchment h2 {
  color: var(--wood-dark);
  font-size: 1.35rem;
  margin-bottom: 0.35rem;
}

.panel .subtitle,
.parchment .subtitle {
  color: #6a4a28;
  font-size: 0.98rem;
  margin-bottom: 1rem;
  font-style: italic;
}

.form-group {
  margin-bottom: 0.85rem;
}

.form-group label,
.field-label {
  display: block;
  font-size: 0.82rem;
  color: #6a4a28;
  margin-bottom: 0.3rem;
  letter-spacing: 0.06em;
  text-transform: uppercase;
}

.form-group input {
  width: 100%;
  padding: 0.7rem 0.85rem;
  background: var(--bg-deep);
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--text);
  font-size: 1rem;
  outline: none;
  transition: border-color 0.15s;
}

.parchment .form-group input,
.parchment .field {
  background: rgba(40, 24, 10, 0.88);
  border: 1px solid #8a6230;
  border-radius: 2px;
  color: #f6e7c3;
  font-family: var(--font-lore);
  font-size: 1.05rem;
}

.form-group input:focus,
.parchment .field:focus {
  border-color: var(--gold);
}

.gate-tabs {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0;
  margin: 0 0 1rem;
  border: 2px solid #5c3a1c;
  background: #cbb07a;
}

.gate-tab {
  appearance: none;
  border: none;
  background: transparent;
  color: #5a3a1a;
  font-family: var(--font-title);
  font-size: 0.78rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  padding: 0.65rem 0.4rem;
  cursor: pointer;
}

.gate-tab.is-on {
  background: #5c3a1c;
  color: #f3e2b6;
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.4rem;
  width: 100%;
  padding: 0.75rem 1rem;
  margin-top: 0.5rem;
  border: none;
  border-radius: 6px;
  font-size: 0.95rem;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s, transform 0.1s;
}

.btn:active {
  transform: scale(0.98);
}

.btn-primary {
  background: var(--accent);
  color: #0d1117;
}

.btn-primary:hover {
  background: var(--accent-hover);
}

.btn-secondary {
  background: var(--bg-panel-2);
  color: var(--text);
  border: 1px solid var(--border);
}

.btn-secondary:hover {
  background: #242b38;
}

.btn-ghost {
  background: transparent;
  color: var(--text-muted);
  border: 1px solid transparent;
}

.btn-ghost:hover {
  color: var(--text);
  border-color: var(--border);
}

.btn-danger {
  background: transparent;
  color: var(--danger);
  border: 1px solid var(--border);
}

.btn-danger:hover {
  background: rgba(248, 81, 73, 0.12);
}

.screen .btn,
.pause-overlay .btn,
.death-overlay .btn,
.modal-overlay .btn,
.mp-pass-overlay .btn {
  margin-top: 0.45rem;
  border-radius: 2px;
  border: 2px solid #5c3a1c;
  font-family: var(--font-title);
  font-size: 0.78rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.screen .btn-primary,
.pause-overlay .btn-primary,
.death-overlay .btn-primary,
.modal-overlay .btn-primary,
.mp-pass-overlay .btn-primary {
  background: linear-gradient(#8d3c1e, #5c2412);
  color: #f8e7b8;
  border-color: #c9a56a;
}

.screen .btn-primary:hover,
.pause-overlay .btn-primary:hover,
.modal-overlay .btn-primary:hover,
.mp-pass-overlay .btn-primary:hover {
  background: linear-gradient(#a84a24, #6d2c14);
}

.screen .btn-secondary,
.pause-overlay .btn-secondary,
.death-overlay .btn-secondary,
.modal-overlay .btn-secondary {
  background: linear-gradient(#6a4a28, #3d2916);
  color: #f0e2c4;
  border-color: #8a6230;
}

.screen .btn-secondary:hover,
.pause-overlay .btn-secondary:hover,
.modal-overlay .btn-secondary:hover {
  background: linear-gradient(#7a5730, #4a3218);
}

.screen .btn-ghost,
.pause-overlay .btn-ghost,
.mp-pass-overlay .btn-ghost {
  background: transparent;
  color: #6a4a28;
  border-color: transparent;
}

.screen .btn-ghost:hover,
.pause-overlay .btn-ghost:hover,
.mp-pass-overlay .btn-ghost:hover {
  color: var(--wood-dark);
  border-color: #8a6230;
}

.screen .btn-danger,
.pause-overlay .btn-danger {
  background: transparent;
  color: #7a2a18;
  border-color: #a06040;
}

.screen .btn-danger:hover,
.pause-overlay .btn-danger:hover {
  background: rgba(122, 42, 24, 0.12);
}

.error-msg {
  color: var(--danger);
  font-size: 0.85rem;
  min-height: 1.2rem;
  margin-bottom: 0.5rem;
}

.parchment .error-msg {
  color: #8b1e12;
}

.player-badge {
  text-align: center;
  color: var(--text-muted);
  font-size: 0.9rem;
  margin-bottom: 1.25rem;
}

.player-badge strong {
  color: var(--accent);
}

.menu-list {
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
}

.menu-list.hidden,
.char-pick.hidden {
  display: none;
}

.char-options {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.75rem;
  margin-bottom: 0.5rem;
}

.char-card {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.5rem;
  padding: 0.75rem 0.5rem;
  background: var(--bg-deep);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text);
  cursor: pointer;
  transition: border-color 0.15s, transform 0.1s;
}

.parchment .char-card {
  background: rgba(40, 24, 10, 0.9);
  border: 2px solid #8a6230;
  border-radius: 2px;
  color: #f0e2c4;
  font-family: var(--font-title);
  font-size: 0.72rem;
  letter-spacing: 0.06em;
  text-transform: uppercase;
}

.char-card:hover {
  border-color: var(--accent);
  transform: translateY(-2px);
}

.parchment .char-card:hover,
.char-card.selected {
  border-color: var(--gold);
  box-shadow: 0 0 0 1px var(--gold);
}

.char-card img {
  width: 96px;
  height: 168px;
  object-fit: contain;
  image-rendering: auto;
}

.btn:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

@media (max-width: 760px) {
  .screen {
    justify-content: center;
    padding: 3vh 4vw;
    background-position: 62% center;
    background-image:
      linear-gradient(rgba(8, 4, 2, 0.62), rgba(8, 4, 2, 0.7)),
      url("assets/ui/lobby-bg.png");
    background-size: cover;
    background-repeat: no-repeat;
  }
}

/* ——— Modal ——— */
.modal-overlay {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(0, 0, 0, 0.55);
  z-index: 50;
}

.modal-overlay.hidden {
  display: none;
}

.modal {
  width: min(420px, 92vw);
  max-height: 85vh;
  overflow-y: auto;
  padding: 1.5rem;
  background: var(--bg-panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

.modal.parchment {
  font-family: var(--font-lore);
}

.modal.parchment .setting-row label {
  color: var(--ink);
}

.modal.parchment select {
  background: rgba(40, 24, 10, 0.88);
  border: 1px solid #8a6230;
  color: #f6e7c3;
  font-family: var(--font-lore);
}

.modal.parchment .controls-help {
  background: rgba(40, 24, 10, 0.12);
  border: 1px solid #c9a56a;
  color: #5a3a1a;
}

.modal h2 {
  font-size: 1.25rem;
  margin-bottom: 1.25rem;
}

.setting-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  margin-bottom: 1rem;
  font-size: 0.9rem;
}

.setting-row label {
  color: var(--text-muted);
}

.setting-row input[type="range"] {
  width: 140px;
}

.setting-row select {
  padding: 0.4rem 0.6rem;
  background: var(--bg-deep);
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--text);
}

.controls-help {
  margin-top: 0.5rem;
  padding: 0.85rem;
  background: var(--bg-deep);
  border-radius: 6px;
  font-size: 0.8rem;
  color: var(--text-muted);
  line-height: 1.6;
}

.controls-help kbd {
  display: inline-block;
  padding: 0.1rem 0.4rem;
  background: var(--bg-panel-2);
  border: 1px solid var(--border);
  border-radius: 4px;
  font-family: inherit;
  color: var(--text);
}

/* ——— HUD ——— */
.hud {
  position: absolute;
  inset: 0;
  pointer-events: none;
  z-index: 20;
  font-family: "Palatino Linotype", Palatino, "Book Antiqua", Georgia, serif;
}

.hud.hidden {
  display: none;
}

.hud-panel {
  background:
    linear-gradient(180deg, rgba(58, 42, 24, 0.92), rgba(28, 18, 10, 0.94));
  border: 2px solid #8a6a3a;
  box-shadow:
    0 0 0 1px #2a1a0c,
    0 8px 24px rgba(0, 0, 0, 0.55),
    inset 0 1px 0 rgba(232, 200, 140, 0.25);
  color: #f0e2c4;
  border-radius: 4px;
}

.hud-panel-title {
  font-size: 0.7rem;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: #c9a56a;
  margin-bottom: 0.55rem;
  text-align: center;
  border-bottom: 1px solid rgba(138, 106, 58, 0.55);
  padding-bottom: 0.35rem;
}

.hud-top-left {
  position: absolute;
  top: 36px;
  left: 16px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 12px 14px 14px;
  min-width: 200px;
}

.hud-resources {
  position: absolute;
  top: 36px;
  right: 16px;
  padding: 12px 14px 14px;
  min-width: 170px;
}

.hud-clock {
  position: absolute;
  top: 36px;
  left: 50%;
  transform: translateX(-50%);
  padding: 10px 18px 12px;
  min-width: 140px;
  text-align: center;
}

.hud-xp-top {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 22px;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 0 12px;
  background: linear-gradient(180deg, rgba(28, 18, 10, 0.92), rgba(18, 12, 6, 0.75));
  border-bottom: 1px solid #6b4e28;
  pointer-events: none;
  z-index: 30;
}

.hud-xp-track {
  flex: 1;
  height: 6px;
  background: rgba(10, 6, 2, 0.85);
  border: 1px solid #6b4e28;
  border-radius: 2px;
  overflow: hidden;
}

.hud-xp-fill {
  display: block;
  height: 100%;
  background: linear-gradient(90deg, #3fb950, #7ee787);
  transition: width 0.2s;
}

.hud-xp-meta {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 0.72rem;
  color: #e8d7b0;
  white-space: nowrap;
  font-family: "Palatino Linotype", Palatino, "Book Antiqua", Georgia, serif;
}

.hud-xp-icon {
  width: 12px;
  height: 12px;
  object-fit: contain;
}

.hud-xp-sep {
  opacity: 0.5;
}

.hud-fullscreen {
  display: none;
  flex-shrink: 0;
  align-items: center;
  justify-content: center;
  width: 22px;
  height: 22px;
  padding: 0;
  margin-left: 2px;
  border: 1px solid #6b4e28;
  border-radius: 3px;
  background: rgba(28, 18, 10, 0.9);
  cursor: pointer;
  pointer-events: auto;
  touch-action: manipulation;
}

html.is-touch .hud-fullscreen {
  display: flex;
  width: 28px;
  height: 22px;
}

html.is-touch .hud-xp-top {
  padding-right: 8px;
}

.hud-fullscreen img {
  width: 14px;
  height: 14px;
  object-fit: contain;
}

.hud-fullscreen.is-active {
  border-color: #c9a56a;
  background: rgba(80, 56, 24, 0.95);
}

.hud-clock.is-night {
  border-color: #4a5d8a;
  box-shadow:
    0 0 0 1px #1a2038,
    0 8px 24px rgba(0, 0, 0, 0.55),
    inset 0 1px 0 rgba(140, 170, 220, 0.2);
}

.clock-time {
  font-size: 1.45rem;
  font-weight: 700;
  color: #ffe7b0;
  letter-spacing: 0.06em;
  line-height: 1.2;
}

.clock-phase {
  margin-top: 0.25rem;
  font-size: 0.75rem;
  color: #c9a56a;
  letter-spacing: 0.04em;
}

.resource-row {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.resource-item {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 0.9rem;
  color: #e8d7b0;
}

.resource-item strong {
  margin-left: auto;
  color: #ffe7b0;
  font-size: 1rem;
}

.resource-coins strong {
  color: #f4d35e;
}

.hud-tool {
  position: absolute;
  bottom: 16px;
  left: 50%;
  transform: translateX(-50%);
  padding: 8px 18px;
  font-size: 0.85rem;
  color: #d7c39a;
  white-space: nowrap;
}

.hud-tool strong {
  color: #ffe7b0;
}

.hud-minimap {
  position: absolute;
  left: 16px;
  bottom: 70px;
  width: 200px;
  height: 150px;
  z-index: 36;
  pointer-events: auto;
  cursor: pointer;
}

.hud-minimap canvas {
  width: 100%;
  height: 100%;
  display: block;
  background: #12180e;
  border: 2px solid #8a6a3a;
  border-radius: 4px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.45);
  image-rendering: auto;
}

.minimap-label {
  position: absolute;
  left: 6px;
  top: 4px;
  font-size: 0.65rem;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: #c9a56a;
  text-shadow: 0 1px 2px #000;
  pointer-events: none;
}

.hud-minimap.is-expanded {
  left: 50%;
  top: 52%;
  bottom: auto;
  width: min(70vw, 620px);
  height: min(52.5vw, 465px);
  transform: translate(-50%, -50%);
  z-index: 60;
}

html.is-touch .hud-minimap {
  left: max(10px, env(safe-area-inset-left));
  bottom: calc(148px + env(safe-area-inset-bottom, 0px));
  width: 112px;
  height: 84px;
}

html.is-touch .hud-minimap.is-expanded {
  width: min(92vw, 420px);
  height: min(69vw, 315px);
}

.hud-prompt {
  position: absolute;
  bottom: 72px;
  left: 50%;
  transform: translateX(-50%);
  padding: 10px 18px;
  background: linear-gradient(180deg, rgba(58, 42, 24, 0.95), rgba(28, 18, 10, 0.96));
  border: 2px solid #c9a56a;
  border-radius: 4px;
  font-size: 0.9rem;
  color: #f0e2c4;
  opacity: 0;
  transition: opacity 0.15s;
  white-space: nowrap;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.45);
}

.hud-prompt.visible {
  opacity: 1;
}

.hud-prompt kbd {
  display: inline-block;
  padding: 0.1rem 0.45rem;
  margin-right: 0.35rem;
  background: #8a6a3a;
  color: #1a1208;
  border-radius: 3px;
  font-weight: 700;
  font-family: inherit;
}

.stat-bar {
  display: flex;
  align-items: center;
  gap: 8px;
}

.stat-icon {
  width: 1.1rem;
  text-align: center;
  filter: drop-shadow(0 1px 1px rgba(0, 0, 0, 0.6));
}

.stat-value {
  min-width: 3.4rem;
  text-align: right;
  font-size: 0.8rem;
  color: #e8d7b0;
}

.stat-bar .bar {
  flex: 1;
  height: 10px;
  background: rgba(10, 6, 2, 0.75);
  border: 1px solid #6b4e28;
  border-radius: 2px;
  overflow: hidden;
  box-shadow: inset 0 1px 3px rgba(0, 0, 0, 0.55);
}

.stat-bar .bar > span {
  display: block;
  height: 100%;
  border-radius: 1px;
  transition: width 0.2s;
}

.bar-health > span {
  background: linear-gradient(180deg, #d64545, #8b1e1e);
}

.bar-hunger > span {
  background: linear-gradient(180deg, #d4a017, #8a5a10);
}

.bar-fatigue > span {
  background: linear-gradient(180deg, #8e7cc3, #4a3f7a);
}

.bar-thirst > span {
  background: linear-gradient(180deg, #5dade2, #1a5276);
}

.bar-xp > span {
  background: linear-gradient(180deg, #7ee787, #2ea043);
}

.stat-icon-img {
  width: 18px;
  height: 18px;
  object-fit: contain;
  flex-shrink: 0;
  filter: drop-shadow(0 1px 1px rgba(0, 0, 0, 0.5));
}

.mp-panel {
  max-width: 480px;
}

.mp-screen {
  pointer-events: auto;
  z-index: 50;
}

.mp-tabs {
  display: flex;
  gap: 8px;
  margin: 0.75rem 0 1rem;
}

.mp-tabs .btn {
  flex: 1;
  margin-top: 0;
}

.field-label {
  display: block;
  margin: 0.55rem 0 0.25rem;
  font-size: 0.78rem;
  color: #6a4a28;
  letter-spacing: 0.06em;
}

.field {
  width: 100%;
  padding: 0.55rem 0.7rem;
  border: 1px solid #6b4e28;
  border-radius: 4px;
  background: rgba(10, 6, 2, 0.55);
  color: #f0e2c4;
  font-family: inherit;
  pointer-events: auto;
}

.mp-status {
  margin-top: 0.9rem;
  font-size: 0.95rem;
  font-style: italic;
  color: #4a6a38;
  min-height: 1.2em;
}

.mp-status.is-error {
  color: #f85149;
}

.mp-actions {
  display: flex;
  gap: 8px;
  margin-top: 0.8rem;
}

.mp-actions .btn {
  flex: 1;
  margin-top: 0;
  pointer-events: auto;
}

.mp-room-list {
  display: flex;
  flex-direction: column;
  gap: 6px;
  max-height: 220px;
  overflow-y: auto;
  margin: 0.25rem 0 0.4rem;
  padding: 6px;
  border: 2px solid #8a6230;
  border-radius: 2px;
  background: rgba(40, 24, 10, 0.18);
  pointer-events: auto;
}

.mp-room-empty {
  margin: 0;
  padding: 10px 8px;
  font-size: 0.82rem;
  color: var(--text-muted);
  text-align: center;
}

.mp-room-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
  width: 100%;
  padding: 0.55rem 0.7rem;
  border: 1px solid #6b4e28;
  border-radius: 4px;
  background: rgba(58, 42, 24, 0.9);
  color: #f0e2c4;
  cursor: pointer;
  font-family: inherit;
  text-align: left;
}

.mp-room-item:hover {
  border-color: #c9a56a;
}

.mp-room-name {
  font-weight: 700;
}

.mp-room-meta {
  font-size: 0.75rem;
  color: #c9a56a;
  white-space: nowrap;
}

.mp-refresh {
  width: 100%;
  margin: 0 0 0.75rem;
}

.mp-create-box {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.mp-create-box .btn {
  margin-top: 4px;
}

.mp-pass-overlay {
  position: absolute;
  inset: 0;
  z-index: 60;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(0, 0, 0, 0.55);
  pointer-events: auto;
}

.mp-pass-overlay.hidden {
  display: none;
}

.mp-pass-box {
  width: min(360px, 90vw);
}

.mp-hint {
  margin-top: 1rem;
  font-size: 0.72rem;
  color: #b89b6a;
  line-height: 1.45;
}

.mp-hint code {
  color: #ffe7b0;
}

.char-options.compact {
  gap: 8px;
}

.char-options.compact .char-card {
  padding: 8px;
  pointer-events: auto;
}

.char-card.selected {
  border-color: #c9a56a;
  box-shadow: 0 0 0 1px #c9a56a;
}

.hud-action-stack {
  position: absolute;
  bottom: 16px;
  right: 16px;
  display: flex;
  flex-direction: row;
  align-items: flex-end;
  gap: 10px;
  pointer-events: none;
  z-index: 40;
}

.hud-backpack,
.hud-pickaxe,
.hud-quest {
  position: relative;
  bottom: auto;
  right: auto;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  padding: 10px 12px 8px;
  background: linear-gradient(180deg, rgba(58, 42, 24, 0.94), rgba(28, 18, 10, 0.96));
  border: 2px solid #8a6a3a;
  border-radius: 6px;
  color: #f0e2c4;
  cursor: pointer;
  pointer-events: auto;
  font-family: "Palatino Linotype", Palatino, "Book Antiqua", Georgia, serif;
  font-size: 0.75rem;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.45);
  transition: border-color 0.15s, transform 0.1s;
}

.hud-backpack:hover,
.hud-pickaxe:hover,
.hud-quest:hover {
  border-color: #c9a56a;
  transform: translateY(-2px);
}

.hud-backpack img,
.hud-pickaxe img,
.hud-quest img {
  width: 48px;
  height: 48px;
  object-fit: contain;
}

.quest-modal {
  position: absolute;
  inset: 0;
  z-index: 46;
  display: flex;
  align-items: center;
  justify-content: center;
  pointer-events: auto;
}

.quest-modal.hidden {
  display: none;
}

.quest-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(8, 5, 2, 0.55);
}

.quest-panel {
  position: relative;
  width: min(400px, 92vw);
  max-height: min(78vh, 560px);
  overflow: auto;
  padding: 14px 16px 16px;
  background:
    linear-gradient(180deg, rgba(58, 42, 24, 0.97), rgba(28, 18, 10, 0.98));
  border: 2px solid #8a6a3a;
  border-radius: 6px;
  box-shadow:
    0 0 0 1px #2a1a0c,
    0 16px 40px rgba(0, 0, 0, 0.65),
    inset 0 1px 0 rgba(232, 200, 140, 0.25);
  color: #f0e2c4;
  font-family: "Palatino Linotype", Palatino, "Book Antiqua", Georgia, serif;
}

.quest-head {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 4px;
}

.quest-head img {
  width: 26px;
  height: 26px;
  object-fit: contain;
}

.quest-head span {
  flex: 1;
  font-size: 1.05rem;
  color: #ffe7b0;
  letter-spacing: 0.04em;
}

.quest-x {
  background: transparent;
  border: 1px solid #6b4e28;
  color: #e8d7b0;
  width: 28px;
  height: 28px;
  border-radius: 4px;
  cursor: pointer;
  font-size: 1rem;
  line-height: 1;
}

.quest-sub {
  margin: 0 0 12px;
  font-size: 0.75rem;
  color: #c9a56a;
}

.quest-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.quest-row {
  display: grid;
  grid-template-columns: 40px 1fr auto;
  gap: 10px;
  align-items: center;
  padding: 8px 10px;
  background: rgba(10, 6, 2, 0.45);
  border: 1px solid #6b4e28;
  border-radius: 4px;
}

.quest-row.is-done {
  opacity: 0.62;
  border-color: #3d7a3a;
}

.quest-row > img {
  width: 40px;
  height: 40px;
  object-fit: contain;
}

.quest-body {
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 3px;
}

.quest-body strong {
  font-size: 0.82rem;
  color: #ffe7b0;
}

.quest-body small {
  font-size: 0.68rem;
  color: #c4b48a;
}

.quest-bar {
  display: block;
  height: 5px;
  background: rgba(10, 6, 2, 0.8);
  border: 1px solid #6b4e28;
  border-radius: 2px;
  overflow: hidden;
}

.quest-bar i {
  display: block;
  height: 100%;
  background: linear-gradient(90deg, #c9a56a, #f4d35e);
}

.quest-row.is-done .quest-bar i {
  background: linear-gradient(90deg, #3d7a3a, #7ee787);
}

.quest-reward {
  display: flex;
  align-items: center;
  gap: 4px;
  font-size: 0.85rem;
  color: #f4d35e;
  white-space: nowrap;
}

.quest-reward img {
  width: 16px;
  height: 16px;
  object-fit: contain;
}

.shop-modal {
  position: absolute;
  inset: 0;
  z-index: 46;
  display: flex;
  align-items: center;
  justify-content: center;
  pointer-events: auto;
}

.shop-modal.hidden {
  display: none;
}

.shop-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(8, 5, 2, 0.55);
}

.shop-panel {
  position: relative;
  width: min(400px, 92vw);
  max-height: min(78vh, 560px);
  overflow: auto;
  padding: 14px 16px 16px;
  background:
    linear-gradient(180deg, rgba(58, 42, 24, 0.97), rgba(28, 18, 10, 0.98));
  border: 2px solid #8a6a3a;
  border-radius: 6px;
  box-shadow:
    0 0 0 1px #2a1a0c,
    0 16px 40px rgba(0, 0, 0, 0.65),
    inset 0 1px 0 rgba(232, 200, 140, 0.25);
  color: #f0e2c4;
  font-family: "Palatino Linotype", Palatino, "Book Antiqua", Georgia, serif;
}

.shop-head {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 4px;
}

.shop-head img {
  width: 32px;
  height: 32px;
  object-fit: contain;
}

.shop-head span {
  flex: 1;
  font-size: 1.05rem;
  color: #ffe7b0;
}

.shop-sub {
  margin: 0 0 12px;
  font-size: 0.8rem;
  color: #c9a56a;
}

.shop-sub strong {
  color: #f4d35e;
}

.shop-tabs {
  display: flex;
  gap: 6px;
  margin: 0 0 10px;
}

.shop-tab {
  flex: 1;
  padding: 7px 8px;
  font-size: 0.8rem;
  color: #c9a56a;
  background: rgba(10, 6, 2, 0.4);
  border: 1px solid #6b4e28;
  border-radius: 4px;
  cursor: pointer;
  font-family: inherit;
}

.shop-tab.is-active {
  color: #1c120a;
  background: linear-gradient(180deg, #ffe7b0, #c9a56a);
  border-color: #e8c88c;
}

.shop-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.shop-row {
  display: grid;
  grid-template-columns: 48px 1fr auto;
  gap: 10px;
  align-items: center;
  padding: 8px 10px;
  background: rgba(10, 6, 2, 0.45);
  border: 1px solid #6b4e28;
  border-radius: 4px;
}

.shop-row.is-locked {
  opacity: 0.7;
}

.shop-row > img {
  width: 48px;
  height: 48px;
  object-fit: contain;
}

.shop-body strong {
  display: block;
  font-size: 0.85rem;
  color: #ffe7b0;
}

.shop-body small {
  font-size: 0.7rem;
  color: #c4b48a;
}

.shop-buy {
  padding: 6px 10px;
  font-size: 0.78rem;
}

.shop-buy:disabled {
  opacity: 0.5;
  cursor: default;
}

.build-tool-divider {
  height: 1px;
  margin: 8px 0;
  background: rgba(138, 106, 58, 0.45);
}

.build-tool-list {
  display: flex;
  flex-direction: column;
  gap: 6px;
  max-height: 280px;
  overflow-y: auto;
  min-height: 0;
  flex: 1;
}

.build-tool-panel {
  position: absolute;
  bottom: 110px;
  right: 16px;
  width: min(300px, 92vw);
  max-height: min(70vh, 520px);
  padding: 12px;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  background:
    linear-gradient(180deg, rgba(58, 42, 24, 0.97), rgba(28, 18, 10, 0.98));
  border: 2px solid #8a6a3a;
  border-radius: 6px;
  color: #f0e2c4;
  pointer-events: auto;
  z-index: 41;
  box-shadow: 0 12px 28px rgba(0, 0, 0, 0.55);
  font-family: "Palatino Linotype", Palatino, "Book Antiqua", Georgia, serif;
}

.build-tool-panel.hidden {
  display: none;
}

.build-tool-title {
  font-size: 0.72rem;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: #c9a56a;
  margin-bottom: 10px;
  text-align: center;
}

.build-tool-item {
  width: 100%;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px;
  background: rgba(10, 6, 2, 0.45);
  border: 1px solid #6b4e28;
  border-radius: 4px;
  color: #f0e2c4;
  cursor: pointer;
  text-align: left;
  font-family: inherit;
}

.build-tool-item:hover {
  border-color: #c9a56a;
}

.build-tool-item img {
  width: 36px;
  height: 56px;
  object-fit: contain;
  flex-shrink: 0;
}

.build-tool-item strong {
  display: block;
  color: #ffe7b0;
  font-size: 0.92rem;
}

.build-tool-item small {
  display: block;
  margin-top: 2px;
  color: #b89b6a;
  font-size: 0.72rem;
  line-height: 1.3;
}

.build-tool-cancel {
  width: 100%;
  margin-top: 8px;
}

.hud-tool {
  display: flex;
  align-items: center;
  gap: 8px;
}

.hud-tool .tool-icon {
  width: 22px;
  height: 22px;
  object-fit: contain;
}

.inv-modal {
  position: absolute;
  inset: 0;
  z-index: 42;
  display: flex;
  align-items: center;
  justify-content: center;
  pointer-events: auto;
}

.inv-modal.hidden {
  display: none;
}

.inv-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(8, 5, 2, 0.55);
}

.inv-dialog {
  position: relative;
  width: min(420px, 92vw);
  padding: 16px 18px 14px;
  background:
    linear-gradient(180deg, rgba(58, 42, 24, 0.97), rgba(28, 18, 10, 0.98));
  border: 2px solid #8a6a3a;
  border-radius: 6px;
  box-shadow:
    0 0 0 1px #2a1a0c,
    0 16px 40px rgba(0, 0, 0, 0.65),
    inset 0 1px 0 rgba(232, 200, 140, 0.25);
  color: #f0e2c4;
  font-family: "Palatino Linotype", Palatino, "Book Antiqua", Georgia, serif;
}

.inv-panel {
  width: min(300px, 92vw);
}

.inv-header {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 14px;
}

.inv-header h3 {
  margin: 0;
  flex: 1;
  font-size: 1.1rem;
  color: #ffe7b0;
  letter-spacing: 0.04em;
}

.inv-header-icon {
  width: 28px;
  height: 28px;
  object-fit: contain;
}

.inv-close {
  background: transparent;
  border: 1px solid #6b4e28;
  color: #e8d7b0;
  width: 28px;
  height: 28px;
  border-radius: 4px;
  cursor: pointer;
  font-size: 1.1rem;
  line-height: 1;
}

.inv-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 8px;
}

.inv-slot {
  position: relative;
  aspect-ratio: 1;
  min-height: 78px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 4px;
  padding: 6px 4px 8px;
  background: rgba(10, 6, 2, 0.55);
  border: 1px solid #6b4e28;
  border-radius: 4px;
  box-shadow: inset 0 1px 3px rgba(0, 0, 0, 0.45);
  color: inherit;
  font: inherit;
  cursor: grab;
  touch-action: none;
}

.inv-slot:disabled {
  opacity: 1;
  cursor: default;
}

.inv-slot-usable {
  cursor: grab;
  transition: border-color 0.12s, transform 0.1s;
}

.inv-slot.is-dragging {
  opacity: 0.35;
}

.inv-drag-ghost {
  position: fixed;
  width: 48px;
  height: 48px;
  margin: 0;
  pointer-events: none;
  z-index: 90;
  transform: translate(-50%, -50%);
  filter: drop-shadow(0 6px 10px rgba(0, 0, 0, 0.55));
}

.inv-drag-ghost img {
  width: 100%;
  height: 100%;
  object-fit: contain;
}

.inv-slot-usable:hover {
  border-color: #c9a56a;
  transform: translateY(-1px);
}

.inv-slot-use {
  font-size: 0.58rem;
  color: #7ee787;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

.inv-slot-empty {
  pointer-events: none;
  cursor: default;
  opacity: 0.55;
  background: rgba(10, 6, 2, 0.35);
}

.inv-slot-icon {
  width: 36px;
  height: 36px;
  object-fit: contain;
}

.inv-slot-fallback {
  font-size: 1.4rem;
}

.inv-slot-qty {
  position: absolute;
  top: 4px;
  right: 6px;
  font-size: 0.75rem;
  font-weight: 700;
  color: #ffe7b0;
  text-shadow: 0 1px 2px #000;
}

.inv-slot-name {
  font-size: 0.65rem;
  color: #c9a56a;
  text-align: center;
  line-height: 1.15;
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.inv-icon {
  width: 28px;
  height: 28px;
  object-fit: contain;
  vertical-align: middle;
  margin-right: 6px;
}

.inv-item-left {
  display: inline-flex;
  align-items: center;
}

.inv-hint {
  margin-top: 12px;
  margin-bottom: 0;
  font-size: 0.72rem;
  color: #b89b6a;
  text-align: center;
}

.inv-empty {
  justify-content: center;
  color: #b89b6a;
}

.hud-hint {
  position: absolute;
  bottom: 16px;
  left: 16px;
  padding: 8px 12px;
  background: linear-gradient(180deg, rgba(40, 28, 14, 0.8), rgba(18, 12, 6, 0.85));
  border: 1px solid #6b4e28;
  border-radius: 4px;
  font-size: 0.72rem;
  color: #b89b6a;
  line-height: 1.5;
  font-family: "Segoe UI", system-ui, sans-serif;
}

.toast {
  padding: 7px 14px;
  background: linear-gradient(180deg, rgba(58, 42, 24, 0.55), rgba(28, 18, 10, 0.5));
  border: 1px solid rgba(201, 165, 106, 0.45);
  border-radius: 4px;
  font-size: 0.8rem;
  color: rgba(240, 226, 196, 0.75);
  opacity: 0.72;
  animation: toast-in 0.15s ease;
  box-shadow: none;
}

.toast.toast-out {
  animation: toast-out 0.35s ease forwards;
}

/* ——— Death ——— */
.death-overlay {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(8, 4, 2, 0.72);
  z-index: 45;
}

.death-panel {
  width: min(420px, 92vw);
  padding: 2rem 1.75rem 1.5rem;
  text-align: center;
  background:
    radial-gradient(ellipse at 50% 0%, rgba(120, 40, 30, 0.35), transparent 55%),
    linear-gradient(180deg, rgba(58, 42, 24, 0.96), rgba(22, 14, 8, 0.98));
  border: 2px solid #8a6a3a;
  box-shadow:
    0 0 0 1px #2a1a0c,
    0 16px 48px rgba(0, 0, 0, 0.65),
    inset 0 1px 0 rgba(232, 200, 140, 0.2);
  border-radius: 6px;
  color: #f0e2c4;
  font-family: "Palatino Linotype", Palatino, "Book Antiqua", Georgia, serif;
}

.death-ornament {
  font-size: 1.6rem;
  margin-bottom: 0.4rem;
  color: #c9a56a;
}

.death-panel h1 {
  font-size: 1.7rem;
  margin-bottom: 0.6rem;
  color: #ffe7b0;
  letter-spacing: 0.02em;
}

.death-sub {
  color: #c9b089;
  font-size: 0.92rem;
  line-height: 1.45;
  margin-bottom: 1.4rem;
}

/* ——— Inventory / Build panels ——— */
.side-panel {
  position: absolute;
  bottom: 16px;
  right: 16px;
  width: min(280px, 90vw);
  padding: 14px;
  background: rgba(13, 17, 23, 0.88);
  border: 1px solid var(--border);
  border-radius: 8px;
  backdrop-filter: blur(8px);
  pointer-events: auto;
  z-index: 25;
}

.side-panel.hidden {
  display: none;
}

.side-panel h3 {
  font-size: 0.95rem;
  margin-bottom: 10px;
}

.inv-list,
.build-list {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.inv-item,
.build-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 8px 10px;
  background: var(--bg-panel-2);
  border: 1px solid var(--border);
  border-radius: 6px;
  font-size: 0.85rem;
  cursor: pointer;
  transition: border-color 0.15s;
}

.build-item:hover,
.build-item.selected {
  border-color: var(--accent);
}

.build-item .cost {
  color: var(--text-muted);
  font-size: 0.8rem;
}

/* ——— Pause ——— */
.pause-overlay {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(10, 6, 2, 0.72);
  z-index: 40;
  font-family: var(--font-lore);
}

.pause-overlay.hidden {
  display: none;
}

/* ——— Toast ——— */
.toast-container {
  position: absolute;
  top: 100px;
  right: 18px;
  left: auto;
  transform: none;
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 5px;
  z-index: 30;
  pointer-events: none;
  max-width: min(260px, 42vw);
}

@keyframes toast-in {
  from {
    opacity: 0;
    transform: translateX(12px);
  }
  to {
    opacity: 0.72;
    transform: translateX(0);
  }
}

@keyframes toast-out {
  from {
    opacity: 0.72;
    transform: translateX(0);
  }
  to {
    opacity: 0;
    transform: translateX(16px);
  }
}

@media (max-width: 600px) {
  .panel {
    padding: 1.5rem;
  }

  .hud-hint {
    display: none;
  }
}

/* ——— Mobile touch controls ——— */
.mobile-controls {
  position: absolute;
  inset: 0;
  z-index: 35;
  pointer-events: none;
}

.mc-stick {
  position: absolute;
  left: max(16px, env(safe-area-inset-left));
  bottom: max(20px, env(safe-area-inset-bottom));
  width: 132px;
  height: 132px;
  pointer-events: auto;
  touch-action: none;
}

.mc-stick-base {
  position: absolute;
  inset: 10px;
  border-radius: 50%;
  background: rgba(20, 14, 8, 0.45);
  border: 2px solid rgba(201, 165, 106, 0.55);
  box-shadow: inset 0 0 20px rgba(0, 0, 0, 0.35);
}

.mc-stick-knob {
  position: absolute;
  left: 50%;
  top: 50%;
  width: 54px;
  height: 54px;
  border-radius: 50%;
  transform: translate(-50%, -50%);
  background: radial-gradient(circle at 35% 30%, #e8c88c, #8a6a3a 70%, #4a3418);
  border: 2px solid rgba(240, 226, 196, 0.65);
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.45);
  pointer-events: none;
}

.mc-actions {
  position: absolute;
  right: max(16px, env(safe-area-inset-right));
  bottom: max(24px, env(safe-area-inset-bottom));
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 14px;
  pointer-events: none;
}

.mc-btn {
  width: 68px;
  height: 68px;
  border-radius: 50%;
  border: 2px solid rgba(201, 165, 106, 0.7);
  background: rgba(28, 18, 10, 0.72);
  color: #f0e2c4;
  font-size: 1.35rem;
  font-weight: 700;
  pointer-events: auto;
  touch-action: none;
  box-shadow: 0 6px 18px rgba(0, 0, 0, 0.4);
  -webkit-user-select: none;
  user-select: none;
}

.mc-btn:active {
  transform: scale(0.94);
  border-color: #c9a56a;
}

.mc-attack {
  width: 78px;
  height: 78px;
  background: rgba(120, 42, 28, 0.78);
  border-color: rgba(240, 150, 110, 0.75);
  font-size: 1.55rem;
}

.mc-interact {
  font-family: var(--font);
  letter-spacing: 0.04em;
}

html.is-touch .hud-action-stack {
  bottom: calc(168px + env(safe-area-inset-bottom, 0px));
  right: max(12px, env(safe-area-inset-right));
}

html.is-touch .hud-backpack,
html.is-touch .hud-pickaxe,
html.is-touch .hud-quest {
  padding: 7px 8px 6px;
  font-size: 0.65rem;
}

html.is-touch .hud-backpack img,
html.is-touch .hud-pickaxe img,
html.is-touch .hud-quest img {
  width: 36px;
  height: 36px;
}

html.is-standalone .hud-fullscreen {
  display: none;
}

html.is-touch .build-tool-panel {
  bottom: calc(158px + env(safe-area-inset-bottom, 0px));
  right: max(10px, env(safe-area-inset-right));
  width: min(260px, calc(100vw - 20px));
  max-height: calc(100dvh - 188px - env(safe-area-inset-bottom, 0px));
  padding: 8px;
}

html.is-touch .build-tool-list {
  max-height: none;
}

html.is-touch .build-tool-item {
  padding: 6px 8px;
  gap: 8px;
}

html.is-touch .build-tool-item img {
  width: 28px;
  height: 34px;
}

html.is-touch .build-tool-item strong {
  font-size: 0.78rem;
}

html.is-touch .build-tool-item small {
  font-size: 0.6rem;
}

html.is-touch .inv-modal {
  display: flex;
  align-items: flex-end;
  justify-content: center;
  padding: 8px 8px calc(138px + env(safe-area-inset-bottom, 0px));
}

html.is-touch .inv-modal.hidden {
  display: none;
}

html.is-touch .inv-dialog {
  width: min(94vw, 380px);
  max-height: min(56vh, calc(100dvh - 170px));
  overflow: auto;
  padding: 10px 10px 8px;
}

html.is-touch .inv-header {
  margin-bottom: 8px;
}

html.is-touch .inv-header h3 {
  font-size: 0.95rem;
}

html.is-touch .inv-grid {
  gap: 4px;
}

html.is-touch .inv-slot {
  min-height: 0;
  aspect-ratio: 1;
  padding: 3px 2px 4px;
  gap: 1px;
}

html.is-touch .inv-slot-icon {
  width: 22px;
  height: 22px;
}

html.is-touch .inv-slot-qty {
  font-size: 0.62rem;
  top: 2px;
  right: 3px;
}

html.is-touch .inv-slot-name {
  font-size: 0.5rem;
}

html.is-touch .inv-hint,
html.is-touch .inv-slot-use {
  display: none;
}

html.is-touch .shop-panel,
html.is-touch .quest-panel {
  width: min(94vw, 400px);
  max-height: min(62vh, calc(100dvh - 150px));
}

html.is-touch .shop-row {
  grid-template-columns: 36px 1fr auto;
  padding: 6px 8px;
}

html.is-touch .shop-row > img {
  width: 36px;
  height: 36px;
}

html.is-touch .toast-container {
  top: 88px;
  max-width: min(220px, 48vw);
}

html.is-touch #game-canvas {
  cursor: default;
  touch-action: none;
}

/* Mobile HUD: slightly smaller panels tucked into corners (PC unchanged) */
html.is-touch .hud-top-left {
  top: 26px;
  left: 8px;
  min-width: 0;
  max-width: 168px;
  padding: 8px 9px 9px;
  gap: 5px;
  font-size: 0.8rem;
}

html.is-touch .hud-resources {
  top: 26px;
  right: 8px;
  min-width: 0;
  max-width: 148px;
  padding: 8px 9px 9px;
  font-size: 0.78rem;
}

html.is-touch .hud-clock {
  top: 26px;
  left: 50%;
  transform: translateX(-50%);
  min-width: 0;
  padding: 6px 12px 7px;
}

html.is-touch .hud-clock .clock-time {
  font-size: 1.05rem;
  line-height: 1.15;
}

html.is-touch .hud-clock .clock-phase {
  font-size: 0.72rem;
}

html.is-touch .hud-panel-title {
  font-size: 0.62rem;
  margin-bottom: 0.35rem;
  padding-bottom: 0.25rem;
  letter-spacing: 0.1em;
}

html.is-touch .stat-bar {
  gap: 5px;
}

html.is-touch .stat-value {
  font-size: 0.72rem;
  min-width: 44px;
}

html.is-touch .resource-row {
  gap: 4px;
}

html.is-touch .resource-item {
  font-size: 0.72rem;
}

/* Portrait phone */
@media (max-width: 700px) and (orientation: portrait) {
  .hud-hint {
    display: none;
  }

  html.is-touch .hud-top-left {
    top: 24px;
    left: 6px;
    max-width: 40vw;
    padding: 7px 8px 8px;
  }

  html.is-touch .hud-resources {
    top: 24px;
    right: 6px;
    max-width: 38vw;
    padding: 7px 8px 8px;
  }

  html.is-touch .hud-clock {
    top: 24px;
    padding: 5px 10px 6px;
  }

  .hud-prompt {
    bottom: calc(150px + env(safe-area-inset-bottom, 0px));
    font-size: 0.85rem;
  }

  .mc-stick {
    width: 120px;
    height: 120px;
    left: max(10px, env(safe-area-inset-left));
    bottom: max(14px, env(safe-area-inset-bottom));
  }

  .mc-stick-knob {
    width: 48px;
    height: 48px;
  }

  .mc-btn {
    width: 62px;
    height: 62px;
  }

  .mc-attack {
    width: 72px;
    height: 72px;
  }
}

/* Landscape phone */
@media (max-height: 500px) and (orientation: landscape) {
  html.is-touch .hud-top-left,
  html.is-touch .hud-resources,
  html.is-touch .hud-clock {
    top: 20px;
    padding: 5px 7px 6px;
    font-size: 0.74rem;
  }

  html.is-touch .hud-top-left {
    left: 6px;
    max-width: 150px;
  }

  html.is-touch .hud-resources {
    right: 6px;
    max-width: 140px;
  }

  .hud-xp-top {
    height: 18px;
  }

  .hud-prompt {
    bottom: calc(12px + env(safe-area-inset-bottom, 0px));
    left: 50%;
    transform: translateX(-50%);
  }

  .mc-stick {
    width: 110px;
    height: 110px;
    left: max(8px, env(safe-area-inset-left));
    bottom: max(8px, env(safe-area-inset-bottom));
  }

  .mc-actions {
    right: max(8px, env(safe-area-inset-right));
    bottom: max(8px, env(safe-area-inset-bottom));
    flex-direction: row;
    gap: 10px;
  }

  .mc-btn {
    width: 56px;
    height: 56px;
    font-size: 1.1rem;
  }

  .mc-attack {
    width: 64px;
    height: 64px;
    font-size: 1.3rem;
  }

  html.is-touch .hud-action-stack {
    bottom: max(12px, env(safe-area-inset-bottom));
    right: calc(210px + env(safe-area-inset-right, 0px));
  }

  html.is-touch .build-tool-panel {
    bottom: max(10px, env(safe-area-inset-bottom));
    right: calc(150px + env(safe-area-inset-right, 0px));
    max-height: calc(100dvh - 24px);
    width: min(240px, 46vw);
  }

  html.is-touch .inv-modal {
    align-items: center;
    padding: 8px 8px 8px calc(120px + env(safe-area-inset-left, 0px));
  }

  html.is-touch .inv-dialog {
    max-height: 88vh;
  }

  html.is-touch .inv-grid {
    grid-template-columns: repeat(8, 1fr);
  }
}

.fishing-overlay {
  position: absolute;
  inset: 0;
  z-index: 80;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  padding: 0 16px calc(110px + env(safe-area-inset-bottom, 0px));
  pointer-events: none;
}

.fishing-overlay.hidden {
  display: none;
}

.fishing-card {
  pointer-events: auto;
  width: min(420px, calc(100vw - 32px));
  padding: 16px 18px 14px;
  background: linear-gradient(180deg, rgba(28, 44, 48, 0.96), rgba(14, 22, 24, 0.97));
  border: 2px solid #7ec8c3;
  border-radius: 10px;
  box-shadow: 0 14px 40px rgba(0, 0, 0, 0.45);
  color: #e8f6f4;
  text-align: center;
}

.fishing-title {
  font-family: Georgia, serif;
  font-size: 1.15rem;
  letter-spacing: 0.04em;
  margin-bottom: 12px;
  color: #d4f0ec;
}

.fishing-bar {
  position: relative;
  height: 28px;
  border-radius: 6px;
  background: linear-gradient(180deg, #243038, #151c22);
  border: 1px solid #5d7a78;
  overflow: hidden;
}

.fishing-green {
  position: absolute;
  top: 3px;
  bottom: 3px;
  width: 20%;
  left: 40%;
  background: #3fb950;
  border-radius: 4px;
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.25);
}

.fishing-pointer {
  position: absolute;
  top: 0;
  bottom: 0;
  width: 4px;
  margin-left: -2px;
  left: 0;
  background: #fff8e1;
  box-shadow: 0 0 8px #ffe082;
}

.fishing-hint {
  margin: 10px 0 12px;
  font-size: 0.82rem;
  color: #b7d4d0;
}

.fishing-actions {
  display: flex;
  gap: 8px;
  justify-content: center;
}

.fishing-hook {
  background: #2e7d4f;
  color: #f3fff6;
  border: 1px solid #56d364;
}

.fishing-hook:hover {
  background: #3a9460;
}

html.is-touch .fishing-overlay {
  padding-bottom: calc(126px + env(safe-area-inset-bottom, 0px));
}

html.is-touch .fishing-card {
  width: min(460px, calc(100vw - 20px));
}

html.is-touch .fishing-bar {
  height: 36px;
}

html.is-touch .fishing-actions .btn {
  min-height: 44px;
  padding: 10px 16px;
}

/* ——— Lobby social / profile ——— */
.mini-profile {
  position: absolute;
  top: 18px;
  left: 18px;
  z-index: 4;
  width: min(280px, 82vw);
  height: 78px;
  padding: 0;
  border: 2px solid #c9a56a;
  border-radius: 4px;
  overflow: hidden;
  cursor: pointer;
  display: flex;
  align-items: stretch;
  background: #1a1008;
  text-align: left;
  font-family: var(--font-lore);
  color: #f3e2b6;
}

.mini-banner {
  position: absolute;
  inset: 0;
  background-size: cover;
  background-position: center;
  filter: saturate(0.9);
}

.mini-banner::after {
  content: "";
  position: absolute;
  inset: 0;
  background: linear-gradient(90deg, rgba(10, 6, 2, 0.15), rgba(10, 6, 2, 0.55));
}

.mini-av {
  position: relative;
  z-index: 1;
  width: 78px;
  height: 78px;
  object-fit: cover;
  border-right: 2px solid #c9a56a;
  flex-shrink: 0;
}

.mini-meta {
  position: relative;
  z-index: 1;
  display: flex;
  flex-direction: column;
  justify-content: center;
  padding: 0 12px;
  min-width: 0;
}

.mini-meta strong {
  font-family: var(--font-title);
  font-size: 0.95rem;
  letter-spacing: 0.04em;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.mini-meta em {
  font-size: 0.8rem;
  color: #f0d48a;
  font-style: italic;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.friends-rail {
  position: absolute;
  top: 18px;
  right: 18px;
  bottom: 18px;
  width: min(260px, 34vw);
  z-index: 4;
  padding: 1rem 0.9rem;
  overflow: auto;
  color: var(--ink);
}

.friends-rail h2 {
  font-family: var(--font-title);
  font-size: 0.85rem;
  letter-spacing: 0.12em;
  margin-bottom: 0.6rem;
}

.friends-list,
.clan-list {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-top: 8px;
}

.friend-row,
.clan-row,
.friend-req {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px;
  background: rgba(40, 24, 10, 0.12);
  border: 1px solid #c9a56a55;
}

.friend-row img,
.clan-row img {
  width: 36px;
  height: 36px;
  object-fit: cover;
  border: 1px solid #8a6230;
}

.friend-row.is-on b {
  color: #2d5a28;
}

.friend-row.is-off {
  opacity: 0.7;
}

.friend-row > div,
.clan-row > div {
  flex: 1;
  min-width: 0;
}

.friend-row small,
.clan-row small {
  display: block;
  font-size: 0.72rem;
}

.friend-row button,
.friend-req button {
  width: auto;
  margin: 0;
  padding: 0.25rem 0.45rem;
  font-size: 0.7rem;
}

.chat-dock {
  position: absolute;
  right: 18px;
  bottom: 18px;
  width: min(320px, 90vw);
  z-index: 8;
  display: flex;
  flex-direction: column;
  max-height: 42vh;
  color: var(--ink);
}

.chat-dock header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 8px 10px 4px;
  font-family: var(--font-title);
}

.chat-dock header button {
  border: none;
  background: none;
  cursor: pointer;
  font-size: 1.2rem;
  color: var(--ink);
}

.chat-log {
  flex: 1;
  overflow: auto;
  padding: 8px 10px;
  min-height: 120px;
  max-height: 220px;
  font-size: 0.9rem;
}

.chat-log .mine {
  text-align: right;
}

.chat-dock form {
  display: flex;
  gap: 6px;
  padding: 8px;
}

.chat-dock form .btn {
  width: auto;
  margin: 0;
}

.profile-overlay {
  z-index: 70;
}

.profile-sheet {
  width: min(560px, 94vw);
  max-height: 90vh;
  overflow: auto;
  padding: 1rem 1.1rem 1.2rem;
  position: relative;
}

.profile-close {
  position: absolute;
  top: 8px;
  right: 10px;
  z-index: 2;
}

.profile-hero {
  height: 140px;
  background-size: cover;
  background-position: center;
  border: 2px solid #5c3a1c;
  display: flex;
  align-items: flex-end;
  gap: 12px;
  padding: 10px;
  margin-bottom: 12px;
}

.profile-hero-av {
  width: 84px;
  height: 84px;
  object-fit: cover;
  border: 2px solid #c9a56a;
}

.profile-hero-meta {
  color: #fff7d6;
  text-shadow: 0 1px 3px #000;
}

.profile-hero-meta span {
  display: block;
  font-size: 0.9rem;
}

.profile-stats {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  gap: 8px;
  margin-bottom: 12px;
}

.profile-stats div {
  background: rgba(40, 24, 10, 0.08);
  border: 1px solid #c9a56a55;
  padding: 8px;
}

.profile-stats em {
  display: block;
  font-size: 0.72rem;
  color: #6a4a28;
}

.cosmetic-row {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
  margin-bottom: 10px;
}

.cosmetic-pick {
  width: 56px;
  height: 56px;
  padding: 0;
  border: 2px solid #8a6230;
  background: #2a180c;
  cursor: pointer;
}

.cosmetic-pick img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.cosmetic-pick.banner {
  width: 84px;
  height: 48px;
}

.cosmetic-pick.is-on {
  border-color: #d4b36a;
  box-shadow: 0 0 0 1px #d4b36a;
}

.rename-row {
  display: flex;
  gap: 6px;
  align-items: center;
}

.rename-row .field {
  flex: 1;
}

.rename-row .btn {
  width: auto;
  margin: 0;
  padding: 0.55rem 0.8rem;
}

.profile-note,
.clan-head {
  font-size: 0.85rem;
  color: #6a4a28;
  margin: 6px 0 10px;
}

.clan-row select {
  max-width: 140px;
}

.clan-row .btn {
  width: auto;
  margin: 0;
  padding: 0.3rem 0.5rem;
  font-size: 0.68rem;
}

.lobby-toast {
  position: absolute;
  top: 18px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 80;
  max-width: min(440px, 86vw);
  padding: 0.55rem 1rem;
  background: #ead7a8;
  color: #24160b;
  border: 2px solid #5c3a1c;
  font-family: var(--font-lore);
  pointer-events: none;
}

@media (max-width: 900px) {
  .friends-rail {
    position: relative;
    top: auto;
    right: auto;
    bottom: auto;
    width: min(420px, 100%);
    margin: 1rem 0 0;
    max-height: 40vh;
  }

  .lobby-screen {
    flex-wrap: wrap;
    align-content: flex-start;
    padding-top: 110px;
  }
}

/* ——— Painel admin (/admin) ——— */
html.is-admin,
html.is-admin body {
  overflow: auto;
  height: auto;
  min-height: 100%;
  user-select: text;
  -webkit-user-select: text;
  touch-action: auto;
  background: #0b1018;
}

html.is-admin #ui-root.admin-root {
  position: relative;
  pointer-events: auto;
  overflow: auto;
  min-height: 100dvh;
}

html.is-admin #game-canvas {
  display: none !important;
}

.admin-gate {
  min-height: 100dvh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 2rem;
  background:
    radial-gradient(circle at top, #182235, #0b1018 58%);
}

.admin-card,
.admin-app {
  font-family: var(--font);
  color: #e6edf3;
}

.admin-card {
  width: min(420px, 100%);
  background: #161b22;
  border: 1px solid #30363d;
  border-radius: 12px;
  padding: 1.6rem;
  box-shadow: var(--shadow);
}

.admin-kicker {
  color: #8b949e;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  font-size: 0.72rem;
  margin-bottom: 0.35rem;
}

.admin-card h1,
.admin-top h1 {
  font-family: var(--font);
  font-size: 1.6rem;
  margin-bottom: 0.4rem;
}

.admin-hint {
  color: #8b949e;
  font-size: 0.92rem;
  margin: 0.35rem 0 0.8rem;
}

.admin-card form,
.admin-edit,
.admin-search {
  display: grid;
  gap: 0.7rem;
}

.admin-card label,
.admin-edit label {
  display: grid;
  gap: 0.25rem;
  font-size: 0.82rem;
  color: #8b949e;
}

.admin-card input,
.admin-edit input,
.admin-edit select,
.admin-search input {
  background: #0d1117;
  border: 1px solid #30363d;
  color: #e6edf3;
  border-radius: 8px;
  padding: 0.55rem 0.7rem;
  font: inherit;
}

.admin-flash {
  min-height: 1.2rem;
  color: #3fb950;
  font-size: 0.9rem;
}

.admin-flash.is-error {
  color: #f85149;
}

.admin-app {
  max-width: 1080px;
  margin: 0 auto;
  padding: 1.2rem 1rem 3rem;
}

.admin-top {
  display: flex;
  justify-content: space-between;
  align-items: flex-end;
  gap: 1rem;
}

.admin-who {
  display: flex;
  align-items: center;
  gap: 0.7rem;
}

.admin-nav {
  display: flex;
  gap: 0.4rem;
  margin: 1rem 0;
  border-bottom: 1px solid #30363d;
}

.admin-nav button {
  background: transparent;
  border: none;
  color: #8b949e;
  padding: 0.55rem 0.8rem;
  cursor: pointer;
  font: inherit;
  border-bottom: 2px solid transparent;
}

.admin-nav button.is-on {
  color: #e6edf3;
  border-bottom-color: #58a6ff;
}

.admin-list {
  display: grid;
  gap: 0.8rem;
}

.admin-row {
  background: #161b22;
  border: 1px solid #30363d;
  border-radius: 10px;
  padding: 0.9rem;
}

.admin-row-head {
  display: flex;
  flex-wrap: wrap;
  gap: 0.55rem 1rem;
  align-items: baseline;
  margin-bottom: 0.7rem;
}

.admin-id {
  color: #58a6ff;
  font-family: ui-monospace, monospace;
}

.is-live {
  color: #3fb950;
}

.admin-row-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.45rem;
}

.admin-people {
  list-style: none;
  display: grid;
  gap: 0.4rem;
  margin: 0.5rem 0;
}

.admin-people li {
  display: flex;
  flex-wrap: wrap;
  gap: 0.45rem;
  align-items: center;
  color: #c9d1d9;
}

.admin-empty {
  color: #8b949e;
}
