* { margin: 0; padding: 0; box-sizing: border-box; }

html, body { height: 100%; }
body {
  background: #1c2b1f;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  color: #e8efe6;
  overflow: hidden;
}

#stage { width: 100vw; height: 100dvh; }

#topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 4px;
}
.brand { font-weight: 800; font-size: 18px; letter-spacing: -0.01em; }
.brand .tag {
  font-size: 10px;
  background: #c9891a;
  color: #fff;
  border-radius: 999px;
  padding: 2px 8px;
  vertical-align: middle;
  letter-spacing: .1em;
}
.chips { display: flex; gap: 8px; }
.chip {
  background: rgba(255,255,255,.08);
  border: 1px solid rgba(255,255,255,.15);
  border-radius: 999px;
  padding: 5px 12px;
  font-size: 14px;
}
.chip.gold b { color: #f0c877; font-variant-numeric: tabular-nums; }
.coin {
  display: inline-block;
  width: 13px;
  height: 13px;
  border-radius: 50%;
  background: radial-gradient(circle at 35% 30%, #ffe9a6, #f0c14b 55%, #b8860b);
  border: 1px solid #8a6508;
  vertical-align: -1px;
}

#viewport {
  position: fixed;
  inset: 0;
  overflow: hidden;
}

#game {
  display: block;
  width: 100%;
  height: 100%;
  image-rendering: pixelated;
  image-rendering: crisp-edges;
  background: #85b25c;
  cursor: pointer;
  touch-action: manipulation;
}

#picker {
  position: absolute;
  left: 50% !important;
  top: auto !important;
  bottom: calc(84px + env(safe-area-inset-bottom, 0px));
  transform: translateX(-50%);
  width: min(380px, 92%);
  z-index: 8;
  background: #fffdf5;
  color: #26331f;
  border: 2px solid #5c3a1d;
  border-radius: 12px;
  padding: 10px;
  display: flex;
  flex-direction: column;
  gap: 6px;
  min-width: 170px;
  box-shadow: 0 10px 30px rgba(0,0,0,.4);
  z-index: 5;
}
#picker.hidden { display: none; }
.picker-title { font-weight: 800; font-size: 13px; text-align: center; margin-bottom: 2px; }
#picker button {
  font: inherit;
  font-size: 14px;
  font-weight: 700;
  text-align: left;
  background: #eef4e4;
  border: 1px solid #c9d1b8;
  border-radius: 8px;
  padding: 7px 10px;
  cursor: pointer;
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 10px;
}
#picker button:hover { background: #dfeacd; }
#picker button small { font-weight: 500; color: #6b7a5f; }
#picker button.cancel { background: transparent; border: none; color: #8a2f2f; justify-content: center; }

#hint {
  margin-top: 10px;
  text-align: center;
  font-size: 14px;
  min-height: 20px;
  color: #cfe0c5;
}

#footer {
  margin-top: 8px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  font-size: 12px;
  color: #92a58c;
}
#reset {
  font: inherit;
  font-size: 12px;
  background: transparent;
  color: #92a58c;
  border: 1px solid #3a4a3a;
  border-radius: 8px;
  padding: 4px 10px;
  cursor: pointer;
  white-space: nowrap;
}
#reset:hover { color: #e8efe6; border-color: #92a58c; }

