/* ---- Основные цвета ---- */
:root {
  --bg-primary: #0d0d0d;
  --bg-secondary: #1a1a1a;
  --bg-card: #242424;
  --bg-input: #2a2a2a;
  --bg-hover: #333333;
  --border-color: #3a3a3a;
  --text-primary: #f0ece6;
  --text-secondary: #b8b0a8;
  --text-muted: #7a7268;
  --text-muted-purple: #6d487a;
  --beige: #d4c5b0;
  --beige-dark: #b8a894;
  --green: #4a9e6e;
  --green-dark: #3a7e5e;
  --green-bright: #5cb885;
  --purple: #7b5ea7;
  --purple-dark: #5e3f8a;
  --purple-bright: #9b7ac7;
  --red: #c0392b;
  --red-dark: #a93226;
  --shadow: 0 4px 20px rgba(0, 0, 0, 0.6);
}

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

body {
  font-family: 'Segoe UI', 'Roboto', system-ui, sans-serif;
  background: var(--bg-primary);
  color: var(--text-primary);
  min-height: 100vh;
  line-height: 1.6;
}

::-webkit-scrollbar {
  width: 8px;
}

::-webkit-scrollbar-track {
  background: var(--bg-secondary);
}

::-webkit-scrollbar-thumb {
  background: var(--purple-dark);
  border-radius: 4px;
}

::-webkit-scrollbar-thumb:hover {
  background: var(--purple);
}

#app {
  max-width: 1200px;
  margin: 0 auto;
  padding: 20px;
  min-height: 100vh;
}

/* ---- Шапка ---- */
header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 12px 20px;
  background: var(--bg-secondary);
  border-radius: 12px;
  border: 1px solid var(--border-color);
  margin-bottom: 24px;
  box-shadow: var(--shadow);
  flex-wrap: wrap;
  gap: 12px;
}

header h1 {
  font-size: 24px;
  font-weight: 600;
  color: var(--beige);
  letter-spacing: 1px;
  margin: 0;
}

header h1 span {
  color: var(--purple-bright);
}

.header-btn {
  color: var(--purple-bright);
  font-size: 13px;
  text-decoration: none;
  font-weight: 500;
  padding: 6px 12px;
  border-radius: 8px;
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  transition: background 0.2s, color 0.2s;
  white-space: nowrap;
  cursor: pointer;
}

.header-btn:hover {
  background: var(--bg-hover);
  color: var(--beige);
}

#auth-section {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

#auth-section button {
  padding: 6px 16px;
  border: none;
  border-radius: 8px;
  font-size: 13px;
  cursor: pointer;
  transition: all 0.2s;
}

#login-btn {
  background: var(--purple);
  color: white;
}

#login-btn:hover {
  background: var(--purple-bright);
  transform: translateY(-1px);
}

#logout-btn {
  background: var(--red);
  color: white;
}

#logout-btn:hover {
  background: var(--red-dark);
}

#user-info {
  color: var(--text-secondary);
  font-size: 13px;
}

button {
  padding: 8px 16px;
  border: none;
  border-radius: 8px;
  font-size: 14px;
  cursor: pointer;
  transition: all 0.2s;
  font-weight: 500;
}

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

button:active {
  transform: translateY(0px);
}

.btn-primary {
  background: var(--purple);
  color: white;
}

.btn-primary:hover {
  background: var(--purple-bright);
}

.btn-success {
  background: var(--green);
  color: white;
}

.btn-success:hover {
  background: var(--green-bright);
}

.btn-danger {
  background: var(--red);
  color: white;
}

.btn-danger:hover {
  background: var(--red-dark);
}

.btn-beige {
  background: var(--beige-dark);
  color: #1a1a1a;
}

.btn-beige:hover {
  background: var(--beige);
}

#character-list {
  margin-top: 8px;
}

#character-list h2 {
  color: var(--beige);
  font-weight: 500;
  font-size: 22px;
}

.cards-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 16px;
  margin-top: 16px;
}

/* ---- Карточка персонажа ---- */
.character-card {
  display: flex;
  align-items: center;
  gap: 12px;
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: 12px;
  padding: 12px 16px;
  cursor: pointer;
  transition: all 0.25s ease;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.3);
  height: 100px;
}

.character-card:hover {
  border-color: var(--purple);
  background: var(--bg-hover);
  transform: translateY(-2px);
  box-shadow: 0 4px 16px rgba(123, 94, 167, 0.2);
}

.character-card .card-avatar {
  flex-shrink: 0;
  width: 56px;
  height: 56px;
  border-radius: 8px;
  overflow: hidden;
  background: var(--bg-input);
  border: 2px solid var(--border-color);
}

.character-card .card-avatar img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.character-card .card-avatar-placeholder {
  width: 100%;
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 28px;
  color: var(--text-muted);
}

.character-card .card-info {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: 4px;
  overflow: hidden;
}

.character-card .card-info .name {
  font-size: 16px;
  font-weight: 600;
  color: var(--text-primary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 100%;
}

.character-card .card-stats {
  display: flex;
  gap: 8px;
  align-items: center;
  flex-wrap: nowrap;
  font-size: 12px;
  color: var(--text-secondary);
}

.character-card .card-stats .card-level,
.character-card .card-stats .card-health {
  background: var(--bg-input);
  padding: 2px 8px;
  border-radius: 6px;
  white-space: nowrap;
}

.character-card .card-stats .health-current {
  font-weight: 700;
}

.character-card .health-current.health-green {
  color: #4ade80;
}

.character-card .health-current.health-yellow {
  color: #fbbf24;
}

.character-card .health-current.health-red {
  color: #f87171;
}

/* ---- Лист персонажа ---- */
#character-sheet {
  background: var(--bg-secondary);
  border-radius: 12px;
  border: 1px solid var(--border-color);
  padding: 24px 28px;
  box-shadow: var(--shadow);
}

