#codes {
  --codes-gold: #ffe0a1;
  --codes-border: #8c693d76;
  --codes-surface: #101b2a;
  background: radial-gradient(ellipse at 84% 0%, #31252a, transparent 35rem), #0b111d;
}

.codes-hero {
  position: relative;
  isolation: isolate;
  overflow: hidden;
  display: grid;
  grid-template-columns: minmax(0, 1.25fr) minmax(0, 1fr);
  gap: clamp(1.4rem, 4vw, 3.5rem);
  align-items: center;
  max-width: none;
  padding: clamp(1.25rem, 5vw, 3.5rem);
  border: 1px solid var(--codes-border);
  border-radius: 1.25rem;
  background: linear-gradient(125deg, #101b2c 15%, #17243a 56%, #312538);
  box-shadow: 0 20px 50px #03061055;
}
.codes-hero::before,
.codes-hero::after {
  position: absolute;
  z-index: -1;
  content: "";
  pointer-events: none;
}
.codes-hero::before {
  inset: -60% -16% -60% 22%;
  background: radial-gradient(ellipse, #d994313d, transparent 56%);
}
.codes-hero::after {
  width: min(60%, 35rem);
  aspect-ratio: 1.16;
  inset: -45% -4% auto auto;
  clip-path: polygon(25% 0, 75% 0, 100% 50%, 75% 100%, 25% 100%, 0 50%);
  background: repeating-radial-gradient(ellipse, #ffd58624 0 1px, transparent 2px 27px);
  opacity: .45;
}
.codes-hero h2 {
  margin: .25rem 0 .75rem;
  font-size: clamp(2.35rem, 7vw, 5rem);
  line-height: 1.03;
  letter-spacing: -.055em;
}
.codes-hero > div > p { max-width: 38ch; }
.codes-count { color: var(--codes-gold); }
.codes-count strong { font: 750 1.75rem var(--mono); vertical-align: -.1em; }

.codes-feature {
  min-width: 0;
  padding: clamp(1rem, 3vw, 1.5rem);
  border: 1px solid var(--codes-border);
  border-radius: .9rem;
  background: #0e1728e8;
}
.codes-feature h3, #codes .code-card h3 { margin: .2rem 0 .45rem; }
#codes code {
  color: var(--codes-gold);
  font: 700 clamp(.9rem, 2vw, 1.16rem) var(--mono);
  overflow-wrap: anywhere;
  user-select: text;
}

.codes-controls {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr)) auto;
  gap: .75rem;
  align-items: end;
  padding: 1rem;
  margin-block: 1.4rem .7rem;
  border: 1px solid var(--line);
  border-radius: .85rem;
  background: var(--codes-surface);
}
.codes-controls label, .codes-toolbar label { display: grid; gap: .35rem; min-width: 0; }
.codes-controls input, .codes-controls select, .codes-toolbar select { width: 100%; min-width: 0; min-height: 44px; }
.codes-controls .button, .codes-copy { min-height: 44px; }
.codes-toolbar { display: flex; align-items: end; justify-content: space-between; gap: .7rem; }
.codes-toolbar p { margin: 0 0 .55rem; }
.codes-announcement { min-height: 1.5em; margin: .15rem 0 .35rem; color: var(--codes-gold); font-size: .875rem; }

.codes-results {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 1rem;
  align-items: stretch;
  min-height: 5.5rem;
}
/* Code card: honey accent bar on top, faint honeycomb in the corner, copy button pinned to the bottom. */
#codes .code-card {
  position: relative;
  isolation: isolate;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  align-items: stretch;
  text-align: start;
  gap: .8rem;
  min-width: 0;
  padding: 1.2rem 1.15rem 1.15rem;
  border: 1px solid var(--line);
  border-radius: 1rem;
  background: linear-gradient(155deg, #1a2740, var(--codes-surface) 62%);
  box-shadow: 0 10px 24px #02050d40;
}
#codes .code-card::before {
  position: absolute;
  inset: 0 0 auto;
  height: 3px;
  content: "";
  background: linear-gradient(90deg, #f6bd38, #ffe0a1 45%, #d98a2b);
  opacity: .85;
}
#codes .code-card::after {
  position: absolute;
  z-index: -1;
  inset: -2.5rem -2.5rem auto auto;
  width: 8.5rem;
  aspect-ratio: 1.16;
  content: "";
  clip-path: polygon(25% 0, 75% 0, 100% 50%, 75% 100%, 25% 100%, 0 50%);
  background: repeating-radial-gradient(circle, #ffd58614 0 1px, transparent 2px 14px);
  pointer-events: none;
}
#codes .code-card:focus-within { border-color: #bf965f; }
#codes .code-card[data-expired] { background: #0d1522; box-shadow: none; }
#codes .code-card[data-expired]::before { background: var(--line); }
#codes .code-card[data-expired] code { color: var(--muted); text-decoration: line-through; text-decoration-thickness: 1px; }
.codes-expired-note { margin: 0; color: var(--muted); font-size: .875rem; }

