:root {
  --brand-outline: #0e2a14;
  --brand-grass: #98d23a;
  --brand-grass-dark: #6db81c;
  --brand-dirt-light: #bb8833;
  --brand-dirt-dark: #633d14;

  --surface-primary: rgba(14, 42, 20, 0.88);
  --surface-secondary: rgba(22, 56, 30, 0.82);
  --surface-card: rgba(14, 42, 20, 0.78);

  --border-color: var(--brand-outline);
  --border-chunky: 3px solid var(--brand-outline);

  --text-primary: #ffffff;
  --text-secondary: #e5eadc;

  --text-shadow-heavy: 3px 3px 0 var(--brand-outline);
  --text-shadow-light: 2px 2px 0 var(--brand-outline);
  --text-shadow-subtle: 1px 2px 3px rgba(0, 0, 0, 0.55);

  --gold: #fbbf24;
  --accent-green: #22c55e;
  --rare-blue: #3b82f6;
  --legendary-gold: #fbbf24;
  --danger-red: #ef4444;

  --font-display: 'Luckiest Guy', 'Impact', -apple-system, BlinkMacSystemFont, sans-serif;
  --font-body: 'Fredoka', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
}

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

[hidden] {
  display: none !important;
}

html, body {
  font-family: var(--font-display);
  color: var(--text-primary);
  -webkit-tap-highlight-color: transparent;
  -webkit-text-size-adjust: 100%;
  overscroll-behavior: none;
  letter-spacing: 0.02em;
}

body {
  display: flex;
  flex-direction: column;
  min-height: 100vh;
  min-height: 100dvh;
  background: #2a7a14;
  position: relative;
}

body::before {
  content: '';
  position: fixed;
  inset: 0;
  background: url('assets/bg-stripes.png') center / cover no-repeat;
  z-index: -1;
}

button {
  font-family: inherit;
  letter-spacing: inherit;
}

.top-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.6rem 1rem;
  padding-top: max(0.6rem, env(safe-area-inset-top));
  background: var(--surface-primary);
  border-bottom: var(--border-chunky);
  position: sticky;
  top: 0;
  z-index: 10;
}

.app-title {
  display: flex;
  align-items: center;
  gap: 0.55rem;
  font-size: 1.2rem;
  font-weight: 400;
  color: var(--text-primary);
  text-shadow: var(--text-shadow-light);
  min-width: 0;
  flex: 1;
}

