:root {
  --paper: #f7dba7;
  --paper2: #fbe8c4;
  --wood: #8a4b2a;
  --wood2: #b8693a;
  --woodlight: #d99a5b;
  --ink: #3b1f0e;
  --green: #4f9a3e;
  --red: #c0392b;
  --gold: #f2b632;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; overflow: hidden; background: #2f5a2a; color: var(--ink);
  font-family: 'Pixelify Sans', 'Courier New', monospace; font-size: 16px; user-select: none; -webkit-user-select: none; }
canvas#game3d { position: fixed; inset: 0; display: none; touch-action: none; }
canvas#game { display: block; image-rendering: pixelated; image-rendering: crisp-edges; touch-action: none; }
[hidden] { display: none !important; }
button { font-family: inherit; cursor: pointer; }
.ico { width: 32px; height: 32px; image-rendering: pixelated; vertical-align: middle; }
.ico.big { width: 48px; height: 48px; }
.gold-ico { width: 20px; height: 20px; vertical-align: -4px; }
.toast .ico, .float .ico, .order .ico, .row .ico, .seedchip .ico { width: 24px; height: 24px; }
#banner .ico { width: 24px; height: 24px; }

.panel {
  background: var(--paper);
  border: 4px solid var(--wood);
  border-radius: 6px;
  box-shadow: inset 0 0 0 3px var(--woodlight), inset 0 0 0 5px var(--paper2), 0 5px 0 rgba(40, 20, 8, .55);
}

