/* Homestead — cozy cartoon farm game */

:root {
  --bg: #efe0bf;
  --bg2: #f6ead0;
  --panel: #fff7e9;
  --panel-line: #e6d2ab;
  --ink: #43301c;
  --ink-soft: #7a6547;
  --accent: #e2892f;
  --accent-dark: #c46f1c;
  --leaf: #6fae3d;
  --leaf-dark: #4f8a2c;
  --sky: #bfe3ef;
  --danger: #c9483a;
  --shadow: 0 6px 18px rgba(67, 48, 28, 0.16);
  --radius: 16px;
  font-family: "Nunito", ui-rounded, "Segoe UI", system-ui, -apple-system, sans-serif;
}

* { box-sizing: border-box; }

html, body { height: 100%; margin: 0; }

body {
  color: var(--ink);
  background:
    radial-gradient(1200px 600px at 20% -10%, #fbf1da, transparent),
    linear-gradient(160deg, var(--bg2), var(--bg));
  -webkit-tap-highlight-color: transparent;
}

button { font-family: inherit; }

/* ---------------------------------------------------------------- layout */
.app {
  height: 100dvh;
  display: grid;
  grid-template-columns: 96px 1fr 366px;
  grid-template-rows: auto 1fr auto;
  gap: 10px;
  padding: 10px;
}
.hud    { grid-column: 1 / -1; grid-row: 1; }
.rail   { grid-column: 1; grid-row: 2; }
.stage  { grid-column: 2; grid-row: 2; }
.panel  { grid-column: 3; grid-row: 2; }
.bottom { grid-column: 1 / -1; grid-row: 3; }

/* ---------------------------------------------------------------- HUD */
.hud {
  display: flex;
  align-items: center;
  gap: 18px;
  padding: 10px 16px;
  background: var(--panel);
  border: 2px solid var(--panel-line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}
.hud-date { display: flex; align-items: center; gap: 10px; min-width: 150px; }
.hud-weather { font-size: 26px; }
.hud-datetext > div:first-child { font-weight: 800; font-size: 15px; }
.hud-sub { font-size: 11px; color: var(--ink-soft); }
.hud-clock { display: flex; flex-direction: column; gap: 6px; flex: 1; max-width: 340px; }
.hud-blocks { display: flex; gap: 4px; flex-wrap: wrap; }
.pip {
  width: 12px; height: 12px; border-radius: 4px;
  background: #e7d8bb; border: 1.5px solid var(--panel-line);
}
.pip.on { background: var(--accent); border-color: var(--accent-dark); }
.hud-stamina { display: flex; align-items: center; gap: 8px; }
.hud-stamina-track {
  flex: 1; height: 12px; border-radius: 8px; overflow: hidden;
  background: #e7d8bb; border: 1.5px solid var(--panel-line);
}
#hud-stamina-fill {
  height: 100%; width: 100%;
  background: linear-gradient(90deg, #8fd06a, #5fae3c);
  transition: width 0.25s ease;
}
#hud-stamina-fill.low { background: linear-gradient(90deg, #f3b24a, #e2892f); }
.hud-right { display: flex; align-items: center; gap: 12px; margin-left: auto; }
.hud-coins { text-align: right; font-weight: 800; }
.hud-coins .hud-sub { display: block; font-weight: 600; color: var(--accent-dark); }
.icon-btn {
  border: 2px solid var(--panel-line); background: #fff;
  width: 40px; height: 40px; border-radius: 12px; font-size: 18px;
  cursor: pointer; transition: transform 0.1s;
}
.icon-btn:hover { transform: translateY(-1px); }

/* ---------------------------------------------------------------- rail */
.rail {
  display: flex; flex-direction: column; gap: 8px;
  padding: 10px; overflow-y: auto;
  background: var(--panel);
  border: 2px solid var(--panel-line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}
.rail-group { display: flex; flex-direction: column; gap: 8px; }
.rail-sep { height: 2px; background: var(--panel-line); border-radius: 2px; margin: 2px 0; }
.rail-foot { margin-top: auto; text-align: center; font-size: 12px; font-weight: 800; color: var(--ink-soft); }
.tool {
  position: relative;
  display: flex; flex-direction: column; align-items: center; gap: 2px;
  padding: 8px 4px 6px;
  border: 2px solid var(--panel-line);
  background: #fff;
  border-radius: 14px;
  cursor: pointer;
  transition: transform 0.08s, box-shadow 0.08s, border-color 0.08s;
}
.tool:hover { transform: translateY(-1px); }
.tool.active {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(226, 137, 47, 0.28);
  background: #fff4e4;
}
.tool.empty { opacity: 0.55; }
.tool-glyph { font-size: 22px; line-height: 1; }
.tool-label { font-size: 10px; font-weight: 800; color: var(--ink-soft); }
.tool .icon { display: block; }
.seed-count {
  position: absolute; top: -6px; right: -6px;
  min-width: 18px; height: 18px; padding: 0 4px;
  background: var(--leaf-dark); color: #fff;
  border-radius: 9px; font-size: 11px; font-weight: 800;
  display: flex; align-items: center; justify-content: center;
}
.offseason {
  position: absolute; bottom: -4px; right: -4px;
  color: var(--danger); font-size: 12px; font-weight: 900;
}

/* ---------------------------------------------------------------- stage / board */
.stage {
  display: flex; align-items: center; justify-content: center;
  padding: 8px; overflow: hidden; position: relative;
  background:
    radial-gradient(700px 400px at 30% 0%, #cdeede, transparent),
    linear-gradient(180deg, #bfe6d0, #a9d9bb);
  border: 2px solid var(--panel-line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}
#board {
  width: 100%; height: 100%;
  filter: drop-shadow(0 10px 18px rgba(48, 34, 18, 0.22));
}
.tile .hit { cursor: pointer; }
.tile:hover .hit { stroke: #fffdf5; stroke-width: 3; }
.tile:active .sprite { transform: translateY(1px) scale(0.96); }
#board-tint { opacity: 0; transition: opacity 0.4s; }
.season-summer #board-tint { fill: #ffd27a; opacity: 0.06; }
.season-fall   #board-tint { fill: #ff9a4d; opacity: 0.09; }
.season-winter #board-tint { fill: #cfe6ff; opacity: 0.14; }

/* weather overlays */
.stage::after {
  content: ""; position: absolute; inset: 0; pointer-events: none;
  opacity: 0; transition: opacity 0.5s;
}
.stage:has(#board.weather-rain)::after {
  opacity: 1;
  background-image: repeating-linear-gradient(
    102deg, transparent 0 14px, rgba(180, 210, 235, 0.55) 14px 16px);
  animation: rain 0.5s linear infinite;
}
.stage:has(#board.weather-snow)::after {
  opacity: 1;
  background-image:
    radial-gradient(2px 2px at 20% 30%, #fff, transparent),
    radial-gradient(2px 2px at 70% 60%, #fff, transparent),
    radial-gradient(2px 2px at 45% 80%, #fff, transparent),
    radial-gradient(2px 2px at 85% 15%, #fff, transparent);
  background-size: 200px 200px;
  animation: snow 6s linear infinite;
}
@keyframes rain { to { background-position: 0 60px; } }
@keyframes snow { to { background-position: 40px 200px; } }

/* sprite motion */
.sprite.bob { animation: bob 2.6s ease-in-out infinite; transform-box: fill-box; transform-origin: 50% 92%; }
.sprite { transition: transform 0.1s; }
@keyframes bob { 0%, 100% { transform: translateY(0); } 50% { transform: translateY(-1.6px); } }
.ripe .ripe-star, .ripe-star { animation: twinkle 1.5s ease-in-out infinite; transform-box: fill-box; transform-origin: 50% 50%; }
@keyframes twinkle { 0%, 100% { transform: translateY(0) scale(1); opacity: 0.9; } 50% { transform: translateY(-2px) scale(1.14); opacity: 1; } }
.smoke circle { animation: rise 3.4s ease-out infinite; opacity: 0; }
.smoke circle:nth-child(2) { animation-delay: 1.1s; }
.smoke circle:nth-child(3) { animation-delay: 2.2s; }
@keyframes rise {
  0% { transform: translateY(4px) scale(0.5); opacity: 0; }
  25% { opacity: 0.7; }
  100% { transform: translateY(-14px) scale(1.1); opacity: 0; }
}

/* ---------------------------------------------------------------- panel */
.panel {
  display: flex; flex-direction: column;
  background: var(--panel);
  border: 2px solid var(--panel-line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow: hidden;
}
.panel-tabs { display: flex; gap: 4px; padding: 8px 8px 0; }
.panel-tabs button {
  flex: 1; padding: 9px 4px; border: none; cursor: pointer;
  background: transparent; font-weight: 800; font-size: 13px; color: var(--ink-soft);
  border-radius: 10px 10px 0 0;
}
.panel-tabs button.active { background: #fff; color: var(--ink); box-shadow: inset 0 -3px 0 var(--accent); }
.panel-body { flex: 1; overflow-y: auto; padding: 12px; display: flex; flex-direction: column; gap: 12px; }

.card {
  background: #fff; border: 2px solid var(--panel-line);
  border-radius: 12px; padding: 12px;
}
.card h3 { margin: 2px 0 6px; font-size: 17px; }
.card h4 { margin: 0 0 8px; font-size: 13px; text-transform: uppercase; letter-spacing: 0.04em; color: var(--ink-soft); }
.muted { color: var(--ink-soft); font-size: 13px; margin: 6px 0 0; }

.j-chap { font-size: 11px; font-weight: 800; letter-spacing: 0.08em; text-transform: uppercase; color: var(--accent-dark); }
.j-blurb { font-size: 13px; color: var(--ink-soft); margin: 4px 0 10px; line-height: 1.45; }
.j-tasks { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 10px; }
.j-tasks li { font-size: 13px; font-weight: 700; }
.j-tasks li.done { color: var(--leaf-dark); }
.j-task-top { display: flex; justify-content: space-between; gap: 8px; }
.j-num { color: var(--ink-soft); font-variant-numeric: tabular-nums; }
.j-reward { margin-top: 12px; font-size: 12.5px; background: #fff4e4; border-radius: 10px; padding: 8px 10px; }
.j-done { display: flex; flex-direction: column; gap: 4px; }
.j-done-row { font-size: 12px; color: var(--leaf-dark); font-weight: 800; }

.bar { height: 8px; margin-top: 6px; border-radius: 6px; background: #ece0c6; overflow: hidden; }
.bar-fill { height: 100%; background: linear-gradient(90deg, #8fd06a, #5fae3c); border-radius: 6px; transition: width 0.3s; }

.row { display: flex; align-items: center; gap: 10px; padding: 8px 0; border-top: 1px solid var(--panel-line); }
.row:first-of-type { border-top: none; }
.row-main { flex: 1; min-width: 0; }
.row-name { font-weight: 800; font-size: 13px; }
.row-sub { font-size: 11.5px; color: var(--ink-soft); }
.row-btns { display: flex; gap: 4px; }

.tag { font-size: 10px; font-weight: 800; padding: 2px 6px; border-radius: 6px; }
.tag.off { background: #f6ded9; color: var(--danger); }
.tag.owned { background: #e3f1d6; color: var(--leaf-dark); }

.bag-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(84px, 1fr)); gap: 8px; }
.bag-cell {
  background: #fff; border: 2px solid var(--panel-line); border-radius: 12px;
  padding: 8px 4px; text-align: center; position: relative;
}
.bag-cell.locked { opacity: 0.4; filter: grayscale(1); }
.bag-name { font-size: 10.5px; font-weight: 800; margin-top: 2px; }
.bag-qty {
  position: absolute; top: -6px; right: -6px;
  background: var(--accent); color: #fff; border-radius: 9px;
  min-width: 18px; height: 18px; font-size: 11px; font-weight: 800;
  display: flex; align-items: center; justify-content: center; padding: 0 4px;
}

/* ---------------------------------------------------------------- bottom bar */
.bottom {
  display: flex; align-items: center; gap: 12px;
  padding: 8px 16px;
  background: var(--panel);
  border: 2px solid var(--panel-line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}
.hint { flex: 1; font-style: italic; color: var(--ink-soft); font-size: 13.5px; }
.bottom-actions { display: flex; gap: 8px; }
#btn-panel-toggle { display: none; }

.btn {
  border: 2px solid var(--accent-dark);
  background: var(--accent);
  color: #fff; font-weight: 800; font-size: 14px;
  padding: 9px 16px; border-radius: 12px; cursor: pointer;
  transition: transform 0.08s, filter 0.08s;
}
.btn:hover { transform: translateY(-1px); }
.btn:disabled { filter: grayscale(0.6); opacity: 0.5; cursor: not-allowed; transform: none; }
.btn.sm { padding: 6px 10px; font-size: 12px; border-radius: 10px; }
.btn.ghost { background: #fff; color: var(--ink); border-color: var(--panel-line); }
.btn.danger { background: var(--danger); border-color: #a5392d; }
.btn.sleep {
  background: linear-gradient(180deg, #6b7fc4, #4a5da3);
  border-color: #3c4d8c;
}
.btn.sleep.urge { animation: urge 1.1s ease-in-out infinite; }
@keyframes urge { 0%, 100% { box-shadow: 0 0 0 0 rgba(74, 93, 163, 0.5); } 50% { box-shadow: 0 0 0 8px rgba(74, 93, 163, 0); } }

/* ---------------------------------------------------------------- modal */
.modal-root {
  position: fixed; inset: 0; z-index: 50;
  display: flex; align-items: center; justify-content: center;
  padding: 20px;
  background: rgba(45, 32, 18, 0.55);
  backdrop-filter: blur(2px);
}
.modal {
  background: var(--panel);
  border: 3px solid var(--panel-line);
  border-radius: 20px;
  box-shadow: 0 20px 50px rgba(0, 0, 0, 0.3);
  padding: 22px 24px;
  max-width: 440px; width: 100%;
  text-align: center;
  animation: pop 0.18s ease-out;
}
@keyframes pop { from { transform: scale(0.9); opacity: 0; } to { transform: scale(1); opacity: 1; } }
.modal h2 { margin: 0 0 8px; }
.modal h3 { margin: 0 0 8px; color: var(--accent-dark); }
.modal p { line-height: 1.5; font-size: 14px; color: var(--ink); margin: 8px 0; }
.modal .btn { margin-top: 12px; }
.modal em { font-style: normal; font-weight: 800; color: var(--accent-dark); }
.reward-badge {
  width: 56px; height: 56px; margin: 0 auto 6px;
  border-radius: 50%; background: #fff4e4; border: 3px solid var(--accent);
  display: flex; align-items: center; justify-content: center;
  font-size: 26px; color: var(--accent-dark);
}
.settings-btns { display: flex; flex-wrap: wrap; gap: 8px; justify-content: center; margin-top: 12px; }
.save-text {
  width: 100%; height: 88px; margin-top: 12px; resize: vertical;
  border: 2px solid var(--panel-line); border-radius: 10px; padding: 8px;
  font-family: ui-monospace, Menlo, Consolas, monospace; font-size: 11px;
}

/* ---------------------------------------------------------------- responsive */
@media (max-width: 860px) {
  .app {
    grid-template-columns: 1fr;
    grid-template-rows: auto auto 1fr auto;
    gap: 8px; padding: 8px;
  }
  .hud { grid-column: 1; grid-row: 1; flex-wrap: wrap; gap: 10px 14px; }
  .hud-clock { max-width: none; order: 3; flex-basis: 100%; }
  .rail { grid-column: 1; grid-row: 2; flex-direction: row; overflow-x: auto; overflow-y: hidden; }
  .rail-group { flex-direction: row; }
  .rail-sep { width: 2px; height: auto; margin: 0 2px; }
  .rail-foot { margin: 0; align-self: center; white-space: nowrap; }
  .tool { min-width: 62px; }
  .stage { grid-column: 1; grid-row: 3; }
  .bottom { grid-column: 1; grid-row: 4; }
  #btn-panel-toggle { display: inline-block; }

  .panel {
    position: fixed; left: 0; right: 0; bottom: 0; z-index: 40;
    height: 72dvh; border-radius: 20px 20px 0 0;
    transform: translateY(102%);
    transition: transform 0.28s ease;
  }
  .panel.open { transform: translateY(0); }
}

@media (prefers-reduced-motion: reduce) {
  *, *::after { animation: none !important; transition: none !important; }
}
