@import url('https://fonts.googleapis.com/css2?family=DM+Mono:wght@400;500&family=Unbounded:wght@500;650&display=swap');

:root {
  color-scheme: dark;
  --ink: #f1eadc;
  --muted: #9f96a8;
  --bg: #0d0914;
  --panel: #171020;
  --panel-2: #20162b;
  --line: #3c2b48;
  --violet: #b482d0;
  --violet-bright: #d4a5ef;
  --acid: #c9dc75;
  --danger: #ef735f;
  --shadow: 0 18px 60px rgba(0, 0, 0, .35);
  --radius: 18px;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

html { scroll-behavior: smooth; }

body {
  margin: 0;
  min-width: 320px;
  min-height: 100vh;
  overflow-x: hidden;
  background:
    radial-gradient(circle at 50% -10%, rgba(126, 71, 152, .25), transparent 36rem),
    var(--bg);
  color: var(--ink);
  font-family: "DM Mono", ui-monospace, SFMono-Regular, Consolas, monospace;
  line-height: 1.45;
}

button { font: inherit; }
button, summary, .supply-row { -webkit-tap-highlight-color: transparent; }
button:focus-visible, summary:focus-visible, a:focus-visible {
  outline: 3px solid var(--acid);
  outline-offset: 3px;
}

.grain {
  position: fixed;
  inset: 0;
  z-index: -1;
  pointer-events: none;
  opacity: .16;
  background-image: url("data:image/svg+xml,%3Csvg viewBox='0 0 180 180' xmlns='http://www.w3.org/2000/svg'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='.82' numOctaves='3' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)' opacity='.28'/%3E%3C/svg%3E");
}

.game-shell {
  width: min(100% - 28px, 720px);
  margin: 0 auto;
  padding: 22px 0 118px;
}

.game-header {
  display: grid;
  grid-template-columns: 42px 1fr 42px;
  gap: 12px;
  align-items: center;
  margin-bottom: 18px;
}

.game-header h1, .section-heading h2, .drawer-heading h2, dialog h2 {
  margin: 0;
  font-family: "Unbounded", system-ui, sans-serif;
  letter-spacing: -.045em;
  line-height: 1.05;
}

.game-header h1 { font-size: clamp(1.35rem, 6vw, 2.1rem); }
.kicker, .eyebrow {
  margin: 0 0 4px;
  color: var(--violet-bright);
  font-size: .69rem;
  font-weight: 500;
  letter-spacing: .13em;
  text-transform: uppercase;
}

.back-link, .icon-button {
  display: grid;
  width: 42px;
  height: 42px;
  place-items: center;
  border: 1px solid var(--line);
  border-radius: 50%;
  background: rgba(23, 16, 32, .75);
  color: var(--ink);
  text-decoration: none;
  cursor: pointer;
}

.creature-panel {
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 26px;
  background: linear-gradient(160deg, rgba(39, 24, 51, .88), rgba(13, 9, 20, .96));
  box-shadow: var(--shadow);
}

.creature-wrap {
  position: relative;
  height: clamp(150px, 26vh, 225px);
  overflow: hidden;
  transition: transform .25s ease, filter .25s ease;
}

.creature-wrap::after {
  position: absolute;
  inset: auto 0 0;
  height: 50%;
  background: linear-gradient(transparent, rgba(13, 9, 20, .86));
  content: "";
}

.creature-wrap img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  transform: scale(1.08);
}

.creature-wrap.urgent { animation: anxious 1s ease-in-out infinite; filter: saturate(1.35); }
.creature-wrap.fed { animation: pleased .7s ease; }
.creature-wrap.angry { animation: angry .45s ease; filter: hue-rotate(-30deg) saturate(2); }

@keyframes anxious { 50% { transform: scale(1.018); } }
@keyframes pleased { 40% { transform: scaleY(.91) scaleX(1.035); } }
@keyframes angry { 20%, 60% { transform: translateX(-9px) scale(1.02); } 40%, 80% { transform: translateX(9px) scale(1.02); } }

