:root {
  --bg: #05070b;
  --ink: #ece8dc;
  --muted: #8d95a3;
  --rice: #f2e7ca;
  --lentil: #f08a3c;
  --rock: #98a2b1;
  --gold: #ffd35c;
  --good: #7ef0b2;
  --bad: #ff5a6a;
  --ease: cubic-bezier(0.2, 0.8, 0.2, 1);
}

* {
  box-sizing: border-box;
}

html,
body {
  height: 100%;
  margin: 0;
}

body {
  background: var(--bg);
  color: var(--ink);
  font-family: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto,
    "Helvetica Neue", Arial, sans-serif;
  overflow: hidden;
  overscroll-behavior: none;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
  user-select: none;
  -webkit-user-select: none;
}

button {
  font-family: inherit;
}

#app {
  position: fixed;
  inset: 0;
  overflow: hidden;
}

#view {
  position: absolute;
  inset: 0;
  display: block;
  width: 100%;
  height: 100%;
  touch-action: none;
  cursor: grab;
}

#view:active {
  cursor: grabbing;
}

#vignette {
  position: absolute;
  inset: 0;
  z-index: 2;
  pointer-events: none;
  background:
    radial-gradient(ellipse at 50% 44%, transparent 38%, rgba(2, 3, 6, 0.42) 100%),
    linear-gradient(180deg, rgba(2, 3, 6, 0.5), transparent 18%, transparent 78%, rgba(2, 3, 6, 0.55));
}

/* ------------------------------------------------------------------ bins */

#bins {
  position: absolute;
  inset: 0;
  z-index: 3;
  pointer-events: none;
}

.bin {
  --bin: var(--rice);
  position: absolute;
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--bin);
  opacity: 0.68;
  transition: opacity 0.18s var(--ease), background 0.18s var(--ease),
    box-shadow 0.18s var(--ease);
  will-change: opacity;
}

.bin-name {
  padding: 4px 8px 4px 10px;
  border-radius: 99px;
  border: 1px solid rgba(255, 255, 255, 0.075);
  background: rgba(6, 8, 12, 0.5);
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.24em;
  text-shadow: 0 2px 10px rgba(0, 0, 0, 0.8);
  backdrop-filter: blur(4px);
}

.bin-chevron {
  font-size: 18px;
  font-weight: 300;
  line-height: 1;
  opacity: 0.8;
}

.bin-left,
.bin-right {
  top: 0;
  bottom: 0;
  width: 76px;
  flex-direction: column;
  justify-content: center;
}

.bin-left {
  --bin: var(--rice);
  left: 0;
  background: linear-gradient(
    90deg,
    rgba(242, 231, 202, 0.075),
    rgba(242, 231, 202, 0.015) 55%,
    transparent
  );
  border-left: 1px solid rgba(242, 231, 202, 0.16);
}

.bin-right {
  --bin: var(--lentil);
  right: 0;
  background: linear-gradient(
    270deg,
    rgba(240, 138, 60, 0.075),
    rgba(240, 138, 60, 0.015) 55%,
    transparent
  );
  border-right: 1px solid rgba(240, 138, 60, 0.16);
}

.bin-down {
  --bin: var(--rock);
  left: 0;
  right: 0;
  bottom: 0;
  height: 66px;
  justify-content: center;
  background: linear-gradient(
    0deg,
    rgba(152, 162, 177, 0.07),
    rgba(152, 162, 177, 0.012) 60%,
    transparent
  );
  border-bottom: 1px solid rgba(152, 162, 177, 0.14);
}

.bin.active {
  opacity: 1;
}

.bin-left.active {
  background: linear-gradient(
    90deg,
    rgba(242, 231, 202, 0.22),
    rgba(242, 231, 202, 0.035) 62%,
    transparent
  );
  box-shadow: inset 3px 0 0 var(--bin), inset 40px 0 80px -50px var(--bin);
}

.bin-right.active {
  background: linear-gradient(
    270deg,
    rgba(240, 138, 60, 0.24),
    rgba(240, 138, 60, 0.04) 62%,
    transparent
  );
  box-shadow: inset -3px 0 0 var(--bin), inset -40px 0 80px -50px var(--bin);
}

.bin-down.active {
  background: linear-gradient(
    0deg,
    rgba(152, 162, 177, 0.2),
    rgba(152, 162, 177, 0.03) 62%,
    transparent
  );
  box-shadow: inset 0 -3px 0 var(--bin), inset 0 -40px 80px -50px var(--bin);
}

