/* ===========================================================================
   Grarup Gaard - styling
   Big text, big buttons, warm colours. Built to be easy for everyone.
   =========================================================================== */

:root {
  --green: #3f7d3a;
  --green-dark: #2c5a28;
  --green-light: #6aa85f;
  --gold: #e0a800;
  --gold-dark: #b07d00;
  --sky: #bfe3f2;
  --grass: #8ec96a;
  --soil: #b07d52;
  --cream: #fbf7ee;
  --paper: #ffffff;
  --ink: #2a2620;
  --muted: #6b6357;
  --danger: #c0392b;
  --danger-bg: #fde8e5;
  --ok: #2e7d32;
  --ok-bg: #e6f4e6;
  --warn: #d98a00;
  --line: #e4ddcd;
  --shadow: 0 4px 14px rgba(0, 0, 0, 0.12);
  --radius: 16px;
  font-size: 18px;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  padding: 0;
}

body {
  font-family: "Segoe UI", system-ui, -apple-system, "Helvetica Neue", Arial, sans-serif;
  color: var(--ink);
  background: var(--cream);
  line-height: 1.45;
  -webkit-text-size-adjust: 100%;
}

.hidden {
  display: none !important;
}

/* ---------------------------------------------------------------- Buttons */
.btn {
  font: inherit;
  font-weight: 700;
  border: none;
  border-radius: var(--radius);
  padding: 0.7em 1.1em;
  cursor: pointer;
  background: #eee;
  color: var(--ink);
  box-shadow: var(--shadow);
  transition: transform 0.05s ease, filter 0.12s ease;
  line-height: 1.2;
}
.btn:hover {
  filter: brightness(1.04);
}
.btn:active {
  transform: translateY(2px);
}
.btn:disabled {
  opacity: 0.45;
  cursor: not-allowed;
  box-shadow: none;
}
.btn-primary {
  background: var(--green);
  color: #fff;
}
.btn-gold {
  background: var(--gold);
  color: #3a2c00;
}
.btn-ghost {
  background: var(--paper);
  color: var(--green-dark);
  border: 2px solid var(--line);
}
.btn-danger {
  background: var(--danger);
  color: #fff;
}
.btn-big {
  font-size: 1.1rem;
  padding: 0.8em 1.2em;
}
.btn-huge {
  font-size: 1.5rem;
  padding: 0.7em 1.6em;
}
.btn-icon {
  font-size: 1.5rem;
  padding: 0.3em 0.6em;
  background: var(--paper);
  border: 2px solid var(--line);
}
.btn-block {
  width: 100%;
}

/* ---------------------------------------------------------------- Screens */
.screen {
  min-height: 100vh;
}

/* ---------------------------------------------------- Start screen */
#start-screen {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1rem;
  background: linear-gradient(180deg, var(--sky) 0%, var(--grass) 100%);
}
.start-card {
  background: var(--paper);
  border-radius: 24px;
  box-shadow: var(--shadow);
  padding: 1.6rem 1.4rem 2rem;
  max-width: 460px;
  width: 100%;
  text-align: center;
}
.start-scene {
  font-size: 3.2rem;
  display: flex;
  justify-content: center;
  gap: 0.3rem;
  align-items: flex-end;
}
.start-scene .flag {
  font-size: 2rem;
}
.start-title {
  font-size: 2.4rem;
  margin: 0.4rem 0 0.2rem;
  color: var(--green-dark);
}
.start-sub {
  color: var(--muted);
  margin: 0.2rem 0 1.2rem;
}
.field-label {
  display: block;
  text-align: left;
  font-weight: 700;
  margin: 0.6rem 0 0.25rem;
  color: var(--green-dark);
}
.text-input {
  width: 100%;
  font: inherit;
  padding: 0.7em 0.9em;
  border: 2px solid var(--line);
  border-radius: 12px;
  background: var(--cream);
}
.text-input:focus {
  outline: 3px solid var(--green-light);
  border-color: var(--green-light);
}
#start-screen .btn {
  width: 100%;
  margin-top: 0.8rem;
}
.lang-row {
  display: flex;
  gap: 0.6rem;
  margin-top: 1.4rem;
  justify-content: center;
}
.lang-btn {
  font: inherit;
  font-weight: 700;
  border: 2px solid var(--line);
  background: var(--cream);
  border-radius: 12px;
  padding: 0.5em 1em;
  cursor: pointer;
}
.lang-btn.is-active {
  background: var(--green);
  color: #fff;
  border-color: var(--green);
}