.food-flight {
  position: absolute;
  z-index: 3;
  left: 50%;
  bottom: -30px;
  font-size: 3rem;
  opacity: 0;
  transform: translate(-50%, 0) scale(1);
}
.food-flight.go { animation: feed-flight .7s cubic-bezier(.2, .7, .4, 1) forwards; }
@keyframes feed-flight {
  0% { opacity: 0; transform: translate(-50%, 20px) scale(.65) rotate(-12deg); }
  20% { opacity: 1; }
  80% { opacity: 1; transform: translate(-50%, -95px) scale(1.15) rotate(8deg); }
  100% { opacity: 0; transform: translate(-50%, -125px) scale(.08); }
}

.request-card {
  position: relative;
  z-index: 4;
  padding: 4px 18px 18px;
}

.request-topline, .timer-row, .section-heading, .drawer-heading, .tool-topline {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
}

.patience { display: flex; gap: 6px; }
.patience-pip {
  width: 20px;
  height: 11px;
  border: 1px solid var(--violet);
  border-radius: 50% 50% 45% 45%;
  background: var(--ink);
  box-shadow: inset 0 0 0 4px var(--bg);
  transform: rotate(-3deg);
}
.patience-pip:nth-child(2) { transform: rotate(4deg) translateY(-2px); }
.patience-pip.empty { background: transparent; box-shadow: none; opacity: .35; }

.demand-title {
  margin: 8px 0 3px;
  font-family: "Unbounded", system-ui, sans-serif;
  font-size: clamp(1.35rem, 6vw, 2rem);
  letter-spacing: -.04em;
  line-height: 1.13;
}
.demand-icon { margin-right: .25em; filter: drop-shadow(0 5px 10px rgba(0,0,0,.3)); }
.demand-progress { margin: 0 0 15px; color: var(--muted); font-size: .78rem; text-transform: uppercase; }