.codes-badges { display: flex; flex-wrap: wrap; gap: .35rem; margin-bottom: .55rem; }
.codes-badge {
  display: inline-flex;
  align-items: center;
  gap: .35rem;
  padding: .15rem .55rem;
  border: 1px solid var(--line);
  border-radius: 999px;
  color: var(--muted);
  font-size: .75rem;
}
.codes-badge[data-active] { border-color: #83bd8a77; background: #83bd8a14; color: #b8ebbd; }
.codes-badge[data-active]::before {
  width: .45rem;
  height: .45rem;
  content: "";
  border-radius: 50%;
  background: #7fdc8a;
  box-shadow: 0 0 0 0 #7fdc8a99;
}

/* The code itself, shown like a ticket stub. */
#codes .code-card h3, .codes-feature h3 {
  position: relative;
  overflow: hidden;
  width: fit-content;
  max-width: 100%;
  margin: 0 0 .45rem;
  padding: .4rem .75rem;
  border: 1px dashed #c8995a8c;
  border-radius: .55rem;
  background: #070d18b3;
}
#codes .code-card h3::after, .codes-feature h3::after {
  position: absolute;
  inset: 0;
  content: "";
  background: linear-gradient(105deg, transparent 35%, #ffe0a138 50%, transparent 65%);
  transform: translateX(-110%);
  pointer-events: none;
}
#codes .code-card[data-expired] h3 { border-color: var(--line); }
#codes .code-card[data-expired] h3::after { display: none; }

.codes-tags { margin: 0; color: var(--codes-gold); font-size: .78rem; }
.codes-reward-groups { display: flex; flex-wrap: wrap; gap: .4rem; margin: 0; padding: 0; list-style: none; }
.codes-reward-groups li {
  display: inline-flex;
  align-items: center;
  gap: .4rem;
  padding: .3rem .65rem .3rem .5rem;
  border: 1px solid #ffffff12;
  border-radius: 999px;
  background: #080f1cb3;
  font-size: .875rem;
  line-height: 1.3;
  overflow-wrap: anywhere;
}
.codes-reward-groups li::before {
  flex: none;
  width: .5rem;
  height: .44rem;
  content: "";
  clip-path: polygon(25% 0, 75% 0, 100% 50%, 75% 100%, 25% 100%, 0 50%);
  background: #f6bd38;
}
.codes-feature .codes-reward-groups { margin-bottom: 1rem; }
.codes-help summary { cursor: pointer; color: var(--codes-gold); }

