/* Base and shared components of every screen (docs/design.md 6). Needs tokens.css first.
   Screens add their own file (home.css, teacher.css, doc.css). */

*, *::before, *::after { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  min-height: 100dvh;
  font-family: var(--font-ui);
  font-size: var(--fs-md);
  line-height: var(--lh-body);
  color: var(--ink);
  background: var(--paper);
  -webkit-font-smoothing: antialiased;
  font-feature-settings: 'tnum' 1;
  /* Korean: break between words, never inside one. */
  word-break: keep-all;
  overflow-wrap: anywhere;
}

h1, h2, h3 { text-wrap: balance; }

/* Paper grain: a tiny turbulence tile multiplied over everything. */
body::after {
  content: '';
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 100;
  opacity: 0.32;
  mix-blend-mode: multiply;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='180' height='180'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='.9' numOctaves='2' stitchTiles='stitch'/%3E%3CfeColorMatrix values='0 0 0 0 .45 0 0 0 0 .4 0 0 0 0 .3 0 0 0 .22 0'/%3E%3C/filter%3E%3Crect width='180' height='180' filter='url(%23n)'/%3E%3C/svg%3E");
}

h1, h2, h3, p { margin: 0; }

.display {
  font-family: var(--font-display);
  /* Jua ships one weight; 800 only reaches the system fallback. */
  font-weight: 800;
  font-synthesis: none;
  letter-spacing: -0.01em;
  line-height: var(--lh-tight);
}

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

:focus-visible {
  outline: 4px solid var(--sun-deep);
  outline-offset: 3px;
}

/* ---------------------------------------------------------------- icons */
.ico { width: 1em; height: 1em; display: inline-block; flex: none; vertical-align: -0.15em; overflow: visible; }

/* ---------------------------------------------------------------- buttons
   Paper-cut sticker: ink outline + hard offset shadow; press sinks 2px. */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--s-2);
  min-height: 56px;
  min-width: var(--hit);
  padding: 0 var(--s-5);
  font: 800 var(--fs-lg) / 1.2 var(--font-ui);
  color: var(--ink);
  text-decoration: none;
  background: var(--paper-hi);
  border: 2.5px solid var(--ink);
  border-radius: var(--r-control);
  box-shadow: 0 4px 0 var(--ink);
  cursor: pointer;
  transition: transform var(--t-tap) var(--ease-out), box-shadow var(--t-tap) var(--ease-out);
  touch-action: manipulation;
}
.btn:active { transform: translateY(3px); box-shadow: 0 1px 0 var(--ink); }
.btn-sun { background: var(--sun); }
.btn-deep { background: var(--map-deep); color: var(--paper-hi); }
.btn-lg { min-height: 64px; font-size: var(--fs-xl); }
.btn-quiet {
  min-height: var(--hit);
  padding: 0 var(--s-3);
  font: 700 var(--fs-md) / 1.2 var(--font-ui);
  color: var(--ink-soft);
  background: transparent;
  border: 0;
  box-shadow: none;
  text-decoration: underline;
  text-underline-offset: 4px;
  text-decoration-thickness: 2px;
}
.btn-icon {
  width: var(--hit);
  height: var(--hit);
  min-height: var(--hit);
  padding: 0;
  border-radius: var(--r-chip);
  font-size: 22px;
  box-shadow: 0 3px 0 var(--ink);
}

