:root {
  --bg-0: #edf6ff;
  --bg-1: #e2f0fc;
  --card: rgba(255, 255, 255, 0.74);
  --card-strong: rgba(255, 255, 255, 0.9);
  --line: rgba(64, 118, 172, 0.2);
  --text: #1f2736;
  --muted: #5f687a;
  --brand: #3fa9f5;
  --brand-strong: #1d8bdd;
  --accent: #e0a847;
  --danger: #d96464;
  --success: #2baf7b;
  --radius-lg: 22px;
  --radius-md: 14px;
  --shadow-soft: 0 24px 44px rgba(20, 44, 77, 0.12);
  --shadow-focus: 0 0 0 3px rgba(63, 169, 245, 0.26);
  --topbar-shadow: 0 10px 24px rgba(20, 44, 77, 0.08);
  --glass-bg: rgba(255, 255, 255, 0.68);
  --glass-border: rgba(255, 255, 255, 0.9);
  --glass-hover: rgba(255, 255, 255, 0.75);
  --menu-bg: rgba(255, 255, 255, 0.95);
  --grid-line: rgba(90, 140, 198, 0.08);
  --overlay-shade: rgba(201, 222, 244, 0.18);
  --hero-glow: rgba(63, 169, 245, 0.18);
  --bg-layer-1: radial-gradient(circle at 14% 12%, rgba(63, 169, 245, 0.28), transparent 38%);
  --bg-layer-2: radial-gradient(circle at 84% 78%, rgba(244, 196, 106, 0.15), transparent 45%);
  --bg-layer-3: linear-gradient(155deg, var(--bg-0) 0%, var(--bg-1) 100%);
  --kpi-bg: linear-gradient(165deg, rgba(255, 255, 255, 0.92), rgba(240, 248, 255, 0.88));
  --kpi-strong: #1f2736;
  --form-bg: linear-gradient(165deg, rgba(255, 255, 255, 0.94), rgba(236, 245, 254, 0.9));
  --grid-bg: linear-gradient(165deg, rgba(253, 250, 241, 0.9), rgba(245, 251, 255, 0.9));
  --grid-border: rgba(87, 136, 188, 0.22);
  --grid-border-hover: rgba(63, 169, 245, 0.48);
  --grid-title: #27364b;
  --select-bg: rgba(255, 255, 255, 0.98);
  --select-border: rgba(112, 161, 214, 0.36);
  --select-border-hover: rgba(63, 169, 245, 0.82);
  --button-text: #f7fbff;
  --result-bg: linear-gradient(165deg, rgba(203, 247, 230, 0.54), rgba(218, 244, 255, 0.58));
  --result-border: rgba(52, 181, 130, 0.44);
  --result-text: #174d3a;
  --error-bg: rgba(217, 100, 100, 0.18);
  --error-border: rgba(217, 100, 100, 0.44);
  --error-text: #7a2f2f;
  --spinner-track: rgba(132, 183, 244, 0.2);
  --footer-border: rgba(64, 118, 172, 0.22);
  --footer-link: #2f86bb;
  --footer-link-hover: #1f2736;
}

