/* CompanionLand — web client. Palette: a map at dusk. Warm paper, layered
   greens, one amber accent for pets and pins. Light/dark via
   prefers-color-scheme. No horizontal scroll anywhere. */

:root {
  --paper: #f2ede0;
  --paper-2: #e9e2d0;
  --ink: #262a20;
  --muted: #6d715f;
  --line: #d9d0b8;
  --panel: #faf7ee;
  --panel-2: #f0ead9;
  --green-1: #7f9b6a;   /* park / grass, light */
  --green-2: #52704a;   /* district tile fill */
  --green-3: #35492f;   /* district tile border / deep shade */
  --water: #4c6a72;
  --accent: #d97a3f;    /* pins, pets, primary actions */
  --accent-ink: #fff8ef;
  --cat: #5b84a3;       /* species colour: cats */
  --dog: #d97a3f;       /* species colour: dogs (= accent) */
  --danger: #b3492f;
  --shadow: rgba(38, 42, 32, 0.18);
  --font-display: "Fraunces", Georgia, "Iowan Old Style", serif;
  --font-body: "Inter", system-ui, -apple-system, "Segoe UI", sans-serif;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --paper: #1c1f18;
    --paper-2: #23271d;
    --ink: #ece6d4;
    --muted: #9a9d87;
    --line: #3a3f2f;
    --panel: #23271e;
    --panel-2: #2a2f22;
    --green-1: #5c7a52;
    --green-2: #3c5536;
    --green-3: #22301e;
    --water: #395059;
    --accent: #e69257;
    --accent-ink: #241505;
    --cat: #7fa6c4;
    --dog: #e69257;
    --danger: #e08066;
    --shadow: rgba(0, 0, 0, 0.45);
  }
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { height: 100%; margin: 0; overflow: hidden; }
body {
  background: var(--paper);
  color: var(--ink);
  font: 400 14px/1.5 var(--font-body);
  display: flex;
  flex-direction: column;
}
h1, h2, h3 { font-family: var(--font-display); font-weight: 650; margin: 0 0 4px; letter-spacing: -0.01em; }
button { font-family: var(--font-body); }
p { margin: 0 0 8px; }
.muted { color: var(--muted); }
::selection { background: var(--accent); color: var(--accent-ink); }

/* ---------------------------------------------------------------- topbar */
#topbar {
  flex: none;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 18px;
  background: var(--panel);
  border-bottom: 1px solid var(--line);
  z-index: 20;
}
#brand { display: flex; align-items: baseline; gap: 12px; min-width: 0; }
#homeBtn {
  font-family: var(--font-display);
  font-size: 19px;
  font-weight: 650;
  color: var(--ink);
  background: none;
  border: none;
  cursor: pointer;
  padding: 2px 0;
  letter-spacing: -0.01em;
}
#homeBtn:hover { color: var(--accent); }
#crumb { color: var(--muted); font-size: 13px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
#topActions { display: flex; gap: 8px; flex: none; }

button.ghost, button.primary, button.secondary {
  border-radius: 8px;
  border: 1px solid var(--line);
  padding: 7px 14px;
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  background: var(--panel-2);
  color: var(--ink);
  transition: background 0.15s, border-color 0.15s, transform 0.1s;
}
button.ghost:hover { border-color: var(--accent); }
button.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
button.primary:hover { filter: brightness(1.06); }
button.primary:active, button.ghost:active, button.secondary:active { transform: translateY(1px); }
button.secondary { background: transparent; }
button:disabled { opacity: 0.5; cursor: default; }

/* ---------------------------------------------------------------- stage */
#stage { position: relative; flex: 1; min-height: 0; overflow: hidden; background: var(--paper); }
canvas.layer { position: absolute; inset: 0; width: 100%; height: 100%; display: block; }

#backBtn {
  position: absolute;
  top: 14px; left: 14px;
  z-index: 10;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: var(--panel);
  color: var(--ink);
  padding: 7px 16px 7px 12px;
  font-size: 13px;
  cursor: pointer;
  box-shadow: 0 2px 10px var(--shadow);
}
#backBtn:hover { border-color: var(--accent); }

