:root {
  --bg-1: #f8e8cf;
  --bg-2: #f2c47a;
  --ink: #362113;
  --card: #fff9ef;
  --accent: #b84f2a;
  --accent-soft: #d87a57;
  --line: #6f4a2f;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  color: var(--ink);
  font-family: "IBM Plex Sans", sans-serif;
  background: radial-gradient(circle at 20% 20%, var(--bg-1), transparent 45%),
    radial-gradient(circle at 85% 10%, #ffe9bd, transparent 38%),
    linear-gradient(130deg, #f6d6a3 0%, var(--bg-2) 100%);
}

.kitchen-glow {
  position: fixed;
  inset: 0;
  pointer-events: none;
  background-image: repeating-linear-gradient(
    -45deg,
    rgba(255, 255, 255, 0.05),
    rgba(255, 255, 255, 0.05) 8px,
    rgba(255, 255, 255, 0.01) 8px,
    rgba(255, 255, 255, 0.01) 16px
  );
}

.game-wrap {
  width: min(980px, 94vw);
  margin: 2.2rem auto 2rem;
  display: grid;
  gap: 0.9rem;
}

h1, h2 {
  font-family: "Fraunces", serif;
  margin: 0;
}

.topbar {
  background: rgba(255, 249, 239, 0.78);
  border: 2px solid var(--line);
  border-radius: 14px;
  padding: 0.8rem 1rem;
  box-shadow: 0 8px 20px rgba(95, 63, 38, 0.18);
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 0.45rem 1rem;
  align-items: start;
}

.topbar-main {
  min-width: 0;
}

.subtitle {
  margin: 0.25rem 0 0;
  font-size: 0.95rem;
}

.ingredient-key {
  grid-column: 1 / -1;
  margin-top: 0.65rem;
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem 0.55rem;
}

.key-chip {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  border: 1px solid #9d7558;
  background: #fff;
  border-radius: 999px;
  padding: 0.2rem 0.45rem 0.2rem 0.25rem;
  font-size: 0.78rem;
}

.key-chip canvas {
  width: 18px;
  height: 18px;
  display: block;
}

.hud {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 0.6rem;
}

.pill {
  background: var(--card);
  border: 2px solid var(--line);
  border-radius: 999px;
  padding: 0.45rem 0.8rem;
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.pill span {
  opacity: 0.75;
  font-size: 0.88rem;
}

.recipe-panel,
.leaderboard {
  background: rgba(255, 249, 239, 0.84);
  border: 2px solid var(--line);
  border-radius: 14px;
  padding: 0.8rem;
}

.recipe-panel {
  background: rgba(255, 249, 239, 0.9);
  padding: 0.9rem 1rem;
}

.recipe-layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 0.85rem;
  align-items: start;
}

.recipe-main {
  min-width: 0;
  display: grid;
  gap: 0.5rem;
}

.recipe-main h2 {
  font-size: clamp(1.2rem, 2.2vw, 1.75rem);
  letter-spacing: 0.1px;
  line-height: 1.05;
}

.sound-bar {
  display: flex;
  justify-content: flex-end;
  align-items: center;
  gap: 0.55rem;
}

.vol-label {
  font-size: 0.88rem;
}

#volume-slider {
  width: 130px;
}

.hud.hud-compact {
  grid-template-columns: minmax(120px, 1fr) minmax(120px, 1fr);
  gap: 0.5rem;
  width: 360px;
  justify-self: end;
  align-self: center;
}

.hud.hud-compact .pill {
  padding: 0.36rem 0.62rem;
  border-width: 2px;
  background: rgba(255, 255, 255, 0.72);
  min-height: 44px;
}

.hud.hud-compact .pill span {
  font-size: 0.76rem;
  letter-spacing: 0;
}

.hud.hud-compact .pill strong {
  font-size: 1.05rem;
  font-family: "IBM Plex Sans", sans-serif;
  font-weight: 700;
  line-height: 1;
  text-align: right;
  max-width: 170px;
  overflow-wrap: anywhere;
  white-space: nowrap;
  font-variant-numeric: tabular-nums;
}

#score {
  white-space: nowrap;
}