.dark {
  --bg-0: #071629;
  --bg-1: #0a223d;
  --card: rgba(12, 32, 56, 0.75);
  --card-strong: rgba(10, 28, 49, 0.9);
  --line: rgba(136, 191, 255, 0.24);
  --text: #edf5ff;
  --muted: #a9bdd8;
  --brand: #3fa9f5;
  --brand-strong: #1d8bdd;
  --accent: #f4c46a;
  --danger: #eb6a6a;
  --success: #48d39b;
  --shadow-soft: 0 24px 44px rgba(3, 11, 25, 0.34);
  --shadow-focus: 0 0 0 3px rgba(63, 169, 245, 0.28);
  --topbar-shadow: 0 12px 24px rgba(4, 8, 14, 0.34);
  --glass-bg: rgba(29, 44, 66, 0.72);
  --glass-border: rgba(136, 191, 255, 0.22);
  --glass-hover: rgba(52, 74, 104, 0.72);
  --menu-bg: rgba(34, 44, 60, 0.96);
  --grid-line: rgba(147, 191, 242, 0.08);
  --overlay-shade: rgba(3, 12, 24, 0.62);
  --hero-glow: rgba(63, 169, 245, 0.2);
  --bg-layer-1: radial-gradient(circle at 14% 12%, rgba(63, 169, 245, 0.3), transparent 38%);
  --bg-layer-2: radial-gradient(circle at 84% 78%, rgba(244, 196, 106, 0.16), transparent 45%);
  --bg-layer-3: linear-gradient(155deg, var(--bg-0) 0%, var(--bg-1) 100%);
  --kpi-bg: linear-gradient(165deg, rgba(14, 35, 59, 0.86), rgba(8, 26, 45, 0.8));
  --kpi-strong: #eff7ff;
  --form-bg: linear-gradient(165deg, rgba(16, 39, 66, 0.88), rgba(10, 29, 50, 0.85));
  --grid-bg: linear-gradient(165deg, rgba(7, 23, 41, 0.86), rgba(8, 27, 49, 0.7));
  --grid-border: rgba(120, 174, 239, 0.26);
  --grid-border-hover: rgba(151, 201, 255, 0.52);
  --grid-title: #d7e9ff;
  --select-bg: rgba(8, 21, 38, 0.95);
  --select-border: rgba(132, 183, 244, 0.35);
  --select-border-hover: rgba(63, 169, 245, 0.82);
  --button-text: #f7fbff;
  --result-bg: linear-gradient(165deg, rgba(21, 72, 80, 0.38), rgba(8, 35, 45, 0.62));
  --result-border: rgba(72, 211, 155, 0.36);
  --result-text: #d9fff0;
  --error-bg: rgba(192, 78, 78, 0.22);
  --error-border: rgba(235, 106, 106, 0.45);
  --error-text: #ffd8d8;
  --spinner-track: rgba(132, 183, 244, 0.2);
  --footer-border: rgba(126, 180, 244, 0.22);
  --footer-link: #84cdfc;
  --footer-link-hover: #b5e3ff;
}

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

html {
  scroll-behavior: smooth;
  overscroll-behavior-y: none;
  background-color: #071629;
}