.app-title span {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.app-logo {
  width: 38px;
  height: 38px;
  object-fit: contain;
  filter: drop-shadow(2px 2px 0 var(--brand-outline));
}

.top-bar-controls {
  display: flex;
  gap: 0.25rem;
}

.icon-button {
  background: transparent;
  border: none;
  color: var(--text-primary);
  font-size: 1.4rem;
  padding: 0.4rem 0.55rem;
  border-radius: 8px;
  cursor: pointer;
  line-height: 1;
  text-shadow: var(--text-shadow-subtle);
}
.icon-button:active {
  background: rgba(255, 255, 255, 0.08);
}
.icon-button:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

.main-area {
  flex: 1;
  display: flex;
  flex-direction: column;
  padding: 1rem;
  gap: 1rem;
}

.shop-area {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0.6rem;
  min-height: 200px;
}

.shop-button {
  width: 100%;
  max-width: 480px;
  padding: 1.9rem 1rem;
  font-size: 2.1rem;
  font-weight: 400;
  letter-spacing: 0.08em;
  color: var(--text-primary);
  background: linear-gradient(145deg, var(--brand-dirt-light) 0%, var(--brand-dirt-dark) 100%);
  border: 4px solid var(--brand-outline);
  border-radius: 16px;
  cursor: pointer;
  box-shadow: 0 6px 0 var(--brand-outline), 0 10px 20px rgba(0, 0, 0, 0.4);
  text-shadow: var(--text-shadow-heavy);
  transition: transform 90ms ease, box-shadow 90ms ease;
}
.shop-button:active {
  transform: translateY(4px);
  box-shadow: 0 2px 0 var(--brand-outline), 0 4px 10px rgba(0, 0, 0, 0.4);
}
.shop-button:disabled {
  opacity: 0.6;
  cursor: not-allowed;
}

.reels-container {
  display: flex;
  flex-direction: column;
  gap: 0.55rem;
  width: 100%;
}

.reroll-button {
  margin-top: 0.3rem;
  padding: 0.75rem 1.5rem;
  font-family: inherit;
  font-size: 1.1rem;
  letter-spacing: 0.05em;
  color: var(--text-primary);
  background: linear-gradient(145deg, var(--brand-grass) 0%, var(--brand-grass-dark) 100%);
  border: 3px solid var(--brand-outline);
  border-radius: 12px;
  cursor: pointer;
  text-shadow: var(--text-shadow-light);
  box-shadow: 0 4px 0 var(--brand-outline);
  align-self: center;
}
.reroll-button:active {
  transform: translateY(3px);
  box-shadow: 0 1px 0 var(--brand-outline);
}
.reroll-button:disabled {
  opacity: 0.55;
  cursor: not-allowed;
}

.pick-two-banner {
  margin-top: 0.5rem;
  padding: 0.4rem 0.9rem;
  font-size: 0.95rem;
  letter-spacing: 0.06em;
  color: var(--text-primary);
  background: linear-gradient(145deg, rgba(251, 191, 36, 0.35), rgba(217, 119, 6, 0.55));
  border: 2px solid var(--brand-outline);
  border-radius: 10px;
  text-shadow: var(--text-shadow-light);
  align-self: center;
}

.reroll-replay-banner {
  margin-top: 0.5rem;
  padding: 0.55rem 1.1rem;
  font-size: 1.3rem;
  letter-spacing: 0.08em;
  color: var(--text-primary);
  background: linear-gradient(145deg, rgba(251, 191, 36, 0.7), rgba(217, 119, 6, 0.9));
  border: 3px solid var(--brand-outline);
  border-radius: 12px;
  text-shadow: var(--text-shadow-heavy);
  box-shadow: 0 4px 0 var(--brand-outline);
  align-self: center;
  animation: rerollBannerFlash 600ms ease-out;
}

@keyframes rerollBannerFlash {
  0% { transform: scale(0.5); opacity: 0; }
  40% { transform: scale(1.15); opacity: 1; }
  100% { transform: scale(1); opacity: 1; }
}

.reel {
  width: 100%;
  height: 92px;
  container-type: size;
  overflow: hidden;
  position: relative;
  background: var(--surface-card);
  border: var(--border-chunky);
  border-radius: 12px;
  user-select: none;
  -webkit-user-select: none;
  box-shadow: 0 4px 0 var(--brand-outline), 0 8px 16px rgba(0, 0, 0, 0.35);
}

.reel.pickable {
  cursor: pointer;
}
.reel.pickable:active {
  transform: scale(0.99);
}

.reel-strip {
  display: flex;
  flex-direction: row;
  position: absolute;
  left: 0;
  top: 0;
  will-change: transform;
  transform: translate(0, 0);
}

.reel-strip.spinning {
  transition: transform 2000ms cubic-bezier(0.17, 0.72, 0.28, 1);
  transform: translate(var(--spin-x, 0), 0);
}

.card {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  gap: 1rem;
  padding: 0 1.1rem;
  width: 100cqw;
  height: 100cqh;
  box-sizing: border-box;
}

.card-icon {
  font-size: 2.2rem;
  line-height: 1.25;
  flex: 0 0 auto;
  filter: drop-shadow(1px 2px 0 var(--brand-outline));
}

.card-name {
  font-size: 1.3rem;
  font-weight: 400;
  color: var(--text-primary);
  text-shadow: var(--text-shadow-light);
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.rarity-rare {
  background: linear-gradient(90deg, rgba(59, 130, 246, 0.18), transparent 80%);
  box-shadow: inset 0 0 0 1px var(--rare-blue);
}

.rarity-legendary {
  background: linear-gradient(90deg, rgba(251, 191, 36, 0.22), transparent 80%);
  box-shadow: inset 0 0 0 1px var(--legendary-gold);
}

.reel.landed.rarity-rare-landed {
  border-color: var(--rare-blue);
  box-shadow: 0 4px 0 var(--brand-outline), 0 0 18px rgba(59, 130, 246, 0.6);
}

.reel.landed.rarity-legendary-landed {
  border-color: var(--legendary-gold);
  animation: legendaryPulse 1.6s ease-in-out infinite;
}

@keyframes legendaryPulse {
  0%, 100% {
    box-shadow: 0 4px 0 var(--brand-outline), 0 0 16px rgba(251, 191, 36, 0.55);
  }
  50% {
    box-shadow: 0 4px 0 var(--brand-outline), 0 0 32px rgba(251, 191, 36, 0.95);
  }
}

.reel.pick-locked {
  animation: pickFlash 600ms ease-out;
  border-color: var(--accent-green);
  box-shadow: 0 4px 0 var(--brand-outline), 0 0 20px rgba(34, 197, 94, 0.7);
}

@keyframes pickFlash {
  0% {
    transform: scale(1);
    box-shadow: 0 4px 0 var(--brand-outline), 0 8px 16px rgba(0, 0, 0, 0.35);
  }
  40% {
    transform: scale(1.04);
    box-shadow: 0 4px 0 var(--brand-outline), 0 0 38px rgba(34, 197, 94, 0.9);
  }
  100% {
    transform: scale(1);
    box-shadow: 0 4px 0 var(--brand-outline), 0 0 20px rgba(34, 197, 94, 0.7);
  }
}

.reel.pick-faded {
  opacity: 0.3;
  filter: grayscale(1);
  transition: opacity 400ms ease, filter 400ms ease;
}

.active-panel {
  background: var(--surface-primary);
  border: var(--border-chunky);
  border-radius: 14px;
  padding: 1rem;
  flex: 1;
  min-height: 140px;
  box-shadow: 0 4px 0 var(--brand-outline), 0 8px 16px rgba(0, 0, 0, 0.35);
}

.panel-title {
  font-size: 1rem;
  font-weight: 400;
  color: var(--text-primary);
  text-shadow: var(--text-shadow-light);
  letter-spacing: 0.12em;
  margin-bottom: 0.75rem;
}

.active-list {
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.active-item {
  display: flex;
  align-items: center;
  gap: 0.8rem;
  padding: 0.7rem 0.85rem;
  background: var(--surface-secondary);
  border: 2px solid var(--brand-outline);
  border-radius: 10px;
  cursor: pointer;
  transition: background-color 150ms ease;
}
.active-item:active {
  background: rgba(152, 210, 58, 0.12);
}
.active-item.expanded {
  align-items: flex-start;
}

.active-item-icon {
  font-size: 1.7rem;
  line-height: 1.25;
  flex: 0 0 auto;
  filter: drop-shadow(1px 2px 0 var(--brand-outline));
}

.active-item-body {
  flex: 1;
  min-width: 0;
}

.active-item-name {
  font-size: 1.1rem;
  font-weight: 400;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.35rem;
  text-shadow: var(--text-shadow-light);
}

.active-item-count {
  font-weight: 400;
  color: var(--gold);
  text-shadow: var(--text-shadow-light);
}

.active-item-description {
  display: none;
  margin-top: 0.5rem;
  font-family: var(--font-body);
  font-weight: 500;
  font-size: 0.95rem;
  line-height: 1.4;
  color: var(--text-secondary);
  text-shadow: var(--text-shadow-subtle);
  letter-spacing: 0.01em;
}

.active-item.expanded .active-item-description {
  display: block;
}

.active-item-badge {
  display: inline-block;
  font-size: 0.68rem;
  padding: 2px 7px;
  border-radius: 999px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
}
.badge-self {
  background: rgba(34, 197, 94, 0.2);
  color: #86efac;
}
.badge-opponent {
  background: rgba(239, 68, 68, 0.2);
  color: #fca5a5;
}
.badge-neutral {
  background: rgba(148, 163, 184, 0.25);
  color: #e2e8f0;
}

.use-button {
  background: linear-gradient(145deg, var(--brand-grass) 0%, var(--brand-grass-dark) 100%);
  color: var(--text-primary);
  border: 2px solid var(--brand-outline);
  border-radius: 10px;
  padding: 0.55rem 1.05rem;
  font-size: 1rem;
  font-weight: 400;
  letter-spacing: 0.05em;
  cursor: pointer;
  flex: 0 0 auto;
  min-width: 72px;
  text-shadow: var(--text-shadow-light);
  box-shadow: 0 3px 0 var(--brand-outline);
}
.use-button:active {
  transform: translateY(2px);
  box-shadow: 0 1px 0 var(--brand-outline);
}

.empty-message {
  color: var(--text-secondary);
  padding: 0.5rem 0.25rem;
  font-size: 1rem;
  text-shadow: var(--text-shadow-subtle);
  letter-spacing: 0.03em;
}

.bottom-bar {
  padding: 0.75rem 1rem;
  padding-bottom: max(0.75rem, env(safe-area-inset-bottom));
  background: var(--surface-primary);
  border-top: var(--border-chunky);
  display: flex;
  gap: 0.6rem;
}

.bar-button {
  flex: 1;
  padding: 0.85rem 0.75rem;
  font-size: 1.1rem;
  font-weight: 400;
  letter-spacing: 0.05em;
  color: var(--text-primary);
  background: var(--surface-secondary);
  border: 2px solid var(--brand-outline);
  border-radius: 12px;
  cursor: pointer;
  text-shadow: var(--text-shadow-light);
  box-shadow: 0 3px 0 var(--brand-outline);
}
.bar-button:active {
  transform: translateY(2px);
  box-shadow: 0 1px 0 var(--brand-outline);
}
.bar-button:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}
.bar-button-danger {
  color: #fecaca;
  background: linear-gradient(145deg, rgba(239, 68, 68, 0.35), rgba(127, 29, 29, 0.5));
}

.top-bar-replay .replay-label,
.top-bar-export .export-label {
  display: none;
}

.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.7);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
  padding: 1rem;
}
.modal-backdrop[hidden] {
  display: none;
}

