/* ALCHEMY — alchemy.css
   Game-specific styles layered on top of styles.css (the sandfall base):
   palette chips, collection book, hint box, HUD readout, toasts on phones. */

.panel-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 12px;
}

.chip-count {
  margin: 0;
  font-family: var(--mono);
  font-size: 11px;
  letter-spacing: 1px;
  color: var(--cyan);
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 2px 10px;
}

.badge-new {
  font-family: var(--pixel);
  font-size: 7px;
  letter-spacing: 1px;
  color: #05050d;
  background: var(--gold);
  border-radius: 3px;
  padding: 3px 4px;
  animation: badge-pulse 1.2s ease-in-out infinite;
}
@keyframes badge-pulse { 50% { box-shadow: 0 0 10px rgba(255, 200, 87, 0.7); } }

/* ---------- collection book ---------- */

.book { margin-top: 24px; gap: 16px; }
.book .panel-title:focus-visible { outline-offset: 6px; }

.meters { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; }
.meter { display: grid; grid-template-columns: auto 1fr; align-items: baseline; gap: 4px 10px; }
.meter-label { font-family: var(--mono); font-size: 11px; letter-spacing: 1px; color: var(--dim); }
.meter-value { justify-self: end; font-family: var(--pixel); font-size: 11px; color: var(--gold); }
.meter-track {
  grid-column: 1 / -1;
  height: 8px;
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: 4px;
  overflow: hidden;
}
.meter-fill {
  display: block;
  height: 100%;
  background: linear-gradient(90deg, var(--gold), var(--magenta));
  transform-origin: left center;
  transform: scaleX(0);
  transition: transform 0.4s var(--ease-out);
}
.meter-fill-alt { background: linear-gradient(90deg, var(--cyan), var(--green)); }

.disclaimer {
  margin: 0;
  font-size: 12.5px;
  color: var(--dim);
  background: var(--bg);
  border-left: 3px solid var(--magenta);
  border-radius: 0 6px 6px 0;
  padding: 6px 10px;
}

.book-layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 320px;
  gap: 20px;
  align-items: start;
}
.book-main, .book-side { display: flex; flex-direction: column; min-width: 0; }
.book-main { gap: 14px; }
.book-side { gap: 12px; }

.el-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(112px, 1fr)); gap: 8px; }

.el-card {
  display: flex;
  align-items: center;
  gap: 8px;
  min-height: 44px;
  padding: 8px 10px;
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: 6px;
  color: var(--text);
  font-family: var(--mono);
  font-size: 11px;
  letter-spacing: 0.5px;
  text-align: left;
  cursor: pointer;
  transition: border-color 0.12s, box-shadow 0.12s, transform 0.12s var(--ease-out);
}
.el-card:hover:not(:disabled) {
  border-color: var(--swatch, var(--cyan));
  box-shadow: 0 0 12px color-mix(in srgb, var(--swatch, var(--cyan)) 30%, transparent);
  transform: translateY(-1px);
}
.el-card[aria-current="true"] {
  border-color: var(--cyan);
  box-shadow: inset 0 0 0 1px var(--swatch, var(--cyan)), 0 0 14px rgba(69, 240, 255, 0.25);
}
.el-card:disabled { cursor: default; color: var(--dim); border-style: dashed; opacity: 0.7; }
.el-card-name { min-width: 0; overflow-wrap: anywhere; }
.el-card-unknown { font-family: var(--pixel); font-size: 9px; letter-spacing: 2px; color: var(--control-line); }

.detail {
  display: flex;
  flex-direction: column;
  gap: 10px;
  min-height: 120px;
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 14px;
}
.detail:focus-visible { outline-offset: 4px; }
.detail-empty, .detail-hint, .detail-base, .detail-more { margin: 0; font-size: 13px; color: var(--dim); }
.detail-head { display: flex; align-items: center; gap: 10px; }
.detail-head .swatch { width: 18px; height: 18px; }
.detail-name { margin: 0; font-family: var(--pixel); font-size: 13px; letter-spacing: 1px; color: var(--text); }
.detail .btn { align-self: flex-start; }
.detail-label, .note-label, .sub-title { margin: 0; font-family: var(--pixel); font-size: 9px; letter-spacing: 1px; color: var(--gold); }

.recipe-list, .hint-list, .log-list, .notes-list {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin: 0;
  padding: 0;
  list-style: none;
  font-family: var(--mono);
  font-size: 12px;
}

.fiction-tag {
  margin: 0;
  font-family: var(--mono);
  font-size: 11.5px;
  color: var(--magenta);
  border: 1px dashed var(--magenta);
  border-radius: 6px;
  padding: 6px 8px;
}

.note-card { display: flex; flex-direction: column; gap: 4px; border-left: 3px solid var(--green); padding: 4px 0 4px 10px; }
.note-text { margin: 0; font-family: var(--body); font-size: 13px; line-height: 1.55; color: var(--text); }
.note-source { font-family: var(--mono); font-size: 11.5px; }
.note-element { margin: 0 0 4px; font-family: var(--pixel); font-size: 9px; color: var(--cyan); }
.note-item { padding-bottom: 8px; border-bottom: 1px dashed var(--line); }