.bin.good {
  --bin: var(--good);
  opacity: 1;
}

.bin.bad {
  --bin: var(--bad);
  opacity: 1;
}

/* -------------------------------------------------------------------- HUD */

#hud {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  z-index: 5;
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  padding: max(16px, env(safe-area-inset-top))
    max(20px, env(safe-area-inset-right)) 0 max(20px, env(safe-area-inset-left));
  pointer-events: none;
}

.level-block {
  display: flex;
  flex-direction: column;
  gap: 9px;
}

.level-chip {
  display: flex;
  align-items: baseline;
  gap: 7px;
  align-self: flex-start;
  padding: 6px 13px 7px;
  border-radius: 12px;
  background: rgba(13, 17, 24, 0.62);
  border: 1px solid rgba(255, 255, 255, 0.07);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  box-shadow: 0 8px 26px rgba(0, 0, 0, 0.28);
}

.lv-label {
  font-size: 9px;
  font-weight: 700;
  letter-spacing: 0.22em;
  color: var(--muted);
}

#levelNum {
  font-size: 19px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  line-height: 1;
  color: #f7f3e8;
}

.level-bar {
  width: 176px;
  height: 4px;
  margin-left: 2px;
  border-radius: 99px;
  background: rgba(255, 255, 255, 0.075);
  overflow: hidden;
  box-shadow: inset 0 1px 2px rgba(0, 0, 0, 0.4);
}

#barFill {
  display: block;
  height: 100%;
  width: 0%;
  border-radius: inherit;
  background: linear-gradient(90deg, #b9a87e, var(--gold) 70%, #fff2c4);
  box-shadow: 0 0 12px rgba(255, 211, 92, 0.45);
  transition: width 0.24s var(--ease);
}

.score-block {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 2px;
  padding-top: 2px;
}

.score-block em {
  font-size: 9px;
  font-style: normal;
  font-weight: 700;
  letter-spacing: 0.26em;
  color: var(--muted);
}

#score {
  font-size: clamp(26px, 4.2vw, 38px);
  font-weight: 700;
  letter-spacing: -0.02em;
  line-height: 1;
  font-variant-numeric: tabular-nums;
  color: #fbf7ec;
  text-shadow: 0 4px 24px rgba(0, 0, 0, 0.55);
  transform-origin: right center;
}

#score.pop {
  animation: scorePop 0.26s var(--ease);
}

@keyframes scorePop {
  0% {
    transform: scale(1);
  }
  35% {
    transform: scale(1.14);
    color: #fff6d8;
  }
  100% {
    transform: scale(1);
  }
}

/* ------------------------------------------------------------------ combo */

#combo {
  position: absolute;
  top: 96px;
  right: max(22px, env(safe-area-inset-right));
  z-index: 5;
  display: flex;
  align-items: flex-end;
  gap: 8px;
  pointer-events: none;
  opacity: 0;
  transform: translateY(-8px);
  transition: opacity 0.2s var(--ease), transform 0.2s var(--ease);
}

#combo.show {
  opacity: 1;
  transform: translateY(0);
}

.combo-main {
  display: flex;
  align-items: baseline;
  gap: 6px;
}

#comboNum {
  font-size: 26px;
  font-weight: 800;
  line-height: 1;
  font-variant-numeric: tabular-nums;
  color: var(--gold);
  text-shadow: 0 0 22px rgba(255, 211, 92, 0.35);
}

.combo-main em {
  font-size: 8.5px;
  font-style: normal;
  font-weight: 700;
  letter-spacing: 0.2em;
  color: var(--muted);
}

#comboMult {
  font-size: 10px;
  font-weight: 700;
  color: #cdb87f;
  padding-bottom: 2px;
}

#combo.pop #comboNum {
  animation: comboPop 0.28s var(--ease);
}

@keyframes comboPop {
  0% {
    transform: scale(1);
  }
  40% {
    transform: scale(1.28);
  }
  100% {
    transform: scale(1);
  }
}

/* ------------------------------------------------------------------ toast */

#toast {
  position: absolute;
  top: 19%;
  left: 50%;
  z-index: 6;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  text-align: center;
  pointer-events: none;
  opacity: 0;
  transform: translate(-50%, -6px) scale(0.97);
  transition: opacity 0.22s var(--ease), transform 0.22s var(--ease);
}

#toast.show {
  opacity: 1;
  transform: translate(-50%, 0) scale(1);
}