/* ---------------------------------------------------- Top bar */
#topbar {
  position: sticky;
  top: 0;
  z-index: 30;
  background: var(--green-dark);
  color: #fff;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.25);
}
.topbar-inner {
  max-width: 980px;
  margin: 0 auto;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.5rem 1.2rem;
  padding: 0.5rem 0.8rem;
}
.stat {
  display: flex;
  align-items: center;
  gap: 0.45rem;
  position: relative;
}
.stat-icon {
  font-size: 1.5rem;
}
.stat-text {
  display: flex;
  flex-direction: column;
  line-height: 1.1;
}
.stat-label {
  font-size: 0.7rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  opacity: 0.8;
}
.stat-text strong {
  font-size: 1.05rem;
}
.topbar-actions {
  margin-left: auto;
}
.nitro-bar {
  position: absolute;
  bottom: -6px;
  left: 0;
  right: 0;
  height: 4px;
  background: rgba(255, 255, 255, 0.25);
  border-radius: 4px;
  overflow: hidden;
}
.nitro-fill {
  height: 100%;
  width: 0%;
  background: var(--green-light);
  transition: width 0.3s ease, background 0.3s ease;
}

/* ---------------------------------------------------- Main layout */
#main {
  max-width: 980px;
  margin: 0 auto;
  padding: 0.8rem 0.8rem 3rem;
}

