:root {
  --bg: #050505;
  --panel: rgba(10, 14, 11, 0.94);
  --panel-2: rgba(14, 22, 18, 0.98);
  --ink: #f4f4f5;
  --muted: #a1a1aa;
  --accent: #10b981;
  --accent-soft: #34d399;
  --danger: #ef4444;
  --good: #22c55e;
  --wall: #17211c;
  --floor: #243129;
  --market: #0f8f63;
  --enemy: #7f1d1d;
  --treasure: #d4a017;
  --stairs: #0ea5a4;
  --shadow: rgba(0, 0, 0, 0.46);
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  min-height: 100%;
}

body {
  background:
    radial-gradient(circle at top, rgba(16, 185, 129, 0.16), transparent 34%),
    linear-gradient(180deg, #080808 0%, #040404 100%);
  color: var(--ink);
  font-family: "Plus Jakarta Sans", system-ui, sans-serif;
}

.app-shell {
  width: min(1480px, calc(100% - 32px));
  margin: 20px auto 32px;
}

.title-panel,
.hud,
.canvas-frame,
.legend,
.story-panel {
  background: linear-gradient(180deg, rgba(12, 18, 14, 0.98), rgba(7, 10, 8, 0.98));
  border: 1px solid rgba(16, 185, 129, 0.16);
  border-radius: 16px;
  box-shadow: 0 18px 40px var(--shadow);
}

.title-panel {
  padding: 20px 24px;
  margin-bottom: 16px;
}

.title-topbar {
  display: flex;
  justify-content: space-between;
  gap: 18px;
  align-items: flex-start;
}

.eyebrow {
  margin: 0 0 6px;
  color: var(--accent-soft);
  font-size: 0.82rem;
  letter-spacing: 0.16em;
  text-transform: uppercase;
}

h1,
h2,
.subtitle,
.story-tip,
.legend p,
.legend li {
  margin: 0;
}

h1 {
  font-size: clamp(2rem, 4vw, 3.4rem);
  line-height: 0.95;
  letter-spacing: -0.04em;
}

.subtitle {
  margin-top: 10px;
  max-width: 780px;
  color: var(--muted);
  line-height: 1.5;
}

.byline {
  margin: 10px 0 0;
  color: var(--accent-soft);
  font-size: 0.98rem;
  letter-spacing: 0.04em;
}

.lang-switch {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-shrink: 0;
}

.lang-btn {
  appearance: none;
  border: 1px solid rgba(255, 255, 255, 0.18);
  background: rgba(255, 255, 255, 0.04);
  color: #d4d4d8;
  padding: 0.38rem 0.65rem;
  border-radius: 0.55rem;
  font: inherit;
  font-size: 0.68rem;
  font-weight: 800;
  letter-spacing: 0.08em;
  line-height: 1;
  cursor: pointer;
}

.lang-btn.active {
  background: var(--accent);
  border-color: var(--accent);
  color: #000;
}

.hud {
  display: grid;
  grid-template-columns: repeat(7, minmax(0, 1fr));
  gap: 12px;
  padding: 14px;
  margin-bottom: 16px;
}

.stat-card {
  padding: 12px 14px;
  background: linear-gradient(180deg, rgba(23, 39, 30, 0.6), rgba(8, 13, 10, 0.4));
  border-radius: 12px;
  border: 1px solid rgba(255, 255, 255, 0.06);
}

.label {
  display: block;
  font-size: 0.8rem;
  color: var(--muted);
  margin-bottom: 6px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

.play-layout {
  display: grid;
  grid-template-columns: 340px minmax(0, 1fr);
  gap: 16px;
  align-items: start;
}

.game-layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 260px;
  gap: 16px;
  align-items: start;
}

.canvas-frame {
  padding: 16px;
}

canvas {
  display: block;
  width: 100%;
  height: auto;
  border-radius: 12px;
  background:
    linear-gradient(180deg, rgba(52, 211, 153, 0.06), rgba(0, 0, 0, 0.08)),
    #0d120f;
}

.legend {
  padding: 18px;
}

.legend h2 {
  margin-bottom: 10px;
  font-size: 1.05rem;
}

.legend p {
  color: var(--muted);
  line-height: 1.5;
}

.legend-button {
  appearance: none;
  margin-top: 14px;
  margin-bottom: 12px;
  width: 100%;
  border: 0;
  border-radius: 999px;
  background: linear-gradient(180deg, #34d399, #10b981);
  color: #02110b;
  font: inherit;
  font-weight: 700;
  padding: 10px 14px;
  cursor: pointer;
  box-shadow: 0 10px 18px rgba(0, 0, 0, 0.16);
}

.legend-button:hover {
  filter: brightness(1.06);
}

.back-link {
  display: block;
  width: 100%;
  margin-bottom: 18px;
  padding: 11px 14px;
  border-radius: 14px;
  text-align: center;
  text-decoration: none;
  background: rgba(16, 185, 129, 0.15);
  border: 1px solid rgba(16, 185, 129, 0.32);
  color: #b9f7db;
  font-weight: 700;
  transition: background 160ms ease, border-color 160ms ease, color 160ms ease;
}

.back-link:hover {
  background: rgba(16, 185, 129, 0.22);
  border-color: rgba(52, 211, 153, 0.48);
  color: #eafff5;
}

.legend ul {
  list-style: none;
  padding: 0;
  margin: 14px 0 0;
}

.legend li {
  display: flex;
  align-items: center;
  gap: 10px;
  color: var(--muted);
  padding: 6px 0;
}

.swatch {
  width: 18px;
  height: 18px;
  border-radius: 5px;
  border: 1px solid rgba(255, 255, 255, 0.16);
}

.wall {
  background: var(--wall);
}

.floor {
  background: var(--floor);
}

.market {
  background: var(--market);
}

.enemy {
  background: var(--enemy);
}

.treasure {
  background: var(--treasure);
}

.stairs {
  background: var(--stairs);
}

.story-panel {
  padding: 18px;
  display: flex;
  flex-direction: column;
  gap: 14px;
  position: sticky;
  top: 16px;
  max-height: calc(100vh - 32px);
  overflow: hidden;
}

.story-header {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.story-tip {
  color: var(--muted);
  max-width: 100%;
  text-align: left;
  line-height: 1.4;
}

.death-notice {
  display: none;
  margin: 0;
  padding: 12px 14px;
  border-radius: 12px;
  background: rgba(127, 29, 29, 0.2);
  border: 1px solid rgba(239, 68, 68, 0.45);
  color: #fca5a5;
  font-weight: 700;
  line-height: 1.45;
}

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

.portrait-card {
  padding: 12px;
  border-radius: 14px;
  background: linear-gradient(180deg, rgba(17, 30, 22, 0.6), rgba(8, 13, 10, 0.45));
  border: 1px solid rgba(255, 255, 255, 0.06);
}

.portrait-label {
  margin: 0 0 8px;
  color: var(--accent-soft);
  font-size: 0.78rem;
  letter-spacing: 0.12em;
  text-transform: uppercase;
}

.portrait-frame {
  position: relative;
  display: grid;
  place-items: center;
  aspect-ratio: 1 / 1;
  padding: 12px;
  border-radius: 14px;
  background:
    radial-gradient(circle at top, rgba(16, 185, 129, 0.16), transparent 52%),
    rgba(4, 6, 5, 0.8);
  overflow: hidden;
}

.portrait-frame img {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: contain;
  image-rendering: auto;
}

.portrait-fallback {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 12px;
  color: var(--muted);
  font-size: 1rem;
  text-align: center;
  line-height: 1.35;
}

.portrait-name {
  display: block;
  margin-top: 10px;
  font-size: 1rem;
}

.action-area {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  align-content: flex-start;
  min-height: 108px;
  padding: 14px;
  border-radius: 14px;
  background: linear-gradient(180deg, rgba(16, 185, 129, 0.08), rgba(9, 14, 11, 0.4));
  border: 1px solid rgba(16, 185, 129, 0.14);
  margin-bottom: 6px;
}

.action-card {
  width: 100%;
  padding: 10px 12px;
  background: rgba(5, 10, 8, 0.58);
  border: 1px solid rgba(16, 185, 129, 0.18);
  border-radius: 12px;
  color: var(--ink);
  line-height: 1.45;
}

.action-button {
  appearance: none;
  border: 0;
  border-radius: 999px;
  background: linear-gradient(180deg, #34d399, #10b981);
  color: #03130c;
  font: inherit;
  font-weight: 700;
  padding: 10px 16px;
  cursor: pointer;
  box-shadow: 0 10px 18px rgba(0, 0, 0, 0.18);
}

.action-button:hover {
  filter: brightness(1.05);
}

.story-log {
  margin: 0;
  padding: 0;
  list-style: none;
  flex: 1 1 auto;
}

.story-log li {
  padding: 14px 16px;
  border-radius: 14px;
  background: rgba(6, 10, 8, 0.62);
  border: 1px solid rgba(255, 255, 255, 0.05);
  color: var(--muted);
  line-height: 1.55;
}

.story-log strong {
  color: var(--ink);
}

@media (max-width: 1040px) {
  .hud {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }

  .play-layout,
  .game-layout {
    grid-template-columns: 1fr;
  }

  .story-header {
    flex-direction: column;
    align-items: start;
  }

  .title-topbar {
    flex-direction: column;
    align-items: stretch;
  }

  .lang-switch {
    align-self: flex-start;
  }

  .story-panel {
    position: static;
    max-height: none;
  }

  .story-tip {
    text-align: left;
  }
}

@media (max-width: 640px) {
  .app-shell {
    width: min(100% - 20px, 1240px);
    margin: 10px auto 24px;
  }

  .title-panel,
  .hud,
  .canvas-frame,
  .legend,
  .story-panel {
    border-radius: 14px;
  }

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

  .portrait-panel {
    grid-template-columns: 1fr;
  }
}
