/* The Living Terrarium — naturalist's desk theme.
   Palette: parchment, moss green, earth brown, glass highlight, ink. */

@font-face {
  font-family: 'EB Garamond';
  src: url('../fonts/ebgaramond-var.woff2') format('woff2');
  font-weight: 400 800;
  font-style: normal;
  font-display: swap;
}
@font-face {
  font-family: 'EB Garamond';
  src: url('../fonts/ebgaramond-italic-var.woff2') format('woff2');
  font-weight: 400 800;
  font-style: italic;
  font-display: swap;
}

:root {
  --parchment: #ece2c8;
  --parchment-deep: #e0d3b2;
  --paper: #f4ecd8;
  --ink: #37302a;
  --ink-soft: #5c5344;
  --moss: #4c6440;
  --moss-deep: #384e30;
  --earth: #6b543c;
  --glass: #c9dcd8;
  --line: #c4b48f;
  --accent: #7a5c34;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

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

body {
  font-family: 'EB Garamond', 'Iowan Old Style', Georgia, 'Times New Roman', serif;
  color: var(--ink);
  background:
    radial-gradient(ellipse at 30% 20%, rgba(255, 250, 232, 0.5), transparent 60%),
    radial-gradient(ellipse at 80% 85%, rgba(150, 128, 88, 0.18), transparent 55%),
    var(--parchment);
  -webkit-font-smoothing: antialiased;
}

#app {
  display: flex;
  flex-direction: column;
  height: 100%;
}

/* ---------------- header ---------------- */

#topbar {
  display: flex;
  align-items: baseline;
  gap: 18px;
  padding: 8px 18px 6px;
  border-bottom: 1px solid var(--line);
  background: linear-gradient(to bottom, rgba(255, 250, 232, 0.55), rgba(255, 250, 232, 0));
  flex: 0 0 auto;
  z-index: 5;
}

#titleblock h1 {
  font-size: 25px;
  font-weight: 500;
  letter-spacing: 0.02em;
  color: var(--moss-deep);
  line-height: 1.05;
}

#titleblock .subtitle {
  font-style: italic;
  font-size: 13.5px;
  color: var(--ink-soft);
  margin-top: 1px;
}

#worldreadout {
  display: flex;
  gap: 14px;
  align-items: baseline;
  font-size: 14.5px;
  color: var(--ink-soft);
  margin-left: 8px;
  font-style: italic;
  flex-wrap: wrap;
}

#worldreadout span:first-child {
  font-style: normal;
  font-size: 15px;
  color: var(--earth);
  font-weight: 500;
}

#controls {
  margin-left: auto;
  display: flex;
  gap: 8px;
  align-items: center;
}

#speedctl {
  display: flex;
  border: 1px solid var(--line);
  border-radius: 6px;
  overflow: hidden;
  background: var(--paper);
}

.ctl {
  font-family: inherit;
  border: 1px solid var(--line);
  background: var(--paper);
  color: var(--ink-soft);
  font-size: 14px;
  padding: 4px 9px;
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
  line-height: 1.2;
}

#speedctl .ctl { border: none; border-radius: 0; font-size: 12px; padding: 4px 8px; }

.ctl:hover { background: #fff8e6; color: var(--ink); }
.ctl.active { background: var(--moss); color: #f2f0e0; }
.ctl.wide { padding: 4px 13px; font-size: 14.5px; border-radius: 6px; }
#btn-sound { border-radius: 6px; }
#btn-sound.active { background: var(--moss); color: #f2f0e0; }

/* ---------------- stage layout ---------------- */

#stage {
  display: flex;
  flex: 1 1 auto;
  min-height: 0;
  gap: 12px;
  padding: 10px 12px 10px 12px;
}

#vessel-wrap {
  position: relative;
  flex: 1 1 auto;
  min-width: 0;
  border-radius: 4px;
  overflow: hidden;
}

#scene {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  touch-action: none;
  cursor: crosshair;
}

/* ---------------- tool palette ---------------- */

#palette {
  position: absolute;
  left: 10px;
  bottom: 10px;
  display: flex;
  align-items: flex-end;
  gap: 4px;
  background: rgba(244, 236, 216, 0.92);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 6px 8px;
  box-shadow: 0 2px 10px rgba(60, 48, 30, 0.18);
  backdrop-filter: blur(2px);
}

