:root {
  --ink: #0e1418;
  --moss: #1a2f28;
  --teal: #2f6f66;
  --foam: #c9e4d6;
  --ember: #d9773a;
  --gold: #e6c17a;
  --blood: #c44b4b;
  --mana: #4aa3c7;
  --panel: rgba(10, 16, 18, 0.88);
  --line: rgba(201, 228, 214, 0.18);
  --shadow: 0 18px 50px rgba(0, 0, 0, 0.45);
  --font-display: "Cinzel", serif;
  --font-body: "Source Sans 3", sans-serif;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  min-height: 100%;
  background:
    radial-gradient(1200px 600px at 20% -10%, rgba(47, 111, 102, 0.35), transparent 55%),
    radial-gradient(900px 500px at 90% 10%, rgba(217, 119, 58, 0.18), transparent 50%),
    linear-gradient(180deg, #121a1d 0%, #0a1012 100%);
  color: var(--foam);
  font-family: var(--font-body);
}

body::before {
  content: "";
  position: fixed;
  inset: 0;
  pointer-events: none;
  background-image:
    linear-gradient(rgba(201, 228, 214, 0.03) 1px, transparent 1px),
    linear-gradient(90deg, rgba(201, 228, 214, 0.03) 1px, transparent 1px);
  background-size: 48px 48px;
  mask-image: radial-gradient(circle at center, black 35%, transparent 85%);
}

#app {
  width: min(1040px, calc(100% - 24px));
  margin: 0 auto;
  padding: 20px 0 40px;
}

.top-bar {
  margin-bottom: 14px;
}

.brand {
  margin: 0;
  font-family: var(--font-display);
  font-size: clamp(2rem, 4vw, 2.8rem);
  letter-spacing: 0.04em;
  color: var(--gold);
  text-shadow: 0 2px 0 rgba(0, 0, 0, 0.35);
  animation: brand-in 0.8s ease both;
}

.tagline {
  margin: 6px 0 0;
  color: rgba(201, 228, 214, 0.72);
  font-size: 1rem;
  animation: brand-in 0.9s ease 0.08s both;
}

.stage {
  position: relative;
  border: 1px solid var(--line);
  border-radius: 18px;
  overflow: hidden;
  box-shadow: var(--shadow);
  background: var(--ink);
  width: 100%;
  aspect-ratio: 960 / 540;
  min-height: 320px;
}

#game {
  position: absolute;
  inset: 0;
  display: block;
  width: 100%;
  height: 100%;
  background: #0b1114;
  touch-action: none;
}

#game.hidden {
  visibility: hidden;
  pointer-events: none;
}

.hud {
  position: absolute;
  inset: 0;
  pointer-events: none;
  animation: fade-up 0.45s ease both;
}

.hud-top {
  position: absolute;
  left: 14px;
  right: 14px;
  top: 12px;
  display: grid;
  gap: 8px;
}

.hotbar {
  position: absolute;
  left: 50%;
  bottom: 14px;
  transform: translateX(-50%);
  display: grid;
  grid-template-columns: repeat(10, minmax(36px, 44px));
  gap: 4px;
  padding: 6px;
  border-radius: 12px;
  background: rgba(8, 12, 14, 0.72);
  border: 1px solid var(--line);
  pointer-events: auto;
  z-index: 4;
}

.hub {
  align-content: stretch;
  padding: 16px;
  overflow: auto;
}

.hub-layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(220px, 260px);
  gap: 14px;
  height: 100%;
  min-height: 0;
}

.hub-map-wrap {
  border-radius: 14px;
  overflow: hidden;
  border: 1px solid var(--line);
  background: #0b1412;
  min-height: 0;
}

#world-map {
  display: block;
  width: 100%;
  height: auto;
  cursor: pointer;
}

.hub-side {
  display: grid;
  align-content: start;
  gap: 10px;
}

.hub-side h2 {
  margin: 0;
}

.hub-selection {
  margin: 0;
  font-family: var(--font-display);
  color: var(--gold);
  font-size: 1.15rem;
}

.hub-blurb {
  margin: 0;
  color: rgba(201, 228, 214, 0.75);
  font-size: 0.92rem;
}

.hub-status {
  margin: 0;
  min-height: 1.2em;
  color: #c44b4b;
  font-size: 0.88rem;
}

.hub-summary {
  margin: 0;
  padding-top: 8px;
  border-top: 1px solid var(--line);
  color: rgba(201, 228, 214, 0.78);
  font-size: 0.9rem;
}