.fright { display: flex; align-items: center; gap: 10px; }
.adminlink { color: #92a58c; text-decoration: none; font-size: 15px; opacity: .7; }
.adminlink:hover { opacity: 1; }

.chip.inv { font-size: 13px; padding: 5px 9px; }
.chip.inv b { font-variant-numeric: tabular-nums; }
.marketbtn {
  font: inherit;
  font-size: 14px;
  font-weight: 700;
  cursor: pointer;
  background: #c9891a;
  color: #fff;
  border: 1px solid #a06d10;
  position: relative;
}
.marketbtn:hover { background: #db9a26; }
.fairdot { margin-left: 2px; }
.fairdot.hidden { display: none; }

.pickernote {
  font-size: 12px;
  color: #a8720f;
  font-weight: 700;
  text-align: center;
  padding: 2px 0;
}
.pickernote.hidden { display: none; }

.mqty {
  font: inherit;
  font-size: 12.5px;
  width: 46px;
  border: 1px solid #c9bb9b;
  border-radius: 7px;
  padding: 4px 5px;
  text-align: center;
  background: #fff;
  color: #26331f;
}
.mqty:disabled { background: #eee7d7; color: #99937f; }

.toolbtn {
  font: inherit;
  font-size: 14px;
  font-weight: 700;
  cursor: pointer;
  background: #2a3d2f;
  color: #e8efe6;
  border: 1px solid #3a4a3a;
}
.toolbtn:hover { background: #37503d; }

.buildhint {
  position: absolute;
  top: 10px;
  left: 50%;
  transform: translateX(-50%);
  background: #c9891a;
  color: #fff;
  font-size: 13px;
  font-weight: 700;
  padding: 7px 14px;
  border-radius: 999px;
  box-shadow: 0 6px 20px rgba(0,0,0,.35);
  z-index: 6;
  white-space: nowrap;
  max-width: 92%;
  overflow: hidden;
  text-overflow: ellipsis;
}
.buildhint.hidden { display: none; }

.m-note { font-size: 12px; color: #6b7a5f; padding: 8px 2px 2px; }

/* falu */
.vmap {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(84px, 1fr));
  gap: 8px;
  background: #e4ecd4;
  border: 1px solid #cfd9b8;
  border-radius: 10px;
  padding: 10px;
}
.vhouse {
  font: inherit;
  background: #fffdf5;
  border: 1px solid #d8d2bf;
  border-radius: 9px;
  padding: 8px 4px 6px;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  position: relative;
}
.vhouse .vh-ic { font-size: 22px; }
.vhouse .vh-name { font-size: 11px; font-weight: 700; }
.vhouse.me { border-color: #256b4c; box-shadow: 0 0 0 2px rgba(37,107,76,.25); }
.vhouse.locked { opacity: .65; }
.vhouse .vh-lock { position: absolute; top: 2px; right: 4px; font-size: 10px; }
.vhouse.shake { animation: vshake .35s; }
@keyframes vshake {
  0%, 100% { transform: translateX(0); }
  25% { transform: translateX(-3px); }
  75% { transform: translateX(3px); }
}
.vhint { font-size: 12px; color: #8a5d0c; font-weight: 600; min-height: 16px; margin-top: 6px; }
.vbar {
  height: 8px;
  background: #eae4d0;
  border-radius: 4px;
  overflow: hidden;
  margin: 6px 0 4px;
}
.vbar i { display: block; height: 100%; background: #c9891a; border-radius: 4px; }
.vsum { font-size: 12.5px; font-weight: 700; font-variant-numeric: tabular-nums; }
.vcontrib { font-size: 12.5px; margin-top: 4px; }
.vcontrib.dim { color: #97927e; font-size: 11.5px; }
.vdonate { display: flex; gap: 6px; margin-top: 8px; }

/* ---------- piac és csűr panel ---------- */
#market, #barn, #build, #village, #neigh, #feedp, #menu, #login {
  position: absolute;
  inset: 0;
  background: rgba(15, 25, 16, .55);
  display: flex;
  align-items: flex-start;
  justify-content: center;
  z-index: 10;
  padding: calc(env(safe-area-inset-top, 0px) + 12px) 14px calc(env(safe-area-inset-bottom, 0px) + 12px);
}
#market.hidden, #barn.hidden, #build.hidden, #village.hidden, #neigh.hidden, #feedp.hidden, #menu.hidden, #login.hidden { display: none; }
.m-head #buildclose, .m-head #vclose, .m-head #nclose, .m-head #fclose, .m-head #menuclose {
  margin-left: auto;
  font: inherit;
  font-size: 14px;
  background: #eee7d7;
  border: 1px solid #c9bb9b;
  border-radius: 7px;
  padding: 2px 9px;
  cursor: pointer;
}
.m-panel {
  max-height: calc(100dvh - env(safe-area-inset-top, 0px) - env(safe-area-inset-bottom, 0px) - 28px) !important;
  background: #fffdf5;
  color: #26331f;
  border: 2px solid #5c3a1d;
  border-radius: 14px;
  width: min(480px, 100%);
  max-height: 100%;
  overflow-y: auto;
  box-shadow: 0 16px 50px rgba(0,0,0,.5);
  padding: 12px 14px 14px;
}
.m-head {
  position: sticky;
  top: -12px;
  background: #fffdf5;
  z-index: 3;
  padding: 6px 0;
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 17px;
  font-weight: 800;
  margin-bottom: 6px;
}
.m-head #mclose, .m-head #bclose {
  margin-left: auto;
  font: inherit;
  font-size: 14px;
  background: #eee7d7;
  border: 1px solid #c9bb9b;
  border-radius: 7px;
  padding: 2px 9px;
  cursor: pointer;
}
.daybadge { font-size: 11.5px; font-weight: 600; color: #6b7a5f; }
.daybadge.fair { color: #a8720f; font-weight: 800; }
.m-sect {
  font-size: 11px;
  font-weight: 700;
  letter-spacing: .08em;
  text-transform: uppercase;
  color: #8a9678;
  margin: 12px 0 6px;
  border-bottom: 1px solid #e5dfc9;
  padding-bottom: 3px;
}
.mrow {
  display: grid;
  grid-template-columns: 1fr auto auto auto;
  gap: 10px;
  align-items: center;
  padding: 6px 2px;
  border-bottom: 1px dashed #eae4d0;
  font-size: 14px;
  position: relative;
}
.mrow:last-child { border-bottom: none; }
.mrow .mi { font-weight: 700; }
.mrow .mq { color: #6b7a5f; font-variant-numeric: tabular-nums; font-size: 13px; }
.mrow .mp { font-weight: 700; font-variant-numeric: tabular-nums; font-size: 13px; }
.mrow .mb { display: flex; gap: 5px; position: relative; }
.mrow button, .mcard button {
  font: inherit;
  font-size: 12.5px;
  font-weight: 700;
  background: #256b4c;
  color: #fff;
  border: none;
  border-radius: 7px;
  padding: 5px 10px;
  cursor: pointer;
}
.mrow button:hover, .mcard button:hover { background: #2f8560; }
.mrow button:disabled, .mcard button:disabled {
  background: #d8d2bf;
  color: #99937f;
  cursor: default;
}
.mcard {
  border: 1px solid #e0d9c2;
  border-radius: 10px;
  padding: 9px 11px;
  margin-bottom: 8px;
  position: relative;
}
.mc-title { font-weight: 800; font-size: 14.5px; }
.mc-desc { font-size: 12.5px; color: #6b7a5f; margin: 3px 0 7px; }
.mflash {
  position: absolute;
  right: 0;
  top: -16px;
  font-size: 12px;
  font-weight: 800;
  color: #a8720f;
  animation: mfl 1.2s ease-out forwards;
  white-space: nowrap;
}
.mflash.err { color: #a83232; }
@keyframes mfl {
  0% { opacity: 0; transform: translateY(4px); }
  20% { opacity: 1; }
  100% { opacity: 0; transform: translateY(-10px); }
}

.feeddot { color: #e85c5c; font-size: 10px; vertical-align: 2px; }
.feeddot.hidden { display: none; }
.feed-prank { border-left: 3px solid #8a2f63; padding-left: 8px; }
.feed-help  { border-left: 3px solid #256b4c; padding-left: 8px; }
#neigh .mcard button {
  background: #8a2f63;
}
#neigh .mcard button:hover { background: #a34079; }
#neigh .mcard button[data-na="help"] { background: #256b4c; }
#neigh .mcard button[data-na="help"]:hover { background: #2f8560; }

/* ---------- app-szerű HUD a képen belül ---------- */
#hud {
  position: absolute;
  top: calc(8px + env(safe-area-inset-top, 0px));
  left: 8px;
  right: 8px;
  display: flex;
  flex-wrap: wrap;
  gap: 5px;
  align-items: center;
  z-index: 6;
  pointer-events: none;
}
#hud .chip, #hud button { pointer-events: auto; }
#hud .chip {
  background: rgba(13, 23, 16, .78);
  border: 1px solid rgba(255,255,255,.16);
  font-size: 12.5px;
  padding: 4px 10px;
  color: #e8efe6;
}
#hud .brandchip { font-weight: 800; }
#hud .marketbtn { background: rgba(201, 137, 26, .92); border-color: #a06d10; }
#hud .toolbtn { background: rgba(42, 61, 47, .85); }
.hudspace { flex: 1; }
.menubtns { display: flex; gap: 12px; align-items: center; margin-top: 10px; }
.menubtns #reset { color: #6b7a5f; border-color: #c9bb9b; }
.menubtns .adminlink { color: #26331f; font-size: 14px; font-weight: 700; opacity: 1; }

.loginrows { display: flex; flex-direction: column; gap: 8px; padding-top: 4px; }
.loginbtn {
  font: inherit;
  font-size: 16px;
  font-weight: 800;
  background: #eef4e4;
  border: 1px solid #c9d1b8;
  border-radius: 10px;
  padding: 12px;
  cursor: pointer;
  text-align: left;
}
.loginbtn:hover { background: #dfeacd; }
.loginbtn.guest { background: transparent; border-style: dashed; color: #6b7a5f; font-weight: 600; }
.menubtns #logout { font: inherit; font-size: 12px; background: transparent; color: #8a2f2f; border: 1px solid #d0a9a9; border-radius: 8px; padding: 4px 10px; cursor: pointer; }

.pinrow { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; margin-top: 4px; }
.pinrow.hidden { display: none; }
#pininput {
  font: inherit;
  font-size: 18px;
  letter-spacing: .2em;
  flex: 1;
  min-width: 120px;
  border: 2px solid #c9d1b8;
  border-radius: 10px;
  padding: 10px 12px;
  text-align: center;
}
.loginbtn.go { background: #256b4c; color: #fff; border-color: #1c523a; text-align: center; }
.loginbtn.picked { border-color: #256b4c; box-shadow: 0 0 0 2px rgba(37,107,76,.3); }
.pinerr { width: 100%; color: #a83232; font-size: 13px; font-weight: 700; min-height: 16px; }

/* ---------- tutorial ---------- */
.tut {
  position: absolute;
  left: 50%;
  bottom: calc(14px + env(safe-area-inset-bottom, 0px));
  transform: translateX(-50%);
  width: min(440px, 92%);
  background: #fffdf5;
  color: #26331f;
  border: 2px solid #c9891a;
  border-radius: 14px;
  padding: 12px 14px;
  font-size: 14px;
  font-weight: 600;
  line-height: 1.45;
  box-shadow: 0 10px 30px rgba(0,0,0,.4);
  z-index: 7;
  display: flex;
  align-items: center;
  gap: 12px;
}
.tut.hidden { display: none; }
.tut #tutskip {
  font: inherit;
  font-size: 12px;
  font-weight: 700;
  background: #c9891a;
  color: #fff;
  border: none;
  border-radius: 8px;
  padding: 7px 10px;
  cursor: pointer;
  white-space: nowrap;
}
.tuthl {
  animation: tutpulse 1.1s ease-in-out infinite;
  outline: 3px solid #f0c877 !important;
  outline-offset: 1px;
}
@keyframes tutpulse {
  0%, 100% { box-shadow: 0 0 0 0 rgba(240,200,119,.8); }
  50% { box-shadow: 0 0 0 7px rgba(240,200,119,0); }
}

.visitbar { display: flex; gap: 10px; align-items: center; }
.visitbar.hidden { display: none; }

/* ---------- szántóföld eszköztár + repülő effekt ---------- */
.fieldbar {
  position: absolute;
  left: 50%;
  bottom: calc(14px + env(safe-area-inset-bottom, 0px));
  transform: translateX(-50%);
  display: flex;
  gap: 6px;
  z-index: 7;
  background: rgba(13, 23, 16, .82);
  border: 1px solid rgba(255,255,255,.18);
  border-radius: 999px;
  padding: 6px;
}
.fieldbar.hidden { display: none; }
.fieldbar button {
  font: inherit;
  font-size: 13.5px;
  font-weight: 700;
  background: transparent;
  color: #e8efe6;
  border: none;
  border-radius: 999px;
  padding: 8px 13px;
  cursor: pointer;
  white-space: nowrap;
}
.fieldbar button.ftsel { background: #c9891a; color: #fff; }
.flyfx {
  position: fixed;
  z-index: 60;
  font-size: 22px;
  pointer-events: none;
  transform: translate(-50%, -50%) scale(1);
  opacity: 1;
  transition: left .65s cubic-bezier(.3,.7,.4,1), top .65s cubic-bezier(.3,.7,.4,1), transform .65s, opacity .65s;
}

/* ---------- app-nav: felül kincstár, alul navigáció ---------- */
#hud { right: 8px; flex-wrap: nowrap; align-items: center; }
.invstrip {
  display: flex;
  gap: 5px;
  overflow-x: auto;
  scrollbar-width: none;
  -webkit-overflow-scrolling: touch;
  pointer-events: auto;
}
.invstrip::-webkit-scrollbar { display: none; }
@media (max-width: 520px) { .bname { display: none; } }

#nav {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  display: flex;
  z-index: 9;
  background: rgba(13, 23, 16, .92);
  border-top: 1px solid rgba(255,255,255,.14);
  padding-bottom: env(safe-area-inset-bottom, 0px);
}
#nav button {
  flex: 1;
  font: inherit;
  font-size: 10.5px;
  font-weight: 700;
  color: #b9c7b4;
  background: transparent;
  border: none;
  padding: 7px 0 8px;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 1px;
  position: relative;
}
#nav button i { font-style: normal; font-size: 19px; filter: grayscale(.4) opacity(.8); }
#nav button.on { color: #f0c877; }
#nav button.on i { filter: none; }
#nav .fairdot, #nav .feeddot { position: absolute; top: 4px; right: 18%; }

/* az also savok a nav fölé */
.fieldbar { bottom: calc(64px + env(safe-area-inset-bottom, 0px)); }
.tut { bottom: calc(64px + env(safe-area-inset-bottom, 0px)); }
#picker { bottom: calc(70px + env(safe-area-inset-bottom, 0px)); }

/* ---------- iPhone finomítások ---------- */
#visitbar {
  top: calc(env(safe-area-inset-top, 0px) + 54px);
  z-index: 12;
}
#nav {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
}
body { background: #0d1710; }
#viewport { background: #85b25c; }