.hint-box {
  display: flex;
  flex-direction: column;
  gap: 8px;
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px;
}
.hint-item { display: flex; align-items: baseline; gap: 8px; color: var(--text); }
.hint-tag {
  flex: 0 0 auto;
  font-family: var(--pixel);
  font-size: 7px;
  color: #05050d;
  background: var(--gold);
  border-radius: 3px;
  padding: 3px 4px;
}

.book-details { background: var(--bg); border: 1px solid var(--line); border-radius: 8px; padding: 10px 12px; }
.book-details summary {
  display: flex;
  align-items: center;
  justify-content: flex-start;
  gap: 8px;
  list-style: none;
  min-height: 32px;
  cursor: pointer;
  font-family: var(--pixel);
  font-size: 9px;
  letter-spacing: 1px;
  color: var(--gold);
}
.book-details summary::-webkit-details-marker { display: none; }
/* display:flex drops the native disclosure marker, so draw one. */
.book-details summary::before {
  content: "";
  flex: 0 0 auto;
  width: 0;
  height: 0;
  border-left: 6px solid currentColor;
  border-top: 4px solid transparent;
  border-bottom: 4px solid transparent;
  transition: transform 0.15s var(--ease-out);
}
.book-details[open] summary::before { transform: rotate(90deg); }
.book-details summary .chip-count { margin-left: auto; }
.book-details[open] summary { margin-bottom: 10px; }
.book-details > .note { margin-bottom: 8px; }
.log-list { max-height: 320px; overflow-y: auto; }
.log-done { color: var(--text); }
.log-hint { color: var(--gold); }
.log-locked { color: var(--dim); font-style: italic; }

.btn-danger { border-color: rgba(255, 85, 96, 0.5); color: var(--red); }
.btn-danger:hover { border-color: var(--red); box-shadow: 0 0 12px rgba(255, 85, 96, 0.3); }

/* Hint button stays focusable when it has nothing to give (aria-disabled). */
.btn[aria-disabled="true"],
.btn[aria-disabled="true"]:hover { opacity: 0.5; cursor: not-allowed; transform: none; box-shadow: none; }

.game-tag {
  display: inline-block;
  font-family: var(--mono);
  font-size: 10.5px;
  letter-spacing: 0.3px;
  color: var(--magenta);
  border: 1px dashed var(--magenta);
  border-radius: 4px;
  padding: 0 5px;
}

.el-card .badge-new { margin-left: auto; }

/* HUD: what the brush paints + what sits under the cursor (tells look-alike
   cells apart), then FPS/cells. */
.hud {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  gap: 2px 12px;
}
.hud-probe { color: var(--text); text-align: left; }
.hud-stats { margin-left: auto; }

@media (max-width: 900px) {
  .book-layout { grid-template-columns: 1fr; }
}

/* Desktop with a mouse: compact chips keep 30 elements to ~3 rows so the
   bench still fits under the palette. */
@media (min-width: 901px) and (pointer: fine) {
  .palette { gap: 6px; }
  .swatch-btn { min-height: 36px; padding: 6px 9px; gap: 7px; }
}

/* Desktop: the palette sticks to the top while the bench is on screen, so
   a short window (1280x800) can show chips and the whole bench at once.
   It is scoped to .bench, so it scrolls away before the book. */
@media (min-width: 901px) and (min-height: 600px) {
  .palette-panel {
    position: sticky;
    top: 8px;
    z-index: 4;
    box-shadow: 0 12px 28px rgba(5, 5, 12, 0.65);
  }
}

/* Touch: shortcut keys mean nothing without a keyboard. */
@media (pointer: coarse) {
  .swatch-btn kbd { display: none; }
}

@media (max-width: 600px) {
  .meters { grid-template-columns: 1fr; }
  .el-grid { grid-template-columns: repeat(auto-fill, minmax(96px, 1fr)); }

  /* Phones: the palette is one horizontally scrolling row, so the bench
     stays right under it however many elements are found. Fresh
     discoveries (data-front) are pulled to the start of the row. No
     scroll-snap: re-snapping to the old first chip would push a freshly
     pulled-forward chip out of view. */
  .palette {
    flex-wrap: nowrap;
    overflow-x: auto;
    overscroll-behavior-x: contain;
    scrollbar-width: thin;
    margin: -4px -4px 0;
    padding: 4px 4px 8px;
  }
  .swatch-btn {
    flex: 0 0 auto;
    align-items: center;
  }
  .swatch-btn[data-front] { order: -1; }
  .swatch-name { max-width: none; white-space: nowrap; }

  /* Toasts sit at the top on phones so they never cover the bench. */
  .toasts { top: 12px; bottom: auto; }
  .toast { padding: 10px 12px; font-size: 13px; animation-name: toast-in-top; }
  .toast.out { transform: translateY(-6px); }
}

@keyframes toast-in-top {
  from { opacity: 0; transform: translateY(-10px); }
}

@media (prefers-reduced-motion: reduce) {
  .badge-new { animation: none; }
  .meter-fill { transition: none; }
}