.hub-actions {
  display: grid;
  gap: 8px;
}

.hub-help {
  margin: 8px 0 0;
  font-size: 0.8rem;
  color: rgba(201, 228, 214, 0.55);
  line-height: 1.4;
}

.inv-close {
  margin-top: 12px;
  width: 100%;
}

@media (max-width: 800px) {
  .hub-layout {
    grid-template-columns: 1fr;
  }
}

.inventory-panel {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  background: rgba(6, 10, 12, 0.62);
  z-index: 5;
  pointer-events: auto;
  animation: panel-in 0.2s ease both;
}

.inventory-card {
  width: min(560px, calc(100% - 28px));
  padding: 16px;
  border-radius: 16px;
  border: 1px solid var(--line);
  background: rgba(12, 18, 20, 0.94);
  box-shadow: var(--shadow);
}

.inventory-header {
  margin-bottom: 12px;
}

.inventory-header h2 {
  margin: 0 0 4px;
  font-family: var(--font-display);
  font-size: 1.35rem;
  color: var(--gold);
}

.inventory-header p {
  margin: 0;
  color: rgba(201, 228, 214, 0.7);
  font-size: 0.9rem;
}

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

.inv-slot {
  position: relative;
  aspect-ratio: 1;
  min-width: 0;
  padding: 0;
  border-radius: 8px;
  border: 1px solid rgba(255, 255, 255, 0.12);
  background: rgba(255, 255, 255, 0.04);
  color: inherit;
  font-weight: 600;
  transform: none;
  filter: none;
}

.inv-slot:hover {
  filter: none;
  transform: none;
  border-color: rgba(230, 193, 122, 0.45);
  background: rgba(47, 111, 102, 0.25);
}

.inv-slot.selected {
  border-color: var(--gold);
  box-shadow: inset 0 0 0 1px rgba(230, 193, 122, 0.45);
}

.inv-key {
  position: absolute;
  top: 2px;
  left: 4px;
  font-size: 0.62rem;
  opacity: 0.45;
  pointer-events: none;
}

.inv-body {
  display: grid;
  place-items: center;
  width: 100%;
  height: 100%;
}

.inv-icon {
  font-size: 1.05rem;
  line-height: 1;
  color: var(--c, var(--foam));
  text-shadow: 0 1px 0 rgba(0, 0, 0, 0.4);
}

.inv-count {
  position: absolute;
  right: 3px;
  bottom: 2px;
  font-size: 0.7rem;
  font-weight: 700;
  color: var(--foam);
  text-shadow: 0 1px 2px rgba(0, 0, 0, 0.8);
}

.inv-cursor {
  position: fixed;
  z-index: 40;
  width: 40px;
  height: 40px;
  pointer-events: none;
  display: grid;
  place-items: center;
  border-radius: 8px;
  background: rgba(8, 12, 14, 0.75);
  border: 1px solid rgba(230, 193, 122, 0.45);
}

.ammo-hint,
.coin-readout {
  margin: 0;
  font-size: 0.82rem;
  color: rgba(201, 228, 214, 0.75);
  max-width: 420px;
}

.coin-readout {
  color: var(--gold);
  font-weight: 700;
}

.save-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.shop {
  align-content: stretch;
  overflow: auto;
}

.shop-card {
  width: min(640px, 100%);
  margin: 0 auto;
  display: grid;
  gap: 12px;
}

.shop-header {
  display: flex;
  flex-wrap: wrap;
  gap: 12px 20px;
  justify-content: space-between;
  align-items: start;
}

.shop-header h2 {
  margin: 0 0 4px;
}

.shop-header p {
  margin: 0;
  color: rgba(201, 228, 214, 0.72);
  max-width: 46ch;
}

.shop-coins {
  font-weight: 700;
  color: var(--gold) !important;
  font-size: 1.1rem;
}

.shop-list {
  display: grid;
  gap: 8px;
  max-height: min(340px, 50vh);
  overflow: auto;
  padding-right: 4px;
}

.shop-row {
  display: grid;
  grid-template-columns: 1fr auto auto;
  gap: 10px;
  align-items: center;
  padding: 10px 12px;
  border-radius: 12px;
  border: 1px solid var(--line);
  background: rgba(26, 47, 40, 0.45);
  text-align: left;
}

.shop-row .name {
  font-weight: 600;
}

