/* ════════════════════════════════════════════════════════════
   FIRST LIGHT — field-journal UI over a three.js valley
   palette: BirdersUnite green #047857, cream paper, warm ink
   ════════════════════════════════════════════════════════════ */
:root {
  --green: #047857;
  --green-dk: #065f46;
  --green-lt: #34d399;
  --paper: #f7f1e3;
  --paper-dk: #efe6d0;
  --ink: #2d2a24;
  --ink-soft: #6b6355;
  --line: #d8cdb4;
  --gold: #d9a441;
  --hud-bg: rgba(20, 26, 22, 0.62);
  --hud-line: rgba(247, 241, 227, 0.16);
  --hud-text: #f2ead8;
  --sat: env(safe-area-inset-top, 0px);
  --sab: env(safe-area-inset-bottom, 0px);
  --sal: env(safe-area-inset-left, 0px);
  --sar: env(safe-area-inset-right, 0px);
}

* { margin: 0; padding: 0; box-sizing: border-box; }
html, body { height: 100%; overflow: hidden; background: #0d1310; }
body {
  font-family: 'IBM Plex Mono', ui-monospace, monospace;
  color: var(--hud-text);
  -webkit-user-select: none; user-select: none;
  -webkit-tap-highlight-color: transparent;
  touch-action: none;
}
#scene { position: fixed; inset: 0; width: 100%; height: 100%; display: block; }
.hidden { display: none !important; }

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

/* ── vignette ── */
#vignette {
  position: fixed; inset: 0; pointer-events: none; z-index: 4;
  background: radial-gradient(ellipse at center, transparent 62%, rgba(8, 12, 9, 0.42) 100%);
}

/* ════════ HUD ════════ */
#hud { position: fixed; inset: 0; pointer-events: none; z-index: 10; }
#hud a, #hud button { pointer-events: auto; }

#topbar {
  position: absolute; top: 0; left: 0; right: 0;
  display: flex; align-items: stretch; justify-content: space-between; gap: 8px;
  padding: calc(8px + var(--sat)) calc(10px + var(--sar)) 0 calc(10px + var(--sal));
}
#daybar {
  display: flex; gap: 6px; align-items: stretch;
}
#daybar .stat {
  background: var(--hud-bg); border: 1px solid var(--hud-line); border-radius: 10px;
  padding: 5px 12px; text-align: center; backdrop-filter: blur(6px);
  display: flex; flex-direction: column; justify-content: center;
}
#daybar label { font-size: 8px; letter-spacing: 0.16em; color: #9fc2a8; display: block; }
#daybar b { font-size: 13px; font-weight: 600; }
#clockbox {
  display: flex; gap: 6px; align-items: stretch;
}
#todinfo {
  background: var(--hud-bg); border: 1px solid var(--hud-line); border-radius: 10px;
  padding: 4px 10px; text-align: center; backdrop-filter: blur(6px);
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 1px;
}
#tod-dial {
  width: 46px; height: 10px; border-bottom: 1px solid var(--hud-line);
  position: relative; overflow: visible;
}
#tod-sun { position: absolute; bottom: -4px; left: 0; font-size: 10px; transform: translateX(-50%); }
#tod-phase { font-size: 9px; letter-spacing: 0.18em; color: var(--gold); font-weight: 600; }
#sysctl {
  display: flex; flex-direction: column; gap: 4px; justify-content: center;
}
#sysctl a, #sysctl button {
  background: var(--hud-bg); border: 1px solid var(--hud-line); color: var(--hud-text);
  font-size: 9px; letter-spacing: 0.1em; padding: 3px 8px; border-radius: 7px;
  text-decoration: none; text-align: center; backdrop-filter: blur(6px);
}
#sysctl a:hover, #sysctl button:hover { border-color: var(--green-lt); color: var(--green-lt); }
#sysctl button.off { opacity: 0.45; }

