:root {
  --pine: #1f5c45;
  --pine-deep: #134032;
  --leaf: #3d8b6e;
  --sky-top: #8ec8e8;
  --sky-mid: #c5e4b8;
  --sky-bottom: #f0f6e8;
  --fire: #ff7a2f;
  --fire-deep: #e85d12;
  --wood: #6b4226;
  --ink: #1a2e24;
  --panel: rgba(255, 255, 255, 0.78);
  --panel-solid: #ffffff;
  --shadow: 0 18px 40px rgba(19, 64, 50, 0.18);
  --radius: 22px;
  --font-display: "Lilita One", cursive;
  --font-body: "Cabin", system-ui, sans-serif;
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

html {
  scroll-behavior: smooth;
}

body {
  margin: 0;
  min-height: 100vh;
  font-family: var(--font-body);
  color: var(--ink);
  background: var(--sky-bottom);
  overflow-x: hidden;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

.sky {
  position: fixed;
  inset: 0;
  z-index: -2;
  background:
    radial-gradient(ellipse 80% 50% at 15% 10%, rgba(255, 210, 120, 0.55), transparent 55%),
    radial-gradient(ellipse 60% 40% at 85% 5%, rgba(255, 255, 255, 0.45), transparent 50%),
    linear-gradient(180deg, var(--sky-top) 0%, var(--sky-mid) 42%, var(--sky-bottom) 100%);
  animation: sky-shift 18s ease-in-out infinite alternate;
}

@keyframes sky-shift {
  from { filter: saturate(1) brightness(1); }
  to { filter: saturate(1.08) brightness(1.03); }
}

.trees {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  height: 28vh;
  z-index: -1;
  pointer-events: none;
  background:
    radial-gradient(ellipse 18% 90% at 8% 100%, var(--pine-deep) 0 42%, transparent 43%),
    radial-gradient(ellipse 14% 80% at 18% 100%, var(--pine) 0 45%, transparent 46%),
    radial-gradient(ellipse 22% 100% at 32% 100%, var(--pine-deep) 0 40%, transparent 41%),
    radial-gradient(ellipse 16% 85% at 48% 100%, var(--leaf) 0 44%, transparent 45%),
    radial-gradient(ellipse 20% 95% at 62% 100%, var(--pine) 0 42%, transparent 43%),
    radial-gradient(ellipse 15% 78% at 76% 100%, var(--pine-deep) 0 46%, transparent 47%),
    radial-gradient(ellipse 24% 100% at 90% 100%, var(--pine) 0 40%, transparent 41%),
    linear-gradient(180deg, transparent 0%, rgba(19, 64, 50, 0.12) 70%, rgba(19, 64, 50, 0.22) 100%);
  opacity: 0.9;
}

.topbar {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 1rem;
  padding: clamp(1.25rem, 3vw, 2rem) clamp(1.25rem, 4vw, 3rem) 0.5rem;
}

.brand-kicker {
  margin: 0 0 0.15rem;
  font-size: 0.85rem;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--pine);
  font-weight: 600;
  opacity: 0.85;
}

.brand {
  margin: 0;
  font-family: var(--font-display);
  font-size: clamp(2.4rem, 7vw, 4.4rem);
  line-height: 0.95;
  color: var(--pine-deep);
  text-shadow: 0 2px 0 rgba(255, 255, 255, 0.35);
  letter-spacing: 0.02em;
  animation: brand-in 0.8s cubic-bezier(0.22, 1, 0.36, 1) both;
}

@keyframes brand-in {
  from {
    opacity: 0;
    transform: translateY(18px) scale(0.96);
  }
  to {
    opacity: 1;
    transform: none;
  }
}

.top-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  justify-content: flex-end;
  padding-top: 0.35rem;
}

.ghost-btn,
.secondary-btn,
.danger-btn,
.draw-btn {
  font-family: var(--font-body);
  border: none;
  cursor: pointer;
  transition: transform 0.18s ease, box-shadow 0.18s ease, background 0.18s ease;
}

