@font-face { font-family: "Rye"; src: url("../assets/fonts/Rye-Regular.ttf") format("truetype"); font-display: swap; }
@font-face { font-family: "Rubik"; src: url("../assets/fonts/Rubik-wght.ttf") format("truetype"); font-weight: 300 900; font-display: swap; }

:root {
  --paper: #f1e6cb;
  --paper-dark: #e2d2ab;
  --ink: #1f1a14;
  --ink-soft: #4a4034;
  --red: #b8261b;
  --gold: #e9b53f;
  --gold-deep: #c98a1e;
  --earth: #b5653a;
  --sky: #9fd3ef;
  --ui-scale: 1;
  --font-ui: "Rubik", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --font-news: "Times New Roman", "Noto Serif", Georgia, "Liberation Serif", serif;
  --font-mast: "Rye", "Times New Roman", Georgia, serif;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; background: #1b140d; overflow: hidden; overscroll-behavior: none; }
body { font-family: var(--font-ui); color: var(--ink); -webkit-user-select: none; user-select: none; touch-action: none; }
button { font-family: var(--font-ui); cursor: pointer; touch-action: manipulation; }
[hidden] { display: none !important; }

#app { position: fixed; inset: 0; overflow: hidden; background: #e9c98a; }
#stage { position: absolute; inset: 0; }
#stage canvas { display: block; width: 100%; height: 100%; touch-action: none; }
#labels { position: absolute; inset: 0; pointer-events: none; overflow: hidden; z-index: 2; }
#vignette { position: absolute; inset: 0; pointer-events: none; z-index: 1;
  background: radial-gradient(ellipse at 50% 45%, rgba(0,0,0,0) 55%, rgba(60,25,0,0.32) 100%); }
#flash { position: absolute; inset: 0; pointer-events: none; z-index: 40; background: #fff7dd; opacity: 0; transition: opacity .35s; }

/* record mode: 9:16 frame, larger text, no chrome */
body.record #app { inset: auto; left: 50%; top: 50%; height: 100vh; width: calc(100vh * 9 / 16); max-width: 100vw; max-height: calc(100vw * 16 / 9); transform: translate(-50%, -50%); }
body.record { --ui-scale: 1.18; cursor: none; }
body.record .icon-btn, body.record #debug { display: none !important; }
body.record.nohud #hud { display: none !important; }

