/* EMOJESIS — styles. Digital laboratory / creation notebook. */

:root {
  --bg: #f2efe7;
  --bg-raised: #faf8f2;
  --ink: #201d17;
  --ink-soft: #5c564a;
  --line: #d8d2c2;
  --accent: #a3501c;
  --accent-ink: #fff;
  --gold: #8a6d1d;
  --danger: #9c2b1f;
  --slot-empty: #e7e2d3;
  --shadow: 0 1px 0 rgba(32, 29, 23, 0.08);
  --mono: ui-monospace, "SF Mono", "Cascadia Mono", Menlo, Consolas, monospace;
  --sans: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", sans-serif;
}

html[data-theme="dark"] {
  --bg: #14151a;
  --bg-raised: #1c1e25;
  --ink: #e9e6dc;
  --ink-soft: #a39c8d;
  --line: #33363f;
  --accent: #e0915a;
  --accent-ink: #181410;
  --gold: #d3b155;
  --danger: #e06c5b;
  --slot-empty: #23252d;
  --shadow: 0 1px 0 rgba(0, 0, 0, 0.4);
}

@media (prefers-color-scheme: dark) {
  html:not([data-theme="light"]):not([data-theme="dark"]) {
    --bg: #14151a;
    --bg-raised: #1c1e25;
    --ink: #e9e6dc;
    --ink-soft: #a39c8d;
    --line: #33363f;
    --accent: #e0915a;
    --accent-ink: #181410;
    --gold: #d3b155;
    --danger: #e06c5b;
    --slot-empty: #23252d;
    --shadow: 0 1px 0 rgba(0, 0, 0, 0.4);
  }
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--sans);
  line-height: 1.45;
}

body {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

/* subtle graph-paper lab backdrop */
body::before {
  content: "";
  position: fixed;
  inset: 0;
  pointer-events: none;
  background-image:
    linear-gradient(var(--line) 1px, transparent 1px),
    linear-gradient(90deg, var(--line) 1px, transparent 1px);
  background-size: 44px 44px;
  opacity: 0.16;
  z-index: -1;
}

.sr-only {
  position: absolute;
  width: 1px; height: 1px;
  margin: -1px; padding: 0;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
  border: 0;
}

.skip-link {
  position: absolute;
  left: -9999px;
  top: 0;
  background: var(--accent);
  color: var(--accent-ink);
  padding: 0.5rem 1rem;
  z-index: 100;
}
.skip-link:focus { left: 0; }

a { color: var(--accent); }

button {
  font-family: inherit;
  color: inherit;
  cursor: pointer;
}

:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.mono { font-family: var(--mono); }
.muted { color: var(--ink-soft); }

/* ---------- header ---------- */
.site-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: 0.7rem 1rem;
  border-bottom: 2px solid var(--ink);
  background: var(--bg-raised);
  flex-wrap: wrap;
}
.brand { display: flex; align-items: center; gap: 0.7rem; }
.title-emoji {
  font-size: 2rem;
  background: none;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 0.15rem 0.4rem;
  line-height: 1.2;
  min-width: 44px;
  min-height: 44px;
}
.brand-text h1 {
  margin: 0;
  font-size: 1.25rem;
  letter-spacing: 0.22em;
  font-family: var(--mono);
}
.tagline {
  margin: 0;
  font-size: 0.75rem;
  color: var(--ink-soft);
}
.header-actions { display: flex; gap: 0.4rem; flex-wrap: wrap; }
.hbtn {
  position: relative;
  font-size: 1.15rem;
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: 6px;
  min-width: 44px;
  min-height: 44px;
  padding: 0.3rem 0.55rem;
}
.hbtn:hover { border-color: var(--ink); }
.badge {
  position: absolute;
  top: -6px; right: -6px;
  background: var(--accent);
  color: var(--accent-ink);
  border-radius: 999px;
  font-size: 0.65rem;
  font-family: var(--mono);
  padding: 0.05rem 0.35rem;
}
.dot {
  position: absolute;
  top: 2px; right: 2px;
  width: 8px; height: 8px;
  border-radius: 50%;
  background: var(--accent);
}

