*,
*::before,
*::after {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  font-family: "Segoe UI", "Hiragino Sans", "Yu Gothic UI", sans-serif;
  background: linear-gradient(160deg, #1a1208 0%, #2d1f0f 45%, #1a1208 100%);
  color: #f5e6d3;
}

.app {
  max-width: 1100px;
  margin: 0 auto;
  padding: 0.75rem;
  padding-bottom: 1rem;
}

.header {
  text-align: center;
  margin-bottom: 0.75rem;
}

.header h1 {
  margin: 0;
  font-size: 1.5rem;
  letter-spacing: 0.06em;
}

.subtitle {
  margin: 0.2rem 0 0;
  opacity: 0.75;
  font-size: 0.85rem;
}

.badge {
  font-size: 0.72rem;
  font-weight: normal;
  background: rgba(255, 183, 77, 0.2);
  color: #ffcc80;
  padding: 0.15rem 0.45rem;
  border-radius: 999px;
  margin-left: 0.25rem;
}

.count-badge {
  font-weight: bold;
}

.game-layout {
  display: grid;
  grid-template-columns: 0.9fr 1.5fr 0.85fr;
  gap: 0.75rem;
  align-items: start;
}

.panel {
  background: rgba(0, 0, 0, 0.35);
  border: 1px solid rgba(255, 200, 120, 0.2);
  border-radius: 12px;
  padding: 0.75rem;
  min-height: 300px;
}

.panel h2 {
  margin: 0 0 0.35rem;
  font-size: 0.95rem;
  color: #ffcc80;
}

.hint {
  margin: 0 0 0.5rem;
  font-size: 0.75rem;
  opacity: 0.65;
}

.meat-tray {
  display: flex;
  flex-direction: column;
  gap: 0.45rem;
}

.meat-option {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.45rem 0.55rem;
  border: 2px solid rgba(255, 200, 120, 0.25);
  border-radius: 10px;
  background: rgba(255, 255, 255, 0.05);
  color: inherit;
  cursor: pointer;
  transition: border-color 0.15s, transform 0.1s;
  font-size: 0.85rem;
}

.meat-preview {
  width: 36px;
  height: 24px;
  background: var(--meat-color, #c44d4d);
  border-radius: 40% 60% 50% 50%;
  box-shadow: inset 0 -2px 0 rgba(0, 0, 0, 0.25);
  flex-shrink: 0;
}

.meat-preview.shape-round {
  width: 28px;
  height: 28px;
  border-radius: 50%;
}

.meat-preview.shape-rect {
  border-radius: 5px;
  height: 22px;
}

.meat-preview.shape-blob {
  border-radius: 60% 40% 55% 45%;
}

.meat-option.selected {
  border-color: #ffb74d;
  box-shadow: 0 0 0 2px rgba(255, 183, 77, 0.35);
}

.meat-option:active:not(:disabled) {
  transform: scale(0.98);
}

.meat-option:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

.grill-panel {
  perspective: 900px;
}

.grill {
  position: relative;
  width: 100%;
  aspect-ratio: 4 / 3;
  transform-style: preserve-3d;
  transform: rotateX(16deg);
  outline: none;
}

.grill:focus-visible {
  box-shadow: 0 0 0 3px rgba(255, 183, 77, 0.6);
  border-radius: 8px;
}

.grill-surface {
  position: absolute;
  inset: 0;
  border-radius: 12px;
  background:
    repeating-linear-gradient(90deg, #444 0 8px, #222 8px 16px),
    repeating-linear-gradient(0deg, #444 0 8px, #333 8px 16px);
  box-shadow:
    0 16px 28px rgba(0, 0, 0, 0.55),
    inset 0 0 40px rgba(255, 120, 40, 0.15);
  border: 3px solid #5a4030;
  overflow: visible;
  cursor: pointer;
}

.grill-surface::after {
  content: "";
  position: absolute;
  inset: 0;
  background: radial-gradient(ellipse at center 70%, rgba(255, 100, 30, 0.22), transparent 65%);
  pointer-events: none;
}

.grill-meats {
  position: absolute;
  inset: 0;
  pointer-events: none;
  z-index: 5;
}

.grill-meat-piece {
  position: absolute;
  width: 76px;
  height: 56px;
  transform: translate(-50%, -50%);
  padding: 0;
  border: none;
  background: transparent;
  cursor: grab;
  pointer-events: auto;
  transition: transform 0.15s, filter 0.2s, opacity 0.15s, box-shadow 0.15s;
  touch-action: none;
  user-select: none;
}

.grill-meat-piece::before {
  content: "";
  position: absolute;
  inset: -14px;
  border-radius: 12px;
  pointer-events: auto;
}

.grill-meat-piece:hover,
.grill-meat-piece.touch-active {
  transform: translate(-50%, -50%) scale(1.1);
  filter: drop-shadow(0 6px 10px rgba(0, 0, 0, 0.55));
}

.grill-meat-piece.focused {
  transform: translate(-50%, -50%) scale(1.12);
  filter: drop-shadow(0 0 8px rgba(255, 183, 77, 0.85));
  box-shadow: 0 0 0 2px rgba(255, 183, 77, 0.55);
  border-radius: 8px;
}

.grill-meat-piece.face-down {
  transform: translate(-50%, -50%) scaleY(0.88);
  filter: brightness(0.9);
}

.grill-meat-piece.face-down:hover,
.grill-meat-piece.face-down.touch-active {
  transform: translate(-50%, -50%) scaleY(0.88) scale(1.08);
}

.grill-meat-piece.focused.face-down {
  transform: translate(-50%, -50%) scaleY(0.88) scale(1.1);
}

.grill-meat-piece.face-down::after {
  content: "";
  position: absolute;
  inset: 0;
  border-radius: inherit;
  box-shadow: inset 0 0 8px rgba(255, 255, 255, 0.15);
  pointer-events: none;
}

.grill-meat-piece.dragging-source {
  opacity: 0.3;
}

.grill-meat-piece.shape-round {
  width: 58px;
  height: 58px;
}

.grill-meat-piece.shape-rect {
  width: 68px;
  height: 46px;
}

.grill-meat-piece.shape-blob {
  width: 64px;
  height: 50px;
}

.grill-meat-piece .meat-svg {
  width: 100%;
  height: 100%;
  display: block;
  filter: drop-shadow(0 4px 6px rgba(0, 0, 0, 0.45));
}

.grill-meat-piece.level-burnt .meat-svg {
  filter: drop-shadow(0 2px 4px rgba(0, 0, 0, 0.6)) brightness(0.85);
}

.meat-smoke {
  position: absolute;
  top: -20px;
  left: 50%;
  width: 20px;
  height: 30px;
  transform: translateX(-50%);
  pointer-events: none;
}

.meat-smoke::before,
.meat-smoke::after {
  content: "";
  position: absolute;
  bottom: 0;
  width: 12px;
  height: 12px;
  background: rgba(180, 180, 180, 0.5);
  border-radius: 50%;
  animation: smoke-rise 1.6s ease-out infinite;
}

.meat-smoke::after {
  right: 0;
  animation-delay: 0.5s;
}

.meat-sizzle {
  position: absolute;
  bottom: -4px;
  left: 50%;
  width: 40px;
  height: 16px;
  transform: translateX(-50%);
  pointer-events: none;
  opacity: 0.7;
}

.meat-sizzle::before,
.meat-sizzle::after {
  content: "";
  position: absolute;
  bottom: 0;
  width: 6px;
  height: 6px;
  background: rgba(255, 220, 180, 0.6);
  border-radius: 50%;
  animation: sizzle-pop 0.8s ease-in-out infinite;
}

.meat-sizzle::after {
  left: 60%;
  animation-delay: 0.35s;
}

@keyframes sizzle-pop {
  0%, 100% { opacity: 0.3; transform: translateY(0) scale(0.8); }
  50% { opacity: 0.9; transform: translateY(-6px) scale(1.1); }
}

.grill-meat-piece.grill-hint {
  filter: drop-shadow(0 2px 6px rgba(255, 120, 40, 0.35));
}

@keyframes smoke-rise {
  0% {
    opacity: 0.7;
    transform: translateY(0) scale(0.5);
  }
  100% {
    opacity: 0;
    transform: translateY(-40px) scale(1.2);
  }
}

.grill-popup {
  position: absolute;
  left: 50%;
  top: 42%;
  transform: translate(-50%, -50%);
  padding: 0;
  border: none;
  background: none;
  font-size: 1.35rem;
  font-weight: 800;
  white-space: nowrap;
  pointer-events: none;
  z-index: 10;
  opacity: 0;
  color: #fff;
  text-shadow:
    0 0 12px rgba(255, 120, 40, 0.9),
    0 2px 6px rgba(0, 0, 0, 0.95),
    0 0 24px rgba(255, 200, 100, 0.5);
}

.grill-popup.show.fade-out {
  animation: reaction-fade 2.6s ease forwards;
}

@keyframes reaction-fade {
  0% {
    opacity: 0;
    transform: translate(-50%, -50%) scale(0.85);
  }
  12% {
    opacity: 1;
    transform: translate(-50%, -50%) scale(1.05);
  }
  25% {
    transform: translate(-50%, -50%) scale(1);
  }
  55% {
    opacity: 1;
  }
  100% {
    opacity: 0;
    transform: translate(-50%, -58%) scale(0.95);
  }
}

.grill.smoking .grill-surface {
  box-shadow:
    0 16px 28px rgba(0, 0, 0, 0.55),
    inset 0 0 50px rgba(255, 60, 20, 0.22);
}

.reaction-box {
  background: rgba(255, 255, 255, 0.06);
  border-radius: 8px;
  padding: 0.5rem 0.65rem;
  margin-bottom: 0.5rem;
}

.reaction-label {
  margin: 0 0 0.15rem;
  font-size: 0.7rem;
  opacity: 0.6;
}

.reaction {
  margin: 0;
  font-size: 0.95rem;
  font-weight: 600;
}

.history-list {
  list-style: none;
  margin: 0;
  padding: 0;
  font-size: 0.78rem;
  max-height: 140px;
  overflow-y: auto;
}

.history-list li {
  padding: 0.25rem 0;
  border-bottom: 1px solid rgba(255, 255, 255, 0.08);
}

.session-message {
  margin-top: 0.5rem;
  padding: 0.5rem;
  background: rgba(255, 183, 77, 0.15);
  border-radius: 8px;
  color: #ffcc80;
  font-weight: 600;
  font-size: 0.85rem;
}

.controls {
  display: flex;
  justify-content: center;
  gap: 0.75rem;
  margin-top: 0.75rem;
  pointer-events: none;
}

.controls > * {
  pointer-events: auto;
}

.controls button {
  min-width: 110px;
  padding: 0.65rem 1.25rem;
  font-size: 0.95rem;
  border: none;
  border-radius: 999px;
  cursor: pointer;
  background: linear-gradient(180deg, #ff8a50, #e65100);
  color: #fff;
  font-weight: 600;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.35);
}

.controls button:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

#reset-btn {
  background: linear-gradient(180deg, #78909c, #455a64);
}

.sauce-plate {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-width: 100px;
  min-height: 80px;
  padding: 0.5rem 1rem;
  border-radius: 50%;
  background: radial-gradient(circle at 40% 30%, #f5ecd8, #d4b880 50%, #a08050);
  border: 3px solid #8a6830;
  box-shadow:
    0 4px 12px rgba(0, 0, 0, 0.4),
    inset 0 3px 8px rgba(255, 255, 255, 0.45);
  cursor: default;
  transition: box-shadow 0.2s, transform 0.2s;
  overflow: hidden;
}

.sauce-liquid {
  position: absolute;
  inset: 12%;
  border-radius: 50%;
  overflow: hidden;
  pointer-events: none;
}

.sauce-svg {
  width: 100%;
  height: 100%;
  display: block;
}

.sauce-plate.glow,
.sauce-plate.near-drop {
  box-shadow:
    0 0 20px rgba(255, 180, 60, 0.85),
    0 4px 12px rgba(0, 0, 0, 0.4),
    inset 0 2px 10px rgba(255, 255, 255, 0.55);
  transform: scale(1.08);
}

.sauce-plate.near-drop .sauce-liquid {
  animation: tare-ripple 0.6s ease infinite;
}

@keyframes tare-ripple {
  0%, 100% { transform: scale(1); }
  50% { transform: scale(1.04); }
}

.sauce-label {
  position: relative;
  z-index: 1;
  font-size: 0.85rem;
  font-weight: 700;
  color: #4a3010;
  text-shadow: 0 1px 0 rgba(255, 255, 255, 0.4);
}

.sauce-hint {
  position: relative;
  z-index: 1;
  font-size: 0.62rem;
  color: #5a4020;
  opacity: 0.9;
}

.drag-ghost {
  position: fixed;
  width: 80px;
  height: 58px;
  transform: translate(-50%, -50%);
  pointer-events: none;
  z-index: 1000;
  filter: drop-shadow(0 12px 16px rgba(0, 0, 0, 0.55));
  scale: 1.12;
}

.drag-ghost .meat-svg {
  width: 100%;
  height: 100%;
}

@media (max-width: 768px) {
  .app {
    padding: 0.4rem;
    padding-bottom: 4.5rem;
  }

  .header h1 {
    font-size: 1.15rem;
  }

  .subtitle {
    font-size: 0.75rem;
  }

  .game-layout {
    grid-template-columns: 1fr;
    gap: 0.5rem;
  }

  .panel {
    min-height: auto;
    padding: 0.55rem;
  }

  .grill-panel {
    order: -2;
  }

  .tray-panel {
    order: -1;
  }

  .grill {
    transform: rotateX(10deg);
    aspect-ratio: 16 / 11;
  }

  .grill-meat-piece {
    width: 56px;
    height: 42px;
  }

  .grill-meat-piece.shape-round {
    width: 46px;
    height: 46px;
  }

  .meat-tray {
    flex-direction: row;
    overflow-x: auto;
    gap: 0.35rem;
    padding-bottom: 0.25rem;
    -webkit-overflow-scrolling: touch;
  }

  .meat-option {
    flex: 0 0 auto;
    min-width: 88px;
    flex-direction: column;
    text-align: center;
    padding: 0.4rem;
    font-size: 0.75rem;
  }

  .side-panel {
    max-height: none;
  }

  .history-list {
    max-height: 72px;
  }

  .reaction-box {
    padding: 0.4rem;
  }

  .reaction {
    font-size: 0.85rem;
  }

  .grill-popup {
    font-size: 1.1rem;
    top: 40%;
    max-width: 90%;
    white-space: normal;
    text-align: center;
  }

  .sauce-plate {
    flex: 1;
    min-width: 0;
    min-height: 56px;
    border-radius: 999px;
    flex-direction: row;
    gap: 0.35rem;
    padding: 0.5rem 0.75rem;
  }

  .controls {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    margin: 0;
    padding: 0.5rem 0.75rem;
    padding-bottom: max(0.5rem, env(safe-area-inset-bottom));
    background: rgba(26, 18, 8, 0.96);
    border-top: 1px solid rgba(255, 200, 120, 0.15);
    z-index: 100;
    gap: 0.5rem;
    pointer-events: none;
  }

  .controls > * {
    pointer-events: auto;
  }

  .grill-panel {
    margin-bottom: 0.25rem;
  }

  .controls button {
    flex: 1;
    min-width: 0;
    padding: 0.75rem;
    font-size: 0.9rem;
  }
}
