:root {
  --bg-a: #f9efe0;
  --bg-b: #f6d4a9;
  --ink: #25211d;
  --accent: #f46f2f;
  --accent-2: #0f766e;
  --surface: #fff9ef;
  --danger: #a11a0e;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  font-family: "Avenir Next", "Gill Sans", "Trebuchet MS", sans-serif;
  color: var(--ink);
  background:
    radial-gradient(circle at 10% 20%, rgba(244, 111, 47, 0.22), transparent 40%),
    radial-gradient(circle at 90% 85%, rgba(15, 118, 110, 0.2), transparent 35%),
    linear-gradient(140deg, var(--bg-a), var(--bg-b));
}

.app-shell {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 1.5rem;
}

.panel {
  width: min(720px, 100%);
  background: var(--surface);
  border: 2px solid rgba(37, 33, 29, 0.12);
  border-radius: 20px;
  padding: 1.5rem;
  box-shadow: 0 20px 40px rgba(37, 33, 29, 0.14);
  animation: slide-up 500ms ease;
}

.panel-start,
.panel-end {
  text-align: center;
}

.eyebrow {
  letter-spacing: 0.12em;
  text-transform: uppercase;
  font-size: 0.75rem;
  font-weight: 700;
  color: rgba(37, 33, 29, 0.75);
}

h1,
h2 {
  margin: 0.2rem 0 0.8rem;
  font-family: "Baskerville", "Times New Roman", serif;
}

h1 {
  font-size: clamp(2.1rem, 6vw, 3.4rem);
}

h2 {
  font-size: clamp(1.4rem, 4vw, 2rem);
}

p {
  line-height: 1.5;
}

.game-header {
  display: flex;
  justify-content: space-between;
  gap: 1rem;
  align-items: flex-end;
  margin-bottom: 1rem;
}

.timer {
  margin: 0.1rem 0 0;
  font-size: clamp(2rem, 7vw, 3.3rem);
  font-weight: 800;
  color: var(--accent);
}

.pill {
  background: rgba(15, 118, 110, 0.12);
  color: var(--accent-2);
  border: 1px solid rgba(15, 118, 110, 0.35);
  border-radius: 999px;
  padding: 0.45rem 0.9rem;
  font-size: 0.95rem;
  font-weight: 600;
}

.card {
  border: 1px solid rgba(37, 33, 29, 0.16);
  border-radius: 14px;
  padding: 1rem;
  background: #ffffff;
}

.label {
  display: block;
  margin-top: 1rem;
  margin-bottom: 0.35rem;
  font-weight: 600;
}

.input {
  width: 100%;
  border-radius: 10px;
  border: 1px solid rgba(37, 33, 29, 0.3);
  font-size: 1rem;
  padding: 0.7rem 0.9rem;
}

.coordinate-grid {
  margin-top: 1rem;
  display: grid;
  gap: 0.5rem;
}

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

.grid-row-header .grid-corner {
  min-height: 2.4rem;
}

.grid-corner,
.grid-axis,
.grid-cell {
  min-height: 2.6rem;
  border-radius: 10px;
  display: grid;
  place-items: center;
}

.grid-corner {
  background: transparent;
}

.grid-axis {
  background: rgba(15, 118, 110, 0.12);
  color: var(--accent-2);
  font-weight: 800;
}

.grid-axis-column {
  font-size: 0.95rem;
}

.grid-cell {
  border: 1px solid rgba(37, 33, 29, 0.18);
  background: #fffdf8;
  color: var(--ink);
  font: inherit;
  font-weight: 800;
  cursor: pointer;
  transition: transform 160ms ease, box-shadow 160ms ease, background-color 160ms ease, color 160ms ease;
}

.grid-cell:hover {
  transform: translateY(-1px);
  box-shadow: 0 8px 18px rgba(37, 33, 29, 0.12);
}

.grid-cell.is-selected {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff8ef;
}

.grid-selection {
  margin: 0.8rem 0 0;
  font-weight: 700;
  color: var(--accent-2);
}

.alchemy-stage {
  margin-top: 1rem;
}

.alchemy-layout {
  display: grid;
  grid-template-columns: minmax(86px, 1fr) minmax(180px, 240px) minmax(86px, 1fr);
  grid-template-rows: auto auto auto;
  gap: 0.9rem 1rem;
  align-items: center;
}

