:root {
  --bg-1: #f3e7c9;
  --bg-2: #b8d1ab;
  --ink: #1f2c22;
  --ink-soft: #3f5847;
  --panel: rgba(255, 250, 240, 0.9);
  --panel-border: #6f815e;
  --accent: #b85c38;
  --accent-2: #3b6c8e;
  --good: #28652a;
  --warn: #9d5a09;
  --danger: #8f2222;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  height: 100%;
  min-height: 100%;
  overflow: hidden;
  font-family: "Trebuchet MS", "Gill Sans", "Segoe UI", sans-serif;
  color: var(--ink);
  background: radial-gradient(circle at 15% 15%, rgba(255, 250, 227, 0.9), transparent 40%),
    radial-gradient(circle at 85% 20%, rgba(155, 198, 240, 0.3), transparent 35%),
    linear-gradient(145deg, var(--bg-1), var(--bg-2));
}

.app-shell {
  height: 100vh;
  min-height: 100vh;
  padding: 12px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  overflow: hidden;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 14px;
  border: 2px solid var(--panel-border);
  border-radius: 12px;
  background: var(--panel);
  box-shadow: 0 6px 16px rgba(26, 39, 32, 0.18);
}

.topbar h1 {
  margin: 0;
  font-family: "Georgia", "Palatino Linotype", serif;
  font-size: 1.4rem;
  color: var(--ink);
}

.subtitle {
  margin: 4px 0 0;
  color: var(--ink-soft);
  font-size: 0.9rem;
}

.topbar-stats {
  display: grid;
  grid-template-columns: repeat(2, minmax(140px, 1fr));
  gap: 6px 12px;
  text-align: right;
  font-weight: 700;
}

.main-layout {
  flex: 1;
  display: grid;
  gap: 10px;
  grid-template-columns: minmax(280px, 330px) minmax(820px, 1fr) minmax(330px, 390px);
  min-height: 0;
  overflow: hidden;
}

.panel,
.game-column {
  min-height: 0;
  max-height: 100%;
}

.panel {
  border: 2px solid var(--panel-border);
  border-radius: 12px;
  background: var(--panel);
  padding: 10px;
  overflow-y: auto;
  box-shadow: 0 4px 10px rgba(31, 44, 34, 0.14);
}

.panel section {
  margin-bottom: 14px;
  padding-bottom: 10px;
  border-bottom: 1px dashed rgba(31, 44, 34, 0.25);
}

.panel section:last-child {
  margin-bottom: 0;
  border-bottom: none;
}

h2,
h3 {
  margin: 0 0 8px;
  font-family: "Georgia", "Palatino Linotype", serif;
}

h2 {
  font-size: 1.05rem;
}

h3 {
  font-size: 0.9rem;
}

button,
input,
select {
  font: inherit;
}

