:root {
  --bg: #080b11;
  --panel: rgba(12, 18, 28, 0.78);
  --panel-strong: rgba(16, 27, 39, 0.92);
  --line: rgba(169, 232, 255, 0.24);
  --text: #f3fbff;
  --muted: #9db2bd;
  --cyan: #53e3ff;
  --lime: #b7ff5a;
  --pink: #ff5ca8;
  --amber: #ffd166;
  --red: #ff6f61;
  --shadow: rgba(0, 0, 0, 0.42);
}

* {
  box-sizing: border-box;
}

body {
  min-height: 100vh;
  margin: 0;
  overflow-x: hidden;
  background:
    radial-gradient(circle at 14% 18%, rgba(83, 227, 255, 0.24), transparent 28%),
    radial-gradient(circle at 82% 28%, rgba(255, 92, 168, 0.16), transparent 30%),
    linear-gradient(135deg, #07090f 0%, #111827 48%, #090a0d 100%);
  color: var(--text);
  font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

body::before,
body::after {
  content: "";
  position: fixed;
  inset: -20vh -20vw;
  z-index: 0;
  pointer-events: none;
  background-repeat: repeat;
  will-change: transform;
}

body::before {
  background-image:
    radial-gradient(circle, rgba(255, 255, 255, 0.9) 0 1px, transparent 1.5px),
    radial-gradient(circle, rgba(83, 227, 255, 0.72) 0 1px, transparent 1.7px);
  background-size: 78px 78px, 132px 132px;
  animation: starDrift 18s linear infinite;
}

body::after {
  background-image:
    radial-gradient(circle, rgba(183, 255, 90, 0.58) 0 1px, transparent 1.8px),
    radial-gradient(circle, rgba(255, 92, 168, 0.44) 0 1px, transparent 1.8px);
  background-size: 118px 118px, 174px 174px;
  animation: starDriftAlt 27s linear infinite;
}

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

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

#spaceCanvas {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  z-index: 1;
  pointer-events: none;
}

.app-shell {
  position: relative;
  z-index: 2;
  display: grid;
  grid-template-columns: minmax(0, 1fr) 360px;
  gap: 22px;
  width: min(1180px, calc(100% - 32px));
  min-height: 100vh;
  margin: 0 auto;
  padding: 32px 0;
  align-items: stretch;
}

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

.page-footer {
  position: relative;
  z-index: 2;
  width: min(1180px, calc(100% - 32px));
  margin: 0 auto 28px;
  text-align: center;
  color: rgba(148, 163, 184, 0.86);
  font-size: 0.85rem;
  letter-spacing: 0.14em;
  text-transform: uppercase;
}

@keyframes starDrift {
  from {
    transform: translate3d(0, 0, 0);
  }

  to {
    transform: translate3d(72px, -112px, 0);
  }
}

@keyframes starDriftAlt {
  from {
    transform: translate3d(0, 0, 0);
  }

  to {
    transform: translate3d(-96px, -150px, 0);
  }
}

.generator-panel,
.history-panel,
.story-hero,
.story-card {
  position: relative;
  overflow: hidden;
  border: 1px solid rgba(255, 255, 255, 0.12);
  background:
    linear-gradient(135deg, rgba(255, 255, 255, 0.08), rgba(255, 255, 255, 0.02)),
    rgba(12, 18, 28, 0.35);
  box-shadow:
    0 24px 80px var(--shadow),
    inset 0 1px 0 rgba(255, 255, 255, 0.15),
    inset 0 -1px 0 rgba(83, 227, 255, 0.05);
  backdrop-filter: blur(20px) saturate(1.4);
  -webkit-backdrop-filter: blur(20px) saturate(1.4);
}

.generator-panel::before,
.history-panel::before,
.story-hero::before,
.story-card::before {
  content: "";
  position: absolute;
  inset: 0;
  pointer-events: none;
  background:
    linear-gradient(120deg, rgba(255, 255, 255, 0.24), transparent 34%),
    radial-gradient(circle at 18% 12%, rgba(83, 227, 255, 0.18), transparent 26%),
    radial-gradient(circle at 88% 20%, rgba(183, 255, 90, 0.12), transparent 24%);
  opacity: 0.72;
}

.generator-panel > *,
.history-panel > *,
.story-hero > *,
.story-card > * {
  position: relative;
  z-index: 1;
}

.generator-panel {
  border-radius: 8px;
  padding: clamp(22px, 4vw, 44px);
}

.history-panel {
  border-radius: 8px;
  padding: 24px;
  align-self: stretch;
  min-height: 540px;
}

.story-hero {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 20px;
  border-radius: 8px;
  padding: clamp(24px, 5vw, 52px);
  margin-bottom: 22px;
}

.panel-top,
.history-header,
.actions,
.control-strip {
  display: flex;
  align-items: center;
  gap: 14px;
}

.panel-top,
.history-header {
  justify-content: space-between;
}

.eyebrow {
  margin: 0 0 8px;
  color: var(--cyan);
  font-size: 0.78rem;
  font-weight: 800;
  letter-spacing: 0.18em;
  text-transform: uppercase;
}

h1,
h2 {
  margin: 0;
  line-height: 1.05;
}

h1 {
  max-width: 760px;
  font-size: clamp(2.4rem, 6vw, 5.2rem);
}

h2 {
  font-size: 1.2rem;
}

.story-lead {
  max-width: 720px;
  margin: 18px 0 0;
  color: #dcebf0;
  font-size: clamp(1rem, 2vw, 1.2rem);
  line-height: 1.7;
}

.draw-count {
  display: grid;
  place-items: center;
  width: 86px;
  aspect-ratio: 1;
  border: 1px solid rgba(183, 255, 90, 0.42);
  border-radius: 8px;
  background: linear-gradient(145deg, rgba(183, 255, 90, 0.18), rgba(83, 227, 255, 0.08));
}

.draw-count span {
  font-size: 1.75rem;
  font-weight: 800;
}

.draw-count small {
  color: var(--muted);
}

.control-strip {
  flex-wrap: wrap;
  margin: 34px 0 24px;
  padding: 14px;
  border: 1px solid rgba(255, 255, 255, 0.18);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.08);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.12);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
}

