:root {
  --ink: #071b2e;
  --panel: #0b2a43;
  --panel-soft: #113955;
  --cyan: #27d9e8;
  --cyan-bright: #7df6ff;
  --paper: #e9fbfd;
  --muted: #9bd4db;
  --icon-background: #c9f3f7;
  --shadow: 0 18px 45px rgba(0, 11, 24, 0.38);
}

* {
  box-sizing: border-box;
}

html {
  background: #031321;
  touch-action: manipulation;
}

body {
  margin: 0;
  min-width: 320px;
  min-height: 100vh;
  color: var(--paper);
  background:
    radial-gradient(circle at 20% 0%, rgba(19, 105, 137, 0.32), transparent 34rem),
    linear-gradient(145deg, #041522, #082941);
  font-family: "Trebuchet MS", "Avenir Next", Avenir, sans-serif;
}

button {
  color: inherit;
  font: inherit;
}

button:focus-visible {
  outline: 3px solid var(--paper);
  outline-offset: 3px;
}

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

.app-shell {
  width: min(100%, 460px);
  min-height: 100vh;
  margin: 0 auto;
  padding: 28px 18px 104px;
  background:
    linear-gradient(rgba(4, 24, 40, 0.91), rgba(4, 24, 40, 0.97)),
    repeating-linear-gradient(120deg, transparent 0 40px, rgba(53, 221, 232, 0.05) 41px 42px);
  box-shadow: 0 0 80px rgba(0, 0, 0, 0.28);
}

.app-header,
.drawer-heading,
.card-main,
.drawer-handle {
  display: flex;
  align-items: center;
}

.app-header {
  justify-content: space-between;
  margin-bottom: 24px;
}

.eyebrow {
  margin: 0 0 4px;
  color: var(--cyan);
  font-size: 0.7rem;
  font-weight: 800;
  letter-spacing: 0.18em;
  text-transform: uppercase;
}

.game-selector {
  position: relative;
  width: max-content;
}

.game-selector-button {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 2px 0 7px;
  cursor: pointer;
  background: transparent;
  border: 0;
}

.game-selector-button svg {
  width: 9px;
  height: 9px;
  transition: transform 180ms ease;
}

.game-selector.open .game-selector-button svg {
  transform: rotate(180deg);
}

.game-menu {
  position: absolute;
  z-index: 20;
  top: calc(100% + 6px);
  left: 0;
  width: min(330px, calc(100vw - 36px));
  padding: 7px;
  visibility: hidden;
  background: #102c45;
  border: 2px solid var(--cyan);
  border-radius: 13px;
  box-shadow: var(--shadow);
  opacity: 0;
  transform: translateY(-7px) scale(0.98);
  transform-origin: top left;
  transition:
    opacity 160ms ease,
    transform 200ms cubic-bezier(0.22, 1, 0.36, 1),
    visibility 0s linear 200ms;
}

.game-selector.open .game-menu {
  visibility: visible;
  opacity: 1;
  transform: translateY(0) scale(1);
  transition-delay: 0s;
}

.game-option {
  display: grid;
  grid-template-columns: 38px 1fr 20px;
  align-items: center;
  width: 100%;
  padding: 10px;
  gap: 10px;
  cursor: pointer;
  color: var(--paper);
  text-align: left;
  background: transparent;
  border: 0;
  border-radius: 9px;
}

.game-option:hover,
.game-option:focus-visible {
  background: rgba(39, 217, 232, 0.12);
}

.game-option strong,
.game-option small {
  display: block;
}

.game-option small {
  margin-top: 3px;
  color: var(--muted);
  font-size: 0.68rem;
}

.game-mark {
  display: grid;
  place-items: center;
  width: 36px;
  height: 36px;
  color: var(--ink);
  background: var(--cyan);
  border-radius: 50%;
  font-weight: 900;
}

.below-zero-mark {
  color: #092c4e;
  background: #a9e1ff;
  font-size: 0.72rem;
}

.game-check {
  color: var(--cyan-bright);
  opacity: 0;
}

.game-option.selected .game-check {
  opacity: 1;
}

h1,
h2,
p {
  margin-top: 0;
}

h1 {
  margin-bottom: 0;
  font-size: clamp(1.75rem, 8vw, 2.25rem);
  line-height: 1;
  letter-spacing: -0.04em;
}

.recipe-count {
  padding: 7px 10px;
  color: var(--cyan-bright);
  border: 1px solid rgba(39, 217, 232, 0.45);
  border-radius: 999px;
  font-size: 0.72rem;
}

.search-bar {
  position: sticky;
  z-index: 8;
  top: 0;
  display: flex;
  align-items: center;
  gap: 0;
  margin: 0 -4px 16px;
  padding: 10px 12px;
  color: var(--cyan);
  background: rgba(6, 29, 49, 0.96);
  border: 2px solid var(--cyan);
  border-radius: 13px;
  box-shadow: 0 10px 24px rgba(0, 11, 24, 0.32);
  backdrop-filter: blur(12px);
}

.search-input-wrap,
.category-filter {
  display: flex;
  align-items: center;
  gap: 10px;
}

.search-input-wrap {
  min-width: 0;
  flex: 1;
}

.search-bar svg {
  flex: 0 0 auto;
  width: 17px;
  height: 17px;
}

.search-bar input,
.category-filter-button {
  width: 100%;
  min-width: 0;
  padding: 3px 0;
  color: var(--paper);
  background: transparent;
  border: 0;
  outline: 0;
  font: inherit;
}

.category-filter {
  position: relative;
  flex: 0 1 210px;
  margin-left: 12px;
  padding-left: 12px;
  border-left: 1px solid rgba(125, 246, 255, 0.28);
}

.category-filter-button {
  display: flex;
  align-items: center;
  gap: 10px;
  cursor: pointer;
  text-align: left;
}

.category-filter-button span {
  min-width: 0;
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.category-filter .select-chevron {
  width: 9px;
  height: 9px;
  transition: transform 180ms ease;
}

.category-filter.open .select-chevron {
  transform: rotate(180deg);
}

.category-menu {
  position: absolute;
  z-index: 30;
  top: calc(100% + 13px);
  right: -12px;
  width: min(310px, calc(100vw - 36px));
  max-height: min(360px, 55vh);
  padding: 7px;
  overflow-y: auto;
  visibility: hidden;
  background: #102c45;
  border: 2px solid var(--cyan);
  border-radius: 13px;
  box-shadow: var(--shadow);
  opacity: 0;
  transform: translateY(-7px);
  transition:
    opacity 160ms ease,
    transform 200ms cubic-bezier(0.22, 1, 0.36, 1),
    visibility 0s linear 200ms;
}

.category-filter.open .category-menu {
  visibility: visible;
  opacity: 1;
  transform: translateY(0);
  transition-delay: 0s;
}

.category-option {
  display: flex;
  align-items: center;
  width: 100%;
  padding: 9px 10px;
  gap: 10px;
  cursor: pointer;
  text-align: left;
  background: transparent;
  border: 0;
  border-radius: 8px;
}

.category-option:hover,
.category-option:focus-visible {
  background: rgba(39, 217, 232, 0.12);
}

.category-checkbox {
  display: grid;
  place-items: center;
  width: 19px;
  height: 19px;
  color: var(--ink);
  border: 1.5px solid var(--cyan);
  border-radius: 5px;
  font-size: 0.75rem;
  font-weight: 900;
}

.category-option[aria-selected="true"] .category-checkbox {
  background: var(--cyan);
}

.category-pills {
  position: sticky;
  z-index: 7;
  top: 58px;
  display: flex;
  flex-wrap: wrap;
  gap: 7px;
  margin: -7px 0 14px;
}

.category-pills:empty {
  display: none;
}

.category-pill {
  display: flex;
  align-items: center;
  padding: 6px 8px 6px 10px;
  gap: 7px;
  color: var(--ink);
  background: var(--cyan);
  border: 0;
  border-radius: 999px;
  box-shadow: 0 5px 12px rgba(0, 11, 24, 0.24);
  font-size: 0.72rem;
  font-weight: 800;
}

.category-pill button {
  display: grid;
  place-items: center;
  width: 18px;
  height: 18px;
  padding: 0;
  cursor: pointer;
  color: var(--ink);
  background: rgba(7, 27, 46, 0.12);
  border: 0;
  border-radius: 50%;
  line-height: 1;
}

.search-bar input::placeholder {
  color: var(--muted);
}

.search-bar input::-webkit-search-cancel-button {
  display: none;
}

.search-clear {
  display: none;
  width: 26px;
  height: 26px;
  padding: 0;
  cursor: pointer;
  color: var(--cyan-bright);
  background: transparent;
  border: 1px solid currentColor;
  border-radius: 50%;
  font-size: 1.1rem;
  line-height: 1;
}

.search-bar.has-value .search-clear {
  display: grid;
  place-items: center;
}

@media (max-width: 520px) {
  .search-bar {
    align-items: stretch;
    flex-direction: column;
    gap: 9px;
  }

  .category-filter {
    flex-basis: auto;
    margin-left: 0;
    padding-top: 9px;
    padding-left: 0;
    border-top: 1px solid rgba(125, 246, 255, 0.28);
    border-left: 0;
  }

  .category-menu {
    top: calc(100% + 9px);
    right: 0;
    left: 0;
    width: 100%;
  }

  .category-pills {
    top: 101px;
  }
}

.recipe-list {
  display: grid;
  gap: 12px;
}

.recipe-card {
  overflow: hidden;
  color: var(--cyan-bright);
  background: var(--panel);
  border: 2px solid var(--cyan);
  border-radius: 13px;
  box-shadow: 0 7px 18px rgba(0, 11, 24, 0.2);
  transition:
    color 180ms ease,
    background 180ms ease,
    transform 180ms ease,
    box-shadow 260ms ease;
}

.recipe-card.active {
  color: var(--ink);
  background: var(--cyan);
}

.recipe-card.expanded {
  box-shadow: 0 14px 28px rgba(0, 11, 24, 0.32);
}

.recipe-card:active {
  transform: scale(0.99);
}

.card-main {
  min-height: 84px;
  padding: 10px;
  gap: 10px;
}

.recipe-image,
.ingredient-image,
.total-image {
  flex: 0 0 auto;
  padding: 5px;
  object-fit: contain;
  background: var(--icon-background);
  border: 2px solid currentColor;
  border-radius: 50%;
}

.recipe-image {
  width: 58px;
  height: 58px;
}

.recipe-title-wrap {
  min-width: 0;
  flex: 1;
}

.recipe-title {
  margin: 0;
  overflow: hidden;
  font-size: 1rem;
  line-height: 1.1;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.recipe-category {
  margin: 5px 0 0;
  font-size: 0.68rem;
  opacity: 0.7;
}

.add-button,
.more-button,
.quantity-button {
  display: grid;
  place-items: center;
  width: 34px;
  height: 34px;
  padding: 0;
  cursor: pointer;
  background: transparent;
  border: 1.5px solid currentColor;
  border-radius: 50%;
}

.add-button svg {
  display: block;
  width: 15px;
  height: 15px;
}

.more-button {
  width: 26px;
  height: 34px;
  border-color: transparent;
}

.more-button svg {
  display: block;
  width: 17px;
  height: 17px;
  transition: transform 260ms cubic-bezier(0.22, 1, 0.36, 1);
}

.recipe-card.expanded .more-button svg {
  transform: scale(0.82);
}

.quantity-control {
  display: none;
  align-items: center;
  gap: 6px;
}

.active .quantity-control {
  display: flex;
}

.active .add-button {
  display: none;
}

.quantity-button {
  width: 26px;
  height: 26px;
  font-weight: 900;
}

.quantity-value {
  min-width: 15px;
  text-align: center;
  font-weight: 900;
}

.ingredients-panel {
  max-height: 0;
  padding: 0 12px;
  overflow: hidden;
  border-top: 0 solid rgba(125, 246, 255, 0.32);
  opacity: 0;
  transform: translateY(-8px);
  transition:
    max-height 360ms cubic-bezier(0.22, 1, 0.36, 1),
    padding 360ms cubic-bezier(0.22, 1, 0.36, 1),
    border-width 240ms ease,
    opacity 180ms ease,
    transform 300ms cubic-bezier(0.22, 1, 0.36, 1);
}

.recipe-card.expanded .ingredients-panel {
  max-height: var(--ingredients-height);
  padding: 13px 12px 15px;
  border-top-width: 1px;
  opacity: 1;
  transform: translateY(0);
}

.ingredients-inner {
  min-height: 0;
  overflow: hidden;
}

.ingredients-panel {
  visibility: hidden;
  transition:
    max-height 360ms cubic-bezier(0.22, 1, 0.36, 1),
    padding 360ms cubic-bezier(0.22, 1, 0.36, 1),
    border-width 240ms ease,
    opacity 180ms ease,
    transform 300ms cubic-bezier(0.22, 1, 0.36, 1),
    visibility 0s linear 360ms;
}

.recipe-card.expanded .ingredients-panel {
  visibility: visible;
  transition-delay: 0s;
}

.ingredients-label {
  margin-bottom: 10px;
  font-size: 0.65rem;
  font-weight: 800;
  letter-spacing: 0.12em;
  opacity: 0.7;
  text-transform: uppercase;
}

.ingredient-grid {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 10px 5px;
}

.ingredient {
  flex: 0 0 calc((100% - 10px) / 3);
  min-width: 0;
  text-align: center;
}

.ingredient-image {
  width: 42px;
  height: 42px;
  padding: 4px;
}

.ingredient-name {
  display: block;
  margin-top: 4px;
  overflow: hidden;
  font-size: 0.62rem;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.ingredient-amount {
  font-weight: 900;
}

.totals-drawer {
  position: fixed;
  z-index: 10;
  right: 0;
  bottom: 0;
  left: 0;
  width: min(100%, 460px);
  height: min(75vh, 620px);
  margin: auto;
  color: var(--paper);
  background: #12283e;
  border: 2px solid var(--cyan);
  border-bottom: 0;
  border-radius: 14px 14px 0 0;
  box-shadow: var(--shadow);
  transform: translateY(calc(100% - 72px));
  transition: transform 320ms cubic-bezier(0.22, 1, 0.36, 1);
}

.totals-drawer.open {
  transform: translateY(0);
}

.drawer-handle {
  width: 100%;
  min-height: 70px;
  padding: 10px 16px;
  gap: 13px;
  cursor: pointer;
  text-align: left;
  background: transparent;
  border: 0;
}

.drawer-handle strong,
.drawer-handle small {
  display: block;
}

.drawer-handle small {
  margin-top: 3px;
  color: var(--muted);
  font-size: 0.72rem;
}

.drawer-chevron {
  width: 11px;
  height: 11px;
  border-top: 2px solid var(--cyan);
  border-left: 2px solid var(--cyan);
  transform: rotate(45deg) translate(2px, 2px);
  transition: transform 260ms ease;
}

.open .drawer-chevron {
  transform: rotate(225deg) translate(-2px, -2px);
}

.total-badge {
  min-width: 30px;
  margin-left: auto;
  padding: 6px;
  color: var(--ink);
  background: var(--cyan);
  border-radius: 999px;
  text-align: center;
  font-weight: 900;
}

.drawer-content {
  height: calc(100% - 72px);
  padding: 8px 18px 24px;
  overflow-y: auto;
}

.drawer-heading {
  justify-content: space-between;
  padding-bottom: 14px;
  border-bottom: 1px solid rgba(125, 246, 255, 0.2);
}

.drawer-heading h2 {
  margin-bottom: 0;
  font-size: 1.45rem;
}

.clear-button {
  padding: 7px 10px;
  cursor: pointer;
  background: transparent;
  border: 1px solid rgba(125, 246, 255, 0.45);
  border-radius: 999px;
}

.clear-button:disabled {
  cursor: default;
  opacity: 0.35;
}

.totals-list {
  display: grid;
  gap: 9px;
  padding-top: 14px;
}

.total-row,
.empty-state {
  display: flex;
  align-items: center;
  padding: 10px;
  background: rgba(4, 24, 40, 0.55);
  border-radius: 10px;
}

.total-image {
  width: 44px;
  height: 44px;
  color: var(--cyan);
  padding: 4px;
}

.total-name {
  flex: 1;
  margin: 0 12px;
}

.total-quantity {
  color: var(--cyan-bright);
  font-size: 1.25rem;
  font-weight: 900;
}

.empty-state {
  min-height: 120px;
  justify-content: center;
  color: var(--muted);
  text-align: center;
}

.app-footer {
  display: flex;
  justify-content: center;
  gap: 8px;
  margin-top: 32px;
  color: var(--muted);
  font-size: 0.75rem;
}

.app-footer span + span::before {
  margin-right: 8px;
  color: var(--cyan);
  content: "•";
}

@media (min-width: 700px) {
  body {
    padding: 26px 0;
  }

  .app-shell {
    min-height: calc(100vh - 52px);
    border: 1px solid rgba(39, 217, 232, 0.25);
    border-radius: 24px;
  }

  .totals-drawer {
    bottom: 26px;
    border-bottom: 2px solid var(--cyan);
    border-radius: 14px;
  }
}

@media (min-width: 900px) {
  body {
    padding: 0;
  }

  .app-shell {
    width: 100%;
    max-width: none;
    min-height: 100vh;
    margin: 0;
    padding: 32px 492px 48px 32px;
    border: 0;
    border-radius: 0;
    box-shadow: none;
  }

  .app-header,
  .search-bar {
    max-width: 100%;
  }

  .recipe-list {
    grid-template-columns: repeat(auto-fit, minmax(360px, 1fr));
    align-items: start;
  }

  .recipe-card {
    width: 100%;
  }

  .totals-drawer {
    top: 0;
    right: 0;
    bottom: 0;
    left: auto;
    width: 460px;
    height: 100vh;
    margin: 0;
    border-top: 0;
    border-right: 0;
    border-bottom: 0;
    border-radius: 0;
    transform: none;
  }

  .totals-drawer.open {
    transform: none;
  }

  .drawer-handle {
    cursor: default;
  }

  .drawer-chevron {
    display: none;
  }

  .drawer-content {
    height: calc(100vh - 72px);
  }
}

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