/* ── reticle & steady meter ── */
#reticle {
  position: absolute; left: 50%; top: 50%; transform: translate(-50%, -50%);
  pointer-events: none;
}
#reticle i {
  display: block; width: 4px; height: 4px; border-radius: 50%;
  background: rgba(247, 241, 227, 0.65); box-shadow: 0 0 4px rgba(0,0,0,0.5);
}
#steadybox {
  position: absolute; left: 50%; top: 50%; transform: translate(-50%, -50%);
  width: 120px; text-align: center; pointer-events: none;
}
#steadybox svg { width: 92px; height: 92px; transform: rotate(-90deg); }
#steadybox .track { fill: none; stroke: rgba(247,241,227,0.22); stroke-width: 3; }
#steady-arc {
  fill: none; stroke: var(--green-lt); stroke-width: 3.5; stroke-linecap: round;
  stroke-dasharray: 213.6; stroke-dashoffset: 213.6;
}
#steady-label {
  margin-top: 4px; font-size: 9px; letter-spacing: 0.2em; color: var(--green-lt);
  text-shadow: 0 1px 3px rgba(0,0,0,0.7);
}

/* ── hint line & sneak tag ── */
#hint {
  position: absolute; left: 50%; bottom: calc(64px + var(--sab));
  transform: translateX(-50%);
  max-width: min(520px, 86vw);
  background: var(--hud-bg); border: 1px solid var(--hud-line); border-radius: 10px;
  padding: 7px 16px; font-size: 12px; font-style: italic; color: #e8f2e2;
  text-align: center; backdrop-filter: blur(6px);
}
#sneak-tag {
  position: absolute; left: 50%; bottom: calc(36px + var(--sab)); transform: translateX(-50%);
  font-size: 9px; letter-spacing: 0.22em; color: #9fc2a8; opacity: 0.85;
}

/* ── toasts ── */
#toasts {
  position: absolute; right: calc(12px + var(--sar)); top: calc(84px + var(--sat));
  display: flex; flex-direction: column; gap: 6px; align-items: flex-end; pointer-events: none;
}
.toast {
  background: var(--hud-bg); border: 1px solid var(--hud-line); border-left: 3px solid var(--green-lt);
  border-radius: 8px; padding: 7px 12px; font-size: 11px; max-width: 300px;
  animation: toast-in 0.25s ease-out, toast-out 0.4s ease-in forwards;
  animation-delay: 0s, var(--ttl, 4s);
  backdrop-filter: blur(6px);
}
.toast.badge { border-left-color: var(--gold); }
.toast b { color: var(--green-lt); }
.toast.badge b { color: var(--gold); }
@keyframes toast-in { from { opacity: 0; transform: translateX(16px); } }
@keyframes toast-out { to { opacity: 0; transform: translateX(16px); } }

