/* Ben's World — layout and look (on top of ../app/styles.css) */
:root {
  --bg: #ece3cd;
  --surface: #fbf6e9;
  --surface-2: #efe6d0;
  --text: #2a2118;
  --muted: #6e604c;
  --border: #d8cbab;
  --accent: #3d7a35;
  --accent-text: #ffffff;
  --accent-soft: #dcebcf;
  --frame: #4a3a28;
  --gold: #e3b53f;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #15130e;
    --surface: #211d16;
    --surface-2: #2c271e;
    --text: #efe7d6;
    --muted: #ab9f88;
    --border: #3b3428;
    --accent: #7cc552;
    --accent-text: #11200b;
    --accent-soft: #233a1a;
    --frame: #0b0a07;
  }
}

.px { image-rendering: pixelated; image-rendering: crisp-edges; }
.title { font-weight: 800; letter-spacing: .02em; }
.small-title { font-size: 1.15rem; }
.block { display: block; width: 100%; text-align: center; text-decoration: none; margin-top: 14px; }
a.btn { display: inline-block; padding: 10px 16px; border-radius: 10px; }
a.btn.primary { background: var(--accent); color: var(--accent-text); font-weight: 600; }

/* ---------- sign in ---------- */
.signin { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
.signin-box { width: min(420px, 100%); text-align: center; }
.signin-logo { width: 88px; height: 88px; border-radius: 20px; image-rendering: pixelated; }
.signin h1 { font-size: 2rem; margin-top: 10px; }
.signin-card { text-align: left; padding: 18px; margin-top: 16px; }
.signin-card p { margin-top: 0; }
.signin-card .link { margin-top: 10px; }

/* ---------- HUD ---------- */
.game { max-width: 1040px; margin: 0 auto; padding: max(10px, env(safe-area-inset-top)) 12px 24px; }
.hud { position: sticky; top: 0; z-index: 3; background: var(--bg); padding-bottom: 8px; }
.hud-top { display: flex; align-items: center; gap: 6px; }
.hud-top .title { margin-right: auto; }
.hud-top .icon-btn { color: var(--text); }
#player-name { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 40vw; }

.resources { display: grid; grid-template-columns: repeat(4, 1fr); gap: 6px; margin-top: 4px; }
.res {
  background: var(--surface); border: 1px solid var(--border); border-radius: 10px;
  padding: 6px 8px; display: grid; grid-template-columns: auto 1fr; gap: 0 6px; align-items: center;
  min-width: 0;
}
.res img { width: 22px; height: 22px; grid-row: span 2; }
.res .amt { font-weight: 800; font-size: 1rem; line-height: 1.1; white-space: nowrap; }
.res .amt small { font-weight: 500; color: var(--muted); font-size: .72rem; }
.res .rate { font-size: .72rem; color: var(--muted); white-space: nowrap; }
.res .rate.pos { color: var(--pos); }
.res .rate.neg { color: var(--neg); }
.res.full .amt { color: var(--gold); }
.res.warn { border-color: var(--neg); }

.jobbar {
  display: flex; align-items: center; gap: 10px; margin-top: 6px;
  background: var(--surface); border: 1px solid var(--border); border-radius: 10px; padding: 6px 10px;
}
.jobbar img { width: 28px; height: 28px; }
.job-text { flex: 1; min-width: 0; font-size: .88rem; font-weight: 600; }
.progress { height: 6px; background: var(--surface-2); border-radius: 3px; overflow: hidden; margin-top: 4px; }
.progress span { display: block; height: 100%; width: 0; background: var(--accent); transition: width .9s linear; }
.jobbar .link { padding: 4px; color: var(--muted); }
.hud .banner { margin: 6px 0 0; }

/* ---------- board ---------- */
.play { display: grid; gap: 14px; margin-top: 6px; }
@media (min-width: 900px) {
  .play { grid-template-columns: minmax(0, 1fr) 360px; align-items: start; }
  .panel { position: sticky; top: 150px; }
}
.board-wrap { display: grid; place-items: center; }
.board {
  display: grid; gap: 3px; padding: 6px;
  width: min(100%, 600px, calc(100vh - 230px));
  min-width: 260px;
  background: var(--frame); border-radius: 12px;
  touch-action: manipulation; user-select: none; -webkit-user-select: none;
}
.sq {
  position: relative; aspect-ratio: 1; padding: 0; border: 0; border-radius: 4px; overflow: visible;
  min-height: 0; background: #5fae3e; cursor: pointer;
}
.sq > img.px { width: 100%; height: 100%; display: block; border-radius: 4px; pointer-events: none; }
.sq:focus-visible { outline: 3px solid var(--gold); outline-offset: 1px; z-index: 2; }
.sq.selected::after {
  content: ""; position: absolute; inset: -3px; border: 3px solid var(--gold); border-radius: 6px;
  pointer-events: none; box-shadow: 0 0 0 2px rgba(0,0,0,.35);
}
.sq:active > img.px { transform: scale(.96); }
.badge {
  position: absolute; pointer-events: none; font-size: clamp(.6rem, 2.2vw, .78rem); font-weight: 800;
  line-height: 1; padding: 3px 5px; border-radius: 6px; border: 2px solid #1d1a22;
}
.badge.lvl { top: 3px; left: 3px; background: var(--gold); color: #1d1a22; }
.badge.alert { top: 3px; right: 3px; background: #d9513f; color: #fff; }
.badge.idle { top: 3px; right: 3px; background: #c4cad3; color: #1d1a22; }
.sq .bar { position: absolute; left: 8%; right: 8%; bottom: 6%; height: 7%; min-height: 4px; background: rgba(0,0,0,.55);
  border-radius: 3px; overflow: hidden; pointer-events: none; }
.sq .bar span { display: block; height: 100%; background: var(--gold); transition: width .9s linear; }
.sq .stockbar span { background: #ffffff; }
.float {
  position: absolute; left: 50%; top: 30%; transform: translate(-50%, 0); pointer-events: none;
  font-weight: 900; font-size: clamp(.9rem, 3.5vw, 1.2rem); color: #fff;
  text-shadow: 0 2px 0 #1d1a22, 0 0 3px #1d1a22; animation: floatup .8s ease-out forwards; z-index: 4;
}
@keyframes floatup { to { transform: translate(-50%, -120%); opacity: 0; } }
@media (prefers-reduced-motion: reduce) { .float { animation-duration: .01s; } }

/* ---------- side / bottom panel ---------- */
.panel { padding: 16px; min-height: 160px; }
.panel h2 { font-size: 1.15rem; display: flex; align-items: center; gap: 10px; }
.panel h2 > img { width: 40px; height: 40px; }
.panel .about { color: var(--muted); font-size: .92rem; margin: 6px 0 10px; }
.stat-row { display: flex; flex-wrap: wrap; gap: 6px; margin: 8px 0; }
.chip-s {
  display: inline-flex; align-items: center; gap: 5px; background: var(--surface-2); border-radius: 999px;
  padding: 3px 10px 3px 6px; font-size: .86rem; font-weight: 600;
}
.chip-s img { width: 16px; height: 16px; }
.chip-s.short { color: var(--neg); }
.status { font-size: .9rem; font-weight: 600; margin: 6px 0; }
.status.bad { color: var(--neg); }
.status.good { color: var(--pos); }
.panel .actions { justify-content: flex-start; margin-top: 12px; }
.panel button.primary { min-width: 120px; }
.hint { font-size: .85rem; color: var(--muted); margin: 8px 0 0; }

.build-list { list-style: none; padding: 0; margin: 10px 0 0; display: grid; gap: 8px; }
.build-item {
  display: grid; grid-template-columns: 48px 1fr auto; gap: 4px 12px; align-items: center;
  padding: 10px; border: 1px solid var(--border); border-radius: 12px; background: var(--surface);
}
.build-item > img { width: 48px; height: 48px; grid-row: span 2; }
.build-item .name { font-weight: 700; }
.build-item .desc { grid-column: 2 / 4; font-size: .82rem; color: var(--muted); }
.build-item .costs { display: flex; flex-wrap: wrap; gap: 4px; grid-column: 2 / 3; }
.build-item button { grid-row: 1 / 3; grid-column: 3; min-height: 40px; padding: 8px 14px; }
.next { margin-top: 14px; padding-top: 12px; border-top: 1px solid var(--border); }
.next h3 { font-size: .95rem; margin-bottom: 4px; }
.help { padding-left: 18px; }
.help li { margin: 6px 0; }

@media (max-width: 420px) {
  .resources { gap: 4px; }
  .res { padding: 5px 6px; gap: 0 4px; }
  .res img { width: 18px; height: 18px; }
  .res .amt { font-size: .9rem; }
}

/* ---------- food, happiness, classes, crops ---------- */
button.res { font: inherit; color: inherit; text-align: left; cursor: pointer; min-height: 0; }
button.res:hover { border-color: var(--accent); }
.res.active { border-color: var(--accent); box-shadow: 0 0 0 1px var(--accent) inset; }
.mood-delighted { background: #4cc985; }
.mood-happy { background: #8fd36a; }
.mood-content { background: #e3c04a; }
.mood-unhappy { background: #e9782f; }
.mood-miserable { background: #d9513f; }
.gauge { position: relative; height: 10px; background: var(--surface-2); border-radius: 5px; overflow: visible; min-width: 80px; }
.gauge .fill { display: block; height: 100%; border-radius: 5px; transition: width .6s ease; }
.gauge .target { position: absolute; top: -3px; bottom: -3px; width: 2px; background: var(--text); opacity: .55; transform: translateX(-1px); }

.food-list, .class-list, .factors { list-style: none; padding: 0; margin: 10px 0; }
.food-row { display: grid; grid-template-columns: 24px 1fr auto auto; gap: 10px; align-items: center; padding: 8px 0; border-top: 1px solid var(--border); }
.food-row:first-child { border-top: 0; }
.food-row img, .class-row > img, .residents > img, .crop-item > img { width: 24px; height: 24px; }
.food-row .amt-s { font-weight: 800; }
.food-row .rate-s { font-size: .85rem; color: var(--muted); min-width: 64px; text-align: right; }
.food-row .rate-s.pos, .factors .pos { color: var(--pos); }
.food-row .rate-s.neg, .factors .neg { color: var(--neg); }

.class-row { display: grid; grid-template-columns: 28px 1fr minmax(110px, 46%); gap: 4px 10px; align-items: center; padding: 10px 0; border-top: 1px solid var(--border); }
.class-row:first-child { border-top: 0; }
.class-row > img { width: 28px; height: 28px; }
.class-row.empty { opacity: .55; }
.class-name { display: grid; }
.class-gauge { display: grid; gap: 4px; }
.class-gauge .small { color: var(--muted); }
.factors { grid-column: 2 / 4; margin: 2px 0 0; display: grid; gap: 2px; }
.factors li { display: flex; justify-content: space-between; color: var(--muted); }

.residents { display: grid; grid-template-columns: 24px 1fr minmax(90px, 40%); gap: 10px; align-items: center; margin: 10px 0; }
.residents .link { padding: 0; min-height: 0; display: block; }
.farm-box h3 { display: flex; align-items: center; gap: 6px; }
.farm-box h3 img { width: 20px; height: 20px; }
.farm-box .progress span.planting, .growbar span.planting { background: #b07d48; }
.crop-head { margin-top: 14px; }
.crop-item > img { grid-row: span 2; width: 32px; height: 32px; }
.crop-item { grid-template-columns: 36px 1fr auto; }
.sq .growbar span { background: #9be06a; }
@media (max-width: 420px) {
  .res .amt small { display: none; }
}
.res .rate, .res .amt { overflow: hidden; text-overflow: ellipsis; }
span.progress { display: block; }

/* ---------- visitors ---------- */
.visitorbar {
  display: flex; align-items: center; gap: 8px; flex-wrap: wrap; width: 100%; margin-top: 6px; text-align: left;
  background: var(--surface); border: 1px solid var(--border); border-radius: 10px; padding: 6px 10px; min-height: 0;
  font: inherit; color: inherit; cursor: pointer;
}
.visitorbar:hover, .visitorbar.active { border-color: var(--accent); }
.visitorbar .vlabel { font-weight: 700; font-size: .85rem; }
.visitorbar .vwait { margin-left: auto; }
.vchip { display: inline-flex; align-items: center; gap: 4px; font-size: .82rem; font-weight: 600; background: var(--surface-2); border-radius: 999px; padding: 2px 8px 2px 4px; }
.vchip img { width: 16px; height: 20px; }
.vchip.v-beggar { color: var(--neg); }
.badge.guests { bottom: 3px; right: 3px; top: auto; background: #4f84cf; color: #fff; }
.visitor-list, .log { list-style: none; padding: 0; margin: 10px 0; }
.visitor-card { display: grid; grid-template-columns: 32px 1fr; gap: 4px 12px; padding: 12px; border: 1px solid var(--border); border-radius: 12px; margin-bottom: 8px; background: var(--surface); }
.visitor-card > img { width: 32px; height: 40px; }
.visitor-card > p, .visitor-card > .actions { grid-column: 1 / 3; margin: 2px 0; }
.visitor-card .about { margin: 4px 0 0; }
.log li { display: grid; grid-template-columns: 92px 1fr; gap: 8px; padding: 6px 0; border-top: 1px solid var(--border); font-size: .88rem; }
.log li:first-child { border-top: 0; }

/* ---------- day & night ---------- */
:root { --dark: 0; }
body::after {
  content: ""; position: fixed; inset: 0; pointer-events: none; z-index: 5;
  background: rgba(12, 18, 50, calc(var(--dark) * .08));
  transition: background 2s linear;
}
.board { position: relative; }
.fx { position: absolute; inset: 0; overflow: hidden; border-radius: 12px; pointer-events: none; }
.nightshade {
  position: absolute; inset: 0; mix-blend-mode: multiply;
  background: rgba(24, 32, 86, calc(var(--dark) * .5));
}
.glows { position: absolute; inset: 0; }
.glow {
  position: absolute; border-radius: 50%; mix-blend-mode: screen; opacity: var(--dark);
  background: radial-gradient(circle, rgba(255, 206, 140, .5) 0%, rgba(255, 176, 90, .24) 34%, rgba(255, 150, 60, 0) 68%);
}
.glow.fire {
  background: radial-gradient(circle, rgba(255, 190, 100, .62) 0%, rgba(255, 150, 60, .3) 32%, rgba(255, 120, 40, 0) 66%);
  animation: flicker 2.6s ease-in-out infinite;
}
@keyframes flicker {
  0%, 100% { transform: scale(1); filter: brightness(1); }
  25% { transform: scale(.97); filter: brightness(.9); }
  55% { transform: scale(1.02); filter: brightness(1.05); }
  80% { transform: scale(.99); filter: brightness(.95); }
}
@media (prefers-reduced-motion: reduce) { .glow.fire { animation: none; } }

/* ---------- timeline ---------- */
.timeline {
  display: flex; gap: 10px; align-items: stretch; margin-top: 6px; cursor: pointer;
  background: var(--surface); border: 1px solid var(--border); border-radius: 10px; padding: 6px 10px;
}
.timeline:hover, .timeline.active, .timeline:focus-visible { border-color: var(--accent); }
.tl-clock { display: flex; align-items: center; gap: 6px; min-width: 76px; }
.tl-clock img { width: 22px; height: 22px; }
.tl-clock b { display: block; font-size: .8rem; line-height: 1.1; }
.tl-time { font-size: .8rem; color: var(--muted); }
.tl-track { position: relative; flex: 1; min-width: 0; height: 46px; }
.tl-sky { position: absolute; left: 0; right: 0; top: 0; height: 32px; border-radius: 6px; box-shadow: inset 0 0 0 1px rgba(0,0,0,.08); }
.tl-events { position: absolute; left: 0; right: 0; top: 0; height: 32px; }
.tl-ev { position: absolute; width: 20px; height: 20px; transform: translateX(-50%); top: 10px; transition: left 1s linear;
  filter: drop-shadow(0 1px 0 rgba(0,0,0,.45)); }
.tl-ev.lane-1 { top: 0; }
.tl-ev.ev-leave { opacity: .5; }
.tl-ev.ev-arrive { filter: drop-shadow(0 0 2px #fff) drop-shadow(0 1px 0 rgba(0,0,0,.5)); }
.tl-ev.ev-sun, .tl-ev.ev-moon { width: 14px; height: 14px; top: 16px; opacity: .85; }
.tl-ticks { position: absolute; left: 0; right: 0; top: 33px; height: 13px; }
.tl-tick { position: absolute; transform: translateX(-50%); font-size: .64rem; color: var(--muted); white-space: nowrap; }
.tl-now { position: absolute; left: 0; top: -3px; height: 38px; width: 3px; background: var(--text); border-radius: 2px; }
.tl-list { list-style: none; padding: 0; margin: 12px 0; }
.tl-row { display: grid; grid-template-columns: 26px 1fr auto; gap: 10px; align-items: center; padding: 8px 0; border-top: 1px solid var(--border); }
.tl-row:first-child { border-top: 0; }
.tl-row img { width: 24px; height: 24px; }
.tl-row.ev-leave img { opacity: .55; }
.tl-when { text-align: right; font-size: .9rem; }
