:root {
  --tea-deep: #1e3a2f;
  --tea-mid: #2d5a47;
  --tea-light: #4a7c59;
  --tea-sage: #8fa88a;
  --tea-mist: #e8f0eb;
  --coffee-dark: #3d2314;
  --coffee-mid: #6f4e37;
  --coffee-warm: #a0622a;
  --coffee-amber: #c17817;
  --coffee-cream: #f5ebe0;
  --cream: #faf7f2;
  --cream-dark: #f0e9df;
  --ink: #1a1612;
  --ink-muted: #5c534a;
  --white: #ffffff;
  --font-serif: "Noto Serif SC", "Cormorant Garamond", Georgia, serif;
  --font-sans: "Outfit", system-ui, sans-serif;
  --radius-sm: 8px;
  --radius-md: 16px;
  --radius-lg: 24px;
  --shadow-md: 0 8px 32px rgba(26, 22, 18, 0.1);
  --transition: 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

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

body {
  font-family: var(--font-sans);
  color: var(--ink);
  background:
    radial-gradient(ellipse at 20% 0%, rgba(74, 124, 89, 0.12) 0%, transparent 50%),
    radial-gradient(ellipse at 80% 100%, rgba(193, 120, 23, 0.1) 0%, transparent 50%),
    var(--cream);
  min-height: 100vh;
}

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

.game-top-bar {
  display: flex;
  justify-content: flex-end;
  padding: 0.75rem 1rem 0;
  max-width: 520px;
  margin-inline: auto;
}

.lang-switcher {
  position: relative;
}

.lang-toggle {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  padding: 0.4rem 0.75rem;
  font-family: var(--font-sans);
  font-size: 0.8125rem;
  font-weight: 500;
  color: var(--tea-mid);
  background: var(--white);
  border: 1px solid rgba(45, 90, 71, 0.12);
  border-radius: 100px;
  cursor: pointer;
  transition: all var(--transition);
}

.lang-toggle:hover {
  border-color: var(--tea-sage);
  color: var(--tea-deep);
}

.lang-menu {
  position: absolute;
  top: calc(100% + 0.35rem);
  right: 0;
  min-width: 9rem;
  background: var(--white);
  border-radius: var(--radius-sm);
  box-shadow: var(--shadow-md);
  padding: 0.35rem;
  z-index: 20;
  list-style: none;
}

.lang-menu.hidden {
  display: none;
}

.lang-option {
  display: block;
  width: 100%;
  text-align: left;
  padding: 0.5rem 0.75rem;
  border: none;
  background: transparent;
  font-family: var(--font-sans);
  font-size: 0.8125rem;
  color: var(--ink);
  border-radius: var(--radius-sm);
  cursor: pointer;
}

.lang-option:hover,
.lang-option.is-active {
  background: var(--tea-mist);
  color: var(--tea-deep);
}

.hidden {
  display: none !important;
}

.game-header {
  padding: 1.5rem 1rem 0.5rem;
  text-align: center;
}

.game-header-inner {
  max-width: 520px;
  margin-inline: auto;
}

.back-link {
  display: inline-block;
  font-size: 0.875rem;
  font-weight: 500;
  color: var(--tea-mid);
  margin-bottom: 1rem;
  transition: color var(--transition);
}

.back-link:hover {
  color: var(--coffee-amber);
}

.game-title {
  font-family: var(--font-serif);
  font-size: clamp(1.75rem, 5vw, 2.25rem);
  font-weight: 600;
  color: var(--tea-deep);
  margin-bottom: 0.35rem;
}

.game-subtitle {
  font-size: 0.9375rem;
  color: var(--ink-muted);
}

.game-main {
  padding: 1.5rem 1rem 2.5rem;
  display: flex;
  justify-content: center;
}

.game-panel {
  width: min(100%, 420px);
}

.stats {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 0.75rem;
  margin-bottom: 1.25rem;
}

.stat {
  background: var(--white);
  border-radius: var(--radius-md);
  padding: 0.875rem 0.75rem;
  text-align: center;
  box-shadow: var(--shadow-md);
  border: 1px solid rgba(45, 90, 71, 0.08);
}

.stat-label {
  display: block;
  font-size: 0.75rem;
  font-weight: 500;
  letter-spacing: 0.06em;
  color: var(--ink-muted);
  margin-bottom: 0.25rem;
}

.stat-value {
  font-family: var(--font-serif);
  font-size: 1.375rem;
  font-weight: 600;
  color: var(--tea-deep);
}

.board-wrap {
  background: linear-gradient(145deg, var(--tea-deep), var(--coffee-dark));
  border-radius: var(--radius-lg);
  padding: 0.75rem;
  box-shadow: var(--shadow-md);
  margin-bottom: 1.25rem;
}

.board {
  display: grid;
  grid-template-columns: repeat(8, 1fr);
  gap: 4px;
  aspect-ratio: 1;
  user-select: none;
  touch-action: manipulation;
}

.tile {
  display: flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(160deg, var(--cream), var(--coffee-cream));
  border-radius: var(--radius-sm);
  border: 2px solid rgba(255, 255, 255, 0.35);
  cursor: pointer;
  transition: transform 0.15s ease, box-shadow 0.15s ease, opacity 0.2s ease;
  aspect-ratio: 1;
  overflow: hidden;
  padding: 2px;
}

.tile img {
  width: 100%;
  height: 100%;
  object-fit: contain;
  pointer-events: none;
}

.tile:hover:not(.tile-empty) {
  transform: scale(1.06);
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.2);
}

