/* ============================================================
   SoilVille — cozy earthy UI
   ============================================================ */
:root {
  --bg1: #f6efdf;
  --bg2: #ecdfc3;
  --panel: #fffdf6;
  --ink: #3d2f22;
  --muted: #8a7a66;
  --line: #e4d7bd;
  --green: #4d9e46;
  --green-dark: #3a7a35;
  --amber: #e0a52e;
  --red: #cf5a44;
  --blue: #4a90c2;
  --sand: #d4a86a;
  --loam: #7c5433;
  --clay: #96573a;
  --radius: 14px;
  font-size: 16px;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: "Trebuchet MS", "Segoe UI", system-ui, -apple-system, sans-serif;
  color: var(--ink);
  background:
    radial-gradient(1200px 500px at 80% -10%, #fdf7e7 0%, transparent 60%),
    radial-gradient(900px 400px at -10% 110%, #e7f0d5 0%, transparent 55%),
    linear-gradient(180deg, var(--bg1), var(--bg2));
  min-height: 100vh;
}
button { font-family: inherit; }
.hidden { display: none !important; }

#app { max-width: 1280px; margin: 0 auto; padding: 12px 16px 40px; }

/* ---------------- HUD ---------------- */
#hud {
  display: flex; align-items: center; gap: 14px; flex-wrap: wrap;
  background: linear-gradient(180deg, #fffdf6, #f7eeda);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 10px 16px;
  box-shadow: 0 3px 12px rgba(90, 70, 40, .08);
  position: sticky; top: 8px; z-index: 50;
}
.logo { font-size: 1.25rem; letter-spacing: .3px; white-space: nowrap; }
.logo b { color: var(--green-dark); }
.tagline { color: var(--muted); font-style: italic; font-size: .78rem; margin-left: 8px; }
.hud-stats { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.stat {
  background: #fff; border: 1px solid var(--line); border-radius: 999px;
  padding: 4px 12px; font-weight: bold; font-size: .85rem;
  box-shadow: inset 0 -2px 0 rgba(120,100,60,.06);
}
.stat.coins { color: #9a7208; }
.hud-nav { margin-left: auto; display: flex; gap: 8px; flex-wrap: wrap; }
.hud-btn {
  border: 1px solid var(--line); background: #fff; border-radius: 10px;
  padding: 6px 12px; font-weight: bold; cursor: pointer; transition: transform .08s, box-shadow .12s;
  position: relative;
}
.hud-btn:hover { transform: translateY(-1px); box-shadow: 0 3px 8px rgba(90,70,40,.15); }
.badge {
  position: absolute; top: -6px; right: -6px; background: var(--red); color: #fff;
  border-radius: 999px; width: 18px; height: 18px; font-size: .7rem; line-height: 18px;
  text-align: center; animation: pulse 1.2s infinite;
}
@keyframes pulse { 50% { transform: scale(1.25); } }

.xpbar {
  display: inline-block; width: 90px; height: 10px; background: #eee3cc;
  border-radius: 999px; overflow: hidden; vertical-align: middle; margin-left: 6px;
}
.xpbar > span { display: block; height: 100%; background: linear-gradient(90deg, #7fc86a, var(--green)); transition: width .4s; }

/* ---------------- Layout ---------------- */
main { display: grid; grid-template-columns: minmax(0, 1fr) 330px; gap: 14px; margin-top: 14px; align-items: start; }
@media (max-width: 980px) { main { grid-template-columns: 1fr; } }

.panel {
  background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 12px 14px; box-shadow: 0 2px 10px rgba(90,70,40,.07);
}
.panel h3 { margin: 2px 0 8px; font-size: 1rem; }

/* ---------------- Farm grid ---------------- */
#farm-wrap { position: relative; overflow: hidden; border-radius: var(--radius); }
#weather-banner {
  display: flex; justify-content: space-between; align-items: center;
  background: rgba(255,255,255,.75); backdrop-filter: blur(3px);
  border: 1px solid var(--line); border-bottom: none;
  border-radius: var(--radius) var(--radius) 0 0; padding: 6px 14px; font-size: .9rem; font-weight: bold;
}
#farm {
  display: grid; grid-template-columns: repeat(6, 1fr); gap: 8px;
  padding: 10px; border: 1px solid var(--line);
  background: linear-gradient(180deg, #dff0fb 0%, #eaf4dc 55%, #f4ecd2 100%);
  position: relative;
}
@media (max-width: 900px) { #farm { grid-template-columns: repeat(4, 1fr); } }
@media (max-width: 520px) { #farm { grid-template-columns: repeat(3, 1fr); } }

.plot {
  position: relative; border-radius: 10px; cursor: pointer;
  border: 2px solid rgba(120,95,60,.25);
  background: #fff; overflow: hidden; user-select: none;
  transition: transform .1s, box-shadow .15s, border-color .15s;
  min-height: 118px; display: flex; flex-direction: column;
}
.plot:hover { transform: translateY(-2px); box-shadow: 0 5px 12px rgba(90,70,40,.18); z-index: 2; }
.plot.selected { border-color: var(--green); box-shadow: 0 0 0 3px rgba(77,158,70,.35); z-index: 3; }
.plot.locked { filter: saturate(.4) brightness(.92); }

.plant-area {
  height: 62px; display: flex; align-items: center; justify-content: center; position: relative;
  background: linear-gradient(180deg, transparent, rgba(255,255,255,.25));
}
.plant-emoji { font-size: 2rem; line-height: 1; filter: drop-shadow(0 2px 2px rgba(0,0,0,.18)); }
.plant-emoji.growing { animation: sway 3s ease-in-out infinite; display: inline-block; transform-origin: bottom center; }
@keyframes sway { 0%,100% { transform: rotate(-3deg); } 50% { transform: rotate(3deg) translateY(-1px); } }
.plant-emoji.ready { animation: bounce .8s ease-in-out infinite; display: inline-block; }
@keyframes bounce { 0%,100% { transform: translateY(0);} 50% { transform: translateY(-4px);} }
.plant-emoji.dead { filter: grayscale(1) brightness(.8); }

.chips { position: absolute; top: 3px; left: 3px; right: 3px; display: flex; gap: 3px; flex-wrap: wrap; }
.chip {
  font-size: .58rem; font-weight: bold; padding: 1px 5px; border-radius: 999px;
  background: rgba(255,255,255,.92); border: 1px solid var(--line); white-space: nowrap;
}
.chip.warn { background: #ffe9c7; border-color: #eec98a; color: #8a5a00; }
.chip.good { background: #dff3d8; border-color: #9fd491; color: #2f6b28; }
.chip.bad { background: #ffded8; border-color: #eda092; color: #8f2d1b; }

.progress-ring {
  position: absolute; bottom: 3px; left: 6px; right: 6px; height: 5px;
  background: rgba(0,0,0,.14); border-radius: 999px; overflow: hidden;
}
.progress-ring > span { display: block; height: 100%; background: var(--green); transition: width .5s; }

.soil { flex: 1; position: relative; padding: 4px 6px 6px; display: flex; flex-direction: column; gap: 3px; }
.soil::before {
  content: ""; position: absolute; inset: 0; opacity: .95; z-index: 0;
}
.texture-sand .soil::before {
  background:
    radial-gradient(circle at 20% 30%, rgba(255,255,255,.35) 1.2px, transparent 1.6px),
    radial-gradient(circle at 65% 60%, rgba(255,255,255,.3) 1.2px, transparent 1.6px),
    radial-gradient(circle at 85% 25%, rgba(120,80,30,.25) 1.2px, transparent 1.6px),
    radial-gradient(circle at 40% 80%, rgba(120,80,30,.2) 1.4px, transparent 1.8px),
    var(--sand);
  background-size: 26px 26px, 34px 34px, 30px 30px, 24px 24px, auto;
}
.texture-loam .soil::before {
  background:
    radial-gradient(ellipse 8px 3px at 25% 35%, rgba(60,40,15,.35), transparent 70%),
    radial-gradient(ellipse 10px 3px at 70% 65%, rgba(40,25,10,.3), transparent 70%),
    radial-gradient(ellipse 6px 3px at 45% 80%, rgba(90,60,25,.35), transparent 70%),
    var(--loam);
}
.texture-clay .soil::before {
  background:
    repeating-linear-gradient(115deg, transparent 0 14px, rgba(60,25,10,.18) 14px 15.5px),
    repeating-linear-gradient(65deg, transparent 0 18px, rgba(60,25,10,.14) 18px 19.5px),
    var(--clay);
}
.soil > * { position: relative; z-index: 1; }

.moist-sheen {
  position: absolute; inset: 0; z-index: 0;
  background: linear-gradient(180deg, rgba(40,90,140,.45), rgba(40,90,140,.05));
  pointer-events: none;
}

.meters { display: flex; gap: 4px; align-items: center; flex-wrap: wrap; font-size: .6rem; color: #fff; text-shadow: 0 1px 1px rgba(0,0,0,.5); }
.npk { display: inline-flex; gap: 2px; align-items: center; }
.dot { width: 8px; height: 8px; border-radius: 999px; background: rgba(255,255,255,.35); border: 1px solid rgba(255,255,255,.5); }
.dot.on-n { background: #63d94f; } .dot.on-p { background: #f2c53d; } .dot.on-k { background: #e8863c; }
.ph-tag, .moist-tag { background: rgba(0,0,0,.28); padding: 0 5px; border-radius: 999px; font-weight: bold; }

.plot-num {
  position: absolute; top: 2px; right: 5px; font-size: .6rem; color: rgba(255,255,255,.85);
  text-shadow: 0 1px 1px rgba(0,0,0,.4); z-index: 2;
}
.lock-cover { position: absolute; inset: 0; display: flex; flex-direction: column; align-items: center; justify-content: center; background: rgba(50,40,25,.35); color: #fff; font-weight: bold; font-size: .72rem; text-shadow: 0 1px 2px rgba(0,0,0,.5); z-index: 2; }

/* weather overlays */
.weather-layer { position: absolute; inset: 0; pointer-events: none; z-index: 5; }
.weather-rain .weather-layer, .weather-storm .weather-layer {
  background-image: repeating-linear-gradient(75deg, rgba(70,130,190,.0) 0 26px, rgba(70,130,190,.35) 26px 27.5px);
  animation: rainfall .5s linear infinite;
}
@keyframes rainfall { from { background-position: 0 0; } to { background-position: -40px 60px; } }
.weather-drought .weather-layer { background: radial-gradient(ellipse at 50% 0%, rgba(230,120,30,.18), transparent 70%); }
.weather-snow .weather-layer {
  background-image: radial-gradient(circle, rgba(255,255,255,.9) 1.5px, transparent 2.2px), radial-gradient(circle, rgba(255,255,255,.8) 1.5px, transparent 2.2px);
  background-size: 46px 46px, 74px 74px;
  animation: snowfall 6s linear infinite;
}
@keyframes snowfall { from { background-position: 0 0, 20px 0; } to { background-position: -30px 92px, -20px 148px; } }

/* ---------------- Quest card ---------------- */
.quest-current { display: flex; gap: 10px; align-items: flex-start; }
.quest-current .q-emoji { font-size: 1.8rem; }
.q-title { font-weight: bold; }
.q-goal { color: var(--muted); font-size: .85rem; margin-top: 2px; }
.q-progress { font-size: .75rem; color: var(--green-dark); font-weight: bold; margin-top: 4px; }
.q-reward { margin-left: auto; font-size: .75rem; white-space: nowrap; color: #9a7208; font-weight: bold; }

/* ---------------- Action dock ---------------- */
.dock-empty { color: var(--muted); font-size: .9rem; }
.dock-title { display: flex; align-items: baseline; gap: 8px; margin-bottom: 8px; }
.dock-title b { font-size: 1rem; }
.dock-sub { color: var(--muted); font-size: .75rem; }
.btn-row { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 8px; }
.act-btn {
  border: 1px solid var(--line); border-radius: 10px; background: #fff; cursor: pointer;
  padding: 8px 10px; font-weight: bold; font-size: .82rem; transition: transform .08s, background .12s;
  display: inline-flex; align-items: center; gap: 5px;
}
.act-btn:hover:not(:disabled) { transform: translateY(-1px); background: #fdf6e6; }
.act-btn.primary { background: var(--green); border-color: var(--green-dark); color: #fff; font-size: .95rem; }
.act-btn.primary:hover:not(:disabled) { background: var(--green-dark); }
.act-btn:disabled { opacity: .45; cursor: not-allowed; }
.count-tag { background: rgba(0,0,0,.08); border-radius: 999px; padding: 0 6px; font-size: .7rem; }

/* ---------------- Journal ---------------- */
#log { list-style: none; margin: 0; padding: 0; max-height: 200px; overflow-y: auto; font-size: .78rem; }
#log li { padding: 4px 6px; border-bottom: 1px dashed var(--line); }
#log li.good { color: var(--green-dark); }
#log li.warn { color: #8a5a00; }
#log li.bad { color: var(--red); }
#log li.levelup { color: #7a3fa0; font-weight: bold; }
#log li.quest { color: var(--blue); font-weight: bold; }

/* ---------------- Modals ---------------- */
.modal-backdrop {
  position: fixed; inset: 0; background: rgba(40,30,15,.45); z-index: 100;
  display: flex; align-items: center; justify-content: center; padding: 16px;
  animation: fadein .15s ease-out;
}
@keyframes fadein { from { opacity: 0; } }
.modal {
  background: var(--panel); border-radius: 16px; max-width: 720px; width: 100%;
  max-height: 86vh; display: flex; flex-direction: column;
  box-shadow: 0 12px 40px rgba(40,30,10,.35); animation: pop .18s ease-out;
  border: 1px solid var(--line);
}
@keyframes pop { from { transform: scale(.94); opacity: .6; } }
.modal-head { display: flex; align-items: center; padding: 14px 18px 8px; gap: 10px; }
.modal-head h2 { margin: 0; font-size: 1.2rem; }
.modal-close { margin-left: auto; border: none; background: none; font-size: 1.3rem; cursor: pointer; color: var(--muted); }
.modal-body { padding: 6px 18px 16px; overflow-y: auto; }
.modal-foot { padding: 10px 18px 16px; display: flex; gap: 8px; justify-content: flex-end; flex-wrap: wrap; }

.tabs { display: flex; gap: 6px; margin: 4px 0 10px; flex-wrap: wrap; }
.tab-btn { border: 1px solid var(--line); background: #fff; border-radius: 999px; padding: 5px 14px; cursor: pointer; font-weight: bold; font-size: .85rem; }
.tab-btn.active { background: var(--green); border-color: var(--green-dark); color: #fff; }

.shop-grid, .almanac-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 10px; }
.card {
  border: 1px solid var(--line); border-radius: 12px; padding: 10px; background: #fff;
  display: flex; flex-direction: column; gap: 5px;
}
.card .big { font-size: 1.7rem; }
.card h4 { margin: 0; }
.card .desc { font-size: .75rem; color: var(--muted); flex: 1; }
.card .price { font-weight: bold; color: #9a7208; font-size: .85rem; }
.fit-row { font-size: .68rem; color: var(--muted); display: flex; gap: 6px; flex-wrap: wrap; }
.fit-ok { color: var(--green-dark); font-weight: bold; }
.fit-no { color: var(--red); font-weight: bold; }

.quiz-option {
  display: block; width: 100%; text-align: left; margin: 6px 0; padding: 10px 12px;
  border: 1px solid var(--line); border-radius: 10px; background: #fff; cursor: pointer; font-size: .9rem;
}
.quiz-option:hover { background: #fdf6e6; }
.quiz-option.correct { background: #dff3d8; border-color: var(--green); font-weight: bold; }
.quiz-option.wrong { background: #ffded8; border-color: var(--red); }
.explain-box { background: #eef5e3; border: 1px solid #cfe0b4; border-radius: 10px; padding: 10px 12px; font-size: .85rem; margin-top: 8px; }

.lesson-card { border: 1px solid var(--line); border-radius: 12px; padding: 12px; margin-bottom: 10px; background: #fff; }
.lesson-card h4 { margin: 0 0 6px; }
.lesson-card p { margin: 0; font-size: .85rem; line-height: 1.45; color: #574636; }

.quest-item { display: flex; gap: 10px; padding: 9px 10px; border: 1px solid var(--line); border-radius: 10px; margin-bottom: 7px; background: #fff; align-items: flex-start; }
.quest-item.done { opacity: .68; background: #f3f8ec; }
.quest-item.current { border-color: var(--green); box-shadow: 0 0 0 2px rgba(77,158,70,.25); }
.quest-item .q-body { flex: 1; }
.quest-check { font-size: 1.1rem; }

.harvest-stars { font-size: 1.6rem; letter-spacing: 3px; text-align: center; margin: 6px 0; }
.harvest-line { text-align: center; font-size: 1rem; }
.fact-box { background: #eef5e3; border: 1px solid #cfe0b4; border-radius: 10px; padding: 10px 12px; font-size: .84rem; margin-top: 10px; }

/* soil report */
.report-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(90px, 1fr)); gap: 8px; margin: 10px 0; }
.report-stat { background: #fff; border: 1px solid var(--line); border-radius: 10px; text-align: center; padding: 8px 4px; }
.report-stat .v { font-size: 1.2rem; font-weight: bold; }
.report-stat .l { font-size: .65rem; color: var(--muted); text-transform: uppercase; letter-spacing: .5px; }
.meter-bar { height: 6px; border-radius: 99px; background: #eee3cc; overflow: hidden; margin-top: 4px; }
.meter-bar > span { display: block; height: 100%; }
.rec-list { margin: 8px 0 0; padding-left: 20px; font-size: .86rem; }
.rec-list li { margin-bottom: 5px; }

/* ---------------- Toasts ---------------- */
#toast-root { position: fixed; top: 76px; right: 16px; z-index: 200; display: flex; flex-direction: column; gap: 8px; max-width: 340px; }
.toast {
  background: #fffdf6; border: 1px solid var(--line); border-left: 5px solid var(--green);
  border-radius: 10px; padding: 10px 14px; font-size: .85rem; box-shadow: 0 6px 18px rgba(60,45,20,.2);
  animation: slidein .25s ease-out;
}
.toast.warn { border-left-color: var(--amber); }
.toast.bad { border-left-color: var(--red); }
.toast.quest { border-left-color: var(--blue); }
.toast.fadeout { opacity: 0; transition: opacity .5s; }
@keyframes slidein { from { transform: translateX(30px); opacity: 0; } }

footer.credit { text-align: center; color: var(--muted); font-size: .75rem; margin-top: 26px; }

/* ---------------- juice: floats, confetti, hud states ---------------- */
.float-text {
  position: absolute; left: 50%; top: 30%; transform: translateX(-50%);
  font-weight: bold; font-size: .95rem; color: #fff; pointer-events: none;
  text-shadow: 0 1px 2px rgba(0,0,0,.55), 0 0 8px rgba(255,215,80,.6);
  z-index: 10; animation: floatUp 1.15s ease-out forwards;
}
.float-text.xp { color: #bfe7ff; }
.float-text.bonus { color: #ffd76a; font-size: .78rem; top: 52%; animation-delay: .25s; }
@keyframes floatUp {
  0% { opacity: 0; translate: 0 6px; scale: .8; }
  15% { opacity: 1; scale: 1.05; }
  100% { opacity: 0; translate: 0 -34px; scale: 1; }
}

#confetti-layer { position: fixed; inset: 0; pointer-events: none; z-index: 300; overflow: hidden; }
.confetto {
  position: absolute; width: 9px; height: 13px; top: -20px;
  animation: confettiFall var(--dur, 1.4s) ease-in forwards;
  border-radius: 2px;
}
@keyframes confettiFall {
  to { translate: var(--drift, 0px) 105vh; rotate: var(--spin, 540deg); opacity: .15; }
}

.hud-btn.active-speed { background: #eaf6e2; border-color: var(--green); }
.hud-btn:disabled { opacity: .45; cursor: default; transform: none !important; box-shadow: none !important; }

.act-btn .mini-label { font-size: .68rem; color: var(--muted); font-weight: normal; }
/* Learning feedback: visible first-crop coaching and explainable conditions. */
.learning-guide, .condition-advice { margin-bottom: 14px; padding: 16px; }
.learning-guide { border: 2px solid var(--green); background: #f4f9e9; }
.learning-guide h3, .condition-advice h3 { margin: 0 0 8px; }
.learning-guide p, .condition-advice p { line-height: 1.5; margin: 8px 0; }
.guide-step { font-size: .72rem; font-weight: 800; letter-spacing: .08em; color: #37592e; }
.guide-young { color: #37592e; }
.condition-advice { border: 2px solid #cd932c; background: #fff6df; }
button.condition-help { cursor: help; font: inherit; }
#btn-academy { border-color: var(--green); font-weight: 800; }
#btn-advance { min-width: 94px; }
.learning-guide .btn-row, .condition-advice .btn-row { flex-wrap: wrap; }