.tool {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  font-family: inherit;
  background: none;
  border: 1px solid transparent;
  border-radius: 6px;
  color: var(--ink-soft);
  padding: 5px 7px 4px;
  cursor: pointer;
  min-width: 52px;
  transition: background 0.12s, color 0.12s, border-color 0.12s;
}

.tool svg { width: 21px; height: 21px; }
.tool span { font-size: 11.5px; font-style: italic; letter-spacing: 0.01em; }

.tool:hover { background: rgba(255, 250, 232, 0.9); color: var(--ink); }
.tool.active {
  background: var(--moss);
  color: #eef0e2;
  border-color: var(--moss-deep);
}
.tool.active svg { color: #eef0e2; }

#brushsize {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  padding: 4px 4px 2px 8px;
  border-left: 1px solid var(--line);
  margin-left: 4px;
}

#brushsize span {
  font-size: 11px;
  font-style: italic;
  color: var(--ink-soft);
}

#brush-range {
  width: 64px;
  accent-color: var(--moss);
}

/* ---------------- magnifier lens ---------------- */

#lens {
  position: absolute;
  width: 150px;
  height: 150px;
  border-radius: 50%;
  border: 3px solid #8a6c42;
  box-shadow:
    0 0 0 2px rgba(240, 230, 200, 0.7),
    0 6px 18px rgba(40, 32, 20, 0.35),
    inset 0 0 18px rgba(60, 48, 30, 0.15);
  pointer-events: none;
  overflow: hidden;
  z-index: 4;
  background: #222;
}

#lens-canvas { width: 100%; height: 100%; }

#lens-caption {
  position: absolute;
  pointer-events: none;
  z-index: 4;
  background: rgba(244, 236, 216, 0.95);
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 6px 10px;
  max-width: 240px;
  box-shadow: 0 3px 10px rgba(60, 48, 30, 0.2);
}

#lens-caption .lens-name {
  font-size: 15px;
  font-weight: 500;
  color: var(--moss-deep);
}

#lens-caption .lens-name em {
  font-weight: 400;
  color: var(--ink-soft);
  font-size: 13.5px;
}

#lens-caption .lens-detail {
  font-size: 13.5px;
  font-style: italic;
  color: var(--ink-soft);
  margin-top: 1px;
}

/* ---------------- species picker ---------------- */

#picker {
  position: absolute;
  z-index: 6;
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: 0 4px 18px rgba(60, 48, 30, 0.28);
  padding: 8px;
  max-width: 320px;
}

#picker h3 {
  font-size: 14px;
  font-weight: 500;
  font-style: italic;
  color: var(--earth);
  margin-bottom: 6px;
}

#picker .pick-grid {
  display: flex;
  flex-wrap: wrap;
  gap: 5px;
}

#picker .pick {
  display: flex;
  align-items: center;
  gap: 7px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: rgba(255, 252, 240, 0.7);
  font-family: inherit;
  font-size: 13.5px;
  color: var(--ink);
  padding: 4px 9px 4px 4px;
  cursor: pointer;
}

#picker .pick:hover { background: #fff8e6; border-color: var(--accent); }
#picker .pick canvas { width: 34px; height: 34px; }
#picker .pick .latin { font-style: italic; color: var(--ink-soft); font-size: 12px; display: block; line-height: 1; }
#picker .pick.disabled { opacity: 0.45; cursor: default; }

/* ---------------- hint ---------------- */

#hint {
  position: absolute;
  top: 8px;
  left: 10px;
  font-size: 12.5px;
  font-style: italic;
  color: rgba(60, 50, 36, 0.66);
  background: rgba(244, 236, 216, 0.55);
  padding: 2px 9px;
  border-radius: 10px;
  pointer-events: none;
  transition: opacity 1s;
}

/* ---------------- journal ---------------- */

#journal {
  flex: 0 0 336px;
  display: flex;
  flex-direction: column;
  min-height: 0;
  /* The host's share bar owns the bottom-right corner: the journal never
     reaches within 92 px of the viewport bottom on wide screens. */
  margin-bottom: 82px;
  background:
    linear-gradient(105deg, rgba(120, 96, 60, 0.06), transparent 40%),
    var(--paper);
  border: 1px solid var(--line);
  border-radius: 6px;
  box-shadow: 2px 3px 14px rgba(70, 56, 34, 0.16);
  overflow: hidden;
}