/* ---------- world strip ---------- */
.world {
  border-bottom: 1px solid var(--line);
  background: var(--bg-raised);
}
.world-toggle {
  background: none;
  border: none;
  font-family: var(--mono);
  font-size: 0.7rem;
  color: var(--ink-soft);
  padding: 0.3rem 1rem;
  min-height: 32px;
}
.world-strip {
  display: flex;
  gap: 0.5rem;
  align-items: flex-end;
  overflow-x: auto;
  padding: 0.2rem 1rem 0.6rem;
  min-height: 56px;
}
.world.collapsed .world-strip { display: none; }
.w-slot {
  flex: 0 0 auto;
  width: 44px;
  height: 44px;
  display: grid;
  place-items: center;
  border: 1px dashed var(--line);
  border-radius: 6px;
  background: var(--bg);
}
.w-slot span {
  font-size: 1.5rem;
  opacity: 0;
  transform: scale(0.5);
  transition: opacity 0.4s ease, transform 0.4s ease;
}
.w-slot.found span { opacity: 1; transform: scale(1); }
.w-sky { border-bottom-style: solid; }
.w-sea { background: color-mix(in srgb, var(--bg) 80%, #4a7fa5 20%); }

/* ---------- main layout ---------- */
main {
  flex: 1;
  display: grid;
  grid-template-columns: minmax(300px, 1fr) minmax(320px, 420px);
  gap: 1rem;
  padding: 1rem;
  max-width: 1200px;
  width: 100%;
  margin: 0 auto;
}

/* ---------- creation ---------- */
.creation {
  align-self: start;
  background: var(--bg-raised);
  border: 2px solid var(--ink);
  border-radius: 10px;
  padding: 1.25rem;
  box-shadow: var(--shadow);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.9rem;
}
.slots {
  display: flex;
  align-items: center;
  gap: 0.8rem;
}
.slot {
  width: 104px;
  height: 104px;
  border: 2px dashed var(--line);
  border-radius: 12px;
  background: var(--slot-empty);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0.15rem;
}
.slot[data-filled="true"] {
  border-style: solid;
  border-color: var(--ink);
  background: var(--bg);
}
.slot.drop-hover { border-color: var(--accent); background: var(--bg); }
.slot-emoji { font-size: 2.6rem; line-height: 1; }
.slot-name {
  font-size: 0.7rem;
  font-family: var(--mono);
  color: var(--ink-soft);
}
.plus { font-size: 1.6rem; color: var(--ink-soft); }

.creation-actions {
  display: flex;
  align-items: center;
  gap: 0.6rem;
}
.combine-btn {
  background: var(--accent);
  color: var(--accent-ink);
  border: 2px solid var(--ink);
  border-radius: 8px;
  font-size: 1.05rem;
  font-weight: 600;
  padding: 0.6rem 1.4rem;
  min-height: 44px;
}
.combine-btn:disabled { opacity: 0.45; cursor: not-allowed; }
.abtn {
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 0.45rem 0.8rem;
  min-height: 44px;
  min-width: 44px;
  font-size: 1rem;
}
.abtn:hover:not(:disabled) { border-color: var(--ink); }
.abtn:disabled { opacity: 0.4; cursor: not-allowed; }
.abtn.danger { color: var(--danger); border-color: var(--danger); }

.result {
  display: flex;
  flex-direction: column;
  align-items: center;
  min-height: 84px;
  justify-content: center;
  gap: 0.2rem;
}
.result-emoji { font-size: 3.2rem; line-height: 1; }
.result-name {
  font-family: var(--mono);
  font-size: 0.85rem;
  color: var(--ink-soft);
}
.message {
  margin: 0;
  text-align: center;
  font-size: 0.95rem;
  color: var(--ink-soft);
  min-height: 1.4em;
  max-width: 40ch;
}
.message.announce { color: var(--ink); }
.daily-line {
  margin: 0;
  font-size: 0.78rem;
  font-family: var(--mono);
  color: var(--gold);
  text-align: center;
}

/* combine animation */
@keyframes fuse {
  0% { transform: translateX(0) scale(1); }
  40% { transform: translateX(var(--fuse-x, 10px)) scale(1.08); }
  60% { transform: translateX(var(--fuse-x, 10px)) scale(1.08); }
  100% { transform: translateX(0) scale(1); }
}
.slot.fusing { animation: fuse 0.5s ease; }
@keyframes pop {
  0% { transform: scale(0.3); opacity: 0; }
  60% { transform: scale(1.15); opacity: 1; }
  100% { transform: scale(1); }
}
.result.reveal { animation: pop 0.45s ease; }
@keyframes fzzap { 0%,100% { filter: none; } 50% { filter: brightness(1.8) saturate(1.6); } }
.result.fx-zap { animation: pop 0.45s ease, fzzap 0.5s ease; }
@keyframes fxflare { 0% { filter: none; } 50% { filter: brightness(1.6) hue-rotate(-20deg); } 100% { filter: none; } }
.result.fx-flare { animation: pop 0.45s ease, fxflare 0.6s ease; }
@keyframes fxshake { 0%,100% { transform: translateX(0); } 25% { transform: translateX(-4px); } 75% { transform: translateX(4px); } }
.result.fx-shake { animation: pop 0.45s ease, fxshake 0.45s ease; }
@keyframes fxcosmic { 0% { filter: none; transform: scale(0.3); } 50% { filter: brightness(1.7) hue-rotate(90deg); transform: scale(1.2); } 100% { filter: none; transform: scale(1); } }
.result.fx-cosmic { animation: fxcosmic 0.7s ease; }
@keyframes fxspooky { 0% { opacity: 0; } 30% { opacity: 1; } 45% { opacity: 0.3; } 60% { opacity: 1; } 100% { opacity: 1; } }
.result.fx-spooky { animation: pop 0.45s ease, fxspooky 0.7s ease; }

/* ---------- inventory ---------- */
.inventory {
  align-self: start;
  background: var(--bg-raised);
  border: 1px solid var(--line);
  border-radius: 10px;
  overflow: hidden;
}
.inv-toggle {
  width: 100%;
  text-align: left;
  background: none;
  border: none;
  border-bottom: 1px solid var(--line);
  padding: 0.7rem 0.9rem;
  font-family: var(--mono);
  font-size: 0.85rem;
  min-height: 44px;
}
.inv-count { color: var(--ink-soft); }
.inventory.collapsed .inv-body { display: none; }
.inv-body { padding: 0.7rem; }
.inv-tools {
  display: flex;
  gap: 0.4rem;
  margin-bottom: 0.5rem;
}
.inv-tools input[type="search"] {
  flex: 1;
  min-width: 0;
  padding: 0.45rem 0.6rem;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--bg);
  color: var(--ink);
  font: inherit;
  min-height: 44px;
}
.inv-tools select {
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--bg);
  color: var(--ink);
  font: inherit;
  min-height: 44px;
}
.chip {
  border: 1px solid var(--line);
  background: var(--bg);
  border-radius: 999px;
  padding: 0.2rem 0.6rem;
  font-size: 0.75rem;
  font-family: var(--mono);
  min-height: 30px;
}
.chip[aria-pressed="true"] {
  background: var(--ink);
  color: var(--bg);
  border-color: var(--ink);
}
.inv-cats {
  display: flex;
  flex-wrap: wrap;
  gap: 0.3rem;
  margin-bottom: 0.6rem;
}
.inv-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(88px, 1fr));
  gap: 0.45rem;
  max-height: 54vh;
  overflow-y: auto;
}
.inv-item {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.15rem;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--bg);
  padding: 0.5rem 0.3rem 0.4rem;
}
.inv-item.is-new { border-color: var(--accent); box-shadow: 0 0 0 1px var(--accent); }
.inv-main {
  background: none;
  border: none;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.15rem;
  width: 100%;
  min-height: 44px;
  cursor: grab;
}
.inv-main:active { cursor: grabbing; }
.inv-emoji { font-size: 1.8rem; line-height: 1; }
.inv-name {
  font-size: 0.62rem;
  font-family: var(--mono);
  color: var(--ink-soft);
  text-align: center;
  overflow-wrap: anywhere;
}
.inv-fav, .inv-info {
  position: absolute;
  top: 1px;
  background: none;
  border: none;
  font-size: 0.7rem;
  padding: 0.2rem;
  min-width: 28px;
  min-height: 28px;
  opacity: 0.55;
}
.inv-fav { left: 1px; }
.inv-info { right: 1px; }
.inv-fav.on { opacity: 1; }
.inv-item:hover .inv-fav, .inv-item:hover .inv-info,
.inv-fav:focus-visible, .inv-info:focus-visible { opacity: 1; }
.inv-empty {
  grid-column: 1 / -1;
  text-align: center;
  color: var(--ink-soft);
  font-size: 0.85rem;
  padding: 1rem 0;
}

