:root {
  --bg: #0b0f14;
  --bg-soft: #111823;
  --panel: #161f2b;
  --panel-2: #1c2735;
  --panel-3: #223041;
  --line: #304052;
  --line-soft: #263444;
  --text: #ece2d2;
  --muted: #a9a293;
  --dim: #7d8794;
  --amber: #e7a33e;
  --amber-bright: #ffc15e;
  --amber-deep: #b9771f;
  --amber-glow: rgba(231, 163, 62, 0.22);
  --danger: #d95f5f;
  --good: #6fbf8b;
  --rare: #4ea6df;
  --epic: #c984ff;
  --common: #68788a;
  --card-w: 148px;
  --radius: 12px;
  --shadow: 0 12px 30px rgba(0, 0, 0, 0.42);
}

* {
  box-sizing: border-box;
}

html,
body {
  width: 100%;
  max-width: 100%;
  overflow-x: hidden;
}

body {
  margin: 0;
  min-height: 100vh;
  color: var(--text);
  background:
    radial-gradient(900px 500px at 50% -10%, rgba(231, 163, 62, 0.11), transparent 65%),
    radial-gradient(700px 420px at 100% 100%, rgba(74, 143, 190, 0.07), transparent 70%),
    linear-gradient(180deg, #0c1219 0%, var(--bg) 55%, #080b10 100%);
  font-family: "Segoe UI", system-ui, -apple-system, BlinkMacSystemFont, "Helvetica Neue", Arial, sans-serif;
  font-size: 14px;
  line-height: 1.4;
}

body::before {
  content: "";
  position: fixed;
  inset: 0;
  pointer-events: none;
  background-image:
    linear-gradient(rgba(255, 255, 255, 0.018) 1px, transparent 1px),
    linear-gradient(90deg, rgba(255, 255, 255, 0.018) 1px, transparent 1px);
  background-size: 42px 42px;
  mask-image: linear-gradient(to bottom, rgba(0, 0, 0, 0.55), transparent 85%);
  z-index: 0;
}

button,
a,
input,
select {
  font: inherit;
}

button {
  position: relative;
  z-index: 1;
  color: var(--text);
  background: linear-gradient(180deg, var(--panel-3), var(--panel-2));
  border: 1px solid var(--line);
  border-radius: 9px;
  padding: 8px 12px;
  cursor: pointer;
  transition:
    background 160ms ease,
    border-color 160ms ease,
    color 160ms ease,
    transform 160ms ease,
    box-shadow 160ms ease,
    opacity 160ms ease;
}

button:hover:not(:disabled) {
  border-color: var(--amber);
  color: var(--amber-bright);
  box-shadow: 0 0 0 3px var(--amber-glow);
  transform: translateY(-1px);
}

button:active:not(:disabled) {
  transform: translateY(0);
}

button:disabled {
  opacity: 0.42;
  cursor: not-allowed;
  filter: grayscale(0.45);
}

button:focus-visible,
a:focus-visible {
  outline: 2px solid var(--amber-bright);
  outline-offset: 2px;
}

.hidden {
  display: none !important;
}

/* ── Верхняя панель ───────────────────────────────────────────── */

#topbar {
  position: relative;
  z-index: 20;
  height: 52px;
  padding: 0 18px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  border-bottom: 1px solid var(--line-soft);
  background: linear-gradient(180deg, rgba(18, 26, 36, 0.96), rgba(11, 15, 20, 0.9));
  backdrop-filter: blur(10px);
}

.logo {
  margin: 0;
  font-size: 18px;
  font-weight: 800;
  letter-spacing: 0.6px;
  color: var(--amber-bright);
  text-shadow: 0 0 18px rgba(231, 163, 62, 0.35);
}

#btn-mute {
  width: 40px;
  height: 34px;
  padding: 0;
  font-size: 17px;
  line-height: 1;
  border-radius: 8px;
}

/* ── Экраны ───────────────────────────────────────────────────── */

.screen {
  position: relative;
  z-index: 1;
  width: 100%;
  max-width: 1280px;
  margin: 0 auto;
}