.alchemy-tube-slot {
  display: flex;
  justify-content: center;
}

.alchemy-top {
  grid-column: 2;
  grid-row: 1;
}

.alchemy-left {
  grid-column: 1;
  grid-row: 2;
  justify-self: end;
}

.alchemy-right {
  grid-column: 3;
  grid-row: 2;
  justify-self: start;
}

.alchemy-bottom {
  grid-column: 2;
  grid-row: 3;
}

.alchemy-bottle-frame {
  grid-column: 2;
  grid-row: 2;
  position: relative;
  width: min(240px, 100%);
  margin: 0 auto;
}

.alchemy-bottle-glow {
  position: absolute;
  inset: 12% 18% 8%;
  border-radius: 48% 48% 34% 34%;
  background: radial-gradient(circle, rgba(244, 111, 47, 0.3), transparent 68%);
  filter: blur(18px);
}

.alchemy-bottle {
  position: relative;
  z-index: 1;
  display: grid;
  justify-items: center;
  gap: 0.35rem;
}

.alchemy-bottle-neck {
  width: 3.2rem;
  height: 4rem;
  border-radius: 1rem 1rem 0.9rem 0.9rem;
  border: 2px solid rgba(37, 33, 29, 0.3);
  background: linear-gradient(180deg, rgba(255, 255, 255, 0.55), rgba(255, 249, 239, 0.8));
  box-shadow: inset 0 -6px 14px rgba(37, 33, 29, 0.08);
}

.alchemy-bottle-body {
  position: relative;
  width: 100%;
  aspect-ratio: 3 / 4;
  border-radius: 38% 38% 26% 26% / 28% 28% 20% 20%;
  border: 2px solid rgba(37, 33, 29, 0.3);
  background: linear-gradient(180deg, rgba(255, 255, 255, 0.92), rgba(255, 249, 239, 0.75));
  overflow: hidden;
  box-shadow: inset 0 -16px 24px rgba(37, 33, 29, 0.05);
}

.alchemy-bottle-body::before {
  content: "";
  position: absolute;
  inset: 7% 12% 5% 12%;
  border-radius: 36% 36% 24% 24% / 28% 28% 18% 18%;
  border: 1px solid rgba(37, 33, 29, 0.08);
  pointer-events: none;
}

.alchemy-liquid-stack {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column-reverse;
  overflow: hidden;
}

.alchemy-liquid-layer {
  position: relative;
  width: 100%;
  min-height: 22%;
  box-shadow: inset 0 10px 12px rgba(255, 255, 255, 0.2);
}

.alchemy-liquid-layer::after {
  content: "";
  position: absolute;
  inset: 0;
  background: linear-gradient(180deg, rgba(255, 255, 255, 0.18), transparent 35%);
}