.control {
  display: grid;
  gap: 8px;
  min-width: 150px;
  flex: 1 1 190px;
  color: var(--muted);
  font-size: 0.86rem;
}

.control input,
.control select {
  width: 100%;
  min-height: 44px;
  border: 1px solid rgba(255, 255, 255, 0.22);
  border-radius: 6px;
  background: rgba(5, 9, 14, 0.54);
  color: var(--text);
  padding: 0 12px;
  outline: none;
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
}

.control input:focus,
.control select:focus {
  border-color: var(--cyan);
  box-shadow: 0 0 0 3px rgba(83, 227, 255, 0.16);
}

.toggle {
  display: flex;
  align-items: center;
  gap: 9px;
  min-height: 44px;
  padding: 0 12px;
  border-radius: 6px;
  color: var(--text);
  border: 1px solid rgba(255, 255, 255, 0.16);
  background: rgba(83, 227, 255, 0.1);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.12);
  cursor: pointer;
}

.toggle input {
  width: 18px;
  height: 18px;
  accent-color: var(--lime);
}

.result-grid {
  display: grid;
  gap: 12px;
  min-height: 242px;
}

.ticket {
  display: grid;
  grid-template-columns: 58px 1fr;
  gap: 14px;
  align-items: center;
  min-height: 70px;
  padding: 12px;
  border: 1px solid rgba(255, 255, 255, 0.2);
  border-radius: 8px;
  background:
    linear-gradient(100deg, rgba(255, 255, 255, 0.15), rgba(255, 255, 255, 0.05)),
    rgba(12, 18, 28, 0.42);
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, 0.16),
    0 10px 28px rgba(0, 0, 0, 0.18);
  backdrop-filter: blur(18px);
  -webkit-backdrop-filter: blur(18px);
  animation: ticketReveal 520ms cubic-bezier(0.2, 0.9, 0.2, 1) both;
  animation-delay: var(--delay, 0ms);
}

.ticket-index {
  display: grid;
  place-items: center;
  width: 46px;
  aspect-ratio: 1;
  border-radius: 6px;
  border: 1px solid rgba(255, 255, 255, 0.14);
  background: rgba(255, 255, 255, 0.12);
  color: var(--muted);
  font-weight: 800;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.16);
}