#screen-menu {
  min-height: calc(100vh - 52px);
  padding: 22px 20px 30px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 16px;
  text-align: center;
}

.menu-hero h2 {
  margin: 0 0 6px;
  font-size: clamp(28px, 4vw, 46px);
  line-height: 1.05;
  letter-spacing: 1px;
  color: var(--text);
  text-shadow: 0 0 34px rgba(231, 163, 62, 0.18);
}

.menu-tagline {
  margin: 0;
  color: var(--muted);
  font-size: 14px;
}

#menu-buttons {
  width: min(520px, 100%);
  display: flex;
  flex-direction: column;
  gap: 9px;
}

#menu-buttons button,
#menu-buttons a {
  width: 100%;
}

#btn-new {
  border-color: rgba(231, 163, 62, 0.55);
  background: linear-gradient(180deg, #253344, #192432);
  font-weight: 700;
}

#btn-onepager {
  display: block;
  padding: 15px 18px;
  border-radius: 12px;
  color: #1d1306;
  background: linear-gradient(135deg, var(--amber-bright), var(--amber) 55%, #d18a27);
  border: 1px solid #ffd58a;
  font-size: 17px;
  font-weight: 900;
  letter-spacing: 0.25px;
  text-decoration: none;
  box-shadow:
    0 10px 26px rgba(231, 163, 62, 0.24),
    inset 0 1px 0 rgba(255, 255, 255, 0.42);
  transition:
    transform 160ms ease,
    box-shadow 160ms ease,
    filter 160ms ease;
}

#btn-onepager:hover {
  transform: translateY(-2px);
  filter: brightness(1.06);
  box-shadow:
    0 14px 34px rgba(231, 163, 62, 0.36),
    inset 0 1px 0 rgba(255, 255, 255, 0.5);
}

#btn-reset {
  color: #c99a9a;
  border-color: rgba(217, 95, 95, 0.32);
  background: transparent;
}

#btn-reset:hover:not(:disabled) {
  border-color: var(--danger);
  color: #ffb3b3;
  box-shadow: 0 0 0 3px rgba(217, 95, 95, 0.14);
}

#leader-select,
#menu-meta {
  width: min(920px, 100%);
}

#leader-select:empty,
#menu-meta:empty {
  display: none;
}

/* ── Игровой экран ───────────────────────────────────────────── */

#screen-game {
  padding: 10px 16px 14px;
  display: flex;
  flex-direction: column;
  gap: 9px;
}

#hud {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px 8px;
  padding: 8px 11px;
  background: linear-gradient(180deg, rgba(28, 39, 53, 0.94), rgba(20, 29, 40, 0.94));
  border: 1px solid var(--line);
  border-left: 3px solid var(--amber);
  border-radius: 10px;
  box-shadow: 0 6px 18px rgba(0, 0, 0, 0.22);
  font-size: 13px;
}

#hud > * {
  min-width: 0;
  padding: 3px 8px;
  border: 1px solid rgba(255, 255, 255, 0.065);
  border-radius: 999px;
  background: rgba(8, 13, 19, 0.34);
  white-space: nowrap;
}

#hud > *:empty {
  display: none;
}

#event {
  padding: 8px 12px;
  border: 1px solid rgba(231, 163, 62, 0.26);
  border-radius: 9px;
  background: linear-gradient(90deg, rgba(231, 163, 62, 0.11), rgba(231, 163, 62, 0.025));
  color: #f0d9b5;
  font-size: 13px;
}

#event:empty {
  display: none;
}

#modules {
  display: flex;
  align-items: stretch;
  gap: 9px;
  min-height: 124px;
}

.module,
.slot-empty {
  flex: 1 1 0;
  min-width: 0;
  min-height: 124px;
  border-radius: var(--radius);
}

.module {
  position: relative;
  display: flex;
  flex-direction: column;
  gap: 5px;
  padding: 9px;
  overflow: hidden;
  background:
    linear-gradient(160deg, rgba(231, 163, 62, 0.09), transparent 45%),
    linear-gradient(180deg, var(--panel-2), #141d28);
  border: 2px solid var(--line);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.05);
  transition:
    border-color 180ms ease,
    transform 180ms ease,
    box-shadow 180ms ease;
}