.alchemy-liquid-layer-amber {
  background: linear-gradient(180deg, #ffd36c, #e6a117);
}

.alchemy-liquid-layer-emerald {
  background: linear-gradient(180deg, #7edcb5, #2f9e6b);
}

.alchemy-liquid-layer-violet {
  background: linear-gradient(180deg, #bba0ff, #7a4bd6);
}

.alchemy-liquid-layer-crimson {
  background: linear-gradient(180deg, #ff8f8f, #d64545);
}

.alchemy-progress {
  margin: 0.8rem 0 0;
  font-weight: 700;
  color: var(--accent-2);
}

.alchemy-tube {
  position: relative;
  width: 5.3rem;
  height: 10rem;
  border: 2px solid rgba(37, 33, 29, 0.3);
  border-radius: 1.5rem 1.5rem 1rem 1rem;
  background: linear-gradient(180deg, rgba(255, 255, 255, 0.82), rgba(255, 249, 239, 0.94));
  padding: 0.5rem 0.3rem 0.4rem;
  cursor: pointer;
  display: grid;
  grid-template-rows: 1fr auto auto;
  align-items: end;
  gap: 0.35rem;
  box-shadow: 0 10px 18px rgba(37, 33, 29, 0.11);
  transition: transform 160ms ease, box-shadow 160ms ease, opacity 160ms ease;
}

.alchemy-tube::before {
  content: "";
  position: absolute;
  inset: 0.45rem 0.45rem 1.6rem;
  border-radius: 1rem 1rem 0.75rem 0.75rem;
  background: linear-gradient(180deg, rgba(255, 255, 255, 0.22), transparent 45%);
  pointer-events: none;
}

.alchemy-tube:hover {
  transform: translateY(-2px) rotate(-1deg);
  box-shadow: 0 14px 24px rgba(37, 33, 29, 0.15);
}

.alchemy-tube.is-used {
  opacity: 0.55;
  filter: saturate(0.82);
}

.alchemy-liquid {
  display: block;
  width: 100%;
  height: 5.3rem;
  border-radius: 0.95rem 0.95rem 0.5rem 0.5rem;
  box-shadow: inset 0 10px 18px rgba(255, 255, 255, 0.18);
}

.alchemy-liquid::after {
  content: "";
  display: block;
  width: 100%;
  height: 100%;
  border-radius: inherit;
  background: linear-gradient(180deg, rgba(255, 255, 255, 0.22), transparent 40%);
}

.alchemy-tube-amber .alchemy-liquid {
  background: linear-gradient(180deg, #ffd36c, #e6a117);
}

.alchemy-tube-emerald .alchemy-liquid {
  background: linear-gradient(180deg, #7edcb5, #2f9e6b);
}

.alchemy-tube-violet .alchemy-liquid {
  background: linear-gradient(180deg, #bba0ff, #7a4bd6);
}

.alchemy-tube-crimson .alchemy-liquid {
  background: linear-gradient(180deg, #ff8f8f, #d64545);
}

.alchemy-tube-label {
  font-size: 0.72rem;
  font-weight: 800;
  text-align: center;
  letter-spacing: 0.04em;
  color: var(--ink);
}

.alchemy-tube-symbol {
  font-size: 1rem;
  color: rgba(37, 33, 29, 0.72);
}

.actions {
  margin-top: 1rem;
  display: flex;
  gap: 0.75rem;
  flex-wrap: wrap;
}

.btn {
  border: 0;
  border-radius: 999px;
  padding: 0.72rem 1.1rem;
  font-size: 0.98rem;
  font-weight: 700;
  cursor: pointer;
  transition: transform 160ms ease, box-shadow 160ms ease, opacity 160ms ease;
}

.btn:hover {
  transform: translateY(-1px);
  box-shadow: 0 8px 18px rgba(37, 33, 29, 0.18);
}

.btn:active {
  transform: translateY(0);
}

.btn-primary {
  background: var(--accent);
  color: #fff8ef;
}

.btn-secondary {
  background: rgba(15, 118, 110, 0.14);
  color: var(--accent-2);
}

.feedback,
.clue {
  min-height: 1.2em;
  margin: 0.7rem 0 0;
}

.feedback {
  font-weight: 700;
}

.clue {
  color: var(--accent-2);
}

.feedback.error {
  color: var(--danger);
}

.feedback.success {
  color: var(--accent-2);
}

.hidden {
  display: none;
}

@keyframes slide-up {
  from {
    opacity: 0;
    transform: translateY(12px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@media (max-width: 640px) {
  .panel {
    padding: 1.1rem;
  }

  .grid-row {
    grid-template-columns: 2rem repeat(4, minmax(0, 1fr));
    gap: 0.35rem;
  }

  .alchemy-layout {
    grid-template-columns: 1fr 1fr;
    grid-template-rows: auto auto auto;
    gap: 0.6rem;
    justify-items: center;
  }

  .alchemy-bottle-frame {
    grid-column: 1 / -1;
    grid-row: 2;
  }

  .alchemy-top {
    grid-column: 1;
    grid-row: 1;
  }

  .alchemy-left {
    grid-column: 2;
    grid-row: 1;
  }

  .alchemy-right {
    grid-column: 1;
    grid-row: 3;
  }

  .alchemy-bottom {
    grid-column: 2;
    grid-row: 3;
  }

  .alchemy-bottle-frame {
    max-width: 220px;
  }

  .alchemy-tube {
    width: 5rem;
    height: 9rem;
  }

  .game-header {
    flex-direction: column;
    align-items: flex-start;
  }

  .actions {
    flex-direction: column;
  }

  .actions .btn {
    width: 100%;
  }
}
