:root {
  color-scheme: dark;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-right: env(safe-area-inset-right, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --safe-left: env(safe-area-inset-left, 0px);
  --panel: rgba(35, 24, 22, 0.72);
  --panel-strong: rgba(24, 18, 18, 0.9);
  --line: rgba(255, 232, 194, 0.22);
  --text: #fff6e9;
  --muted: #ddc6ae;
  --accent: #ffb14a;
  --accent-2: #8fe082;
  --danger: #ff6b5e;
  --shadow: 0 16px 38px rgba(0, 0, 0, 0.38);
  font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* {
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
}

html,
body {
  width: 100%;
  height: 100%;
  min-height: 100%;
  margin: 0;
  overflow: hidden;
  background: #180e11;
  color: var(--text);
  overscroll-behavior: none;
  touch-action: none;
}

body {
  position: fixed;
  inset: 0;
  user-select: none;
  -webkit-user-select: none;
}

button {
  font: inherit;
}

#app {
  position: fixed;
  inset: 0;
  width: 100vw;
  height: 100vh;
  height: 100dvh;
  overflow: hidden;
  background: #180e11;
  touch-action: none;
}

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

.hud {
  position: absolute;
  inset: 0;
  z-index: 3;
  pointer-events: none;
  padding: calc(10px + var(--safe-top)) calc(10px + var(--safe-right)) calc(12px + var(--safe-bottom)) calc(10px + var(--safe-left));
  display: grid;
  grid-template-rows: auto auto 1fr;
  gap: 10px;
}

.top-bar,
.meters,
.hint-bar,
.coach-overlay,
.small-screen-warning {
  pointer-events: auto;
}

.kebab-controls {
  position: absolute;
  inset: 0;
  z-index: 4;
  pointer-events: none;
}

.kebab-control {
  position: absolute;
  display: grid;
  grid-template-rows: 22px 42px 42px;
  grid-template-columns: 46px;
  align-items: center;
  justify-items: center;
  gap: 5px;
  width: 52px;
  min-height: 116px;
  transform: translate(-50%, -50%);
  padding: 3px;
  border: 1px solid rgba(255, 232, 188, 0.2);
  border-radius: 8px;
  background: rgba(28, 19, 18, 0.6);
  box-shadow: 0 8px 20px rgba(0, 0, 0, 0.26);
  backdrop-filter: blur(6px);
  pointer-events: auto;
}

.kebab-control.selected {
  border-color: rgba(255, 211, 105, 0.75);
  box-shadow: 0 0 0 1px rgba(255, 211, 105, 0.18), 0 8px 22px rgba(0, 0, 0, 0.34);
}

.kebab-control-label {
  display: grid;
  place-items: center;
  width: 24px;
  height: 22px;
  border-radius: 6px;
  background: rgba(0, 0, 0, 0.26);
  color: #ffe7b2;
  font-size: 0.82rem;
  font-weight: 900;
  line-height: 1;
}

.kebab-mini-button {
  width: 42px;
  height: 38px;
  display: grid;
  place-items: center;
  border: 1px solid rgba(255, 238, 202, 0.28);
  border-radius: 8px;
  color: #fff8eb;
  font-weight: 900;
  font-size: 1.18rem;
  line-height: 1;
  cursor: pointer;
  touch-action: none;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.12), 0 4px 10px rgba(0, 0, 0, 0.22);
}