.hud.hud-compact .pill.basin-pill {
  grid-column: 1;
}

.hud.hud-compact .pill.pill-score {
  grid-column: 1;
}

.hud.hud-compact .pill.pill-recipes {
  grid-column: 2;
}

.hud.hud-compact .pill.pill-lives {
  grid-column: 2;
}

.recipe-list {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
}

.recipe-chip {
  border: 1px solid #8a6346;
  border-radius: 999px;
  padding: 0.22rem 0.5rem 0.22rem 0.32rem;
  background: #fff;
  font-size: 0.72rem;
  display: inline-flex;
  align-items: center;
  gap: 0.3rem;
}

.recipe-chip canvas {
  width: 15px;
  height: 15px;
  display: block;
}

.controls {
  margin: 0.15rem 0 0;
  font-size: 0.82rem;
  color: #5a402c;
  opacity: 0.85;
}

kbd {
  border: 1px solid #9f7d64;
  border-radius: 4px;
  padding: 0.05rem 0.3rem;
  font-family: inherit;
}

.canvas-shell {
  position: relative;
  border: 3px solid var(--line);
  border-radius: 22px;
  overflow: hidden;
  background: linear-gradient(180deg, #fff5e3 0%, #f8dab0 100%);
}

.quit-btn {
  position: absolute;
  top: 8px;
  right: 10px;
  width: 32px;
  height: 32px;
  border-radius: 999px;
  border: 1px solid rgba(111, 74, 47, 0.45);
  background: rgba(255, 249, 239, 0.86);
  color: #5d3a24;
  font-weight: 700;
  font-size: 1.2rem;
  line-height: 1;
  cursor: pointer;
  z-index: 5;
}

.quit-btn:hover {
  background: rgba(255, 237, 223, 0.96);
}

canvas {
  display: block;
  width: 100%;
  height: auto;
}

.overlay {
  position: fixed;
  inset: 0;
  display: grid;
  place-items: center;
  background: rgba(39, 22, 8, 0.4);
  z-index: 20;
}

.overlay.hidden,
.toast.hidden {
  display: none;
}

.card {
  width: min(520px, 92vw);
  background: #fff9ef;
  border: 2px solid var(--line);
  border-radius: 16px;
  padding: 1rem;
  box-shadow: 0 14px 32px rgba(41, 23, 8, 0.28);
}

.name-row {
  margin: 0.8rem 0;
  display: grid;
  gap: 0.35rem;
}

input {
  border: 1px solid #9d7558;
  border-radius: 8px;
  padding: 0.5rem;
  font-size: 0.95rem;
}

.btn {
  border: none;
  background: var(--accent);
  color: #fff;
  font-weight: 700;
  padding: 0.55rem 0.95rem;
  border-radius: 8px;
  cursor: pointer;
}

.btn:hover {
  background: var(--accent-soft);
}

.btn.ghost {
  background: #fff;
  color: #5a371f;
  border: 1px solid #8e664a;
}

.leader-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 0.7rem;
}

table {
  width: 100%;
  border-collapse: collapse;
  margin-top: 0.6rem;
  font-size: 0.9rem;
}

th,
td {
  border-bottom: 1px dashed #b99578;
  padding: 0.45rem;
  text-align: left;
}

th:not(:last-child),
td:not(:last-child) {
  border-right: 1px dashed rgba(111, 74, 47, 0.35);
}

.toast {
  position: absolute;
  top: 14px;
  left: 50%;
  transform: translateX(-50%);
  background: #fff;
  border: 1px solid #8b6549;
  border-radius: 999px;
  padding: 0.45rem 0.85rem;
  font-weight: 700;
}