/* Scene banner (animated) */
.scene-banner {
  position: relative;
  height: 140px;
  border-radius: var(--radius);
  overflow: hidden;
  margin-bottom: 0.9rem;
  box-shadow: var(--shadow);
}
.scene-sky {
  position: absolute;
  inset: 0;
  background: linear-gradient(180deg, #aedcf0 0%, var(--sky) 45%, #e9f6c9 85%);
}

/* Sun, gently glowing */
.scene-sun {
  position: absolute;
  top: 10px;
  right: 24px;
  font-size: 2rem;
  z-index: 1;
  animation: sun-glow 5s ease-in-out infinite;
  filter: drop-shadow(0 0 6px rgba(255, 215, 0, 0.6));
}
@keyframes sun-glow {
  0%, 100% { transform: scale(1); }
  50% { transform: scale(1.12); }
}

/* Drifting clouds */
.scene-clouds {
  position: absolute;
  inset: 0;
  z-index: 1;
  pointer-events: none;
}
.cloud {
  position: absolute;
  font-size: 1.9rem;
  opacity: 0.92;
  will-change: transform;
}
.cloud-1 { top: 14px; animation: drift 34s linear infinite; }
.cloud-2 { top: 36px; font-size: 1.5rem; animation: drift 52s linear infinite; animation-delay: -12s; }
.cloud-3 { top: 6px; font-size: 1.3rem; opacity: 0.8; animation: drift 44s linear infinite; animation-delay: -28s; }
@keyframes drift {
  from { transform: translateX(-15vw); }
  to { transform: translateX(105vw); }
}

/* An occasional bird */
.scene-bird {
  position: absolute;
  top: 30px;
  z-index: 2;
  pointer-events: none;
}
.scene-bird span {
  display: inline-block;
  font-size: 1rem;
  animation: fly 26s linear infinite;
}
@keyframes fly {
  0% { transform: translate(-10vw, 0); }
  45% { transform: translate(55vw, -14px); }
  100% { transform: translate(115vw, -4px); }
}

/* Slowly scrolling distant treeline */
.scene-treeline {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 52px;
  height: 34px;
  overflow: hidden;
  z-index: 2;
  opacity: 0.55;
}
.treeline-inner {
  display: flex;
  width: max-content;
  font-size: 1.5rem;
  line-height: 1;
  animation: treescroll 48s linear infinite;
  will-change: transform;
}
.treeline-inner span {
  white-space: nowrap;
  letter-spacing: 0.15em;
}
@keyframes treescroll {
  from { transform: translateX(0); }
  to { transform: translateX(-50%); }
}

/* Ground with the fixed Grarup village */
.scene-ground {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  height: 56px;
  background: linear-gradient(180deg, #97d172 0%, var(--grass) 100%);
  z-index: 3;
}
.village {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: flex-end;
  justify-content: space-around;
  font-size: 2.4rem;
  padding: 0 0.6rem;
  z-index: 2;
}
.village span {
  line-height: 1;
  transform: translateY(6px);
}
.village .s-church {
  font-size: 3rem;
}

/* The roaming tractor - sits behind the village so it drives among the
   buildings (and is hidden behind the house/church) rather than over them. */
.tractor-track {
  position: absolute;
  inset: 0;
  z-index: 1;
  pointer-events: none;
}
.s-tractor {
  position: absolute;
  bottom: 4px;
  left: 3%;
  animation: drive 18s ease-in-out infinite alternate, bob 0.7s ease-in-out infinite;
  will-change: left, transform;
}
.s-tractor .veh {
  display: inline-block;
  font-size: 2.1rem;
  animation: face 36s linear infinite;
}
@keyframes drive {
  from { left: 3%; }
  to { left: 84%; }
}
@keyframes bob {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(-3px); }
}
/* Drive cycle is 36s (18s each way); flip exactly at the turn. */
@keyframes face {
  0%, 49.9% { transform: scaleX(-1); }   /* facing right while driving right */
  50%, 100% { transform: scaleX(1); }    /* faces left on the way back */
}

/* Snow overlay in winter */
.scene-snow {
  position: absolute;
  inset: 0;
  z-index: 5;
  pointer-events: none;
  background-image:
    radial-gradient(2px 2px at 20% 30%, #fff, transparent),
    radial-gradient(2px 2px at 60% 60%, #fff, transparent),
    radial-gradient(2px 2px at 80% 20%, #fff, transparent),
    radial-gradient(2px 2px at 40% 80%, #fff, transparent),
    radial-gradient(2px 2px at 90% 50%, #fff, transparent);
  background-size: 200px 140px;
  animation: snowfall 8s linear infinite;
  opacity: 0.9;
}
@keyframes snowfall {
  from { background-position: 0 -140px; }
  to { background-position: 0 140px; }
}

/* Respect users who prefer less motion */
@media (prefers-reduced-motion: reduce) {
  .cloud, .scene-bird span, .treeline-inner, .s-tractor, .s-tractor .veh, .scene-sun, .scene-snow {
    animation: none !important;
  }
}

/* Next turn row */
.next-turn-row {
  display: flex;
  gap: 0.8rem;
  align-items: center;
  justify-content: center;
  margin-bottom: 1rem;
  flex-wrap: wrap;
}

/* Panels */
.panel {
  background: var(--paper);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 0.9rem 1rem 1.1rem;
  margin-bottom: 1rem;
}
.panel-title {
  margin: 0 0 0.7rem;
  font-size: 1.3rem;
  color: var(--green-dark);
  border-bottom: 2px solid var(--line);
  padding-bottom: 0.4rem;
}

/* News */
.news-list {
  list-style: none;
  margin: 0;
  padding: 0;
  max-height: 230px;
  overflow-y: auto;
}
.news-list li {
  padding: 0.55rem 0.6rem;
  border-radius: 10px;
  margin-bottom: 0.35rem;
  display: flex;
  gap: 0.55rem;
  align-items: flex-start;
}
.news-list li .news-icon {
  font-size: 1.3rem;
  flex-shrink: 0;
}
.news-good {
  background: var(--ok-bg);
}
.news-bad {
  background: var(--danger-bg);
}
.news-info {
  background: #eef4fb;
}
.news-month {
  font-weight: 700;
  color: var(--muted);
  font-size: 0.8rem;
}

/* Fields grid */
.fields-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
  gap: 0.7rem;
}
.field-card {
  border: 2px solid var(--line);
  border-radius: 14px;
  padding: 0.7rem;
  text-align: center;
  background: var(--cream);
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
}
.field-card.is-pen {
  background: #fbeede;
}
.field-card.is-crop {
  background: #eef7e3;
}
.field-card.for-sale {
  background: #f0f0f0;
  border-style: dashed;
}
.field-emoji {
  font-size: 2.6rem;
  line-height: 1;
}
.field-name {
  font-weight: 700;
}
.field-sub {
  font-size: 0.85rem;
  color: var(--muted);
  min-height: 1.1em;
}
.field-card .btn {
  font-size: 0.95rem;
  padding: 0.55em 0.7em;
}
.progress {
  height: 8px;
  background: var(--line);
  border-radius: 6px;
  overflow: hidden;
}
.progress > div {
  height: 100%;
  background: var(--green-light);
}

/* Pigs panel */
.pigs-panel {
  display: flex;
  flex-wrap: wrap;
  gap: 1rem;
  align-items: center;
}
.pig-stat {
  flex: 1 1 160px;
  background: var(--cream);
  border-radius: 12px;
  padding: 0.7rem;
  text-align: center;
  border: 2px solid var(--line);
}
.pig-stat .big {
  font-size: 1.6rem;
  font-weight: 800;
  color: var(--green-dark);
}
.pig-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.6rem;
  flex: 1 1 100%;
}

/* Market / upgrades grid */
.market-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 0.8rem;
}
.market-card {
  border: 2px solid var(--line);
  border-radius: 14px;
  padding: 0.8rem;
  background: var(--cream);
  display: flex;
  flex-direction: column;
  gap: 0.45rem;
}
.market-card h3 {
  margin: 0;
  font-size: 1.05rem;
  display: flex;
  align-items: center;
  gap: 0.4rem;
}
.market-card p {
  margin: 0;
  font-size: 0.88rem;
  color: var(--muted);
  flex-grow: 1;
}
.market-card .price {
  font-weight: 700;
  color: var(--green-dark);
}
.market-card.owned {
  background: var(--ok-bg);
  border-color: var(--green-light);
}
.badge {
  display: inline-block;
  font-size: 0.72rem;
  font-weight: 700;
  padding: 0.1em 0.5em;
  border-radius: 999px;
  background: var(--gold);
  color: #3a2c00;
}

.game-footer {
  text-align: center;
  color: var(--muted);
  font-size: 0.85rem;
  margin-top: 1.5rem;
}

/* ---------------------------------------------------- Modal */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.5);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1rem;
  z-index: 100;
}
.modal {
  background: var(--paper);
  border-radius: 20px;
  max-width: 520px;
  width: 100%;
  max-height: 88vh;
  overflow-y: auto;
  padding: 1.4rem 1.3rem;
  position: relative;
  box-shadow: 0 10px 40px rgba(0, 0, 0, 0.3);
}
.modal-close {
  position: absolute;
  top: 0.6rem;
  right: 0.6rem;
  border: none;
  background: var(--cream);
  border-radius: 999px;
  width: 38px;
  height: 38px;
  font-size: 1.1rem;
  cursor: pointer;
}
.modal h2 {
  margin-top: 0.2rem;
  color: var(--green-dark);
}
.modal .modal-emoji {
  font-size: 3rem;
  text-align: center;
}
.modal-actions {
  display: flex;
  flex-direction: column;
  gap: 0.6rem;
  margin-top: 1.1rem;
}
.modal-actions.row {
  flex-direction: row;
  flex-wrap: wrap;
}
.modal-actions.row .btn {
  flex: 1 1 45%;
}
.quantity-row {
  display: flex;
  align-items: center;
  gap: 0.8rem;
  justify-content: center;
  margin: 1rem 0;
}
.quantity-row button {
  font-size: 1.6rem;
  width: 52px;
  height: 52px;
  border-radius: 12px;
  border: 2px solid var(--line);
  background: var(--cream);
  cursor: pointer;
  font-weight: 800;
}
.quantity-row .qty-val {
  font-size: 2rem;
  font-weight: 800;
  min-width: 70px;
  text-align: center;
}
.modal .help-list {
  padding-left: 1.1rem;
}
.modal .help-list li {
  margin-bottom: 0.5rem;
}
.modal-note {
  background: var(--cream);
  border-radius: 12px;
  padding: 0.6rem 0.8rem;
  font-size: 0.9rem;
  color: var(--muted);
}
.modal-note.warn {
  background: var(--danger-bg);
  color: #7a241b;
}

/* ---------------------------------------------------- Toast */
.toast {
  position: fixed;
  left: 50%;
  bottom: 1.4rem;
  transform: translateX(-50%);
  background: var(--ink);
  color: #fff;
  padding: 0.8rem 1.2rem;
  border-radius: 999px;
  box-shadow: var(--shadow);
  z-index: 200;
  font-weight: 700;
  max-width: 90vw;
  text-align: center;
}
.toast.good {
  background: var(--ok);
}
.toast.bad {
  background: var(--danger);
}

/* ---------------------------------------------------- Responsive */
@media (max-width: 560px) {
  :root {
    font-size: 17px;
  }
  .stat-label {
    display: none;
  }
  .topbar-inner {
    gap: 0.4rem 0.9rem;
  }
  .btn-huge {
    font-size: 1.25rem;
    width: 100%;
  }
  .next-turn-row {
    flex-direction: column;
  }
  .next-turn-row .btn {
    width: 100%;
  }
}
