:root {
  --dark: #3f2832;
  --paper: #f6e2b8;
  --paper2: #ecc98f;
  --wood: #b8693f;
  --accent: #e07b39;
  --green: #4f9a45;
  --red: #c9483d;
  --blue: #4a8fd6;
  --atlas: none;
  --atlas2: none;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  background: #84c669;
  font-family: 'Pixelify Sans', 'Trebuchet MS', sans-serif;
  color: var(--dark);
  user-select: none;
  -webkit-user-select: none;
}

canvas { display: block; image-rendering: pixelated; cursor: crosshair; }

.hidden { display: none !important; }

.ico {
  display: inline-block;
  flex: none;
  background-image: var(--atlas);
  background-repeat: no-repeat;
  image-rendering: pixelated;
  vertical-align: middle;
}

.ui {
  background: var(--paper);
  border: 3px solid var(--dark);
  border-radius: 6px;
  box-shadow: 0 4px 0 rgba(0, 0, 0, .25), inset 0 0 0 2px #fff4d8;
}

kbd {
  font-family: inherit;
  font-size: .75em;
  background: rgba(0, 0, 0, .2);
  border-radius: 3px;
  padding: 0 4px;
  margin-left: 4px;
}

/* ---------- Üst bilgi ---------- */
#hud { position: fixed; left: 12px; top: 12px; display: flex; gap: 8px; flex-wrap: wrap; max-width: 55vw; }
.hud-box {
  display: flex; align-items: center; gap: 6px;
  padding: 5px 10px; font-size: 18px; font-weight: 600;
  background: var(--paper); border: 3px solid var(--dark); border-radius: 6px;
  box-shadow: 0 3px 0 rgba(0, 0, 0, .25);
}
.coin {
  display: inline-block; flex: none;
  width: 16px; height: 16px; border-radius: 50%;
  background: #f4c542; border: 2px solid #a8741a;
  box-shadow: inset -2px -2px 0 #e0a52c;
  vertical-align: middle;
}
.water-bar { width: 60px; height: 10px; border: 2px solid var(--dark); border-radius: 3px; background: #d8c3a0; overflow: hidden; }
.water-bar > i { display: block; height: 100%; background: var(--blue); }

/* ---------- Görev paneli ---------- */
#quest { position: fixed; right: 12px; top: 12px; width: 330px; padding: 0; overflow: hidden; }
#quest .q-tabs { display: flex; background: var(--wood); border-bottom: 3px solid var(--dark); }
#quest .q-tab {
  flex: 1; padding: 7px 8px; text-align: center; cursor: pointer;
  color: #fde7c6; font-weight: 600; font-size: 15px;
}
#quest .q-tab.on { background: var(--paper); color: var(--dark); }
#quest .q-tab.tog { flex: none; width: 36px; }
#quest .q-body { padding: 10px 12px 12px; max-height: 60vh; overflow: auto; }
#quest.collapsed .q-body { display: none; }
#quest h3 { margin: 0 0 4px; font-size: 18px; }
#quest p { margin: 0 0 8px; font-size: 14px; line-height: 1.3; }
.q-num { font-size: 12px; opacity: .7; }
.goal { font-size: 14px; margin-bottom: 6px; }
.goal .lbl { display: flex; justify-content: space-between; }
.progress { height: 10px; background: #d8b67c; border: 2px solid var(--dark); border-radius: 3px; overflow: hidden; margin-top: 2px; }
.progress > i { display: block; height: 100%; background: var(--green); }
.reward { font-size: 13px; margin-top: 6px; display: flex; flex-wrap: wrap; gap: 6px; align-items: center; }
.order { border-bottom: 2px dashed #d9b77e; padding: 6px 0 8px; }
.order:last-child { border-bottom: none; }
.order .who { font-weight: 700; font-size: 15px; }
.order .items { display: flex; flex-wrap: wrap; gap: 8px; margin: 4px 0; font-size: 14px; }
.order .items span.it { display: inline-flex; align-items: center; gap: 2px; }
.order .foot { display: flex; justify-content: space-between; align-items: center; font-size: 14px; }

/* ---------- Alet çubuğu ---------- */
#hotbar {
  position: fixed; left: 50%; bottom: 12px; transform: translateX(-50%);
  display: flex; gap: 4px; padding: 6px; max-width: calc(100vw - 24px); overflow-x: auto;
}
.slot {
  position: relative; flex: none;
  width: 54px; height: 54px;
  background: #e8cfa0; border: 2px solid var(--dark); border-radius: 4px;
  display: flex; align-items: center; justify-content: center; cursor: pointer;
}
.slot:hover { background: #f3dcae; }
.slot.sel { background: #fff3cf; box-shadow: 0 0 0 3px #fff, 0 0 0 6px var(--accent); z-index: 1; }
.slot .k { position: absolute; left: 3px; top: 0; font-size: 12px; font-weight: 700; opacity: .75; }
.slot .n {
  position: absolute; right: 3px; bottom: 0; font-size: 14px; font-weight: 700;
  color: #fff; text-shadow: -1px -1px 0 var(--dark), 1px -1px 0 var(--dark), -1px 1px 0 var(--dark), 1px 1px 0 var(--dark);
}
.slot.empty .ico { opacity: .35; }
.slot.off { background: #d9d4e6; }
.slot.off .ico { filter: grayscale(.7); opacity: .5; }
.slot .sb { position: absolute; right: 2px; top: 0; font-size: 11px; }
.slot .wb { position: absolute; left: 5px; right: 5px; bottom: 3px; height: 4px; background: #c9b28c; border-radius: 2px; overflow: hidden; }
.slot .wb > i { display: block; height: 100%; background: var(--blue); }
.sel-name {
  position: fixed; left: 50%; bottom: 84px; transform: translateX(-50%);
  background: rgba(63, 40, 50, .85); color: #fff; padding: 3px 10px; border-radius: 4px; font-size: 15px;
  pointer-events: none; white-space: nowrap;
}

/* ---------- Menü düğmeleri ---------- */
#menu { position: fixed; left: 12px; bottom: 12px; display: flex; flex-direction: column; gap: 6px; }

.btn {
  font-family: inherit; font-size: 16px; font-weight: 600;
  background: var(--accent); color: #fff;
  border: 2px solid var(--dark); border-radius: 4px;
  padding: 6px 12px; cursor: pointer;
  box-shadow: 0 3px 0 var(--dark);
  text-shadow: 1px 1px 0 rgba(0, 0, 0, .3);
}
.btn:hover { filter: brightness(1.08); }
.btn:active { transform: translateY(2px); box-shadow: 0 1px 0 var(--dark); }
.btn.btn:disabled { background: #b9a58a; cursor: not-allowed; filter: none; transform: none; box-shadow: 0 3px 0 var(--dark); }
.btn.green { background: var(--green); }
.btn.wood { background: var(--wood); }
.btn.blue { background: var(--blue); }
.btn.red { background: var(--red); }
.btn.small { font-size: 14px; padding: 3px 8px; }

/* ---------- Pencere ---------- */
#modal { position: fixed; inset: 0; background: rgba(30, 20, 30, .45); display: flex; align-items: center; justify-content: center; z-index: 20; }
.panel { width: min(640px, 94vw); max-height: 88vh; display: flex; flex-direction: column; overflow: hidden; }
.panel-head { display: flex; justify-content: space-between; align-items: center; padding: 8px 12px; background: var(--wood); border-bottom: 3px solid var(--dark); }
.panel-head h2 { margin: 0; font-size: 22px; color: #fff; text-shadow: 2px 2px 0 var(--dark); }
#modal-body { padding: 12px 14px 16px; overflow: auto; }
#modal-body p { margin: 4px 0 10px; line-height: 1.35; }
.row { display: flex; align-items: center; gap: 10px; padding: 8px 4px; border-bottom: 2px dashed #d9b77e; }
.row:last-child { border-bottom: none; }
.row .grow { flex: 1; min-width: 0; }
.row .title { font-weight: 700; font-size: 17px; }
.row .desc { font-size: 14px; opacity: .85; }
.row .btns { display: flex; gap: 6px; flex-wrap: wrap; justify-content: flex-end; }
.row.locked { opacity: .5; }
.tabs { display: flex; gap: 6px; margin-bottom: 10px; flex-wrap: wrap; }
.tabs .btn { background: #c9a878; }
.tabs .btn.on { background: var(--accent); }
.cost { display: inline-flex; gap: 8px; align-items: center; font-size: 15px; flex-wrap: wrap; }
.cost > span { display: inline-flex; align-items: center; gap: 3px; }
.cost .lack { color: var(--red); font-weight: 700; }
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(76px, 1fr)); gap: 8px; }
.cell { background: #e8cfa0; border: 2px solid var(--dark); border-radius: 4px; padding: 6px 2px; text-align: center; font-size: 13px; }
.cell b { display: block; font-size: 16px; }
#modal-body h3 { margin: 12px 0 4px; }
.preview { image-rendering: pixelated; flex: none; }
.keys { display: grid; grid-template-columns: auto 1fr; gap: 6px 14px; font-size: 15px; margin: 8px 0 12px; }
.keys kbd { margin: 0; font-size: 14px; padding: 1px 6px; background: var(--dark); color: #fff; }
.center { text-align: center; }
.big-btn { font-size: 20px; padding: 10px 26px; }
.bar2 { height: 12px; background: #d8b67c; border: 2px solid var(--dark); border-radius: 3px; overflow: hidden; }
.bar2 > i { display: block; height: 100%; background: #e7b23a; }

/* ---------- Bildirimler ---------- */
#toasts { position: fixed; top: 70px; left: 50%; transform: translateX(-50%); display: flex; flex-direction: column; align-items: center; gap: 6px; pointer-events: none; z-index: 30; }
.toast {
  background: var(--paper); border: 2px solid var(--dark); border-radius: 4px;
  padding: 6px 14px; font-size: 16px; font-weight: 600; text-align: center; max-width: 80vw;
  box-shadow: 0 3px 0 rgba(0, 0, 0, .25);
  animation: pop .25s ease-out; transition: opacity .5s;
}
.toast.big { background: #fff3cf; font-size: 21px; border-width: 3px; padding: 10px 22px; box-shadow: 0 0 0 4px var(--accent), 0 6px 0 rgba(0, 0, 0, .25); }
.toast.warn { background: #ffd9cf; }
.toast.out { opacity: 0; }
@keyframes pop { from { transform: scale(.7); opacity: 0; } to { transform: scale(1); opacity: 1; } }

.choice-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(118px, 1fr)); gap: 10px; }
.choice {
  font-family: inherit; color: var(--dark); cursor: pointer;
  display: flex; flex-direction: column; align-items: center; justify-content: flex-end; gap: 6px;
  padding: 10px 6px; background: #fff8e8; border: 3px solid var(--dark); border-radius: 6px;
  box-shadow: 0 4px 0 rgba(0, 0, 0, .2); font-size: 15px; transition: transform .1s;
}
.choice:hover { transform: translateY(-2px); }
.choice.on { background: #fff3cf; box-shadow: 0 0 0 4px var(--accent), 0 4px 0 rgba(0, 0, 0, .2); }
.choice.on b::before { content: '✔ '; color: var(--green); }
.name-input {
  font-family: inherit; font-size: 24px; font-weight: 700; text-align: center;
  width: 260px; padding: 8px 10px; color: var(--dark);
  background: #fff8e8; border: 3px solid var(--dark); border-radius: 6px; outline: none;
}
.name-input:focus { box-shadow: 0 0 0 3px var(--accent); }

/* ---------- Posta kutusu ve mektuplar ---------- */
.envelopes { display: grid; grid-template-columns: repeat(auto-fill, minmax(170px, 1fr)); gap: 12px; }
.envelope {
  position: relative; font-family: inherit; cursor: pointer; text-align: center;
  display: flex; flex-direction: column; align-items: center; gap: 2px;
  padding: 14px 8px 12px; background: #fff8e8; color: var(--dark);
  border: 3px solid var(--dark); border-radius: 6px; box-shadow: 0 4px 0 rgba(0, 0, 0, .2);
  transition: transform .1s;
}
.envelope:hover { transform: translateY(-3px) rotate(-1deg); background: #fffdf5; }
.envelope.read { background: #efe3c8; opacity: .9; }
.env-icon { font-size: 38px; line-height: 1; }
.env-who { font-weight: 700; font-size: 17px; }
.env-sub { font-size: 13px; opacity: .8; }
.envelope:not(.read) .env-sub { color: var(--red); font-weight: 700; opacity: 1; }
.seal { position: absolute; top: 8px; right: 10px; width: 16px; height: 16px; border-radius: 50%; background: #c9483d; box-shadow: inset -2px -2px 0 #9a2f27, 0 0 0 2px #fff8e8; }
.letter {
  position: relative; max-width: 480px; margin: 4px auto; padding: 22px 26px 18px;
  background: #fffaf0 repeating-linear-gradient(transparent, transparent 27px, #e8dcc2 27px, #e8dcc2 28px);
  border: 2px solid #d9c49a; border-radius: 4px; box-shadow: 0 6px 14px rgba(0, 0, 0, .18);
  transform: rotate(-.6deg); font-size: 17px; line-height: 28px;
}
.letter p { margin: 0 0 8px; }
.letter ul { list-style: none; margin: 4px 0 10px; padding: 0 0 0 10px; }
.letter li { display: flex; align-items: center; gap: 8px; }
.letter .have { font-size: 14px; color: var(--red); }
.letter .have.ok { color: #2e7d32; }
.letter .l-date { position: absolute; top: 8px; right: 14px; font-size: 13px; opacity: .6; }
.letter .sign { text-align: right; margin-top: 10px; }
.mail-note { background: #fff3cf; border: 2px dashed var(--accent); border-radius: 4px; padding: 6px 8px; }

/* ---------- Harita ---------- */
#minimap-box { position: fixed; right: 12px; bottom: 96px; padding: 4px; cursor: pointer; z-index: 4; }
#minimap-box:hover { box-shadow: 0 0 0 3px var(--accent), 0 4px 0 rgba(0, 0, 0, .25); }
#minimap { display: block; width: 192px; height: 144px; image-rendering: pixelated; border: 2px solid var(--dark); border-radius: 3px; }
.mm-label { text-align: center; font-size: 13px; font-weight: 700; padding-top: 2px; }
#bigmap { display: block; margin: 0 auto; max-width: 100%; height: auto; image-rendering: pixelated; border: 3px solid var(--dark); border-radius: 4px; }
.legend { display: flex; flex-wrap: wrap; gap: 6px 14px; justify-content: center; margin-top: 10px; font-size: 14px; }
.legend span { display: inline-flex; align-items: center; gap: 5px; }
.legend i { display: inline-block; width: 12px; height: 12px; border: 2px solid var(--dark); border-radius: 2px; }
@media (max-width: 900px) { #minimap-box { display: none; } }

#buildbar { position: fixed; top: 64px; left: 50%; transform: translateX(-50%); padding: 6px 14px; font-size: 16px; font-weight: 600; z-index: 5; display: flex; gap: 10px; align-items: center; }

@media (max-width: 900px) {
  #quest { width: 260px; }
  #hud { max-width: 45vw; }
  .hud-box { font-size: 15px; }
  .slot { width: 46px; height: 46px; }
  #menu .btn { font-size: 13px; padding: 4px 8px; }
}

/* ---------- Dil seçimi ---------- */
#lang-select { position: fixed; inset: 0; background: rgba(30, 20, 30, .45); display: flex; align-items: center; justify-content: center; z-index: 30; }
#lang-select .panel { width: min(420px, 94vw); }
#lang-select .lang-body { display: flex; flex-direction: column; gap: 12px; align-items: stretch; padding: 18px 22px 22px; }

/* ---------- Dokunmatik kontroller (body.touch) ---------- */
html { touch-action: manipulation; -webkit-tap-highlight-color: transparent; }
#touch-ctl { display: none; }
.bb-x { order: 9; }
body.touch #touch-ctl { display: block; }
body.touch canvas { touch-action: none; }
#stick, .tbtn { position: fixed; z-index: 6; touch-action: none; user-select: none; -webkit-user-select: none; }
#stick {
  left: calc(20px + env(safe-area-inset-left)); bottom: 20px; width: 128px; height: 128px; border-radius: 50%;
  background: rgba(246, 226, 184, .35); border: 3px solid rgba(63, 40, 50, .55);
}
#stick-knob {
  position: absolute; left: 50%; top: 50%; width: 58px; height: 58px; margin: -29px 0 0 -29px; border-radius: 50%;
  background: var(--paper); border: 3px solid var(--dark); box-shadow: 0 3px 0 rgba(0, 0, 0, .25); pointer-events: none;
}
.tbtn {
  border-radius: 50%; border: 3px solid var(--dark); color: #fff; font-family: inherit; font-weight: 700;
  box-shadow: 0 4px 0 var(--dark); text-shadow: 1px 1px 0 var(--dark);
}
.tbtn:active { transform: translateY(3px); box-shadow: 0 1px 0 var(--dark); }
#tb-use { right: calc(20px + env(safe-area-inset-right)); bottom: 24px; width: 84px; height: 84px; font-size: 17px; background: var(--accent); }
#tb-e { right: calc(116px + env(safe-area-inset-right)); bottom: 44px; width: 60px; height: 60px; font-size: 22px; background: var(--green); }

/* menü düğmeleri alet çubuğunun üstünde yatay sıra olur, kısayol tuşları gizlenir */
body.touch #menu { left: 50%; bottom: 112px; transform: translateX(-50%); flex-direction: row; flex-wrap: wrap; justify-content: center; gap: 4px; width: max-content; max-width: calc(100vw - 300px); }
body.touch #menu .btn { font-size: 12px; padding: 4px 7px; }
body.touch kbd, body.touch .slot .k { display: none; }
body.touch .sel-name { bottom: 82px; }
body.touch #quest .q-body { max-height: 32vh; }
body.touch #minimap-box { display: none; }

/* dikey telefon: kontroller alet çubuğu ve menünün üstüne çıkar */
@media (orientation: portrait) {
  body.touch #menu { max-width: calc(100vw - 24px); }
  body.touch #stick { bottom: 190px; }
  body.touch #tb-use { bottom: 194px; }
  body.touch #tb-e { bottom: 214px; }
  body.touch #quest { width: min(260px, 60vw); }
}
body.touch #hotbar { max-width: calc(100vw - 370px); }
@media (orientation: portrait) { body.touch #hotbar { max-width: calc(100vw - 24px); } }
/* dikey telefon: üst bilgi tam genişlikte, görev paneli onun altında */
@media (orientation: portrait) {
  body.touch #hud { max-width: calc(100vw - 24px); }
  body.touch #quest { top: 108px; left: 12px; right: 12px; width: auto; }
  body.touch #quest .q-body { max-height: 22vh; }
}
