:root {
  --bg: #0a0908;
  --bg-elev: #14110f;
  --bg-input: #1c1916;
  --bg-panel: rgba(14, 11, 9, 0.82);
  --text: #d4c8b0;
  --text-dim: #8a7e68;
  --accent: #a86b2c;
  --accent-hot: #c98a4a;
  --border: #2a2520;
  --border-glow: rgba(168, 107, 44, 0.35);
  --danger: #8b2020;
  --hp: #c83232;
  --mana: #3a6bc8;
  --stamina: #b89020;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: 'Iowan Old Style', 'Palatino', Georgia, serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  line-height: 1.55;
}

/* Скрываем скролл body только когда открыт полноэкранный игровой режим */
body.in-game { overflow: hidden; }

.screen { min-height: 100vh; display: flex; justify-content: center; align-items: flex-start; padding: 32px 16px; overflow-y: auto; }
.hidden, .hidden.modal, .modal.hidden { display: none !important; }

/* ===== Setup ===== */
.setup-box {
  max-width: 600px;
  width: 100%;
  background: var(--bg-elev);
  border: 1px solid var(--border);
  padding: 32px;
  border-radius: 4px;
}
.setup-box h1 {
  font-size: 32px;
  margin: 0 0 6px;
  color: var(--accent-hot);
  letter-spacing: 0.5px;
  text-shadow: 0 0 12px rgba(168, 107, 44, 0.3);
}
.subtitle { color: var(--text-dim); margin: 0 0 24px; font-style: italic; }

label {
  display: block;
  margin: 14px 0;
  font-size: 13px;
  color: var(--text-dim);
  text-transform: uppercase;
  letter-spacing: 1px;
}