body {
  font-family: "Manrope", "Segoe UI", sans-serif;
  color: var(--text);
  min-height: 100dvh;
  line-height: 1.6;
  background-color: var(--bg-0);
  background:
    radial-gradient(circle at 14% 12%, rgba(63, 169, 245, 0.28), transparent 38%),
    radial-gradient(circle at 84% 78%, rgba(244, 196, 106, 0.15), transparent 45%),
    linear-gradient(155deg, #edf6ff 0%, #e2f0fc 100%);
  position: relative;
  overflow-x: hidden;
  overscroll-behavior-y: none;
  -webkit-font-smoothing: antialiased;
  display: flex;
  flex-direction: column;
}

.light body {
  background-color: #edf6ff;
  background:
    radial-gradient(circle at 14% 12%, rgba(63, 169, 245, 0.28), transparent 38%),
    radial-gradient(circle at 84% 78%, rgba(244, 196, 106, 0.15), transparent 45%),
    linear-gradient(155deg, #edf6ff 0%, #e2f0fc 100%);
}

.dark body {
  background-color: #071629;
  background:
    radial-gradient(circle at 14% 12%, rgba(63, 169, 245, 0.3), transparent 38%),
    radial-gradient(circle at 84% 78%, rgba(244, 196, 106, 0.16), transparent 45%),
    linear-gradient(155deg, #071629 0%, #0a223d 100%);
}

.light {
  background-color: #edf6ff;
}

.dark {
  background-color: #071629;
}

@supports (-webkit-touch-callout: none) {
  @media (pointer: coarse) {
    .dark body {
      background-image: none;
    }
  }
}

body::before,
body::after {
  content: "";
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: -1;
}

body::before {
  background-image:
    linear-gradient(var(--grid-line) 1px, transparent 1px),
    linear-gradient(90deg, var(--grid-line) 1px, transparent 1px);
  background-size: 48px 48px;
  mask-image: radial-gradient(circle at 50% 50%, black 35%, transparent 85%);
}

body::after {
  background: linear-gradient(to bottom, transparent, var(--overlay-shade));
}

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

.topbar {
  position: sticky;
  top: calc(env(safe-area-inset-top, 0px) + 0.7rem);
  z-index: 20;
  width: min(1220px, 94vw);
  margin: 1rem auto 0;
  border-radius: 999px;
  border: 1px solid var(--glass-border);
  background: var(--glass-bg);
  backdrop-filter: blur(16px);
  box-shadow: var(--topbar-shadow);
  padding: 0.62rem 0.84rem;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 0.85rem;
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: 0.62rem;
  min-width: 0;
  font-family: "Space Grotesk", sans-serif;
  font-size: 0.98rem;
  font-weight: 700;
  letter-spacing: -0.01em;
}

.brand img {
  width: 1.95rem;
  height: 1.95rem;
  border-radius: 0.62rem;
  border: 0;
  background: transparent;
  object-fit: cover;
}

.topnav {
  margin-left: auto;
  display: inline-flex;
  align-items: center;
  gap: 0.55rem;
}

.topnav a {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  white-space: nowrap;
  font-size: 0.84rem;
  color: var(--muted);
  font-weight: 700;
  padding: 0.42rem 0.72rem;
  border-radius: 999px;
  transition: color 0.2s ease, background-color 0.2s ease;
}

.topnav a:hover,
.topnav a[aria-current="page"] {
  color: var(--text);
  background: var(--glass-hover);
}

.topbar-actions {
  display: inline-flex;
  align-items: center;
  gap: 0.42rem;
  margin-left: 0.35rem;
}

.theme-toggle {
  border: 1px solid var(--line);
  background: var(--glass-bg);
  color: var(--muted);
  border-radius: 999px;
  padding: 0.38rem 0.7rem;
  min-width: 4.1rem;
  margin: 0;
  font-size: 0.79rem;
  font-weight: 800;
  letter-spacing: 0.02em;
  cursor: pointer;
  transition: color 0.2s ease, background-color 0.2s ease, transform 0.2s ease;
}

.theme-toggle:hover {
  color: var(--text);
  background: var(--glass-hover);
  transform: translateY(-1px);
}

.theme-toggle:focus-visible {
  outline: none;
  box-shadow: var(--shadow-focus);
}

.menu-toggle {
  display: none;
  position: relative;
  border: 1px solid var(--line);
  background: var(--glass-bg);
  color: var(--muted);
  border-radius: 0.72rem;
  width: 2.15rem;
  height: 2.15rem;
  margin: 0;
  align-items: center;
  justify-content: center;
  overflow: visible;
  cursor: pointer;
  transition: background-color 0.2s ease;
}

.menu-toggle:hover {
  background: var(--glass-hover);
}

.menu-toggle span {
  position: absolute;
  top: 50%;
  left: 50%;
  width: 0.9rem;
  height: 2px;
  border-radius: 2px;
  background: currentColor;
  transform-origin: center;
  transition: transform 0.24s ease, opacity 0.2s ease;
}

.menu-toggle span:nth-child(1) {
  transform: translate(-50%, -0.32rem);
}

.menu-toggle span:nth-child(2) {
  transform: translate(-50%, -50%);
}

.menu-toggle span:nth-child(3) {
  transform: translate(-50%, 0.2rem);
}

.menu-toggle.open span:nth-child(1) {
  transform: translate(-50%, -50%) rotate(45deg);
}

.menu-toggle.open span:nth-child(2) {
  opacity: 0;
}

.menu-toggle.open span:nth-child(3) {
  transform: translate(-50%, -50%) rotate(-45deg);
}

.mobile-menu {
  display: none;
}

main {
  width: min(1220px, 94vw);
  margin: 1rem auto 0;
  animation: fade-rise 0.65s ease;
  flex: 1 0 auto;
}

.kpi-strip {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 0.85rem;
  margin: 0 0 1.5rem;
}

.kpi-card {
  background: var(--kpi-bg);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 0.72rem 0.8rem;
  text-align: left;
}

.kpi-label {
  display: block;
  color: var(--muted);
  font-size: 0.78rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  margin-bottom: 0.26rem;
}

.kpi-card strong {
  font-family: "Space Grotesk", "Manrope", sans-serif;
  font-size: 1.08rem;
  color: var(--kpi-strong);
}

h1 {
  font-family: "Space Grotesk", "Manrope", sans-serif;
  font-size: clamp(1.8rem, 4vw, 2.7rem);
  margin-bottom: 1.8rem;
  letter-spacing: 0.02em;
  font-weight: 700;
  color: var(--text);
  text-shadow: 0 0 28px var(--hero-glow);
}

.app-container {
  display: grid;
  grid-template-columns: 1fr;
  gap: 1.8rem;
  align-items: start;
}

@media (min-width: 1024px) {
  .app-container {
    grid-template-columns: minmax(0, 1.2fr) minmax(0, 0.8fr);
  }
}

.form-section,
.results-section {
  width: 100%;
}

.results-section {
  position: sticky;
  top: 16px;
  min-height: 220px;
}

form,
#spinner,
#result {
  border-radius: var(--radius-lg);
  border: 1px solid var(--line);
  box-shadow: var(--shadow-soft);
  backdrop-filter: blur(8px);
}

form {
  margin-bottom: 20px;
  width: min(860px, 100%);
  margin-left: auto;
  margin-right: auto;
  background: var(--form-bg);
  padding: clamp(1rem, 2.4vw, 1.7rem);
}

.form-group {
  margin-bottom: 1.5rem;
}

#grids-container {
  display: grid;
  gap: clamp(0.72rem, 1.5vw, 1rem);
}

label {
  display: block;
  font-weight: 600;
  margin-bottom: 0.9rem;
  font-size: 0.97rem;
  color: var(--muted);
  letter-spacing: 0.01em;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border-width: 0;
}

select {
  font-family: inherit;
  font-size: 0.98rem;
  padding: 0.68rem;
  border: 1px solid var(--select-border);
  border-radius: 12px;
  background: var(--select-bg);
  color: var(--text);
  outline: none;
  width: 100%;
  max-width: 94px;
  cursor: pointer;
  transition: border-color 0.25s, transform 0.2s, box-shadow 0.25s;
}

select:hover {
  border-color: var(--select-border-hover);
  transform: translateY(-1px);
}

select:focus {
  border-color: var(--brand);
  box-shadow: var(--shadow-focus);
}

.number-group {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: clamp(8px, 1.1vw, 14px);
  margin: 0.2rem 0 0.55rem;
}

.number-selection,
.star-selection {
  margin-bottom: 0.35rem;
}

.grid {
  background: var(--grid-bg);
  padding: clamp(0.78rem, 1.7vw, 1rem);
  margin: 0;
  border-radius: var(--radius-md);
  border: 1px solid var(--grid-border);
  transition: transform 0.2s ease, border-color 0.2s ease;
}

.grid:hover {
  transform: translateY(-2px);
  border-color: var(--grid-border-hover);
}

.grid h3 {
  font-family: "Space Grotesk", "Manrope", sans-serif;
  font-size: 1.06rem;
  margin-bottom: 10px;
  color: var(--grid-title);
}

button {
  font-family: inherit;
  padding: 0.78rem 1.35rem;
  font-size: 0.96rem;
  cursor: pointer;
  color: var(--button-text);
  border: 0;
  border-radius: 12px;
  font-weight: 700;
  transition: transform 0.2s, box-shadow 0.25s, filter 0.2s;
  margin: 0;
}

button:hover {
  transform: translateY(-2px);
  box-shadow: 0 10px 18px rgba(4, 16, 32, 0.24);
}

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

button:focus-visible {
  outline: none;
  box-shadow: var(--shadow-focus);
}

button:disabled {
  opacity: 0.5;
  cursor: not-allowed;
  transform: none;
  box-shadow: none;
}

.btn-primary {
  background: linear-gradient(135deg, #2589d4, #3fa9f5);
}

.btn-primary:hover {
  filter: brightness(1.07);
}

.btn-danger {
  background: linear-gradient(135deg, #b84c4c, #dc6f6f);
}

.btn-danger:hover {
  filter: brightness(1.07);
}

.auto-btn {
  background: linear-gradient(135deg, #208d8f, #2fb3a8);
  margin-top: 10px;
  width: 100%;
}

.auto-btn:hover {
  filter: brightness(1.06);
}

.button-group {
  display: flex;
  justify-content: center;
  flex-wrap: wrap;
  gap: 10px;
  margin-top: 1rem;
}

#result {
  margin-top: 0;
  font-size: 1.09rem;
  color: var(--result-text);
  padding: 1.35rem;
  background: var(--result-bg);
  line-height: 1.6;
  border-color: var(--result-border);
  display: none;
  align-items: center;
  justify-content: center;
  text-align: center;
}

#result:not(:empty) {
  min-height: 150px;
  display: flex;
}

.result-content {
  width: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0.35rem;
}

.result-line {
  width: 100%;
  color: var(--result-text);
}

.error {
  color: var(--error-text);
  margin-top: 1rem;
  padding: 0.75rem;
  background: var(--error-bg);
  border: 1px solid var(--error-border);
  border-radius: 12px;
  font-weight: 600;
}

.error:empty {
  display: none;
}

#spinner {
  margin-top: 0;
  padding: 1.9rem;
  background: var(--card);
  min-height: 200px;
  display: none;
  flex-direction: column;
  align-items: center;
  justify-content: center;
}

#spinner[style*="display: block"] {
  display: flex !important;
}