/* ════════ binocular mask ════════ */
#binox-mask {
  position: fixed; inset: 0; width: 100%; height: 100%;
  z-index: 6; pointer-events: none;
}
#binox-plate { fill: rgba(4, 7, 5, 0.99); }
.binox-vigc { fill: url(#binox-vig); }
.binox-rim { fill: none; stroke: rgba(0, 0, 0, 0.72); }
.binox-glass { fill: none; stroke: rgba(190, 215, 235, 0.09); }
.binox-glint { fill: none; stroke: rgba(225, 240, 255, 0.13); stroke-linecap: round; }

/* ════════ overlays & paper cards ════════ */
.overlay {
  position: fixed; inset: 0; z-index: 20;
  display: flex; align-items: center; justify-content: center;
  background: rgba(13, 19, 16, 0.66);
  padding: calc(14px + var(--sat)) 14px calc(14px + var(--sab));
  overflow-y: auto;
  backdrop-filter: blur(3px);
}
.paper-card {
  background:
    linear-gradient(rgba(247,241,227,0.97), rgba(239,230,208,0.97));
  color: var(--ink);
  border-radius: 14px;
  border: 1px solid #c9bda0;
  box-shadow: 0 18px 60px rgba(0,0,0,0.5), inset 0 0 0 4px rgba(255,255,255,0.35);
  padding: 26px 28px 22px;
  max-width: 560px; width: 100%;
  margin: auto;
  max-height: calc(100vh - 40px);
  overflow-y: auto;
}
.card-pre {
  font-size: 9px; letter-spacing: 0.24em; color: var(--green);
  font-weight: 600; margin-bottom: 6px;
}
.paper-card h2 {
  font-family: 'Fraunces', serif; font-size: 26px; font-weight: 700;
  color: var(--ink); margin-bottom: 4px; letter-spacing: 0.01em;
}
.paper-card h3 {
  font-family: 'Fraunces', serif; font-size: 14px; color: var(--green-dk);
  margin: 12px 0 6px; letter-spacing: 0.04em;
}
.paper-card p { font-size: 12px; line-height: 1.55; color: var(--ink); margin: 6px 0; }
.card-foot { margin-top: 12px; font-size: 10px; color: var(--ink-soft); font-style: italic; }

.big-btn {
  display: block; width: 100%; margin-top: 16px;
  background: var(--green); color: #f4fbf6; border: none;
  border-radius: 10px; padding: 13px 18px;
  font-size: 13px; font-weight: 600; letter-spacing: 0.12em;
  box-shadow: 0 4px 14px rgba(4, 120, 87, 0.35);
  transition: background 0.15s, transform 0.1s;
}
.big-btn:hover { background: var(--green-dk); }
.big-btn:active { transform: translateY(1px); }

/* ── identify panel ── */
.id-card { max-width: 480px; }
.field-hint {
  background: rgba(4, 120, 87, 0.08); border-left: 3px solid var(--green);
  border-radius: 0 8px 8px 0; padding: 8px 12px; margin: 10px 0 14px;
  font-size: 12px; font-style: italic; color: var(--green-dk); line-height: 1.5;
}
.field-hint.second {
  background: rgba(179, 83, 43, 0.08); border-left-color: #b3532b;
  color: #8a3c22; margin-top: -6px;
}
#id-options button:disabled { cursor: default; opacity: 0.85; }
#id-options { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
#id-options button {
  background: #fff; border: 1.5px solid var(--line); border-radius: 10px;
  padding: 12px 10px; font-size: 12px; font-weight: 500; color: var(--ink);
  min-height: 48px; line-height: 1.35;
  transition: border-color 0.12s, background 0.12s;
}
#id-options button:hover { border-color: var(--green); background: #f2fbf6; }
#id-options button.right { border-color: var(--green); background: #dcf5e7; }
#id-options button.wrong { border-color: #c0392b; background: #fbe9e5; }

/* ── sighting card ── */
.sight-card { max-width: 460px; text-align: center; }
.sight-card h2 { margin-bottom: 0; }
#sight-sci { font-size: 12px; font-style: italic; color: var(--ink-soft); margin-bottom: 12px; }
#sight-figure { margin: 0 0 4px; }
#sight-photo {
  width: 100%; aspect-ratio: 4 / 3; border-radius: 10px; overflow: hidden;
  background: #ddd4bd center / cover no-repeat;
  border: 1px solid var(--line);
  display: flex; align-items: center; justify-content: center;
  color: var(--ink-soft); font-size: 11px;
}
#sight-photo img, #sight-photo canvas { width: 100%; height: 100%; object-fit: cover; display: block; }
#sight-attr {
  font-size: 9px; color: var(--ink-soft); margin-top: 5px; line-height: 1.4;
  text-align: right;
}
#sight-fact { text-align: left; }
.sight-links {
  display: flex; flex-wrap: wrap; gap: 6px 18px; justify-content: center; margin-top: 10px;
}
.sight-links a {
  font-size: 11px; color: var(--green-dk); font-weight: 600; text-decoration: none;
  border-bottom: 1px dashed var(--green);
}
.sight-links a:hover { color: var(--green); }
#sighting.miss .card-pre { color: #b3532b; }

/* ── journal ── */
.journal-card { max-width: 640px; }
#journal-tabs { display: flex; gap: 4px; margin: 10px 0 14px; border-bottom: 2px solid var(--line); }
.jtab {
  background: none; border: none; padding: 8px 14px; font-size: 11px; letter-spacing: 0.12em;
  color: var(--ink-soft); font-weight: 600; border-bottom: 2px solid transparent; margin-bottom: -2px;
}
.jtab.on { color: var(--green-dk); border-bottom-color: var(--green); }
.jpage { min-height: 200px; }

