:root {
  --bg: #1f2129;
  --panel: #282b36;
  --border: #3a3e4d;
  --text: #e6e6eb;
  --muted: #9aa0b4;
  --accent: #7c8cff;
  --accent-text: #11131a;
  --danger: #ff7b7b;
  --json-bg: #2b3447;
  --json-text: #a9d3ff;
  --teal: #3fcfbf;
}
* { box-sizing: border-box; }
body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}
header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px 16px;
  background: var(--panel);
  border-bottom: 1px solid var(--border);
}
.brand { display: flex; align-items: baseline; gap: 16px; min-width: 0; }
.logo { font-weight: 700; font-size: 20px; color: var(--text); text-decoration: none; }
.nav-link { color: var(--muted); font-weight: 600; text-decoration: none; white-space: nowrap; }
.nav-link:hover, .nav-link[aria-current="page"] { color: var(--text); }
.account { display: flex; align-items: center; gap: 10px; }
.avatar {
  display: grid;
  place-items: center;
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: var(--accent);
  color: var(--accent-text);
  font-weight: 700;
}
main { max-width: 1200px; margin: 0 auto; padding: 32px 16px; }
h1 { font-size: 28px; margin: 0 0 8px; }
p { color: var(--muted); margin: 0 0 16px; }
.card {
  max-width: 640px;
  margin: 0 auto 16px;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 24px;
}
.button {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  min-height: 44px;
  padding: 10px 18px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: transparent;
  color: var(--text);
  font: inherit;
  text-decoration: none;
  cursor: pointer;
}
.button.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-text); font-weight: 600; }
.button.danger { background: var(--danger); border-color: var(--danger); color: var(--accent-text); font-weight: 600; }
.button:disabled, .icon-button:disabled, .add-card:disabled { cursor: not-allowed; opacity: 0.6; }
.error { color: var(--danger); white-space: pre-line; }
.status { white-space: pre-line; }

/* Список персонажей */
.icon-sprite { position: absolute; width: 0; height: 0; overflow: hidden; }
.icon { width: 22px; height: 22px; flex: none; }
.characters-head {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 16px;
}
.page-title { margin: 0; font-size: 32px; font-weight: 800; line-height: 1.2; letter-spacing: -0.01em; }
.page-count { color: var(--muted); font-size: 18px; font-weight: 500; }
.toolbar { display: flex; align-items: center; gap: 8px; }
.json-button {
  padding: 0 18px;
  border: 0;
  background: var(--json-bg);
  color: var(--json-text);
  font-family: ui-monospace, "SFMono-Regular", Menlo, Consolas, monospace;
  font-weight: 700;
}
.icon-button {
  display: grid;
  place-items: center;
  width: 44px;
  height: 44px;
  padding: 0;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: transparent;
  color: var(--text);
  cursor: pointer;
}
.character-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 16px;
  margin: 0 0 16px;
  padding: 0;
  list-style: none;
}
@media (min-width: 600px) {
  .character-grid:not(.is-list) { grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); }
}
.character-card {
  position: relative;
  display: flex;
  align-items: center;
  min-width: 0;
  min-height: 96px;
  padding: 16px;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 14px;
}
.character-body {
  display: flex;
  flex: 1;
  align-items: center;
  gap: 16px;
  min-width: 0;
  padding-right: 36px; /* the menu button sits in the corner, outside the text */
}
.portrait {
  position: relative;
  display: grid;
  place-items: center;
  flex: none;
  width: 64px;
  height: 64px;
  overflow: hidden;
  border-radius: 12px;
  background: var(--accent);
  color: var(--accent-text);
  font-size: 26px;
  font-weight: 800;
}
.portrait img {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
}
.character-text { min-width: 0; }
.character-name {
  margin: 0;
  color: var(--text);
  font-size: 20px;
  font-weight: 800;
  line-height: 1.2;
  overflow-wrap: anywhere;
}
.character-subtitle { margin: 2px 0 6px; font-size: 15px; }
.character-hp {
  display: flex;
  align-items: center;
  gap: 6px;
  margin: 0;
  color: var(--text);
  font-size: 15px;
  font-weight: 600;
}
.character-hp .icon { width: 18px; height: 18px; color: var(--teal); }
.card-menu { position: absolute; top: 8px; right: 8px; }
.card-menu > summary {
  display: grid;
  place-items: center;
  width: 44px;
  height: 44px;
  border-radius: 10px;
  color: var(--muted);
  cursor: pointer;
  list-style: none;
}
.card-menu > summary::-webkit-details-marker { display: none; }
.card-menu > summary:hover,
.card-menu[open] > summary { color: var(--text); }
.card-menu:not([open]) .menu-items { display: none; }
.menu-items {
  position: absolute;
  top: 46px;
  right: 0;
  z-index: 2;
  display: grid;
  min-width: 200px;
  padding: 6px;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 12px;
  box-shadow: 0 12px 30px rgba(0, 0, 0, 0.45);
}
.menu-item {
  min-height: 44px;
  padding: 0 12px;
  border: 0;
  border-radius: 8px;
  background: transparent;
  color: var(--text);
  font: inherit;
  text-align: left;
  cursor: pointer;
}
.menu-item:hover { background: rgba(255, 255, 255, 0.06); }
.menu-item.danger { color: var(--danger); }
.add-card {
  display: grid;
  place-items: center;
  width: 100%;
  min-height: 96px;
  padding: 0;
  border: 1px dashed var(--border);
  border-radius: 14px;
  background: var(--panel);
  color: var(--accent);
  cursor: pointer;
}
.add-card .icon { width: 44px; height: 44px; }
.character-grid.is-list { gap: 10px; }
.character-grid.is-list .character-card { min-height: 72px; padding: 12px; }
.character-grid.is-list .character-body { gap: 12px; }
.character-grid.is-list .portrait { width: 44px; height: 44px; border-radius: 10px; font-size: 18px; }
.character-grid.is-list .character-name { font-size: 17px; }
.character-grid.is-list .character-subtitle { margin: 0; }
.character-grid.is-list .add-card { min-height: 56px; }