.tile.selected {
  transform: scale(1.08);
  box-shadow: 0 0 0 3px var(--coffee-amber), 0 4px 16px rgba(193, 120, 23, 0.4);
  z-index: 1;
}

.tile.matching {
  animation: pop 0.35s ease forwards;
}

@keyframes pop {
  0% { transform: scale(1); opacity: 1; }
  50% { transform: scale(1.15); opacity: 0.7; }
  100% { transform: scale(0); opacity: 0; }
}

.tile-empty {
  visibility: hidden;
  pointer-events: none;
}

.game-actions {
  display: flex;
  justify-content: center;
  margin-bottom: 1rem;
}

.game-hint {
  font-size: 0.8125rem;
  color: var(--ink-muted);
  text-align: center;
  line-height: 1.6;
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0.75rem 1.5rem;
  font-family: var(--font-sans);
  font-size: 0.9375rem;
  font-weight: 500;
  border-radius: 100px;
  border: 2px solid transparent;
  cursor: pointer;
  transition: all var(--transition);
}

.btn:disabled {
  opacity: 0.6;
  cursor: not-allowed;
  transform: none !important;
}

.btn-primary {
  background: linear-gradient(135deg, var(--tea-mid), var(--tea-deep));
  color: var(--white);
  box-shadow: 0 4px 20px rgba(45, 90, 71, 0.35);
}

.btn-primary:hover:not(:disabled) {
  transform: translateY(-2px);
  box-shadow: 0 8px 28px rgba(45, 90, 71, 0.45);
}

.btn-outline-dark {
  background: transparent;
  color: var(--tea-deep);
  border-color: rgba(30, 58, 47, 0.25);
}

.btn-outline-dark:hover {
  background: var(--tea-mist);
  border-color: var(--tea-mid);
}

.overlay {
  position: fixed;
  inset: 0;
  background: rgba(26, 22, 18, 0.55);
  backdrop-filter: blur(4px);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1.5rem;
  z-index: 100;
}

.overlay-card {
  background: var(--white);
  border-radius: var(--radius-lg);
  padding: clamp(1.75rem, 5vw, 2.5rem);
  max-width: 380px;
  width: 100%;
  text-align: center;
  box-shadow: var(--shadow-md);
}

.overlay-card h2 {
  font-family: var(--font-serif);
  font-size: 1.5rem;
  color: var(--tea-deep);
  margin-bottom: 0.75rem;
}

.overlay-card p {
  color: var(--ink-muted);
  margin-bottom: 0.5rem;
}

.overlay-score {
  font-size: 1.05rem;
  margin-bottom: 1.25rem !important;
}

.overlay-score strong {
  font-family: var(--font-serif);
  font-size: 1.5rem;
  color: var(--coffee-amber);
}

.lottery-section {
  margin-bottom: 1.25rem;
}

.lottery-intro {
  font-size: 0.875rem;
  font-weight: 500;
  color: var(--tea-deep);
  margin-bottom: 0.75rem !important;
}

.lottery-drum {
  background: linear-gradient(135deg, var(--tea-mist), var(--coffee-cream));
  border: 2px dashed rgba(193, 120, 23, 0.45);
  border-radius: var(--radius-md);
  padding: 1.25rem 1rem;
  margin-bottom: 1rem;
  min-height: 3.5rem;
  display: flex;
  align-items: center;
  justify-content: center;
}

.lottery-drum.spinning .lottery-drum-text {
  animation: drumBlink 0.12s ease infinite alternate;
}

.lottery-drum-text {
  font-family: var(--font-serif);
  font-size: 1.25rem;
  font-weight: 600;
  color: var(--coffee-amber);
}

@keyframes drumBlink {
  from { opacity: 0.5; transform: scale(0.98); }
  to { opacity: 1; transform: scale(1.02); }
}

.btn-lottery {
  width: 100%;
}

.prize-result {
  margin-bottom: 1.25rem;
}

.prize-card {
  background: linear-gradient(160deg, var(--tea-deep), var(--coffee-dark));
  color: var(--white);
  border-radius: var(--radius-md);
  padding: 1.5rem 1.25rem;
  position: relative;
  overflow: hidden;
}

.prize-card::before {
  content: "";
  position: absolute;
  inset: 0;
  background: radial-gradient(circle at 80% 20%, rgba(193, 120, 23, 0.25) 0%, transparent 55%);
  pointer-events: none;
}

.prize-badge {
  display: inline-block;
  padding: 0.25rem 0.75rem;
  font-size: 0.75rem;
  font-weight: 600;
  letter-spacing: 0.08em;
  background: var(--coffee-amber);
  border-radius: 100px;
  margin-bottom: 0.75rem;
  position: relative;
}

.prize-card h3 {
  font-family: var(--font-serif);
  font-size: 1.35rem;
  margin-bottom: 0.5rem;
  position: relative;
}

.prize-card p {
  color: rgba(255, 255, 255, 0.82);
  font-size: 0.875rem;
  line-height: 1.6;
  position: relative;
}

.prize-code {
  margin-top: 1rem !important;
  font-size: 0.9375rem !important;
}

.prize-code strong {
  font-family: "Courier New", monospace;
  font-size: 1.125rem;
  letter-spacing: 0.06em;
  color: var(--coffee-cream);
}

.prize-note {
  font-size: 0.75rem !important;
  opacity: 0.75;
  margin-top: 0.5rem !important;
}

.overlay-actions {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

@media (max-width: 380px) {
  .board {
    gap: 3px;
  }
}

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