input[type=text], select {
  width: 100%;
  padding: 10px 12px;
  background: var(--bg-input);
  border: 1px solid var(--border);
  color: var(--text);
  font-family: inherit;
  font-size: 16px;
  margin-top: 6px;
  border-radius: 3px;
}
input[type=text]:focus, select:focus { outline: none; border-color: var(--accent); }
input[type=range] { width: 100%; margin-top: 8px; accent-color: var(--accent); }
.row { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.val { color: var(--accent-hot); font-size: 16px; }
.hint { display: flex; justify-content: space-between; font-size: 11px; color: var(--text-dim); margin-top: 4px; text-transform: none; letter-spacing: 0; }

button {
  background: var(--accent);
  color: #0a0908;
  border: none;
  padding: 14px 24px;
  font-size: 16px;
  font-family: inherit;
  font-weight: bold;
  cursor: pointer;
  border-radius: 3px;
  letter-spacing: 1px;
  text-transform: uppercase;
  margin-top: 24px;
  width: 100%;
  transition: background 0.2s;
}
button:hover:not(:disabled) { background: var(--accent-hot); }
button:disabled { opacity: 0.5; cursor: wait; }

.status { color: var(--text-dim); font-size: 13px; font-style: italic; min-height: 20px; margin-top: 16px; }
.status-fixed { position: fixed; bottom: 4px; left: 50%; transform: translateX(-50%); z-index: 50; pointer-events: none; }

/* ===== Saves ===== */
.saves-section h2 { font-size: 13px; color: var(--text-dim); text-transform: uppercase; letter-spacing: 1px; margin: 0 0 10px; font-weight: normal; }
.save-item { background: var(--bg-input); border: 1px solid var(--border); padding: 10px 12px; margin-bottom: 6px; cursor: pointer; border-radius: 3px; display: flex; justify-content: space-between; gap: 12px; transition: border-color 0.15s; }
.save-item:hover { border-color: var(--accent); }
.save-info { flex: 1; min-width: 0; }
.save-title { color: var(--accent-hot); font-size: 14px; margin-bottom: 2px; }
.save-meta { color: var(--text-dim); font-size: 11px; margin-bottom: 4px; }
.save-preview { color: var(--text); font-size: 12px; font-style: italic; opacity: 0.7; overflow: hidden; text-overflow: ellipsis; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; }
.save-delete { background: transparent; color: var(--text-dim); border: 1px solid var(--border); padding: 4px 10px; font-size: 12px; text-transform: none; letter-spacing: 0; width: auto; margin: 0; font-weight: normal; border-radius: 3px; flex-shrink: 0; }
.save-delete:hover { color: var(--danger); border-color: var(--danger); background: transparent; }
.divider { text-align: center; color: var(--text-dim); font-size: 11px; text-transform: uppercase; letter-spacing: 1px; margin: 20px 0 8px; position: relative; }
.divider::before, .divider::after { content: ""; position: absolute; top: 50%; width: 35%; height: 1px; background: var(--border); }
.divider::before { left: 0; }
.divider::after { right: 0; }
.divider span { background: var(--bg-elev); padding: 0 12px; position: relative; }

/* ===== Полноэкранная игра ===== */
.game-fullscreen {
  position: fixed;
  inset: 0;
  overflow: hidden;
  background: var(--bg);
}

.scene-fullimg {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  opacity: 0;
  transition: opacity 1.2s ease;
  background: var(--bg);
}
.scene-fullimg.visible { opacity: 1; }
.scene-fullimg.prev { z-index: 1; }
.scene-fullimg.current { z-index: 2; }

.skeleton-overlay {
  position: absolute;
  inset: 0;
  z-index: 3;
  background: linear-gradient(110deg, transparent 0%, rgba(80, 65, 50, 0.18) 50%, transparent 100%);
  background-size: 200% 100%;
  animation: shimmer 2.8s linear infinite;
  pointer-events: none;
}
@keyframes shimmer { 0% { background-position: 200% 0; } 100% { background-position: -200% 0; } }

.bottom-gradient {
  position: absolute;
  left: 0; right: 0; bottom: 0;
  height: 45%;
  z-index: 4;
  background: linear-gradient(180deg, transparent 0%, rgba(10,9,8,0.5) 35%, rgba(10,9,8,0.92) 100%);
  pointer-events: none;
}

/* ===== Верхняя панель ===== */
.top-bar {
  position: absolute;
  top: 12px;
  right: 12px;
  z-index: 20;
  display: flex;
  gap: 6px;
}
.tool-btn {
  background: rgba(20, 17, 15, 0.75);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  color: var(--text);
  border: 1px solid var(--border);
  padding: 8px 12px;
  font-size: 16px;
  text-transform: none;
  letter-spacing: 0;
  font-weight: normal;
  margin: 0;
  width: auto;
  cursor: pointer;
  border-radius: 4px;
  transition: border-color 0.15s, background 0.15s;
}
.tool-btn:hover { border-color: var(--accent); background: rgba(40, 30, 20, 0.8); }

/* ===== HUD: орбы + центр ===== */
.hud {
  position: absolute;
  left: 0; right: 0; bottom: 0;
  z-index: 10;
  display: grid;
  grid-template-columns: auto 1fr auto;
  align-items: end;
  gap: 16px;
  padding: 16px;
  pointer-events: none;
}
.hud > * { pointer-events: auto; }

/* Орбы Diablo-style */
.orb-wrap { display: flex; align-items: flex-end; }

.orb {
  width: 110px;
  height: 110px;
  border-radius: 50%;
  position: relative;
  overflow: hidden;
  box-shadow:
    inset 0 0 30px rgba(0,0,0,0.7),
    inset 0 -10px 20px rgba(0,0,0,0.5),
    0 4px 16px rgba(0,0,0,0.7),
    0 0 0 3px #1a1410,
    0 0 0 4px #3a2818;
  background: radial-gradient(circle at 35% 30%, #2a1810, #0a0605 70%);
}

.orb-fill {
  position: absolute;
  left: 0; right: 0; bottom: 0;
  transition: height 0.6s cubic-bezier(0.4, 0, 0.2, 1);
  background: linear-gradient(180deg, var(--fill-color-light, #ff4040) 0%, var(--fill-color, #c83232) 100%);
  box-shadow: inset 0 4px 12px rgba(255,255,255,0.2);
}
.orb-hp { --fill-color: var(--hp); --fill-color-light: #ff5050; }
.orb-mana { --fill-color: var(--mana); --fill-color-light: #5080ff; }

/* Блик на жидкости */
.orb-fill::before {
  content: "";
  position: absolute;
  left: 10%; right: 30%;
  top: 8%;
  height: 30%;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.15);
  filter: blur(4px);
}

.orb-label {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 15px;
  font-weight: bold;
  color: #fff;
  text-shadow: 0 0 6px rgba(0,0,0,0.9), 0 1px 2px rgba(0,0,0,1);
  z-index: 2;
  letter-spacing: 0.5px;
}

/* Центр: текст сцены + инвентарь + стамина */
.hud-center {
  display: flex;
  flex-direction: column;
  align-items: stretch;
  gap: 10px;
  min-width: 0;
  max-width: 100%;
}

.scene-strip {
  background: var(--bg-panel);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  border: 1px solid var(--border-glow);
  border-radius: 6px;
  padding: 14px 18px;
  max-height: 50vh;
  overflow-y: auto;
}

.current-scene {
  font-size: 16px;
  line-height: 1.55;
  white-space: pre-wrap;
  text-align: center;
  margin-bottom: 10px;
}
.current-scene .action {
  color: var(--accent-hot);
  font-style: italic;
  font-size: 13px;
  margin-bottom: 8px;
  opacity: 0.75;
  text-align: center;
}
.current-scene .action::before { content: "› "; }

.generating-indicator {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  padding: 6px 0 10px;
  color: var(--text-dim);
  font-style: italic;
  font-size: 14px;
}
.spinner-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--accent-hot);
  animation: pulse 1.2s ease-in-out infinite;
}
@keyframes pulse { 0%, 100% { opacity: 0.3; transform: scale(0.8); } 50% { opacity: 1; transform: scale(1.2); } }

/* Эффекты последнего хода — всплывающие плашки */
.effects-flash {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  justify-content: center;
  margin-bottom: 6px;
  min-height: 0;
}
.effect-chip {
  font-size: 12px;
  padding: 3px 8px;
  border-radius: 3px;
  background: rgba(20,17,15,0.7);
  border: 1px solid var(--border);
  animation: flashIn 0.5s ease;
}
.effect-chip.dmg { color: #ff8080; border-color: rgba(200,50,50,0.5); }
.effect-chip.heal { color: #80ff80; border-color: rgba(50,200,50,0.5); }
.effect-chip.mana { color: #80a0ff; border-color: rgba(80,120,255,0.5); }
.effect-chip.item { color: var(--accent-hot); border-color: var(--border-glow); }
.effect-chip.status { color: #e0c060; }
@keyframes flashIn { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: translateY(0); } }

/* Кнопки выбора */
.choices {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 6px;
  margin-bottom: 10px;
}
.choice-btn {
  width: auto;
  flex: 0 1 auto;
  padding: 7px 12px;
  font-size: 13px;
  text-align: center;
  background: rgba(28, 25, 22, 0.85);
  color: var(--text);
  border: 1px solid var(--border);
  cursor: pointer;
  border-radius: 4px;
  text-transform: none;
  letter-spacing: 0;
  font-weight: normal;
  margin: 0;
  font-family: inherit;
  transition: border-color 0.15s, background 0.15s;
}
.choice-btn:hover { border-color: var(--accent); background: rgba(40, 30, 20, 0.9); }

.action-form { display: flex; gap: 6px; padding: 0; background: transparent; }
.action-form input {
  flex: 1;
  font-size: 14px;
  padding: 8px 12px;
  margin: 0;
  background: rgba(20,17,15,0.7);
  border: 1px solid var(--border);
}
.action-form button {
  width: 44px;
  margin: 0;
  padding: 0;
  font-size: 18px;
}

/* Инвентарь — 3 слота */
.inventory-bar {
  display: flex;
  justify-content: center;
  gap: 8px;
}
.inv-slot {
  width: 50px;
  height: 50px;
  background: rgba(20,17,15,0.85);
  border: 1px solid var(--border);
  border-radius: 4px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 24px;
  cursor: pointer;
  position: relative;
  transition: border-color 0.15s, transform 0.1s;
}
.inv-slot:hover { border-color: var(--accent-hot); transform: translateY(-2px); }
.inv-slot.empty { color: var(--text-dim); opacity: 0.4; }
.inv-slot .inv-tooltip {
  position: absolute;
  bottom: 110%;
  left: 50%;
  transform: translateX(-50%);
  background: var(--bg-elev);
  border: 1px solid var(--border-glow);
  padding: 6px 10px;
  font-size: 12px;
  white-space: nowrap;
  border-radius: 3px;
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.15s;
  z-index: 30;
}
.inv-slot:hover .inv-tooltip { opacity: 1; }

/* Стамина */
.stamina-bar {
  position: relative;
  height: 8px;
  background: rgba(20,17,15,0.85);
  border: 1px solid var(--border);
  border-radius: 4px;
  overflow: hidden;
}
.stamina-fill {
  height: 100%;
  background: linear-gradient(90deg, #d8a020, var(--stamina));
  transition: width 0.6s ease;
  border-radius: 4px;
}
.stamina-label {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 10px;
  color: var(--text);
  text-shadow: 0 0 4px rgba(0,0,0,1);
  letter-spacing: 0.5px;
}

/* ===== Модалы ===== */
.modal {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.85);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
  padding: 24px;
}
.modal-content {
  background: var(--bg-elev);
  border: 1px solid var(--border-glow);
  max-width: 700px;
  width: 100%;
  max-height: 85vh;
  display: flex;
  flex-direction: column;
  border-radius: 4px;
}
.modal-header { display: flex; justify-content: space-between; align-items: center; padding: 16px 20px; border-bottom: 1px solid var(--border); }
.modal-header h2 { margin: 0; color: var(--accent-hot); font-size: 18px; font-weight: normal; }
.modal-header .tool-btn { background: transparent; }
.history-list, .inventory-detail, .stats-detail { overflow-y: auto; padding: 18px 20px; }

.history-turn { padding-bottom: 14px; margin-bottom: 14px; border-bottom: 1px dashed var(--border); }
.history-turn:last-child { border-bottom: none; margin-bottom: 0; }
.history-turn .action { color: var(--accent-hot); font-style: italic; margin-bottom: 6px; font-size: 13px; }
.history-turn .action::before { content: "› "; }
.history-turn .scene { color: var(--text-dim); line-height: 1.55; font-size: 13px; }

.inventory-detail .item {
  display: flex;
  gap: 14px;
  padding: 12px;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: 4px;
  margin-bottom: 8px;
  align-items: center;
}
.inventory-detail .item .icon { font-size: 32px; flex-shrink: 0; }
.inventory-detail .item .name { color: var(--accent-hot); font-size: 15px; }
.inventory-detail .item .desc { color: var(--text-dim); font-size: 12px; margin-top: 2px; }
.inventory-detail .empty { color: var(--text-dim); font-style: italic; text-align: center; padding: 20px; }

.stats-detail .stat-row { display: flex; justify-content: space-between; padding: 8px 0; border-bottom: 1px dashed var(--border); }
.stats-detail .stat-row:last-child { border: none; }
.stats-detail .stat-name { color: var(--text-dim); }
.stats-detail .stat-val { color: var(--accent-hot); font-weight: bold; }

/* ===== Мобильная адаптация ===== */
@media (max-width: 760px) {
  .top-bar { top: 8px; right: 8px; gap: 4px; }
  .tool-btn { padding: 6px 9px; font-size: 14px; }

  .hud { padding: 8px; gap: 8px; grid-template-columns: 70px 1fr 70px; }
  .orb { width: 70px; height: 70px; }
  .orb-label { font-size: 11px; }
  .scene-strip { padding: 10px 12px; max-height: 55vh; }
  .current-scene { font-size: 14px; line-height: 1.5; }
  .choices { gap: 4px; }
  .choice-btn { padding: 6px 10px; font-size: 12px; }
  .action-form input { font-size: 14px; padding: 7px 10px; }
  .action-form button { width: 38px; font-size: 16px; }
  .inv-slot { width: 42px; height: 42px; font-size: 20px; }
  .stamina-bar { height: 6px; }
  .stamina-label { font-size: 9px; }
}

@media (max-height: 640px) and (orientation: landscape) {
  .scene-strip { max-height: 38vh; }
  .orb { width: 60px; height: 60px; }
  .inv-slot { width: 38px; height: 38px; font-size: 18px; }
}
