:root {
  --ink: #2b1d16;
  --paper: #f6ecd6;
  --paper-2: #ead9b6;
  --wood: #8b5e3c;
  --wood-dark: #6b4428;
  --aegean: #3d6f9e;
  --aegean-dark: #2c5378;
  --terracotta: #c0643a;
  --olive: #5f7548;
  --gold: #f2c94c;
  --muted: #7a6450;
  --danger: #b5523b;
  --font: 'Pixelify Sans', ui-monospace, monospace;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; overflow: hidden; background: #5b8836; font-family: var(--font); color: var(--ink); }
#game { position: fixed; inset: 0; }
#game canvas { display: block; }
.labels { position: absolute; inset: 0; pointer-events: none; overflow: hidden; }
.name-tag { position: absolute; left: 0; top: 0; font-size: 13px; color: #fff; text-shadow: 1px 1px 0 var(--ink), -1px -1px 0 var(--ink), 1px -1px 0 var(--ink), -1px 1px 0 var(--ink); white-space: nowrap; }
[hidden] { display: none !important; }

.panel {
  background: var(--paper);
  border: 3px solid var(--ink);
  box-shadow: inset 0 0 0 2px var(--paper-2), 0 4px 0 rgba(43, 29, 22, 0.35);
  border-radius: 4px;
}
.muted { color: var(--muted); }

.btn {
  font: inherit; font-size: 16px; cursor: pointer;
  background: var(--paper-2); color: var(--ink);
  border: 2px solid var(--ink); border-radius: 3px;
  padding: 6px 12px; box-shadow: 0 2px 0 var(--ink);
}
.btn:hover { background: #fff6e2; }
.btn:active { transform: translateY(2px); box-shadow: none; }
.btn:disabled { opacity: .45; cursor: not-allowed; transform: none; box-shadow: 0 2px 0 var(--ink); }
.btn.primary { background: var(--aegean); color: #fff; }
.btn.primary:hover { background: var(--aegean-dark); }
.btn.small { font-size: 14px; padding: 3px 8px; }
.btn.ghost { background: transparent; }
.btn.dev { background: #e4d3f0; }

/* ---------- giriş ---------- */
.screen { position: fixed; inset: 0; display: grid; place-items: center; padding: 16px; z-index: 20; }
#auth { background: radial-gradient(circle at 50% 30%, #9cc56b, #4f7a32); }
.auth-card { width: min(380px, 100%); padding: 24px; }
.auth-card h1 { margin: 0; font-size: 34px; color: var(--terracotta); text-shadow: 2px 2px 0 var(--ink); letter-spacing: 1px; }
.subtitle { margin: 4px 0 16px; color: var(--muted); }
.tabs { display: flex; gap: 6px; margin-bottom: 12px; }
.tabs button { flex: 1; font: inherit; font-size: 16px; padding: 6px; border: 2px solid var(--ink); background: var(--paper-2); cursor: pointer; border-radius: 3px; }
.tabs button.active { background: var(--olive); color: #fff; }
form label { display: block; margin-bottom: 10px; font-size: 15px; }
form input, .modal-card input {
  display: block; width: 100%; margin-top: 3px; font: inherit; font-size: 16px;
  padding: 6px 8px; border: 2px solid var(--ink); border-radius: 3px; background: #fffaf0;
}
.error { color: var(--danger); min-height: 1.2em; margin: 4px 0 8px; }
#auth-submit { width: 100%; }

/* ---------- HUD ---------- */
#hud { position: fixed; inset: 0; pointer-events: none; z-index: 10; }
#hud .panel, #hud button { pointer-events: auto; }
.hud-bar { position: absolute; top: 10px; display: flex; align-items: center; gap: 10px; padding: 6px 10px; font-size: 16px; }
.hud-left { left: 10px; }
.hud-right { right: 10px; flex-wrap: wrap; justify-content: flex-end; max-width: calc(100% - 20px); }
#hud-weather-icon { width: 32px; height: 32px; image-rendering: pixelated; }
#hud-date { font-weight: 600; }
.stat { display: inline-flex; align-items: center; gap: 4px; }
.stat img { width: 18px; height: 18px; image-rendering: pixelated; }
.who { font-weight: 600; color: var(--aegean-dark); }
#event-banner { position: absolute; top: 70px; left: 50%; transform: translateX(-50%); padding: 6px 14px; font-size: 15px; background: #fff3c4; max-width: calc(100% - 20px); text-align: center; }
#prompt { position: absolute; bottom: 112px; left: 50%; transform: translateX(-50%); padding: 6px 14px; background: rgba(43, 29, 22, .82); color: #fff; border-radius: 4px; font-size: 17px; white-space: nowrap; }
#help { position: absolute; bottom: 12px; left: 50%; transform: translateX(-50%); font-size: 13px; color: #f6ecd6; text-shadow: 1px 1px 0 var(--ink); white-space: nowrap; }
#toasts { position: absolute; left: 10px; bottom: 112px; display: flex; flex-direction: column; gap: 6px; max-width: min(360px, 70vw); }
.toast { background: rgba(246, 236, 214, .95); border: 2px solid var(--ink); border-radius: 3px; padding: 4px 8px; font-size: 14px; animation: toast-in .2s ease-out; }
.toast.error { background: #f8d6cc; }
@keyframes toast-in { from { opacity: 0; transform: translateY(6px); } }

@media (max-width: 720px) {
  .hud-bar { font-size: 13px; gap: 6px; }
  .hud-right { top: 64px; }
  #event-banner { top: 116px; }
  #help { display: none; }
}

/* ---------- modal ---------- */
#modal { background: rgba(20, 14, 10, .45); }
.modal-card { position: relative; width: min(560px, 100%); max-height: calc(100vh - 32px); overflow: auto; padding: 18px 20px; }
.modal-card h2 { margin: 0 0 10px; color: var(--wood-dark); }
.close { position: absolute; top: 8px; right: 10px; font: inherit; font-size: 18px; background: none; border: 0; cursor: pointer; }
.list { display: flex; flex-direction: column; gap: 6px; }
.row { display: grid; grid-template-columns: 36px 1fr auto; align-items: center; gap: 10px; padding: 6px 8px; background: #fffaf0; border: 2px solid var(--paper-2); border-radius: 3px; }
.row.clickable { cursor: pointer; }
.row.clickable:hover { border-color: var(--aegean); }
.row.disabled { opacity: .5; cursor: not-allowed; }
.row img { width: 32px; height: 32px; image-rendering: pixelated; }
.row .name { font-weight: 600; }
.row .meta { font-size: 13px; color: var(--muted); }
.row .key { font-size: 12px; border: 1px solid var(--muted); border-radius: 2px; padding: 0 4px; margin-right: 4px; }
.market-row { grid-template-columns: 36px 1fr auto auto; }
.price { font-weight: 600; font-size: 18px; text-align: right; }
.badge { display: inline-block; font-size: 11px; padding: 0 4px; border-radius: 2px; margin-left: 4px; color: #fff; vertical-align: middle; }
.badge.up { background: var(--olive); }
.badge.down { background: var(--danger); }
.badge.off { background: var(--aegean); }
.sell { display: flex; align-items: center; gap: 4px; }
.sell input { width: 54px; margin: 0; padding: 3px 4px; text-align: center; }
.spark { display: block; }
.empty { color: var(--muted); padding: 12px 0; }
.donate-form { display: flex; gap: 8px; align-items: flex-end; }
.donate-form label { flex: 1; margin: 0; }

/* ---------- enerji, alet çubuğu, beceriler ---------- */
.energy .bar { display: inline-block; width: 70px; height: 10px; border: 2px solid var(--ink); background: #5a4636; border-radius: 2px; overflow: hidden; }
#hud-energy-fill { display: block; height: 100%; background: linear-gradient(#9fd06a, #5f9a3c); transition: width .3s; }
#hud-energy-fill.low { background: linear-gradient(#f0a060, #c0643a); }
.dot { display: inline-block; width: 8px; height: 8px; margin-left: 4px; border-radius: 50%; background: var(--terracotta); border: 1px solid var(--ink); vertical-align: middle; }
#hotbar { position: absolute; bottom: 36px; left: 50%; transform: translateX(-50%); display: flex; gap: 4px; padding: 4px; }
.slot { position: relative; width: 52px; height: 52px; display: grid; place-items: center; background: #fffaf0; border: 2px solid var(--paper-2); border-radius: 3px; cursor: pointer; }
.slot.active { border-color: var(--terracotta); box-shadow: inset 0 0 0 2px var(--gold); }
.slot img { width: 36px; height: 36px; image-rendering: pixelated; }
.slot .k { position: absolute; top: 1px; left: 3px; font-size: 11px; color: var(--muted); }
.slot .water { position: absolute; left: 4px; right: 4px; bottom: 3px; height: 4px; background: #c9b89a; }
.slot .water i { display: block; height: 100%; background: var(--aegean); }
.skill { padding: 8px 10px; background: #fffaf0; border: 2px solid var(--paper-2); border-radius: 3px; }
.skill-head { display: flex; justify-content: space-between; align-items: baseline; }
.skill-head .lvl { font-weight: 600; color: var(--aegean-dark); }
.xpbar { height: 8px; margin: 4px 0; border: 2px solid var(--ink); background: #e6d8bd; }
.xpbar i { display: block; height: 100%; background: var(--olive); }
.pips { display: flex; gap: 2px; }
.pips span { width: 14px; height: 6px; background: #d9cbb0; border: 1px solid var(--muted); }
.pips span.on { background: var(--gold); }
.pips span.milestone { border-color: var(--terracotta); }
.prof { font-size: 13px; margin-top: 4px; }
.prof b { color: var(--olive); }
.choice { margin-top: 6px; padding: 6px; border: 2px dashed var(--terracotta); background: #fff3e6; }
.choice-options { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; margin-top: 4px; }
.choice-options button { text-align: left; }
.choice-options small { display: block; font-size: 12px; color: var(--muted); }
.cat-tabs { display: flex; gap: 4px; flex-wrap: wrap; margin-bottom: 8px; }
.cat-tabs button { font: inherit; font-size: 14px; padding: 3px 8px; border: 2px solid var(--ink); background: var(--paper-2); border-radius: 3px; cursor: pointer; }
.cat-tabs button.active { background: var(--aegean); color: #fff; }
@media (max-width: 720px) {
  .slot { width: 42px; height: 42px; }
  .slot img { width: 28px; height: 28px; }
}

/* ---------- restorasyon ve hayvanlar ---------- */
.quote { font-style: italic; color: var(--wood-dark); }
.project .meta { margin: 2px 0 6px; }
.req { display: grid; grid-template-columns: 28px 1fr auto; align-items: center; gap: 8px; margin: 4px 0; }
.req img { width: 24px; height: 24px; image-rendering: pixelated; }
.req-coin { font-weight: 600; text-align: center; }
.req-label { display: flex; justify-content: space-between; font-size: 13px; }
.project > .btn.primary { margin-top: 6px; width: 100%; }
.log { margin: 0; padding-left: 18px; font-size: 13px; color: var(--muted); }
.modal-card h3 { margin: 12px 0 6px; color: var(--wood-dark); font-size: 17px; }
.hearts { color: #d8392b; letter-spacing: 1px; }
.animal-bar { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 8px; }
.animal-actions { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 4px; }
.buy-form { display: grid; grid-template-columns: auto 1fr auto; gap: 6px; align-items: center; }
.buy-form input, .buy-form select { margin: 0; font: inherit; font-size: 15px; padding: 5px 6px; border: 2px solid var(--ink); border-radius: 3px; background: #fffaf0; }
@media (max-width: 560px) { .buy-form { grid-template-columns: 1fr; } }

/* ---------- pano, ev, dolap ---------- */
.note-form { display: grid; gap: 6px; margin-bottom: 10px; }
.note-form textarea { font: inherit; font-size: 15px; padding: 6px 8px; border: 2px solid var(--ink); border-radius: 3px; background: #fffaf0; resize: vertical; }
.notes { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 8px; }
.note { position: relative; background: #fff6c8; border: 2px solid #d9c27a; padding: 14px 8px 6px; transform: rotate(-0.6deg); box-shadow: 0 2px 0 rgba(0,0,0,.15); }
.note:nth-child(2n) { background: #e3f3ff; border-color: #9cc6e8; transform: rotate(0.8deg); }
.note:nth-child(3n) { background: #ffe3e0; border-color: #e8a59c; }
.note::before { content: ''; position: absolute; top: 3px; left: 50%; width: 9px; height: 9px; margin-left: -4px; border-radius: 50%; background: var(--pin, #c8402a); border: 1px solid var(--ink); }
.note-body { white-space: pre-wrap; word-break: break-word; font-size: 15px; }
.note-del { position: absolute; top: 2px; right: 4px; background: none; border: 0; cursor: pointer; font: inherit; color: var(--muted); }
.decor-row { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; margin: 6px 0; }
.decor-row > span { min-width: 170px; font-size: 14px; }
.swatch { min-width: 30px; height: 30px; border: 2px solid var(--ink); border-radius: 3px; background: var(--paper-2); font: inherit; font-size: 13px; cursor: pointer; padding: 0 6px; }
.swatch.on { box-shadow: 0 0 0 3px var(--gold); }
.swatch:disabled { cursor: default; }
.shop-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(120px, 1fr)); gap: 6px; }
.shop-item { display: flex; flex-direction: column; align-items: flex-start; gap: 2px; padding: 6px 8px; border: 2px solid var(--paper-2); background: #fffaf0; border-radius: 3px; font: inherit; font-size: 14px; cursor: pointer; text-align: left; }
.shop-item:hover { border-color: var(--aegean); }
.shop-item.on { border-color: var(--terracotta); box-shadow: inset 0 0 0 2px var(--gold); }
.shop-item small { color: var(--muted); }
.dot-color { display: inline-block; width: 16px; height: 16px; border: 1px solid var(--ink); border-radius: 50%; }
.hp .bar { display: inline-block; width: 60px; height: 10px; border: 2px solid var(--ink); background: #5a3636; border-radius: 2px; overflow: hidden; }
#hud-hp-fill { display: block; height: 100%; background: linear-gradient(#ff7a6a, #c8302a); transition: width .3s; }
.hp-heart { color: #d8392b; }
#mine-badge { position: absolute; bottom: 152px; left: 50%; transform: translateX(-50%); padding: 4px 12px; background: #2a1e16; color: #ffd27a; border: 2px solid #ffd27a; border-radius: 3px; font-size: 16px; }
body.in-mine .labels { display: none; }

/* ---------- köy seçimi ve davet ---------- */
#villages { background: radial-gradient(circle at 50% 30%, #9cc56b, #4f7a32); }
.villages-card { width: min(520px, 100%); max-height: calc(100vh - 32px); overflow: auto; }
.villages-card h3 { margin: 14px 0 6px; color: var(--wood-dark); }
.inline-form { display: grid; grid-template-columns: 1fr 1fr auto; gap: 6px; }
.inline-form input { margin: 0; font: inherit; font-size: 15px; padding: 6px 8px; border: 2px solid var(--ink); border-radius: 3px; background: #fffaf0; }
@media (max-width: 560px) { .inline-form { grid-template-columns: 1fr; } }
.village-row { display: flex; justify-content: space-between; align-items: center; gap: 8px; padding: 8px 10px; background: #fffaf0; border: 2px solid var(--paper-2); border-radius: 3px; }
.village-row .name { font-weight: 600; }
.invite-code { font-size: 34px; letter-spacing: 3px; text-align: center; padding: 10px; margin: 8px 0; background: #fff6c8; border: 2px dashed var(--terracotta); border-radius: 4px; user-select: all; }
.invite-actions { display: flex; flex-wrap: wrap; gap: 6px; justify-content: center; }