#toastTitle {
  font-size: clamp(20px, 3vw, 28px);
  font-weight: 800;
  letter-spacing: 0.16em;
  color: #fff6da;
  text-shadow: 0 6px 28px rgba(0, 0, 0, 0.6);
}

#toastSub {
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 0.22em;
  color: #bfae7c;
  text-transform: uppercase;
}

/* --------------------------------------------------------------- floaters */

#floaters {
  position: absolute;
  inset: 0;
  z-index: 7;
  pointer-events: none;
  overflow: hidden;
}

.floater {
  position: absolute;
  font-size: 20px;
  font-weight: 800;
  letter-spacing: -0.01em;
  opacity: 0;
  will-change: transform, opacity;
  text-shadow: 0 2px 14px rgba(0, 0, 0, 0.7);
  color: #dfffe9;
  white-space: nowrap;
}

.floater.kind-good {
  color: #d7ffe7;
}

.floater.kind-rice {
  color: #fff3cf;
}

.floater.kind-lentil {
  color: #ffb175;
}

.floater.kind-rock {
  color: #d2d9e4;
}

.floater.kind-gold {
  color: var(--gold);
  text-shadow: 0 0 18px rgba(255, 211, 92, 0.5);
}

.floater.kind-bad {
  color: var(--bad);
  font-size: 14px;
  letter-spacing: 0.08em;
}

.floater.go {
  animation: floatUp 0.9s var(--ease) forwards;
}

@keyframes floatUp {
  0% {
    opacity: 0;
    transform: translate(-50%, -35%) scale(0.82);
  }
  14% {
    opacity: 1;
    transform: translate(-50%, -50%) scale(1.06);
  }
  100% {
    opacity: 0;
    transform: translate(-50%, -210%) scale(1);
  }
}

/* ------------------------------------------------------------------ flash */

#flash {
  position: absolute;
  inset: 0;
  z-index: 8;
  pointer-events: none;
  opacity: 0;
}

#flash.flash-bad {
  background: radial-gradient(
    ellipse at 50% 55%,
    rgba(255, 60, 80, 0.02) 25%,
    rgba(255, 60, 80, 0.2) 100%
  );
  box-shadow: inset 0 0 120px rgba(255, 60, 80, 0.3);
  animation: flashFade 0.45s ease-out;
}

#flash.flash-gold {
  background: radial-gradient(
    ellipse at 50% 50%,
    rgba(255, 211, 92, 0.16),
    rgba(255, 211, 92, 0.02) 60%
  );
  animation: flashFade 0.35s ease-out;
}

@keyframes flashFade {
  0% {
    opacity: 1;
  }
  100% {
    opacity: 0;
  }
}

/* ------------------------------------------------------------------ debug */

#debug {
  position: absolute;
  right: max(16px, env(safe-area-inset-right));
  bottom: max(16px, env(safe-area-inset-bottom));
  z-index: 7;
  display: flex;
  gap: 12px;
  padding: 7px 11px;
  border-radius: 9px;
  background: rgba(8, 11, 16, 0.55);
  border: 1px solid rgba(255, 255, 255, 0.055);
  color: #5f6978;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 9.5px;
  letter-spacing: 0.02em;
  backdrop-filter: blur(8px);
  transition: opacity 0.2s;
  pointer-events: none;
}

#debug b {
  color: #93a0b2;
  font-weight: 600;
}

#debug.hidden {
  opacity: 0;
}

/* ------------------------------------------------------------------- mute */

.ghost {
  position: absolute;
  left: max(18px, env(safe-area-inset-left));
  bottom: max(18px, env(safe-area-inset-bottom));
  z-index: 7;
  padding: 7px 10px;
  background: transparent;
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 8px;
  color: #7d879a;
  font-size: 8.5px;
  font-weight: 700;
  letter-spacing: 0.18em;
  cursor: pointer;
  transition: color 0.15s, border-color 0.15s, background 0.15s;
}

.ghost:hover {
  color: #d6dce6;
  border-color: rgba(255, 255, 255, 0.18);
  background: rgba(255, 255, 255, 0.03);
}

.ghost.muted {
  color: #4c5563;
}

/* ---------------------------------------------------------------- overlays */

.overlay {
  position: absolute;
  inset: 0;
  z-index: 20;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 32px 22px;
  background: radial-gradient(
      ellipse at 50% 42%,
      rgba(10, 14, 21, 0.45),
      rgba(3, 4, 7, 0.9) 74%
    ),
    linear-gradient(180deg, rgba(3, 4, 7, 0.55), rgba(3, 4, 7, 0.72));
  backdrop-filter: blur(5px);
  -webkit-backdrop-filter: blur(5px);
  transition: opacity 0.4s var(--ease), visibility 0.4s var(--ease);
}