.module:hover {
  border-color: rgba(231, 163, 62, 0.62);
  box-shadow: 0 0 0 3px rgba(231, 163, 62, 0.09);
}

.module.disabled {
  opacity: 0.46;
  filter: grayscale(0.7);
}

.module.disabled::after {
  content: "ОТКЛЮЧЁН";
  position: absolute;
  right: 7px;
  top: 7px;
  padding: 2px 5px;
  border: 1px solid rgba(217, 95, 95, 0.5);
  border-radius: 5px;
  color: #ffadad;
  background: rgba(50, 13, 13, 0.7);
  font-size: 9px;
  font-weight: 800;
  letter-spacing: 0.6px;
}

.slot-empty {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 10px;
  color: var(--dim);
  text-align: center;
  border: 2px dashed #344355;
  background: rgba(13, 20, 28, 0.42);
  font-size: 12px;
}

#hand {
  display: flex;
  flex-wrap: wrap;
  align-content: flex-start;
  gap: 6px;
  min-height: 218px;
  padding: 7px;
  border: 1px solid rgba(255, 255, 255, 0.045);
  border-radius: 11px;
  background: rgba(7, 11, 16, 0.25);
}

/* ── Карты ───────────────────────────────────────────────────── */

.card {
  position: relative;
  flex: 0 0 var(--card-w);
  width: var(--card-w);
  min-height: 204px;
  display: flex;
  flex-direction: column;
  gap: 4px;
  padding: 8px 7px 7px;
  overflow: hidden;
  border: 2px solid var(--common);
  border-radius: 11px;
  background:
    radial-gradient(120px 90px at 50% 0%, rgba(255, 255, 255, 0.075), transparent 70%),
    linear-gradient(180deg, #202c3a, #151e29 70%, #111821);
  box-shadow:
    0 6px 14px rgba(0, 0, 0, 0.28),
    inset 0 1px 0 rgba(255, 255, 255, 0.06);
  transition:
    transform 160ms ease,
    box-shadow 160ms ease,
    border-color 160ms ease;
}

.card:hover {
  transform: translateY(-3px);
  box-shadow:
    0 12px 22px rgba(0, 0, 0, 0.38),
    inset 0 1px 0 rgba(255, 255, 255, 0.08);
}

.card.rare {
  border-color: var(--rare);
  box-shadow:
    0 6px 14px rgba(0, 0, 0, 0.28),
    0 0 18px rgba(78, 166, 223, 0.12),
    inset 0 1px 0 rgba(255, 255, 255, 0.08);
}

.card.epic {
  border-color: var(--epic);
  box-shadow:
    0 6px 14px rgba(0, 0, 0, 0.3),
    0 0 20px rgba(201, 132, 255, 0.16),
    inset 0 1px 0 rgba(255, 255, 255, 0.09);
}

.card-emoji {
  font-size: 26px;
  line-height: 1.1;
  text-align: center;
  filter: drop-shadow(0 2px 5px rgba(0, 0, 0, 0.4));
}

.card-name {
  min-height: 32px;
  display: flex;
  align-items: center;
  justify-content: center;
  text-align: center;
  font-size: 12.5px;
  font-weight: 800;
  line-height: 1.15;
}

.card-cost {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 3px;
  color: var(--amber-bright);
  font-size: 10.5px;
  font-weight: 700;
}

.card-face,
.card-back {
  padding: 4px 5px;
  border-radius: 6px;
  font-size: 10.5px;
  line-height: 1.22;
}

.card-face {
  color: #d9e6ef;
  background: rgba(78, 166, 223, 0.09);
  border: 1px solid rgba(78, 166, 223, 0.16);
}

.card-back {
  color: #ead6b8;
  background: rgba(231, 163, 62, 0.09);
  border: 1px solid rgba(231, 163, 62, 0.2);
}

.card-actions {
  display: flex;
  gap: 4px;
  margin-top: auto;
  padding-top: 3px;
}

.card-actions button {
  flex: 1 1 0;
  min-width: 0;
  padding: 5px 3px;
  border-radius: 6px;
  font-size: 10.5px;
  font-weight: 700;
  line-height: 1.1;
}

.card-actions button:first-child {
  border-color: rgba(231, 163, 62, 0.35);
}

/* ── Управление и журнал ────────────────────────────────────── */

#controls {
  display: flex;
  flex-wrap: wrap;
  gap: 7px;
  align-items: center;
}