.modal {
  background: var(--surface-primary);
  border: var(--border-chunky);
  border-radius: 16px;
  padding: 1.5rem;
  max-width: 420px;
  width: 100%;
  box-shadow: 0 6px 0 var(--brand-outline), 0 16px 32px rgba(0, 0, 0, 0.5);
}

.modal-text {
  font-family: var(--font-body);
  font-weight: 500;
  font-size: 1.05rem;
  margin-bottom: 1.25rem;
  color: var(--text-primary);
  line-height: 1.4;
  letter-spacing: 0.01em;
  text-shadow: var(--text-shadow-subtle);
}

.modal-buttons {
  display: flex;
  gap: 0.75rem;
  justify-content: flex-end;
}

.modal-button {
  padding: 0.7rem 1.3rem;
  font-size: 1rem;
  font-weight: 400;
  letter-spacing: 0.05em;
  border-radius: 10px;
  border: 2px solid var(--brand-outline);
  background: var(--surface-secondary);
  color: var(--text-primary);
  cursor: pointer;
  text-shadow: var(--text-shadow-light);
  box-shadow: 0 3px 0 var(--brand-outline);
}
.modal-button-danger {
  background: linear-gradient(145deg, #ef4444, #991b1b);
  border-color: var(--brand-outline);
  color: white;
}
.modal-button:active {
  transform: translateY(2px);
  box-shadow: 0 1px 0 var(--brand-outline);
}

.admin-add-modal {
  max-width: 520px;
}

.admin-add-grid {
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
  max-height: 55vh;
  overflow-y: auto;
  margin-bottom: 1.1rem;
  padding-right: 0.25rem;
}

.admin-add-option {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.6rem 0.85rem;
  background: var(--surface-secondary);
  border: 2px solid var(--brand-outline);
  border-radius: 10px;
  color: var(--text-primary);
  text-shadow: var(--text-shadow-light);
  cursor: pointer;
  font-family: inherit;
  font-size: 1rem;
  letter-spacing: 0.02em;
  text-align: left;
  width: 100%;
  box-shadow: 0 2px 0 var(--brand-outline);
}
.admin-add-option:active {
  transform: translateY(1px);
  box-shadow: 0 1px 0 var(--brand-outline);
  background: rgba(152, 210, 58, 0.15);
}
.admin-add-option-icon {
  font-size: 1.5rem;
  line-height: 1.25;
  flex: 0 0 auto;
  filter: drop-shadow(1px 2px 0 var(--brand-outline));
}
.admin-add-option-name {
  flex: 1;
  min-width: 0;
}

.active-item.long-press-active {
  background: rgba(251, 191, 36, 0.18);
  border-color: var(--gold);
}

@media (min-width: 900px) {
  .main-area {
    max-width: 1100px;
    margin: 0 auto;
    width: 100%;
    padding: 1.5rem;
  }

  .shop-area {
    min-height: 360px;
    gap: 1rem;
  }

  .shop-button {
    max-width: 520px;
    font-size: 2.4rem;
    padding: 2.4rem 1rem;
  }

  .reels-container {
    flex-direction: row;
    justify-content: center;
    gap: 1.5rem;
  }

  .reel {
    width: 240px;
    height: 320px;
    flex: 0 0 auto;
  }

  .reel-strip {
    flex-direction: column;
  }

  .reel-strip.spinning {
    transform: translate(0, var(--spin-y, 0));
  }

  .card {
    flex-direction: column;
    justify-content: center;
    gap: 0.9rem;
    padding: 1.25rem;
    text-align: center;
  }

  .card-icon {
    font-size: 3.6rem;
    line-height: 1.3;
  }

  .card-name {
    font-size: 1.15rem;
    white-space: normal;
    line-height: 1.3;
    flex: 0 0 auto;
  }

  .active-panel {
    min-height: 160px;
  }

  .active-list {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
    gap: 0.75rem;
  }

  .bottom-bar {
    justify-content: center;
  }

  .bar-button {
    flex: 0 0 auto;
    min-width: 200px;
  }

  .top-bar-replay .replay-label,
  .top-bar-export .export-label {
    display: inline;
    font-size: 0.85rem;
    font-weight: 600;
    margin-left: 0.2rem;
    letter-spacing: 0.02em;
  }
}