.timer-row { margin-bottom: 13px; }
.timer { min-width: 52px; color: var(--ink); font-weight: 500; }
.timer-track { flex: 1; height: 7px; overflow: hidden; border-radius: 10px; background: #33253d; }
.timer-track span { display: block; width: 100%; height: 100%; background: var(--acid); transform-origin: left; transition: transform .2s linear, background .2s; }
.timer-track span.urgent { background: var(--danger); }

.feed-button, .action-button {
  width: 100%;
  min-height: 58px;
  border: 0;
  border-radius: 14px;
  background: var(--acid);
  box-shadow: 0 5px 0 #74803f;
  color: #171c09;
  font-weight: 500;
  letter-spacing: .045em;
  cursor: pointer;
  touch-action: manipulation;
  transition: transform .08s, box-shadow .08s, filter .15s;
}
.feed-button:active, .action-button:active, .action-button.pressed { transform: translateY(4px); box-shadow: 0 1px 0 #74803f; }
.feed-button:disabled, .action-button:disabled { background: #3b3340; box-shadow: none; color: #7d7482; cursor: not-allowed; }

.run-stats {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  margin: 14px 0;
  border: 1px solid var(--line);
  border-radius: 16px;
  background: rgba(23, 16, 32, .82);
}
.run-stats div { min-width: 0; padding: 11px 8px; text-align: center; }
.run-stats div + div { border-left: 1px solid var(--line); }
.run-stats span { display: block; color: var(--muted); font-size: .59rem; letter-spacing: .08em; text-transform: uppercase; }
.run-stats strong { display: block; overflow: hidden; font-size: .9rem; text-overflow: ellipsis; }

.panel, .production-area { scroll-margin-top: 14px; }
.panel {
  margin: 14px 0 22px;
  padding: 18px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: rgba(23, 16, 32, .82);
}
.section-heading h2, .drawer-heading h2 { font-size: 1.35rem; }

.segmented { display: flex; padding: 3px; border: 1px solid var(--line); border-radius: 10px; }
.segmented button { border: 0; border-radius: 7px; padding: 7px 9px; background: transparent; color: var(--muted); font-size: .68rem; cursor: pointer; }
.segmented button.active { background: var(--violet); color: #140c19; }

.supplies-list { display: grid; gap: 7px; margin-top: 15px; }
.supply-row {
  display: grid;
  grid-template-columns: 28px 1fr auto;
  gap: 9px;
  align-items: center;
  width: 100%;
  min-height: 44px;
  padding: 8px 10px;
  border: 1px solid transparent;
  border-radius: 10px;
  background: #120d19;
  color: var(--ink);
  text-align: left;
  cursor: pointer;
}
.supply-row:hover { border-color: var(--line); }
.supply-row strong { font-size: .79rem; }
.supply-row small { display: block; color: var(--muted); font-size: .66rem; }
.supply-row .count { color: var(--acid); font-size: .75rem; text-align: right; }
.supply-row.missing .count { color: var(--danger); }
.empty-note { margin: 16px 0 2px; color: var(--muted); font-size: .78rem; }

.production-heading { margin-top: 30px; }
.small-button {
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 9px 11px;
  background: var(--panel);
  color: var(--ink);
  font-size: .7rem;
  cursor: pointer;
}
.section-note { margin: 8px 0 18px; color: var(--muted); font-size: .72rem; }
.family-section { margin: 25px 0 32px; scroll-margin-top: 12px; }
.family-title {
  display: flex;
  align-items: center;
  gap: 10px;
  margin: 0 0 10px;
  color: var(--violet-bright);
  font-family: "Unbounded", system-ui, sans-serif;
  font-size: .72rem;
  letter-spacing: .09em;
  text-transform: uppercase;
}
.family-title::after { flex: 1; height: 1px; background: var(--line); content: ""; }
.resource-grid { display: grid; gap: 10px; }
.resource-card {
  scroll-margin-top: 14px;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 16px;
  background: linear-gradient(145deg, rgba(32, 22, 43, .96), rgba(20, 14, 27, .96));
}
.resource-top { display: grid; grid-template-columns: 43px 1fr auto; gap: 10px; align-items: center; margin-bottom: 12px; }
.resource-icon { display: grid; width: 43px; height: 43px; place-items: center; border: 1px solid var(--line); border-radius: 12px; background: #100b17; font-size: 1.4rem; }
.resource-name { margin: 0; font-size: .84rem; font-weight: 500; }
.resource-tool { display: block; margin-top: 2px; color: var(--muted); font-size: .62rem; }
.stored { text-align: right; }
.stored strong { display: block; font-size: 1rem; }
.stored span { color: var(--muted); font-size: .59rem; text-transform: uppercase; }
.action-button { min-height: 52px; font-size: .76rem; }

.recipe { margin-top: 10px; font-size: .7rem; }
.recipe summary { color: var(--muted); cursor: pointer; list-style: none; }
.recipe summary::before { margin-right: 7px; content: "+"; color: var(--violet-bright); }
.recipe[open] summary::before { content: "−"; }
.recipe-list { display: grid; gap: 5px; margin: 9px 0 0; padding: 10px; border-radius: 9px; background: #100b17; }
.recipe-row { display: flex; justify-content: space-between; gap: 10px; }
.recipe-row .insufficient { color: var(--danger); }

.resource-card.pop .stored strong { animation: number-pop .25s ease; }
@keyframes number-pop { 50% { color: var(--acid); transform: scale(1.12); } }
.floating-gain { position: fixed; z-index: 30; pointer-events: none; color: var(--acid); font-weight: 500; animation: float-up .75s ease forwards; }
@keyframes float-up { to { opacity: 0; transform: translateY(-42px); } }

.bottom-nav {
  position: fixed;
  z-index: 20;
  right: 0;
  bottom: 0;
  left: 0;
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  padding: 8px max(8px, env(safe-area-inset-right)) calc(8px + env(safe-area-inset-bottom)) max(8px, env(safe-area-inset-left));
  border-top: 1px solid var(--line);
  background: rgba(13, 9, 20, .94);
  box-shadow: 0 -10px 35px rgba(0,0,0,.3);
  backdrop-filter: blur(15px);
}
.bottom-nav button { position: relative; border: 0; padding: 6px 3px; background: transparent; color: var(--muted); font-size: .61rem; cursor: pointer; }
.bottom-nav button span { display: block; margin-bottom: 1px; color: var(--ink); font-size: 1.15rem; }
.bottom-nav b { position: absolute; top: 1px; left: calc(50% + 8px); display: grid; width: 15px; height: 15px; place-items: center; border-radius: 50%; background: var(--danger); color: white; font-size: .55rem; }

.drawer-backdrop { position: fixed; z-index: 39; inset: 0; background: rgba(3,2,5,.68); backdrop-filter: blur(3px); }
.tools-drawer {
  position: fixed;
  z-index: 40;
  right: 0;
  bottom: 0;
  left: 0;
  max-height: min(84vh, 760px);
  overflow: auto;
  padding: 10px max(18px, calc((100vw - 690px) / 2)) calc(28px + env(safe-area-inset-bottom));
  border: 1px solid var(--line);
  border-radius: 24px 24px 0 0;
  background: #15101d;
  box-shadow: 0 -24px 80px rgba(0,0,0,.55);
  transform: translateY(105%);
  visibility: hidden;
  transition: transform .3s cubic-bezier(.2,.8,.2,1), visibility .3s;
}
.tools-drawer.open { transform: translateY(0); visibility: visible; }
.drawer-handle { width: 42px; height: 4px; margin: 0 auto 14px; border-radius: 3px; background: var(--line); }
.drawer-balance { margin: 14px 0 12px; color: var(--muted); font-size: .72rem; }
.drawer-balance strong { color: var(--acid); }
.tools-list { display: grid; gap: 10px; }
.tool-card { padding: 14px; border: 1px solid var(--line); border-radius: 14px; background: var(--panel-2); }
.tool-family { margin: 0; color: var(--violet-bright); font-size: .63rem; letter-spacing: .1em; text-transform: uppercase; }
.current-tool { margin: 4px 0 9px; font-weight: 500; }
.next-tool { display: grid; grid-template-columns: 1fr auto; gap: 12px; align-items: center; padding-top: 10px; border-top: 1px solid var(--line); }
.next-tool p { margin: 0; font-size: .76rem; }
.next-tool small { display: block; margin-top: 2px; color: var(--muted); font-size: .63rem; }
.buy-button { min-width: 86px; border: 0; border-radius: 9px; padding: 10px; background: var(--violet); color: #160b1b; font-size: .69rem; font-weight: 500; cursor: pointer; }
.buy-button:disabled { background: #3a3040; color: #786e7e; cursor: not-allowed; }
.maxed { color: var(--muted); font-size: .7rem; }

dialog {
  width: min(90vw, 520px);
  border: 1px solid var(--line);
  border-radius: 20px;
  padding: 24px;
  background: #171020;
  box-shadow: var(--shadow);
  color: var(--ink);
}
dialog::backdrop { background: rgba(4, 2, 7, .82); backdrop-filter: blur(5px); }
.info-dialog ol { padding-left: 1.4rem; color: #d2c8d4; font-size: .82rem; }
.info-dialog li + li { margin-top: 8px; }
.info-dialog > p:last-child { color: var(--muted); font-size: .75rem; }
.dialog-close { float: right; border: 0; background: transparent; color: var(--muted); font-size: 1.5rem; cursor: pointer; }
.game-over-dialog { text-align: center; }
.game-over-dialog h2 { margin: 8px auto 20px; max-width: 390px; font-size: 1.55rem; }
.summary-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin: 18px 0 22px; }
.summary-grid div { padding: 12px 8px; border-radius: 10px; background: #100b17; }
.summary-grid span { display: block; color: var(--muted); font-size: .6rem; text-transform: uppercase; }
.summary-grid strong { font-size: .9rem; }

.toast-stack { position: fixed; z-index: 60; top: 14px; right: 14px; left: 14px; display: grid; gap: 8px; pointer-events: none; }
.toast { max-width: 520px; margin: 0 auto; padding: 11px 14px; border: 1px solid var(--violet); border-radius: 11px; background: #21162a; box-shadow: var(--shadow); color: var(--ink); font-size: .72rem; animation: toast-in .3s ease, toast-out .3s ease 2.7s forwards; }
.toast strong { color: var(--violet-bright); }
@keyframes toast-in { from { opacity: 0; transform: translateY(-12px); } }
@keyframes toast-out { to { opacity: 0; transform: translateY(-8px); } }

.game-footer { display: flex; align-items: center; justify-content: center; gap: 9px; margin: 50px 0 5px; color: var(--muted); font-size: .66rem; }
.game-footer img { width: 24px; height: 24px; opacity: .65; }
.fatal-error { padding: 30px; border: 1px solid var(--danger); border-radius: 14px; background: #29151d; color: #ffb5aa; }

@media (min-width: 620px) {
  .game-shell { padding-top: 34px; }
  .resource-grid { grid-template-columns: 1fr 1fr; }
  .resource-card { display: flex; flex-direction: column; }
  .resource-card .action-button { margin-top: auto; }
  .toast-stack { left: auto; width: 360px; }
}

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