:root {
  color-scheme: light;
  --paper: rgba(255, 248, 240, 0.94);
  --ink: #2c2416;
  --muted: #6d6256;
  --gold: #d4a017;
  --line: rgba(44, 36, 22, 0.12);
  --shadow: 0 12px 32px rgba(24, 16, 8, 0.28);
  --red: #c0392b;
  --green: #1e8c45;
  --yellow: #b8860b;
  --gray: #5c6770;
  font-family: "Segoe UI", system-ui, sans-serif;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  background: #1b2438;
  color: var(--ink);
}

button, select {
  font: inherit;
  color: inherit;
  touch-action: manipulation;
}

button {
  min-height: 44px;
  border: 0;
  border-radius: 999px;
  padding: 0 14px;
  background: var(--paper);
  box-shadow: var(--shadow);
  cursor: pointer;
}

button:focus-visible, select:focus-visible, a:focus-visible {
  outline: 3px solid var(--gold);
  outline-offset: 2px;
}

#scene {
  position: fixed;
  inset: 0;
}

#scene canvas {
  display: block;
  width: 100%;
  height: 100%;
  touch-action: none;
}

.hud {
  position: fixed;
  z-index: 2;
  pointer-events: none;
}

.hud > * { pointer-events: auto; }

#topbar {
  top: 0;
  left: 0;
  right: 0;
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 10px;
  padding: calc(8px + env(safe-area-inset-top)) 12px 0;
}

.brand {
  flex: 1;
  min-width: 0;
}

.brand h1 {
  margin: 0;
  font-family: Palatino, "Iowan Old Style", Georgia, serif;
  font-size: 1.35rem;
  letter-spacing: -0.02em;
  color: #fffaf3;
  text-shadow: 0 2px 10px rgba(0, 0, 0, 0.45);
}

.meta {
  margin: 2px 0 0;
  color: #fff6e8;
  font-size: 0.78rem;
  line-height: 1.35;
  text-shadow: 0 1px 6px rgba(0, 0, 0, 0.55);
}

#needs-btn { white-space: nowrap; flex: 0 0 auto; }

#needs-btn {
  background: #fffaf3;
  display: flex;
  align-items: center;
  gap: 8px;
  font-weight: 700;
}

#needs-btn .count {
  min-width: 1.6rem;
  height: 1.6rem;
  border-radius: 999px;
  display: grid;
  place-items: center;
  background: #efe6d6;
}

#needs-btn.has-needs {
  background: var(--red);
  color: white;
}

#needs-btn.has-needs .count { background: rgba(255, 255, 255, 0.2); }

@media (prefers-reduced-motion: no-preference) {
  #needs-btn.has-needs { animation: needs-pulse 1.5s ease-in-out infinite; }
}

@keyframes needs-pulse {
  50% { transform: scale(1.04); }
}

#teams {
  top: calc(68px + env(safe-area-inset-top));
  left: 0;
  right: 0;
  display: flex;
  gap: 6px;
  overflow-x: auto;
  padding: 6px 12px 8px;
  scrollbar-width: none;
}

#teams::-webkit-scrollbar { display: none; }

.chip {
  flex: 0 0 auto;
  min-height: 36px;
  padding: 0 12px;
  border-radius: 999px;
  border: 0;
  font-size: 0.82rem;
  font-weight: 700;
  box-shadow: var(--shadow);
}

#dock {
  left: 50%;
  bottom: calc(10px + env(safe-area-inset-bottom));
  transform: translateX(-50%);
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 6px;
  width: max-content;
  max-width: calc(100% - 16px);
}

#dock select, #help, #quality, #refresh, #reset {
  background: var(--paper);
  box-shadow: var(--shadow);
}

#dock select {
  min-height: 44px;
  border-radius: 999px;
  border: 0;
  padding: 0 12px;
}

#help-pop, #needs-panel, #card, #motto-banner, #toast, #fatal {
  position: fixed;
  z-index: 3;
  background: var(--paper);
  color: var(--ink);
  box-shadow: var(--shadow);
}

#help-pop {
  right: 12px;
  bottom: calc(64px + env(safe-area-inset-bottom));
  width: min(280px, calc(100% - 24px));
  border-radius: 16px;
  padding: 12px 14px;
  font-size: 0.9rem;
  line-height: 1.4;
}