@keyframes pulseHint {
  0%, 100% { box-shadow: 0 0 0 0 var(--accent); }
  50% { box-shadow: 0 0 0 4px color-mix(in srgb, var(--accent) 40%, transparent); }
}
.inv-item.ob-pulse { animation: pulseHint 1.4s ease infinite; }

/* ---------- footer ---------- */
.site-footer {
  border-top: 1px solid var(--line);
  padding: 0.8rem 1rem;
  text-align: center;
  font-size: 0.78rem;
  color: var(--ink-soft);
  background: var(--bg-raised);
}
.linklike {
  background: none;
  border: none;
  padding: 0;
  color: var(--accent);
  text-decoration: underline;
  font-size: inherit;
}

/* ---------- modals ---------- */
.modal {
  position: fixed;
  inset: 0;
  background: rgba(10, 10, 12, 0.55);
  display: grid;
  place-items: center;
  padding: 1rem;
  z-index: 50;
}
.modal[hidden] { display: none; }
.modal-card {
  background: var(--bg-raised);
  border: 2px solid var(--ink);
  border-radius: 10px;
  padding: 1.2rem;
  max-width: 480px;
  width: 100%;
  max-height: 85vh;
  overflow-y: auto;
}
.modal-card h2 { margin-top: 0; font-size: 1.1rem; }
.modal-card h3 { font-size: 0.95rem; margin-bottom: 0.3rem; }
.modal-actions {
  display: flex;
  gap: 0.5rem;
  justify-content: flex-end;
  margin-top: 1rem;
}
.modal-actions.wrap { flex-wrap: wrap; justify-content: flex-start; }
.about-links { padding-left: 1.1rem; }
.settings-grid {
  display: flex;
  gap: 1.2rem;
  flex-wrap: wrap;
  align-items: center;
}
.settings-grid select {
  font: inherit;
  background: var(--bg);
  color: var(--ink);
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 0.3rem;
  min-height: 40px;
}
.checkline { display: flex; align-items: center; gap: 0.4rem; min-height: 44px; }
.reset-confirm {
  margin-top: 0.8rem;
  border: 1px solid var(--danger);
  border-radius: 8px;
  padding: 0.7rem;
}
.daily-goal { font-size: 1.05rem; }
.share-block {
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 0.6rem;
  font-family: var(--mono);
  font-size: 0.8rem;
  white-space: pre-wrap;
}
.stats-list {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 0.3rem 1rem;
}
.stats-list dt { font-family: var(--mono); color: var(--ink-soft); }
.stats-list dd { margin: 0; text-align: right; }