.empty-state { margin-top: 8px; text-align: center; }
.empty-title { margin: 0 0 4px; color: var(--text); font-weight: 700; }

/* Диалог подтверждения */
.dialog {
  width: min(420px, calc(100% - 32px));
  padding: 24px;
  background: var(--panel);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 14px;
}
.dialog::backdrop { background: rgba(8, 9, 12, 0.7); }
.dialog h2 { margin: 0 0 8px; font-size: 22px; }
.dialog p { margin: 0 0 20px; }
.dialog-actions { display: flex; flex-wrap: wrap; justify-content: flex-end; gap: 10px; }

/* Справка по миру Мифика */
main.lore { max-width: 760px; }
main.lore h1 { font-size: 36px; letter-spacing: -0.02em; }
main.lore h2 { margin: 32px 0 8px; font-size: 24px; }
main.lore h3 { margin: 22px 0 6px; font-size: 18px; }
main.lore a { color: var(--accent); }
main.lore .lede { color: var(--text); font-size: 18px; }
main.lore .note { font-size: 14px; }
main.lore ul, main.lore ol { margin: 0 0 16px; padding-left: 1.2em; color: var(--muted); }
main.lore li { margin: 4px 0; }
main.lore li strong, main.lore h2, main.lore h3 { color: var(--text); }
.toc {
  display: flex;
  flex-wrap: wrap;
  gap: 8px 14px;
  margin: 0 0 24px;
  padding: 0;
  list-style: none;
}
.toc a { text-decoration: none; }
.toc a:hover { text-decoration: underline; }
.table-wrap { overflow-x: auto; margin: 0 0 16px; }
table { width: 100%; border-collapse: collapse; font-size: 15px; }
th, td { padding: 8px 10px; text-align: left; border-bottom: 1px solid var(--border); vertical-align: top; }
th { color: var(--muted); font-weight: 600; }
.links { display: grid; gap: 10px; margin: 0; padding: 0; list-style: none; }
.links a {
  display: block;
  padding: 12px 14px;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 12px;
  text-decoration: none;
}
.links a:hover { border-color: var(--accent); }
.links small { display: block; color: var(--muted); font-size: 14px; }

:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; }
[hidden] { display: none !important; }

/* Карточка — ссылка на лист персонажа: нажимается вся, меню остаётся поверх. */
a.character-body { color: inherit; text-decoration: none; }
a.character-body::after { content: ""; position: absolute; inset: 0; border-radius: 14px; }
a.character-body:focus-visible { outline: none; }
a.character-body:focus-visible::after { outline: 2px solid var(--accent); outline-offset: 2px; }
.character-card:hover { border-color: var(--accent); }
.card-menu { z-index: 1; }
