:root {
  --bg: #080908;
  --panel: rgba(19, 21, 20, 0.78);
  --panel-strong: rgba(28, 31, 29, 0.92);
  --line: rgba(238, 236, 220, 0.16);
  --line-strong: rgba(238, 236, 220, 0.28);
  --text: #f4f0df;
  --muted: #a9aa9f;
  --dim: #73766d;
  --gold: #f2c94c;
  --amber: #d99b42;
  --cyan: #58d5c9;
  --green: #7ccf88;
  --red: #ef6b66;
  --violet: #a38be0;
  --blue: #548fd6;
  --shadow: rgba(0, 0, 0, 0.42);
  color-scheme: dark;
  font-family:
    Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI",
    "Noto Sans KR", "Apple SD Gothic Neo", sans-serif;
}

* {
  box-sizing: border-box;
}

html {
  min-height: 100%;
  background: var(--bg);
}

body {
  min-height: 100vh;
  margin: 0;
  color: var(--text);
  overflow-x: hidden;
  background:
    linear-gradient(rgba(255, 255, 255, 0.025) 1px, transparent 1px),
    linear-gradient(90deg, rgba(255, 255, 255, 0.025) 1px, transparent 1px),
    linear-gradient(145deg, #080908 0%, #11120f 46%, #14100e 100%);
  background-size: 42px 42px, 42px 42px, 100% 100%;
}

button {
  font: inherit;
}

.matrix-canvas {
  position: fixed;
  inset: 0;
  z-index: 0;
  width: 100%;
  height: 100%;
  opacity: 0.5;
  pointer-events: none;
}

.app-shell {
  position: relative;
  z-index: 1;
  width: min(1180px, calc(100% - 32px));
  min-height: 100vh;
  margin: 0 auto;
  padding: 28px 0 36px;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 20px;
}

.brand {
  display: flex;
  align-items: center;
  min-width: 0;
  gap: 14px;
}

.brand-mark {
  position: relative;
  width: 46px;
  height: 46px;
  flex: 0 0 46px;
  border: 1px solid rgba(242, 201, 76, 0.58);
  border-radius: 50%;
  background:
    conic-gradient(from 20deg, var(--gold), var(--cyan), var(--red), var(--green), var(--gold)),
    #111;
  box-shadow: 0 0 26px rgba(242, 201, 76, 0.18), inset 0 0 20px rgba(0, 0, 0, 0.45);
}

.brand-mark::after {
  content: "45";
  position: absolute;
  inset: 8px;
  display: grid;
  place-items: center;
  border-radius: 50%;
  color: #16140d;
  background: #f7edd1;
  font-weight: 900;
  font-size: 14px;
}

.eyebrow,
.section-kicker {
  margin: 0 0 4px;
  color: var(--cyan);
  font-size: 12px;
  font-weight: 800;
}

h1,
h2 {
  margin: 0;
  letter-spacing: 0;
}

h1 {
  font-size: clamp(24px, 3.4vw, 44px);
  line-height: 1.08;
}

h2 {
  font-size: 20px;
  line-height: 1.2;
}

.mode-pill,
.status-badge,
.seed-readout {
  display: inline-flex;
  align-items: center;
  min-height: 32px;
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 7px 12px;
  color: var(--muted);
  background: rgba(8, 9, 8, 0.48);
  white-space: nowrap;
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.02);
}

.generator-grid {
  display: grid;
  grid-template-columns: minmax(0, 1.1fr) minmax(318px, 0.9fr);
  gap: 16px;
}

.panel {
  position: relative;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 8px;
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.055), transparent 44%),
    var(--panel);
  box-shadow: 0 18px 60px var(--shadow);
  backdrop-filter: blur(14px);
}

.panel::before {
  content: "";
  position: absolute;
  inset: 0;
  border-radius: inherit;
  pointer-events: none;
  background:
    linear-gradient(90deg, transparent, rgba(88, 213, 201, 0.08), transparent),
    repeating-linear-gradient(135deg, transparent 0 18px, rgba(255, 255, 255, 0.025) 18px 19px);
  opacity: 0.8;
}