.shop-row .meta {
  margin: 2px 0 0;
  font-size: 0.82rem;
  color: rgba(201, 228, 214, 0.65);
  max-width: none;
}

.shop-row .price {
  color: var(--gold);
  font-weight: 700;
  white-space: nowrap;
}

.shop-row button {
  padding: 8px 12px;
}

.shop-row.locked {
  opacity: 0.55;
}

.shop-status {
  margin: 0;
  min-height: 1.2em;
  color: rgba(201, 228, 214, 0.8);
  font-size: 0.9rem;
}

.stat {
  display: grid;
  grid-template-columns: 48px 1fr auto;
  gap: 8px;
  align-items: center;
  max-width: 320px;
  font-size: 0.85rem;
}

.label {
  opacity: 0.75;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  font-size: 0.72rem;
}

.bar {
  height: 10px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.08);
  overflow: hidden;
  border: 1px solid rgba(255, 255, 255, 0.08);
}

.bar i {
  display: block;
  height: 100%;
  width: 100%;
  transform-origin: left center;
  transition: transform 0.15s linear;
}

.bar.hp i {
  background: linear-gradient(90deg, #8f2f2f, var(--blood));
}

.bar.xp i {
  background: linear-gradient(90deg, #8a6a2e, var(--gold));
}

.meta {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  margin-top: 2px;
  font-size: 0.85rem;
  color: rgba(201, 228, 214, 0.8);
  max-width: 420px;
}

.panel {
  position: absolute;
  inset: 0;
  display: grid;
  align-content: center;
  justify-items: stretch;
  gap: 14px;
  padding: 28px clamp(18px, 4vw, 48px);
  background:
    linear-gradient(180deg, rgba(14, 20, 24, 0.72), rgba(14, 20, 24, 0.92)),
    radial-gradient(700px 300px at 50% 0%, rgba(47, 111, 102, 0.28), transparent 70%);
  backdrop-filter: blur(2px);
  animation: panel-in 0.5s ease both;
}

.panel h2 {
  margin: 0;
  font-family: var(--font-display);
  font-size: clamp(1.6rem, 3vw, 2.1rem);
  color: var(--gold);
}

.help {
  margin: 0;
  max-width: 56ch;
  color: rgba(201, 228, 214, 0.78);
}

kbd {
  display: inline-block;
  padding: 1px 6px;
  border-radius: 5px;
  border: 1px solid rgba(255, 255, 255, 0.18);
  background: rgba(255, 255, 255, 0.06);
  font-size: 0.85em;
}

.dungeon-list {
  display: grid;
  gap: 10px;
}

.dungeon-card {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 8px 16px;
  text-align: left;
  padding: 14px 16px;
  border-radius: 14px;
  border: 1px solid var(--line);
  background: rgba(26, 47, 40, 0.55);
  color: inherit;
  cursor: pointer;
  transition: transform 0.15s ease, border-color 0.15s ease, background 0.15s ease;
  font: inherit;
}

.dungeon-card:hover:not(:disabled),
.dungeon-card:focus-visible {
  transform: translateY(-2px);
  border-color: rgba(230, 193, 122, 0.55);
  background: rgba(47, 111, 102, 0.35);
  outline: none;
}

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

.dungeon-card strong {
  font-family: var(--font-display);
  font-size: 1.05rem;
  color: var(--foam);
}

.dungeon-card .desc {
  grid-column: 1 / -1;
  margin: 0;
  color: rgba(201, 228, 214, 0.7);
  font-size: 0.92rem;
}

.dungeon-card .badge {
  align-self: start;
  color: var(--gold);
  font-size: 0.8rem;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

.save-row {
  display: flex;
  flex-wrap: wrap;
  gap: 10px 16px;
  align-items: center;
  justify-content: space-between;
  margin-top: 4px;
  padding-top: 10px;
  border-top: 1px solid var(--line);
}

.save-row p {
  margin: 0;
  color: rgba(201, 228, 214, 0.75);
}

button {
  font: inherit;
  border: 0;
  border-radius: 12px;
  padding: 10px 16px;
  background: linear-gradient(180deg, #d9773a, #b55a28);
  color: #1a1008;
  font-weight: 700;
  cursor: pointer;
  transition: transform 0.12s ease, filter 0.12s ease;
}

button:hover {
  filter: brightness(1.06);
  transform: translateY(-1px);
}

button.ghost {
  background: transparent;
  color: var(--foam);
  border: 1px solid var(--line);
  font-weight: 600;
}

.overlay-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
}

.hidden {
  display: none !important;
}

@keyframes brand-in {
  from {
    opacity: 0;
    transform: translateY(8px);
  }
  to {
    opacity: 1;
    transform: none;
  }
}

@keyframes panel-in {
  from {
    opacity: 0;
  }
  to {
    opacity: 1;
  }
}

@keyframes fade-up {
  from {
    opacity: 0;
    transform: translateY(6px);
  }
  to {
    opacity: 1;
    transform: none;
  }
}

#world-map {
  touch-action: none;
}

.touch-controls {
  position: absolute;
  inset: 0;
  z-index: 3;
  pointer-events: none;
}

.touch-cluster {
  position: absolute;
  bottom: 64px;
  display: grid;
  gap: 8px;
  pointer-events: auto;
}

.touch-left {
  left: 10px;
  grid-template-columns: 56px 56px;
  grid-template-rows: auto auto;
}

.touch-left .touch-jump {
  grid-column: 1 / -1;
}

.touch-right {
  right: 10px;
  justify-items: end;
}

.touch-hotbar-row {
  display: flex;
  gap: 8px;
}

.touch-btn {
  min-width: 56px;
  min-height: 56px;
  padding: 10px 12px;
  border-radius: 16px;
  border: 1px solid rgba(255, 255, 255, 0.22);
  background: rgba(8, 12, 14, 0.55);
  color: var(--foam);
  font-weight: 700;
  font-size: 1rem;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
  transform: none;
  filter: none;
}

.touch-btn.touch-small {
  min-width: 48px;
  min-height: 48px;
}

.touch-btn.touch-attack {
  min-width: 72px;
  min-height: 72px;
  background: rgba(217, 119, 58, 0.55);
  border-color: rgba(230, 193, 122, 0.45);
}

.touch-btn.pressed,
.touch-btn:active {
  background: rgba(47, 111, 102, 0.65);
  transform: none;
  filter: none;
}

.rotate-hint {
  position: sticky;
  top: 0;
  z-index: 50;
  text-align: center;
  padding: 8px 12px;
  background: rgba(217, 119, 58, 0.92);
  color: #1a1008;
  font-weight: 700;
  font-size: 0.92rem;
}

.rotate-hint[hidden] {
  display: none !important;
}

@media (max-width: 640px) {
  #app {
    width: calc(100% - 12px);
    padding-top: 12px;
  }

  .panel {
    align-content: start;
    padding-top: 20px;
    overflow: auto;
  }

  .stat {
    max-width: none;
  }

  .hotbar {
    grid-template-columns: repeat(10, minmax(28px, 34px));
    gap: 3px;
    bottom: 8px;
    padding: 4px;
  }
}

@media (orientation: landscape) and (max-height: 520px) {
  body {
    overflow: hidden;
  }

  #app {
    width: 100%;
    max-width: none;
    padding: 4px 8px 8px;
    margin: 0;
  }

  .top-bar {
    display: none;
  }

  .stage {
    aspect-ratio: auto;
    height: calc(100dvh - 12px);
    min-height: 0;
    border-radius: 12px;
  }

  .hub {
    padding: 8px;
  }

  .hub-layout {
    grid-template-columns: minmax(0, 1fr) minmax(160px, 200px);
    gap: 8px;
  }

  .hub-side h2 {
    font-size: 1.2rem;
  }

  .hub-selection {
    font-size: 1rem;
  }

  .hub-blurb,
  .hub-help {
    font-size: 0.75rem;
  }

  .hub-actions button {
    padding: 8px 10px;
  }

  .hud-top {
    top: 6px;
    left: 8px;
    right: 8px;
    gap: 4px;
  }

  .stat {
    max-width: 240px;
    font-size: 0.78rem;
  }

  .hotbar {
    bottom: 58px;
    grid-template-columns: repeat(10, minmax(26px, 32px));
  }

  .touch-cluster {
    bottom: 8px;
  }

  .touch-btn {
    min-width: 48px;
    min-height: 48px;
    font-size: 0.9rem;
  }

  .touch-btn.touch-attack {
    min-width: 64px;
    min-height: 64px;
  }

  .inventory-card,
  .shop-card {
    max-height: calc(100dvh - 24px);
    overflow: auto;
  }
}

@media (orientation: portrait) and (max-width: 900px) {
  .rotate-hint:not([hidden]) {
    display: block;
  }
}