/* ---------- HUD ---------- */
#hud { position: absolute; inset: 0; pointer-events: none; z-index: 5; font-size: calc(14px * var(--ui-scale)); }
.hud-top { position: absolute; left: 0; right: 0; top: 0; padding: calc(8px + var(--safe-top)) 10px 0; display: flex; flex-direction: column; gap: 6px; }
.hud-row { display: flex; align-items: center; gap: 8px; }
.hud-day { flex: 1; display: flex; flex-direction: column; line-height: 1.05; color: #fff; text-shadow: 0 2px 0 rgba(70,30,0,.55), 0 0 8px rgba(70,30,0,.35); }
.hud-day b { font-weight: 900; font-size: 1.25em; letter-spacing: .02em; }
.hud-day span { font-family: var(--font-news); font-style: italic; font-size: .95em; opacity: .95; }
.hud-flock { background: var(--paper); border: 2px solid var(--ink); border-radius: 999px; padding: 3px 12px 3px 8px; font-weight: 800; font-size: 1.15em; display: flex; align-items: baseline; gap: 4px; box-shadow: 0 3px 0 rgba(0,0,0,.35); }
.hud-flock .feather { font-size: .95em; }
.hud-flock small { font-weight: 600; color: var(--ink-soft); font-size: .75em; }
.hud-flock.danger { background: #ffd4c7; animation: pulse .6s infinite alternate; }
.hud-flock.bump { animation: bump .35s; }
@keyframes pulse { to { transform: scale(1.07); } }
@keyframes bump { 40% { transform: scale(1.25); } }
.icon-btn { pointer-events: auto; width: 2.6em; height: 2.6em; border-radius: 50%; border: 2px solid var(--ink); background: var(--paper); font-weight: 900; font-size: .9em; box-shadow: 0 3px 0 rgba(0,0,0,.35); color: var(--ink); }
.bars { gap: 10px; }
.bar { flex: 1; display: flex; align-items: center; gap: 6px; background: rgba(31,26,20,.55); border-radius: 10px; padding: 5px 8px; color: #fff; }
.bar-label { font-weight: 800; font-size: .72em; letter-spacing: .08em; }
.bar-value { font-weight: 900; min-width: 2.6em; text-align: right; }
.track { position: relative; flex: 1; height: 12px; background: rgba(255,255,255,.18); border-radius: 6px; overflow: visible; }
.track .fill { position: absolute; left: 0; top: 0; bottom: 0; width: 0%; border-radius: 6px; background: linear-gradient(90deg, #f3cf6b, #e2a12c); box-shadow: inset 0 -3px 0 rgba(0,0,0,.18); transition: width .15s linear; }
.bar.wheat.met .fill { background: linear-gradient(90deg, #a8e06b, #5fb83a); }
.track .goal { position: absolute; top: -4px; bottom: -4px; width: 3px; background: #fff; border-radius: 2px; box-shadow: 0 0 0 1.5px var(--ink); }
.bar.sun .fill { background: linear-gradient(90deg, #ffe08a, #ff9a3c, #e0503a); }
.sun-icon { position: absolute; top: 50%; width: 16px; height: 16px; margin: -8px 0 0 -8px; border-radius: 50%; background: radial-gradient(circle, #fff6c8 0 35%, #ffc94a 36% 100%); box-shadow: 0 0 10px #ffcc4a; }

.hint { position: absolute; left: 50%; top: calc(98px * var(--ui-scale) + var(--safe-top)); transform: translateX(-50%); max-width: min(92%, 440px); width: max-content; background: var(--paper); border: 2px solid var(--ink); border-radius: 12px; padding: 8px 14px; font-weight: 700; text-align: center; box-shadow: 0 4px 0 rgba(0,0,0,.3); opacity: 0; transition: opacity .3s, transform .3s; pointer-events: none; font-size: 1em; }
.hint.show { opacity: 1; transform: translateX(-50%) translateY(4px); }
.toast { position: absolute; left: 50%; top: 40%; transform: translate(-50%, -50%) scale(.6); font-weight: 900; font-size: 1.7em; color: #fff; text-align: center; text-shadow: 0 3px 0 var(--ink), 0 0 12px rgba(0,0,0,.4); -webkit-text-stroke: 1px var(--ink); opacity: 0; pointer-events: none; white-space: nowrap; }
.toast.show { animation: toast 1.6s ease-out forwards; }
@keyframes toast { 0% { opacity: 0; transform: translate(-50%,-50%) scale(.4) rotate(-6deg); } 15% { opacity: 1; transform: translate(-50%,-50%) scale(1.12) rotate(2deg); } 25% { transform: translate(-50%,-50%) scale(1) rotate(-1deg); } 80% { opacity: 1; } 100% { opacity: 0; transform: translate(-50%,-60%) scale(1); } }

.hud-bottom { position: absolute; left: 0; right: 0; bottom: calc(14px + var(--safe-bottom)); display: flex; justify-content: center; align-items: flex-end; gap: 12px; padding: 0 12px; }
.scatter-btn { pointer-events: auto; min-width: 9.5em; height: 4.1em; border-radius: 999px; border: 3px solid var(--ink); background: linear-gradient(#ffd25e, #f0a92b); color: var(--ink); font-weight: 900; font-size: 1.05em; letter-spacing: .04em; display: flex; align-items: center; justify-content: center; gap: 8px; box-shadow: 0 6px 0 #7a4a10, 0 8px 14px rgba(0,0,0,.3); transition: transform .08s; }
.scatter-btn:active { transform: translateY(4px); box-shadow: 0 2px 0 #7a4a10; }
.scatter-btn.on { background: linear-gradient(#9fe0ff, #4fb0e8); box-shadow: 0 6px 0 #1d5a80, 0 8px 14px rgba(0,0,0,.3); }
.scatter-btn.pulse { animation: scatterPulse .7s infinite alternate; }
@keyframes scatterPulse { to { transform: scale(1.1); box-shadow: 0 6px 0 #7a4a10, 0 0 0 8px rgba(255,210,94,.5); } }
.scatter-ico { font-size: 1.5em; line-height: 1; }
.pill-btn { pointer-events: auto; border: 3px solid var(--ink); border-radius: 999px; background: #8fd16a; font-weight: 900; padding: .8em 1.1em; font-size: .95em; box-shadow: 0 5px 0 #2f6b1b; animation: pulse .8s infinite alternate; }

/* ---------- world-anchored labels ---------- */
.lbl { position: absolute; left: 0; top: 0; will-change: transform; white-space: nowrap; pointer-events: none; font-size: calc(12px * var(--ui-scale)); }
.name-tag { transform-origin: 50% 100%; text-align: center; }
.name-tag .n { display: inline-block; background: rgba(255,250,235,.92); border: 1.5px solid var(--ink); border-radius: 8px; padding: 1px 6px; font-weight: 800; color: var(--ink); }
.name-tag .c { display: block; font-size: .78em; font-weight: 700; color: #fff; text-shadow: 0 1px 2px rgba(0,0,0,.8); margin-top: 1px; }
.name-tag.leader .n { background: var(--gold); font-size: 1.1em; }
.name-tag.wild .n { background: rgba(255,255,255,.55); border-style: dashed; color: var(--ink-soft); }
.float { font-weight: 900; font-size: calc(19px * var(--ui-scale)); color: #fff; -webkit-text-stroke: 1px var(--ink); text-shadow: 0 2px 0 var(--ink); animation: floatUp 1.3s ease-out forwards; }
.float.small { font-size: calc(15px * var(--ui-scale)); }
.float.gold { color: var(--gold); }
.float.red { color: #ff6a4d; }
.float.big { font-size: calc(30px * var(--ui-scale)); }
@keyframes floatUp { 0% { opacity: 0; margin-top: 10px; scale: .5; } 15% { opacity: 1; scale: 1.15; } 30% { scale: 1; } 75% { opacity: 1; } 100% { opacity: 0; margin-top: -46px; } }
.bubble { max-width: 210px; white-space: normal; background: #fff; border: 2px solid var(--ink); border-radius: 14px; padding: 6px 10px 7px; font-weight: 700; font-size: calc(13px * var(--ui-scale)); line-height: 1.2; box-shadow: 0 3px 0 rgba(0,0,0,.3); animation: pop .25s cubic-bezier(.3,1.6,.6,1); }
.bubble::after { content: ""; position: absolute; left: 50%; bottom: -10px; margin-left: -8px; border: 8px solid transparent; border-top-color: var(--ink); border-bottom: 0; }
.bubble .who { display: block; font-size: .72em; text-transform: uppercase; letter-spacing: .06em; color: var(--red); font-weight: 900; }
.bubble.quote { background: var(--paper); font-family: var(--font-news); font-style: italic; }
.bubble.jam { background: #fff2b0; font-size: calc(22px * var(--ui-scale)); font-weight: 900; font-style: italic; color: var(--ink); padding: 6px 14px; letter-spacing: .02em; }
@keyframes pop { from { scale: .2; opacity: 0; } to { scale: 1; opacity: 1; } }
.gauge { width: 46px; height: 7px; border: 1.5px solid var(--ink); border-radius: 4px; background: rgba(255,255,255,.75); overflow: hidden; }
.gauge i { display: block; height: 100%; width: 0; background: linear-gradient(90deg, #ffd04a, #ff4a2a); }
.gauge.jammed { width: auto; height: auto; overflow: visible; background: var(--red); color: #fff; font-weight: 900; font-size: 10px; padding: 1px 5px; animation: pulse .3s infinite alternate; }
.gauge.jammed i { display: none; }
.target-ring { width: 0; height: 0; }

/* ---------- newspaper screens ---------- */
#screen { position: absolute; inset: 0; z-index: 20; display: flex; align-items: center; justify-content: center; padding: calc(12px + var(--safe-top)) 12px calc(12px + var(--safe-bottom)); pointer-events: none; font-size: calc(15px * var(--ui-scale)); }
#screen.active { pointer-events: auto; background: radial-gradient(ellipse at center, rgba(40,20,5,.25), rgba(25,12,2,.62)); }
.paper { position: relative; width: min(100%, 520px); max-height: 100%; overflow-y: auto; overflow-x: hidden; background:
    radial-gradient(circle at 20% 15%, rgba(255,255,255,.35), transparent 40%),
    radial-gradient(circle at 80% 85%, rgba(140,100,40,.18), transparent 45%),
    repeating-linear-gradient(0deg, rgba(90,60,20,.035) 0 1px, transparent 1px 3px),
    var(--paper);
  color: var(--ink); padding: 16px 18px 18px; box-shadow: 0 18px 40px rgba(0,0,0,.45), inset 0 0 50px rgba(120,80,30,.25); border-radius: 2px; transform: rotate(-1deg); scrollbar-width: none; }
.paper::-webkit-scrollbar { display: none; }
.paper.spin { animation: paperSpin .85s cubic-bezier(.2,.9,.25,1.05); }
.paper.slide { animation: paperSlide .5s cubic-bezier(.2,.9,.25,1.1); }
@keyframes paperSpin { from { transform: rotate(-900deg) scale(.05); opacity: 0; } 60% { opacity: 1; } to { transform: rotate(-1deg) scale(1); } }
@keyframes paperSlide { from { transform: translateY(70vh) rotate(8deg); } to { transform: rotate(-1deg); } }
.masthead { font-family: var(--font-mast); text-align: center; font-size: 2.05em; letter-spacing: .02em; line-height: 1; padding-bottom: 4px; }
.edition { display: flex; justify-content: space-between; border-top: 3px double var(--ink); border-bottom: 1px solid var(--ink); font-family: var(--font-news); font-size: .78em; padding: 3px 0; margin-bottom: 10px; font-style: italic; }
.headline { font-family: var(--font-news); font-weight: 900; text-transform: uppercase; font-size: 2.15em; line-height: .98; text-align: center; letter-spacing: -.01em; margin: 6px 0 6px; }
.headline.huge { font-size: 2.7em; }
.subhead { font-family: var(--font-news); text-align: center; font-style: italic; font-size: 1.08em; margin-bottom: 10px; border-bottom: 1px solid var(--ink); padding-bottom: 8px; }
.kicker { text-align: center; font-weight: 900; letter-spacing: .14em; font-size: .75em; color: var(--red); }
.fact { font-family: var(--font-news); font-size: 1.04em; line-height: 1.38; margin: 8px 0; text-align: justify; hyphens: auto; }
.fact::first-letter { font-size: 2.6em; float: left; line-height: .85; padding: 3px 5px 0 0; font-weight: 900; }
.plain { font-family: var(--font-news); font-size: 1.02em; line-height: 1.35; text-align: center; margin: 8px 0; }
.source { font-size: .72em; color: var(--ink-soft); font-style: italic; font-family: var(--font-news); }
.cols { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; border-top: 1px solid var(--ink); padding-top: 8px; margin-top: 8px; }
.col h4 { margin: 0 0 4px; font-size: .72em; letter-spacing: .12em; text-transform: uppercase; color: var(--red); }
.col p, .col li { margin: 0; font-size: .9em; line-height: 1.3; font-weight: 600; }
.col ul { margin: 0; padding-left: 1.1em; }
.stats { display: grid; grid-template-columns: 1fr auto; gap: 3px 10px; font-family: var(--font-news); font-size: 1em; margin: 8px 0; border-top: 1px solid var(--ink); border-bottom: 1px solid var(--ink); padding: 8px 0; }
.stats b { font-family: var(--font-ui); font-weight: 900; text-align: right; }
.btns { display: flex; flex-wrap: wrap; gap: 8px; justify-content: center; margin-top: 12px; }
.btn { border: 3px solid var(--ink); background: var(--gold); color: var(--ink); font-weight: 900; font-size: 1.02em; padding: .7em 1.2em; border-radius: 10px; box-shadow: 0 5px 0 var(--ink); letter-spacing: .03em; }
.btn:active { transform: translateY(3px); box-shadow: 0 2px 0 var(--ink); }
.btn.big { font-size: 1.25em; padding: .75em 1.6em; width: 100%; }
.btn.alt { background: var(--paper-dark); }
.btn.red { background: var(--red); color: #fff; }
.btn.blue { background: #8cc8ea; }
.btn.small { font-size: .82em; padding: .5em .8em; box-shadow: 0 3px 0 var(--ink); }
.row-mini { display: flex; justify-content: space-between; align-items: center; gap: 8px; margin-top: 10px; font-size: .82em; }
.row-mini a { color: var(--ink-soft); }
.votes { display: flex; align-items: center; justify-content: center; gap: 10px; font-weight: 900; margin: 10px 0 2px; }
.votes .v { padding: 4px 10px; border: 2px solid var(--ink); border-radius: 6px; }
.votes .v.emu { background: #f7d77a; }
.votes .v.army { background: #b9c48e; }
.votes-title { text-align: center; font-size: .72em; letter-spacing: .12em; text-transform: uppercase; color: var(--ink-soft); }
.cta { text-align: center; font-weight: 800; font-size: .88em; margin-top: 8px; color: var(--red); }
.title-photo { position: relative; height: 0; }
.stamp { display: inline-block; border: 4px solid var(--red); color: var(--red); font-weight: 900; padding: 2px 10px; transform: rotate(-8deg); letter-spacing: .08em; border-radius: 6px; font-size: 1.3em; opacity: .9; }
.quote { font-family: var(--font-news); font-style: italic; font-size: 1.25em; line-height: 1.25; text-align: center; margin: 10px 4px 2px; }
.quote-attr { text-align: center; font-size: .85em; font-family: var(--font-news); margin-bottom: 8px; }
.share-preview { width: 100%; max-width: 230px; display: block; margin: 8px auto; border: 2px solid var(--ink); box-shadow: 0 6px 14px rgba(0,0,0,.3); background: #ddd; aspect-ratio: 9/16; object-fit: cover; }
.team-pick { display: flex; gap: 8px; justify-content: center; }
.team-pick .btn { flex: 1; }
.team-pick .btn.sel { outline: 4px solid var(--red); outline-offset: 2px; }
.pause-paper .btn { width: 100%; margin-top: 6px; }

/* ---------- loading ---------- */
#loading { position: absolute; inset: 0; z-index: 60; display: flex; align-items: center; justify-content: center; background: radial-gradient(ellipse at center, #e8b65a, #9a5a24); transition: opacity .5s; }
#loading.done { opacity: 0; pointer-events: none; }
.loading-paper { background: var(--paper); padding: 18px 26px; transform: rotate(-2deg); box-shadow: 0 12px 30px rgba(0,0,0,.4); text-align: center; min-width: 250px; font-family: var(--font-news); font-style: italic; }
.loading-bar { height: 8px; border: 2px solid var(--ink); margin-top: 10px; }
.loading-bar i { display: block; height: 100%; width: 0; background: var(--ink); transition: width .2s; }

/* ---------- debug ---------- */
#debug { position: fixed; left: 6px; bottom: 6px; z-index: 100; background: rgba(15,12,8,.86); color: #e8f7c8; font: 11px/1.35 ui-monospace, Menlo, monospace; padding: 8px; border-radius: 8px; max-width: 290px; max-height: 60vh; overflow: auto; pointer-events: auto; }
#debug button, #debug select { font: 11px ui-monospace, Menlo, monospace; margin: 2px 2px 0 0; padding: 3px 6px; border-radius: 4px; border: 1px solid #889; background: #2c3; color: #000; }
#debug .warn { color: #ffb36b; }
#debug.collapsed .body { display: none; }

@media (min-aspect-ratio: 4/3) {
  #hud { font-size: calc(15px * var(--ui-scale)); }
  .hud-top { left: 50%; right: auto; width: min(560px, 100%); transform: translateX(-50%); }
}
@media (max-height: 640px) { #screen { font-size: calc(13px * var(--ui-scale)); } }
/* portrait: menus sit low so the flock stays visible in the top third */
@media (max-aspect-ratio: 3/4) { #screen.low { align-items: flex-end; } }