/* journal */
.journal-head {
  display: flex;
  align-items: center;
  gap: 0.8rem;
  margin-bottom: 0.6rem;
}
.journal-emoji { font-size: 2.6rem; }
.journal-head h2 { margin: 0; }
.journal-meta {
  font-family: var(--mono);
  font-size: 0.72rem;
  color: var(--ink-soft);
}
.journal-sec { margin: 0.7rem 0 0.2rem; font-size: 0.85rem; }
.journal-recipes { margin: 0; padding-left: 1.2rem; font-size: 0.88rem; }
.journal-hint { color: var(--gold); font-size: 0.85rem; font-style: italic; }

/* terminal */
.term-card { background: #101216; color: #c9e7c9; border-color: #3a4a3a; }
.term-card h2 { color: #8fce8f; font-size: 0.9rem; }
.term-out {
  min-height: 160px;
  max-height: 40vh;
  overflow-y: auto;
  font-size: 0.8rem;
  white-space: pre-wrap;
  margin-bottom: 0.5rem;
}
.term-form { display: flex; align-items: center; gap: 0.3rem; }
.term-form input {
  flex: 1;
  background: none;
  border: none;
  color: #c9e7c9;
  font: inherit;
  outline: none;
  min-height: 40px;
}

/* toasts */
.toasts {
  position: fixed;
  bottom: 1rem;
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
  z-index: 80;
  pointer-events: none;
  width: min(92vw, 420px);
}
.toast {
  background: var(--ink);
  color: var(--bg);
  border-radius: 8px;
  padding: 0.55rem 0.9rem;
  font-size: 0.85rem;
  text-align: center;
  animation: toastIn 0.25s ease;
}
@keyframes toastIn {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: translateY(0); }
}

/* onboarding */
.onboarding {
  position: fixed;
  inset: 0;
  background: var(--bg);
  display: grid;
  place-items: center;
  z-index: 90;
  padding: 1rem;
}
.onboarding[hidden] { display: none; }
.ob-card {
  text-align: center;
  max-width: 420px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.8rem;
}
.ob-card h2 {
  font-family: var(--mono);
  letter-spacing: 0.3em;
  margin: 0;
}
.ob-primordials {
  display: flex;
  gap: 1rem;
  margin: 0.6rem 0;
}
.ob-el {
  font-size: 2.4rem;
  display: flex;
  flex-direction: column;
  align-items: center;
}
.ob-el small {
  font-size: 0.68rem;
  font-family: var(--mono);
  color: var(--ink-soft);
}
.ob-hint { font-size: 0.85rem; color: var(--ink-soft); }

/* ---------- world animations ---------- */
@keyframes drift { 0%,100% { transform: translateX(0); } 50% { transform: translateX(7px); } }
@keyframes twinkle { 0%,100% { opacity: 1; } 50% { opacity: 0.45; } }
@keyframes sway { 0%,100% { transform: rotate(-3deg); } 50% { transform: rotate(3deg); } }
@keyframes bob { 0%,100% { transform: translateY(0); } 50% { transform: translateY(3px); } }
@keyframes flap { 0%,100% { transform: translateY(0); } 50% { transform: translateY(-5px); } }
@keyframes hover { 0%,100% { transform: translateY(0); } 50% { transform: translateY(-3px); } }
@keyframes fall { 0%,100% { transform: translateY(0); } 50% { transform: translateY(2px); } }
@keyframes rise { 0%,100% { transform: translateY(0); } 50% { transform: translateY(-4px); } }
.w-slot.found.anim-drift span { animation: drift 5s ease-in-out infinite; }
.w-slot.found.anim-twinkle span { animation: twinkle 2.4s ease-in-out infinite; }
.w-slot.found.anim-sway span { animation: sway 3.6s ease-in-out infinite; transform-origin: bottom center; }
.w-slot.found.anim-bob span { animation: bob 2.8s ease-in-out infinite; }
.w-slot.found.anim-flap span { animation: flap 1.6s ease-in-out infinite; }
.w-slot.found.anim-hover span { animation: hover 3.2s ease-in-out infinite; }
.w-slot.found.anim-fall span { animation: fall 2.2s ease-in-out infinite; }
.w-slot.found.anim-rise span { animation: rise 2.6s ease-in-out infinite; }

/* ---------- responsive ---------- */
@media (max-width: 860px) {
  main {
    grid-template-columns: 1fr;
    padding: 0.7rem;
  }
  .inventory {
    position: fixed;
    left: 0; right: 0; bottom: 0;
    z-index: 40;
    border-radius: 14px 14px 0 0;
    border: 2px solid var(--ink);
    border-bottom: none;
    max-height: 70vh;
    display: flex;
    flex-direction: column;
    transform: translateY(calc(100% - 52px));
    transition: transform 0.25s ease;
  }
  .inventory.open { transform: translateY(0); }
  .inventory.collapsed .inv-body { display: block; }
  .inv-body { overflow-y: auto; }
  .inv-grid { max-height: none; }
  .inv-toggle { text-align: center; }
  main { padding-bottom: 64px; }
}

/* ---------- reduced motion ---------- */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.001s !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.001s !important;
  }
  .slot.fusing, .result.reveal, .result.fx-zap, .result.fx-flare,
  .result.fx-shake, .result.fx-cosmic, .result.fx-spooky,
  .inv-item.ob-pulse { animation: none !important; }
}
