:root {
  --sand: #f3e6c4;
  --sand-2: #e9d7a8;
  --paper: #fffaf0;
  --ink: #3b2a1a;
  --ink-2: #6b5640;
  --green: #4f8a35;
  --green-d: #3b6d26;
  --terra: #c8643b;
  --gold: #e8b83a;
  --sky: #a9d4ea;
  --red: #c0392b;
  --shadow: 0 4px 0 rgba(59, 42, 26, .18), 0 8px 20px rgba(59, 42, 26, .12);
  --r: 18px;
  font-family: 'Rubik', system-ui, sans-serif;
  color: var(--ink);
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; min-height: 100%; }
body {
  background: var(--sand);
  overscroll-behavior: none;
  -webkit-user-select: none; user-select: none;
  -webkit-text-size-adjust: 100%;
}
input { -webkit-user-select: text; user-select: text; }
h1, h2 { font-family: 'Secular One', 'Rubik', sans-serif; font-weight: 400; margin: .3em 0; line-height: 1.2; }
h1 { font-size: 1.7rem; }
h2 { font-size: 1.35rem; }
button { font: inherit; color: inherit; cursor: pointer; }

.screen {
  max-width: 560px; margin: 0 auto; min-height: 100vh; min-height: 100dvh;
  padding: max(14px, env(safe-area-inset-top)) 16px max(18px, env(safe-area-inset-bottom));
  display: flex; flex-direction: column; gap: 12px;
}

