:root {
  --ink: #07111f;
  --ink-soft: #1d2b40;
  --muted: #5a6778;
  --line: #d8e4ef;
  --line-strong: #b8c8da;
  --surface: #ffffff;
  --surface-soft: #f4f8fd;
  --blue: #1267e8;
  --blue-dark: #083982;
  --cyan: #18b7ff;
  --green: #29c95b;
  --gold: #f8b81d;
  --danger: #c03534;
  --shadow: 0 22px 58px rgba(7, 17, 31, 0.16);
  --radius: 8px;
}

* {
  box-sizing: border-box;
}

html,
body {
  min-height: 100%;
}

body {
  margin: 0;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", Arial, sans-serif;
  color: var(--ink);
  background:
    linear-gradient(135deg, rgba(244, 248, 253, 0.98), rgba(230, 241, 255, 0.94)),
    #f4f8fd;
  letter-spacing: 0;
}

button,
a {
  font: inherit;
}

button {
  cursor: pointer;
}

button:disabled {
  cursor: not-allowed;
}

a {
  color: inherit;
  text-decoration: none;
}

[hidden] {
  display: none !important;
}

.app-shell {
  min-height: 100vh;
}

.start-screen {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 28px;
  background-image:
    linear-gradient(90deg, rgba(7, 17, 31, 0.86), rgba(7, 17, 31, 0.35) 54%, rgba(7, 17, 31, 0.72)),
    url("../../assets/game-idle.png");
  background-size: cover;
  background-position: center;
}

.start-panel {
  width: min(520px, 100%);
  margin-right: auto;
  padding: clamp(26px, 5vw, 44px);
  color: #ffffff;
  border: 1px solid rgba(255, 255, 255, 0.18);
  border-radius: var(--radius);
  background: rgba(7, 17, 31, 0.72);
  box-shadow: var(--shadow);
  backdrop-filter: blur(18px);
}

.brand-link {
  display: inline-flex;
  align-items: center;
  min-height: 28px;
  color: #9bd4ff;
  font-size: 12px;
  font-weight: 850;
  letter-spacing: 0;
}

.brand-link.compact {
  color: var(--blue);
}

.start-panel h1,
.game-topbar h1 {
  margin: 0;
  letter-spacing: 0;
}

.start-panel h1 {
  margin-top: 18px;
  font-size: clamp(48px, 9vw, 86px);
  line-height: 0.95;
}

.start-panel p {
  margin: 22px 0 0;
  max-width: 450px;
  color: rgba(255, 255, 255, 0.82);
  font-size: 17px;
  line-height: 1.55;
}

.start-actions,
.topbar-actions {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 12px;
}

.start-actions {
  margin-top: 34px;
}

.primary-button,
.secondary-button,
.ghost-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 44px;
  padding: 0 18px;
  border-radius: 6px;
  border: 1px solid transparent;
  color: var(--ink);
  font-size: 14px;
  font-weight: 800;
  letter-spacing: 0;
  transition: transform 0.18s ease, border-color 0.18s ease, background 0.18s ease, opacity 0.18s ease;
}