.spinner {
  border: 5px solid var(--spinner-track);
  border-top: 5px solid var(--brand);
  border-radius: 50%;
  width: 58px;
  height: 58px;
  animation: spin 1s linear infinite;
  margin: 0 auto 1rem;
  box-shadow: 0 0 22px rgba(63, 169, 245, 0.35);
}

p {
  padding-top: 1rem;
  font-size: 0.95rem;
  color: var(--muted);
}

.site-footer {
  width: min(1220px, 94vw);
  text-align: center;
  padding: 2rem 1rem 1.1rem;
  font-size: 0.9rem;
  color: var(--muted);
  margin: 2rem auto calc(1rem + env(safe-area-inset-bottom, 0px));
  border-top: 1px solid var(--footer-border);
}

.site-footer p {
  padding-top: 0;
}

.site-footer a {
  color: var(--footer-link);
  text-decoration: none;
  transition: color 0.2s;
  font-weight: 600;
}

.site-footer a:hover {
  color: var(--footer-link-hover);
  text-decoration: underline;
}

.site-footer a:focus-visible {
  outline: 2px solid var(--footer-link);
  outline-offset: 2px;
  border-radius: 2px;
}

@keyframes spin {
  0% { transform: rotate(0deg); }
  100% { transform: rotate(360deg); }
}