#character-sheet .sheet-nav {
  display: flex;
  gap: 10px;
  margin-bottom: 20px;
  flex-wrap: wrap;
}

#character-sheet .sheet-nav button {
  padding: 6px 16px;
  border-radius: 8px;
  font-size: 13px;
}

#char-title {
  color: var(--beige);
  font-size: 26px;
  font-weight: 500;
  margin-bottom: 20px;
  padding-bottom: 12px;
  border-bottom: 1px solid var(--border-color);
}

#character-form {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 20px 30px;
}

#character-form .full-width {
  grid-column: 1 / -1;
}

#character-form h3 {
  grid-column: 1 / -1;
  color: var(--beige-dark);
  font-size: 16px;
  font-weight: 500;
  margin-top: 4px;
  padding-bottom: 6px;
  border-bottom: 1px solid var(--border-color);
}

/* Общие стили полей */
.field {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.field label {
  font-size: 13px;
  color: var(--text-secondary);
  font-weight: 500;
}

.field input,
.field select {
  padding: 8px 12px;
  background: var(--bg-input);
  border: 1px solid var(--border-color);
  border-radius: 8px;
  color: var(--text-primary);
  font-size: 14px;
  transition: border 0.2s;
  width: 100%;
  height: 42px;
}

.field input:focus,
.field select:focus,
.field textarea:focus {
  outline: none;
  border-color: var(--purple);
  box-shadow: 0 0 0 2px rgba(123, 94, 167, 0.2);
}

.field input[readonly] {
  color: var(--text-muted);
  background: var(--bg-secondary);
}

.field textarea {
  padding: 8px 12px;
  background: var(--bg-input);
  border: 1px solid var(--border-color);
  border-radius: 8px;
  color: var(--text-primary);
  font-size: 14px;
  width: 100%;
  font-family: inherit;
  resize: none;
}

#character-notes {
  width: 100% !important;
  max-width: 100% !important;
  box-sizing: border-box;
  height: 400px;
  resize: none;
  padding: 10px 14px;
  background: var(--bg-input);
  border: 1px solid var(--border-color);
  border-radius: 8px;
  color: var(--text-primary);
  font-size: 14px;
  font-family: inherit;
  grid-column: 1 / -1;
}

#character-notes:focus {
  border-color: var(--purple);
}

#char-appearance {
  height: 130px;
}

#feature-description {
  height: 130px;
}

#item-name {
  height: 60px;
  resize: none;
}

#item-description {
  height: 180px;
  resize: none;
}

/* ============================================================
   ВЕРХНЯЯ ЧАСТЬ ЛИСТА
   ============================================================ */
.character-header {
  grid-column: 1 / -1;
  display: flex;
  gap: 20px;
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: 14px;
  padding: 18px 22px;
  margin-bottom: 10px;
  align-items: stretch;
  flex-wrap: wrap;
}

.character-header .avatar-preview {
  flex-shrink: 0;
  width: 150px;
  height: 200px;
  border-radius: 10px;
  overflow: hidden;
  background: var(--bg-input);
  border: 2px solid var(--border-color);
}

.character-header .avatar-preview img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.character-header .header-center {
  flex: 0.45;
  min-width: 100px;
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: 2px;
}

.character-header .header-center .field label {
  font-size: 10px;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.4px;
}

.character-header .header-center .field textarea#char-name {
  padding: 2px 6px;
  background: var(--bg-input);
  border: 1px solid var(--border-color);
  border-radius: 5px;
  color: var(--text-primary);
  font-size: 13px;
  width: 100%;
  height: 46px;
  resize: none;
  font-family: inherit;
  line-height: 1.3;
}

.character-header .header-center .field textarea#char-name:focus {
  outline: none;
  border-color: var(--purple);
}

.character-header .header-center input[type="file"] {
  padding: 2px 0;
  color: var(--text-secondary);
  font-size: 10px;
  height: auto;
}

.character-header .header-center input[type="file"]::file-selector-button {
  padding: 2px 8px;
  border: none;
  border-radius: 4px;
  background: var(--purple-dark);
  color: white;
  cursor: pointer;
  font-weight: 500;
  font-size: 10px;
  margin-right: 4px;
}

.character-header .header-center input[type="file"]::file-selector-button:hover {
  background: var(--purple);
}

.character-header .header-right {
  flex: 0.75;
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1px 8px;
  align-content: center;
  padding-left: 10px;
  border-left: 1px solid var(--border-color);
}

.character-header .header-right .detail-item {
  display: flex;
  flex-direction: column;
  gap: 1px;
}

.character-header .header-right .detail-item label {
  font-size: 7.5px;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.3px;
}

.character-header .header-right .detail-item input {
  padding: 1px 5px;
  background: var(--bg-input);
  border: 1px solid var(--border-color);
  border-radius: 4px;
  color: var(--text-primary);
  font-size: 10px;
  width: 100%;
  height: 22px;
}

.character-header .header-right .detail-item input:focus {
  outline: none;
  border-color: var(--purple);
}

.character-header .header-right .detail-full {
  grid-column: 1 / -1;
}