button {
  border: 1px solid var(--panel-border);
  background: linear-gradient(180deg, #fff8e3, #efe2c9);
  border-radius: 8px;
  color: var(--ink);
  cursor: pointer;
  padding: 6px 10px;
  transition: transform 100ms ease, box-shadow 120ms ease, background 120ms ease;
}

button:hover {
  box-shadow: 0 3px 8px rgba(31, 44, 34, 0.18);
  transform: translateY(-1px);
}

button:active {
  transform: translateY(0);
}

button:disabled {
  cursor: not-allowed;
  opacity: 0.55;
}

label {
  display: grid;
  gap: 4px;
  font-size: 0.9rem;
}

input,
select {
  border-radius: 6px;
  border: 1px solid rgba(31, 44, 34, 0.25);
  background: rgba(255, 255, 255, 0.9);
  padding: 6px 8px;
  color: var(--ink);
}

.game-column {
  display: flex;
  flex-direction: column;
  gap: 10px;
  overflow: hidden;
}

.scene-switcher {
  border: 2px solid var(--panel-border);
  border-radius: 10px;
  background: var(--panel);
  padding: 8px;
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.canvas-wrap {
  flex: 1;
  min-height: 420px;
  border: 2px solid var(--panel-border);
  border-radius: 12px;
  background: linear-gradient(180deg, #f3f8f2, #dce8d3);
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  position: relative;
}

#game-canvas {
  width: 100%;
  height: 100%;
  object-fit: contain;
  image-rendering: pixelated;
  background: #a9d19f;
  outline: none;
}

.overlay-ui {
  position: absolute;
  inset: 0;
  pointer-events: none;
}

.overlay-focus-hint {
  position: absolute;
  top: 10px;
  right: 10px;
  font-size: 0.82rem;
  padding: 5px 8px;
  background: rgba(16, 24, 18, 0.7);
  color: #f4ead2;
  border-radius: 8px;
  border: 1px solid rgba(238, 227, 200, 0.32);
}

.overlay-left-actions,
.overlay-right-abilities {
  display: none;
}

.world-map-panel {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  min-width: 320px;
  max-width: 420px;
  border: 2px solid rgba(245, 234, 201, 0.65);
  border-radius: 12px;
  background: rgba(19, 29, 24, 0.9);
  color: #f3e9ce;
  padding: 12px;
  z-index: 4;
}

.world-map-panel.hidden {
  display: none;
}

.world-map-panel h3 {
  margin: 0 0 6px;
  font-family: "Georgia", "Palatino Linotype", serif;
}

.world-map-panel p {
  margin: 0 0 10px;
  font-size: 0.9rem;
}

.map-actions {
  display: grid;
  grid-template-columns: repeat(3, minmax(120px, 1fr));
  gap: 8px;
}

.map-actions button {
  background: rgba(246, 232, 196, 0.92);
}

.popup-panel {
  position: fixed;
  top: 84px;
  right: 22px;
  width: min(420px, 96vw);
  border: 2px solid var(--panel-border);
  border-radius: 12px;
  background: rgba(250, 246, 234, 0.97);
  box-shadow: 0 18px 34px rgba(24, 36, 29, 0.26);
  z-index: 12;
  padding: 10px;
}

#skills-popup {
  right: 462px;
  width: min(360px, 96vw);
}

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

.popup-panel header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 6px;
}

.popup-hint {
  margin: 0 0 8px;
  color: var(--ink-soft);
  font-size: 0.82rem;
}

.popup-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(86px, 1fr));
  gap: 8px;
  max-height: 360px;
  overflow-y: auto;
}

.popup-slot {
  border: 1px solid rgba(31, 44, 34, 0.28);
  border-radius: 10px;
  background: rgba(255, 255, 255, 0.92);
  padding: 8px 6px;
  display: grid;
  justify-items: center;
  gap: 4px;
  cursor: grab;
}

.popup-slot:active {
  cursor: grabbing;
}

.popup-slot.drag-target {
  outline: 2px dashed rgba(59, 108, 142, 0.7);
  outline-offset: -3px;
}

.popup-skills {
  display: grid;
  gap: 8px;
  max-height: 360px;
  overflow-y: auto;
}

.popup-skill-row {
  border: 1px solid rgba(31, 44, 34, 0.22);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.85);
  padding: 6px 8px;
  display: flex;
  justify-content: space-between;
  gap: 8px;
}

.log-wrap {
  border: 2px solid var(--panel-border);
  border-radius: 10px;
  background: var(--panel);
  padding: 8px;
  height: 230px;
  display: flex;
  flex-direction: column;
}

#log {
  flex: 1;
  overflow-y: auto;
  font-size: 0.88rem;
  display: flex;
  flex-direction: column-reverse;
  gap: 4px;
}

.log-line {
  padding: 4px 6px;
  border-left: 3px solid var(--accent-2);
  background: rgba(255, 255, 255, 0.72);
  border-radius: 4px;
}

.stat-grid,
.skills,
.ability-slots,
.equip-grid,
.action-row {
  display: grid;
  gap: 6px;
}

.stat-grid {
  grid-template-columns: repeat(2, minmax(0, 1fr));
  font-size: 0.9rem;
}

.skills {
  grid-template-columns: repeat(2, minmax(0, 1fr));
  font-size: 0.88rem;
}

.ability-slots {
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.ability-chip {
  border: 1px solid rgba(31, 44, 34, 0.35);
  border-radius: 7px;
  padding: 5px;
  background: rgba(255, 255, 255, 0.7);
  font-size: 0.84rem;
}

.action-row {
  grid-template-columns: repeat(auto-fit, minmax(130px, 1fr));
  align-items: end;
}

.listing,
.shop-card,
.inv-row {
  border: 1px solid rgba(31, 44, 34, 0.22);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.75);
  padding: 6px;
  margin-bottom: 6px;
  font-size: 0.86rem;
}

.inventory-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(86px, 1fr));
  gap: 7px;
}