#btn-end-day {
  margin-left: auto;
  border-color: rgba(231, 163, 62, 0.6);
  background: linear-gradient(180deg, #3a2a14, #241a0e);
  color: var(--amber-bright);
  font-weight: 800;
}

#btn-end-day:hover:not(:disabled) {
  background: linear-gradient(180deg, #4a3518, #2d2010);
}

#btn-menu {
  opacity: 0.86;
}

#log {
  max-height: 58px;
  overflow-y: auto;
  padding: 6px 9px;
  border: 1px solid var(--line-soft);
  border-radius: 8px;
  background: rgba(5, 8, 12, 0.4);
  color: #9fa8b3;
  font-size: 11px;
  line-height: 1.35;
  scrollbar-width: thin;
  scrollbar-color: #3a4a5d transparent;
}

#log:empty {
  display: none;
}

#log > * {
  margin: 0 0 2px;
}

/* ── Модальное окно ─────────────────────────────────────────── */

#modal {
  position: fixed;
  inset: 0;
  z-index: 60;
  display: grid;
  place-items: center;
  padding: 20px;
  background: rgba(4, 7, 11, 0.76);
  backdrop-filter: blur(5px);
  animation: fade-in 150ms ease both;
}

#modal-box {
  width: min(720px, 100%);
  max-height: min(82vh, 680px);
  overflow-y: auto;
  padding: 20px;
  border: 1px solid rgba(231, 163, 62, 0.5);
  border-radius: 14px;
  background:
    radial-gradient(500px 220px at 50% 0%, rgba(231, 163, 62, 0.09), transparent 70%),
    linear-gradient(180deg, #1b2532, #111820);
  box-shadow:
    var(--shadow),
    0 0 0 1px rgba(255, 255, 255, 0.035) inset;
  animation: modal-in 180ms ease both;
  scrollbar-width: thin;
  scrollbar-color: #46586d transparent;
}

#modal-box h2,
#modal-box h3 {
  margin: 0 0 10px;
  color: var(--amber-bright);
}

#modal-box h2 {
  font-size: 23px;
  letter-spacing: 0.3px;
}

#modal-box h3 {
  font-size: 17px;
}

#modal-box p {
  margin: 0 0 10px;
  color: #d4cbbb;
}

#modal-box ul {
  margin: 8px 0 12px;
  padding-left: 20px;
}

#modal-box li {
  margin-bottom: 4px;
}

#modal-box button {
  margin-top: 6px;
}

#modal-box .reward-options,
#modal-box .reward-list {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 8px;
  margin: 12px 0;
}

#modal-box .reward-options button,
#modal-box .reward-list button {
  min-height: 70px;
  white-space: normal;
}

@keyframes fade-in {
  from { opacity: 0; }
  to { opacity: 1; }
}

@keyframes modal-in {
  from { opacity: 0; transform: translateY(10px) scale(0.985); }
  to { opacity: 1; transform: translateY(0) scale(1); }
}

/* ── Подсказка обучения ────────────────────────────────────── */

#hint {
  position: fixed;
  right: 16px;
  bottom: 16px;
  z-index: 70; /* fix: подсказка обучения поверх модалки награды/отчёта */
  width: min(330px, calc(100vw - 32px));
  padding: 12px 13px;
  border: 2px solid var(--amber);
  border-radius: 12px;
  background:
    linear-gradient(160deg, rgba(231, 163, 62, 0.13), transparent 55%),
    linear-gradient(180deg, #1d2835, #111922);
  box-shadow:
    0 14px 34px rgba(0, 0, 0, 0.5),
    0 0 24px rgba(231, 163, 62, 0.12);
  animation: hint-in 200ms ease both;
}