.numbers {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.ball {
  display: grid;
  place-items: center;
  width: 44px;
  aspect-ratio: 1;
  border-radius: 50%;
  color: #071017;
  font-weight: 800;
  box-shadow:
    0 8px 20px rgba(0, 0, 0, 0.22),
    0 0 20px rgba(83, 227, 255, 0.18),
    inset 0 1px 0 rgba(255, 255, 255, 0.72);
  transform-origin: center;
  animation: ballRollIn 700ms cubic-bezier(0.17, 0.84, 0.26, 1.2) both;
  animation-delay: var(--delay, 0ms);
}

.ball.low {
  background: linear-gradient(145deg, #ffd166, #ff9f1c);
}

.ball.mid {
  background: linear-gradient(145deg, #53e3ff, #3b82f6);
}

.ball.high {
  background: linear-gradient(145deg, #ff5ca8, #f72585);
}

.ball.top {
  background: linear-gradient(145deg, #b7ff5a, #34d399);
}

.ball.bonus {
  position: relative;
  outline: 2px solid rgba(255, 255, 255, 0.78);
}

.ball.bonus::after {
  content: "행";
  position: absolute;
  right: -4px;
  bottom: -5px;
  display: grid;
  place-items: center;
  width: 18px;
  aspect-ratio: 1;
  border-radius: 50%;
  background: #101827;
  color: var(--lime);
  font-size: 0.65rem;
}

.actions {
  flex-wrap: wrap;
  margin-top: 24px;
}

button {
  min-height: 48px;
  border: 0;
  border-radius: 6px;
  padding: 0 18px;
  color: var(--text);
  cursor: pointer;
  transition: transform 160ms ease, box-shadow 160ms ease, background 160ms ease;
}

button:hover {
  transform: translateY(-1px);
}

.app-nav,
.nav-header {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 24px;
  grid-column: 1 / -1;
  justify-content: center;
  flex-wrap: wrap;
  align-self: start;
}

.visitor-stats {
  display: flex;
  align-items: center;
  gap: 12px;
  min-height: 40px;
  padding: 8px 14px;
  background: rgba(7, 16, 23, 0.68);
  border: 1px solid rgba(83, 227, 255, 0.22);
  border-radius: 12px;
  font-size: 0.78rem;
  font-weight: 700;
  color: #dcebf0;
  margin-left: 12px;
  white-space: nowrap;
  box-shadow: 0 8px 20px rgba(0, 0, 0, 0.18);
}

.visitor-stats b {
  color: var(--cyan);
  font-size: 0.86rem;
  font-weight: 900;
}

.visitor-stat-item {
  display: inline-flex;
  align-items: baseline;
  gap: 5px;
}

.stat-divider {
  width: 1px;
  height: 12px;
  background: rgba(255, 255, 255, 0.2);
}

.nav-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 10px 24px;
  border-radius: 20px;
  font-weight: 700;
  font-size: 0.9rem;
  transition: 0.2s;
  cursor: pointer;
  border: 0;
  color: var(--text);
  min-height: 40px;
}

.app-nav .nav-btn {
  flex: 0 0 auto;
  min-height: 40px;
  height: 40px;
}

.app-nav .music-toggle {
  margin-left: auto;
  white-space: nowrap;
}

.nav-btn.active {
  background: linear-gradient(90deg, var(--cyan), var(--lime));
  color: #071017;
  box-shadow: 0 8px 20px rgba(83, 227, 255, 0.2);
}

.primary-action {
  flex: 1 1 220px;
  background: linear-gradient(90deg, var(--cyan), var(--lime));
  color: #071017;
  font-weight: 800;
  box-shadow: 0 12px 30px rgba(83, 227, 255, 0.22);
}

.secondary-action,
.ghost-action {
  border: 1px solid rgba(255, 255, 255, 0.16);
  background: rgba(255, 255, 255, 0.1);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
}

.link-action {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 48px;
  border-radius: 6px;
  padding: 0 18px;
  white-space: nowrap;
}

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

.icon {
  margin-right: 6px;
}

#statusText {
  color: var(--muted);
  font-size: 0.82rem;
}

.history-list {
  display: grid;
  gap: 10px;
  margin: 24px 0 0;
  padding: 0;
  list-style: none;
}

.history-list li {
  border-left: 3px solid var(--cyan);
  border-radius: 6px;
  padding: 12px;
  border-top: 1px solid rgba(255, 255, 255, 0.12);
  background: rgba(255, 255, 255, 0.08);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.1);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  color: #dcebf0;
  font-size: 0.9rem;
  line-height: 1.5;
}

.history-list time {
  display: block;
  margin-bottom: 4px;
  color: var(--muted);
  font-size: 0.76rem;
}

.story-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 18px;
}

.legal-shell {
  padding-bottom: 24px;
}

.legal-card {
  border-radius: 14px;
}

.legal-copy {
  display: grid;
  gap: 12px;
  margin-top: 18px;
  color: #dcebf0;
}

.legal-copy h2 {
  font-size: 1.02rem;
  color: var(--text);
}

.legal-copy p {
  margin: 0;
  line-height: 1.72;
  color: #dcebf0;
}

.story-card {
  display: grid;
  grid-template-columns: 210px minmax(0, 1fr);
  gap: 18px;
  align-items: stretch;
  border-radius: 8px;
  padding: 14px;
  animation: ticketReveal 520ms cubic-bezier(0.2, 0.9, 0.2, 1) both;
}

.story-card:nth-child(2) {
  animation-delay: 60ms;
}

.story-card:nth-child(3) {
  animation-delay: 120ms;
}

.story-card:nth-child(4) {
  animation-delay: 180ms;
}

.story-card:nth-child(5) {
  animation-delay: 240ms;
}

.story-card:nth-child(6) {
  animation-delay: 300ms;
}

.feature-card {
  grid-column: 1 / -1;
  grid-template-columns: minmax(280px, 420px) minmax(0, 1fr);
}

.story-card img {
  width: 100%;
  height: 100%;
  min-height: 190px;
  object-fit: cover;
  border-radius: 6px;
  border: 1px solid rgba(255, 255, 255, 0.18);
  background: rgba(255, 255, 255, 0.06);
  box-shadow: 0 14px 34px rgba(0, 0, 0, 0.24);
}

.story-copy {
  display: flex;
  min-width: 0;
  flex-direction: column;
  justify-content: center;
  padding: 6px 4px;
}

.story-copy h2 {
  margin: 8px 0 10px;
  color: var(--text);
  font-size: clamp(1.28rem, 2.4vw, 2rem);
  line-height: 1.18;
}

.story-copy p {
  margin: 0 0 10px;
  color: #dcebf0;
  font-size: 0.98rem;
  line-height: 1.72;
}

.story-copy p:last-child {
  margin-bottom: 0;
}

.story-tag {
  color: var(--lime);
  font-size: 0.78rem;
  font-weight: 800;
  letter-spacing: 0.08em;
}

@keyframes ticketReveal {
  from {
    opacity: 0;
    transform: translateY(16px) scale(0.98);
  }

  to {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
}

@keyframes ballRollIn {
  0% {
    opacity: 0;
    transform: translateX(-22px) rotate(-160deg) scale(0.58);
    filter: blur(4px);
  }

  62% {
    opacity: 1;
    transform: translateX(3px) rotate(12deg) scale(1.12);
    filter: blur(0);
  }

  100% {
    opacity: 1;
    transform: translateX(0) rotate(0) scale(1);
    filter: blur(0);
  }
}

@media (prefers-reduced-motion: reduce) {
  body::before,
  body::after,
  .ticket,
  .ball,
  .story-card {
    animation: none;
  }
}

@media (max-width: 920px) {
  .app-shell {
    grid-template-columns: 1fr;
    align-items: start;
    padding: 18px 0;
  }

  .history-panel {
    min-height: 0;
  }

  .story-hero,
  .story-card,
  .feature-card {
    grid-template-columns: 1fr;
  }

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

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

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

  .app-nav {
    gap: 8px;
    flex-wrap: nowrap;
    justify-content: flex-start;
    overflow-x: auto;
    overflow-y: hidden;
    -webkit-overflow-scrolling: touch;
    padding-bottom: 2px;
  }

  .app-nav .nav-btn,
  .app-nav .music-toggle {
    flex: 0 0 auto;
    min-height: 42px;
    height: 42px;
    padding: 0 12px;
    font-size: 0.82rem;
    white-space: nowrap;
  }

  .app-nav .music-toggle {
    margin-left: 0;
  }

  .visitor-stats {
    flex: 0 0 auto;
    justify-content: center;
    margin-left: 0;
    min-height: 42px;
    padding: 6px 10px;
    font-size: 0.72rem;
  }

  .panel-top {
    align-items: flex-start;
  }

  .draw-count {
    width: 68px;
  }

  .ticket {
    grid-template-columns: clamp(26px, 8vw, 32px) minmax(0, 1fr);
    gap: 6px;
    min-height: 52px;
    padding: 10px;
  }

  .ticket-index {
    width: clamp(26px, 8vw, 32px);
    min-height: clamp(26px, 8vw, 32px);
    font-size: 0.72rem;
  }

  .numbers {
    flex-wrap: nowrap;
    gap: clamp(4px, 1.4vw, 7px);
    min-width: 0;
  }

  .ball {
    width: clamp(29px, 9vw, 36px);
    font-size: clamp(0.76rem, 2.8vw, 0.92rem);
  }

  .ball.bonus::after {
    right: -3px;
    bottom: -4px;
    width: 15px;
    font-size: 0.56rem;
  }

  button {
    width: 100%;
  }

  .link-action {
    width: 100%;
  }

  .story-shell {
    width: min(100% - 20px, 1180px);
    padding: 18px 0 32px;
  }

  .story-card {
    gap: 12px;
    padding: 12px;
  }

  .story-card img {
    min-height: 170px;
  }

  .story-copy h2 {
    font-size: 1.22rem;
  }

  .story-copy p {
    font-size: 0.92rem;
  }
}