#jt-lifelist { display: grid; grid-template-columns: repeat(auto-fill, minmax(96px, 1fr)); gap: 8px; }
.ll-cell {
  background: #fff; border: 1px solid var(--line); border-radius: 10px; overflow: hidden;
  text-align: center; padding-bottom: 6px;
}
.ll-cell .ll-img {
  width: 100%; aspect-ratio: 1; background: #e7dfc9 center / cover no-repeat;
  display: flex; align-items: center; justify-content: center; font-size: 26px;
  color: #b9ad8f;
}
.ll-cell.seen .ll-img { filter: none; }
.ll-cell .ll-name { font-size: 9px; padding: 5px 4px 0; line-height: 1.3; color: var(--ink); }
.ll-cell.unseen .ll-name { color: var(--ink-soft); }
.ll-cell .ll-count { font-size: 8px; color: var(--green-dk); }

#jt-badges { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.badge-row {
  display: flex; gap: 10px; align-items: center;
  background: #fff; border: 1px solid var(--line); border-radius: 10px; padding: 8px 10px;
}
.badge-row.locked { opacity: 0.45; }
.badge-ico { font-size: 20px; width: 28px; text-align: center; }
.badge-row b { display: block; font-size: 11px; color: var(--ink); }
.badge-row small { font-size: 9px; color: var(--ink-soft); line-height: 1.3; display: block; }

#jt-credits { font-size: 11px; line-height: 1.6; }
#jt-credits h3 { margin-top: 10px; }
#jt-credits ul { margin: 4px 0 8px 16px; }
#jt-credits li { margin: 3px 0; }
#jt-credits a { color: var(--green-dk); }

/* ── help ── */
.help-card { max-width: 640px; }
.help-cols { display: grid; grid-template-columns: 1fr 1fr; gap: 18px; margin-top: 8px; }
.help-card table { border-collapse: collapse; width: 100%; }
.help-card td { padding: 3.5px 6px; font-size: 11px; color: var(--ink); }
.kbd {
  font-size: 10px; background: #fff; border: 1px solid var(--line); border-bottom-width: 2px;
  border-radius: 5px; padding: 1px 6px; white-space: nowrap; color: var(--green-dk); font-weight: 600;
}
.touch-note { font-size: 10.5px; color: var(--ink-soft); margin-top: 10px; line-height: 1.5; }