#journal-tabs {
  display: flex;
  border-bottom: 1px solid var(--line);
  background: rgba(224, 211, 178, 0.5);
}

.jtab {
  flex: 1;
  font-family: inherit;
  font-size: 14px;
  font-style: italic;
  background: none;
  border: none;
  border-right: 1px solid var(--line);
  padding: 7px 4px;
  color: var(--ink-soft);
  cursor: pointer;
}

.jtab:last-child { border-right: none; }
.jtab:hover { background: rgba(255, 248, 230, 0.7); color: var(--ink); }
.jtab.active {
  background: var(--paper);
  color: var(--moss-deep);
  font-weight: 500;
  font-style: normal;
  box-shadow: inset 0 -2px 0 var(--moss);
}

#journal-page {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
  position: relative;
  perspective: 900px;
}

#journal-content {
  flex: 1;
  overflow-y: auto;
  padding: 12px 14px;
  font-size: 14.5px;
  line-height: 1.42;
}

#journal-content::-webkit-scrollbar { width: 8px; }
#journal-content::-webkit-scrollbar-thumb { background: var(--line); border-radius: 4px; }

#journal-nav {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 14px;
  padding: 5px 0 7px;
  border-top: 1px solid rgba(196, 180, 143, 0.5);
  flex: 0 0 auto;
}

#journal-nav button {
  font-family: inherit;
  font-size: 18px;
  background: none;
  border: 1px solid var(--line);
  border-radius: 50%;
  width: 26px;
  height: 26px;
  line-height: 1;
  color: var(--ink-soft);
  cursor: pointer;
}

#journal-nav button:hover:not(:disabled) { background: #fff8e6; color: var(--ink); }
#journal-nav button:disabled { opacity: 0.3; cursor: default; }
#jpageno { font-size: 12.5px; font-style: italic; color: var(--ink-soft); min-width: 70px; text-align: center; }

/* species pages */
.sp-page h2 {
  font-size: 19px;
  font-weight: 500;
  color: var(--moss-deep);
  line-height: 1.15;
}

.sp-page .latin-line {
  font-style: italic;
  color: var(--ink-soft);
  font-size: 13.5px;
  margin-bottom: 8px;
}

.sp-page .sketch {
  display: block;
  margin: 6px auto 8px;
  background:
    radial-gradient(ellipse at 50% 42%, rgba(140, 160, 110, 0.16), transparent 70%),
    rgba(255, 252, 240, 0.65);
  border: 1px solid rgba(196, 180, 143, 0.6);
  border-radius: 4px;
}

.sp-page .note-line {
  font-size: 14px;
  margin: 5px 0;
  padding-left: 12px;
  text-indent: -12px;
}

.sp-page .note-line::before { content: '·'; margin-right: 7px; color: var(--accent); }

.sp-page .observed {
  font-style: italic;
  color: var(--ink-soft);
  font-size: 13px;
  margin-top: 8px;
  padding-top: 6px;
  border-top: 1px solid rgba(196, 180, 143, 0.5);
}

.empty-journal {
  font-style: italic;
  color: var(--ink-soft);
  text-align: center;
  margin-top: 40px;
  font-size: 15px;
  line-height: 1.6;
}

/* notes log */
.log-entry {
  margin-bottom: 9px;
  font-size: 14px;
  line-height: 1.38;
}

.log-entry .log-day {
  font-style: italic;
  color: var(--earth);
  font-size: 12.5px;
  display: block;
}

/* charts */
.chart-block { margin-bottom: 16px; }
.chart-block h3 {
  font-size: 14px;
  font-weight: 500;
  color: var(--earth);
  margin-bottom: 3px;
}
.chart-block canvas {
  display: block;
  width: 100%;
  background: rgba(255, 252, 240, 0.6);
  border: 1px solid rgba(196, 180, 143, 0.5);
  border-radius: 4px;
}
.chart-legend { font-size: 12px; font-style: italic; color: var(--ink-soft); margin-top: 2px; line-height: 1.5; }
.chart-legend span { margin-right: 9px; white-space: nowrap; }
.chart-legend i {
  display: inline-block; width: 10px; height: 2.5px; vertical-align: middle; margin-right: 4px;
}

