:root {
  color-scheme: dark;
  font-family: system-ui, sans-serif;
  color: #fbefd9;
  background: #a8c2be;
  --ink: #202d26;
  --muted: #d6daca;
  --amber: #e6b86d;
  /* Distância das bordas, já somando o recorte da câmera/notch. */
  --gap: 1.25rem;
  --safe-t: env(safe-area-inset-top, 0px);
  --safe-r: env(safe-area-inset-right, 0px);
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-l: env(safe-area-inset-left, 0px);
}
/* Girado 90° no sentido horário: a borda esquerda do jogo é o topo físico do aparelho. */
:root[data-rotated] {
  --safe-t: env(safe-area-inset-right, 0px);
  --safe-r: env(safe-area-inset-bottom, 0px);
  --safe-b: env(safe-area-inset-left, 0px);
  --safe-l: env(safe-area-inset-top, 0px);
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; height: 100%; overflow: hidden; overscroll-behavior: none; background: #a8c2be; }
#game {
  --top: calc(var(--gap) + var(--safe-t));
  --right: calc(var(--gap) + var(--safe-r));
  --bottom: calc(var(--gap) + var(--safe-b));
  --left: calc(var(--gap) + var(--safe-l));
  position: fixed;
  top: 0;
  left: 0;
  width: 100vw;
  height: 100vh;
  width: 100dvw;
  height: 100dvh;
  overflow: hidden;
  container-type: size;
  -webkit-tap-highlight-color: transparent;
}
/* Celular em pé: o jogo inteiro vira paisagem sozinho. */
:root[data-rotated] #game {
  width: 100vh;
  height: 100vw;
  width: 100dvh;
  height: 100dvw;
  transform-origin: top left;
  transform: rotate(90deg) translateY(-100%);
}
canvas { display: block; width: 100%; height: 100%; touch-action: none; }
.field-notes, #notice {
  background: var(--ink);
  border: 1px solid #75816d;
  border-radius: .8rem;
}
.field-notes {
  position: absolute;
  width: min(21rem, calc(100cqw - var(--left) - var(--right)));
  padding: 1rem 1.15rem;
  max-height: calc(100cqh - var(--top) - var(--bottom) - 3.3rem);
  overflow: auto;
}
h1 { font: 700 clamp(1.3rem, 3cqw, 1.85rem)/1.08 Georgia, serif; margin: 0; }
p { margin: .55rem 0; }
#action { color: var(--amber); font-weight: 650; }
.care-panel {
  border-top: 1px solid #75816d;
  padding: .75rem 0 .9rem;
}
.care-panel h2 {
  font: 700 1rem Georgia, serif;
  margin: 0 0 .65rem;
}
.need + .need { margin-top: .65rem; }
.need-heading {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  align-items: baseline;
  column-gap: .5rem;
  row-gap: .1rem;
  font-size: .9rem;
}
.need-heading label { font-weight: 700; }
.need-heading span { color: var(--muted); font-size: .8rem; }
.need { --fill: #a8c582; }
.need[data-severity="low"] { --fill: var(--amber); }
.need[data-severity="urgent"] { --fill: #efa492; }
.need meter { appearance: none; width: 100%; height: .58rem; display: block; margin-top: .33rem; }
.need meter::-webkit-meter-bar { background: #46554b; border: 0; border-radius: .25rem; }
.need meter::-webkit-meter-optimum-value,
.need meter::-webkit-meter-suboptimum-value,
.need meter::-webkit-meter-even-less-good-value { background: var(--fill); border-radius: .25rem; }
.need meter::-moz-meter-bar { background: var(--fill); border-radius: .25rem; }
@supports (-moz-appearance: none) {
  .need meter { background: #46554b; border: 0; border-radius: .25rem; }
}
details { border-top: 1px solid #75816d; padding-top: .55rem; color: var(--muted); }
summary { cursor: pointer; }
#return:empty { display: none; }
ol { padding-left: 1.3rem; margin: .5rem 0 0; }
li + li { margin-top: .35rem; }
canvas { cursor: default; }
canvas.placing { cursor: crosshair; }
button {
  border: 1px solid #75816d;
  border-radius: .35rem;
  background: #304439;
  color: #fbefd9;
  padding: .35rem .55rem;
  font: inherit;
  cursor: pointer;
}
button[aria-pressed="true"] { background: var(--amber); color: #2b211b; }
button:disabled { cursor: wait; }
:focus-visible { outline: 3px solid #fff5db; outline-offset: 3px; }
#notice {
  position: absolute;
  left: 50%;
  transform: translateX(-50%);
  width: max-content;
  max-width: calc(100% - 2rem);
  padding: .5rem .8rem;
  margin: 0;
}
#notice { left: auto; right: var(--right); transform: none; max-width: min(26rem, calc(100cqw - var(--left) - var(--right))); }
kbd {
  display: inline-block;
  padding: .12rem .33rem;
  border-radius: .25rem;
  color: #252b23;
  background: #e4dcc4;
  font: 700 .82em system-ui, sans-serif;
}

.panel-filters, .panel-actions { display: flex; flex-wrap: wrap; gap: .4rem; }
.panel-filters { margin: .75rem 0; }
.panel-filters button, .panel-actions button { font-size: .85rem; }
.panel-actions { margin-top: .9rem; }
.profile-grid {
  display: grid;
  grid-template-columns: repeat(2,minmax(0,1fr));
  gap: .45rem;
  margin: 0;
}
.profile-grid div { background: #35473a; border-radius: .4rem; padding: .45rem .6rem; }
.profile-grid dt { color: var(--muted); font-size: .78rem; }
.profile-grid dd { margin: .1rem 0 0; font-weight: 700; }
#notebook {
  color-scheme: light;
  color: #352a20;
  background: #f6edd9;
  border: 2px solid #9a795a;
  border-radius: .85rem;
  box-shadow: 0 .8rem 3rem #172b2280;
  width: min(42rem, calc(100% - 2rem));
  max-height: 84dvh;
  padding: clamp(.7rem, 2.7vw, 1.15rem);
  overflow: hidden;
}
#notebook[open] { display: grid; grid-template-rows: auto auto minmax(0, 1fr); }
/* O caderninho fica na camada do topo, fora do #game, e precisa girar junto. */
:root[data-rotated] #notebook {
  inset: 50% auto auto 50%;
  margin: 0;
  width: min(42rem, calc(100dvh - 2rem));
  max-width: none;
  max-height: calc(100dvw - 2rem - env(safe-area-inset-top, 0px));
  transform: translate(-50%, -50%) rotate(90deg);
}
#notebook::backdrop { background: #172b2277; }
.notebook-heading { display: flex; justify-content: space-between; align-items: center; gap: .55rem; }
.notebook-heading h2, .notebook-page h3 { font-family: Georgia, serif; margin: 0; }
.notebook-heading h2 { font-size: clamp(1.25rem, 4vw, 1.85rem); }
#notebook nav { display: flex; flex-wrap: wrap; gap: .4rem; margin: .65rem 0; }
#notebook nav button, #notebook .notebook-secondary { background: #eee0c5; color: #442f22; border-color: #a58a6c; }
#notebook nav button[aria-selected="true"] { background: #4a5e49; color: #fff4dd; border-color: #4a5e49; box-shadow: inset 0 -3px #dfc7a3; }
#notebook :focus-visible { outline-color: #654225; }
.notebook-page {
  min-height: 0;
  overflow: auto;
  overscroll-behavior: contain;
  overflow-wrap: anywhere;
  border-top: 1px solid #c4ad8d;
  padding: .75rem .25rem .25rem;
}
.notebook-page [role="tabpanel"]:focus-visible { outline-offset: -2px; }
.notebook-search { display: grid; gap: .3rem; margin: .65rem 0; }
.notebook-search label { font-size: .9rem; font-weight: 650; }
.notebook-search input {
  width: min(100%, 28rem);
  min-height: 44px;
  padding: .55rem .7rem;
  border: 1px solid #927758;
  border-radius: .45rem;
  background: #fffaf0;
  color: inherit;
  font: inherit;
}
.notebook-secondary { margin-top: .3rem; }
.notebook-result { background: #fbf4e6; }
.notebook-result > summary time { color: #6b5642; font-size: .8rem; font-weight: 400; margin-inline-start: .5rem; }
.notebook-result h4 { margin-top: .6rem; }
.notebook-page blockquote { font: italic 1.25rem/1.45 Georgia, serif; margin: .7rem 0; }
.notebook-page ul { padding-left: 1.25rem; }
.notebook-page details { color: inherit; border-color: #c4ad8d; margin-top: .65rem; }
.notebook-page .notebook-chips { display: flex; flex-wrap: wrap; gap: .4rem; list-style: none; padding: 0; margin: .5rem 0 .85rem; }
.notebook-chips li { display: flex; gap: .35rem; align-items: baseline; padding: .25rem .6rem; border: 1px solid #c4ad8d; border-radius: 999px; background: #efe2c8; font-size: .85rem; }
.notebook-chips span { color: #6b5642; }
.notebook-chips strong { color: #352a20; }
.notebook-chips li + li { margin-top: 0; }
.notebook-section { margin-top: 1rem; }
.notebook-section h4 { margin: 0 0 .4rem; font: 700 1rem Georgia, serif; color: #4a3626; }
.notebook-empty { color: #7a6450; font-style: italic; margin: .25rem 0; }
.notebook-pending { padding: .7rem .85rem; border: 1px dashed #a58a6c; border-radius: .6rem; background: #f1e5cd; }
.notebook-question { font: italic 1.05rem/1.4 Georgia, serif; margin: .2rem 0; }
.notebook-card { padding: .75rem .85rem; margin-top: .6rem; border: 1px solid #d3bf9f; border-radius: .6rem; background: #fbf4e6; }
.notebook-card h5 { margin: 0; font: 700 1rem Georgia, serif; }
.notebook-card p { margin: .35rem 0; }
.notebook-card a { color: #4a5e49; font-weight: 650; }
.notebook-page a { color: #4a5e49; }
.notebook-page .notebook-friends { list-style: none; padding: 0; margin: .4rem 0 0; display: grid; gap: .5rem; }
.notebook-friends li { padding: .55rem .7rem; border: 1px solid #d3bf9f; border-radius: .6rem; background: #fbf4e6; }
.notebook-friends li + li { margin-top: 0; }
.notebook-friends p { margin: .25rem 0 0; }
.notebook-research strong { display: block; font-weight: 650; color: #4a3626; }
.notebook-date { color: #7a6450; font-size: .8rem; margin: .1rem 0 .35rem; }
.notebook-observed { padding-left: .6rem; border-left: 3px solid #a8c582; }
.notebook-page details > summary { font-weight: 650; padding: .2rem 0; }
.notebook-page details details { margin-left: .5rem; }

#keyboard-help {
  position: absolute;
  right: var(--right);
  bottom: var(--bottom);
  padding: 0;
  border: 0;
}
#keyboard-help > summary {
  display: grid;
  place-content: center;
  list-style: none;
  width: 2.8rem;
  height: 2.6rem;
  color: #2b211b;
  background: var(--amber);
  border: 1px solid #553f31;
  border-radius: .55rem;
  font: 700 1.45rem/1 system-ui, sans-serif;
}
#keyboard-help > summary::-webkit-details-marker { display: none; }
.keyboard-card {
  background: var(--ink);
  color: #fbefd9;
  border: 1px solid #75816d;
  border-radius: .8rem;
  position: absolute;
  right: 0;
  bottom: calc(100% + .55rem);
  width: min(21rem, calc(100cqw - var(--left) - var(--right)));
  max-height: calc(100cqh - var(--top) - var(--bottom) - 3.2rem);
  overflow: auto;
  padding: .85rem;
}
.keyboard-card h2 { font: 700 1.15rem Georgia, serif; margin: 0; }
.keyboard-card dl { margin: .55rem 0; }
.keyboard-card dl div {
  display: flex;
  align-items: baseline;
  gap: .5rem;
  justify-content: space-between;
  border-bottom: 1px solid #657266;
  padding: .35rem 0;
}
.keyboard-card dd { margin: 0; text-align: right; }
.keyboard-card p { color: var(--muted); font-size: .86rem; margin-bottom: 0; }

#forest-chat {
  position: absolute;
  right: var(--right);
  bottom: calc(var(--bottom) + 3.3rem);
  width: min(20rem, calc(100cqw - var(--left) - var(--right)));
  padding: 0;
  border: 1px solid #75816d;
  border-radius: .8rem;
  background: var(--ink);
  color: #fbefd9;
}
#forest-chat:not([open]) { width: max-content; }
#forest-chat > summary { padding: .65rem .85rem; font-weight: 700; }
#forest-chat > p { margin: 0; padding: 0 .85rem .75rem; font-size: .85rem; color: var(--muted); }
#forest-chat ol {
  margin: 0;
  padding: .6rem .75rem .75rem;
  list-style: none;
  max-height: min(34cqh, 18rem);
  overflow: auto;
  overscroll-behavior: contain;
  border-top: 1px solid #75816d;
}
#forest-chat li { display: grid; gap: .35rem; }
#forest-chat li + li { margin-top: .65rem; }
.chat-older { margin: 0 .75rem .45rem; font-size: .8rem; }
.chat-time { justify-self: center; color: var(--muted); font-size: .75rem; }
.chat-line {
  justify-self: start;
  max-width: 92%;
  padding: .45rem .65rem;
  border-radius: .65rem .65rem .65rem .15rem;
  background: #35473a;
  font-size: .85rem;
  overflow-wrap: anywhere;
}
.chat-line strong { display: block; margin-bottom: .1rem; color: #efcb91; font-size: .76rem; }
.chat-line.fox-line {
  justify-self: end;
  border-radius: .65rem .65rem .15rem .65rem;
  background: #4a3e34;
}
.chat-listen { justify-self: start; font-size: .8rem; }
.chat-audio { display: grid; }
.chat-audio span:not(:empty) { padding: .4rem .75rem; font-size: .82rem; }
.chat-audio audio { width: 100%; max-height: 2.5rem; }
@container (max-width: 760px) or (max-height: 520px) {
  #game:has(#fox-panel:not([hidden])) #forest-chat,
  #game:has(#keyboard-help[open]) #forest-chat { visibility: hidden; }
}

.dock-icon {
  display: grid;
  place-items: center;
  min-width: 2.8rem;
  min-height: 2.6rem;
  font-size: 1.3rem;
}
#fox-menu { position: absolute; bottom: var(--bottom); left: var(--left); }
#fox-menu[aria-expanded="true"] { background: var(--amber); }
.field-notes { inset: auto auto calc(var(--bottom) + 3.3rem) var(--left); }
#fox-activities { padding-left: 1.2rem; font-size: .88rem; }
.notebook-dock { position: absolute; top: var(--top); right: var(--right); display: flex; gap: .4rem; }
#notice { top: calc(var(--top) + 3.25rem); }
.world-actions { margin-top: 0; }


#suzano-weather {
  position: absolute;
  top: var(--top);
  left: var(--left);
  max-width: calc(100cqw - var(--left) - var(--right) - 10rem);
  margin: 0;
  padding: .4rem .65rem;
  border-radius: .5rem;
  background: #19271fde;
  color: #fff6e7;
  font-size: .85rem;
  pointer-events: none;
}

#suzano-rain {
  position: absolute;
  inset: 0;
  pointer-events: none;
  background: repeating-linear-gradient(105deg,transparent 0 25px,#d3edff28 26px,transparent 27px 44px);
  mask-image: repeating-linear-gradient(0deg,transparent 0 34px,#000 36px 53px,transparent 55px 80px);
  animation: suzano-rain .52s linear infinite;
}

@keyframes suzano-rain { to { mask-position: 0 80px; } }
@media (prefers-reduced-motion: reduce) { #suzano-rain { animation: none; } }

/* Telas baixas (celular deitado) e estreitas: tudo mais compacto. */
@container (max-height: 520px) {
  #game { --gap: .6rem; }
  .dock-icon { min-width: 2.5rem; min-height: 2.3rem; font-size: 1.15rem; }
  .field-notes { padding: .7rem .85rem; font-size: .92rem; max-height: calc(100cqh - var(--top) - var(--bottom) - 3rem); bottom: calc(var(--bottom) + 3rem); }
  .field-notes h1 { font-size: 1.2rem; }
  .care-panel { padding: .5rem 0 .6rem; }
  .care-panel h2 { margin-bottom: .45rem; }
  .panel-filters { margin: .5rem 0; }
  .panel-actions { margin-top: .6rem; }
  #notice { top: calc(var(--top) + 2.9rem); font-size: .9rem; }
  #suzano-weather { font-size: .78rem; padding: .3rem .55rem; }
}
@container (max-width: 480px) {
  #game { --gap: .6rem; }
  .profile-grid { grid-template-columns: minmax(0,1fr); }
}
/* Toque: botões com área confortável para o dedo. */
@media (pointer: coarse) {
  #forest-chat { bottom: var(--bottom); }
  .panel-filters button, .panel-actions button, #notebook nav button { min-height: 2.5rem; padding: .45rem .75rem; }
}

/* Clareira, entrada e controles de cuidado. */
#game { user-select: none; -webkit-touch-callout: none; }
.arrival-card, .field-notes, .clearing-popover {
  background: #f8edda;
  color: #332b23;
  border: 1px solid #a89072;
  border-radius: 1rem;
  box-shadow: 0 .4rem 1.4rem #1c2a2260;
}
#arrival {
  position: absolute;
  inset: 0;
  z-index: 6;
  display: grid;
  place-items: center;
  padding: var(--top) var(--right) var(--bottom) var(--left);
  background: linear-gradient(135deg,#1d30246b,#47332238);
  transition: opacity 320ms ease;
}
#arrival.leaving { opacity: 0; pointer-events: none; }
.arrival-card { width: min(29rem,100%); padding: clamp(1rem,5cqh,2.5rem); }
.arrival-card h1 { font: 700 clamp(1.8rem,8cqh,3.25rem)/1 Georgia,serif; }
.arrival-card p { line-height: 1.45; }
.arrival-actions { display: flex; flex-wrap: wrap; gap: .5rem; margin-top: 1rem; }
#enter-clearing { background: #e6b86d; color: #2b211b; border-color: #956733; font-weight: 700; }
#enter-clearing:disabled { opacity: .72; }
.clearing-dock {
  position: absolute;
  z-index: 2;
  bottom: var(--bottom);
  left: var(--left);
  right: var(--right);
  width: fit-content;
  max-width: calc(100cqw - var(--left) - var(--right));
  display: flex;
  flex-wrap: wrap;
  gap: .35rem;
  padding: .3rem;
  border: 1px solid #a89072;
  border-radius: .8rem;
  background: #f8eddaf5;
}
.clearing-dock button, .arrival-actions button, .clearing-popover button, #return-letter {
  min-height: 44px;
  min-width: 44px;
  touch-action: manipulation;
  font-size: .86rem;
}
.clearing-dock #feed { background: #e6b86d; color: #2b211b; border-color: #956733; }
/* 🦊 sozinho no canto inferior esquerdo; a barra de ações fica logo ao lado. */
#fox-menu { z-index: 2; color: #2b211b; }
.clearing-dock { left: calc(var(--left) + 3.4rem); }
.clearing-dock:not(:has(button:not([hidden]))) { display: none; }
.clearing-popover {
  display: flex;
  gap: .35rem;
  width: max-content;
  max-width: calc(100cqw - var(--left) - var(--right));
  padding: .4rem;
  position: absolute;
  z-index: 3;
}
#build-options { left: var(--left); bottom: calc(var(--bottom) + 3.8rem); }
#fox-card button:last-child { background: #eee0c5; color: #442f22; }
.field-notes { color-scheme: light; bottom: calc(var(--bottom) + 4rem); z-index: 3; overscroll-behavior: contain; }
.field-notes #action { color: #765023; }
.field-notes .need-heading span,.field-notes details { color: #554132; }
.field-notes .profile-grid div { background: #ecddc5; }
.field-notes .profile-grid dt { color: #5a4434; }
.field-notes :focus-visible,.arrival-card :focus-visible,.clearing-dock :focus-visible { outline-color: #765023; }
.field-notes button,#notebook button { min-height: 44px; min-width: 44px; touch-action: manipulation; }
.notebook-dock { z-index: 2; }
#return-letter { position: relative; font-size: 1.3rem; }
#letter-unread { position: absolute; top: -.2rem; right: -.2rem; width: .8rem; height: .8rem; border-radius: 50%; background: #e0603a; border: 2px solid #fff6e7; }
.visually-hidden { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
#visitor-role {
  position: absolute;
  left: var(--left);
  top: calc(var(--top) + 2.6rem);
  margin: 0;
  padding: .35rem .55rem;
  color: #fff6e7;
  background: #19271fee;
  border-radius: .45rem;
  font-size: .82rem;
  pointer-events: none;
}
#fox-cue {
  position: absolute;
  transform: translate(-50%,-100%);
  color: #332b23;
  background: #fff5dc;
  border: 1px solid #a89072;
  border-radius: .6rem;
  padding: .25rem .5rem;
  font-size: .8rem;
  pointer-events: none;
}
#clearing-tip {
  position: absolute;
  left: var(--left);
  bottom: calc(var(--bottom) + 4.1rem);
  max-width: min(21rem,calc(100cqw - var(--left) - var(--right)));
  display: flex;
  align-items: center;
  gap: .45rem;
  border: 1px solid #a89072;
  border-radius: .65rem;
  background: #f8edda;
  color: #332b23;
  padding: .25rem .35rem .25rem .65rem;
  font-size: .84rem;
}
#clearing-tip button { min-height: 44px; min-width: 44px; }
#game:has(#fox-panel:not([hidden]),#build-options:not([hidden]),#fox-card:not([hidden])) #clearing-tip { visibility: hidden; }
#notice { z-index: 3; top: calc(var(--top) + 3.5rem); }
#forest-chat { bottom: calc(var(--bottom) + 3.75rem); }
#forest-chat > summary { min-height: 44px; }
@media (pointer: coarse) { #keyboard-help { display: none; } }
@media (prefers-reduced-motion: reduce) { #arrival { transition: none; } }
#fox-card { transform: translate(-50%,-50%); }
#build-preview {
  position: absolute;
  width: 2.3rem;
  height: 1.2rem;
  transform: translate(-50%,-50%);
  border: 2px solid #ebefd1;
  border-radius: 50%;
  background: #53784dad;
  pointer-events: none;
}
#build-preview[data-valid="false"] { background: #9b3f31ad; border-color: #ffddc5; }

#computer-status {
  margin: .65rem 0 0;
  color: #554132;
  font-size: .82rem;
}
