/* =====================================================================
   AIFAB — the game surface.  One chat, one Fablin.
   The creature (js/pet.js) is pure; this is the only file that touches the DOM.
   ===================================================================== */

.game {
  display: grid;
  grid-template-columns: minmax(0, 0.92fr) minmax(0, 1.08fr);
  gap: 22px;
  max-width: 1180px;
  margin: 0 auto;
  padding: 26px 22px 48px;
  align-items: start;
}
body.booting .game { grid-template-columns: minmax(0, 1fr); max-width: 720px; align-content: center; min-height: calc(100vh - 160px); }
body.booting .stage-panel { display: none; }
body.booting .chat-panel { background: transparent; border-color: transparent; box-shadow: none; backdrop-filter: none; -webkit-backdrop-filter: none; max-height: none; }

/* ---------- the pet ---------- */
.stage-panel { display: grid; gap: 16px; align-content: start; }
.pad {
  position: relative;
  display: grid;
  place-items: center;
  min-height: 292px;
  border-radius: var(--radius);
  border: 1px dashed var(--line-2);
  background:
    radial-gradient(58% 58% at 50% 42%, rgba(0, 113, 227, .10), transparent 72%),
    var(--bg1);
  transition: border-color .3s;
}
body.has-pet .pad { border-style: solid; border-color: var(--line); }
.pad-empty {
  position: absolute;
  bottom: 16px;
  left: 0; right: 0;
  text-align: center;
  font-family: var(--mono);
  font-size: .68rem;
  letter-spacing: .16em;
  text-transform: uppercase;
  color: var(--dim);
}
body.has-pet .pad-empty { display: none; }
.pet-slot { width: 240px; height: 240px; display: grid; place-items: center; cursor: crosshair; }