.character-header .header-right .detail-full textarea {
  padding: 1px 5px;
  background: var(--bg-input);
  border: 1px solid var(--border-color);
  border-radius: 4px;
  color: var(--text-primary);
  font-size: 10px;
  width: 100%;
  height: 130px;
  resize: none;
  font-family: inherit;
}

.character-header .header-right .detail-full textarea:focus {
  outline: none;
  border-color: var(--purple);
}

/* ---- Уровень и Опыт ---- */
.level-exp-row {
  display: flex;
  gap: 10px;
  justify-content: flex-start;
  margin-bottom: 6px;
  width: 100%;
}

.mini-resource {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: 6px;
  padding: 4px 8px 6px;
  transition: border 0.2s, background 0.2s;
}

.mini-resource:hover {
  border-color: var(--purple-dark);
  background: var(--bg-hover);
}

.mini-resource label {
  font-size: 8px;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.4px;
}

.mini-resource input {
  background: var(--bg-input);
  border: none;
  border-radius: 4px;
  color: var(--text-primary);
  font-size: 18px;
  font-weight: 700;
  text-align: center;
  padding: 2px 0;
  height: 32px;
}

.mini-resource input:focus {
  outline: none;
  border-color: var(--purple);
}

.mini-resource.level input {
  width: 44px;
  font-size: 18px;
}

.mini-resource.exp input {
  width: 90px;
  font-size: 18px;
}

/* ---- Ресурсы (2 колонки) ---- */
.resources-grid {
  grid-column: 1 / -1;
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 12px;
  margin-top: 8px;
}

.resource-block {
  display: flex;
  flex-direction: row;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: 10px;
  padding: 12px 16px;
  transition: border 0.2s, background 0.2s;
}

.resource-block:hover {
  border-color: var(--purple-dark);
  background: var(--bg-hover);
}

.resource-left {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  flex-shrink: 0;
  min-width: 110px;
}

.resource-left .resource-icon {
  width: 64px;
  height: 64px;
  object-fit: contain;
  opacity: 0.6;
  transition: opacity 0.2s;
}

.resource-block:hover .resource-left .resource-icon {
  opacity: 1;
}

.resource-left label {
  font-size: 10px;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  text-align: center;
  line-height: 1.2;
  max-width: 120px;
  word-wrap: break-word;
}

.resource-right {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
}

.resource-control {
  display: flex;
  align-items: center;
  gap: 6px;
}

.res-btn {
  width: 28px;
  height: 28px;
  border: none;
  border-radius: 6px;
  font-size: 16px;
  font-weight: 700;
  cursor: pointer;
  transition: all 0.15s;
  display: flex;
  align-items: center;
  justify-content: center;
  color: white;
  flex-shrink: 0;
}

.res-btn:hover {
  transform: scale(1.1);
}

.res-btn:active {
  transform: scale(0.9);
}

.minus-btn {
  background: var(--red);
}

.minus-btn:hover {
  background: var(--red-dark);
}

.plus-btn {
  background: var(--green);
}

.plus-btn:hover {
  background: var(--green-bright);
}

.resource-display {
  font-size: 18px;
  font-weight: 700;
  min-width: 56px;
  text-align: center;
  font-variant-numeric: tabular-nums;
}

.resource-display .sep {
  color: var(--text-muted);
  margin: 0 2px;
}

/* ---- Цвета ресурсов ---- */
.resource-display #res-health-current {
  color: var(--green-bright);
}

.resource-display #res-inspiration-current {
  color: var(--text-secondary);
}

.resource-display #res-inspiration-max {
  color: var(--text-secondary);
}

.resource-display #res-health-max {
  color: var(--text-secondary);
}

/* ---- Переносимый вес и скорость – серые, красные при перегрузке ---- */
#res-carry-current,
#res-carry-weight,
#res-speed {
  color: var(--text-secondary);
}

#carry-weight-block.overload #res-carry-current,
#carry-weight-block.overload #res-carry-weight,
#carry-weight-block.overload .sep {
  color: var(--red);
}

#res-speed.overload {
  color: var(--red) !important;
}

/* Computed ресурсы */
.resource-block.computed {
  background: var(--bg-secondary);
  border-color: var(--border-color);
}

.resource-block.computed:hover {
  border-color: var(--purple-dark);
  background: var(--bg-card);
}

.computed-right {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
}

.computed-right .computed-value {
  font-size: 24px;
  font-weight: 700;
}

.computed-right .computed-hint {
  font-size: 10px;
  color: var(--text-muted);
  white-space: nowrap;
}

.resource-block.computed .resource-left .resource-icon {
  opacity: 0.5;
}

.resource-block.computed:hover .resource-left .resource-icon {
  opacity: 0.9;
}

/* ---- Цвета здоровья ---- */
#res-health-current.health-green {
  color: #4ade80;
}

#res-health-current.health-yellow {
  color: #fbbf24;
}

#res-health-current.health-red {
  color: #f87171;
}

/* ---- Адаптив ресурсов ---- */
@media (max-width: 480px) {
  .resources-grid {
    grid-template-columns: 1fr 1fr;
    gap: 8px;
  }

  .resource-block {
    padding: 10px 12px;
  }

  .resource-left {
    min-width: 90px;
  }

  .resource-left .resource-icon {
    width: 52px;
    height: 52px;
  }

  .resource-left label {
    font-size: 8px;
    max-width: 80px;
  }

  .resource-control {
    gap: 4px;
  }

  .res-btn {
    width: 24px;
    height: 24px;
    font-size: 14px;
  }

  .resource-display {
    font-size: 15px;
    min-width: 44px;
  }

  .computed-right .computed-value {
    font-size: 20px;
  }
}

