:root {
  color-scheme: light;
  --ink: #243028;
  --muted: #70776b;
  --wall: #d9d4bd;
  --cream: #f7f2df;
  --orange: #e66b3d;
  --line: rgba(45, 53, 44, 0.18);
  font-family: "Trebuchet MS", "Avenir Next", system-ui, sans-serif;
  touch-action: manipulation;
}

* { box-sizing: border-box; }

html, body { width: 100%; height: 100%; margin: 0; overflow: hidden; }

body {
  color: var(--ink);
  background: var(--wall);
  -webkit-tap-highlight-color: transparent;
  user-select: none;
}

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

.game-shell { position: relative; width: 100%; height: 100%; overflow: hidden; isolation: isolate; }

.game-shell::before {
  position: absolute;
  inset: 0;
  z-index: -1;
  content: "";
  background:
    radial-gradient(circle at 16% 28%, rgba(255,255,255,.26) 0 1px, transparent 2px),
    radial-gradient(circle at 78% 65%, rgba(82,74,54,.10) 0 1px, transparent 2px),
    linear-gradient(116deg, rgba(255,255,255,.12), transparent 32%, rgba(84,76,57,.06));
  background-size: 91px 83px, 137px 119px, 100% 100%;
}

#wall { display: block; width: 100%; height: 100%; cursor: crosshair; }

.topbar {
  position: absolute;
  z-index: 3;
  top: 0;
  left: 0;
  right: 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: max(14px, env(safe-area-inset-top)) max(18px, env(safe-area-inset-right)) 12px max(18px, env(safe-area-inset-left));
  pointer-events: none;
}