/* ---------------------------------------------------------------- HUD */
#hud { position: fixed; inset: 0; pointer-events: none; }
#hud > * { pointer-events: auto; }
#hud-left { position: absolute; left: 12px; top: 12px; padding: 10px 14px; min-width: 210px; }
.farmname { font-weight: 700; font-size: 17px; margin-bottom: 4px; white-space: nowrap; }
.goldrow { font-size: 22px; font-weight: 700; display: flex; align-items: center; gap: 6px; }
.goldrow .ico { width: 24px; height: 24px; }
#gold.bump { animation: bump .4s; display: inline-block; }
@keyframes bump { 30% { transform: scale(1.3); color: #2e8b2e; } }
.lvlrow { display: flex; align-items: center; gap: 8px; margin-top: 6px; }
.badge { background: var(--green); color: #fff; border: 3px solid #2f6b2a; border-radius: 50%; width: 34px; height: 34px;
  display: grid; place-items: center; font-weight: 700; text-shadow: 1px 1px 0 #1f4a1a; flex: none; }
.xpbar { flex: 1; height: 12px; background: #6b4a2a; border: 2px solid var(--wood); border-radius: 3px; overflow: hidden; }
#xpfill { height: 100%; background: linear-gradient(#ffe066, #f2b632); width: 0; transition: width .4s; }
.xptext { font-size: 12px; text-align: right; opacity: .8; margin-top: 2px; }

#hud-right { position: absolute; right: 12px; top: 12px; display: flex; flex-direction: column; align-items: flex-end; gap: 8px; }
#clock { padding: 6px 12px; font-size: 20px; font-weight: 700; }
.btns { display: flex; gap: 6px; flex-wrap: wrap; justify-content: flex-end; max-width: 260px; }
.hbtn { position: relative; width: 44px; height: 44px; font-size: 22px; background: var(--paper); border: 3px solid var(--wood);
  border-radius: 6px; box-shadow: inset 0 -3px 0 var(--woodlight), 0 3px 0 rgba(40,20,8,.5); padding: 0; }
.hbtn:hover { background: var(--paper2); transform: translateY(-1px); }
.badge-dot { position: absolute; top: -8px; right: -8px; background: var(--red); color: #fff; font-size: 12px; border-radius: 10px;
  min-width: 20px; height: 20px; display: grid; place-items: center; border: 2px solid #fff; animation: pulse 1.2s infinite; }
@keyframes pulse { 50% { transform: scale(1.15); } }

#bottom { position: absolute; left: 50%; bottom: 10px; transform: translateX(-50%); display: flex; flex-direction: column; align-items: center; gap: 6px; max-width: calc(100vw - 16px); }
#hotbar { display: flex; gap: 4px; padding: 6px; }
.slot { position: relative; width: 56px; height: 56px; background: #f0c98a; border: 3px solid var(--wood2); border-radius: 4px; padding: 0;
  display: grid; place-items: center; box-shadow: inset 0 -3px 0 rgba(0,0,0,.12); }
.slot .ico { width: 40px; height: 40px; }
.slot:hover { background: #f7d9a4; }
.slot.active { border-color: #e03c28; background: #fff1cf; box-shadow: 0 0 0 2px #ffd23f, inset 0 -3px 0 rgba(0,0,0,.1); transform: translateY(-3px); }
.slot .key { position: absolute; left: 3px; top: 1px; font-size: 11px; opacity: .65; }
.slot .cnt { position: absolute; right: 3px; bottom: 0; font-size: 14px; font-weight: 700; color: #fff; text-shadow: -1px -1px 0 #3b1f0e, 1px -1px 0 #3b1f0e, -1px 1px 0 #3b1f0e, 1px 1px 0 #3b1f0e; }
.slot .stars { position: absolute; right: 2px; top: 0; font-size: 10px; color: #e0a020; text-shadow: 1px 1px 0 #6b3e1f; }
#seedbar { display: flex; gap: 4px; padding: 5px 8px; background: rgba(59, 31, 14, .82); border-radius: 8px; flex-wrap: wrap; justify-content: center; }
#seedbar .empty { color: #fbe8c4; padding: 4px 8px; font-size: 14px; }
.seedchip { display: flex; align-items: center; gap: 2px; background: #f0c98a; border: 2px solid var(--wood2); border-radius: 5px; padding: 2px 6px 2px 2px; font-weight: 700; }
.seedchip.active { background: #fff1cf; border-color: #e03c28; }

#toasts { position: absolute; top: 14px; left: 50%; transform: translateX(-50%); display: flex; flex-direction: column; align-items: center; gap: 6px; pointer-events: none !important; width: min(92vw, 520px); }
.toast { background: rgba(59, 31, 14, .9); color: #fff6e0; padding: 8px 14px; border-radius: 8px; border: 2px solid #d99a5b; font-size: 15px;
  animation: tin .25s ease-out; transition: opacity .5s, transform .5s; text-align: center; }
.toast.good { border-color: #8fe36a; }
.toast.err { border-color: #ff6b6b; }
.toast.out { opacity: 0; transform: translateY(-10px); }
@keyframes tin { from { opacity: 0; transform: translateY(-12px); } }

#banner { position: absolute; left: 50%; top: 30%; transform: translate(-50%, -50%); padding: 18px 28px; text-align: center; font-size: 18px; pointer-events: none !important; max-width: 90vw; }
#banner.show { animation: pop .5s cubic-bezier(.2, 1.6, .4, 1); }
#banner .lvlup { font-size: 34px; font-weight: 700; color: #d9480f; text-shadow: 2px 2px 0 #ffe066; margin-bottom: 6px; }
@keyframes pop { from { transform: translate(-50%, -50%) scale(.3); opacity: 0; } }

#fx { position: fixed; inset: 0; pointer-events: none; overflow: hidden; }
.float { position: absolute; transform: translate(-50%, -50%); font-weight: 700; font-size: 20px; color: #fff; white-space: nowrap;
  text-shadow: -2px -2px 0 #3b1f0e, 2px -2px 0 #3b1f0e, -2px 2px 0 #3b1f0e, 2px 2px 0 #3b1f0e; animation: floatup 1.6s ease-out forwards; }
.float .xp { color: #9fe36a; font-size: 16px; }
.float .goldtxt { color: #ffd23f; }
.float.gold { font-size: 24px; }
@keyframes floatup { 0% { opacity: 0; transform: translate(-50%, -30%) scale(.6); } 15% { opacity: 1; transform: translate(-50%, -60%) scale(1.1); } 100% { opacity: 0; transform: translate(-50%, -260%); } }

#tip { position: fixed; z-index: 30; pointer-events: none; background: rgba(251, 232, 196, .97); border: 3px solid var(--wood); border-radius: 6px; padding: 6px 10px;
  font-size: 14px; line-height: 1.35; box-shadow: 0 3px 0 rgba(40,20,8,.4); max-width: 260px; }

/* ---------------------------------------------------------------- Buttons */
.btn { background: linear-gradient(#f5b14a, #e08a2a); color: #3b1f0e; border: 3px solid var(--wood); border-radius: 6px; padding: 8px 14px; font-size: 16px; font-weight: 700;
  box-shadow: inset 0 2px 0 #ffd890, 0 3px 0 #5a2e17; }
.btn:hover:not(:disabled) { filter: brightness(1.08); transform: translateY(-1px); }
.btn:active:not(:disabled) { transform: translateY(2px); box-shadow: inset 0 2px 0 #ffd890, 0 1px 0 #5a2e17; }
.btn:disabled { filter: grayscale(.8); opacity: .55; cursor: not-allowed; }
.btn.sm { padding: 3px 9px; font-size: 14px; }
.btn.alt { background: linear-gradient(#9fdc6a, #5fae3a); box-shadow: inset 0 2px 0 #d2f5ae, 0 3px 0 #2f5a1f; }
.btn.ghost { background: #e9cfa0; box-shadow: 0 2px 0 #5a2e17; }

/* ---------------------------------------------------------------- Modal */
#modal { position: fixed; inset: 0; overflow: hidden; background: rgba(20, 12, 6, .55); display: grid; place-items: center; z-index: 20; padding: 12px; }
.modal-box { position: relative; width: min(880px, 100%); max-height: calc(100vh - 24px); max-height: calc(100dvh - 24px); min-width: 0; display: flex; flex-direction: column; padding: 18px 20px; animation: pop2 .2s ease-out; }
@keyframes pop2 { from { transform: scale(.92); opacity: 0; } }
#modal-content { display: flex; flex-direction: column; min-height: 0; flex: 1; }
.modal-box .close { position: absolute; right: 10px; top: 10px; width: 36px; height: 36px; border: 3px solid var(--wood); background: #e9a07a; border-radius: 6px; font-size: 18px; font-weight: 700; color: #3b1f0e; z-index: 2; }
.scroll { overflow-y: auto; overflow-x: hidden; min-height: 0; flex: 1; padding-right: 6px; padding-bottom: 12px; margin-top: 8px; -webkit-overflow-scrolling: touch; }
.scroll::-webkit-scrollbar { width: 10px; } .scroll::-webkit-scrollbar-thumb { background: var(--wood2); border-radius: 5px; }
h2 { margin: 0 0 4px; font-size: 26px; }
h3 { margin: 16px 0 8px; font-size: 19px; border-bottom: 2px dashed var(--woodlight); padding-bottom: 3px; }
.sub { font-size: 13px; opacity: .75; }

.vendor-head { display: flex; gap: 14px; align-items: center; padding-right: 40px; }
.portrait { width: 80px; height: 80px; image-rendering: pixelated; border: 4px solid var(--wood); border-radius: 6px; flex: none; }
.vendor-head .who { font-weight: 600; opacity: .75; }
.speech { margin-top: 4px; background: #fff7e4; border: 2px solid var(--woodlight); border-radius: 8px; padding: 4px 10px; font-size: 15px; display: inline-block; }
.purse { margin-left: auto; font-size: 22px; font-weight: 700; white-space: nowrap; }

.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(min(240px, 100%), 1fr)); gap: 10px; }
.card { min-width: 0; background: #fff3da; border: 3px solid var(--woodlight); border-radius: 6px; padding: 8px 10px; display: flex; flex-direction: column; gap: 5px; }
.card.wide { grid-column: 1 / -1; }
.card.locked { opacity: .55; filter: grayscale(.6); }
.card-top { display: flex; align-items: center; gap: 8px; }
.facts { display: flex; flex-wrap: wrap; gap: 4px 10px; font-size: 13px; }
.facts span { background: #f5e0b5; border-radius: 4px; padding: 1px 6px; }
.buy { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
.price { font-weight: 700; margin-right: auto; white-space: nowrap; }
.own { font-size: 12px; opacity: .7; }
.lock { font-weight: 700; color: #8a4b2a; }

.sellall { display: flex; align-items: center; justify-content: space-between; gap: 10px; flex-wrap: wrap; margin-top: 10px; }
.hot { background: #ffe1c2; border: 2px solid #f08a24; border-radius: 6px; padding: 3px 8px; }
.list { display: flex; flex-direction: column; gap: 4px; margin-top: 8px; }
.row { display: flex; align-items: center; gap: 8px; background: #fff3da; border: 2px solid var(--woodlight); border-radius: 6px; padding: 4px 8px; }
.row.dim { opacity: .55; }
.row .name { flex: 1; font-weight: 600; }
.row .trend { width: 28px; text-align: center; }
.row .price { margin-right: 0; width: 70px; }
.row .have { width: 50px; text-align: right; font-weight: 700; }
.up { color: #2e8b2e; } .down { color: #c0392b; }

.orders { display: grid; grid-template-columns: repeat(auto-fill, minmax(min(240px, 100%), 1fr)); gap: 12px; }
.order { background: #fffaf0 repeating-linear-gradient(#fffaf0 0 22px, #f0e2c4 22px 23px); border: 3px solid var(--woodlight); border-radius: 4px; padding: 10px; display: flex; flex-direction: column; gap: 6px; transform: rotate(-.6deg); }
.order:nth-child(2) { transform: rotate(.7deg); }
.order.ready { border-color: #5fae3a; box-shadow: 0 0 0 3px #b8e07a; }
.order .npc { font-weight: 700; font-size: 18px; }
.order .it { opacity: .75; } .order .it.ok { opacity: 1; color: #2e7b2e; font-weight: 600; }
.order .reward { font-weight: 700; }
.order .actions { display: flex; justify-content: space-between; gap: 6px; margin-top: auto; }

.inv { display: grid; grid-template-columns: repeat(auto-fill, minmax(110px, 1fr)); gap: 8px; }
.invitem { position: relative; background: #fff3da; border: 3px solid var(--woodlight); border-radius: 6px; padding: 6px; text-align: center; }
.invitem.goldq { border-color: #f2b632; background: #fff7d0; }
.invitem.unknown img { filter: brightness(0) opacity(.35); }
.invitem .n { position: absolute; right: 6px; top: 4px; font-weight: 700; }
.invitem .lbl { font-size: 13px; font-weight: 600; }
.invitem .sub { font-size: 11px; }
.stats { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 6px; }

table.lb { width: 100%; border-collapse: collapse; font-size: 17px; }
.lb th, .lb td { padding: 6px 8px; text-align: left; border-bottom: 2px dashed var(--woodlight); }
.lb tr.me { background: #fff1cf; font-weight: 700; }
.help ul { padding-left: 20px; } .help li { margin: 4px 0; line-height: 1.35; }

/* ---------------------------------------------------------------- Login */
#login { position: fixed; inset: 0; display: grid; place-items: center; background: radial-gradient(ellipse at center, rgba(0,0,0,0) 30%, rgba(20,12,6,.45)); z-index: 40; padding: 12px; }
#login-form { padding: 26px 30px; width: min(420px, 100%); display: flex; flex-direction: column; gap: 10px; animation: pop2 .4s ease-out; }
#login h1 { margin: 0; font-size: 44px; text-align: center; color: #d9480f; text-shadow: 3px 3px 0 #ffe066, 5px 5px 0 rgba(59,31,14,.35); letter-spacing: 1px; }
#login h1 .sun { display: inline-block; animation: spin 8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.tagline { text-align: center; margin: 0 0 6px; }
#login label { display: flex; flex-direction: column; font-weight: 600; gap: 3px; }
#login input { font-family: inherit; font-size: 18px; padding: 8px 10px; border: 3px solid var(--wood2); border-radius: 6px; background: #fffaf0; color: var(--ink); }
#login input:focus { outline: none; border-color: #e03c28; }
#login-error { color: var(--red); min-height: 20px; font-weight: 600; text-align: center; }
.login-btns { display: flex; gap: 8px; } .login-btns .btn { flex: 1; }
#login .small { font-size: 13px; text-align: center; opacity: .7; margin: 4px 0 0; }

@media (max-width: 640px) {
  #hud-left { min-width: 0; padding: 6px 10px; left: 6px; top: 6px; }
  .farmname { font-size: 14px; }
  .goldrow { font-size: 18px; }
  #hud-right { right: 6px; top: 6px; }
  .btns { max-width: 150px; }
  .hbtn { width: 38px; height: 38px; font-size: 18px; }
  #clock { font-size: 15px; }
  .slot { width: 40px; height: 40px; border-width: 2px; } .slot .ico { width: 30px; height: 30px; }
  .slot .cnt { font-size: 12px; }
  #hotbar { gap: 2px; padding: 3px; }
  #bottom { bottom: 6px; }
  #modal { padding: 6px; }
  .modal-box { padding: 12px 10px; max-height: calc(100dvh - 12px); }
  .vendor-head { flex-wrap: wrap; gap: 8px; padding-right: 44px; }
  .vendor-head > div { flex: 1; min-width: 0; }
  .portrait { width: 56px; height: 56px; }
  .purse { font-size: 16px; margin-left: 0; width: 100%; }
  .speech { font-size: 14px; }
  h2 { font-size: 22px; }
  .facts span { white-space: normal; }
  .buy .btn.sm { padding: 6px 10px; }
  .row { flex-wrap: wrap; }
}

/* ---------------------------------------------------------------- Grafikmodus */
.hbtn.gfx { font-size: 15px; font-weight: 700; color: #3b1f0e; }
.gfx-choice { display: flex; align-items: center; justify-content: center; gap: 6px; font-weight: 600; }
.gfx-choice .btn.active { background: linear-gradient(#9fdc6a, #5fae3a); box-shadow: inset 0 2px 0 #d2f5ae, 0 2px 0 #2f5a1f; }