/* ════════ start screen ════════ */
#startscreen {
  background: linear-gradient(180deg, #1a2331 0%, #2c3a44 34%, #7a5a41 72%, #c98a4b 100%);
  z-index: 30;
}
.dawn-bg {
  position: absolute; inset: 0; pointer-events: none; overflow: hidden;
}
.dawn-bg::before {
  content: ''; position: absolute; left: 50%; bottom: -12vh; transform: translateX(-50%);
  width: 70vmin; height: 70vmin; border-radius: 50%;
  background: radial-gradient(circle, rgba(255, 196, 110, 0.55), rgba(255, 158, 66, 0.12) 55%, transparent 70%);
}
.dawn-bg::after {
  content: ''; position: absolute; left: 0; right: 0; bottom: 0; height: 26vh;
  background: linear-gradient(transparent, rgba(13, 19, 16, 0.8));
}
.start-inner {
  position: relative; text-align: center; max-width: 640px; padding: 20px;
  margin: auto;
}
.start-pre { font-size: 10px; letter-spacing: 0.32em; color: #ffd9a3; margin-bottom: 14px; }
#title {
  font-family: 'Fraunces', serif; font-weight: 700; font-size: clamp(44px, 10vw, 84px);
  letter-spacing: 0.04em; color: #fdf6e6;
  text-shadow: 0 4px 30px rgba(255, 170, 80, 0.35);
}
.start-rule {
  display: flex; align-items: center; gap: 12px; margin: 10px 0 18px; justify-content: center;
}
.start-rule span { height: 1px; flex: 1; max-width: 120px; background: rgba(253, 246, 230, 0.35); }
.start-rule em {
  font-style: normal; font-size: 10px; letter-spacing: 0.26em; color: #ffd9a3;
}
.start-lore {
  font-size: 13px; line-height: 1.7; color: #f2e8d2; max-width: 470px; margin: 0 auto;
}
.start-opts {
  margin-top: 22px; display: flex; flex-direction: column; gap: 8px; align-items: center;
}
.opt-row {
  display: flex; gap: 6px; align-items: center; flex-wrap: wrap; justify-content: center;
}
.opt-label {
  font-size: 9px; letter-spacing: 0.22em; color: rgba(255, 217, 163, 0.85);
  margin-right: 4px; min-width: 84px; text-align: right;
}
.opt-btn {
  background: rgba(13, 19, 16, 0.4); border: 1px solid rgba(253, 246, 230, 0.28);
  color: #f2e8d2; border-radius: 999px; padding: 7px 14px;
  font-size: 9.5px; letter-spacing: 0.12em; font-weight: 600;
  transition: border-color 0.12s, background 0.12s;
}
.opt-btn:hover { border-color: #ffd9a3; }
.opt-btn.sel {
  background: rgba(4, 120, 87, 0.55); border-color: var(--green-lt); color: #eafff3;
}

.start-btns { margin-top: 22px; display: flex; justify-content: center; }
.start-btns .big-btn {
  width: auto; min-width: 280px; margin-top: 0; font-size: 14px; padding: 15px 30px;
}
.start-foot {
  margin-top: 26px; font-size: 9.5px; letter-spacing: 0.14em; color: rgba(242, 232, 210, 0.75);
  line-height: 2;
}
.game-links { margin-top: 8px; display: flex; gap: 18px; justify-content: center; }
.game-links a {
  color: #ffd9a3; text-decoration: none; border-bottom: 1px dashed rgba(255, 217, 163, 0.5);
  font-size: 9.5px; letter-spacing: 0.14em;
}
.game-links a:hover { color: #fff; }

/* ════════ touch controls ════════ */
#touchui { display: none; }
body.touch #touchui { display: block; }
body.touch #hint { bottom: calc(150px + var(--sab)); }
body.touch #sneak-tag { display: none; }

#stick-zone {
  position: absolute; left: 0; bottom: 0;
  width: 44vw; max-width: 300px; height: 42vh;
  pointer-events: auto;
}
#stick-base {
  position: absolute; left: 24px; bottom: calc(28px + var(--sab));
  width: 116px; height: 116px; border-radius: 50%;
  border: 1.5px solid rgba(247,241,227,0.3); background: rgba(20, 26, 22, 0.35);
  opacity: 0.6; transition: opacity 0.15s;
}
#stick-base.live { opacity: 1; }
#stick-nub {
  position: absolute; left: 50%; top: 50%; margin: -26px 0 0 -26px;
  width: 52px; height: 52px; border-radius: 50%;
  background: rgba(247,241,227,0.28); border: 1.5px solid rgba(247,241,227,0.5);
}
#look-zone {
  position: absolute; right: 0; bottom: 0; top: 30%;
  width: 55vw; pointer-events: auto;
}
#touchui .tbtn {
  position: absolute; pointer-events: auto;
  background: rgba(20, 26, 22, 0.55); border: 1.5px solid rgba(247,241,227,0.35);
  color: var(--hud-text); border-radius: 14px;
  min-width: 64px; min-height: 46px; font-size: 11px; letter-spacing: 0.1em; font-weight: 600;
  backdrop-filter: blur(4px);
}
#touchui .tbtn.on, #touchui .tbtn:active { background: rgba(4, 120, 87, 0.65); border-color: var(--green-lt); }
#tb-binox { right: calc(18px + var(--sar)); bottom: calc(96px + var(--sab)); min-width: 92px; min-height: 56px; }
#tb-torch { right: calc(124px + var(--sar)); bottom: calc(96px + var(--sab)); min-width: 52px; }
#tb-sneak { right: calc(124px + var(--sar)); bottom: calc(30px + var(--sab)); }
#tb-journal { right: calc(18px + var(--sar)); bottom: calc(30px + var(--sab)); }
#tb-sneak.latched, #tb-torch.latched { background: rgba(217, 164, 65, 0.5); border-color: var(--gold); }

/* ════════ small screens ════════ */
@media (max-width: 720px) {
  #daybar .stat.wide { display: none; }
  #daybar b { font-size: 11px; }
  .paper-card { padding: 20px 16px 16px; }
  .paper-card h2 { font-size: 21px; }
  .help-cols { grid-template-columns: 1fr; }
  #id-options { grid-template-columns: 1fr; }
  #jt-badges { grid-template-columns: 1fr; }
  #steadybox svg { width: 76px; height: 76px; }
}
@media (max-height: 500px) {
  #topbar { transform: scale(0.9); transform-origin: top left; }
  .paper-card { max-height: calc(100vh - 20px); }
}
