@import url('https://fonts.googleapis.com/css2?family=DM+Mono:wght@400;500&family=DM+Sans:wght@400;500;600;700&family=Newsreader:opsz,wght@6..72,400;6..72,500;6..72,600&display=swap');

:root {
  --paper: #f2eedf;
  --paper-deep: #e6dfca;
  --ink: #17211d;
  --muted: #6f756d;
  --line: #c9c4b3;
  --green: #245e4f;
  --green-dark: #173d36;
  --yellow: #d49a3a;
  --gray: #777a72;
  --orange: #d95f3e;
  --white: #fffdf5;
  --shadow: 0 24px 70px rgba(54, 47, 32, .12);
  --serif: 'Newsreader', Georgia, serif;
  --sans: 'DM Sans', system-ui, sans-serif;
  --mono: 'DM Mono', ui-monospace, monospace;
  color-scheme: light;
}

html[data-theme="night"] {
  --paper: #121a17;
  --paper-deep: #1a2521;
  --ink: #eff0e7;
  --muted: #a4aaa1;
  --line: #38433e;
  --green: #4f9a83;
  --green-dark: #a9cbbb;
  --yellow: #d5a452;
  --gray: #5c625f;
  --orange: #e47756;
  --white: #19231f;
  --shadow: 0 24px 70px rgba(0, 0, 0, .25);
  color-scheme: dark;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

html { min-width: 320px; background: var(--paper); scroll-behavior: smooth; }

body {
  margin: 0;
  min-height: 100vh;
  color: var(--ink);
  background:
    linear-gradient(rgba(67, 74, 65, .035) 1px, transparent 1px),
    linear-gradient(90deg, rgba(67, 74, 65, .025) 1px, transparent 1px),
    var(--paper);
  background-size: 24px 24px;
  font-family: var(--sans);
  -webkit-font-smoothing: antialiased;
}

button, input { font: inherit; }
button { color: inherit; }
button:focus-visible, a:focus-visible { outline: 3px solid var(--orange); outline-offset: 3px; }

.skip-link { position: fixed; top: 8px; left: 8px; z-index: 20; padding: 10px 14px; background: var(--ink); color: var(--paper); transform: translateY(-150%); }
.skip-link:focus { transform: none; }

.site-header {
  width: min(1120px, calc(100% - 32px));
  height: 78px;
  margin: 0 auto;
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  border-bottom: 1px solid var(--line);
}

.home-link { display: inline-flex; gap: 5px; width: max-content; color: var(--muted); text-decoration: none; font: 500 11px var(--mono); letter-spacing: .12em; }
.home-link span { transition: transform .2s ease; }
.home-link:hover span { transform: translateX(-3px); }

.wordmark { display: flex; align-items: baseline; gap: 9px; font-weight: 700; letter-spacing: .21em; font-size: 21px; }
.wordmark svg { width: 24px; height: 24px; align-self: center; }
.bird-mark { fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.wordmark .bird-mark { color: var(--green); stroke-dasharray: 90; stroke-dashoffset: 90; animation: mark-in .7s ease-out forwards; }
.wordmark > span { animation: wordmark-in .45s ease-out both; }
.wordmark b { color: var(--orange); font: 500 11px var(--mono); letter-spacing: 0; transform: translateY(-9px); }

.header-actions { justify-self: end; display: flex; gap: 3px; }
.icon-button { width: 38px; height: 38px; border: 0; background: transparent; border-radius: 50%; display: grid; place-items: center; cursor: pointer; font: 600 17px var(--serif); }
.icon-button:hover { background: var(--paper-deep); }
.icon-button svg { width: 17px; height: 17px; fill: currentColor; }
.bird-button svg { width: 23px; height: 19px; fill: none; }

main { width: min(1120px, calc(100% - 32px)); margin: 0 auto; }
.play-view { width: min(510px, 100%); min-height: calc(100vh - 144px); margin: 0 auto; padding: 36px 0 32px; display: flex; flex-direction: column; align-items: center; }

.edition-line { width: 100%; display: flex; justify-content: space-between; align-items: center; margin-bottom: 18px; color: var(--muted); font: 500 10px var(--mono); letter-spacing: .12em; }
.edition-line b { color: var(--ink); }
.pilot-badge { padding: 5px 8px; border: 1px solid var(--line); border-radius: 20px; font-size: 8px; }

.board-shell { position: relative; width: min(350px, 83vw); }
.board { position: relative; z-index: 2; display: grid; grid-template-rows: repeat(6, 1fr); gap: 7px; width: 100%; aspect-ratio: 5 / 6; transition: transform .65s cubic-bezier(.16, 1, .3, 1), opacity .45s ease; }
.board.revealing { transform: translateY(-22px) scale(.96); opacity: 0; }
.board-row { display: grid; grid-template-columns: repeat(5, 1fr); gap: 7px; }
.tile {
  position: relative;
  display: grid;
  place-items: center;
  border: 1px solid var(--line);
  background: color-mix(in srgb, var(--paper) 86%, transparent);
  font-size: clamp(1.35rem, 7vw, 2rem);
  font-weight: 600;
  line-height: 1;
  text-transform: uppercase;
  user-select: none;
  transform-style: preserve-3d;
}
.tile.filled { border-color: color-mix(in srgb, var(--ink) 58%, transparent); animation: tile-pop .09s ease; }
.tile[data-state="correct"], .tile[data-state="present"], .tile[data-state="absent"] { color: #fffdf5; border-color: transparent; }
.tile[data-state="correct"] { background: var(--green); }
.tile[data-state="correct"]::after { content: ''; position: absolute; inset: 5px; border: 1px solid rgba(255,255,255,.24); }
.tile[data-state="present"] { background: var(--yellow); background-image: repeating-linear-gradient(135deg, transparent 0 7px, rgba(255,255,255,.14) 7px 9px); }
.tile[data-state="absent"] { background: var(--gray); }
.tile.flip { animation: tile-flip .5s ease both; }
.board-row.shake { animation: shake .32s ease; }

.game-status { min-height: 20px; margin: 18px 0 16px; color: var(--muted); font: 500 11px var(--mono); letter-spacing: .04em; text-align: center; }
.game-status.error { color: var(--orange); }
.return-card { margin: -8px 0 14px; padding: 0; border: 0; border-bottom: 1px solid currentColor; color: var(--green); background: none; cursor: pointer; font: 500 9px var(--mono); letter-spacing: .09em; }

.keyboard { width: 100%; display: flex; flex-direction: column; gap: 6px; }
.key-row { display: flex; justify-content: center; gap: 5px; }
.key {
  height: 50px;
  min-width: 0;
  flex: 1 1 0;
  max-width: 42px;
  padding: 0;
  border: 0;
  border-radius: 4px;
  background: var(--paper-deep);
  color: var(--ink);
  font-size: 12px;
  font-weight: 700;
  cursor: pointer;
  touch-action: manipulation;
  transition: transform .1s ease, background .2s ease;
}
.key:hover { transform: translateY(-1px); }
.key.wide { flex-basis: 62px; max-width: 62px; font-size: 9px; letter-spacing: .03em; }
.key[data-state="correct"] { color: #fff; background: var(--green); }
.key[data-state="present"] { color: #fff; background: var(--yellow); }
.key[data-state="absent"] { color: #fff; background: var(--gray); }

.quiet-progress { width: 100%; margin-top: auto; padding-top: 30px; display: flex; justify-content: space-between; color: var(--muted); font: 500 10px var(--mono); letter-spacing: .08em; }
.quiet-progress button, .site-footer button { border: 0; padding: 0; background: none; cursor: pointer; color: var(--ink); font: inherit; letter-spacing: inherit; }
.quiet-progress button span { display: inline-block; transition: transform .2s ease; }
.quiet-progress button:hover span { transform: translateX(4px); }

.site-footer { width: min(1120px, calc(100% - 32px)); min-height: 66px; margin: 0 auto; border-top: 1px solid var(--line); display: flex; justify-content: space-between; align-items: center; color: var(--muted); font: 500 8px var(--mono); letter-spacing: .1em; }
.site-footer button { color: var(--muted); }

/* Dossier */
.dossier { width: min(900px, 100%); margin: 0 auto; padding: 34px 0 64px; animation: dossier-in .7s cubic-bezier(.16, 1, .3, 1) both; }
.result-strip { display: flex; justify-content: space-between; align-items: center; padding-bottom: 13px; border-bottom: 1px solid var(--line); color: var(--green); font: 500 10px var(--mono); letter-spacing: .14em; }
.result-strip p { margin: 0; }
.text-button { padding: 4px 0; border: 0; border-bottom: 1px solid currentColor; background: none; color: var(--muted); cursor: pointer; font: 500 9px var(--mono); letter-spacing: .1em; }

.specimen-header { min-height: 190px; display: flex; justify-content: space-between; align-items: center; gap: 24px; }
.eyebrow { margin: 0 0 11px; color: var(--orange); font: 500 9px var(--mono); letter-spacing: .18em; }
.specimen-header h1 { margin: 0; font: 500 clamp(3.7rem, 11vw, 7rem)/.78 var(--serif); letter-spacing: -.055em; }
.common-name { margin: 22px 0 1px; font: 500 18px var(--sans); }
.scientific-name { margin: 0; color: var(--muted); font: italic 17px var(--serif); }
.representative-note { margin: 9px 0 0; color: var(--muted); font: 500 7px var(--mono); letter-spacing: .13em; }
.collection-stamp { width: 86px; height: 86px; flex: none; display: grid; place-items: center; border: 2px solid var(--orange); border-radius: 50%; color: var(--orange); font: 500 10px/1.6 var(--mono); letter-spacing: .08em; text-align: center; transform: rotate(7deg); }

.bird-portrait { position: relative; margin: 0; overflow: hidden; background: var(--paper-deep); border: 1px solid color-mix(in srgb, var(--ink) 16%, transparent); }
.bird-portrait::after { content: ''; position: absolute; inset: 0; pointer-events: none; box-shadow: inset 0 0 0 1px rgba(255,255,255,.14), inset 0 -90px 90px rgba(8,14,12,.28); }
.bird-portrait > img { display: block; width: 100%; height: clamp(320px, 58vw, 530px); object-fit: cover; object-position: var(--photo-position, 50% 50%); filter: saturate(.88) contrast(1.03); }
.photo-index { position: absolute; z-index: 2; top: 15px; left: 15px; padding: 7px 9px; color: #fffdf5; background: rgba(12,19,16,.78); backdrop-filter: blur(8px); font: 500 8px var(--mono); letter-spacing: .12em; }
.bird-portrait figcaption { position: absolute; z-index: 2; left: 0; right: 0; bottom: 0; display: flex; justify-content: space-between; gap: 15px; padding: 14px 16px; color: rgba(255,255,255,.82); font: 500 7px/1.5 var(--mono); letter-spacing: .08em; }
.bird-portrait figcaption a { color: inherit; text-decoration: none; border-bottom: 1px solid rgba(255,255,255,.45); }

.field-grid { display: grid; grid-template-columns: repeat(2, 1fr); border: 1px solid var(--line); border-top: 0; }
.field-grid > div { min-height: 105px; padding: 20px; border-right: 1px solid var(--line); border-bottom: 1px solid var(--line); }
.field-grid > div:nth-child(2), .field-grid > div:nth-child(4), .field-grid > div:nth-child(7) { border-right: 0; }
.field-grid .conservation, .field-grid .behavior { grid-column: span 2; min-height: 84px; border-right: 0; }
.field-grid .behavior { border-bottom: 0; }
.field-grid span, .spec-grid span { color: var(--muted); font: 500 8px var(--mono); letter-spacing: .13em; }
.field-grid p { margin: 9px 0 0; font: 500 13px/1.45 var(--sans); }

.truth-card { margin: 42px 0; padding: 36px clamp(24px, 6vw, 62px); border-left: 4px solid var(--green); background: var(--white); box-shadow: var(--shadow); }
.section-number { margin: 0 0 24px; color: var(--green); font: 500 9px var(--mono); letter-spacing: .14em; }
.large-fact { max-width: 26ch; margin: 0; font: 500 clamp(1.8rem, 4.4vw, 2.75rem)/1.08 var(--serif); letter-spacing: -.02em; }

.classified-card { position: relative; padding: clamp(24px, 6vw, 56px); color: #e5e8dd; background: #14201d; box-shadow: var(--shadow); overflow: hidden; }
.classified-card::before { content: 'FOR OFFICIAL USE ONLY  •  FOR OFFICIAL USE ONLY  •  FOR OFFICIAL USE ONLY'; position: absolute; top: 48%; left: -5%; width: 110%; color: rgba(255,255,255,.025); font: 700 44px var(--mono); white-space: nowrap; transform: rotate(-7deg); pointer-events: none; }
.classified-head { position: relative; display: flex; justify-content: space-between; gap: 24px; padding-bottom: 28px; border-bottom: 1px solid rgba(255,255,255,.22); }
.classified-head span { color: #87928c; font: 500 8px var(--mono); letter-spacing: .13em; }
.classified-head h2 { margin: 6px 0 0; font: 500 clamp(2rem, 6vw, 4rem)/1 var(--serif); letter-spacing: -.03em; }
.classified-head strong { align-self: flex-start; padding: 8px 10px; border: 2px solid var(--orange); color: var(--orange); font: 500 9px var(--mono); letter-spacing: .1em; transform: rotate(3deg); }
.spec-grid { position: relative; display: grid; grid-template-columns: repeat(2, 1fr); padding: 18px 0 30px; border-bottom: 1px solid rgba(255,255,255,.22); }
.spec-grid div { padding: 14px 14px 14px 0; }
.spec-grid b { display: block; margin-top: 6px; font: 500 13px/1.4 var(--mono); }
.classified-card h3 { position: relative; margin: 31px 0 7px; color: #87928c; font: 500 9px var(--mono); letter-spacing: .15em; }
.claims { position: relative; }
.claim { display: grid; grid-template-columns: minmax(115px, .6fr) 1.4fr; gap: 20px; padding: 18px 0; border-bottom: 1px solid rgba(255,255,255,.12); }
.claim b { color: #b9c0bb; font: 500 10px/1.5 var(--mono); }
.claim p { margin: 0; font: 400 16px/1.45 var(--serif); }
.fine-print { position: relative; margin: 26px 0 0; color: #77827d; font: 400 8px/1.5 var(--mono); }
.dossier-footer { display: flex; justify-content: space-between; gap: 18px; padding: 15px 0; color: var(--muted); border-bottom: 1px solid var(--line); font: 500 8px var(--mono); letter-spacing: .06em; }
.dossier-footer a { color: var(--ink); text-decoration: none; }
.result-actions { display: flex; gap: 10px; justify-content: center; padding-top: 32px; }

.primary-button, .secondary-button { min-height: 48px; padding: 0 22px; border: 1px solid var(--ink); cursor: pointer; font: 600 10px var(--mono); letter-spacing: .08em; }
.primary-button { color: var(--paper); background: var(--ink); }
.secondary-button { color: var(--ink); background: transparent; }
.primary-button:hover, .secondary-button:hover { transform: translateY(-1px); }

/* Dialogs */
dialog { width: min(520px, calc(100% - 28px)); max-height: min(760px, calc(100dvh - 32px)); padding: 0; color: var(--ink); background: var(--paper); border: 1px solid var(--line); box-shadow: 0 24px 90px rgba(0,0,0,.25); overflow: auto; }
dialog::backdrop { background: rgba(11, 17, 15, .64); backdrop-filter: blur(4px); }
dialog[open] { animation: dialog-in .25s ease both; }
.wide-dialog { width: min(780px, calc(100% - 28px)); }
.dialog-inner { position: relative; padding: clamp(26px, 6vw, 52px); }
.dialog-close { position: absolute; top: 14px; right: 14px; width: 38px; height: 38px; border: 0; background: transparent; color: var(--muted); font: 300 28px var(--sans); cursor: pointer; }
.dialog-inner h2 { margin: 0 0 18px; font: 500 clamp(2.2rem, 8vw, 3.6rem)/1 var(--serif); letter-spacing: -.04em; }
.dialog-inner > p:not(.eyebrow):not(.dialog-note) { color: var(--muted); font: 400 15px/1.65 var(--sans); }
.dialog-inner > .primary-button, .dialog-inner > .secondary-button { width: 100%; margin-top: 20px; }
.example-row { display: grid; grid-template-columns: repeat(5, 1fr); gap: 5px; width: 245px; max-width: 100%; margin: 25px 0; }
.example-row span { aspect-ratio: 1; display: grid; place-items: center; border: 1px solid var(--line); font-weight: 700; }
.example-row span[data-state="correct"] { background: var(--green); color: #fff; }
.example-row span[data-state="present"] { background: var(--yellow); color: #fff; }
.example-row span[data-state="absent"] { background: var(--gray); color: #fff; }
.legend { margin: 0; }
.legend div { display: flex; align-items: center; gap: 10px; margin: 9px 0; }
.legend dd { margin: 0; color: var(--muted); font-size: 12px; }
.swatch { width: 15px; height: 15px; }
.swatch.correct { background: var(--green); }
.swatch.present { background: var(--yellow); }
.swatch.absent { background: var(--gray); }
.lifecycle { display: flex; flex-wrap: wrap; align-items: center; gap: 7px; margin: 24px 0; font: 500 8px var(--mono); letter-spacing: .08em; }
.lifecycle span { padding: 8px 9px; border: 1px solid var(--line); }
.lifecycle span.active { background: var(--green); border-color: var(--green); color: #fff; }
.lifecycle i { color: var(--muted); font-style: normal; }
.inspiration-note { margin-top: 22px !important; padding-top: 16px; border-top: 1px solid var(--line); font: 400 10px/1.6 var(--mono) !important; }

.aviary-summary { display: flex; flex-direction: column; margin: 24px 0; }
.aviary-summary span { font: 500 36px var(--serif); }
.aviary-summary small { color: var(--muted); font: 500 8px var(--mono); letter-spacing: .12em; }
.aviary-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 9px; }
.aviary-card { position: relative; aspect-ratio: .82; padding: 0; overflow: hidden; border: 1px solid var(--line); background: var(--paper-deep); cursor: pointer; text-align: left; }
.aviary-card .mini-photo { position: absolute; inset: 0 0 28%; width: 100%; height: 72%; object-fit: cover; filter: saturate(.8); transition: transform .3s ease, filter .3s ease; }
.aviary-card:hover .mini-photo { transform: scale(1.025); filter: saturate(1); }
.aviary-card .mini-scene { position: absolute; inset: 0 0 28%; display: grid; place-items: center; background: var(--paper-deep); }
.aviary-card .mini-scene::before { content: ''; position: absolute; inset: 13px; border: 1px solid color-mix(in srgb, var(--line) 68%, transparent); }
.aviary-card .mini-scene i { position: relative; color: var(--muted); font: 500 10px var(--mono); font-style: normal; letter-spacing: .14em; }
.aviary-card .card-caption { position: absolute; inset: auto 0 0; padding: 10px; background: var(--paper); border-top: 1px solid var(--line); }
.aviary-card b { display: block; font: 600 11px var(--mono); letter-spacing: .09em; }
.aviary-card small { display: block; margin-top: 3px; color: var(--muted); font: 400 8px var(--sans); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.aviary-card.locked { cursor: default; filter: grayscale(1); }
.dialog-note { margin: 18px 0 0; color: var(--muted); font: 400 9px/1.55 var(--mono); }

.stat-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 1px; margin: 25px 0 34px; background: var(--line); border: 1px solid var(--line); }
.stat-grid div { min-height: 90px; display: flex; flex-direction: column; justify-content: center; padding: 12px; background: var(--paper); text-align: center; }
.stat-grid b { font: 500 30px var(--serif); }
.stat-grid span { color: var(--muted); font: 500 8px var(--mono); letter-spacing: .08em; }
.mini-heading { margin: 0 0 12px; color: var(--muted); font: 500 9px var(--mono); letter-spacing: .12em; }
.era-progress > div:not(.progress-track) { display: flex; justify-content: space-between; padding: 11px 0; font: 500 9px var(--mono); letter-spacing: .06em; }
.progress-track { height: 5px; margin: -4px 0 12px; background: var(--paper-deep); }
.progress-track i { display: block; width: 0; height: 100%; background: var(--green); transition: width .5s ease; }
.locked-era { color: var(--muted); border-top: 1px solid var(--line); }

.toast { position: fixed; z-index: 30; left: 50%; bottom: 24px; max-width: calc(100% - 32px); padding: 11px 15px; color: var(--paper); background: var(--ink); box-shadow: var(--shadow); font: 500 10px var(--mono); letter-spacing: .05em; transform: translate(-50%, 20px); opacity: 0; pointer-events: none; transition: .22s ease; }
.toast.show { transform: translate(-50%, 0); opacity: 1; }

@keyframes tile-pop { 50% { transform: scale(1.05); } }
@keyframes tile-flip { 0% { transform: rotateX(0); } 45% { transform: rotateX(90deg); } 55% { transform: rotateX(90deg); } 100% { transform: rotateX(0); } }
@keyframes shake { 20%, 60% { transform: translateX(-5px); } 40%, 80% { transform: translateX(5px); } }
@keyframes dossier-in { from { opacity: 0; transform: translateY(24px); } }
@keyframes dialog-in { from { opacity: 0; transform: translateY(10px) scale(.985); } }
@keyframes mark-in { to { stroke-dashoffset: 0; } }
@keyframes wordmark-in { from { opacity: 0; transform: translateY(3px); } }

@media (max-width: 600px) {
  .site-header { height: 65px; }
  .home-link { font-size: 0; }
  .home-link::before { content: '←'; font-size: 16px; }
  .wordmark { gap: 6px; font-size: 17px; }
  .wordmark svg { width: 25px; }
  .icon-button { width: 34px; height: 34px; }
  .header-actions .bird-button { display: none; }
  .play-view { min-height: calc(100dvh - 128px); padding-top: 22px; }
  .key { height: 47px; }
  .site-footer { min-height: 55px; }
  .site-footer > span { display: none; }
  .site-footer { justify-content: center; }
  .specimen-header { min-height: 165px; }
  .collection-stamp { width: 68px; height: 68px; font-size: 8px; }
  .field-grid { grid-template-columns: 1fr; }
  .field-grid > div, .field-grid > div:nth-child(2), .field-grid > div:nth-child(4), .field-grid > div:nth-child(7) { border-right: 0; }
  .field-grid .conservation, .field-grid .behavior { grid-column: auto; }
  .bird-portrait > img { height: clamp(320px, 108vw, 460px); }
  .bird-portrait figcaption { flex-direction: column; gap: 4px; }
  .classified-head { flex-direction: column; }
  .classified-head strong { align-self: flex-start; }
  .spec-grid { grid-template-columns: 1fr; }
  .claim { grid-template-columns: 1fr; gap: 7px; }
  .dossier-footer { flex-direction: column; }
  .result-actions { flex-direction: column; }
  .aviary-grid { grid-template-columns: repeat(2, 1fr); }
}

@media (prefers-reduced-motion: reduce) {
  .wordmark .bird-mark { stroke-dashoffset: 0; animation: none; }
  .wordmark > span { opacity: 1; transform: none; animation: none; }
  *, *::before, *::after { scroll-behavior: auto !important; animation-duration: .01ms !important; animation-iteration-count: 1 !important; transition-duration: .01ms !important; }
}