/* world tab */
.world-block h2 { font-size: 18px; font-weight: 500; color: var(--moss-deep); }
.world-block .blurb { font-style: italic; color: var(--ink-soft); font-size: 13.5px; margin: 3px 0 10px; line-height: 1.4; }
.world-block h3 { font-size: 14px; font-weight: 500; color: var(--earth); margin: 12px 0 5px; }
.seed-code {
  font-family: 'EB Garamond', serif;
  font-size: 15px;
  letter-spacing: 0.06em;
  background: rgba(255, 252, 240, 0.8);
  border: 1px solid var(--line);
  border-radius: 4px;
  padding: 4px 8px;
  display: inline-block;
  color: var(--ink);
}
.world-block button, .biome-btn {
  font-family: inherit;
  font-size: 13.5px;
  border: 1px solid var(--line);
  border-radius: 5px;
  background: rgba(255, 250, 234, 0.8);
  color: var(--ink);
  padding: 4px 10px;
  cursor: pointer;
  margin: 2px 4px 2px 0;
}
.world-block button:hover, .biome-btn:hover { background: #fff8e6; border-color: var(--accent); }
.biome-btn { display: block; width: 100%; text-align: left; padding: 6px 10px; margin-bottom: 5px; }
.biome-btn b { font-weight: 500; color: var(--moss-deep); display: block; font-size: 14px; }
.biome-btn small { font-style: italic; color: var(--ink-soft); line-height: 1.3; display: block; }
.biome-btn.current { outline: 2px solid var(--moss); }
#savecode-box {
  width: 100%;
  font-family: inherit;
  font-size: 12px;
  border: 1px solid var(--line);
  border-radius: 4px;
  padding: 5px 7px;
  background: rgba(255, 252, 240, 0.8);
  color: var(--ink);
  resize: vertical;
  min-height: 54px;
}
.slot-line { display: flex; align-items: center; gap: 6px; margin: 4px 0; font-size: 13px; }
.slot-line .slot-name { flex: 1; font-style: italic; color: var(--ink-soft); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* journal leaf animation */
@keyframes leaf-in {
  0% { transform: rotateY(-62deg); opacity: 0.2; }
  100% { transform: rotateY(0deg); opacity: 1; }
}
.leafing #journal-content {
  animation: leaf-in 0.28s ease-out;
  transform-origin: left center;
}

/* ---------------- mobile / narrow ---------------- */

#journal-scrim { display: none; }

@media (max-width: 920px) {
  #stage { flex-direction: column; padding: 6px; gap: 6px; }
  #vessel-wrap { flex: 1 1 auto; }
  #journal {
    position: fixed;
    top: 0;
    right: 0;
    bottom: 0;
    width: min(88vw, 360px);
    z-index: 20;
    margin-bottom: 0;
    border-radius: 0;
    transform: translateX(103%);
    transition: transform 0.25s ease;
    box-shadow: -6px 0 26px rgba(50, 40, 24, 0.3);
  }
  #journal.open { transform: translateX(0); }
  #journal-scrim {
    display: block;
    position: fixed;
    inset: 0;
    background: rgba(40, 32, 20, 0.35);
    z-index: 15;
  }
  #topbar { flex-wrap: wrap; gap: 6px 10px; padding: 6px 10px 4px; }
  #titleblock h1 { font-size: 19px; }
  #titleblock .subtitle { display: none; }
  #worldreadout { font-size: 12.5px; gap: 8px; margin-left: 0; order: 3; width: 100%; }
  #controls { margin-left: auto; }
  #palette {
    gap: 1px;
    padding: 4px 5px;
    left: 6px;
    bottom: 6px;
    max-width: calc(100vw - 12px);
    overflow-x: auto;
  }
  .tool { min-width: 44px; padding: 4px 5px 3px; }
  .tool span { font-size: 10px; }
  #brushsize { display: none; }
  #hint { display: none; }
}

@media (prefers-reduced-motion: reduce) {
  .leafing #journal-content { animation: none; }
  #journal { transition: none; }
}

#journal-scrim[hidden] { display: none !important; }