.primary-button {
  color: #ffffff;
  background: linear-gradient(180deg, #1787ff, var(--blue));
  box-shadow: 0 13px 32px rgba(18, 103, 232, 0.35);
}

.secondary-button {
  color: var(--ink);
  border-color: var(--line-strong);
  background: #ffffff;
}

.ghost-button {
  color: #ffffff;
  border-color: rgba(255, 255, 255, 0.28);
  background: rgba(255, 255, 255, 0.08);
}

.small {
  min-height: 38px;
  padding-inline: 14px;
  font-size: 13px;
}

.primary-button:hover:not(:disabled),
.secondary-button:hover:not(:disabled),
.ghost-button:hover:not(:disabled) {
  transform: translateY(-1px);
}

.primary-button:disabled,
.secondary-button:disabled,
.ghost-button:disabled {
  opacity: 0.48;
}

.game-screen {
  min-height: 100vh;
  padding: 20px;
}

.game-topbar {
  width: min(1420px, 100%);
  min-height: 82px;
  margin: 0 auto 18px;
  display: grid;
  grid-template-columns: minmax(180px, 0.7fr) minmax(430px, 1.15fr) minmax(160px, 0.55fr);
  align-items: center;
  gap: 18px;
  padding: 14px 16px;
  border: 1px solid rgba(184, 200, 218, 0.76);
  border-radius: var(--radius);
  background: rgba(255, 255, 255, 0.88);
  box-shadow: 0 18px 45px rgba(7, 17, 31, 0.08);
  backdrop-filter: blur(18px);
}

.game-topbar h1 {
  font-size: clamp(26px, 4vw, 42px);
  line-height: 1;
}

.stat-strip {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 10px;
}

.stat-pill {
  min-width: 0;
  min-height: 56px;
  padding: 10px 12px;
  border-radius: var(--radius);
  border: 1px solid var(--line);
  background: linear-gradient(180deg, #ffffff, #eef5fd);
}

.stat-pill span,
.panel-heading span,
.machine-meta,
.milestone-meta,
.save-status {
  color: var(--muted);
  font-size: 12px;
  font-weight: 750;
  letter-spacing: 0;
}

.stat-pill strong {
  display: block;
  overflow: hidden;
  margin-top: 3px;
  color: var(--ink);
  font-size: clamp(19px, 2vw, 26px);
  line-height: 1.05;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.topbar-actions {
  justify-content: flex-end;
}

.save-status {
  min-width: 76px;
  text-align: right;
}

.play-layout {
  width: min(1420px, 100%);
  margin: 0 auto;
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(340px, 420px);
  gap: 18px;
  align-items: stretch;
}

.factory-stage {
  position: relative;
  height: clamp(560px, calc(100vh - 170px), 650px);
  min-height: 0;
  overflow: hidden;
  border: 1px solid rgba(184, 200, 218, 0.86);
  border-radius: var(--radius);
  background:
    linear-gradient(180deg, #dce9f6, #eef6ff 45%, #d8e6f3),
    #e8f1fb;
  box-shadow: var(--shadow);
}

#game-canvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  min-height: 0;
}

#game-canvas canvas {
  display: block;
}

.offline-toast {
  position: absolute;
  left: 18px;
  bottom: 18px;
  max-width: min(360px, calc(100% - 36px));
  padding: 12px 14px;
  color: #ffffff;
  border-radius: var(--radius);
  background: rgba(7, 17, 31, 0.82);
  box-shadow: 0 16px 38px rgba(7, 17, 31, 0.22);
}

.management-panel {
  min-width: 0;
  display: grid;
  gap: 18px;
  align-content: start;
}

.panel-section {
  padding: 16px;
  border: 1px solid rgba(184, 200, 218, 0.86);
  border-radius: var(--radius);
  background: rgba(255, 255, 255, 0.9);
  box-shadow: 0 18px 45px rgba(7, 17, 31, 0.08);
}

.panel-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 12px;
}

.panel-heading h2 {
  margin: 0;
  font-size: 19px;
  line-height: 1.1;
}

.machine-list,
.milestone-list {
  display: grid;
  gap: 10px;
}

.machine-card,
.milestone-card {
  min-width: 0;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: #ffffff;
}

.machine-card.is-boosted {
  border-color: rgba(41, 201, 91, 0.72);
  box-shadow: inset 0 0 0 1px rgba(41, 201, 91, 0.18), 0 12px 28px rgba(41, 201, 91, 0.12);
}

.machine-card-header,
.milestone-card-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
}

.machine-title,
.milestone-title {
  min-width: 0;
}

.machine-title strong,
.milestone-title strong {
  display: block;
  overflow-wrap: anywhere;
  font-size: 15px;
  line-height: 1.2;
}

.machine-title span,
.milestone-title span {
  display: block;
  margin-top: 3px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 650;
}

.level-badge,
.ready-badge,
.claimed-badge {
  flex: 0 0 auto;
  min-width: 52px;
  padding: 5px 7px;
  border-radius: 999px;
  text-align: center;
  font-size: 12px;
  font-weight: 850;
}

.level-badge {
  color: #073484;
  background: #e5f1ff;
}

.ready-badge {
  color: #0b6b2e;
  background: #dcffe5;
}

.claimed-badge {
  color: #6c4a04;
  background: #fff2c6;
}

.machine-meta,
.milestone-meta {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
  margin: 12px 0;
}

.machine-meta span,
.milestone-meta span {
  min-width: 0;
  padding: 8px;
  border-radius: 6px;
  background: var(--surface-soft);
}

.machine-meta strong,
.milestone-meta strong {
  display: block;
  overflow: hidden;
  margin-top: 3px;
  color: var(--ink);
  font-size: 15px;
  line-height: 1.1;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.card-actions {
  display: grid;
  grid-template-columns: 0.85fr 1.15fr;
  gap: 8px;
}

.card-actions .primary-button,
.card-actions .secondary-button {
  width: 100%;
  min-height: 40px;
  padding-inline: 10px;
}

.milestone-progress {
  height: 8px;
  overflow: hidden;
  border-radius: 999px;
  background: #e8eef5;
}

.milestone-progress span {
  display: block;
  height: 100%;
  border-radius: inherit;
  background: linear-gradient(90deg, var(--green), var(--gold));
}

.milestone-card .primary-button {
  width: 100%;
  margin-top: 12px;
}

@media (max-width: 1080px) {
  .game-topbar {
    grid-template-columns: 1fr;
  }

  .topbar-actions {
    justify-content: flex-start;
  }

  .play-layout {
    grid-template-columns: 1fr;
  }

  .factory-stage {
    height: 520px;
  }

  .management-panel {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

@media (max-width: 760px) {
  .start-screen,
  .game-screen {
    padding: 14px;
  }

  .start-panel {
    margin: 0;
    padding: 24px;
  }

  .start-actions,
  .topbar-actions {
    align-items: stretch;
    flex-direction: column;
  }

  .start-actions button,
  .topbar-actions button {
    width: 100%;
  }

  .stat-strip,
  .management-panel,
  .machine-meta,
  .milestone-meta,
  .card-actions {
    grid-template-columns: 1fr;
  }

  .factory-stage {
    height: 430px;
  }

  .save-status {
    min-width: 0;
    text-align: left;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    scroll-behavior: auto !important;
    transition-duration: 0.01ms !important;
    animation-duration: 0.01ms !important;
  }
}