#hint-text {
  margin-bottom: 9px;
  color: #f0e3cd;
  font-size: 13px;
  line-height: 1.4;
}

#hint-next {
  border-color: rgba(231, 163, 62, 0.55);
  color: var(--amber-bright);
  font-weight: 700;
}

@keyframes hint-in {
  from { opacity: 0; transform: translateY(12px); }
  to { opacity: 1; transform: translateY(0); }
}

/* ── Тост ───────────────────────────────────────────────────── */

#toast {
  position: fixed;
  left: 50%;
  bottom: 22px;
  z-index: 80;
  max-width: min(520px, calc(100vw - 40px));
  padding: 9px 14px;
  border: 1px solid rgba(231, 163, 62, 0.55);
  border-radius: 9px;
  color: #f4e6ce;
  background: rgba(20, 28, 38, 0.96);
  box-shadow: 0 12px 28px rgba(0, 0, 0, 0.45);
  opacity: 0;
  pointer-events: none;
  transform: translate(-50%, 12px);
  transition:
    opacity 180ms ease,
    transform 180ms ease;
}

#toast.show,
#toast.visible,
#toast:not(:empty) {
  opacity: 1;
  transform: translate(-50%, 0);
}

#toast:empty {
  opacity: 0;
}

/* ── Меню: мета-прогрессия и магазин ────────────────────────── */

#menu-meta {
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding: 12px;
  border: 1px solid var(--line-soft);
  border-radius: 12px;
  background: rgba(15, 22, 30, 0.66);
  text-align: left;
}

#menu-meta:empty {
  display: none;
}

#menu-meta h3,
#menu-meta h4 {
  margin: 0;
  color: var(--amber-bright);
}

#meta-stats,
.meta-stats {
  display: flex;
  flex-wrap: wrap;
  gap: 7px;
  color: var(--muted);
  font-size: 12px;
}

#meta-shop {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 8px;
}

#meta-shop > h3 {
  grid-column: 1 / -1;
  margin: 0 0 4px;
}

#meta-shop > * {
  min-width: 0;
}

#meta-shop button {
  width: 100%;
  text-align: left;
  white-space: normal;
}

#leader-select {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 7px;
}

#leader-select:empty {
  display: none;
}

#leader-select button {
  min-width: 150px;
  white-space: normal;
}

#leader-select button.active,
#leader-select button.selected {
  border-color: var(--amber);
  color: var(--amber-bright);
  box-shadow: 0 0 0 3px var(--amber-glow);
}

/* ── Общие утилиты ──────────────────────────────────────────── */

.muted {
  color: var(--muted);
}

.amber {
  color: var(--amber-bright);
}

.danger {
  color: #ff9c9c;
}

.good {
  color: var(--good);
}

.row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 7px;
}

.stack {
  display: flex;
  flex-direction: column;
  gap: 7px;
}

::-webkit-scrollbar {
  width: 9px;
  height: 9px;
}

::-webkit-scrollbar-track {
  background: transparent;
}

::-webkit-scrollbar-thumb {
  background: #3a4a5d;
  border: 2px solid transparent;
  border-radius: 10px;
  background-clip: padding-box;
}

::-webkit-scrollbar-thumb:hover {
  background: #4c6178;
  border: 2px solid transparent;
  background-clip: padding-box;
}

@media (max-width: 1000px) {
  #modules {
    flex-wrap: wrap;
  }

  .module,
  .slot-empty {
    flex: 1 1 180px;
  }

  #btn-end-day {
    margin-left: 0;
  }
}

@media (max-width: 700px) {
  :root {
    --card-w: 136px;
  }

  #screen-menu {
    justify-content: flex-start;
    padding-top: 16px;
  }

  #screen-game {
    padding: 8px;
  }

  #hud {
    font-size: 12px;
  }

  #hint {
    right: 8px;
    bottom: 8px;
  }
}