#needs-panel {
  top: calc(112px + env(safe-area-inset-top));
  right: 12px;
  width: min(340px, calc(100% - 24px));
  max-height: min(48vh, 420px);
  overflow: auto;
  border-radius: 18px;
  padding: 12px;
}

#needs-panel h2 {
  margin: 0 0 8px;
  font-size: 1rem;
}

#needs-list { list-style: none; margin: 0; padding: 0; display: grid; gap: 6px; }

#needs-list button {
  width: 100%;
  border-radius: 12px;
  background: white;
  text-align: left;
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 2px;
  padding: 8px 12px;
  box-shadow: none;
  border: 1px solid var(--line);
}

#needs-list span { color: var(--muted); font-size: 0.82rem; }

#needs-empty { margin: 0; color: var(--muted); }

#card {
  z-index: 5;
  left: 50%;
  bottom: calc(12px + env(safe-area-inset-bottom));
  transform: translateX(-50%);
  width: min(420px, calc(100% - 20px));
  border-radius: 22px;
  padding: 14px;
  display: grid;
  grid-template-columns: 76px 1fr;
  gap: 12px;
}

body.card-open #walk-pad { display: none; }

#card[hidden] { display: none; }

#card img {
  width: 76px;
  height: 76px;
  border-radius: 50%;
  object-fit: cover;
  background: #efe6d6;
}

#card h2 { margin: 0; font-size: 1.15rem; }

#card p { margin: 3px 0; }

.team-pill, .status-pill {
  display: inline-block;
  border-radius: 999px;
  padding: 2px 8px;
  font-size: 0.75rem;
  font-weight: 700;
}

.status-working { background: #d9f5e4; color: var(--green); }
.status-needs_kyle { background: #ffe1d6; color: var(--red); }
.status-idle { background: #fff3cc; color: #8a6a08; }
.status-paused { background: #e6eaee; color: var(--gray); }

.note { color: var(--muted); font-size: 0.92rem; }

.question {
  margin: 8px 0;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  max-height: 34vh;
  overflow: auto;
}

#card-reply {
  display: inline-block;
  margin-top: 6px;
  min-height: 44px;
  line-height: 44px;
  padding: 0 12px;
  border-radius: 999px;
  background: #2c2416;
  color: #fff6e8;
  text-decoration: none;
  font-weight: 700;
}

#card-reply[hidden] { display: none; }

#walk-pad {
  position: fixed;
  z-index: 4;
  right: calc(10px + env(safe-area-inset-right));
  bottom: calc(156px + env(safe-area-inset-bottom));
  display: grid;
  grid-template-columns: 52px 52px 52px;
  gap: 6px;
}

@media (min-width: 800px) {
  #walk-pad { bottom: calc(16px + env(safe-area-inset-bottom)); }
}

#walk-pad[hidden] { display: none; }

#walk-pad button {
  width: 52px;
  height: 52px;
  min-height: 52px;
  padding: 0;
  font-size: 1.2rem;
  border-radius: 16px;
  background: rgba(255, 248, 240, 0.92);
}

#card-close {
  position: absolute;
  top: 8px;
  right: 8px;
  width: 44px;
  padding: 0;
  background: transparent;
  box-shadow: none;
  font-size: 1.3rem;
}

#motto-banner, #toast {
  left: 50%;
  top: calc(118px + env(safe-area-inset-top));
  transform: translateX(-50%);
  width: min(520px, calc(100% - 24px));
  border-radius: 16px;
  padding: 12px 14px;
  text-align: center;
}

#motto-banner strong { display: block; font-size: 1.05rem; }
#motto-banner span, #toast { font-size: 0.95rem; }

#loader, #fatal {
  position: fixed;
  inset: 0;
  z-index: 5;
  display: grid;
  place-items: center;
  background: #1b2438;
  color: #fff6e8;
  text-align: center;
  padding: 24px;
}

#loader[hidden], #fatal[hidden] { display: none; }

#loader p, #fatal p {
  font-family: Palatino, Georgia, serif;
  font-size: 1.6rem;
}

#fatal { z-index: 6; }

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

@media (max-width: 760px) {
  #teams { top: calc(112px + env(safe-area-inset-top)); }
  .brand h1 { font-size: 1.2rem; }
  .meta { font-size: 0.74rem; }
}

@media (min-width: 800px) {
  .brand h1 { font-size: 1.7rem; }
  #teams { top: calc(74px + env(safe-area-inset-top)); }
  #card {
    top: auto;
    bottom: 78px;
    left: 24px;
    transform: none;
  }
}