/* ---- Адаптив верхней части ---- */
@media (max-width: 820px) {
  .character-header {
    flex-direction: column;
    align-items: center;
    padding: 14px 16px;
  }

  .character-header .avatar-preview {
    width: 100px;
    height: 140px;
  }

  .character-header .header-center {
    width: 100%;
  }

  .character-header .header-right {
    border-left: none;
    border-top: 1px solid var(--border-color);
    padding-left: 0;
    padding-top: 8px;
    width: 100%;
  }

  .level-exp-row {
    justify-content: center;
  }
}

/* ============================================================
   ХАРАКТЕРИСТИКИ
   ============================================================ */
.attributes-grid {
  grid-column: 1 / -1;
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 12px;
  width: 100%;
}

.attr-item {
  display: flex;
  flex-direction: row;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: 12px;
  padding: 14px 18px;
  width: 100%;
  min-height: 100px;
  height: 100%;
  transition: border 0.2s, background 0.2s;
  box-sizing: border-box;
}

.attr-item:hover {
  border-color: var(--purple-dark);
  background: var(--bg-hover);
}

.attr-left {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 3px;
  flex-shrink: 0;
  min-width: 72px;
}

.attr-left .attr-icon {
  width: 38px;
  height: 38px;
  object-fit: contain;
  opacity: 0.5;
  transition: opacity 0.2s;
}

.attr-item:hover .attr-left .attr-icon {
  opacity: 0.9;
}

.attr-left label {
  font-size: 10px;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.4px;
  text-align: center;
  line-height: 1.2;
  max-width: 72px;
  word-wrap: break-word;
}

.attr-content {
  display: flex;
  flex-direction: row;
  align-items: center;
  justify-content: flex-end;
  gap: 10px;
  flex-shrink: 0;
}

.attr-item input {
  padding: 0;
  background: var(--bg-input);
  border: 1px solid var(--border-color);
  border-radius: 8px;
  color: var(--text-primary);
  font-size: 24px;
  font-weight: 700;
  width: 60px;
  height: 60px;
  text-align: center;
  flex-shrink: 0;
  box-sizing: border-box;
}

.attr-item input:focus {
  border-color: var(--green);
  outline: none;
}

.attr-roll-btn {
  width: 60px;
  height: 60px;
  padding: 0;
  border: none;
  border-radius: 8px;
  background: var(--purple-dark);
  color: white;
  font-size: 24px;
  cursor: pointer;
  transition: all 0.2s;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  box-sizing: border-box;
}

.attr-roll-btn:hover {
  background: var(--purple-bright);
  transform: scale(1.05);
}

.attr-roll-btn:active {
  transform: scale(0.95);
}

.attr-roll-btn img {
  width: 32px;
  height: 32px;
  object-fit: contain;
  display: block;
  filter: brightness(0) invert(1);
  transition: transform 0.2s;
}

.attr-roll-btn:hover img {
  transform: scale(1.1);
}

/* ---- Переключатель скрытых бросков ---- */
.attributes-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 8px;
  grid-column: 1 / -1;
}

.stealth-toggle {
  display: flex;
  align-items: center;
  gap: 8px;
}

.stealth-label {
  font-size: 13px;
  color: var(--text-muted);
  user-select: none;
}

/* ============================================================
   СЕТКА СПОСОБНОСТЕЙ И ЧЕРТ
   ============================================================ */
.features-grid {
  grid-column: 1 / -1;
  display: grid;
  grid-template-columns: 1.5fr 1fr;
  gap: 20px;
  align-items: start;
  margin-top: 12px;
}

.features-column {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.features-column-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  padding-bottom: 6px;
  border-bottom: 1px solid var(--border-color);
}

.features-column-header h4 {
  font-size: 16px;
  font-weight: 500;
  color: var(--beige-dark);
  margin: 0;
}

.features-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.ability-item,
.trait-item {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: 8px;
  padding: 12px 16px;
}

.ability-header,
.trait-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: 8px;
}

.ability-header strong,
.trait-header strong {
  color: var(--beige);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 180px;
  display: inline-block;
}

.ability-use-btn {
  padding: 4px 14px;
  font-size: 13px;
  border-radius: 6px;
  background: var(--green-dark);
  color: white;
  border: 1px solid var(--green-dark);
  cursor: pointer;
  transition: background 0.2s;
  margin-left: auto;
}

.ability-use-btn:hover {
  background: var(--green);
}

.ability-description,
.trait-description {
  color: var(--text-secondary);
  font-size: 13px;
  margin-top: 4px;
  padding-left: 4px;
  cursor: pointer;
  overflow: hidden;
  text-overflow: ellipsis;
  display: -webkit-box;
  -webkit-line-clamp: 3;
  -webkit-box-orient: vertical;
  line-clamp: 3;
  line-height: 1.4;
  max-height: calc(1.4em * 3);
  transition: max-height 0.2s;
}

.ability-description.expanded,
.trait-description.expanded {
  -webkit-line-clamp: unset !important;
  line-clamp: unset !important;
  max-height: none !important;
  overflow: visible !important;
  text-overflow: unset !important;
  display: block !important;
}

/* Меню */
.card-menu {
  position: relative;
  display: inline-block;
}