@keyframes fade-rise {
  from {
    opacity: 0;
    transform: translateY(10px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@media (max-width: 1023px) {
  .results-section {
    position: static;
    margin-top: 0.6rem;
  }
}

@media (max-width: 840px) {
  .topbar {
    width: min(96vw, 760px);
    top: calc(env(safe-area-inset-top, 0px) + 0.5rem);
    border-radius: 999px;
    gap: 0.45rem;
    padding: 0.48rem 0.56rem;
    overflow: visible;
  }

  .brand {
    gap: 0.46rem;
    font-size: 0.9rem;
    flex-shrink: 0;
  }

  .brand img {
    width: 1.78rem;
    height: 1.78rem;
  }

  .topnav {
    display: none;
  }

  .topbar-actions {
    margin-left: auto;
    display: inline-flex;
    flex-wrap: nowrap;
    gap: 0.34rem;
  }

  .theme-toggle {
    min-width: auto;
    padding: 0.36rem 0.58rem;
    font-size: 0.74rem;
    line-height: 1.1;
  }

  .menu-toggle {
    display: inline-flex;
    flex-shrink: 0;
    width: 2rem;
    height: 2rem;
  }

  .mobile-menu {
    display: flex;
    position: absolute;
    top: calc(100% + 0.48rem);
    right: 0;
    width: min(16.8rem, calc(100vw - 1.2rem));
    flex-direction: column;
    gap: 0.2rem;
    padding: 0.38rem;
    border-radius: 1rem;
    border: 1px solid var(--line);
    background: var(--menu-bg);
    backdrop-filter: blur(14px) saturate(120%);
    -webkit-backdrop-filter: blur(14px) saturate(120%);
    box-shadow: var(--topbar-shadow);
    opacity: 0;
    pointer-events: none;
    transform: translateY(-6px);
    transition: opacity 0.2s ease, transform 0.2s ease;
    z-index: 30;
  }

  .mobile-menu.open {
    opacity: 1;
    pointer-events: auto;
    transform: translateY(0);
  }

  .mobile-menu a {
    display: flex;
    align-items: center;
    padding: 0.55rem 0.68rem;
    border-radius: 0.76rem;
    color: var(--muted);
    font-size: 0.84rem;
    font-weight: 700;
    transition: color 0.2s ease, background-color 0.2s ease;
  }

  .mobile-menu a:hover,
  .mobile-menu a[aria-current="page"] {
    color: var(--text);
    background: var(--glass-hover);
  }

  body.menu-open {
    overflow: hidden;
  }

  main {
    width: min(96vw, 760px);
    margin-top: 0.85rem;
  }

  .site-footer {
    width: min(96vw, 760px);
    margin-top: 1.3rem;
  }
}

@media (max-width: 768px) {
  h1 {
    margin-bottom: 1.25rem;
  }

  .kpi-strip {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 0.55rem;
    margin-bottom: 1.1rem;
  }

  .kpi-card {
    padding: 0.62rem 0.65rem;
  }

  .kpi-card strong {
    font-size: 1rem;
  }

  form,
  #spinner,
  #result {
    border-radius: 16px;
  }

  form {
    padding: 1rem;
  }

  .number-group {
    gap: 6px;
    margin-top: 0.15rem;
    margin-bottom: 0.45rem;
  }

  select {
    max-width: 70px;
    padding: 0.48rem;
  }

  .grid {
    padding: 0.72rem;
  }

  button {
    padding: 0.65rem 1.08rem;
    font-size: 0.9rem;
  }

  .spinner {
    width: 42px;
    height: 42px;
    border-width: 4px;
  }

  .site-footer {
    margin-top: 1.9rem;
    padding-top: 1.8rem;
  }
}

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

@media (prefers-contrast: high) {
  :root {
    --card: #ffffff;
    --line: rgba(0, 0, 0, 0.45);
    --muted: #3b4558;
    --text: #10141f;
  }

  .dark {
    --card: #04111f;
    --line: rgba(255, 255, 255, 0.6);
    --muted: #d2e6ff;
    --text: #ffffff;
  }

  form,
  #spinner,
  #result,
  .grid {
    border-width: 2px;
  }

  .site-footer a {
    color: var(--footer-link);
  }
}