.canvas-copyright {
  position: absolute;
  right: 10px;
  bottom: 8px;
  margin: 0;
  font-size: 0.72rem;
  color: rgba(70, 45, 27, 0.8);
  background: rgba(255, 249, 239, 0.72);
  border: 1px solid rgba(111, 74, 47, 0.35);
  border-radius: 999px;
  padding: 0.15rem 0.45rem;
}

@media (max-width: 700px) {
  .topbar {
    grid-template-columns: 1fr;
  }

  .sound-bar {
    justify-content: flex-start;
    flex-wrap: wrap;
  }

  .recipe-layout {
    grid-template-columns: 1fr;
  }

  .hud.hud-compact {
    width: 100%;
    justify-self: stretch;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    align-self: stretch;
  }

  .recipe-main h2 {
    font-size: 1.35rem;
  }

  .recipe-chip {
    font-size: 0.72rem;
  }

  .hud {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  table {
    font-size: 0.8rem;
  }
}

@media (min-width: 1200px) {
  .game-wrap {
    width: min(1420px, 96vw);
    grid-template-columns: minmax(0, 1fr) 460px;
    gap: 1rem;
    align-items: start;
  }

  .topbar,
  .recipe-panel,
  .canvas-shell {
    grid-column: 1;
  }

  .leaderboard {
    grid-column: 2;
    grid-row: 1 / span 3;
    position: sticky;
    top: 1rem;
    max-height: calc(100vh - 2rem);
    display: grid;
    grid-template-rows: auto 1fr;
    overflow: hidden;
    padding-bottom: 0.55rem;
  }

  .leader-header {
    position: sticky;
    top: 0;
    z-index: 2;
    background: rgba(255, 249, 239, 0.95);
    padding-bottom: 0.45rem;
    margin-bottom: 0.2rem;
    border-bottom: 1px dashed rgba(111, 74, 47, 0.25);
  }

  .leaderboard table {
    margin-top: 0;
    width: 100%;
    table-layout: fixed;
  }

  .leaderboard thead {
    display: table;
    width: 100%;
    table-layout: fixed;
  }

  .leaderboard tbody {
    display: block;
    width: 100%;
    max-height: calc(100vh - 13rem);
    overflow-y: auto;
    overflow-x: hidden;
  }

  .leaderboard tbody tr {
    display: table;
    width: 100%;
    table-layout: fixed;
  }

  .leaderboard thead {
    position: sticky;
    top: 0;
    z-index: 1;
    background: rgba(255, 249, 239, 0.98);
  }

  .leaderboard th,
  .leaderboard td {
    padding: 0.42rem 0.35rem;
    vertical-align: middle;
    line-height: 1.2;
    overflow-wrap: break-word;
  }

  .leaderboard th {
    overflow-wrap: normal;
    word-break: keep-all;
  }

  .leaderboard th:nth-child(1),
  .leaderboard td:nth-child(1) {
    width: 11%;
  }

  .leaderboard th:nth-child(2),
  .leaderboard td:nth-child(2) {
    width: 18%;
  }

  .leaderboard th:nth-child(3),
  .leaderboard td:nth-child(3) {
    width: 18%;
  }

  .leaderboard th:nth-child(4),
  .leaderboard td:nth-child(4) {
    width: 15%;
  }

  .leaderboard th:nth-child(5),
  .leaderboard td:nth-child(5) {
    width: 19%;
  }

  .leaderboard th:nth-child(6),
  .leaderboard td:nth-child(6) {
    width: 19%;
    white-space: nowrap;
  }

  .leaderboard th:nth-child(3),
  .leaderboard td:nth-child(3),
  .leaderboard th:nth-child(4),
  .leaderboard td:nth-child(4),
  .leaderboard th:nth-child(6),
  .leaderboard td:nth-child(6) {
    text-align: right;
  }

  .leaderboard td:nth-child(3) {
    white-space: nowrap;
    overflow-wrap: normal;
    font-variant-numeric: tabular-nums;
  }
}