.card-menu-btn {
  width: 32px;
  height: 32px;
  border-radius: 8px;
  background: var(--bg-input);
  border: 1px solid var(--border-color);
  color: var(--text-secondary);
  font-size: 18px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.2s;
  padding: 0;
  line-height: 1;
}

.card-menu-btn:hover {
  background: var(--bg-hover);
  border-color: var(--purple);
}

.card-menu-dropdown {
  display: none;
  position: absolute;
  right: 0;
  top: 100%;
  margin-top: 6px;
  background: var(--bg-secondary);
  border: 1px solid var(--border-color);
  border-radius: 10px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.7);
  min-width: 130px;
  z-index: 100;
  overflow: hidden;
}

.card-menu.open .card-menu-dropdown {
  display: block;
}

.card-menu-item {
  display: block;
  width: 100%;
  padding: 8px 16px;
  background: none;
  border: none;
  text-align: left;
  font-size: 14px;
  color: var(--text-primary);
  cursor: pointer;
  transition: background 0.15s;
}

.card-menu-item:hover {
  background: var(--bg-hover);
}

.card-menu-item.delete-action:hover,
.card-menu-item.ability-delete-action:hover,
.card-menu-item.trait-delete-action:hover,
.card-menu-item.item-delete-action:hover {
  color: var(--red);
}

/* Точки стоимости */
.ability-cost-dots {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-top: 6px;
  flex-wrap: wrap;
}

.ability-cost-dots .cost-label {
  font-size: 12px;
  color: var(--text-muted);
  margin-right: 4px;
}

.ability-cost-dots .dot {
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: var(--bg-input);
  border: 1px solid var(--border-color);
  display: inline-block;
  transition: background 0.2s;
}

.ability-cost-dots .dot.filled {
  background: #ffffff;
  border-color: #ffffff;
  box-shadow: 0 0 6px rgba(255, 255, 255, 0.4);
}

/* ---- Модальное окно ---- */
.modal {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(0, 0, 0, 0.7);
  display: flex;
  justify-content: center;
  align-items: center;
  z-index: 1000;
  backdrop-filter: blur(4px);
}

.modal-content {
  background: var(--bg-secondary);
  border: 1px solid var(--border-color);
  border-radius: 16px;
  padding: 28px 32px;
  max-width: 520px;
  width: 92%;
  max-height: 90vh;
  overflow-y: auto;
  box-shadow: var(--shadow);
  position: relative;
}

.modal-content .field textarea {
  resize: none;
}

.modal-close {
  position: absolute;
  top: 12px;
  right: 18px;
  font-size: 28px;
  color: var(--text-muted);
  cursor: pointer;
  line-height: 1;
}

.modal-close:hover {
  color: var(--text-primary);
}

.modal-content h2 {
  color: var(--beige);
  font-size: 20px;
  font-weight: 500;
  margin-bottom: 16px;
}

.modal-content .field {
  margin-bottom: 12px;
}

.modal-content .field label {
  font-size: 13px;
  color: var(--text-secondary);
  margin-bottom: 2px;
}

.modal-content .field input,
.modal-content .field select {
  padding: 8px 12px;
  background: var(--bg-input);
  border: 1px solid var(--border-color);
  border-radius: 8px;
  color: var(--text-primary);
  font-size: 14px;
  width: 100%;
  height: 42px;
}

.modal-content .field textarea {
  padding: 8px 12px;
  background: var(--bg-input);
  border: 1px solid var(--border-color);
  border-radius: 8px;
  color: var(--text-primary);
  font-size: 14px;
  width: 100%;
  font-family: inherit;
  resize: none;
}

.modal-content .field input:focus,
.modal-content .field select:focus,
.modal-content .field textarea:focus {
  border-color: var(--purple);
}

.modal-content button[type="submit"] {
  background: var(--purple);
  color: white;
  padding: 8px 24px;
  border-radius: 8px;
  margin-right: 8px;
}

.modal-content button[type="submit"]:hover {
  background: var(--purple-bright);
}

#feature-cancel-btn {
  background: var(--bg-input);
  color: var(--text-secondary);
  border: 1px solid var(--border-color);
}

#feature-cancel-btn:hover {
  background: var(--bg-hover);
}

/* ---- Toast уведомления ---- */
.toast-container {
  position: fixed;
  bottom: 24px;
  right: 24px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  z-index: 9999;
  max-width: 360px;
  width: 100%;
}

.toast {
  background: var(--bg-secondary);
  border: 1px solid var(--border-color);
  border-radius: 12px;
  padding: 16px 20px;
  box-shadow: var(--shadow);
  color: var(--text-primary);
  font-size: 14px;
  animation: slideInRight 0.3s ease, fadeOut 0.3s ease 4.7s forwards;
  border-left: 4px solid var(--purple);
}

.toast.success {
  border-left-color: var(--green);
}

.toast.error {
  border-left-color: var(--red);
}

.toast .toast-title {
  font-weight: 600;
  font-size: 15px;
  margin-bottom: 4px;
}

.toast .toast-body {
  color: var(--text-secondary);
  font-size: 13px;
}

.toast .toast-dice {
  display: flex;
  gap: 4px;
  flex-wrap: wrap;
  margin-top: 6px;
}

.toast .toast-dice img {
  width: 28px;
  height: 28px;
}

@keyframes slideInRight {
  from {
    transform: translateX(120%);
    opacity: 0;
  }

  to {
    transform: translateX(0);
    opacity: 1;
  }
}