.panel > * {
  position: relative;
  z-index: 1;
}

.draw-panel {
  grid-row: span 2;
  padding: 20px;
}

.analysis-panel,
.history-panel,
.lattice-panel {
  padding: 18px;
}

.lattice-panel {
  grid-column: 1 / -1;
}

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

.panel-head.tight {
  margin-bottom: 12px;
}

.status-badge.is-active {
  color: #101210;
  border-color: rgba(88, 213, 201, 0.72);
  background: var(--cyan);
}

.status-badge.is-done {
  color: #191308;
  border-color: rgba(242, 201, 76, 0.7);
  background: var(--gold);
}

.orbital-stage {
  position: relative;
  display: grid;
  place-items: center;
  min-height: clamp(292px, 38vw, 420px);
  overflow: hidden;
  border: 1px solid rgba(238, 236, 220, 0.12);
  border-radius: 8px;
  background:
    linear-gradient(90deg, rgba(255, 255, 255, 0.035) 1px, transparent 1px),
    linear-gradient(rgba(255, 255, 255, 0.035) 1px, transparent 1px),
    rgba(7, 8, 7, 0.56);
  background-size: 32px 32px;
  box-shadow: inset 0 0 70px rgba(0, 0, 0, 0.52);
}

.axis-grid {
  position: absolute;
  inset: 20px;
  border: 1px solid rgba(88, 213, 201, 0.14);
  border-radius: 50%;
  transform: rotate(-9deg);
}

.axis-grid::before,
.axis-grid::after {
  content: "";
  position: absolute;
  inset: 50% auto auto 50%;
  width: 140%;
  height: 1px;
  background: rgba(88, 213, 201, 0.14);
  transform: translate(-50%, -50%);
}

.axis-grid::after {
  width: 1px;
  height: 140%;
}

.ring {
  position: absolute;
  border-radius: 50%;
  border: 1px solid rgba(242, 201, 76, 0.18);
}

.ring-one {
  width: min(78%, 520px);
  aspect-ratio: 1;
  animation: rotateSlow 18s linear infinite;
}

.ring-two {
  width: min(58%, 380px);
  aspect-ratio: 1;
  border-color: rgba(88, 213, 201, 0.18);
  animation: rotateSlow 12s linear reverse infinite;
}

.ring-three {
  width: min(34%, 230px);
  aspect-ratio: 1;
  border-color: rgba(239, 107, 102, 0.16);
  animation: rotateSlow 9s linear infinite;
}

.ring::before,
.ring::after {
  content: "";
  position: absolute;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--gold);
  box-shadow: 0 0 18px rgba(242, 201, 76, 0.72);
}

.ring::before {
  top: 12%;
  left: 17%;
}

.ring::after {
  right: 14%;
  bottom: 18%;
  background: var(--cyan);
  box-shadow: 0 0 18px rgba(88, 213, 201, 0.72);
}

.scan-line {
  position: absolute;
  inset: 0;
  background: linear-gradient(180deg, transparent, rgba(88, 213, 201, 0.16), transparent);
  transform: translateY(-120%);
  opacity: 0;
}

.is-drawing .scan-line {
  animation: scanSweep 1.25s ease-in-out infinite;
}

.ball-track {
  position: relative;
  display: grid;
  grid-template-columns: repeat(6, minmax(64px, 80px));
  align-items: center;
  justify-content: center;
  gap: 12px;
  width: min(100%, 620px);
  padding: 24px 10px;
}

