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

body {
  background: #14181d;
  color: #d8dee4;
  font-family: "Menlo", "Consolas", monospace;
  font-size: 14px;
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}

header {
  display: flex;
  align-items: baseline;
  gap: 16px;
  padding: 10px 16px;
}

header h1 {
  font-size: 18px;
  letter-spacing: 2px;
}

#map-info {
  color: #8b949e;
}

main {
  flex: 1;
  display: flex;
  justify-content: center;
  align-items: flex-start;
  gap: 16px;
  padding: 0 16px;
}

canvas {
  image-rendering: pixelated;
  max-width: calc(96vw - 280px);
  height: auto;
  border: 1px solid #30363d;
}

aside {
  width: 260px;
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

#stats {
  position: absolute;
  left: 8px;
  top: 8px;
  z-index: 4;
  width: 240px;
  background: rgba(13, 17, 23, 0.85);
  border: 1px solid #30363d;
  padding: 10px 12px;
  font-size: 12px;
}

.stat {
  margin-bottom: 6px;
}

.stat.dim {
  color: #8b949e;
  font-size: 12px;
}

.bar {
  height: 8px;
  background: #30363d;
  margin-top: 4px;
}

.bar-fill {
  height: 100%;
  background: #58a65c;
  transition: width 0.15s;
}

.bar-fill.xp {
  background: #b48ead;
}

.bar-fill.act {
  background: #e8c547;
}

.levelup {
  color: #e8c547;
}

.actions.skills {
  margin-top: 6px;
  flex-wrap: wrap;
}

button:disabled {
  opacity: 0.45;
  cursor: default;
}

button:disabled:hover {
  background: #21262d;
}

#map-wrap {
  position: relative;
}

#minimap {
  position: absolute;
  left: 8px;
  bottom: 8px;
  z-index: 4;
  border: 1px solid #30363d;
  background: rgba(13, 17, 23, 0.85);
  image-rendering: pixelated;
  pointer-events: none;
}

.hidden {
  display: none;
}

#combat-overlay {
  position: absolute;
  inset: 0;
  z-index: 5;
  background: rgba(13, 17, 23, 0.94);
  display: flex;
  align-items: center;
  justify-content: center;
}

#combat-overlay.hidden {
  display: none;
}

.combat-box {
  width: 320px;
  text-align: center;
}

.combat-title {
  font-size: 16px;
  letter-spacing: 3px;
  margin-bottom: 14px;
}

.combat-foe {
  width: 72px;
  height: 66px;
  margin: 0 auto 10px;
  background: #e05d4f;
  clip-path: polygon(50% 0, 100% 100%, 0 100%);
}

.combat-foe.elite-shape {
  width: 96px;
  height: 88px;
  background: #ff8a7a;
}

.combat-name {
  font-size: 15px;
  margin-bottom: 2px;
}

.combat-stat {
  font-size: 12px;
  margin-bottom: 10px;
}

.combat-hp-row {
  margin-bottom: 8px;
  font-size: 12px;
  text-align: left;
}

.combat-hp-row .bar {
  margin-top: 3px;
}

.combat-log {
  border: 1px solid #30363d;
  padding: 8px 10px;
  margin: 12px 0;
  height: 108px;
  overflow: hidden;
  text-align: left;
  font-size: 12px;
  line-height: 1.5;
}

.combat-box .actions {
  justify-content: center;
}

.bar-fill.enemy {
  background: #c9564a;
}

#town-overlay {
  position: absolute;
  inset: 0;
  z-index: 5;
  background: rgba(13, 17, 23, 0.94);
  display: flex;
  align-items: center;
  justify-content: center;
}

#town-overlay.hidden {
  display: none;
}

#victory-overlay {
  position: absolute;
  inset: 0;
  z-index: 6;
  background: rgba(13, 17, 23, 0.94);
  display: flex;
  align-items: center;
  justify-content: center;
}

#victory-overlay.hidden {
  display: none;
}

/* Диалоги в комикс-стиле: пузыри реплик героя и собеседника */
#dialog-overlay {
  position: absolute;
  inset: 0;
  z-index: 7;
  background: rgba(13, 17, 23, 0.78);
  display: flex;
  align-items: flex-end;
  justify-content: center;
  padding-bottom: 48px;
  cursor: pointer;
}

#dialog-overlay.hidden {
  display: none;
}

.dlg-box {
  width: 520px;
  max-width: 90%;
  cursor: default;
}

.dlg-row {
  display: flex;
  gap: 10px;
  margin-bottom: 10px;
  align-items: flex-end;
}

.dlg-row.hero {
  flex-direction: row-reverse;
}

.dlg-row.old {
  opacity: 0.55;
}