@keyframes fadeOut {
  to {
    opacity: 0;
    transform: translateY(-10px);
  }
}

/* ---- Кастомный переключатель ---- */
.switch {
  position: relative;
  display: inline-block;
  width: 44px;
  height: 24px;
  flex-shrink: 0;
}

.switch input {
  opacity: 0;
  width: 0;
  height: 0;
}

.switch .slider {
  position: absolute;
  cursor: pointer;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: var(--bg-input);
  border: 1px solid var(--border-color);
  transition: 0.3s;
  border-radius: 24px;
}

.switch .slider:before {
  content: "";
  position: absolute;
  height: 18px;
  width: 18px;
  left: 2px;
  bottom: 2px;
  background: var(--text-muted);
  transition: 0.3s;
  border-radius: 50%;
}

.switch input:checked+.slider {
  background: var(--purple);
  border-color: var(--purple);
}

.switch input:checked+.slider:before {
  transform: translateX(20px);
  background: white;
}

.switch input:focus+.slider {
  box-shadow: 0 0 0 2px rgba(123, 94, 167, 0.3);
}

/* ---- Селектор точек ---- */
.ability-cost-selector {
  display: flex;
  gap: 4px;
  align-items: center;
  margin-top: 6px;
  padding: 6px 10px;
  background: var(--bg-input);
  border-radius: 6px;
  border: 1px solid var(--border-color);
  flex-wrap: wrap;
}

.ability-cost-selector .cost-label {
  font-size: 12px;
  color: var(--text-muted);
  margin-right: 6px;
}

.ability-cost-selector .dot-option {
  width: 26px;
  height: 26px;
  border-radius: 50%;
  border: 2px solid var(--border-color);
  background: var(--bg-card);
  cursor: pointer;
  transition: all 0.2s;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 10px;
  color: var(--text-muted);
  font-weight: 600;
}

.ability-cost-selector .dot-option:hover {
  border-color: var(--purple);
  background: var(--bg-hover);
  transform: scale(1.05);
}

.ability-cost-selector .dot-option.active {
  border-color: var(--purple-bright);
  background: var(--purple);
  color: white;
  box-shadow: 0 0 10px rgba(123, 94, 167, 0.3);
}

/* ---- Попап с клавиатурой ---- */
.popup-display {
  font-size: 36px;
  font-weight: 700;
  text-align: center;
  padding: 12px 0;
  background: var(--bg-input);
  border-radius: 8px;
  border: 1px solid var(--border-color);
  margin-bottom: 16px;
  color: var(--text-primary);
  min-height: 60px;
  font-variant-numeric: tabular-nums;
}

.popup-keyboard {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.popup-row {
  display: flex;
  gap: 8px;
  justify-content: center;
}

.popup-key {
  width: 60px;
  height: 50px;
  border: 1px solid var(--border-color);
  border-radius: 8px;
  background: var(--bg-card);
  color: var(--text-primary);
  font-size: 22px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.15s;
  display: flex;
  align-items: center;
  justify-content: center;
}

.popup-key:hover {
  background: var(--bg-hover);
  transform: scale(1.05);
}

.popup-key:active {
  transform: scale(0.95);
  background: var(--purple-dark);
}

.popup-key-clear {
  background: var(--red-dark);
  color: white;
  font-size: 18px;
}

.popup-key-clear:hover {
  background: var(--red);
}

.popup-key-ok {
  background: var(--green-dark);
  color: white;
  font-size: 24px;
}

.popup-key-ok:hover {
  background: var(--green);
}

#popup-cancel {
  padding: 8px 24px;
  border-radius: 8px;
  border: none;
  cursor: pointer;
  font-size: 14px;
  background: var(--bg-input);
  color: var(--text-secondary);
  border: 1px solid var(--border-color);
}

#popup-cancel:hover {
  background: var(--bg-hover);
}

/* ---- Плавающая кнопка свободного броска ---- */
.floating-roll-btn {
  display: none;
  position: fixed;
  left: 24px;
  bottom: 24px;
  z-index: 999;
  width: 64px;
  height: 64px;
  border-radius: 50%;
  background: var(--purple-dark);
  border: 2px solid var(--purple-bright);
  box-shadow: 0 4px 16px rgba(123, 94, 167, 0.4);
  cursor: pointer;
  align-items: center;
  justify-content: center;
  transition: transform 0.2s, background 0.2s, box-shadow 0.2s;
  padding: 0;
}

.floating-roll-btn:hover {
  transform: scale(1.1);
  background: var(--purple);
  box-shadow: 0 6px 20px rgba(123, 94, 167, 0.6);
}

.floating-roll-btn:active {
  transform: scale(0.95);
}

.floating-roll-btn img {
  width: 36px;
  height: 36px;
  object-fit: contain;
  filter: brightness(0) invert(1);
}

/* ---- Инвентарь ---- */
.inventory-section {
  grid-column: 1 / -1;
  display: flex;
  flex-direction: column;
  gap: 12px;
  margin-top: 12px;
}

.inventory-header {
  display: flex;
  justify-content: flex-start;
  gap: 12px;
}

.inventory-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 12px;
}

.item-card {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: 10px;
  padding: 12px;
  display: flex;
  flex-direction: column;
  gap: 6px;
  min-width: 200px;
}

.item-name-rarity {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 8px;
}

.item-name-rarity .item-name {
  font-weight: 600;
  color: var(--text-primary);
  font-size: 14px;
  line-height: 1.3;
  white-space: normal;
  word-wrap: break-word;
}

