:root {
  --ink: #222426;
  --muted: #687078;
  --panel: #fffdf8;
  --field: #e5dfcf;
  --line: #d8d1c4;
  --accent: #2f777c;
  --accent-dark: #1f565a;
  --gold: #d79a2b;
  --danger: #aa3f3f;
  --vine: #5f8f59;
  --shadow: 0 10px 26px rgba(34, 36, 38, 0.11);
}

* {
  box-sizing: border-box;
}

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

body {
  background: #f5f1e8;
  color: var(--ink);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

button,
input {
  font: inherit;
}

button {
  min-height: 42px;
  border: 1px solid var(--accent-dark);
  border-radius: 8px;
  background: var(--accent);
  color: white;
  font-weight: 800;
  cursor: pointer;
}

button.secondary {
  background: #f3efe6;
  color: var(--ink);
  border-color: var(--line);
}

.hidden {
  display: none !important;
}

.login-gate {
  display: grid;
  min-height: 100vh;
  place-items: center;
  padding: 20px;
}

.login-panel,
.modal-card {
  width: min(440px, 100%);
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--panel);
  box-shadow: var(--shadow);
  padding: 20px;
}

.login-panel h1,
.modal-card h2 {
  margin: 0 0 8px;
}

.login-panel p,
.modal-card p {
  color: var(--muted);
}

.login-panel label {
  display: block;
  margin: 14px 0 6px;
  color: var(--muted);
  font-weight: 700;
}

.login-row {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 8px;
}

.login-row input {
  min-width: 0;
  min-height: 42px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0 10px;
}

.login-error {
  min-height: 20px;
  color: var(--danger) !important;
  font-weight: 800;
}

.app {
  width: min(1100px, 100%);
  margin: 0 auto;
  padding: 14px;
}

.topbar {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: start;
  margin-bottom: 12px;
}

.topbar h1 {
  margin: 0 0 4px;
  font-size: 28px;
}

.topbar p {
  margin: 0;
  color: var(--muted);
}

.hud {
  display: grid;
  grid-template-columns: 2fr repeat(3, 1fr);
  gap: 8px;
  margin-bottom: 10px;
}

.hud article,
.stage-shell,
.legend,
.notes {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: var(--shadow);
}

.hud article {
  display: grid;
  gap: 4px;
  padding: 10px;
}

.hud span {
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
  text-transform: uppercase;
}

.hud strong {
  font-size: 15px;
}

.stage-shell {
  position: relative;
  overflow: hidden;
  min-height: 64vh;
  background:
    linear-gradient(180deg, rgba(255, 253, 248, 0.72), rgba(229, 223, 207, 0.84)),
    var(--field);
}

#dungeonCanvas {
  display: block;
  width: 100%;
  height: min(68vh, 680px);
  min-height: 480px;
  touch-action: none;
}

.joystick {
  position: absolute;
  left: 18px;
  bottom: 18px;
  width: 116px;
  height: 116px;
  border: 2px solid rgba(31, 86, 90, 0.36);
  border-radius: 50%;
  background: rgba(255, 253, 248, 0.72);
  box-shadow: 0 8px 22px rgba(34, 36, 38, 0.18);
  touch-action: none;
}

.joystick-knob {
  position: absolute;
  top: 33px;
  left: 33px;
  width: 46px;
  height: 46px;
  border-radius: 50%;
  background: var(--accent);
  box-shadow: inset 0 -4px 0 rgba(0, 0, 0, 0.12);
}

.legend {
  display: flex;
  flex-wrap: wrap;
  gap: 8px 14px;
  margin-top: 10px;
  padding: 10px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
}

.legend span {
  display: inline-flex;
  gap: 6px;
  align-items: center;
}

.swatch {
  width: 13px;
  height: 13px;
  border-radius: 3px;
  border: 1px solid rgba(34, 36, 38, 0.16);
}

.swatch.player { background: var(--accent); }
.swatch.enemy { background: var(--danger); }
.swatch.optional { background: #ca7a3d; }
.swatch.button { background: var(--gold); }
.swatch.gate { background: #7c6b5a; }
.swatch.treasure { background: #f2ca4c; }
.swatch.boss { background: #7e4ca8; }

.notes {
  margin-top: 10px;
  padding: 10px 14px;
}

.notes summary {
  cursor: pointer;
  font-weight: 800;
}

.notes li {
  margin: 6px 0;
  color: var(--muted);
}

.modal {
  position: fixed;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 18px;
  background: rgba(34, 36, 38, 0.38);
  z-index: 20;
}

.modal-card {
  display: grid;
  gap: 10px;
}

.battle-stats {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.battle-stat {
  display: grid;
  gap: 6px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #f8f4eb;
  padding: 10px;
}

.battle-stat span {
  color: var(--muted);
  font-size: 12px;
  font-weight: 900;
  text-transform: uppercase;
}

.battle-stat strong {
  font-size: 18px;
}

.battle-meter {
  height: 10px;
  overflow: hidden;
  border: 1px solid rgba(34, 36, 38, 0.12);
  border-radius: 999px;
  background: #e7e0d2;
}

.battle-meter b {
  display: block;
  height: 100%;
  border-radius: inherit;
  transition: width 180ms ease;
}

.battle-stat.player .battle-meter b {
  background: var(--accent);
}

.battle-stat.enemy .battle-meter b {
  background: var(--danger);
}

.battle-log-mini {
  display: grid;
  gap: 4px;
  min-height: 92px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fffaf0;
  padding: 10px;
}

.battle-log-mini p {
  margin: 0;
  color: var(--ink);
  font-size: 14px;
}

.battle-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.battle-actions button:last-child {
  grid-column: 1 / -1;
}

.summary-stats {
  display: grid;
  gap: 8px;
}

.summary-stat {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #f8f4eb;
  padding: 10px;
}

.summary-stat span {
  color: var(--muted);
  font-weight: 800;
}

.summary-stat strong {
  color: var(--ink);
}

@media (max-width: 700px) {
  .app {
    padding: 10px 8px;
  }

  .topbar {
    align-items: center;
  }

  .topbar h1 {
    font-size: 21px;
  }

  .topbar p {
    display: none;
  }

  .hud {
    grid-template-columns: 1fr 1fr;
  }

  .hud article:first-child {
    grid-column: 1 / -1;
  }

  #dungeonCanvas {
    height: 63vh;
    min-height: 420px;
  }

  .joystick {
    width: 104px;
    height: 104px;
  }

  .joystick-knob {
    top: 30px;
    left: 30px;
    width: 40px;
    height: 40px;
  }
}