#stageHint {
  position: absolute;
  right: 14px; bottom: 14px;
  z-index: 5;
  font-size: 11.5px;
  color: var(--muted);
  background: color-mix(in srgb, var(--panel) 78%, transparent);
  padding: 4px 9px;
  border-radius: 6px;
  pointer-events: none;
  max-width: calc(100% - 28px);
}

#tooltip {
  position: absolute;
  z-index: 15;
  pointer-events: none;
  background: var(--ink);
  color: var(--paper);
  font-size: 12px;
  font-weight: 500;
  padding: 4px 9px;
  border-radius: 6px;
  transform: translate(-50%, -130%);
  white-space: nowrap;
  box-shadow: 0 2px 8px var(--shadow);
}

#loading {
  position: absolute; inset: 0; z-index: 30;
  display: flex; align-items: center; justify-content: center;
  background: color-mix(in srgb, var(--paper) 70%, transparent);
  font-family: var(--font-display);
  font-size: 15px; color: var(--muted);
}

/* ---------------------------------------------------------------- toasts */
#toasts {
  position: fixed;
  left: 16px; bottom: 16px;
  z-index: 40;
  display: flex;
  flex-direction: column-reverse;
  gap: 6px;
  max-width: 320px;
  pointer-events: none;
}
.toast {
  background: var(--panel);
  border: 1px solid var(--line);
  border-left: 3px solid var(--accent);
  color: var(--ink);
  padding: 8px 12px;
  border-radius: 8px;
  font-size: 12.5px;
  box-shadow: 0 4px 16px var(--shadow);
  animation: toastIn 0.25s ease-out;
}
.toast.out { animation: toastOut 0.35s ease-in forwards; }
@keyframes toastIn { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }
@keyframes toastOut { to { opacity: 0; transform: translateX(-8px); } }

/* ---------------------------------------------------------------- panels */
.panel {
  position: fixed;
  top: 0; right: 0; bottom: 0;
  width: 380px;
  max-width: 92vw;
  background: var(--panel);
  border-left: 1px solid var(--line);
  box-shadow: -8px 0 24px var(--shadow);
  padding: 18px 20px 24px;
  overflow-y: auto;
  transform: translateX(100%);
  transition: transform 0.28s cubic-bezier(.2,.8,.2,1);
  z-index: 50;
}
.panel.open { transform: translateX(0); }
.panelClose {
  position: absolute; top: 12px; right: 14px;
  background: none; border: none; font-size: 22px; line-height: 1;
  color: var(--muted); cursor: pointer; padding: 4px;
}
.panelClose:hover { color: var(--ink); }

.overlay {
  position: fixed; inset: 0; z-index: 60;
  background: color-mix(in srgb, var(--ink) 45%, transparent);
  display: flex; align-items: center; justify-content: center;
  padding: 24px;
}
#createModal {
  position: relative;
  background: var(--panel);
  border-radius: 14px;
  border: 1px solid var(--line);
  width: 560px;
  max-width: 100%;
  max-height: 88vh;
  overflow-y: auto;
  padding: 24px 26px 26px;
  box-shadow: 0 20px 60px var(--shadow);
}

/* ---------------------------------------------------------------- pet card */
.petHead { display: flex; gap: 12px; align-items: center; margin-bottom: 10px; }
.petAvatar {
  width: 46px; height: 46px; border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  font-family: var(--font-display); font-weight: 650; font-size: 18px;
  color: var(--accent-ink); flex: none;
}
.petAvatar.cat { background: var(--cat); }
.petAvatar.dog { background: var(--dog); }
.petHead h2 { font-size: 20px; }
.petSub { font-size: 12.5px; color: var(--muted); }
.petTag {
  display: inline-block; font-size: 10.5px; font-weight: 600; text-transform: uppercase;
  letter-spacing: 0.04em; color: var(--accent-ink); background: var(--accent);
  padding: 2px 7px; border-radius: 999px; margin-left: 6px; vertical-align: 1px;
}
.section { margin: 16px 0; }
.section h3 { font-size: 12.5px; text-transform: uppercase; letter-spacing: 0.05em; color: var(--muted); font-weight: 600; margin-bottom: 8px; }
.personality { font-style: italic; color: var(--ink); font-family: var(--font-display); font-size: 15px; line-height: 1.45; }