.lotto-ball {
  position: relative;
  display: grid;
  place-items: center;
  aspect-ratio: 1;
  min-width: 0;
  border-radius: 50%;
  color: #101010;
  font-weight: 900;
  font-size: clamp(24px, 4vw, 34px);
  text-shadow: 0 1px 0 rgba(255, 255, 255, 0.3);
  background: linear-gradient(145deg, #f4f0df, #9fa197);
  box-shadow:
    inset 10px 12px 18px rgba(255, 255, 255, 0.46),
    inset -12px -18px 28px rgba(0, 0, 0, 0.32),
    0 18px 34px rgba(0, 0, 0, 0.34);
  transform: translateY(0) scale(1);
  transition: transform 240ms ease, filter 240ms ease, opacity 240ms ease;
}

.lotto-ball::after {
  content: "";
  position: absolute;
  top: 13%;
  left: 18%;
  width: 24%;
  height: 18%;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.58);
  filter: blur(1px);
}

.lotto-ball span {
  position: relative;
  z-index: 1;
}

.lotto-ball.empty {
  color: rgba(244, 240, 223, 0.42);
  background: rgba(255, 255, 255, 0.06);
  border: 1px dashed rgba(244, 240, 223, 0.2);
  box-shadow: inset 0 0 30px rgba(0, 0, 0, 0.35);
}

.lotto-ball.spinning {
  color: var(--text);
  background: #171916;
  border: 1px solid rgba(88, 213, 201, 0.4);
  animation: slotPulse 90ms linear infinite;
}

.lotto-ball.revealed {
  animation: ballReveal 680ms cubic-bezier(0.18, 0.9, 0.22, 1.18) both;
}