.brand { display: flex; gap: 9px; align-items: center; color: var(--ink); text-decoration: none; pointer-events: auto; }
.brand > span:last-child { display: flex; flex-direction: column; line-height: .84; letter-spacing: -.04em; }
.brand b { font-size: 11px; letter-spacing: .2em; }
.brand strong { font-size: 21px; }
.brand-eye { position: relative; width: 38px; height: 28px; border: 3px solid var(--ink); border-radius: 55% 45% 48% 52%; transform: rotate(-8deg); }
.brand-eye::after, .brand-eye i { position: absolute; content: ""; border-radius: 50%; }
.brand-eye::after { width: 12px; height: 12px; left: 11px; top: 5px; background: #f4c64e; }
.brand-eye i { width: 5px; height: 8px; left: 15px; top: 7px; background: var(--ink); }

.top-actions { display: flex; gap: 8px; pointer-events: auto; }
.round-button, .close-button {
  position: relative;
  display: grid;
  place-items: center;
  width: 45px;
  height: 45px;
  border: 1px solid rgba(42,48,39,.18);
  border-radius: 50%;
  background: rgba(247,242,223,.87);
  box-shadow: 0 4px 14px rgba(54,52,39,.12);
  font-size: 20px;
  font-weight: 900;
  cursor: pointer;
}
.round-button em { position: absolute; right: -2px; bottom: -2px; display: grid; place-items: center; min-width: 19px; height: 19px; padding: 0 4px; border-radius: 10px; background: var(--orange); color: white; font-size: 10px; font-style: normal; }
button:active { transform: translateY(1px) scale(.98); }
button:focus-visible, input:focus-visible { outline: 3px solid rgba(230,107,61,.38); outline-offset: 2px; }

.food-tray {
  position: absolute;
  z-index: 4;
  left: 50%;
  bottom: max(14px, env(safe-area-inset-bottom));
  display: grid;
  grid-template-columns: repeat(4, minmax(112px, 1fr));
  gap: 5px;
  width: min(650px, calc(100% - 28px));
  padding: 6px;
  border: 1px solid rgba(56,59,47,.18);
  border-radius: 18px;
  background: rgba(247,242,223,.91);
  box-shadow: 0 10px 32px rgba(60,55,40,.18);
  backdrop-filter: blur(8px);
  transform: translateX(-50%);
}

.food, .add-gecko {
  min-width: 0;
  height: 58px;
  padding: 7px 8px;
  border: 0;
  border-radius: 12px;
  background: transparent;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 9px;
  cursor: pointer;
  transition: background .18s, color .18s, transform .1s;
}
.food > span:last-child, .add-gecko > span:last-child { display: flex; min-width: 0; flex-direction: column; align-items: flex-start; }
.food b, .add-gecko b { font-size: 11px; letter-spacing: .08em; }
.food small, .add-gecko small { color: var(--muted); font-size: 9px; white-space: nowrap; }
.food.selected { background: var(--ink); color: var(--cream); }
.food.selected small { color: rgba(255,255,255,.66); }
.add-gecko { border-left: 1px solid var(--line); }
.add-gecko > span:first-child { font-size: 23px; }

.food-icon { position: relative; display: block; flex: 0 0 28px; width: 28px; height: 28px; }
.worm-icon i { position: absolute; width: 10px; height: 10px; border: 3px solid #c56a5b; border-color: #c56a5b transparent transparent #c56a5b; border-radius: 50%; transform: rotate(35deg); }
.worm-icon i:nth-child(1) { left: 1px; top: 11px; }.worm-icon i:nth-child(2) { left: 9px; top: 5px; transform: rotate(215deg); }.worm-icon i:nth-child(3) { left: 17px; top: 10px; }
.beetle-icon::before { position: absolute; inset: 5px 7px 3px; content: ""; border-radius: 52% 52% 44% 44%; background: #a86535; border: 2px solid #533e2d; }
.beetle-icon::after { position: absolute; width: 2px; height: 17px; left: 13px; top: 7px; content: ""; background: #533e2d; }
.fly-icon::before { position: absolute; width: 9px; height: 15px; left: 10px; top: 8px; content: ""; border-radius: 50%; background: #35433c; }
.fly-icon::after { position: absolute; width: 25px; height: 10px; left: 2px; top: 5px; content: ""; border: 2px solid #829c93; border-radius: 50% 50% 45% 45%; background: rgba(255,255,255,.28); }

.placement-hint, .toast {
  position: absolute;
  z-index: 3;
  left: 50%;
  border-radius: 999px;
  pointer-events: none;
  transform: translateX(-50%);
}
.placement-hint { bottom: max(94px, calc(env(safe-area-inset-bottom) + 86px)); padding: 7px 13px; background: rgba(43,51,43,.74); color: white; font-size: 11px; font-weight: 800; letter-spacing: .05em; transition: opacity .4s; }
.placement-hint.faded { opacity: 0; }
.toast { top: 74px; padding: 9px 16px; background: var(--ink); color: white; font-size: 12px; font-weight: 800; opacity: 0; transition: opacity .2s, transform .2s; transform: translate(-50%, -8px); }
.toast.show { opacity: 1; transform: translate(-50%, 0); }

.overlay { position: fixed; z-index: 10; inset: 0; display: grid; place-items: center; padding: 18px; background: rgba(32,38,31,.42); backdrop-filter: blur(5px); }
.overlay[hidden] { display: none; }
.panel { width: min(440px, 100%); max-height: min(640px, calc(100dvh - 36px)); overflow: auto; padding: 22px; border: 1px solid rgba(57,58,46,.18); border-radius: 24px; background: var(--cream); box-shadow: 0 20px 60px rgba(38,40,32,.28); }
.panel-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 20px; margin-bottom: 20px; }
.panel-head small, form label { color: var(--orange); font-size: 10px; font-weight: 900; letter-spacing: .16em; }
.panel h1 { margin: 2px 0 0; font-size: 28px; letter-spacing: -.04em; }
.close-button { flex: 0 0 auto; width: 38px; height: 38px; box-shadow: none; background: #e9e3cf; }
.roster-list { display: grid; gap: 8px; }
.roster-row { display: grid; grid-template-columns: 38px 1fr auto; align-items: center; gap: 11px; padding: 9px; border-radius: 13px; background: #ebe5d2; }
.swatch { position: relative; width: 36px; height: 24px; border: 2px solid var(--swatch-dark); border-radius: 55% 45% 50% 48%; background: var(--swatch); transform: rotate(-5deg); }
.swatch::after { position: absolute; right: 5px; top: 4px; width: 5px; height: 5px; border-radius: 50%; background: var(--eye); content: ""; }
.gecko-summary { display: flex; min-width: 0; padding: 4px 2px; border: 0; background: transparent; flex-direction: column; align-items: flex-start; text-align: left; cursor: pointer; }
.gecko-summary b { overflow: hidden; max-width: 100%; font-size: 14px; text-decoration: underline; text-decoration-color: rgba(36,48,40,.25); text-underline-offset: 3px; text-overflow: ellipsis; white-space: nowrap; }
.gecko-summary small { color: var(--muted); font-size: 9px; letter-spacing: .035em; text-transform: uppercase; }
.remove-button { width: 31px; height: 31px; border: 0; border-radius: 50%; background: rgba(73,72,58,.09); color: #796f61; cursor: pointer; }
.primary-button { width: 100%; min-height: 49px; margin-top: 14px; border: 0; border-radius: 13px; background: var(--ink); color: white; font-size: 12px; font-weight: 900; letter-spacing: .09em; cursor: pointer; }
.primary-button:disabled { opacity: .4; cursor: default; }
.panel-note { margin: 15px 5px 0; color: var(--muted); font-size: 11px; line-height: 1.45; text-align: center; }
form { display: flex; flex-direction: column; }
form label { margin: 0 2px 7px; }
form input { width: 100%; padding: 14px 15px; border: 2px solid #d8d0bb; border-radius: 13px; background: #fffdf4; color: var(--ink); font-size: 18px; font-weight: 800; outline: none; }
.suggestions { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 10px; }
.suggestions button { padding: 7px 10px; border: 1px solid #d6ceba; border-radius: 999px; background: transparent; color: var(--muted); font-size: 10px; font-weight: 700; cursor: pointer; }
.form-message { min-height: 18px; margin: 9px 3px -4px; color: #b74c35; font-size: 11px; font-weight: 800; }

.bio-panel { width: min(420px, 100%); }
.bio-sex-sign { color: var(--orange); font-size: .82em; }
.bio-details { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin: 0; }
.bio-details div { min-width: 0; padding: 11px 12px; border-radius: 12px; background: #ebe5d2; }
.bio-details dt { margin-bottom: 3px; color: var(--muted); font-size: 8px; font-weight: 900; letter-spacing: .13em; }
.bio-details dd { overflow: hidden; margin: 0; font-size: 13px; font-weight: 900; text-overflow: ellipsis; white-space: nowrap; }
.bio-details .bio-sex-row { grid-column: 1 / -1; }

@media (max-width: 590px) {
  .brand strong { font-size: 18px; }
  .brand-eye { width: 33px; height: 25px; }
  .brand-eye::after { left: 9px; top: 4px; }
  .brand-eye i { left: 13px; top: 6px; }
  .food-tray { grid-template-columns: repeat(4, 1fr); width: calc(100% - 18px); bottom: max(8px, env(safe-area-inset-bottom)); }
  .food, .add-gecko { height: 60px; flex-direction: column; gap: 2px; padding: 4px 2px; }
  .food > span:last-child, .add-gecko > span:last-child { align-items: center; }
  .food small, .add-gecko small { display: none; }
  .food-icon { flex-basis: 25px; height: 25px; transform: scale(.84); }
  .add-gecko > span:first-child { height: 25px; }
  .placement-hint { bottom: max(82px, calc(env(safe-area-inset-bottom) + 73px)); }
}

@media (prefers-reduced-motion: reduce) {
  .toast, .placement-hint, .food { transition: none; }
}