.barRow { display: grid; grid-template-columns: 92px 1fr 30px; align-items: center; gap: 8px; font-size: 12px; margin-bottom: 5px; }
.barTrack { height: 7px; border-radius: 999px; background: var(--paper-2); border: 1px solid var(--line); overflow: hidden; }
.barFill { height: 100%; background: var(--green-2); border-radius: 999px; }
.barFill.accent { background: var(--accent); }
.barVal { text-align: right; color: var(--muted); font-variant-numeric: tabular-nums; }

.moodBar .barTrack { height: 10px; }
.chipRow { display: flex; flex-wrap: wrap; gap: 6px; }
.chip {
  font-size: 12px; padding: 4px 10px; border-radius: 999px;
  background: var(--panel-2); border: 1px solid var(--line); color: var(--ink);
}
.eventList { display: flex; flex-direction: column; gap: 7px; }
.eventRow { font-size: 12.5px; display: flex; gap: 8px; }
.eventTime { color: var(--muted); flex: none; font-variant-numeric: tabular-nums; width: 62px; }
.diaryBox {
  background: var(--panel-2); border: 1px solid var(--line); border-radius: 10px;
  padding: 12px 14px; font-size: 13px; line-height: 1.5;
}
.diaryBox .notif { margin-top: 8px; font-size: 12px; color: var(--muted); }
.blurb { font-size: 13px; line-height: 1.55; color: var(--ink); }
.cardActions { display: flex; gap: 8px; margin-top: 16px; }
.confirmBox {
  margin-top: 10px; padding: 12px 14px; border-radius: 10px;
  background: var(--panel-2); border: 1px solid var(--accent); font-size: 13px; line-height: 1.5;
}

/* ---------------------------------------------------------------- strays */
.strayCard {
  border: 1px solid var(--line); border-radius: 10px; padding: 12px 14px;
  margin-bottom: 10px; background: var(--panel-2);
}
.strayCard .strayTop { display: flex; justify-content: space-between; align-items: baseline; gap: 8px; }
.strayCard h4 { font-family: var(--font-display); font-size: 15px; margin: 0; }
.strayCard .blurb { margin: 6px 0 10px; }
.strayCard .strayActions { display: flex; gap: 8px; }

/* ---------------------------------------------------------------- create form */
.field { margin-bottom: 14px; }
.field label { display: block; font-size: 12.5px; font-weight: 600; color: var(--muted); margin-bottom: 5px; }
.field input[type=text], .field select {
  width: 100%; padding: 8px 10px; border-radius: 8px; border: 1px solid var(--line);
  background: var(--paper); color: var(--ink); font: 13.5px var(--font-body);
}
.stageRow { display: flex; gap: 8px; flex-wrap: wrap; }
.stageOpt {
  border: 1px solid var(--line); border-radius: 8px; padding: 7px 13px; font-size: 13px;
  cursor: pointer; background: var(--paper); color: var(--ink);
}
.stageOpt.selected { border-color: var(--accent); background: var(--accent); color: var(--accent-ink); }
.qIntro { font-size: 13px; line-height: 1.5; background: var(--panel-2); border-radius: 10px; padding: 12px 14px; margin-bottom: 14px; }
.qRow { margin-bottom: 14px; }
.qText { font-size: 13px; margin-bottom: 6px; }
.likert { display: flex; gap: 6px; }
.likert button {
  flex: 1; padding: 7px 0; border-radius: 7px; border: 1px solid var(--line);
  background: var(--paper); color: var(--muted); cursor: pointer; font-size: 12.5px;
}
.likert button.selected { background: var(--green-2); border-color: var(--green-2); color: #fff; }
.formActions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 18px; }
.formError { color: var(--danger); font-size: 12.5px; margin-top: 8px; }

/* ---------------------------------------------------------------- misc */
@media (max-width: 640px) {
  .panel, #createModal { width: 100%; max-width: 100vw; }
  #topbar { padding: 8px 12px; }
  #crumb { display: none; }
  /* On a narrow phone the toast stack (bottom-left) can grow tall enough to
     collide with the persistent stage hint (bottom-right) — move the hint up
     to the top of the stage, clear of both the toasts and the back button
     (top-left), instead of fighting over the same strip at the bottom. */
  #stageHint { top: 14px; right: 14px; bottom: auto; }
  #toasts { max-width: calc(100% - 32px); }
}