.dlg-avatar {
  width: 42px;
  height: 42px;
  border-radius: 50%;
  border: 2px solid #14181d;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: bold;
  font-size: 16px;
}

.dlg-row.stranger .dlg-avatar {
  background: #1a1423;
  color: #c586ff;
  box-shadow: 0 0 12px rgba(197, 134, 255, 0.45);
}

.dlg-row.hero .dlg-avatar {
  background: #f5f5f5;
  color: #14181d;
  font-size: 12px;
}

.dlg-bubble {
  position: relative;
  border: 2px solid #14181d;
  border-radius: 12px;
  padding: 7px 12px 9px;
  font-size: 13px;
  line-height: 1.45;
  box-shadow: 3px 3px 0 rgba(0, 0, 0, 0.5);
  max-width: 420px;
}

.dlg-row.stranger .dlg-bubble {
  background: #241b33;
  color: #d8c8f0;
  border-color: #0a0710;
  border-bottom-left-radius: 2px;
}

.dlg-row.hero .dlg-bubble {
  background: #f5f1e6;
  color: #1a1a1a;
  border-bottom-right-radius: 2px;
}

/* хвостики пузырей */
.dlg-row.stranger .dlg-bubble::after {
  content: "";
  position: absolute;
  left: -9px;
  bottom: 10px;
  border: 5px solid transparent;
  border-right-color: #0a0710;
}

.dlg-row.hero .dlg-bubble::after {
  content: "";
  position: absolute;
  right: -9px;
  bottom: 10px;
  border: 5px solid transparent;
  border-left-color: #14181d;
}

.dlg-name {
  font-size: 10px;
  font-weight: bold;
  letter-spacing: 1px;
  text-transform: uppercase;
  opacity: 0.75;
  margin-bottom: 2px;
}

.dlg-actions {
  display: flex;
  gap: 8px;
  justify-content: flex-end;
  margin-top: 6px;
}

#intro-btn {
  margin-left: auto;
  width: 26px;
  height: 26px;
  border-radius: 50%;
  padding: 0;
  font-weight: bold;
}

/* Вход/сейв в шапке (этап 2). Блок прижат вправо вместе с intro-btn. */
#auth {
  margin-left: auto;
  color: #8b949e;
}
#auth ~ #intro-btn {
  margin-left: 0;
}
#auth .auth-name {
  color: #c9d1d9;
}
#auth button {
  font-size: 12px;
  padding: 2px 8px;
}

/* Кнопка рейтинга (этап 3) — круглая, как intro-btn. */
#board-btn {
  width: 26px;
  height: 26px;
  border-radius: 50%;
  padding: 0;
  font-size: 14px;
  line-height: 1;
}

.town-box {
  width: 480px;
  text-align: left;
}

.town-box .combat-title,
.town-box .combat-name,
.town-box .combat-stat {
  text-align: center;
}

.town-desc {
  font-size: 12px;
  color: #b6bfc9;
  margin: 10px 0;
  line-height: 1.5;
}

.town-head2 {
  font-size: 12px;
  font-weight: bold;
  margin: 8px 0 4px;
}

.town-row {
  font-size: 12px;
  margin-bottom: 5px;
  line-height: 1.5;
}

.elite {
  color: #ff8a7a;
  font-size: 12px;
}

.bonus {
  color: #6fdc73;
  font-size: 12px;
}

.frag {
  color: #c586ff;
}

.dim {
  color: #8b949e;
}

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

button {
  background: #21262d;
  color: #d8dee4;
  border: 1px solid #30363d;
  font: inherit;
  font-size: 12px;
  padding: 3px 10px;
  cursor: pointer;
}

button:hover {
  background: #30363d;
}

#inventory {
  border: 1px solid #30363d;
  padding: 10px 12px;
  font-size: 12px;
}

.inv-item {
  margin-bottom: 4px;
  color: #b6bfc9;
}

#log {
  border: 1px solid #30363d;
  padding: 10px 12px;
  height: 260px;
  overflow-y: auto;
  font-size: 12px;
  line-height: 1.5;
}

.log-line {
  color: #b6bfc9;
  margin-bottom: 2px;
}

.log-line.good {
  color: #6fdc73;
}

.log-line.bad {
  color: #ff8a7a;
}

.log-line.night {
  color: #9ecfff;
}

footer {
  padding: 10px 16px;
}

#legend {
  display: flex;
  flex-wrap: wrap;
  gap: 14px;
}

.legend-item {
  display: flex;
  align-items: center;
  gap: 6px;
  color: #b6bfc9;
}

.swatch {
  display: inline-block;
  width: 14px;
  height: 14px;
  border: 1px solid rgba(0, 0, 0, 0.4);
}
