:root {
  color-scheme: dark;
  --ink: #f6f3ff;
  --muted: #a8a2bf;
  --panel: rgba(25, 21, 47, 0.82);
  --panel-strong: #1c1735;
  --line: rgba(255, 255, 255, 0.09);
  --cyan: #8ce7f5;
  --violet: #9f8cff;
  --rose: #f08da8;
  --gold: #f6d68a;
  --shadow: 0 26px 80px rgba(4, 3, 17, 0.42);
  font-family: Inter, ui-sans-serif, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  min-width: 320px;
  min-height: 100vh;
  color: var(--ink);
  background:
    radial-gradient(circle at 18% -10%, rgba(106, 92, 216, 0.26), transparent 38%),
    radial-gradient(circle at 90% 20%, rgba(42, 185, 199, 0.13), transparent 30%),
    #0d0b1a;
}

button, input, select { font: inherit; }
button { color: inherit; }

.app-shell { min-height: 100vh; padding: 0 24px; }

.topbar, footer {
  max-width: 1440px;
  margin: 0 auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.topbar { height: 82px; border-bottom: 1px solid var(--line); }
.brand { display: flex; align-items: center; gap: 12px; color: inherit; text-decoration: none; }
.brand img { border-radius: 12px; box-shadow: 0 10px 28px rgba(70, 51, 166, .28); }
.brand span { display: flex; flex-direction: column; line-height: 1.08; }
.brand strong { font-size: 17px; letter-spacing: .01em; }
.brand small { margin-top: 5px; color: var(--muted); font-size: 10px; letter-spacing: .12em; text-transform: uppercase; }
.topbar-status { display: flex; align-items: center; gap: 9px; color: var(--muted); font-size: 13px; }
.topbar-actions { display: flex; align-items: center; gap: 18px; }
.install-button {
  min-height: 36px;
  padding: 0 14px;
  border: 1px solid rgba(168, 155, 255, .34);
  border-radius: 999px;
  color: #e9e5ff;
  background: rgba(159, 140, 255, .1);
  cursor: pointer;
  font-size: 10px;
  font-weight: 700;
}
.install-button:hover, .install-button.install-ready {
  border-color: rgba(140, 231, 245, .56);
  background: rgba(140, 231, 245, .12);
  box-shadow: 0 0 24px rgba(140, 231, 245, .09);
}
.hatch-link { padding: 9px 12px; border: 1px solid rgba(140,231,245,.24); border-radius: 999px; color: var(--cyan); background: rgba(140,231,245,.06); text-decoration: none; font-size: 10px; font-weight: 650; }
.hatch-link:hover { border-color: rgba(140,231,245,.42); background: rgba(140,231,245,.1); }
.hatch-link span { color: var(--muted); font-weight: 400; }
.status-light { width: 8px; height: 8px; border-radius: 50%; background: var(--cyan); box-shadow: 0 0 18px var(--cyan); }
.status-light.error { background: var(--rose); box-shadow: 0 0 18px var(--rose); }

.workspace {
  max-width: 1440px;
  min-height: calc(100vh - 150px);
  margin: 22px auto 26px;
  display: grid;
  grid-template-columns: minmax(0, 1.72fr) minmax(340px, .72fr);
  gap: 20px;
}

.habitat {
  position: relative;
  min-height: 720px;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 34px;
  background:
    linear-gradient(180deg, rgba(24, 20, 53, .42), rgba(10, 10, 28, .5)),
    radial-gradient(circle at 50% 64%, rgba(78, 189, 208, .13), transparent 30%),
    linear-gradient(145deg, #191532, #0d1326 62%, #151125);
  box-shadow: var(--shadow);
  isolation: isolate;
}

.ambient { position: absolute; border-radius: 50%; filter: blur(2px); opacity: .54; }
.ambient-one { width: 460px; height: 460px; top: -190px; right: -120px; background: radial-gradient(circle, rgba(139, 124, 255, .32), transparent 68%); }
.ambient-two { width: 360px; height: 360px; bottom: -120px; left: -80px; background: radial-gradient(circle, rgba(48, 213, 204, .2), transparent 68%); }
.stars { position: absolute; inset: 0; opacity: .4; background-image: radial-gradient(circle, rgba(255,255,255,.72) 0 1px, transparent 1.4px); background-size: 71px 71px; mask-image: linear-gradient(to bottom, black, transparent 68%); }

.habitat-copy { position: absolute; z-index: 2; top: 44px; left: 48px; }
.eyebrow { color: var(--cyan); font-weight: 700; font-size: 10px; letter-spacing: .19em; }
.habitat h1 { margin: 12px 0 6px; font-size: clamp(34px, 4vw, 60px); letter-spacing: -.045em; font-weight: 640; }
.habitat h1 span { background: linear-gradient(90deg, var(--cyan), #c5bbff); background-clip: text; color: transparent; }
.habitat-copy p { margin: 0; color: var(--muted); font-size: 14px; }

.speech {
  position: absolute;
  z-index: 3;
  top: 165px;
  right: 7%;
  max-width: 270px;
  padding: 14px 17px;
  border: 1px solid rgba(255,255,255,.13);
  border-radius: 18px 18px 4px 18px;
  color: #e8e5f7;
  background: rgba(25, 22, 48, .72);
  box-shadow: 0 16px 50px rgba(5, 4, 19, .24);
  backdrop-filter: blur(14px);
  font-size: 13px;
  line-height: 1.45;
}

#petCanvas { position: absolute; inset: 0; z-index: 2; width: 100%; height: 100%; cursor: pointer; }
#petCanvas:focus-visible { outline: 2px solid var(--cyan); outline-offset: -7px; border-radius: 34px; }
.floor-glow { position: absolute; z-index: 1; left: 24%; right: 24%; bottom: 6%; height: 90px; border-radius: 50%; background: radial-gradient(ellipse, rgba(101, 224, 230, .22), transparent 68%); filter: blur(8px); }
.gesture-hint { position: absolute; z-index: 4; bottom: 22px; left: 50%; transform: translateX(-50%); color: rgba(231,228,247,.5); font-size: 11px; letter-spacing: .04em; white-space: nowrap; }

.side-panel { display: flex; flex-direction: column; gap: 14px; }
.panel-card { padding: 20px; border: 1px solid var(--line); border-radius: 24px; background: var(--panel); box-shadow: 0 18px 50px rgba(5,4,18,.2); backdrop-filter: blur(16px); }
.card-heading { display: flex; align-items: center; justify-content: space-between; gap: 14px; }
.card-heading h2 { margin: 5px 0 0; font-size: 23px; letter-spacing: -.03em; }
.card-heading.compact h2 { margin: 0; font-size: 15px; }
.state-chip { padding: 7px 10px; border: 1px solid rgba(140,231,245,.22); border-radius: 999px; color: var(--cyan); background: rgba(140,231,245,.08); font-size: 9px; font-weight: 800; letter-spacing: .14em; }

.mode-switch {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 6px;
  margin-top: 20px;
  padding: 5px;
  border-radius: 15px;
  background: rgba(8, 7, 20, .38);
}
.mode-switch button {
  min-height: 40px;
  border: 1px solid transparent;
  border-radius: 11px;
  color: var(--muted);
  background: transparent;
  cursor: pointer;
  font-size: 11px;
}
.mode-switch button.active {
  border-color: rgba(140, 231, 245, .22);
  color: var(--ink);
  background: linear-gradient(135deg, rgba(140, 231, 245, .12), rgba(159, 140, 255, .11));
}
.mode-hint { min-height: 17px; margin: 13px 2px 0; color: var(--muted); font-size: 10px; }

.vitals { display: grid; gap: 7px; margin-top: 20px; }
.vitals label { display: flex; justify-content: space-between; color: var(--muted); font-size: 11px; }
.meter { height: 5px; margin-bottom: 5px; overflow: hidden; border-radius: 999px; background: rgba(255,255,255,.07); }
.meter i { display: block; height: 100%; border-radius: inherit; background: linear-gradient(90deg, #5bcbd9, var(--cyan)); transition: width .35s ease; }
.meter.trust i { background: linear-gradient(90deg, #7665df, #b5a9ff); }
.meter.curiosity i { background: linear-gradient(90deg, #df728f, #f4b4c5); }

.reaction-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin-top: 16px; }
.reaction-grid button, .connect-form button, .memory-form button {
  min-height: 39px;
  border: 1px solid var(--line);
  border-radius: 12px;
  color: #dcd7ee;
  background: rgba(255,255,255,.035);
  cursor: pointer;
  font-size: 11px;
  transition: transform .16s ease, border-color .16s ease, background .16s ease;
}
.reaction-grid button:hover, .connect-form button:hover, .memory-form button:hover { transform: translateY(-1px); border-color: rgba(140,231,245,.35); background: rgba(140,231,245,.07); }
.text-button { padding: 0; border: 0; color: var(--cyan); background: none; cursor: pointer; font-size: 11px; }
.text-button.danger { color: #eaa0b3; margin-top: 12px; }

.tab-card { flex: 1; min-height: 0; }
.advanced-card { padding: 0; overflow: hidden; }
.advanced-card > summary {
  padding: 17px 20px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  color: var(--muted);
  cursor: pointer;
  font-size: 11px;
  list-style: none;
}
.advanced-card > summary::-webkit-details-marker { display: none; }
.advanced-card > summary::after { content: "+"; color: var(--cyan); font-size: 16px; }
.advanced-card[open] > summary { border-bottom: 1px solid var(--line); color: var(--ink); }
.advanced-card[open] > summary::after { content: "−"; }
.advanced-content { padding: 18px 20px 20px; }
.pet-import { margin-bottom: 17px; padding-bottom: 17px; border-bottom: 1px solid var(--line); }
.pet-import > div:first-child { display: grid; gap: 4px; }
.pet-import strong { font-size: 12px; }
.pet-import small { color: var(--muted); font-size: 9px; line-height: 1.45; }
.pet-import-actions { margin-top: 11px; display: flex; align-items: center; gap: 12px; }
.compact-file { flex: 1; margin-top: 0 !important; padding: 9px 11px !important; }
#petFolder { position: absolute; width: 1px; height: 1px; opacity: 0; }
.built-in-pets { margin-top: 10px; display: flex; align-items: center; gap: 12px; }
.built-in-pets span { color: var(--muted); font-size: 9px; text-transform: uppercase; letter-spacing: .12em; }
.pet-import-status { min-height: 14px; margin: 9px 0 0; color: var(--cyan); font-size: 9px; }
.tabs { display: grid; grid-template-columns: repeat(3, 1fr); gap: 4px; padding: 4px; border-radius: 13px; background: rgba(8,7,20,.34); }
.tab { padding: 8px; border: 0; border-radius: 10px; color: var(--muted); background: transparent; cursor: pointer; font-size: 11px; }
.tab.active { color: var(--ink); background: rgba(255,255,255,.07); }
.tab-panel { padding-top: 16px; }
.activity-list, .memory-list { display: grid; gap: 13px; max-height: 230px; margin: 0; padding: 0; overflow: auto; list-style: none; }
.activity-list li { display: grid; grid-template-columns: 10px 1fr; gap: 10px; align-items: start; }
.activity-list strong, .memory-list strong { display: block; font-size: 12px; font-weight: 560; }
.activity-list small { display: block; margin-top: 4px; color: var(--muted); font-size: 10px; }
.activity-dot { width: 7px; height: 7px; margin-top: 4px; border-radius: 50%; background: var(--violet); box-shadow: 0 0 10px rgba(159,140,255,.65); }
.activity-dot.success { background: var(--cyan); }
.activity-dot.failure { background: var(--rose); }
.activity-dot.waiting { background: var(--gold); }

.memory-form label, .connect-form label { display: block; margin-bottom: 7px; color: var(--muted); font-size: 10px; }
.input-row { display: grid; grid-template-columns: 1fr auto; gap: 8px; }
input, select { width: 100%; min-height: 39px; padding: 0 12px; border: 1px solid var(--line); border-radius: 11px; outline: none; color: var(--ink); background: rgba(7,6,18,.38); font-size: 11px; }
input:focus, select:focus { border-color: rgba(140,231,245,.45); box-shadow: 0 0 0 3px rgba(140,231,245,.07); }
.memory-form button { padding: 0 14px; }
.memory-list { margin-top: 16px; }
.memory-list li { display: flex; align-items: start; justify-content: space-between; gap: 10px; padding-bottom: 10px; border-bottom: 1px solid var(--line); }
.memory-list p { margin: 0; color: #ded9ed; font-size: 11px; line-height: 1.45; }
.memory-list button { border: 0; color: var(--muted); background: none; cursor: pointer; }
.connect-form { display: grid; gap: 7px; }
.connect-form button { margin-top: 5px; }
.muted { margin: 0 0 13px; color: var(--muted); font-size: 11px; line-height: 1.5; }
.file-button { display: block; margin-top: 12px; padding: 10px 12px; border: 1px dashed rgba(255,255,255,.15); border-radius: 11px; color: #d9d4e9; cursor: pointer; text-align: center; font-size: 11px; }
#replayFile { position: absolute; width: 1px; height: 1px; opacity: 0; }

footer { min-height: 46px; border-top: 1px solid var(--line); color: rgba(196,190,215,.55); font-size: 10px; letter-spacing: .04em; }
footer a { color: var(--cyan); text-decoration: none; }

.install-dialog {
  width: min(420px, calc(100% - 32px));
  padding: 0;
  border: 1px solid rgba(255, 255, 255, .13);
  border-radius: 24px;
  color: var(--ink);
  background: #19152f;
  box-shadow: var(--shadow);
}
.install-dialog::backdrop { background: rgba(4, 3, 14, .72); backdrop-filter: blur(8px); }
.install-dialog form { padding: 28px; }
.install-dialog h2 { margin: 12px 0 10px; font-size: 28px; letter-spacing: -.04em; }
.install-dialog p { margin: 0; color: var(--muted); font-size: 12px; line-height: 1.55; }
.install-dialog-close {
  width: 100%;
  min-height: 42px;
  margin-top: 22px;
  border: 1px solid rgba(140, 231, 245, .36);
  border-radius: 12px;
  color: #111323;
  background: linear-gradient(135deg, #a8eff8, #a89bff);
  cursor: pointer;
  font-weight: 700;
}

body[data-mode="focus"] .speech { opacity: 0; pointer-events: none; }
body[data-mode="focus"] .ambient,
body[data-mode="focus"] .floor-glow { opacity: .18; }
body[data-mode="play"] .floor-glow { transform: scale(1.12); filter: blur(5px); }

@media (max-width: 980px) {
  .workspace { grid-template-columns: 1fr; }
  .habitat { min-height: 660px; }
  .side-panel { display: grid; grid-template-columns: 1fr 1fr; }
  .tab-card { grid-column: 1 / -1; }
}

@media (max-width: 620px) {
  .app-shell { padding: 0 12px; }
  .topbar { height: 70px; }
  .topbar-status { font-size: 11px; }
  .topbar-actions { gap: 8px; }
  .install-button { padding: 0 11px; }
  .hatch-link span { display: none; }
  .workspace { margin-top: 12px; }
  .habitat { min-height: 570px; border-radius: 25px; }
  .habitat-copy { top: 28px; left: 26px; }
  .speech { top: 132px; right: 22px; max-width: 220px; }
  .side-panel { display: flex; }
  .reaction-grid { grid-template-columns: repeat(2, 1fr); }
  .gesture-hint { display: none; }
  footer { flex-direction: column; justify-content: center; gap: 5px; }
}

@media (max-width: 480px) {
  .hatch-link { display: none; }
}

@media (display-mode: standalone) {
  .install-button { display: none; }
  .app-shell { padding-top: env(safe-area-inset-top); }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { scroll-behavior: auto !important; transition-duration: .01ms !important; }
}