.kebab-mini-button.flip {
  background: linear-gradient(180deg, #f1a34d, #a95028 62%, #74301f);
}

.kebab-mini-button.serve {
  background: linear-gradient(180deg, #78c66b, #368343 62%, #225b33);
}

.kebab-mini-button:active {
  transform: translateY(1px) scale(0.98);
}

.kebab-mini-button:disabled {
  opacity: 0.48;
  cursor: default;
  transform: none;
}

.kebab-controls[data-count="5"] .kebab-control,
.kebab-controls[data-count="6"] .kebab-control {
  grid-template-rows: 20px 34px 34px;
  grid-template-columns: 38px;
  gap: 4px;
  width: 42px;
  min-height: 96px;
  padding: 2px;
}

.kebab-controls[data-count="5"] .kebab-mini-button,
.kebab-controls[data-count="6"] .kebab-mini-button {
  width: 36px;
  height: 34px;
  font-size: 1rem;
}

.kebab-controls[data-count="5"] .kebab-control-label,
.kebab-controls[data-count="6"] .kebab-control-label {
  width: 22px;
  height: 30px;
}

.beer-button {
  --beer-fill: 0%;
  position: absolute;
  top: calc(74px + var(--safe-top));
  right: calc(10px + var(--safe-right));
  z-index: 5;
  width: 76px;
  min-height: 106px;
  display: grid;
  justify-items: center;
  gap: 4px;
  padding: 7px 6px;
  border: 1px solid rgba(255, 232, 188, 0.28);
  border-radius: 8px;
  color: #fff8eb;
  background: rgba(28, 19, 18, 0.68);
  box-shadow: 0 10px 22px rgba(0, 0, 0, 0.3), inset 0 1px 0 rgba(255, 255, 255, 0.12);
  backdrop-filter: blur(7px);
  cursor: pointer;
  pointer-events: auto;
  touch-action: none;
}

.beer-button[hidden],
.kebab-controls[hidden] {
  display: none;
}

.beer-button.ready {
  border-color: rgba(142, 224, 130, 0.75);
  box-shadow: 0 0 0 1px rgba(142, 224, 130, 0.22), 0 0 18px rgba(142, 224, 130, 0.2), 0 10px 22px rgba(0, 0, 0, 0.3);
}

.beer-button.active {
  border-color: rgba(180, 224, 255, 0.76);
  background: rgba(28, 39, 43, 0.74);
}

.beer-button:disabled {
  cursor: default;
}

.beer-bottle {
  position: relative;
  width: 46px;
  height: 78px;
  display: block;
  overflow: visible;
  filter: drop-shadow(0 7px 8px rgba(0, 0, 0, 0.34));
}

.beer-cap {
  position: absolute;
  left: 14px;
  top: 0;
  z-index: 4;
  width: 18px;
  height: 8px;
  border: 1px solid rgba(255, 249, 202, 0.54);
  border-radius: 4px 4px 2px 2px;
  background:
    repeating-linear-gradient(90deg, rgba(255, 255, 255, 0.28) 0 2px, rgba(99, 82, 58, 0.18) 2px 4px),
    linear-gradient(180deg, #e8d29a, #9b7a37 64%, #5f4c27);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.38);
}

.beer-neck {
  position: absolute;
  left: 16px;
  top: 7px;
  z-index: 3;
  width: 14px;
  height: 29px;
  border: 1px solid rgba(196, 242, 179, 0.42);
  border-bottom: 0;
  border-radius: 5px 5px 2px 2px;
  background:
    linear-gradient(90deg, rgba(255, 255, 255, 0.14), transparent 24% 68%, rgba(0, 0, 0, 0.22)),
    linear-gradient(180deg, rgba(64, 112, 50, 0.88), rgba(26, 64, 34, 0.96));
}

.beer-neck::after {
  content: "";
  position: absolute;
  left: 3px;
  top: 3px;
  width: 3px;
  height: 21px;
  border-radius: 3px;
  background: rgba(255, 255, 255, 0.22);
}

.beer-shoulder {
  position: absolute;
  left: 7px;
  top: 29px;
  z-index: 2;
  width: 32px;
  height: 21px;
  clip-path: polygon(28% 0, 72% 0, 100% 100%, 0 100%);
  border: 1px solid rgba(196, 242, 179, 0.38);
  border-bottom: 0;
  border-radius: 15px 15px 3px 3px;
  background:
    linear-gradient(90deg, rgba(255, 255, 255, 0.11), transparent 28% 72%, rgba(0, 0, 0, 0.24)),
    linear-gradient(180deg, rgba(54, 105, 45, 0.9), rgba(25, 68, 35, 0.97));
}

.beer-body {
  position: absolute;
  left: 5px;
  top: 42px;
  z-index: 1;
  width: 36px;
  height: 35px;
  overflow: hidden;
  border: 1px solid rgba(196, 242, 179, 0.42);
  border-radius: 8px 8px 11px 11px;
  background:
    radial-gradient(circle at 70% 20%, rgba(255, 237, 178, 0.13), transparent 30%),
    linear-gradient(90deg, rgba(255, 255, 255, 0.13), transparent 25% 70%, rgba(0, 0, 0, 0.28)),
    linear-gradient(180deg, rgba(43, 91, 40, 0.94), rgba(18, 52, 30, 0.98));
  box-shadow: inset 0 0 12px rgba(6, 24, 13, 0.48);
}

.beer-fill {
  position: absolute;
  left: 3px;
  right: 3px;
  bottom: 3px;
  z-index: 1;
  height: var(--beer-fill);
  max-height: calc(100% - 6px);
  border-radius: 4px 4px 8px 8px;
  background:
    radial-gradient(circle at 30% 18%, rgba(255, 255, 214, 0.56), transparent 16%),
    linear-gradient(180deg, #ffe681, #e2a12d 50%, #a96516);
  box-shadow: 0 0 10px rgba(255, 216, 91, 0.45);
  transition: height 120ms linear;
}

.beer-fill::before {
  content: "";
  position: absolute;
  left: 0;
  right: 0;
  top: -2px;
  height: 5px;
  border-radius: 50%;
  background: rgba(255, 238, 156, 0.86);
}

.beer-foam {
  position: absolute;
  left: 6px;
  right: 6px;
  bottom: calc(3px + var(--beer-fill));
  z-index: 2;
  height: 5px;
  border-radius: 999px;
  opacity: 0;
  background:
    radial-gradient(circle at 20% 58%, #fff9d6 0 3px, transparent 4px),
    radial-gradient(circle at 48% 42%, #fff4bd 0 3px, transparent 4px),
    radial-gradient(circle at 75% 60%, #fff8cf 0 2px, transparent 3px);
  transition: bottom 120ms linear, opacity 120ms linear;
}

.beer-button.ready .beer-foam,
.beer-button.active .beer-foam {
  opacity: 1;
}

.beer-label {
  position: absolute;
  left: 7px;
  right: 7px;
  bottom: 8px;
  z-index: 3;
  display: grid;
  place-items: center;
  height: 15px;
  border: 1px solid rgba(86, 55, 27, 0.36);
  border-radius: 4px;
  background: linear-gradient(180deg, #f8e8bb, #d7aa55);
  color: #5b321e;
  font-size: 0.48rem;
  font-weight: 900;
  line-height: 1;
  text-transform: uppercase;
}

.beer-highlight {
  position: absolute;
  left: 6px;
  top: 4px;
  z-index: 4;
  width: 5px;
  height: 26px;
  border-radius: 999px;
  background: linear-gradient(180deg, rgba(255, 255, 255, 0.34), rgba(255, 255, 255, 0.02));
  pointer-events: none;
}

.beer-button.active .beer-fill {
  background: linear-gradient(180deg, #d6f1ff, #94cbe5);
  box-shadow: 0 0 12px rgba(171, 225, 255, 0.5);
}

.beer-text {
  color: #ffe6ad;
  font-size: 0.72rem;
  font-weight: 800;
  line-height: 1;
  font-variant-numeric: tabular-nums;
}

.top-bar {
  justify-self: center;
  display: grid;
  grid-template-columns: repeat(3, minmax(74px, auto)) 48px;
  align-items: center;
  gap: 8px;
  max-width: min(680px, 100%);
  width: fit-content;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: var(--shadow);
  padding: 7px;
  backdrop-filter: blur(8px);
}

.stat {
  min-width: 74px;
  padding: 5px 8px;
  border-radius: 6px;
  background: rgba(255, 245, 224, 0.08);
  text-align: center;
}

.stat-label {
  display: block;
  color: var(--muted);
  font-size: clamp(0.68rem, 1.8vw, 0.78rem);
  line-height: 1.1;
}

.stat strong {
  display: block;
  font-size: clamp(1rem, 3vw, 1.28rem);
  line-height: 1.2;
}

.icon-button {
  width: 48px;
  height: 48px;
  border: 1px solid rgba(255, 235, 190, 0.28);
  border-radius: 8px;
  color: var(--text);
  background: linear-gradient(180deg, rgba(255, 210, 136, 0.18), rgba(70, 42, 34, 0.84));
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.12);
  cursor: pointer;
  touch-action: none;
}

.icon-button:active,
.overlay-button:active {
  transform: translateY(1px) scale(0.99);
}

.meters {
  justify-self: center;
  display: grid;
  grid-template-columns: repeat(2, minmax(140px, 240px));
  gap: 10px;
  max-width: min(560px, 100%);
  width: 100%;
}

.meter-card {
  position: relative;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 9px 10px;
  background: var(--panel);
  box-shadow: var(--shadow);
  backdrop-filter: blur(8px);
  transition: border-color 160ms ease, transform 160ms ease, box-shadow 160ms ease;
}

.meter-card.active {
  border-color: rgba(255, 179, 74, 0.78);
  box-shadow: 0 0 0 1px rgba(255, 179, 74, 0.16), var(--shadow);
}

.meter-card.danger {
  border-color: rgba(255, 95, 76, 0.85);
  animation: dangerPulse 700ms ease-in-out infinite alternate;
}

.meter-head {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 8px;
  font-size: clamp(0.85rem, 2.2vw, 1rem);
}

.meter-head span {
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}

.meter-track {
  position: relative;
  height: 16px;
  margin-top: 7px;
  overflow: hidden;
  border-radius: 5px;
  background: linear-gradient(90deg, #5a2631, #8d4428 36%, #4f3f20 65%, #521d1d 90%, #151211);
  border: 1px solid rgba(255, 240, 210, 0.16);
}

.meter-zone {
  position: absolute;
  top: 0;
  bottom: 0;
  left: var(--zone-left, 62%);
  width: var(--zone-width, 24%);
  background: linear-gradient(90deg, rgba(128, 226, 126, 0.34), rgba(255, 198, 71, 0.5));
  border-inline: 1px solid rgba(255, 255, 255, 0.5);
}

.meter-fill {
  position: absolute;
  inset: 0 auto 0 0;
  width: var(--meter-value, 0%);
  min-width: 0;
  border-radius: inherit;
  background: var(--fill-color, #f26b70);
  box-shadow: 0 0 14px var(--fill-glow, rgba(255, 130, 94, 0.38));
  transition: width 100ms linear, background 120ms linear;
}

.meter-caption {
  margin-top: 5px;
  color: var(--muted);
  font-size: clamp(0.74rem, 1.9vw, 0.84rem);
  min-height: 1.2em;
}

.hint-bar {
  align-self: end;
  justify-self: center;
  max-width: min(720px, calc(100vw - 24px));
  min-height: 42px;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 8px 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(34, 22, 20, 0.74);
  color: #fff5dc;
  box-shadow: var(--shadow);
  text-align: center;
  font-size: clamp(0.92rem, 2.5vw, 1.1rem);
  backdrop-filter: blur(8px);
}

.hint-bar.critical {
  border-color: rgba(255, 96, 76, 0.78);
  background: rgba(77, 24, 22, 0.82);
}

.overlay-button {
  min-height: 54px;
  border: 1px solid rgba(255, 238, 202, 0.28);
  border-radius: 8px;
  color: #fff8eb;
  box-shadow: 0 10px 20px rgba(0, 0, 0, 0.3), inset 0 1px 0 rgba(255, 255, 255, 0.15);
  cursor: pointer;
  touch-action: none;
}

.icon-button:disabled,
.overlay-button:disabled {
  opacity: 0.46;
  cursor: default;
  transform: none;
}

.overlay {
  position: absolute;
  inset: 0;
  z-index: 8;
  display: grid;
  place-items: center;
  padding: calc(18px + var(--safe-top)) calc(16px + var(--safe-right)) calc(18px + var(--safe-bottom)) calc(16px + var(--safe-left));
  background: radial-gradient(circle at 50% 44%, rgba(104, 57, 36, 0.36), rgba(11, 8, 10, 0.72) 72%);
  pointer-events: auto;
}

.overlay.hidden {
  display: none;
}

.panel {
  width: min(560px, 100%);
  max-height: min(720px, calc(100dvh - 36px - var(--safe-top) - var(--safe-bottom)));
  overflow: auto;
  border: 1px solid rgba(255, 226, 179, 0.26);
  border-radius: 8px;
  background: linear-gradient(180deg, rgba(45, 29, 24, 0.94), rgba(22, 15, 15, 0.96));
  box-shadow: 0 28px 70px rgba(0, 0, 0, 0.55);
  padding: clamp(18px, 4vw, 28px);
}

.panel h1,
.panel h2 {
  margin: 0 0 10px;
  letter-spacing: 0;
  line-height: 1;
}

.panel h1 {
  font-size: clamp(2.1rem, 9vw, 4rem);
  color: #ffd188;
  text-shadow: 0 4px 22px rgba(255, 139, 63, 0.22);
}

.panel h2 {
  font-size: clamp(1.55rem, 5vw, 2.35rem);
}

.panel p {
  margin: 8px 0;
  color: #f5dfc5;
  line-height: 1.45;
}

.panel .lead {
  font-size: clamp(1rem, 2.5vw, 1.16rem);
  color: #ffe6be;
}

.panel-grid {
  display: grid;
  gap: 10px;
  margin: 16px 0 0;
}

.overlay-button {
  width: 100%;
  min-height: 52px;
  padding: 11px 14px;
  font-weight: 800;
  background: linear-gradient(180deg, rgba(255, 194, 100, 0.96), rgba(158, 80, 38, 0.98));
}

.overlay-button.secondary {
  background: linear-gradient(180deg, rgba(91, 72, 63, 0.94), rgba(42, 31, 29, 0.96));
}

.overlay-button.good {
  background: linear-gradient(180deg, rgba(132, 212, 109, 0.94), rgba(45, 121, 59, 0.96));
}

.facts {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
  margin: 14px 0;
}

.fact {
  border: 1px solid rgba(255, 231, 194, 0.16);
  border-radius: 8px;
  padding: 10px;
  background: rgba(255, 245, 220, 0.07);
}

.fact span {
  display: block;
  color: var(--muted);
  font-size: 0.8rem;
}

.fact strong {
  display: block;
  margin-top: 2px;
  font-size: 1.2rem;
}

.tutorial-list {
  display: grid;
  gap: 9px;
  margin: 14px 0;
  padding: 0;
  list-style: none;
}

.tutorial-list li {
  display: grid;
  grid-template-columns: 18px 1fr;
  gap: 9px;
  align-items: start;
  color: #f8e4c9;
}

.swatch {
  width: 18px;
  height: 18px;
  margin-top: 2px;
  border-radius: 4px;
  border: 1px solid rgba(255, 255, 255, 0.3);
}

.swatch.raw { background: #ec6d76; }
.swatch.cook { background: #ec9142; }
.swatch.perfect { background: linear-gradient(90deg, #86dc73, #f0bf45); }
.swatch.danger { background: #d83c31; }
.swatch.burn { background: #161413; }

.result-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px;
  margin: 14px 0;
}

.coach-overlay {
  position: absolute;
  left: max(12px, var(--safe-left));
  right: max(12px, var(--safe-right));
  bottom: calc(88px + var(--safe-bottom));
  z-index: 5;
  margin: auto;
  max-width: 520px;
  border: 1px solid rgba(255, 216, 142, 0.72);
  border-radius: 8px;
  background: rgba(38, 25, 20, 0.9);
  box-shadow: 0 0 0 9999px rgba(0, 0, 0, 0.12), 0 12px 28px rgba(0, 0, 0, 0.34);
  padding: 10px 12px;
  color: #fff2d6;
  text-align: center;
  font-size: clamp(0.88rem, 2.5vw, 1rem);
}

.coach-highlight {
  outline: 3px solid rgba(255, 214, 114, 0.95);
  outline-offset: 3px;
  animation: coachPulse 900ms ease-in-out infinite alternate;
}

.small-screen-warning {
  position: absolute;
  left: max(8px, var(--safe-left));
  right: max(8px, var(--safe-right));
  top: calc(74px + var(--safe-top));
  z-index: 4;
  display: none;
  padding: 7px 10px;
  border: 1px solid rgba(255, 205, 105, 0.5);
  border-radius: 8px;
  background: rgba(47, 29, 22, 0.82);
  color: #ffe2a8;
  text-align: center;
  font-size: 0.78rem;
}

@media (max-width: 520px) {
  .hud {
    gap: 8px;
    padding-inline: calc(8px + var(--safe-left)) calc(8px + var(--safe-right));
  }

  .top-bar {
    grid-template-columns: repeat(3, minmax(62px, auto)) 48px;
    gap: 6px;
    padding: 6px;
    width: 100%;
  }

  .stat {
    min-width: 0;
    padding-inline: 6px;
  }

  .meters {
    grid-template-columns: 1fr;
    gap: 7px;
  }

}

@media (orientation: landscape) and (max-height: 560px) {
  .hud {
    grid-template-columns: minmax(230px, 320px) 1fr;
    grid-template-rows: auto 1fr auto;
    align-items: start;
    gap: 8px;
  }

  .top-bar {
    grid-column: 1 / 3;
  }

  .meters {
    grid-column: 1;
    grid-row: 2 / 4;
    grid-template-columns: 1fr;
    justify-self: start;
    align-self: end;
  }

  .hint-bar {
    grid-column: 2;
    grid-row: 3;
    align-self: end;
  }

  .coach-overlay {
    left: 50%;
    right: max(12px, var(--safe-right));
    bottom: calc(78px + var(--safe-bottom));
  }
}

@media (max-height: 470px), (max-width: 350px) {
  .small-screen-warning {
    display: block;
  }
}

@keyframes dangerPulse {
  from { box-shadow: 0 0 0 1px rgba(255, 95, 76, 0.18), var(--shadow); }
  to { box-shadow: 0 0 0 3px rgba(255, 95, 76, 0.34), 0 0 20px rgba(255, 68, 48, 0.24), var(--shadow); }
}

@keyframes coachPulse {
  from { filter: brightness(1); }
  to { filter: brightness(1.18); }
}