.overlay.hidden {
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
}

/* ------------------------------------------------------------------ intro */

.intro-panel {
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  max-width: 660px;
  animation: introIn 0.7s var(--ease) both;
}

@keyframes introIn {
  from {
    opacity: 0;
    transform: translateY(16px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.eyebrow {
  margin: 0;
  font-size: 9px;
  font-weight: 700;
  letter-spacing: 0.34em;
  color: #8e8060;
  text-transform: uppercase;
}

.eyebrow b {
  color: var(--gold);
}

h1 {
  margin: 12px 0 8px;
  font-size: clamp(54px, 12vw, 108px);
  font-weight: 800;
  letter-spacing: 0.14em;
  line-height: 0.95;
  text-indent: 0.14em; /* balance the trailing letter-spacing */
  background: linear-gradient(180deg, #fffaf0 0%, #e8d7ae 55%, #a48f62 100%);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
  filter: drop-shadow(0 14px 44px rgba(255, 211, 92, 0.16));
}

.tagline {
  margin: 6px 0 30px;
  font-size: clamp(13px, 1.6vw, 15px);
  line-height: 1.6;
  color: #9ba3b0;
  letter-spacing: 0.01em;
}

.legend {
  display: flex;
  gap: 26px;
  flex-wrap: wrap;
  justify-content: center;
  margin-bottom: 34px;
}

.legend-item {
  display: flex;
  align-items: center;
  gap: 10px;
  text-align: left;
}

.legend-item b {
  display: block;
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.16em;
  color: #ded9cc;
}

.legend-item em {
  display: block;
  margin-top: 2px;
  font-size: 10px;
  font-style: normal;
  color: #7f8896;
}

.grain {
  position: relative;
  display: inline-block;
  flex: none;
  width: 34px;
  height: 24px;
}

.grain.rice {
  width: 34px;
  height: 14px;
  border-radius: 50%;
  background: radial-gradient(
    70% 120% at 35% 20%,
    #fffaf0 0%,
    #f2e7ca 45%,
    #cbb98e 100%
  );
  transform: rotate(-26deg);
  box-shadow: 0 4px 14px rgba(242, 231, 202, 0.22);
}

.grain.lentil {
  width: 23px;
  height: 23px;
  border-radius: 50%;
  background: radial-gradient(
    60% 60% at 35% 30%,
    #ffb878 0%,
    #f08a3c 48%,
    #b4521a 100%
  );
  box-shadow: 0 4px 16px rgba(240, 138, 60, 0.28),
    inset 0 -2px 4px rgba(90, 35, 5, 0.5);
}

.grain.rock {
  width: 25px;
  height: 23px;
  background: linear-gradient(145deg, #79828f 0%, #4a505b 55%, #2c313a 100%);
  clip-path: polygon(22% 6%, 72% 0%, 100% 38%, 86% 88%, 40% 100%, 4% 70%, 0% 30%);
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.6);
}

.primary {
  position: relative;
  padding: 16px 42px;
  border: 0;
  border-radius: 999px;
  background: linear-gradient(180deg, #ffe9a8 0%, #ffd35c 45%, #d9a52e 100%);
  color: #221a06;
  font-size: 11px;
  font-weight: 800;
  letter-spacing: 0.22em;
  cursor: pointer;
  box-shadow: 0 12px 34px rgba(255, 196, 58, 0.22),
    inset 0 1px 0 rgba(255, 255, 255, 0.55);
  transition: transform 0.16s var(--ease), box-shadow 0.16s var(--ease),
    filter 0.16s;
}

.primary:hover {
  transform: translateY(-2px);
  filter: brightness(1.04);
  box-shadow: 0 16px 44px rgba(255, 196, 58, 0.32),
    inset 0 1px 0 rgba(255, 255, 255, 0.55);
}

.primary:active {
  transform: translateY(0) scale(0.98);
}

.controls {
  margin: 22px 0 0;
  font-size: 9.5px;
  font-weight: 600;
  letter-spacing: 0.13em;
  color: #5f6876;
  text-transform: uppercase;
  text-align: center;
}

/* ------------------------------------------------------------------ cards */

#cards {
  z-index: 30;
  gap: 26px;
  justify-content: center;
}

.cards-head {
  text-align: center;
}

.cards-head h2 {
  margin: 10px 0 0;
  font-size: clamp(26px, 4vw, 38px);
  font-weight: 800;
  letter-spacing: 0.16em;
  color: #f6f1e4;
  text-indent: 0.16em;
}

.cards-head .eyebrow {
  font-size: 11px;
}

.card-row {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 20px;
  width: 100%;
  max-width: 780px;
}

.card {
  --tone: var(--gold);
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  justify-content: center;
  overflow: hidden;
  min-height: 200px;
  padding: 26px 26px 28px;
  border: 1px solid rgba(255, 255, 255, 0.075);
  border-radius: 20px;
  background: linear-gradient(
    180deg,
    rgba(25, 30, 40, 0.94) 0%,
    rgba(10, 13, 18, 0.97) 100%
  );
  color: var(--ink);
  text-align: left;
  cursor: pointer;
  box-shadow: 0 20px 50px rgba(0, 0, 0, 0.32);
  animation: cardIn 0.52s var(--ease) both;
  animation-delay: calc(var(--i) * 70ms);
  transition: transform 0.18s var(--ease), border-color 0.18s,
    box-shadow 0.18s;
}

@keyframes cardIn {
  from {
    opacity: 0;
    transform: translateY(20px) scale(0.975);
  }
  to {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
}

.card::before {
  content: "";
  position: absolute;
  inset: 0 0 auto;
  height: 2px;
  background: linear-gradient(90deg, transparent, var(--tone), transparent);
  opacity: 0.85;
}

.card::after {
  content: "";
  position: absolute;
  inset: -60% -30% auto;
  height: 120px;
  background: radial-gradient(
    ellipse at 50% 0%,
    color-mix(in srgb, var(--tone) 16%, transparent),
    transparent 70%
  );
  pointer-events: none;
}

.card:hover,
.card:focus-visible {
  transform: translateY(-6px);
  border-color: var(--tone);
  box-shadow: 0 26px 60px rgba(0, 0, 0, 0.45),
    0 0 0 1px color-mix(in srgb, var(--tone) 35%, transparent),
    0 0 50px -18px var(--tone);
  outline: none;
}

.card-icon {
  display: block;
  width: 48px;
  height: 48px;
  margin-bottom: 24px;
  color: var(--tone);
  filter: drop-shadow(0 0 16px color-mix(in srgb, var(--tone) 30%, transparent));
}

.card-icon svg {
  width: 100%;
  height: 100%;
}

.card-name {
  font-size: 17px;
  font-weight: 800;
  letter-spacing: 0.14em;
  color: #f7f2e6;
}

.card-desc {
  display: block;
  margin-top: 12px;
  font-size: 14.5px;
  line-height: 1.6;
  color: #a4aebd;
}

/* -------------------------------------------------------------- responsive */

@media (max-width: 720px) {
  #hud {
    padding-top: max(12px, env(safe-area-inset-top));
    padding-left: max(14px, env(safe-area-inset-left));
    padding-right: max(14px, env(safe-area-inset-right));
  }

  .level-bar {
    width: 118px;
  }

  .bin-left,
  .bin-right {
    width: 58px;
  }

  .bin-name {
    font-size: 8.5px;
    letter-spacing: 0.2em;
  }

  .bin-down {
    height: 56px;
  }

  .bin-chevron {
    font-size: 15px;
  }

  #combo {
    top: 82px;
  }

  .legend {
    gap: 18px;
    margin-bottom: 28px;
  }

  .tagline {
    margin-bottom: 24px;
  }

  .overlay {
    padding: 22px 14px;
    overflow-y: auto;
  }

  #cards {
    justify-content: flex-start;
    gap: 18px;
  }

  .card-row {
    grid-template-columns: 1fr;
    max-width: 430px;
    gap: 10px;
  }

  .card {
    min-height: 0;
    padding: 20px 18px 22px;
  }

  .card-icon {
    width: 34px;
    height: 34px;
    margin-bottom: 14px;
  }

  .card-name {
    font-size: 15px;
  }

  .card-desc {
    margin-top: 8px;
    font-size: 13.5px;
    line-height: 1.55;
  }

  #debug {
    display: none;
  }

  .ghost {
    font-size: 8px;
    padding: 6px 8px;
  }
}

@media (max-height: 560px) and (orientation: landscape) {
  .intro-panel h1 {
    margin: 6px 0 4px;
    font-size: clamp(42px, 9vh, 72px);
  }

  .tagline {
    margin-bottom: 16px;
  }

  .legend {
    margin-bottom: 18px;
  }

  .controls {
    margin-top: 12px;
  }
}
