:root {
  --ground: #8fc0a0;
  --ink: #4a2030;
  --plum: #3d2238;
  --cream: #fff1d6;
  --cream-2: #ffe3b3;
  --cream-3: #f3cf94;
  --orange: #f08a2c;
  --gold: #ffc22e;
  --green: #6dcf74;
  --green-d: #2f8f4a;
  --red: #e2503c;
  --muted: #8a6658;
  --lift: 0 5px 0 rgba(74, 32, 48, 0.45);
  /* notch / home-bar clearance on phones */
  --sat: env(safe-area-inset-top, 0px);
  --sab: env(safe-area-inset-bottom, 0px);
  --sal: env(safe-area-inset-left, 0px);
  --sar: env(safe-area-inset-right, 0px);
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

html, body { height: 100%; }
body {
  margin: 0;
  overflow: hidden;
  background: var(--ground);
  color: var(--ink);
  font: 700 14px/1.3 "Trebuchet MS", "Segoe UI", system-ui, sans-serif;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;      /* no double-tap zoom */
  overscroll-behavior: none;       /* no pull-to-refresh while dragging tools */
}

#game { position: fixed; inset: 0; width: 100%; height: 100%; display: block; touch-action: none; }

button { font: inherit; color: inherit; cursor: pointer; }
button:disabled { cursor: default; }

/* ---------- HUD ---------- */
.hud { position: fixed; z-index: 2; }

.pill {
  display: flex;
  align-items: center;
  gap: 7px;
  padding: 4px 14px 4px 6px;
  background: rgba(61, 34, 56, 0.9);
  border: 3px solid var(--cream);
  border-radius: 999px;
  color: #fff;
  font-variant-numeric: tabular-nums;
  box-shadow: 0 4px 0 rgba(74, 32, 48, 0.3);
}

#inv { top: 14px; left: 14px; display: flex; flex-direction: column; gap: 7px; pointer-events: none; }
#inv .pill { min-width: 104px; font-size: 16px; }
#inv .pill img { width: 30px; height: 30px; margin: -6px 0 -6px -4px; }
#inv .pill span { margin-left: auto; }

/* Farm level badge and XP bar */
#level { padding: 3px 8px 3px 3px; gap: 6px; }
#inv #level .lv {
  margin: 0;
  min-width: 30px;
  height: 30px;
  padding: 0 4px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: #3b82f6;
  border: 2px solid var(--cream);
  border-radius: 50%;
  font-size: 15px;
}
.xp { position: relative; flex: 1; min-width: 96px; height: 16px; background: #24131f; border-radius: 8px; overflow: hidden; }
.xp i { display: block; height: 100%; background: linear-gradient(#7fd4ff, #3b9ff0); border-radius: 8px; }
.xp b { position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; font-size: 10px; text-shadow: 0 1px 0 #0009; }

#topHud {
  top: 14px;
  left: 50%;
  transform: translateX(-50%);
  width: min(44vw, 460px);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  pointer-events: none;
}
#craving { width: 100%; text-align: center; color: #fff; text-shadow: 0 2px 0 rgba(74, 32, 48, 0.6); font-size: 16px; }
#craveText img { width: 28px; height: 28px; vertical-align: -8px; }
#craving .bar {
  height: 20px;
  margin-top: 4px;
  background: var(--plum);
  border: 3px solid var(--cream);
  border-radius: 8px;
  overflow: hidden;
  box-shadow: 0 4px 0 rgba(74, 32, 48, 0.3);
}
#craveFill { height: 100%; background: linear-gradient(#ffd75a, var(--gold)); border-radius: 0 4px 4px 0; }
#hint { padding: 5px 16px; font-size: 14px; }

#topRight { top: 14px; right: 14px; display: flex; align-items: center; gap: 10px; }
#money { font-size: 19px; color: #ffe07a; padding-right: 16px; }
#money img { width: 26px; height: 26px; }

/* Round wooden buttons (tavern, shop, menu) */
.round {
  position: relative;
  width: 68px;
  height: 68px;
  padding: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  background: var(--cream);
  border: 3px solid var(--ink);
  border-radius: 18px;
  box-shadow: var(--lift);
  transition: transform 0.08s;
}
.round img { width: 36px; height: 36px; pointer-events: none; }
.round .cap { font-size: 11px; line-height: 1; margin-top: 1px; }
.round:hover { background: #fff8e8; transform: translateY(-2px); }
.round:active { transform: translateY(3px); box-shadow: 0 2px 0 rgba(74, 32, 48, 0.45); }
.round.small { width: 44px; height: 44px; border-radius: 14px; background: var(--plum); border-color: var(--cream); }
.round.small:hover { background: #55304e; }
.round.small img { width: 26px; height: 26px; }
.badge {
  position: absolute;
  top: -7px;
  right: -7px;
  width: 18px;
  height: 18px;
  background: var(--red);
  border: 3px solid var(--cream);
  border-radius: 50%;
  animation: pulse 1s ease-in-out infinite;
}
@keyframes pulse { 50% { transform: scale(1.25); } }

#sideBtns { right: 14px; bottom: 14px; display: flex; gap: 12px; }

/* Hotbar */
#hotbar {
  left: 50%;
  bottom: 14px;
  transform: translateX(-50%);
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 10px;
  background: var(--cream);
  border: 3px solid var(--ink);
  border-radius: 20px;
  box-shadow: var(--lift);
}
.slots { display: flex; gap: 8px; }
#hotbar .sep { width: 3px; height: 44px; border-radius: 2px; background: var(--cream-3); }
.slot {
  position: relative;
  width: 58px;
  height: 58px;
  padding: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  background: var(--cream-2);
  border: 3px solid var(--cream-3);
  border-radius: 14px;
  transition: transform 0.08s;
}
.slot img { width: 34px; height: 34px; pointer-events: none; }
.slot .cap { font-size: 10px; line-height: 1; color: var(--muted); }
.slot .key {
  position: absolute;
  top: -8px;
  left: -8px;
  min-width: 20px;
  padding: 1px 0;
  background: var(--plum);
  border: 2px solid var(--cream);
  border-radius: 7px;
  color: #fff;
  font-size: 11px;
  text-align: center;
}
.slot:hover { transform: translateY(-2px); }
.slot.active { background: var(--gold); border-color: var(--ink); transform: translateY(-7px); box-shadow: 0 5px 0 rgba(74, 32, 48, 0.35); }
.slot.active .cap { color: var(--ink); }

/* Crop info card */
#tileInfo {
  position: fixed;
  left: 0;
  top: 0;
  z-index: 3;
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 168px;
  padding: 6px 12px 7px 7px;
  background: var(--cream);
  border: 3px solid var(--ink);
  border-radius: 14px;
  box-shadow: 0 4px 0 rgba(74, 32, 48, 0.35);
  pointer-events: none;
  white-space: nowrap;
}
#tileInfo > div { flex: 1; }
#tileInfo img { width: 34px; height: 34px; }
#tileInfo .name { font-size: 14px; line-height: 1.15; }
#tileInfo .status { font-size: 11px; font-weight: 600; color: var(--muted); }
#tileInfo.thirsty .status { color: var(--red); }
.mini { height: 6px; margin-top: 3px; background: var(--cream-3); border-radius: 3px; overflow: hidden; }
.mini i { display: block; height: 100%; border-radius: 3px; }
.mini.grow i { background: var(--green-d); }
.mini.water i { background: #39a7e8; }

/* ---------- pop-up windows ---------- */
#overlay {
  position: fixed;
  inset: 0;
  z-index: 5;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  background: rgba(61, 34, 56, 0.45);
}
.modal {
  display: flex;
  flex-direction: column;
  width: min(720px, 100%);
  max-height: min(86vh, 720px);
  max-height: min(86dvh, 720px);
  background: var(--cream);
  border: 4px solid var(--ink);
  border-radius: 22px;
  box-shadow: 0 10px 0 rgba(74, 32, 48, 0.45);
  overflow: hidden;
  animation: pop 0.14s ease-out;
}
.modal.narrow, #tavern { width: min(440px, 100%); }
@keyframes pop { from { transform: scale(0.92); opacity: 0; } }

.modalHead {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px 10px 16px;
  background: var(--orange);
  border-bottom: 4px solid var(--ink);
}
.modalHead img { width: 34px; height: 34px; }
.modalHead h2 { margin: 0; flex: 1; font-size: 22px; color: #fff; text-shadow: 0 2px 0 rgba(74, 32, 48, 0.55); }
.close {
  width: 34px;
  height: 34px;
  padding: 0;
  background: var(--cream);
  border: 3px solid var(--ink);
  border-radius: 50%;
  font-size: 22px;
  line-height: 1;
}
.close:hover { background: #fff; }

.modalBody { padding: 14px 16px 18px; overflow-y: auto; }
.modalBody h3 { margin: 2px 2px 9px; font-size: 12px; letter-spacing: 1.5px; text-transform: uppercase; color: var(--muted); }
.modalBody h3:not(:first-child) { margin-top: 18px; }

.list { display: grid; gap: 10px; }
.list.two { grid-template-columns: repeat(auto-fill, minmax(min(300px, 100%), 1fr)); }

.row {
  display: grid;
  grid-template-columns: 44px minmax(0, 1fr) auto;
  align-items: center;
  gap: 10px;
  padding: 8px 10px 8px 8px;
  background: #fffaf0;
  border: 3px solid var(--cream-3);
  border-radius: 16px;
}
.row > img { width: 44px; height: 44px; object-fit: contain; }
.row .name { font-size: 15px; }
.row .lvl { margin-left: 6px; padding: 0 7px; background: var(--cream-2); border-radius: 999px; font-size: 12px; color: var(--muted); }
.row .info { font-size: 12px; font-weight: 600; color: var(--muted); }
.row.hot { background: #fff3b8; border-color: var(--gold); }

.row button, button.big {
  background: var(--green);
  border: 3px solid var(--ink);
  border-radius: 14px;
  box-shadow: 0 4px 0 rgba(74, 32, 48, 0.4);
}
.row button { min-width: 92px; padding: 5px 10px; line-height: 1.15; }
.row button .cost { display: flex; align-items: center; justify-content: center; gap: 4px; font-size: 13px; font-variant-numeric: tabular-nums; }
.row button .cost:empty { display: none; }
.row button .cost::before { content: ""; width: 14px; height: 14px; background: url(assets/coin.svg) center / contain no-repeat; }
.row button:hover:not(:disabled), button.big:hover:not(:disabled) { filter: brightness(1.07); }
.row button:active:not(:disabled), button.big:active:not(:disabled) { transform: translateY(3px); box-shadow: 0 1px 0 rgba(74, 32, 48, 0.4); }
.row button:disabled, button.big:disabled { background: #e2d2b6; border-color: #b9a58c; color: #a08b78; box-shadow: none; }

button.big { width: 100%; margin-top: 14px; padding: 11px; background: var(--gold); font-size: 16px; }
button.big.danger { background: #ff9d8c; margin-top: 10px; }

.keeper { display: flex; gap: 12px; align-items: center; margin-bottom: 14px; }
.keeper img { width: 84px; height: 98px; flex-shrink: 0; }
.keeper .name { font-size: 16px; }
.speech { position: relative; margin-top: 6px; padding: 8px 12px; background: #fff; border: 3px solid var(--ink); border-radius: 14px; font-weight: 600; }
.speech::before { content: ""; position: absolute; left: -9px; top: 12px; width: 12px; height: 12px; background: #fff; border-left: 3px solid var(--ink); border-bottom: 3px solid var(--ink); transform: rotate(45deg); }

.help { margin: 0 0 4px; font-weight: 600; color: var(--muted); }

.musicRow { display: flex; align-items: center; gap: 12px; }
.musicRow .round.small { flex-shrink: 0; box-shadow: 0 3px 0 rgba(74, 32, 48, 0.4); }
.musicRow.muted input, .musicRow.muted span { opacity: 0.45; }
#volumeText { min-width: 42px; text-align: right; font-variant-numeric: tabular-nums; }
#volume {
  flex: 1;
  min-width: 0;
  height: 28px;
  margin: 0;
  appearance: none;
  -webkit-appearance: none;
  background: transparent;
  cursor: pointer;
  touch-action: pan-y;
}
#volume::-webkit-slider-runnable-track { height: 12px; background: var(--cream-3); border: 3px solid var(--ink); border-radius: 8px; box-sizing: content-box; }
#volume::-moz-range-track { height: 12px; background: var(--cream-3); border: 3px solid var(--ink); border-radius: 8px; }
#volume::-webkit-slider-thumb { -webkit-appearance: none; width: 26px; height: 26px; margin-top: -7px; background: var(--orange); border: 3px solid var(--ink); border-radius: 50%; box-shadow: 0 2px 0 rgba(74, 32, 48, 0.4); }
#volume::-moz-range-thumb { width: 20px; height: 20px; background: var(--orange); border: 3px solid var(--ink); border-radius: 50%; }

#toast { position: fixed; left: 50%; bottom: 104px; transform: translateX(-50%); z-index: 6; padding: 7px 18px; max-width: 90vw; text-align: center; }

.row .lvl:empty { display: none; }

/* ---------- compact HUD: phones, in either orientation ----------
   game.js uses the same media query to switch the camera (COMPACT). */
@media (max-width: 760px), (max-height: 520px) {
  #inv {
    top: calc(8px + var(--sat));
    left: calc(8px + var(--sal));
    flex-direction: row;
    flex-wrap: wrap;
    gap: 5px;
    max-width: calc(100vw - 150px - var(--sal) - var(--sar));
  }
  #inv .pill { min-width: 0; gap: 4px; padding: 2px 9px 2px 4px; border-width: 2px; font-size: 13px; box-shadow: none; }
  #inv .pill img { width: 22px; height: 22px; margin: -3px 0 -3px -2px; }
  #inv .pill span { margin-left: 0; }
  #level { padding: 1px 6px 1px 2px; }
  #inv #level .lv { min-width: 22px; height: 22px; font-size: 12px; border-width: 1.5px; }
  .xp { min-width: 58px; height: 12px; }
  .xp b { font-size: 8px; }

  #topRight { top: calc(8px + var(--sat)); right: calc(8px + var(--sar)); gap: 6px; }
  #money { font-size: 15px; padding: 2px 10px 2px 4px; border-width: 2px; }
  #money img { width: 20px; height: 20px; }
  .round.small { width: 36px; height: 36px; border-radius: 11px; border-width: 2px; }
  .round.small img { width: 22px; height: 22px; }

  #topHud { top: calc(76px + var(--sat)); width: min(86vw, 420px); gap: 5px; }
  #craving { font-size: 13px; }
  #craveText img { width: 22px; height: 22px; vertical-align: -6px; }
  #craving .bar { height: 14px; margin-top: 2px; border-width: 2px; }
  #hint { padding: 3px 12px; font-size: 12px; border-width: 2px; }

  #hotbar {
    bottom: calc(8px + var(--sab));
    gap: 6px;
    padding: 6px;
    border-radius: 16px;
    max-width: calc(100vw - 16px - var(--sal) - var(--sar));
  }
  .slots { gap: 5px; }
  #seeds { overflow-x: auto; min-width: 0; scrollbar-width: none; }
  #seeds::-webkit-scrollbar { display: none; }
  #hotbar .sep { height: 34px; flex-shrink: 0; }
  .slot { width: 44px; height: 44px; flex-shrink: 0; border-width: 2px; border-radius: 11px; }
  .slot img { width: 30px; height: 30px; }
  .slot .cap, .slot .key { display: none; }
  .slot:hover { transform: none; }
  .slot.active { transform: none; box-shadow: inset 0 0 0 2px #fff; }

  #sideBtns { right: calc(8px + var(--sar)); bottom: calc(72px + var(--sab)); gap: 8px; }
  .round { width: 50px; height: 50px; border-radius: 14px; }
  .round img { width: 30px; height: 30px; }
  .round .cap { display: none; }
  .round:hover { transform: none; }

  #toast { bottom: calc(134px + var(--sab)); font-size: 13px; }

  #overlay { padding: 8px; }
  .modal { max-height: 90vh; max-height: 90dvh; border-radius: 18px; }
  .modalHead { padding: 7px 10px 7px 12px; }
  .modalHead h2 { font-size: 18px; }
  .modalBody { padding: 12px 10px 14px; }
  .row { grid-template-columns: 36px minmax(0, 1fr) auto; gap: 8px; padding: 7px; }
  .row > img { width: 36px; height: 36px; }
  .row button { min-width: 78px; }
  .keeper img { width: 64px; height: 75px; }
}

/* phone held sideways: everything fits on one row top and bottom */
@media (max-height: 520px) and (orientation: landscape) {
  #inv { max-width: 30vw; }
  #topHud { top: calc(8px + var(--sat)); width: 32vw; }
  #sideBtns { bottom: calc(8px + var(--sab)); }
  #toast { bottom: calc(70px + var(--sab)); }
}
