:root {
  --ink: #17261c;
  --muted: #718078;
  --cream: #f6f1e7;
  --paper: #fffdf7;
  --green: #1e5a3a;
  --green-dark: #15432b;
  --line: #d8ded8;
  --yellow: #f5bd3c;
  --blue: #5b9bd5;
  --red: #df6257;
  --gray: #8c9692;
  --glow: rgba(30, 57, 39, 0.09);
  --bg-gradient: radial-gradient(circle at 14% 10%, rgba(245, 189, 60, 0.13), transparent 24rem),
                 linear-gradient(180deg, #f9f6ee 0%, var(--cream) 100%);
  --generator-border: rgba(30, 90, 58, 0.16);
  --generator-bg: rgba(255, 253, 247, 0.88);
}

.dark-theme {
  --ink: #f1f5f9;
  --muted: #94a3b8;
  --cream: #090d16;
  --paper: #1e293b;
  --green: #4ade80;
  --green-dark: #22c55e;
  --line: #334155;
  --yellow: #fbbf24;
  --blue: #60a5fa;
  --red: #f87171;
  --gray: #64748b;
  --glow: rgba(0, 0, 0, 0.3);
  --bg-gradient: radial-gradient(circle at 14% 10%, rgba(251, 191, 36, 0.08), transparent 24rem),
                 linear-gradient(180deg, #0f172a 0%, var(--cream) 100%);
  --generator-border: rgba(255, 255, 255, 0.08);
  --generator-bg: rgba(15, 23, 42, 0.75);
}

* { box-sizing: border-box; }

body {
  margin: 0;
  min-height: 100vh;
  color: var(--ink);
  background: var(--bg-gradient);
  font-family: "Gowun Dodum", sans-serif;
}

body::before {
  content: "";
  position: fixed;
  inset: 0;
  pointer-events: none;
  opacity: 0.18;
  background-image: url("data:image/svg+xml,%3Csvg viewBox='0 0 180 180' xmlns='http://www.w3.org/2000/svg'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='.85' numOctaves='3' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)' opacity='.18'/%3E%3C/svg%3E");
}

button { font: inherit; }

.shell {
  position: relative;
  width: min(100% - 32px, 880px);
  margin: 0 auto;
  padding: 72px 0 36px;
}

.hero { margin-bottom: 40px; text-align: center; }
.eyebrow { color: var(--green); font-size: 14px; letter-spacing: 0.16em; }
.eyebrow span { color: var(--yellow); }

h1 {
  margin: 10px 0 2px;
  font-family: Manrope, sans-serif;
  font-size: clamp(48px, 9vw, 76px);
  font-weight: 800;
  letter-spacing: -0.07em;
  line-height: 1;
}

.hero p { margin: 14px 0 0; color: var(--muted); font-size: 17px; }

.generator {
  padding: clamp(22px, 5vw, 46px);
  border: 1px solid var(--generator-border);
  border-radius: 28px;
  background: var(--generator-bg);
  box-shadow: 0 24px 70px var(--glow);
  backdrop-filter: blur(10px);
}

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

.panel-heading > div:first-child { display: flex; align-items: center; gap: 12px; }
.step { color: var(--green); font-family: Manrope, sans-serif; font-size: 12px; font-weight: 800; }
h2 { margin: 0; font-size: 18px; font-weight: 400; }

.count-picker { display: flex; gap: 7px; }
.count-button {
  width: 38px;
  height: 38px;
  border: 1px solid var(--line);
  border-radius: 50%;
  color: var(--muted);
  background: transparent;
  cursor: pointer;
}
.count-button:hover { border-color: var(--green); color: var(--green); }
.count-button.is-active { border-color: var(--green); color: #fff; background: var(--green); }

.ticket {
  position: relative;
  overflow: hidden;
  padding: 20px 24px 24px;
  border: 1px solid var(--line);
  border-radius: 16px;
  background: var(--paper);
}

.ticket::before,
.ticket::after {
  content: "";
  position: absolute;
  top: 50%;
  width: 20px;
  height: 20px;
  border: 1px solid var(--line);
  border-radius: 50%;
  background: var(--cream);
  transform: translateY(-50%);
}
.ticket::before { left: -12px; }
.ticket::after { right: -12px; }

.ticket-top {
  display: flex;
  justify-content: space-between;
  padding-bottom: 14px;
  border-bottom: 1px dashed var(--line);
  color: var(--muted);
  font-family: Manrope, sans-serif;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.12em;
}

.results { display: grid; gap: 15px; margin: 20px 0 0; padding: 0; list-style: none; }
.game { display: flex; align-items: center; gap: clamp(10px, 2vw, 18px); }
.game-label {
  width: 22px;
  flex: 0 0 22px;
  color: var(--muted);
  font-family: Manrope, sans-serif;
  font-size: 11px;
  font-weight: 700;
}
.numbers { display: flex; flex: 1; justify-content: space-between; gap: 7px; }
.ball {
  display: grid;
  width: clamp(38px, 7vw, 52px);
  aspect-ratio: 1;
  place-items: center;
  border-radius: 50%;
  color: #fff;
  font-family: Manrope, sans-serif;
  font-size: clamp(13px, 2.7vw, 16px);
  font-weight: 800;
  box-shadow: inset 0 -3px 7px rgba(0, 0, 0, 0.12), 0 4px 9px rgba(22, 38, 28, 0.09);
  animation: pop 280ms both;
}
.ball-yellow { color: #3b321c; background: var(--yellow); }
.ball-blue { background: var(--blue); }
.ball-red { background: var(--red); }
.ball-gray { background: var(--gray); }
.ball-green { background: #54a56a; }

.actions { display: flex; gap: 10px; margin-top: 24px; }
.actions button {
  min-height: 50px;
  border-radius: 999px;
  cursor: pointer;
  transition: transform 160ms ease, background 160ms ease;
}
.actions button:active { transform: scale(0.98); }
.primary-button { flex: 1; border: 0; color: #fff; background: var(--green); font-weight: 700; }
.primary-button:hover { background: var(--green-dark); }
.button-icon { display: inline-block; margin-right: 7px; font-size: 20px; vertical-align: -2px; }
.secondary-button { padding: 0 24px; border: 1px solid var(--line); color: var(--green); background: transparent; }
.secondary-button:hover { border-color: var(--green); }
.status { min-height: 1.5em; margin: 10px 0 -10px; color: var(--green); text-align: center; font-size: 13px; }

footer { padding: 26px 0 0; color: var(--muted); text-align: center; font-size: 13px; }
footer p { margin: 3px; }
.fine-print { opacity: 0.72; font-size: 12px; }

@keyframes pop {
  from { opacity: 0; transform: translateY(6px) scale(0.88); }
  to { opacity: 1; transform: translateY(0) scale(1); }
}

@media (max-width: 560px) {
  .shell { padding-top: 46px; }
  .panel-heading { align-items: flex-start; flex-direction: column; }
  .count-picker { align-self: stretch; }
  .count-button { flex: 1; border-radius: 10px; }
  .ticket { padding-inline: 16px; }
  .game { gap: 6px; }
  .ball { width: clamp(35px, 10.5vw, 44px); }
  .actions { flex-direction: column; }
  .secondary-button { min-height: 44px !important; }
}

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

/* --- Theme Transition & Header Layout --- */
body, .generator, .ticket, .count-button, .secondary-button, .theme-toggle-btn, h1, h2, p, .game-label, .eyebrow {
  transition: background 0.3s cubic-bezier(0.4, 0, 0.2, 1),
              color 0.3s cubic-bezier(0.4, 0, 0.2, 1),
              border-color 0.3s cubic-bezier(0.4, 0, 0.2, 1),
              box-shadow 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

.app-header {
  display: flex;
  justify-content: flex-end;
  margin-bottom: 16px;
}

.theme-toggle-btn {
  background: var(--generator-bg);
  border: 1px solid var(--generator-border);
  color: var(--ink);
  width: 42px;
  height: 42px;
  border-radius: 50%;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 4px 14px var(--glow);
  backdrop-filter: blur(10px);
  padding: 0;
}

.theme-toggle-btn:hover {
  transform: translateY(-1px) rotate(15deg);
  border-color: var(--green);
}

.theme-toggle-btn svg {
  width: 18px;
  height: 18px;
  color: var(--ink);
}

/* Icons toggling */
.dark-theme .theme-toggle-btn .sun-icon {
  display: block;
}
.dark-theme .theme-toggle-btn .moon-icon {
  display: none;
}
.theme-toggle-btn .sun-icon {
  display: none;
}
.theme-toggle-btn .moon-icon {
  display: block;
}