.hud { display: grid; gap: 13px; }
.hud-top { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.hud-top strong { font-family: var(--display); font-size: 1.5rem; }
.pet-mood {
  font-family: var(--mono); font-size: .68rem; letter-spacing: .13em; text-transform: uppercase;
  color: var(--neon); border: 1px solid rgba(0, 113, 227, .22); background: rgba(0, 113, 227, .07);
  padding: 4px 10px; border-radius: 999px;
}
.pet-stage-badge { font-family: var(--mono); font-size: .64rem; letter-spacing: .18em; text-transform: uppercase; color: var(--dim); margin-left: auto; }

.parts { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 10px 8px; margin: 0; }
.parts dt { font-family: var(--mono); font-size: .58rem; letter-spacing: .13em; text-transform: uppercase; color: var(--dim); }
.parts dd { margin: 3px 0 0; font-size: .84rem; color: var(--text); overflow-wrap: anywhere; }

.pet-stats { display: grid; gap: 9px; }
.pet-stat { display: grid; grid-template-columns: 74px minmax(0, 1fr) 38px; align-items: center; gap: 10px; font-size: .82rem; color: var(--muted); }
.pet-track { height: 7px; border-radius: 99px; background: rgba(0, 0, 0, .07); overflow: hidden; }
.pet-track i { display: block; height: 100%; width: 2%; border-radius: 99px; background: var(--grad); transition: width .5s cubic-bezier(.2, .8, .2, 1); }
.pet-stat b { font-family: var(--mono); font-size: .76rem; color: var(--text); text-align: right; font-variant-numeric: tabular-nums; }

.pet-care { display: flex; gap: 8px; flex-wrap: wrap; }
.pet-note { font-size: .82rem; color: var(--dim); line-height: 1.6; }

/* ---------- the chat ---------- */
.chat-panel {
  display: grid;
  grid-template-rows: auto minmax(140px, 1fr) auto auto;
  gap: 14px;
  padding: 20px;
  border-radius: var(--radius);
  background: var(--glass);
  border: 1px solid var(--line);
  box-shadow: var(--shadow), inset 0 1px 0 rgba(255, 255, 255, .06);
  backdrop-filter: blur(18px) saturate(160%);
  -webkit-backdrop-filter: blur(18px) saturate(160%);
  max-height: calc(100vh - 130px);
}
.boot h1 { font-size: clamp(1.9rem, 4.4vw, 2.9rem); }
.boot p { color: var(--muted); margin-top: 12px; max-width: 48ch; }
.examples { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 18px; }
.examples button {
  font: inherit; font-size: .82rem; cursor: pointer; color: var(--muted);
  background: var(--glass); border: 1px solid var(--line); border-radius: 999px; padding: 8px 13px;
  transition: color .2s, border-color .2s, transform .15s;
}
.examples button:hover { color: var(--text); border-color: var(--line-2); transform: translateY(-1px); }

.thread { overflow-y: auto; display: grid; gap: 10px; align-content: start; padding-right: 4px; scrollbar-width: thin; }
.bubble {
  max-width: 90%; padding: 10px 14px; border-radius: 16px; font-size: .93rem; line-height: 1.5;
  white-space: pre-wrap; overflow-wrap: anywhere;
}
.bubble.user { justify-self: end; background: var(--neon); color: #ffffff; border: 0; border-bottom-right-radius: 6px; }
.bubble.pet { justify-self: start; background: #f0f0f5; border: 1px solid rgba(0, 0, 0, .05); border-bottom-left-radius: 6px; }
.bubble .src { display: block; margin-top: 6px; font-family: var(--mono); font-size: .58rem; letter-spacing: .1em; text-transform: uppercase; color: var(--dim); }
.bubble.sys { justify-self: center; background: transparent; border: 1px dashed var(--line); color: var(--dim); font-size: .8rem; font-family: var(--mono); }
.bubble.fresh { animation: bubble-in .3s ease; }
@keyframes bubble-in { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }

.composer { display: flex; gap: 10px; align-items: flex-end; }
.composer textarea {
  flex: 1; min-width: 0; resize: none; max-height: 132px; font: inherit; font-size: .95rem;
  color: var(--text); background: var(--bg1); border: 1px solid var(--line-2);
  border-radius: 16px; padding: 12px 14px; line-height: 1.5;
}
.composer textarea:focus { border-color: var(--neon); outline: none; }
.send {
  flex: none; width: 46px; height: 46px; border-radius: 50%; border: 0; cursor: pointer;
  display: grid; place-items: center; background: var(--neon); color: #ffffff;
  box-shadow: 0 12px 30px -12px rgba(124, 92, 255, .8); transition: transform .18s;
}
.send:hover { transform: translateY(-2px); }
.send svg { width: 20px; height: 20px; }
.engine { font-family: var(--mono); font-size: .64rem; letter-spacing: .07em; color: var(--dim); }
.engine.on { color: var(--good); }
.engine.off { color: var(--warn); }

/* ---------- the creature ---------- */
.pet-slot .pet-svg { transition: transform .4s ease; overflow: visible; }
.pet-slot .pet-svg[data-stage='0'] { transform: scale(.88); }
.pet-slot .pet-svg[data-stage='1'] { transform: scale(.94); }
.pet-slot .pet-svg[data-stage='2'] { transform: scale(1); }
.pet-slot .pet-svg[data-stage='3'] { transform: scale(1.04); }

.pet-svg .p-bob { transform-box: fill-box; transform-origin: center bottom; animation: pet-bob 3.4s ease-in-out infinite; }
.pet-svg .p-twig { transform-box: fill-box; transform-origin: center bottom; animation: pet-twig 2.6s ease-in-out infinite; }
.pet-svg .p-eyes { transform-box: fill-box; transform-origin: center; animation: pet-blink 5.6s infinite; }
.pet-svg .p-core { transform-box: fill-box; transform-origin: center; animation: pet-core 2.8s ease-in-out infinite; }
.pet-svg .p-halo { animation: pet-halo 4.2s ease-in-out infinite; }
.pet-svg .p-scan { animation: pet-scan 2.2s ease-in-out infinite alternate; }
.pet-svg .p-face { transition: transform .18s ease-out; }
.pet-svg[data-mood='sleepy'] .p-bob { animation-duration: 6.6s; }
.pet-svg[data-mood='sleepy'] .p-eyes { animation: none; }
.pet-svg[data-mood='happy'] .p-bob { animation-duration: 1.9s; }
.pet-svg[data-mood='curious'] .p-twig { animation-duration: 1.2s; }
.pet-svg[data-mood='hungry'] .p-core { animation-duration: 1.1s; }
.pet-svg[data-mood='hungry'] .p-plates { opacity: .7; }

@keyframes pet-bob { 0%, 100% { transform: translateY(0); } 50% { transform: translateY(-6px); } }
@keyframes pet-twig { 0%, 100% { transform: rotate(-5deg); } 50% { transform: rotate(5deg); } }
@keyframes pet-blink { 0%, 92%, 100% { transform: scaleY(1); } 95% { transform: scaleY(.1); } 97% { transform: scaleY(1); } }
@keyframes pet-core { 0%, 100% { opacity: .85; transform: scale(1); } 50% { opacity: 1; transform: scale(1.09); } }
@keyframes pet-halo { 0%, 100% { opacity: .35; } 50% { opacity: .6; } }
@keyframes pet-scan { from { transform: translateX(-3.5px); } to { transform: translateX(3.5px); } }

@media (max-width: 900px) {
  .game { grid-template-columns: 1fr; padding: 18px 16px 40px; }
  .chat-panel { max-height: none; grid-template-rows: auto minmax(180px, 44vh) auto auto; }
  .pet-slot { width: 208px; height: 208px; }
  .pad { min-height: 250px; }
  .parts { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  body { padding-bottom: 0; }
}

/* =====================================================================
   The gallery (examples made with the kiln) and the shared 3D forge.
   ===================================================================== */
.gallery { padding: 34px 22px 64px; max-width: 1180px; margin: 0 auto; }
.gal-head { max-width: 660px; margin-bottom: 26px; }
.gal-head p { color: var(--muted); margin-top: 14px; }
.gal-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); gap: 14px; }
.gal-card {
  display: grid; gap: 10px; padding: 16px 16px 14px; border-radius: var(--radius);
  border: 1px solid var(--line); background: var(--bg1); text-align: center;
  transition: border-color .25s, transform .25s;
}
.gal-card:hover { border-color: var(--line-2); transform: translateY(-3px); }
.gal-art { width: 132px; height: 132px; margin: 0 auto; display: grid; place-items: center; }
.gal-art .pet-svg { width: 132px; height: 132px; }
.gal-name { font-family: var(--display); font-size: 1.08rem; }
.gal-tag { color: var(--muted); font-size: .84rem; line-height: 1.5; min-height: 2.6em; }
.gal-says { color: var(--dim); font-size: .78rem; font-style: italic; line-height: 1.5; }
.gal-code { font-family: var(--mono); font-size: .6rem; letter-spacing: .1em; color: var(--dim); }
.gal-acts { display: flex; gap: 8px; justify-content: center; flex-wrap: wrap; }
.gal-acts .btn { padding: 7px 12px; font-size: .78rem; }
.gal-note { margin-top: 20px; font-family: var(--mono); font-size: .64rem; letter-spacing: .06em; color: var(--dim); }
.forge-btn { margin-top: 2px; }
.forge-btn svg { width: 16px; height: 16px; }

.forge {
  position: fixed; inset: 0; z-index: 200; display: grid; place-items: center; padding: 18px;
  background: rgba(0, 0, 0, .28); backdrop-filter: blur(12px); -webkit-backdrop-filter: blur(12px);
}
.forge[hidden] { display: none !important; }
.forge-card {
  width: min(1020px, 100%); display: grid; grid-template-rows: auto minmax(0, 1fr) auto;
  border-radius: var(--radius); border: 1px solid var(--line-2); overflow: hidden;
  background: var(--bg1);
  box-shadow: 0 40px 110px -30px rgba(0, 0, 0, .45);
}
.forge-top { display: flex; align-items: center; gap: 14px; padding: 15px 18px; border-bottom: 1px solid var(--line); }
.forge-title { display: grid; gap: 3px; min-width: 0; }
.forge-title strong { font-family: var(--display); font-size: 1.16rem; }
.forge-sub { color: var(--muted); font-size: .84rem; }
.forge-top .btn { margin-left: auto; }
/* The 3D stage stays DARK on purpose: it is a viewer, not page chrome, and
   check-page.mjs isolates the creature from the stage by brightness (sum > 150).
   A light stage makes every background pixel "bright" and the framing assertion
   meaningless — js/pet3d.js records that a brighter disc already did exactly that
   once. Dark well inside a light card is also just how product viewers look. */
.forge-stage { position: relative; background: radial-gradient(70% 70% at 50% 36%, #23232a, #0d0d10 72%); }
.forge-stage canvas { width: 100%; height: min(62vh, 560px); display: block; touch-action: none; cursor: grab; outline: none; }
.forge-stage canvas:active { cursor: grabbing; }
.forge-hint, .forge-load {
  position: absolute; left: 0; right: 0; text-align: center; font-family: var(--mono);
  font-size: .64rem; letter-spacing: .08em; color: rgba(255, 255, 255, .62); pointer-events: none;
}
.forge-hint { bottom: 10px; }
.forge-load { top: 50%; transform: translateY(-50%); }
.forge-load[hidden] { display: none !important; }
.forge-foot { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; padding: 13px 18px; border-top: 1px solid var(--line); }
.forge-parts { font-family: var(--mono); font-size: .62rem; letter-spacing: .06em; color: var(--dim); }
.forge-adopt { margin-left: auto; }
@media (max-width: 700px) {
  .forge { padding: 0; }
  .forge-card { border-radius: 0; height: 100%; }
  .forge-stage canvas { height: 54vh; }
}
.forge-says {
  flex: 1 1 100%; order: 9; margin: 0; font-size: .88rem; color: var(--neon);
  line-height: 1.5; font-style: italic;
}
.forge-says[hidden] { display: none !important; }