.lotto-ball.tone-yellow {
  background: linear-gradient(145deg, #ffe57b, #d89d19);
}

.lotto-ball.tone-blue {
  color: #f7fbff;
  background: linear-gradient(145deg, #6cb8ff, #2e61b2);
}

.lotto-ball.tone-red {
  color: #fff8f2;
  background: linear-gradient(145deg, #ff8585, #c23e3e);
}

.lotto-ball.tone-gray {
  color: #101010;
  background: linear-gradient(145deg, #ecebe1, #83887d);
}

.lotto-ball.tone-green {
  color: #07120b;
  background: linear-gradient(145deg, #9dea89, #3e9d52);
}

.stage-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-top: 16px;
  color: var(--muted);
  font-size: 14px;
}

.progress-shell {
  height: 9px;
  margin-top: 8px;
  overflow: hidden;
  border: 1px solid rgba(238, 236, 220, 0.12);
  border-radius: 999px;
  background: rgba(0, 0, 0, 0.28);
}

.progress-fill {
  width: 0%;
  height: 100%;
  border-radius: inherit;
  background: linear-gradient(90deg, var(--cyan), var(--gold), var(--green));
  box-shadow: 0 0 22px rgba(88, 213, 201, 0.36);
  transition: width 180ms ease;
}

.control-row {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin-top: 18px;
}

.primary-btn,
.secondary-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 46px;
  border: 1px solid transparent;
  border-radius: 8px;
  padding: 0 16px;
  color: #15120a;
  font-weight: 850;
  cursor: pointer;
  transition: transform 160ms ease, border-color 160ms ease, background 160ms ease, opacity 160ms ease;
}

.primary-btn {
  flex: 1 1 190px;
  background: linear-gradient(135deg, #f8d86b, #dc9d3f);
  box-shadow: 0 16px 34px rgba(217, 155, 66, 0.18);
}

.secondary-btn {
  flex: 0 1 auto;
  color: var(--text);
  background: rgba(255, 255, 255, 0.07);
  border-color: var(--line);
}

.secondary-btn.compact {
  min-width: 94px;
}

.primary-btn:hover,
.secondary-btn:hover {
  transform: translateY(-1px);
}

.primary-btn:disabled,
.secondary-btn:disabled {
  cursor: not-allowed;
  opacity: 0.48;
  transform: none;
}

.button-glyph {
  position: relative;
  width: 18px;
  height: 18px;
  flex: 0 0 18px;
  margin-right: 8px;
}

.spin-glyph {
  border: 2px solid currentColor;
  border-right-color: transparent;
  border-radius: 50%;
}

.refresh-glyph::before,
.refresh-glyph::after {
  content: "";
  position: absolute;
  border: 2px solid currentColor;
}

.refresh-glyph::before {
  inset: 2px;
  border-left-color: transparent;
  border-radius: 50%;
}

.refresh-glyph::after {
  right: 1px;
  top: 2px;
  width: 5px;
  height: 5px;
  border-left: 0;
  border-bottom: 0;
  transform: rotate(42deg);
}

.copy-glyph::before,
.copy-glyph::after {
  content: "";
  position: absolute;
  width: 11px;
  height: 13px;
  border: 2px solid currentColor;
  border-radius: 3px;
}

.copy-glyph::before {
  left: 2px;
  top: 1px;
  opacity: 0.5;
}

.copy-glyph::after {
  right: 1px;
  bottom: 1px;
  background: rgba(255, 255, 255, 0.04);
}

.notice {
  margin: 14px 0 0;
  color: var(--dim);
  font-size: 12px;
  line-height: 1.55;
}

.score-gauge {
  display: flex;
  align-items: baseline;
  justify-content: center;
  min-width: 76px;
  min-height: 58px;
  border: 1px solid rgba(242, 201, 76, 0.28);
  border-radius: 8px;
  padding: 8px;
  background: rgba(242, 201, 76, 0.08);
}

.score-gauge strong {
  font-size: 28px;
  line-height: 1;
}

.score-gauge span {
  color: var(--muted);
  font-size: 12px;
  margin-left: 2px;
}

.metrics-list {
  display: grid;
  gap: 14px;
}

.metric-row {
  display: grid;
  gap: 7px;
}

.metric-copy {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  color: var(--muted);
  font-size: 13px;
}

.metric-copy strong {
  color: var(--text);
}

.metric-bar {
  height: 8px;
  overflow: hidden;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.08);
}

.metric-bar span {
  display: block;
  width: 0%;
  height: 100%;
  border-radius: inherit;
  background: linear-gradient(90deg, var(--red), var(--amber), var(--cyan));
  transition: width 520ms cubic-bezier(0.18, 0.9, 0.24, 1);
}

.stat-grid,
.zone-strip {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px;
  margin-top: 16px;
}

.stat-grid div,
.zone-strip div {
  min-width: 0;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px;
  background: rgba(255, 255, 255, 0.045);
}

.stat-grid span,
.zone-strip span {
  display: block;
  color: var(--muted);
  font-size: 12px;
}

.stat-grid strong,
.zone-strip strong {
  display: block;
  margin-top: 4px;
  color: var(--text);
  font-size: 18px;
  line-height: 1.15;
  white-space: nowrap;
}

.history-list {
  display: grid;
  gap: 8px;
  min-height: 176px;
  margin: 0;
  padding: 0;
  list-style: none;
}

.history-item,
.empty-history {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px;
  background: rgba(255, 255, 255, 0.045);
}

.empty-history {
  display: grid;
  place-items: center;
  min-height: 150px;
  color: var(--dim);
  text-align: center;
}

.history-item {
  display: grid;
  grid-template-columns: 1fr auto;
  align-items: center;
  gap: 10px;
}

.history-balls {
  display: flex;
  flex-wrap: wrap;
  gap: 5px;
}

.mini-ball {
  display: grid;
  place-items: center;
  width: 28px;
  height: 28px;
  border-radius: 50%;
  color: #101010;
  background: #f2c94c;
  font-size: 12px;
  font-weight: 900;
}

.mini-ball.tone-yellow {
  background: linear-gradient(145deg, #ffe57b, #d89d19);
}

.mini-ball.tone-blue {
  color: #f7fbff;
  background: linear-gradient(145deg, #6cb8ff, #2e61b2);
}

.mini-ball.tone-red {
  color: #fff8f2;
  background: linear-gradient(145deg, #ff8585, #c23e3e);
}

.mini-ball.tone-gray {
  color: #101010;
  background: linear-gradient(145deg, #ecebe1, #83887d);
}

.mini-ball.tone-green {
  color: #07120b;
  background: linear-gradient(145deg, #9dea89, #3e9d52);
}

.history-score {
  color: var(--muted);
  font-size: 12px;
  white-space: nowrap;
}

.number-grid {
  display: grid;
  grid-template-columns: repeat(15, minmax(0, 1fr));
  gap: 7px;
}

.number-cell {
  display: grid;
  place-items: center;
  min-height: 40px;
  border: 1px solid rgba(238, 236, 220, 0.1);
  border-radius: 6px;
  color: var(--muted);
  background: rgba(255, 255, 255, 0.035);
  font-weight: 750;
  transition: transform 160ms ease, color 160ms ease, border-color 160ms ease, background 160ms ease;
}

.number-cell.is-scan {
  color: #101210;
  border-color: rgba(88, 213, 201, 0.7);
  background: var(--cyan);
  transform: translateY(-2px);
}

.number-cell.is-selected {
  color: #101010;
  border-color: rgba(242, 201, 76, 0.82);
  background: var(--gold);
  box-shadow: 0 0 20px rgba(242, 201, 76, 0.2);
}

@keyframes rotateSlow {
  to {
    transform: rotate(360deg);
  }
}

@keyframes scanSweep {
  0% {
    opacity: 0;
    transform: translateY(-120%);
  }
  28%,
  72% {
    opacity: 1;
  }
  100% {
    opacity: 0;
    transform: translateY(120%);
  }
}

@keyframes slotPulse {
  0%,
  100% {
    filter: brightness(1);
    transform: translateY(0) scale(1);
  }
  50% {
    filter: brightness(1.32);
    transform: translateY(-2px) scale(1.03);
  }
}

@keyframes ballReveal {
  0% {
    opacity: 0;
    filter: brightness(1.8);
    transform: translateY(-42px) rotate(-18deg) scale(0.7);
  }
  62% {
    opacity: 1;
    transform: translateY(8px) rotate(8deg) scale(1.08);
  }
  100% {
    opacity: 1;
    filter: brightness(1);
    transform: translateY(0) rotate(0deg) scale(1);
  }
}

@media (max-width: 920px) {
  .app-shell {
    width: min(100% - 24px, 720px);
    padding-top: 18px;
  }

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

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

  .draw-panel {
    grid-row: auto;
  }

  .lattice-panel {
    grid-column: auto;
  }

  .ball-track {
    grid-template-columns: repeat(3, minmax(68px, 84px));
  }

  .number-grid {
    grid-template-columns: repeat(9, minmax(0, 1fr));
  }
}

@media (max-width: 560px) {
  .app-shell {
    width: min(100% - 18px, 520px);
  }

  .draw-panel,
  .analysis-panel,
  .history-panel,
  .lattice-panel {
    padding: 14px;
  }

  .brand-mark {
    width: 40px;
    height: 40px;
    flex-basis: 40px;
  }

  h1 {
    font-size: 25px;
  }

  .panel-head {
    align-items: flex-start;
    flex-direction: column;
  }

  .status-badge,
  .seed-readout {
    width: 100%;
    justify-content: center;
  }

  .orbital-stage {
    min-height: 332px;
  }

  .ball-track {
    grid-template-columns: repeat(3, minmax(66px, 78px));
    gap: 10px;
  }

  .control-row {
    display: grid;
    grid-template-columns: 1fr;
  }

  .primary-btn,
  .secondary-btn {
    width: 100%;
  }

  .stat-grid,
  .zone-strip {
    grid-template-columns: 1fr;
  }

  .history-item {
    grid-template-columns: 1fr;
  }

  .number-grid {
    grid-template-columns: repeat(5, minmax(0, 1fr));
  }
}

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