.item-rarity {
  font-size: 12px;
  color: var(--text-muted);
  white-space: nowrap;
  flex-shrink: 0;
}

.item-type-weight {
  display: flex;
  justify-content: space-between;
  font-size: 13px;
  color: var(--text-secondary);
}

.item-charges-row {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 13px;
  color: var(--text-secondary);
  flex-shrink: 0;
}

.item-charges-row button {
  width: 24px;
  height: 24px;
  border-radius: 4px;
  border: 1px solid var(--border-color);
  background: var(--bg-input);
  color: var(--text-primary);
  font-size: 14px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
}

.item-charges-row button:hover {
  background: var(--bg-hover);
}

.item-maxcharges-clickable {
  cursor: pointer;
  border-bottom: 1px dashed var(--border-color);
  padding: 0 2px;
}

.item-maxcharges-clickable:hover {
  border-bottom-color: var(--purple-bright);
}

.item-description {
  font-size: 12px;
  color: var(--text-muted);
  overflow: hidden;
  text-overflow: ellipsis;
  display: -webkit-box;
  -webkit-line-clamp: 4;
  -webkit-box-orient: vertical;
  line-clamp: 4;
  line-height: 1.3;
  max-height: calc(1.3em * 4);
  cursor: pointer;
}

.item-description.expanded {
  -webkit-line-clamp: unset !important;
  line-clamp: unset !important;
  max-height: none !important;
  overflow: visible !important;
}

.item-actions {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
  margin-top: 4px;
}

.item-actions .card-menu {
  flex-shrink: 0;
}

/* Markdown */
.notes-markdown {
  background: var(--bg-input);
  border: 1px solid var(--border-color);
  border-radius: 8px;
  padding: 14px 18px;
  color: var(--text-primary);
  font-size: 14px;
  line-height: 1.6;
  min-height: 400px;
  height: 400px;
  overflow-y: auto;
  grid-column: 1 / -1;
  box-sizing: border-box;
}

.notes-markdown h1,
.notes-markdown h2,
.notes-markdown h3,
.notes-markdown h4,
.notes-markdown h5,
.notes-markdown h6 {
  color: var(--beige);
  margin: 1em 0 0.5em;
}

.notes-markdown p {
  margin: 0.5em 0;
}

.notes-markdown ul,
.notes-markdown ol {
  padding-left: 1.5em;
  margin: 0.5em 0;
}

.notes-markdown li {
  margin-bottom: 0.25em;
}

.notes-markdown code {
  background: var(--bg-card);
  padding: 2px 6px;
  border-radius: 4px;
  font-family: monospace;
  font-size: 0.9em;
}

.notes-markdown pre {
  background: var(--bg-card);
  padding: 12px;
  border-radius: 8px;
  overflow-x: auto;
}

.notes-markdown pre code {
  background: none;
  padding: 0;
}

.notes-markdown blockquote {
  border-left: 3px solid var(--purple);
  padding-left: 12px;
  color: var(--text-secondary);
  margin: 0.5em 0;
}

.notes-markdown a {
  color: var(--purple-bright);
  text-decoration: underline;
}

.notes-markdown table {
  border-collapse: collapse;
  width: 100%;
  margin: 0.5em 0;
}

.notes-markdown th,
.notes-markdown td {
  border: 1px solid var(--border-color);
  padding: 6px 10px;
  text-align: left;
}

.notes-markdown th {
  background: var(--bg-card);
  color: var(--beige);
}

.notes-markdown ul {
  list-style: none;
  padding-left: 1.5em;
}

.notes-markdown ul li::before {
  content: "●";
  color: var(--purple-bright);
  font-weight: bold;
  display: inline-block;
  width: 1em;
  margin-left: -1em;
}

/* Карточка-плейсхолдер */
.character-card-placeholder {
  border: 2px dashed var(--border-color);
  opacity: 0.6;
  cursor: pointer;
}

.character-card-placeholder:hover {
  border-color: var(--purple);
  opacity: 1;
  transform: translateY(-2px);
  box-shadow: 0 4px 16px rgba(123, 94, 167, 0.2);
}

.character-card-placeholder .card-avatar-placeholder {
  font-size: 32px;
  color: var(--text-muted);
  display: flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  height: 100%;
}

.character-card-placeholder .name {
  color: var(--text-muted);
}

/* Новости */
#news-modal ul {
  list-style: none;
  padding-left: 1.5em;
}

#news-modal ul li::before {
  content: "●";
  color: var(--purple-bright);
  font-weight: bold;
  display: inline-block;
  width: 1em;
  margin-left: -1em;
}

#news-link:hover {
  color: var(--purple-bright) !important;
}

/* ============================================================
   ПОЛНАЯ АДАПТАЦИЯ ДЛЯ МОБИЛЬНЫХ
   ============================================================ */