.ghost-btn {
  background: rgba(255, 255, 255, 0.55);
  color: var(--pine-deep);
  border: 1.5px solid rgba(31, 92, 69, 0.22);
  border-radius: 999px;
  padding: 0.55rem 0.95rem;
  font-weight: 600;
  font-size: 0.9rem;
  backdrop-filter: blur(8px);
}

.ghost-btn:hover,
.secondary-btn:hover:not(:disabled),
.danger-btn:hover {
  transform: translateY(-1px);
}

.ghost-btn[aria-pressed="false"] {
  opacity: 0.65;
}

.stage {
  display: grid;
  grid-template-columns: 1.05fr 1fr;
  grid-template-areas:
    "draw board"
    "history board";
  gap: clamp(1rem, 2.5vw, 1.75rem);
  padding: 0.75rem clamp(1.25rem, 4vw, 3rem) 2.5rem;
  max-width: 1400px;
  margin: 0 auto;
}

.hero-draw {
  grid-area: draw;
  background: var(--panel);
  backdrop-filter: blur(14px);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  border: 1px solid rgba(255, 255, 255, 0.65);
  padding: clamp(1.25rem, 3vw, 2rem);
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  min-height: 420px;
}

.ball-stage {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  width: 100%;
  padding: 0.5rem 0 1rem;
}