.codes-copy {
  width: 100%;
  margin-top: auto;
  border-color: #c8995a;
  background: linear-gradient(180deg, #f6bd38, #d98a2b);
  color: #1a1206;
  font-weight: 750;
}
.codes-copy:hover { filter: brightness(1.08); }
.codes-feature .codes-copy { width: fit-content; min-width: 10rem; }
.codes-copy[data-copied] { border-color: #83bd8a; background: linear-gradient(180deg, #9be3a3, #5fb76b); color: #08150a; }

#codes[data-view="compact"] .codes-results { gap: .65rem; grid-template-columns: repeat(4, minmax(0, 1fr)); }
#codes[data-view="compact"] .code-card { gap: .5rem; padding: .85rem .75rem .75rem; }
#codes[data-view="compact"] .codes-reward-groups li { padding: .15rem .5rem .15rem .4rem; font-size: .8rem; }
#codes[data-view="list"] .codes-results { grid-template-columns: minmax(0, 1fr); gap: .65rem; }
#codes[data-view="list"] .code-card {
  display: grid;
  grid-template-columns: minmax(10rem, 1fr) minmax(0, 1.65fr) minmax(8rem, auto);
  align-items: center;
}
#codes[data-view="list"] .codes-copy { width: auto; margin-top: 0; }
.codes-empty { grid-column: 1 / -1; padding: 1rem; border: 1px dashed var(--line); border-radius: .75rem; }
.codes-help { margin-top: 1.25rem; padding: 1rem; border: 1px solid var(--line); border-radius: .85rem; }
.codes-help dt { margin-top: .7rem; font-weight: 700; }
.codes-help dd { margin-inline-start: 0; color: var(--muted); }

@keyframes codes-glow {
  from { opacity: .18; transform: translateX(9%); }
  to { opacity: 1; transform: none; }
}
/* Cards rise in one after another (--i is set by js/app.js), every time the list changes. */
@keyframes codes-card-in {
  from { opacity: 0; transform: translateY(14px) scale(.98); }
  to { opacity: 1; transform: none; }
}
/* A light sweep across the code every few seconds. */
@keyframes codes-shimmer {
  0%, 70% { transform: translateX(-110%); }
  100% { transform: translateX(110%); }
}
/* The green "active" dot gently pings. */
@keyframes codes-ping {
  0% { box-shadow: 0 0 0 0 #7fdc8a99; }
  80%, 100% { box-shadow: 0 0 0 .4rem #7fdc8a00; }
}
/* Reward chips drop in after their card. */
@keyframes codes-chip-in {
  from { opacity: 0; transform: translateY(6px); }
  to { opacity: 1; transform: none; }
}
@keyframes codes-copied {
  0% { transform: scale(1); }
  40% { transform: scale(1.05); }
  100% { transform: scale(1); }
}
@keyframes codes-feature-float {
  0%, 100% { transform: translateY(0); box-shadow: 0 14px 34px #02050d55; }
  50% { transform: translateY(-4px); box-shadow: 0 20px 40px #d994312e; }
}
@media (prefers-reduced-motion: no-preference) {
  :root:not([data-motion-paused]) .codes-hero::before { animation: codes-glow 900ms var(--motion-out, ease-out) both; }
  :root:not([data-motion-paused]) #codes .code-card {
    animation: codes-card-in 460ms cubic-bezier(.2, .8, .2, 1) both;
    animation-delay: calc(var(--i, 0) * 55ms);
    transition: border-color 200ms, translate 200ms, box-shadow 200ms;
  }
  :root:not([data-motion-paused]) #codes .code-card:not([data-expired]) h3::after { animation: codes-shimmer 4.5s ease-in-out infinite; animation-delay: calc(var(--i, 0) * 280ms + 1s); }
  :root:not([data-motion-paused]) .codes-feature h3::after { animation: codes-shimmer 3.5s ease-in-out infinite 1s; }
  :root:not([data-motion-paused]) .codes-badge[data-active]::before { animation: codes-ping 2.2s ease-out infinite; }
  :root:not([data-motion-paused]) #codes .code-card .codes-reward-groups li { animation: codes-chip-in 320ms ease-out both; animation-delay: calc(var(--i, 0) * 55ms + 220ms); }
  :root:not([data-motion-paused]) .codes-copy { transition: filter 150ms, background 200ms, border-color 200ms; }
  :root:not([data-motion-paused]) .codes-copy[data-copied] { animation: codes-copied 320ms ease-out; }
  :root:not([data-motion-paused]) .codes-feature { animation: codes-feature-float 6s ease-in-out infinite; }
  @media (hover: hover) {
    :root:not([data-motion-paused]) #codes .code-card:hover { translate: 0 -4px; border-color: #bf965f; box-shadow: 0 16px 34px #02050d66, 0 0 0 1px #f6bd3826, 0 0 28px #f6bd381f; }
    :root:not([data-motion-paused]) #codes .code-card:hover h3::after { animation-duration: 1.2s; animation-delay: 0s; }
  }
}

@media (max-width: 1050px) {
  .codes-controls { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  #codes[data-view="compact"] .codes-results { grid-template-columns: repeat(3, minmax(0, 1fr)); }
}
@media (max-width: 760px) {
  .codes-hero { grid-template-columns: minmax(0, 1fr); }
  .codes-controls, .codes-results, #codes[data-view="compact"] .codes-results { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .codes-search { grid-column: 1 / -1; }
  #codes[data-view="list"] .code-card { grid-template-columns: minmax(0, 1fr) auto; }
  #codes[data-view="list"] .codes-reward-groups, #codes[data-view="list"] .codes-expired-note { grid-column: 1 / -1; }
  #codes[data-view="list"] .codes-copy { grid-column: 2; grid-row: 1; }
}
@media (max-width: 520px) {
  .codes-results, #codes[data-view="compact"] .codes-results { grid-template-columns: minmax(0, 1fr); }
}