@media (max-width: 768px) {
  body {
    overflow-wrap: break-word;
  }

  #app {
    padding: 10px 0;
  }

  #character-sheet {
    overflow-x: hidden;
    padding: 16px 8px;
  }

  #character-form {
    grid-template-columns: 1fr;
    gap: 16px;
    width: 100%;
    max-width: 100%;
  }

  .character-header {
    flex-direction: column;
    align-items: flex-start;
    gap: 12px;
    padding: 14px 10px;
    width: 100%;
  }

  .character-header .avatar-preview {
    width: 120px;
    height: 160px;
    flex-shrink: 0;
    align-self: center;
  }

  .character-header .header-center,
  .character-header .header-right {
    width: 100%;
    min-width: 0;
  }

  .character-header .header-right {
    border-left: none;
    border-top: 1px solid var(--border-color);
    padding-left: 0;
    padding-top: 10px;
    grid-template-columns: 1fr 1fr;
    gap: 4px 8px;
  }

  .level-exp-row {
    justify-content: flex-start;
    flex-wrap: wrap;
  }

  .resources-grid {
    grid-template-columns: 1fr 1fr;
    gap: 8px;
  }

  .resource-block {
    flex-wrap: wrap;
    justify-content: flex-start;
    gap: 8px;
    padding: 10px 12px;
  }

  .resource-left {
    min-width: 0;
    flex-shrink: 1;
  }

  .resource-left .resource-icon {
    width: 48px;
    height: 48px;
  }

  .resource-left label {
    font-size: 9px;
    max-width: 100%;
  }

  .resource-display {
    font-size: 16px;
    min-width: 0;
  }

  .res-btn {
    width: 26px;
    height: 26px;
    font-size: 15px;
  }

  .attributes-grid {
    grid-template-columns: 1fr 1fr;
    gap: 8px;
  }

  .attr-item {
    min-height: 80px;
    padding: 10px 12px;
    gap: 8px;
  }

  .attr-left {
    min-width: 0;
  }

  .attr-left .attr-icon {
    width: 32px;
    height: 32px;
  }

  .attr-item input {
    width: 48px;
    height: 48px;
    font-size: 20px;
  }

  .attr-roll-btn {
    width: 48px;
    height: 48px;
    font-size: 20px;
  }

  .features-grid {
    grid-template-columns: 1fr;
    gap: 16px;
  }

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

  .item-card {
    min-width: 0;
    max-width: 100%;
    box-sizing: border-box;
  }

  .modal-content {
    padding: 20px 16px;
    max-width: 100%;
    width: 95%;
  }

  .modal-content h2 {
    font-size: 18px;
  }

  .floating-roll-btn {
    width: 56px;
    height: 56px;
    left: 8px;
    bottom: 8px;
  }

  .floating-roll-btn img {
    width: 30px;
    height: 30px;
  }

  #character-notes {
    height: 300px;
    max-width: 100%;
    box-sizing: border-box;
  }

  .notes-markdown {
    min-height: 300px;
    height: 300px;
    max-width: 100%;
    box-sizing: border-box;
  }

  .character-card {
    height: auto;
    padding: 12px;
  }

  .character-card .card-avatar {
    width: 48px;
    height: 48px;
  }
}

@media (max-width: 480px) {
  .header-btn {
    font-size: 12px;
    padding: 5px 10px;
  }

  #auth-section button {
    font-size: 12px;
    padding: 5px 12px;
  }

  .btn-primary,
  .btn-success,
  .btn-danger,
  .btn-beige {
    font-size: 13px;
    padding: 6px 12px;
  }

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

  .character-header .avatar-preview {
    width: 100px;
    height: 140px;
  }

  .attr-item {
    min-height: 70px;
    padding: 8px 8px;
  }

  .attr-item input {
    width: 44px;
    height: 44px;
    font-size: 18px;
  }

  .attr-roll-btn {
    width: 44px;
    height: 44px;
    font-size: 18px;
  }

  .item-card {
    padding: 10px;
  }

  .item-name-rarity .item-name {
    font-size: 13px;
  }

  .toast-container {
    right: 10px;
    bottom: 10px;
    max-width: 300px;
  }
}

/* Класс для редкости */
.rarity {
  font-size: 13px;
  color: #666;
  margin-left: auto;
  margin-right: 8px;
  white-space: nowrap;
}

.ability-use-btn {
  margin-left: 0;
}

/* Исправление белого фона в полях модальных окон */
.modal-content input,
.modal-content select,
.modal-content textarea {
  background: var(--bg-input) !important;
  color: var(--text-primary) !important;
}

.modal-content input:focus,
.modal-content select:focus,
.modal-content textarea:focus {
  background: var(--bg-input) !important;
  color: var(--text-primary) !important;
  border-color: var(--purple);
  box-shadow: 0 0 0 2px rgba(123, 94, 167, 0.2);
}

.modal-content input:-webkit-autofill,
.modal-content input:-webkit-autofill:hover,
.modal-content input:-webkit-autofill:focus,
.modal-content textarea:-webkit-autofill,
.modal-content textarea:-webkit-autofill:hover,
.modal-content textarea:-webkit-autofill:focus {
  -webkit-box-shadow: 0 0 0 1000px var(--bg-input) inset !important;
  -webkit-text-fill-color: var(--text-primary) !important;
  background-color: var(--bg-input) !important;
}

/* ---- Кликабельные максимумы (все ресурсы) ---- */
.clickable-max,
.health-max-clickable,
.inspiration-max-clickable {
  cursor: pointer;
  border-bottom: 1px dashed var(--border-color);
  padding: 0 2px;
  transition: border-color 0.2s;
}

.clickable-max:hover,
.health-max-clickable:hover,
.inspiration-max-clickable:hover {
  border-bottom-color: var(--purple-bright);
}

.clickable-max:active,
.health-max-clickable:active,
.inspiration-max-clickable:active {
  border-bottom-color: var(--purple);
}

/* Ручной режим – фиолетовый */
.manual-max {
  color: var(--purple-bright) !important;
}

.computed-hint-purple {
  color: var(--text-muted-purple) !important;
}