/* ---------------------------------------------------------------- chips */
.chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  min-height: 36px;
  padding: 4px 14px 4px 10px;
  font-weight: 800;
  font-size: var(--fs-sm);
  border-radius: var(--r-chip);
  background: var(--paper-hi);
  border: 2px solid var(--ink);
  white-space: nowrap;
}
.chip .ico { font-size: 22px; }
.chip-over { background: var(--over-tint); color: #7A2E06; border-color: var(--over); }
.chip-under { background: var(--under-tint); color: #183E66; border-color: var(--under); }
.chip-ok { background: var(--ok-tint); color: #154A25; border-color: var(--ok); }
.chip-gone { background: var(--gone-tint); color: #3D423A; border-color: var(--gone); }
.chip-nature { background: var(--role-producer-tint); color: #24521A; border: 2px dashed var(--role-producer); }

/* Season chip: icon + "3년 봄" */
.season {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  min-height: 44px;
  padding: 4px 16px 4px 6px;
  border-radius: var(--r-chip);
  background: var(--paper-hi);
  border: 2.5px solid var(--ink);
  font: 800 var(--fs-lg) / 1 var(--font-display);
  font-synthesis: none;
  white-space: nowrap;
}
.season-dot {
  width: 32px; height: 32px; border-radius: 50%;
  display: grid; place-items: center;
  border: 2px solid var(--ink);
}
.season-dot .ico { font-size: 20px; }
[data-season='spring'] .season-dot { background: #F6C9D3; }
[data-season='summer'] .season-dot { background: #9ED36A; }
[data-season='autumn'] .season-dot { background: #F0A14A; }
[data-season='winter'] .season-dot { background: #DCE7F2; }

/* ---------------------------------------------------------------- role badge
   A creature always sits on its role shape. Shape carries role for colour-blind users. */
.critter {
  position: relative;
  display: inline-grid;
  place-items: center;
  width: 64px;
  height: 64px;
  flex: none;
}
.critter > .badge { position: absolute; inset: 0; width: 100%; height: 100%; }
.critter > .art { position: relative; width: 82%; height: 82%; }
.critter[data-role='producer'] { color: var(--role-producer-tint); }
.critter[data-role='consumer'] { color: var(--role-consumer-tint); }
.critter[data-role='upper'] { color: var(--role-upper-tint); }
.critter[data-role='apex'] { color: var(--role-apex-tint); }
.critter[data-role='decomposer'] { color: var(--role-decomposer-tint); }
.critter.strong[data-role='producer'] { color: var(--role-producer); }
.critter.strong[data-role='consumer'] { color: var(--role-consumer); }
.critter.strong[data-role='upper'] { color: var(--role-upper); }
.critter.strong[data-role='apex'] { color: var(--role-apex); }
.critter.strong[data-role='decomposer'] { color: var(--role-decomposer); }

/* ---------------------------------------------------------------- scene */
.scene {
  position: relative;
  overflow: hidden;
  isolation: isolate;
  background: linear-gradient(180deg, var(--sky-top), var(--sky-bottom) 85%);
}
/* Landscape: 1600x400 artwork pinned to the bottom, sliced to fill. */
.scene-art {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  width: 100%;
  height: var(--land-h, 70%);
  display: block;
  transition: filter var(--t-scene) ease;
}
.scene-sun {
  position: absolute;
  top: var(--sun-y, 14%);
  right: var(--sun-x, 16%);
  width: clamp(56px, 9vw, 140px);
  aspect-ratio: 1;
  border-radius: 50%;
  background: #FFF7D6;
  box-shadow: 0 0 0 clamp(14px, 2.4vw, 36px) rgba(255, 247, 214, 0.45), 0 0 0 clamp(30px, 5vw, 76px) rgba(255, 247, 214, 0.2);
}
[data-season='autumn'] .scene-sun { background: #FFE0A6; }
[data-season='winter'] .scene-sun { background: #FFFFFF; }
.l-far { fill: var(--l-far); color: var(--l-far-2); }
.l-mid { fill: var(--l-mid); color: var(--l-mid-2); }
.l-near { fill: var(--l-near); color: var(--l-near-2); }
.l-ground { fill: var(--ground); }
.l-paper { fill: var(--paper); }
.cloud { fill: #FFFFFF; opacity: 0.85; }
.spark { fill: var(--accent); }
.snow { fill: #FFFFFF; display: none; }
[data-season='winter'] .snow { display: inline; }

/* Health mood: the whole world loses colour and gathers haze. */
.haze {
  position: absolute;
  inset: 0;
  pointer-events: none;
  opacity: 0;
  background: linear-gradient(180deg, rgba(150, 130, 100, 0.55), rgba(120, 100, 80, 0.15) 70%);
  mix-blend-mode: multiply;
  transition: opacity var(--t-scene) ease;
}
[data-mood='uneasy'] .scene-art,
[data-mood='uneasy'] .scene-sun { filter: saturate(0.72); }
[data-mood='uneasy'] .haze { opacity: 0.35; }
[data-mood='bad'] .scene-art,
[data-mood='bad'] .scene-sun { filter: saturate(0.4) brightness(0.96); }
[data-mood='bad'] .haze { opacity: 0.8; }

/* ---------------------------------------------------------------- panels */
.sheet {
  background: var(--paper-hi);
  border: 2.5px solid var(--ink);
  border-radius: var(--r-panel);
  box-shadow: 0 5px 0 var(--ink);
}

/* ---------------------------------------------------------------- code form
   The room code form of the first screen and /chase (docs/design.md 5.1). */
.join {
  position: relative;
  z-index: 1;
  display: grid;
  gap: var(--s-3);
  padding: var(--s-5) var(--s-4) var(--s-4);
}
.join-title { font-size: var(--fs-2xl); }
.join-fields { display: grid; gap: var(--s-3); }
.join-field { display: grid; gap: var(--s-1); min-width: 0; }
.join-label { font-weight: 800; font-size: var(--fs-lg); }
.join-input {
  width: 100%;
  min-width: 0;
  min-height: 64px;
  padding: 0 var(--s-2);
  font: 800 2.125rem / 1 var(--font-display);
  font-synthesis: none;
  letter-spacing: 0.16em;
  text-indent: 0.16em;
  text-align: center;
  color: var(--ink);
  background: var(--paper);
  border: 2.5px solid var(--ink);
  border-radius: var(--r-control);
  box-shadow: inset 0 4px 0 rgba(31, 43, 28, 0.08);
}
.join-input::placeholder { color: #7F8A6E; } /* 3.2:1 on the paper field: an example, still clearly empty */
.join-input[aria-invalid='true'] { border-color: var(--over); box-shadow: inset 0 0 0 2px var(--over); }
.join-error {
  padding: var(--s-2) var(--s-3);
  font-weight: 800;
  color: #7A2E06;
  background: var(--over-tint);
  border: 2px solid var(--over);
  border-radius: var(--r-control);
}
.join-error[hidden] { display: none; }
.join-go { width: 100%; }
.join-help { font-size: var(--fs-sm); line-height: 1.5; color: var(--ink-soft); font-weight: 600; }
@media (min-width: 900px) {
  .join { padding: var(--s-5); }
  .join-fields { grid-template-columns: 1fr 1fr; }
}

/* ---------------------------------------------------------------- meters */
.meter {
  position: relative;
  height: 20px;
  border-radius: var(--r-chip);
  background: var(--paper-lo);
  border: 2.5px solid var(--ink);
  overflow: hidden;
}
.meter > i {
  position: absolute;
  inset: 0 auto 0 0;
  width: var(--v, 50%);
  border-radius: var(--r-chip);
  background: var(--c, var(--ok));
  box-shadow: inset 0 -4px 0 rgba(0, 0, 0, 0.12), inset 0 3px 0 rgba(255, 255, 255, 0.35);
  transition: width 600ms var(--ease-out);
}

/* ---------------------------------------------------------------- placed things
   --x/--y/--s (and --d delay) come from data via CSSOM setProperty, or from a screen's CSS
   class for fixed artwork. Never a style="" attribute (CSP). */
.at {
  position: absolute;
  left: var(--x, 0);
  top: var(--y, 0);
  width: var(--s, 64px);
  height: var(--s, 64px);
}
.dweller { overflow: visible; }
.bob { animation: bob 3.2s ease-in-out infinite; animation-delay: var(--d, 0s); }
.sway { animation: sway 4s ease-in-out infinite; animation-delay: var(--d, 0s); transform-origin: 50% 100%; }

.wide-only { display: none; }
@media (min-width: 900px) {
  .wide-only { display: block; }
}

/* ---------------------------------------------------------------- motion */
@keyframes bob { 0%, 100% { transform: translateY(0); } 50% { transform: translateY(-6px); } }
@keyframes sway { 0%, 100% { transform: rotate(-3deg); } 50% { transform: rotate(3deg); } }
@keyframes fall {
  0% { transform: translate(0, -40px) rotate(0deg); opacity: 0; }
  10% { opacity: 1; }
  100% { transform: translate(-60px, 110vh) rotate(320deg); opacity: 1; }
}
@keyframes pop { 0% { transform: scale(0.4); opacity: 0; } 60% { transform: scale(1.12); opacity: 1; } 100% { transform: scale(1); } }
@keyframes rise { 0% { transform: translateY(0); opacity: 1; } 100% { transform: translateY(-36px); opacity: 0; } }
@keyframes pulse-ring { 0% { transform: scale(0.9); opacity: 0.9; } 100% { transform: scale(1.5); opacity: 0; } }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}