.inv-item {
  border: 1px solid rgba(31, 44, 34, 0.26);
  border-radius: 10px;
  background: rgba(255, 255, 255, 0.78);
  padding: 6px;
  display: grid;
  justify-items: center;
  gap: 3px;
  min-height: 72px;
}

.inv-icon {
  font-size: 1.1rem;
}

.inv-name {
  font-size: 0.72rem;
  text-align: center;
  color: var(--ink-soft);
}

.inv-qty {
  font-weight: 700;
}

.inventory-hidden-store {
  display: none !important;
}

.control-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 6px;
  margin-bottom: 8px;
}

.control-grid button,
.control-runes button {
  min-height: 36px;
  text-align: left;
  font-size: 0.92rem;
}

.control-runes {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 6px;
}

.control-runes button.cooldown {
  opacity: 0.66;
}

.control-runes button.locked {
  opacity: 0.44;
}

.metrics-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 6px;
}

.metric-chip {
  border: 1px solid rgba(31, 44, 34, 0.25);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.68);
  padding: 6px;
  font-size: 0.82rem;
  display: grid;
  gap: 2px;
}

.metric-chip strong {
  font-size: 0.78rem;
  color: var(--ink-soft);
}

.admin-event-section {
  border: 1px solid rgba(31, 44, 34, 0.2);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.48);
  padding: 8px;
}

.admin-event-section .inline-check {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 0.86rem;
}

.admin-event-section input[type="checkbox"] {
  transform: scale(1.1);
}

.left-panel {
  display: flex;
  flex-direction: column;
}

.left-panel > section {
  order: 10;
}

#stats-section {
  order: 1;
}

#character-section {
  order: 2;
}

#account-section {
  order: 3;
}

#metrics-section {
  order: 4;
}

.shop-card header {
  display: flex;
  justify-content: space-between;
  font-weight: 700;
}

.listing-item {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  margin-right: 6px;
}

.listing-icon {
  font-size: 1rem;
  width: 20px;
  text-align: center;
}

.event-tier {
  font-weight: 700;
}

.event-tier.bronze {
  color: #8b5a2b;
}

.event-tier.silver {
  color: #4f6272;
}

.event-tier.gold {
  color: #b07e1a;
}

.event-tier.mythic {
  color: #8f2222;
}

.controls {
  border: 2px solid var(--panel-border);
  border-radius: 10px;
  background: var(--panel);
  padding: 8px 10px;
  font-size: 0.9rem;
}

.context-section {
  display: none;
}

.context-section.visible {
  display: block;
}

.town-market-overlay {
  position: absolute;
  right: 12px;
  top: 58px;
  width: min(460px, calc(100% - 24px));
  max-height: calc(100% - 74px);
  overflow: auto;
  z-index: 3;
  border: 2px solid rgba(77, 96, 79, 0.9);
  border-radius: 10px;
  background: rgba(251, 248, 238, 0.95);
  padding: 8px;
  box-shadow: 0 6px 16px rgba(19, 27, 21, 0.22);
}

.town-market-overlay #shop-results {
  max-height: 280px;
  overflow: auto;
}

.section-hint {
  margin: 0 0 8px;
  font-size: 0.83rem;
  color: var(--ink-soft);
}

.good {
  color: var(--good);
}

.warn {
  color: var(--warn);
}

.danger {
  color: var(--danger);
}

@media (max-width: 1450px) {
  .main-layout {
    grid-template-columns: minmax(250px, 320px) minmax(620px, 1fr);
    grid-template-areas:
      "left center"
      "right center";
    overflow: auto;
  }

  .left-panel {
    grid-area: left;
  }

  .right-panel {
    grid-area: right;
  }

  .game-column {
    grid-area: center;
  }
}

@media (max-width: 1080px) {
  .main-layout {
    grid-template-columns: 1fr;
    overflow: auto;
  }

  .canvas-wrap {
    min-height: 420px;
  }

  .topbar {
    flex-direction: column;
    align-items: flex-start;
    gap: 8px;
  }

  .popup-panel {
    left: 8px;
    right: 8px;
    top: 70px;
    width: auto;
  }

  #skills-popup {
    top: 300px;
    right: 8px;
    left: 8px;
    width: auto;
  }

  .topbar-stats {
    width: 100%;
    text-align: left;
    grid-template-columns: repeat(2, minmax(120px, 1fr));
  }

  .control-grid,
  .control-runes {
    grid-template-columns: 1fr;
  }

  .town-market-overlay {
    left: 10px;
    right: 10px;
    width: auto;
    max-height: 56%;
  }
}