.ball {
  width: clamp(160px, 28vw, 220px);
  height: clamp(160px, 28vw, 220px);
  border-radius: 50%;
  display: grid;
  place-items: center;
  position: relative;
  background:
    radial-gradient(circle at 32% 28%, #fff7ec 0%, #ffe0a8 28%, var(--fire) 62%, var(--fire-deep) 100%);
  box-shadow:
    inset -12px -16px 28px rgba(120, 40, 0, 0.28),
    inset 10px 12px 20px rgba(255, 255, 255, 0.45),
    0 22px 40px rgba(232, 93, 18, 0.35);
  transform: rotate(-6deg);
}

.ball[data-empty="true"] {
  background:
    radial-gradient(circle at 32% 28%, #ffffff 0%, #e8f3ec 35%, #b7d9c8 70%, #7fb89a 100%);
  box-shadow:
    inset -12px -16px 28px rgba(19, 64, 50, 0.18),
    inset 10px 12px 20px rgba(255, 255, 255, 0.55),
    0 18px 36px rgba(19, 64, 50, 0.2);
}

.ball.pulse {
  animation: ball-pop 0.55s cubic-bezier(0.22, 1, 0.36, 1);
}

@keyframes ball-pop {
  0% {
    transform: scale(0.55) rotate(-18deg);
    filter: blur(2px);
  }
  60% {
    transform: scale(1.08) rotate(4deg);
  }
  100% {
    transform: scale(1) rotate(-6deg);
  }
}

.ball-number {
  font-family: var(--font-display);
  font-size: clamp(4.5rem, 12vw, 6.5rem);
  line-height: 1;
  color: var(--pine-deep);
  text-shadow: 0 2px 0 rgba(255, 255, 255, 0.35);
  user-select: none;
}

.ball[data-empty="true"] .ball-number {
  color: rgba(31, 92, 69, 0.45);
  font-size: clamp(3.5rem, 10vw, 5rem);
}

.ball-caption {
  margin: 1.1rem 0 0;
  font-size: 1.05rem;
  font-weight: 600;
  color: var(--pine);
}

.controls {
  display: flex;
  flex-wrap: wrap;
  gap: 0.65rem;
  justify-content: center;
  width: 100%;
  margin-bottom: 1rem;
}

.auto-panel {
  width: 100%;
  margin-bottom: 1.25rem;
  padding: 0.95rem 1rem;
  border-radius: 16px;
  background: rgba(31, 92, 69, 0.08);
  border: 1.5px solid rgba(31, 92, 69, 0.18);
  text-align: left;
}

.auto-panel.is-running {
  background: rgba(255, 122, 47, 0.1);
  border-color: rgba(255, 122, 47, 0.35);
}

.auto-header h3 {
  margin: 0;
  font-family: var(--font-display);
  font-size: 1.2rem;
  color: var(--pine-deep);
  letter-spacing: 0.02em;
}

.auto-hint {
  margin: 0.2rem 0 0.75rem;
  font-size: 0.9rem;
  color: var(--leaf);
  font-weight: 600;
}

.auto-controls {
  display: flex;
  flex-wrap: wrap;
  gap: 0.65rem;
  align-items: flex-end;
}

.speed-label {
  display: flex;
  flex-direction: column;
  gap: 0.3rem;
  font-size: 0.8rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--pine);
  flex: 1;
  min-width: 140px;
}

.speed-select {
  font-family: var(--font-body);
  font-size: 0.95rem;
  font-weight: 600;
  color: var(--pine-deep);
  background: rgba(255, 255, 255, 0.9);
  border: 1.5px solid rgba(31, 92, 69, 0.22);
  border-radius: 12px;
  padding: 0.65rem 0.8rem;
  cursor: pointer;
}

.auto-btn {
  font-family: var(--font-body);
  border: none;
  cursor: pointer;
  border-radius: 999px;
  padding: 0.8rem 1.35rem;
  font-size: 1rem;
  font-weight: 700;
  color: #fff;
  background: linear-gradient(160deg, #ff9a4a 0%, var(--fire) 55%, var(--fire-deep) 100%);
  box-shadow: 0 10px 22px rgba(232, 93, 18, 0.3);
  transition: transform 0.18s ease, box-shadow 0.18s ease;
  white-space: nowrap;
}

.auto-btn:hover:not(:disabled) {
  transform: translateY(-1px);
  box-shadow: 0 14px 26px rgba(232, 93, 18, 0.38);
}

.auto-btn[aria-pressed="true"] {
  background: linear-gradient(160deg, #4aa882 0%, var(--pine) 60%, var(--pine-deep) 100%);
  box-shadow: 0 10px 22px rgba(31, 92, 69, 0.3);
}

.auto-btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
  box-shadow: none;
}

.auto-countdown {
  margin-top: 0.85rem;
}

.auto-countdown[hidden] {
  display: none;
}

.countdown-track {
  height: 8px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.65);
  overflow: hidden;
  border: 1px solid rgba(31, 92, 69, 0.12);
}

.countdown-bar {
  height: 100%;
  width: 100%;
  border-radius: inherit;
  background: linear-gradient(90deg, var(--fire), #ffb065);
  transform-origin: left center;
  transform: scaleX(1);
}

.countdown-bar.ticking {
  transition: transform linear;
}

.countdown-text {
  margin: 0.45rem 0 0;
  font-size: 0.9rem;
  font-weight: 600;
  color: var(--pine-deep);
  text-align: center;
}

.draw-btn {
  background: linear-gradient(160deg, #2f9b6f 0%, var(--pine) 55%, var(--pine-deep) 100%);
  color: #fff;
  border-radius: 999px;
  padding: 0.95rem 1.8rem;
  font-size: 1.15rem;
  font-weight: 700;
  box-shadow: 0 12px 28px rgba(31, 92, 69, 0.35);
  min-width: 220px;
}

.draw-btn:hover:not(:disabled) {
  transform: translateY(-2px) scale(1.02);
  box-shadow: 0 16px 32px rgba(31, 92, 69, 0.42);
}

.draw-btn:active:not(:disabled) {
  transform: translateY(0) scale(0.98);
}

.draw-btn:disabled {
  opacity: 0.55;
  cursor: not-allowed;
  box-shadow: none;
}

.draw-btn.shake,
.auto-btn.shake {
  animation: btn-shake 0.45s ease;
}

@keyframes btn-shake {
  0%, 100% { transform: translateX(0); }
  25% { transform: translateX(-4px); }
  75% { transform: translateX(4px); }
}

.secondary-btn,
.danger-btn {
  border-radius: 999px;
  padding: 0.75rem 1.1rem;
  font-weight: 600;
  font-size: 0.95rem;
}

.secondary-btn {
  background: rgba(255, 255, 255, 0.85);
  color: var(--pine-deep);
  border: 1.5px solid rgba(31, 92, 69, 0.2);
}

.secondary-btn:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

.danger-btn {
  background: rgba(255, 122, 47, 0.12);
  color: var(--fire-deep);
  border: 1.5px solid rgba(255, 122, 47, 0.35);
}

.stats {
  display: flex;
  gap: 2rem;
}

.stat {
  display: flex;
  flex-direction: column;
  align-items: center;
}

.stat-value {
  font-family: var(--font-display);
  font-size: 2rem;
  color: var(--pine-deep);
  line-height: 1;
}

.stat-label {
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--leaf);
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

.phases {
  width: 100%;
  margin-top: 1.25rem;
  padding: 0.95rem 1rem;
  border-radius: 16px;
  background: rgba(255, 255, 255, 0.55);
  border: 1.5px solid rgba(31, 92, 69, 0.16);
  text-align: left;
}

.phases-header h3 {
  margin: 0;
  font-family: var(--font-display);
  font-size: 1.2rem;
  color: var(--pine-deep);
}

.phases-hint {
  margin: 0.2rem 0 0.75rem;
  font-size: 0.9rem;
  color: var(--leaf);
  font-weight: 600;
}

.phase-steps {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 0.5rem;
  margin-bottom: 0.75rem;
}

.phase-step {
  font-family: var(--font-body);
  border: 1.5px solid rgba(31, 92, 69, 0.18);
  background: rgba(255, 255, 255, 0.75);
  border-radius: 14px;
  padding: 0.65rem 0.4rem;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.2rem;
  cursor: default;
  color: rgba(26, 46, 36, 0.45);
}

.phase-step.is-current {
  border-color: var(--fire);
  background: rgba(255, 122, 47, 0.12);
  color: var(--pine-deep);
  box-shadow: 0 4px 14px rgba(232, 93, 18, 0.18);
}

.phase-step.is-done {
  border-color: rgba(31, 92, 69, 0.35);
  background: rgba(47, 155, 111, 0.18);
  color: var(--pine-deep);
}

.phase-num {
  font-family: var(--font-display);
  font-size: 1.25rem;
  line-height: 1;
}

.phase-label {
  font-size: 0.8rem;
  font-weight: 700;
}

.phase-win-btn {
  width: 100%;
  font-family: var(--font-body);
  border: none;
  cursor: pointer;
  border-radius: 999px;
  padding: 0.8rem 1rem;
  font-size: 1rem;
  font-weight: 700;
  color: #fff;
  background: linear-gradient(160deg, #ff9a4a 0%, var(--fire) 55%, var(--fire-deep) 100%);
  box-shadow: 0 10px 22px rgba(232, 93, 18, 0.28);
  transition: transform 0.18s ease, opacity 0.18s ease;
}

.phase-win-btn:hover:not(:disabled) {
  transform: translateY(-1px);
}

.phase-win-btn:disabled {
  opacity: 0.45;
  cursor: not-allowed;
  box-shadow: none;
}

.claim-banner {
  position: fixed;
  left: 50%;
  bottom: 1.25rem;
  transform: translateX(-50%);
  z-index: 40;
  width: min(560px, calc(100% - 1.5rem));
  animation: claim-in 0.35s cubic-bezier(0.22, 1, 0.36, 1);
}

.claim-banner[hidden] {
  display: none;
}

.claim-banner-inner {
  background: rgba(255, 248, 240, 0.96);
  border: 2px solid var(--fire);
  border-radius: 18px;
  box-shadow: 0 18px 40px rgba(120, 40, 0, 0.25);
  padding: 1rem 1.1rem;
  text-align: center;
}

.claim-title {
  margin: 0;
  font-family: var(--font-display);
  font-size: 1.35rem;
  color: var(--pine-deep);
}

.claim-text {
  margin: 0.35rem 0 0.85rem;
  font-weight: 600;
  color: var(--fire-deep);
}

.claim-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.55rem;
  justify-content: center;
}

.claim-actions .phase-win-btn {
  width: auto;
  flex: 1 1 180px;
}

.claim-actions .secondary-btn {
  flex: 1 1 160px;
}

@keyframes claim-in {
  from {
    opacity: 0;
    transform: translateX(-50%) translateY(16px);
  }
  to {
    opacity: 1;
    transform: translateX(-50%) translateY(0);
  }
}

.ghost-btn.is-listening {
  background: rgba(255, 122, 47, 0.2);
  border-color: rgba(255, 122, 47, 0.55);
  color: var(--fire-deep);
}

.board-section {
  grid-area: board;
  background: var(--panel);
  backdrop-filter: blur(14px);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  border: 1px solid rgba(255, 255, 255, 0.65);
  padding: clamp(1rem, 2.5vw, 1.5rem);
  display: flex;
  flex-direction: column;
  min-height: 0;
}

.board-header h2,
.history-section h2 {
  margin: 0;
  font-family: var(--font-display);
  font-size: 1.55rem;
  color: var(--pine-deep);
  letter-spacing: 0.02em;
}

.board-hint {
  margin: 0.25rem 0 1rem;
  color: var(--leaf);
  font-size: 0.95rem;
}

.number-board {
  display: grid;
  grid-template-columns: repeat(10, minmax(0, 1fr));
  gap: 0.35rem;
  flex: 1;
}

.cell {
  aspect-ratio: 1;
  display: grid;
  place-items: center;
  border-radius: 10px;
  background: rgba(255, 255, 255, 0.7);
  border: 1px solid rgba(31, 92, 69, 0.12);
  font-weight: 700;
  font-size: clamp(0.7rem, 1.4vw, 0.95rem);
  color: rgba(26, 46, 36, 0.45);
  transition: background 0.25s ease, color 0.25s ease, transform 0.25s ease, box-shadow 0.25s ease;
}

.cell.drawn {
  background: linear-gradient(145deg, #ffb065, var(--fire));
  color: #fff;
  border-color: transparent;
  box-shadow: 0 4px 12px rgba(232, 93, 18, 0.28);
  transform: scale(1.04);
}

.cell.latest {
  animation: cell-flash 0.7s ease;
  outline: 2px solid var(--pine-deep);
  outline-offset: 1px;
}

@keyframes cell-flash {
  0% { transform: scale(1.25); }
  100% { transform: scale(1.04); }
}

.history-section {
  grid-area: history;
  background: var(--panel);
  backdrop-filter: blur(14px);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  border: 1px solid rgba(255, 255, 255, 0.65);
  padding: clamp(1rem, 2.5vw, 1.35rem);
}

.history-list {
  list-style: none;
  margin: 0.85rem 0 0;
  padding: 0;
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
}

.history-list li {
  width: 48px;
  height: 48px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  font-family: var(--font-display);
  font-size: 1.15rem;
  background: linear-gradient(145deg, #ffe0a8, var(--fire));
  color: var(--pine-deep);
  box-shadow: 0 4px 10px rgba(232, 93, 18, 0.25);
  animation: history-in 0.35s cubic-bezier(0.22, 1, 0.36, 1) both;
}

@keyframes history-in {
  from {
    opacity: 0;
    transform: scale(0.6) translateY(8px);
  }
  to {
    opacity: 1;
    transform: none;
  }
}

.history-empty {
  margin: 0.75rem 0 0;
  color: var(--leaf);
  font-weight: 600;
}

.history-empty[hidden] {
  display: none;
}

.footer {
  text-align: center;
  padding: 0 1.5rem 2rem;
  color: var(--pine);
  font-size: 0.9rem;
  font-weight: 600;
  opacity: 0.8;
}

.confetti {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 50;
  overflow: hidden;
}

.confetti span {
  position: absolute;
  top: -12px;
  width: 10px;
  height: 14px;
  border-radius: 2px;
  animation: fall linear forwards;
}

@keyframes fall {
  to {
    transform: translateY(105vh) rotate(720deg);
    opacity: 0.2;
  }
}

@media (max-width: 960px) {
  .stage {
    grid-template-columns: 1fr;
    grid-template-areas:
      "draw"
      "history"
      "board";
  }

  .topbar {
    flex-direction: column;
    align-items: stretch;
  }

  .top-actions {
    justify-content: flex-start;
  }

  .hero-draw {
    min-height: 360px;
  }

  .number-board {
    grid-template-columns: repeat(9, minmax(0, 1fr));
  }
}

@media (max-width: 480px) {
  .number-board {
    grid-template-columns: repeat(6, minmax(0, 1fr));
  }

  .draw-btn {
    width: 100%;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}