/* ---------- buttons & fields ---------- */
.btn {
  border: 0; border-radius: 999px; padding: 14px 26px; font-size: 1.15rem; font-weight: 700;
  background: var(--green); color: #fff; box-shadow: 0 4px 0 var(--green-d);
  transition: transform .08s, box-shadow .08s, opacity .2s;
}
.btn:active:not(:disabled) { transform: translateY(3px); box-shadow: 0 1px 0 var(--green-d); }
.btn:disabled { opacity: .45; }
.btn.small { padding: 10px 16px; font-size: 1rem; }
.btn.ghost { background: var(--paper); color: var(--ink); box-shadow: 0 4px 0 var(--sand-2); }
.btn.go { align-self: center; margin-top: 6px; }
.link { background: none; border: 0; color: var(--ink-2); text-decoration: underline; font-size: .95rem; padding: 8px; align-self: center; }
.back { align-self: flex-start; background: none; border: 0; font-size: 1rem; color: var(--ink-2); padding: 4px 0; }
.row { display: flex; gap: 10px; justify-content: center; flex-wrap: wrap; }
.card { background: var(--paper); border-radius: var(--r); padding: 14px 16px; box-shadow: var(--shadow); }
.sub { text-align: center; color: var(--ink-2); margin: 0; }
.note { background: #dff0fa; border-radius: 14px; padding: 10px 14px; font-size: .95rem; }

.field { display: flex; flex-direction: column; gap: 8px; font-weight: 500; }
.field input, input.word, input.pin {
  font: inherit; font-size: 1.25rem; padding: 10px 14px; border-radius: 14px;
  border: 2px solid var(--sand-2); background: #fff; color: var(--ink); outline: none;
}
.field input:focus, input.word:focus, input.pin:focus { border-color: var(--green); }
.seg { display: flex; flex-wrap: wrap; gap: 8px; }
.seg button {
  flex: 1; min-width: 56px; border: 2px solid var(--sand-2); background: var(--paper); border-radius: 14px;
  padding: 10px 12px; font-size: 1.1rem; font-weight: 500;
}
.seg button.on { background: var(--gold); border-color: #c99a22; }
.seg.ages button { flex: 0 0 calc(25% - 6px); }

/* ---------- avatar ---------- */
.avatar {
  position: relative; width: var(--s); height: var(--s); flex: none; display: inline-grid; place-items: center;
  border-radius: 50%; background: var(--sand-2); border: 3px solid #fff; box-shadow: 0 2px 8px rgba(0, 0, 0, .18);
  font-size: calc(var(--s) * .42); font-weight: 700; color: var(--ink-2);
}
.avatar img { width: 100%; height: 100%; border-radius: 50%; object-fit: cover; }
.avatar:not(.plus) { border-color: var(--gold); }
.avatar.plus { background: var(--paper); border: 3px dashed var(--sand-2); box-shadow: none; }

/* ---------- start ---------- */
.start { text-align: center; align-items: center; }
.title-art { width: calc(100% + 32px); margin: -14px -16px 0; height: 190px; overflow: hidden; position: relative; }
.title-art img { width: 100%; height: 100%; object-fit: cover; object-position: center 60%; }
.title-art::after { content: ''; position: absolute; inset: auto 0 0 0; height: 70px; background: linear-gradient(transparent, var(--sand)); }
.start h1 { font-size: 2.1rem; margin-top: -24px; position: relative; }
.profiles { display: grid; grid-template-columns: repeat(auto-fill, minmax(130px, 1fr)); gap: 14px; width: 100%; margin-top: 8px; }
.profile {
  border: 0; background: var(--paper); border-radius: var(--r); padding: 26px 8px 12px; box-shadow: var(--shadow);
  display: flex; flex-direction: column; align-items: center; gap: 6px;
}
.profile b { font-size: 1.15rem; }
.profile small { color: var(--ink-2); font-size: .8rem; }
.profile:active { transform: scale(.97); }

/* ---------- register ---------- */
.photo-pick { display: flex; flex-direction: column; align-items: center; gap: 12px; padding-top: 18px; }
.farm-name { text-align: center; font-family: 'Secular One', sans-serif; font-size: 1.4rem; color: var(--green-d); }

/* ---------- letter ---------- */
.letter-screen { justify-content: center; }
.letter {
  background: #fff8e6; border-radius: 6px; padding: 22px 22px 18px; position: relative; margin-top: 70px;
  box-shadow: var(--shadow); line-height: 1.65; font-size: 1.08rem;
  background-image: repeating-linear-gradient(transparent 0 27px, rgba(160, 120, 60, .13) 27px 28px);
  transform: rotate(-.6deg);
}
.letter p { margin: 0 0 .7em; }
.letter p:last-child { margin: 0; font-family: 'Secular One', sans-serif; }
.letter .grandpa { width: 130px; position: absolute; top: -92px; left: 10px; filter: drop-shadow(0 4px 6px rgba(0,0,0,.2)); }

/* ---------- plan ---------- */
.plan-head { display: flex; align-items: center; gap: 12px; padding-top: 14px; }
.plan-head h1 { font-size: 1.4rem; margin: 0; }
.plan-head small { color: var(--ink-2); }
.dog-say { display: flex; align-items: center; gap: 10px; background: var(--paper); border-radius: var(--r); padding: 8px 12px; box-shadow: var(--shadow); }
.dog-say img { width: 52px; flex: none; }
.dog-say p { margin: 0; font-size: 1rem; line-height: 1.4; }
.dog-say.pop { animation: pop .35s; }
.actions { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.action {
  border: 2px solid transparent; background: var(--paper); border-radius: 16px; padding: 10px 4px 8px;
  display: flex; flex-direction: column; align-items: center; gap: 2px; font-weight: 700; font-size: .95rem; box-shadow: var(--shadow);
}
.action span { font-size: 1.7rem; }
.action small { font-weight: 400; font-size: .68rem; color: var(--ink-2); line-height: 1.25; text-align: center; }
.action.on { border-color: var(--gold); background: #fff3cf; }
.action.locked { border-color: var(--green); }
.sentences { display: flex; flex-direction: column; gap: 8px; }
.sentence { background: var(--paper); border-radius: 16px; padding: 10px 12px; box-shadow: var(--shadow); }
.sentence.done { background: #e7f3dc; }
.line { display: flex; align-items: center; flex-wrap: wrap; gap: 4px; font-size: 1.2rem; }
.blank { display: inline-flex; align-items: center; gap: 4px; vertical-align: middle; }
input.word { width: auto; min-width: 5.5em; padding: 6px 10px; font-size: 1.2rem; text-align: center; }
.blank.ok input.word { border-color: var(--green); background: #f1f9ea; color: var(--green-d); font-weight: 700; }
.check { border: 0; background: var(--green); color: #fff; width: 40px; height: 40px; border-radius: 50%; font-size: 1.2rem; font-weight: 700; }
.hint { color: var(--terra); font-size: .95rem; margin-top: 4px; min-height: 0; line-height: 1.4; }
.hint:empty { display: none; }
.bank {
  display: flex; flex-wrap: wrap; align-items: center; gap: 6px; padding: 8px 10px; border-radius: 14px;
  background: #fff3cf; border: 2px dashed #e2c26a;
}
.bank b { font-size: .9rem; color: var(--ink-2); margin-inline-end: 4px; }
.bank span { background: #fff; border-radius: 10px; padding: 3px 10px; font-size: 1.15rem; font-weight: 700; color: var(--green-d); box-shadow: 0 1px 0 var(--sand-2); -webkit-user-select: text; user-select: text; }
.journal .bank { margin: 6px 0 4px; }
.chips { display: inline-flex; gap: 6px; flex-wrap: wrap; }
.chip { border: 2px solid var(--sand-2); background: #fff; border-radius: 12px; padding: 6px 12px; font-size: 1.15rem; font-weight: 500; }
.chip.nope { opacity: .35; text-decoration: line-through; }
.filled { color: var(--green-d); background: #e7f3dc; border-radius: 8px; padding: 2px 8px; }
.shake { animation: shake .35s; }

/* ---------- farm ---------- */
.farm {
  padding: 0; gap: 0; max-width: none; height: 100vh; height: 100dvh; min-height: 0; overflow: hidden; background:
    linear-gradient(to bottom, transparent calc(min(100vw, 100%) * .5 - 70px), #e6d5a4 calc(min(100vw, 100%) * .5)),
    url(assets/hills.jpg) top center / 100% auto no-repeat, #e6d5a4;
}
.hud {
  display: flex; align-items: center; gap: 10px; padding: max(10px, env(safe-area-inset-top)) 14px 6px;
  background: linear-gradient(rgba(255, 250, 240, .92), rgba(255, 250, 240, .75)); backdrop-filter: blur(6px);
}
.hud-name { display: flex; flex-direction: column; line-height: 1.2; flex: 1; min-width: 0; }
.hud-name b { font-family: 'Secular One', sans-serif; font-weight: 400; font-size: 1.15rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.hud-name small { color: var(--ink-2); }
.sun { width: 110px; display: flex; flex-direction: column; align-items: center; gap: 2px; font-size: .8rem; color: var(--ink-2); }
.sun-track { position: relative; width: 100%; height: 8px; border-radius: 4px; background: linear-gradient(to left, #ffe08a, #f2994a 70%, #7b4a8c); }
.sun-track i { position: absolute; top: 50%; width: 20px; height: 20px; margin-inline-start: -10px; translate: 0 -50%; border-radius: 50%; background: #ffd23f; box-shadow: 0 0 10px #ffb700; transition: inset-inline-start 1s linear; }
.sun.late small { color: var(--red); font-weight: 700; }
.res { display: flex; justify-content: center; gap: 6px; padding: 6px 10px; flex-wrap: wrap; }
.res span { background: rgba(255, 250, 240, .9); border-radius: 999px; padding: 4px 12px; font-size: 1rem; box-shadow: 0 2px 6px rgba(0,0,0,.1); }
.res b { font-weight: 700; }
.plan-chips { text-align: center; font-size: .9rem; display: flex; justify-content: center; gap: 6px; }
.plan-chips span { background: #fff3cf; border-radius: 999px; padding: 2px 8px; }
.map-wrap { position: relative; width: 100%; max-width: 720px; margin: 0 auto; overflow: hidden; flex: 1; min-height: 0; }
.map { position: absolute; left: 0; top: 0; transform-origin: 0 0; direction: ltr; }
.ground { position: absolute; inset: 0; }
.ground polygon { transition: fill .3s; }
.tile {
  position: absolute; border: 0; padding: 0; background: transparent;
  clip-path: polygon(50% 0, 100% 50%, 50% 100%, 0 50%);
}
.tile:active { background: rgba(255, 255, 255, .25); }
.spr { position: absolute; translate: -50% -100%; pointer-events: none; }
.spr img { display: block; }
.deco.tappable, .terrace { pointer-events: auto; cursor: pointer; }
.tile-spr { display: flex; justify-content: center; }
.tile-spr .badge { position: absolute; top: -6px; left: 50%; translate: -50% 0; font-style: normal; font-size: 26px; filter: drop-shadow(0 2px 2px rgba(0,0,0,.25)); }
.tile-spr .bob { animation: bob 1.2s ease-in-out infinite; }
.tile-spr .sparkle { animation: twinkle 1.4s ease-in-out infinite; }
.st-locked img { filter: grayscale(.5) brightness(.85); opacity: .8; }
.st-sown img { scale: .6; transform-origin: bottom; filter: saturate(.3) brightness(.95); }
.ring {
  position: absolute; top: -14px; left: 50%; translate: -50% 0; width: 30px; height: 30px; border-radius: 50%;
  background: conic-gradient(var(--green) calc(var(--p) * 360deg), rgba(255,255,255,.7) 0);
  -webkit-mask: radial-gradient(circle, transparent 8px, #000 9px); mask: radial-gradient(circle, transparent 8px, #000 9px);
}
.tap img, img.tap { animation: squish .3s; }
.clearing img { animation: clear .65s forwards; }
.float {
  position: absolute; z-index: 2000; translate: -50% 0; font-weight: 700; font-size: 22px; color: #fff;
  text-shadow: 0 2px 0 rgba(0,0,0,.35), 0 0 6px rgba(0,0,0,.3); animation: rise 1.2s forwards; pointer-events: none; white-space: nowrap;
}
.bottom { padding: 6px 12px max(12px, env(safe-area-inset-bottom)); display: flex; flex-direction: column; gap: 10px; }
.bottom .dog-say { min-height: 64px; }

/* ---------- modals ---------- */
.modal-back {
  position: fixed; inset: 0; z-index: 5000; background: rgba(40, 28, 15, .45);
  display: grid; place-items: center; padding: 16px; animation: fade .2s;
}
.modal {
  width: min(420px, 100%); max-height: 90vh; overflow: auto; background: var(--paper); border-radius: 22px; padding: 18px;
  box-shadow: 0 20px 50px rgba(0,0,0,.3); text-align: center; animation: pop .3s;
  display: flex; flex-direction: column; gap: 10px;
}
.modal p { margin: 0; line-height: 1.5; }
.modal .pin { text-align: center; letter-spacing: .4em; font-size: 1.6rem; }
.modal .deal { text-align: start; background: #fff3cf; }
.modal .deal p { margin: 4px 0; line-height: 2; font-size: 1.1rem; }
.modal .who { font-weight: 700; }
.terrace-pic { width: 160px; align-self: center; }
.cost { font-size: 1.3rem; font-weight: 700; }
.cost .ok { color: var(--green-d); }
.cost .no { color: var(--red); }
.sunset { background: linear-gradient(#ffe2b0, #f6b98a); }

/* ---------- evening & night ---------- */
.evening { background: linear-gradient(#f6c27a, #e59a6c 45%, #8a5a8c); min-height: 100dvh; color: #2d1a10; }
.evening h1 { text-align: center; color: #fff; text-shadow: 0 2px 6px rgba(0,0,0,.25); }
.evening .stats p { margin: 4px 0; font-size: 1.1rem; }
.evening .sub { color: #fff; }
.journal {
  background: #fff8e6; border-radius: 6px; padding: 16px 18px; box-shadow: var(--shadow);
  background-image: repeating-linear-gradient(transparent 0 33px, rgba(160, 120, 60, .13) 33px 34px);
}
.journal h2 { font-size: 1.15rem; }
.jtext { line-height: 2.3; font-size: 1.15rem; margin: 0; }
.jtext .blank { margin: 0 2px; }
.jtext input.word, .deal input.word { min-width: 3.2em; padding: 2px 8px; font-size: 1.1rem; border-radius: 10px; }
.jtext .check, .deal .check { width: 32px; height: 32px; font-size: 1rem; }
.night { background: linear-gradient(#1d2b4f, #3a3f6e); color: #fff; text-align: center; justify-content: center; align-items: center; min-height: 100dvh; max-width: none; }
.night .sub, .night .link { color: #d8dcf2; }
.moon { font-size: 5rem; animation: float 3s ease-in-out infinite; }

/* ---------- parent ---------- */
.kid header { display: flex; gap: 10px; align-items: center; margin-bottom: 10px; }
.kid header div { display: flex; flex-direction: column; }
.kid small { color: var(--ink-2); }
.kid table { width: 100%; border-collapse: collapse; margin-top: 10px; font-size: .95rem; }
.kid th, .kid td { padding: 6px 4px; border-bottom: 1px solid var(--sand-2); text-align: center; }

/* ---------- effects ---------- */
.confetti {
  position: fixed; top: -12px; width: 9px; height: 14px; z-index: 9000; border-radius: 2px; pointer-events: none;
  animation: fall 2s cubic-bezier(.3, .6, .5, 1) forwards;
}
@keyframes fall { to { transform: translate(var(--dx), 105vh) rotate(540deg); } }
@keyframes pop { 0% { scale: .85; opacity: 0; } 60% { scale: 1.04; opacity: 1; } 100% { scale: 1; } }
@keyframes fade { from { opacity: 0; } }
@keyframes shake { 20%, 60% { translate: -6px 0; } 40%, 80% { translate: 6px 0; } }
@keyframes squish { 30% { scale: 1.12 .9; } 60% { scale: .95 1.08; } 100% { scale: 1; } }
@keyframes clear { 30% { scale: 1.15; rotate: -8deg; } 100% { scale: .2; opacity: 0; rotate: 25deg; } }
@keyframes rise { from { opacity: 1; translate: -50% 0; } to { opacity: 0; translate: -50% -50px; } }
@keyframes bob { 50% { translate: -50% -6px; } }
@keyframes float { 50% { translate: 0 -10px; } }
@keyframes twinkle { 50% { opacity: .4; scale: .8; } }
