:root {
  --wood: #6b4a2f;
  --wood-dark: #4a3120;
  --parch: #fff6e2;
  --parch-2: #ffeecb;
  --green: #6ec24a;
  --green-dark: #4d9430;
  --blue: #4aa6e0;
  --blue-dark: #2f7cb0;
  --red: #e0574a;
  --red-dark: #b23a2e;
  --gold: #f5b33c;
  --ink: #4a3624;
  --shadow: 0 6px 0 rgba(0, 0, 0, .18), 0 10px 22px rgba(0, 0, 0, .22);
}

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

html, body {
  height: 100%;
  overflow: hidden;
  background: #7fc4e8;
  font-family: "Trebuchet MS", "Segoe UI", Tahoma, sans-serif;
  color: var(--ink);
  -webkit-font-smoothing: antialiased;
  user-select: none;
}

#app { position: fixed; inset: 0; }

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

/* ---------- Üst çubuk ---------- */
#topbar {
  position: absolute; top: 0; left: 0; right: 0;
  display: flex; align-items: center; gap: 8px;
  padding: 10px 12px;
  pointer-events: none;
  z-index: 20;
  flex-wrap: wrap;
}
#topbar > * { pointer-events: auto; }
.grow { flex: 1; pointer-events: none !important; }

.chip {
  display: flex; align-items: center; gap: 7px;
  background: linear-gradient(#fffaf0, var(--parch-2));
  border: 3px solid var(--wood);
  border-radius: 999px;
  padding: 6px 14px 6px 10px;
  font-weight: 700; font-size: 15px;
  box-shadow: 0 4px 0 var(--wood-dark), 0 8px 16px rgba(0,0,0,.2);
  white-space: nowrap;
  transition: transform .12s;
}
.chip .ico { font-size: 17px; line-height: 1; }
.chip.money .val { color: #2f7a2a; }
.chip.pop { animation: pop .35s ease; }
@keyframes pop { 0%{transform:scale(1)} 40%{transform:scale(1.15)} 100%{transform:scale(1)} }

.chip.level { padding-right: 10px; }
.xpbar {
  width: 62px; height: 9px; border-radius: 99px;
  background: #d9c39a; border: 2px solid var(--wood);
  overflow: hidden;
}
.xpbar i { display: block; height: 100%; width: 0%; background: linear-gradient(90deg, var(--gold), #ffd97a); transition: width .3s; }

.up   { color: #2f7a2a !important; }
.down { color: #c0392b !important; }

.speeds {
  display: flex; gap: 4px;
  background: linear-gradient(#fffaf0, var(--parch-2));
  border: 3px solid var(--wood); border-radius: 999px; padding: 4px;
  box-shadow: 0 4px 0 var(--wood-dark);
}
.speeds button {
  border: none; background: transparent; cursor: pointer;
  font-size: 15px; width: 32px; height: 28px; border-radius: 99px;
  color: var(--ink);
}
.speeds button:hover { background: #eddcb8; }
.speeds button.active { background: var(--green); color: #fff; box-shadow: inset 0 -2px 0 var(--green-dark); }

.iconbtn {
  width: 40px; height: 40px; border-radius: 50%;
  border: 3px solid var(--wood);
  background: linear-gradient(#fffaf0, var(--parch-2));
  box-shadow: 0 4px 0 var(--wood-dark);
  font-size: 17px; cursor: pointer;
}
.iconbtn:active { transform: translateY(3px); box-shadow: 0 1px 0 var(--wood-dark); }

/* ---------- Sağ panel ---------- */
#panel {
  position: absolute; top: 74px; right: 12px; width: 306px;
  max-height: calc(100% - 96px); overflow-y: auto;
  background: linear-gradient(#fffdf6, var(--parch));
  border: 4px solid var(--wood);
  border-radius: 18px;
  box-shadow: var(--shadow);
  padding: 14px;
  z-index: 15;
  transition: transform .2s ease, opacity .2s ease;
}
#panel.hidden { transform: translateX(120%); opacity: 0; pointer-events: none; }

.p-head { display: flex; align-items: flex-start; gap: 10px; margin-bottom: 10px; }
.p-emoji { font-size: 34px; line-height: 1; }
.p-title { flex: 1; }
.p-title h3 { font-size: 18px; }
.p-title .sub { font-size: 12px; opacity: .7; font-weight: 600; }
.closebtn {
  border: none; background: #e6d5b0; color: var(--wood-dark);
  width: 26px; height: 26px; border-radius: 50%; cursor: pointer; font-size: 13px; font-weight: 900;
}
.closebtn:hover { background: var(--red); color: #fff; }

.rows { display: flex; flex-direction: column; gap: 5px; margin: 10px 0; }
.row {
  display: flex; justify-content: space-between; gap: 8px;
  font-size: 13px; font-weight: 600;
  background: #fff8e6; border: 2px solid #e2cfa5; border-radius: 9px;
  padding: 5px 9px;
}
.row span:last-child { font-weight: 800; }

.bar { height: 10px; border-radius: 99px; background: #e2cfa5; overflow: hidden; margin-top: 4px; border: 2px solid #cbb182; }
.bar i { display: block; height: 100%; transition: width .3s; }
.bar.good i { background: var(--green); }
.bar.mid  i { background: var(--gold); }
.bar.bad  i { background: var(--red); }

.tag {
  display: inline-block; font-size: 11px; font-weight: 800;
  padding: 2px 8px; border-radius: 99px; color: #fff;
}
.tag.rented { background: var(--green-dark); }
.tag.idle   { background: var(--gold); color: #5c3f10; }
.tag.build  { background: var(--blue-dark); }
.tag.free   { background: #9c8563; }

.note { font-size: 12px; opacity: .75; line-height: 1.4; margin-top: 8px; font-weight: 600; }

/* ---------- Butonlar ---------- */
.btn {
  display: flex; align-items: center; justify-content: center; gap: 6px;
  border: none; cursor: pointer;
  font-family: inherit; font-weight: 800; font-size: 14px; color: #fff;
  background: linear-gradient(var(--green), var(--green-dark));
  padding: 10px 12px; border-radius: 12px;
  box-shadow: 0 4px 0 rgba(0,0,0,.25);
  transition: transform .08s, box-shadow .08s, filter .15s;
  width: 100%;
}
.btn + .btn { margin-top: 7px; }
.btn:hover:not(:disabled) { filter: brightness(1.07); }
.btn:active:not(:disabled) { transform: translateY(4px); box-shadow: 0 0 0 rgba(0,0,0,.25); }
.btn:disabled { filter: grayscale(.7) brightness(.9); cursor: not-allowed; opacity: .75; }
.btn.blue  { background: linear-gradient(var(--blue), var(--blue-dark)); }
.btn.red   { background: linear-gradient(var(--red), var(--red-dark)); }
.btn.gold  { background: linear-gradient(#f7c25a, #d99512); color: #4a3005; }
.btn.ghost { background: linear-gradient(#efe0bd, #d9c194); color: var(--wood-dark); }
.btn.wide  { margin-top: 8px; }
.btn small { font-weight: 700; opacity: .85; }

/* ---------- Overlay / katalog ---------- */
.overlay {
  position: absolute; inset: 0; z-index: 40;
  background: rgba(20, 12, 4, .5);
  display: flex; align-items: center; justify-content: center;
  padding: 20px;
  backdrop-filter: blur(2px);
}
.overlay.hidden { display: none; }

.sheet {
  width: min(880px, 100%); max-height: 88vh; overflow: hidden;
  background: linear-gradient(#fffdf6, var(--parch));
  border: 5px solid var(--wood); border-radius: 22px;
  box-shadow: var(--shadow);
  display: flex; flex-direction: column;
  animation: rise .22s ease;
}
.sheet.small { width: min(460px, 100%); }
@keyframes rise { from { transform: translateY(24px) scale(.97); opacity: 0 } }

.sheet-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 14px 18px; border-bottom: 4px solid #e2cfa5;
  background: linear-gradient(#ffefc9, #ffe4ad);
}
.sheet-head h2 { font-size: 19px; }

.catalog {
  display: grid; grid-template-columns: repeat(auto-fill, minmax(196px, 1fr));
  gap: 12px; padding: 16px; overflow-y: auto;
}
.card {
  background: #fff8e6; border: 3px solid #e2cfa5; border-radius: 16px;
  padding: 12px; cursor: pointer; text-align: center;
  transition: transform .12s, border-color .12s, box-shadow .12s;
  position: relative;
}
.card:hover:not(.locked):not(.poor) { transform: translateY(-4px); border-color: var(--green); box-shadow: 0 6px 0 rgba(0,0,0,.12); }
.card.locked, .card.poor { opacity: .55; cursor: not-allowed; }
.card .emoji { font-size: 40px; display: block; }
.card h4 { font-size: 15px; margin: 4px 0 6px; }
.card .price { font-size: 15px; font-weight: 900; color: #2f7a2a; }
.card.poor .price { color: var(--red-dark); }
.card .meta { font-size: 11.5px; font-weight: 700; opacity: .75; margin-top: 6px; line-height: 1.45; }
.card .lock {
  position: absolute; top: 8px; right: 8px;
  background: var(--wood); color: #fff; font-size: 10.5px; font-weight: 800;
  padding: 2px 7px; border-radius: 99px;
}
.card .kindtag {
  position: absolute; top: 8px; left: 8px;
  background: var(--blue-dark); color: #fff; font-size: 10px; font-weight: 800;
  padding: 2px 7px; border-radius: 99px;
}

/* ---------- Görev panosu ---------- */
#questBoard {
  position: absolute; left: 12px; top: 74px; width: 244px;
  background: linear-gradient(#fffdf6, var(--parch));
  border: 4px solid var(--wood); border-radius: 18px;
  box-shadow: var(--shadow);
  z-index: 14; overflow: hidden;
  transition: transform .2s ease;
}
#questBoard.collapsed #questList { display: none; }
.qb-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 8px 10px 8px 13px;
  background: linear-gradient(#ffefc9, #ffe4ad);
  border-bottom: 3px solid #e2cfa5;
}
.qb-head h3 { font-size: 14.5px; }
#questList { padding: 9px; display: flex; flex-direction: column; gap: 8px; }

.quest {
  background: #fff8e6; border: 3px solid #e2cfa5; border-radius: 12px;
  padding: 8px 10px; position: relative;
}
.quest.ready { border-color: var(--green); background: #f2fbe9; animation: glow 1.6s ease-in-out infinite; }
@keyframes glow {
  0%,100% { box-shadow: 0 0 0 rgba(110,194,74,0) }
  50%     { box-shadow: 0 0 14px rgba(110,194,74,.75) }
}
.quest .qtop { display: flex; gap: 7px; align-items: flex-start; }
.quest .qicon { font-size: 19px; line-height: 1.1; }
.quest .qtext { flex: 1; font-size: 12.5px; font-weight: 800; line-height: 1.3; }
.quest .qskip {
  border: none; background: #e6d5b0; color: var(--wood-dark);
  width: 20px; height: 20px; border-radius: 50%; cursor: pointer;
  font-size: 11px; font-weight: 900; flex: none;
}
.quest .qskip:hover { background: var(--gold); }
.quest .qprog { display: flex; justify-content: space-between; font-size: 11px; font-weight: 800; margin-top: 5px; }
.quest .qreward { font-size: 11.5px; font-weight: 800; color: #2f7a2a; margin-top: 4px; }
.quest .btn { padding: 6px; font-size: 12.5px; margin-top: 6px; }
.quest.empty { text-align: center; font-size: 12px; opacity: .7; font-weight: 700; }

/* ---------- Banka ---------- */
.bank-body { padding: 16px; overflow-y: auto; }
.bank-body .section {
  font-size: 15px; margin: 18px 0 8px;
  padding-top: 14px; border-top: 3px dashed #e2cfa5;
}
.scorecard {
  display: flex; gap: 14px; align-items: center;
  background: #fff8e6; border: 3px solid #e2cfa5; border-radius: 14px; padding: 12px;
}
.scoreleft { text-align: center; flex: none; width: 92px; }
.scorenum { font-size: 34px; font-weight: 900; line-height: 1; }
.scorelabel { font-size: 12px; font-weight: 800; opacity: .75; margin-top: 2px; }
.scoreright { flex: 1; min-width: 0; }
.scoreright .rows { margin: 8px 0 0; }

.loanform label {
  display: flex; align-items: center; gap: 10px;
  font-size: 13.5px; font-weight: 800; margin-bottom: 10px;
}
.loanform label span { width: 52px; flex: none; }
.loanform label b { width: 96px; text-align: right; flex: none; color: #2f7a2a; }
.loanform input[type="range"] {
  flex: 1; -webkit-appearance: none; appearance: none;
  height: 10px; border-radius: 99px; background: #e2cfa5;
  border: 2px solid #cbb182; cursor: pointer;
}
.loanform input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none; appearance: none;
  width: 20px; height: 20px; border-radius: 50%;
  background: linear-gradient(var(--gold), #d99512);
  border: 2px solid var(--wood); box-shadow: 0 2px 0 var(--wood-dark);
}
.loanform input[type="range"]::-moz-range-thumb {
  width: 18px; height: 18px; border-radius: 50%;
  background: var(--gold); border: 2px solid var(--wood);
}
.terms { display: flex; gap: 8px; margin-bottom: 10px; }
.terms button {
  flex: 1; border: 3px solid #e2cfa5; background: #fff8e6;
  border-radius: 11px; padding: 8px; cursor: pointer;
  font-family: inherit; font-weight: 800; font-size: 13px; color: var(--ink);
}
.terms button.active { border-color: var(--gold); background: #fff1cf; }
.quote {
  background: #fff8e6; border: 2px dashed #cbb182; border-radius: 11px;
  padding: 9px 12px; font-size: 12.5px; font-weight: 700; line-height: 1.6;
  margin-bottom: 10px;
}
.loans { display: flex; flex-direction: column; gap: 9px; }
.loan {
  background: #fff8e6; border: 3px solid #e2cfa5; border-radius: 13px; padding: 10px 12px;
}
.loan.late { border-color: var(--red); background: #fff0ee; }
.loan .ltop { display: flex; justify-content: space-between; font-size: 13.5px; font-weight: 900; }
.loan .lmeta { display: flex; justify-content: space-between; font-size: 11.5px; font-weight: 700; opacity: .8; margin: 3px 0 5px; }
.loan .btn { margin-top: 7px; padding: 7px; font-size: 12.5px; }
.loans .empty, .board .empty {
  text-align: center; padding: 14px; font-size: 13px; font-weight: 700; opacity: .7;
  background: #fff8e6; border: 3px dashed #e2cfa5; border-radius: 13px;
}

/* ---------- Sıralama ---------- */
.board { display: flex; flex-direction: column; gap: 6px; }
.brow {
  display: flex; align-items: center; gap: 9px;
  background: #fff8e6; border: 2px solid #e2cfa5; border-radius: 11px;
  padding: 7px 11px; font-size: 13px; font-weight: 700;
}
.brow.me { border-color: var(--gold); background: #fff3d8; font-weight: 900; }
.brow .rank { font-size: 15px; font-weight: 900; width: 22px; flex: none; }
.brow .bname { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.brow .bval { font-weight: 900; }
.brow .bplots { font-size: 11px; opacity: .7; }

/* ---------- Rakip teklifi ---------- */
.offercard { text-align: center; }
.offercard .oemoji { font-size: 44px; }
.offercard h4 { font-size: 17px; margin: 6px 0; }
.offercard .oprice { font-size: 26px; font-weight: 900; color: #2f7a2a; margin: 8px 0 2px; }
.offercard .osub { font-size: 12.5px; font-weight: 700; opacity: .75; margin-bottom: 12px; }

/* ---------- Ekip paneli ---------- */
.wagebox {
  margin-left: auto; margin-right: 12px;
  font-size: 13px; font-weight: 700;
  background: #fff8e6; border: 2px solid #e2cfa5; border-radius: 99px;
  padding: 4px 12px;
}
.wagebox b { color: #c0392b; }

.staff-body { padding: 16px; overflow-y: auto; }
.staff-body .section {
  font-size: 15px; margin: 18px 0 8px;
  padding-top: 14px; border-top: 3px dashed #e2cfa5;
}
.staff-body .catalog { padding: 0; }

.crew { display: grid; grid-template-columns: repeat(auto-fill, minmax(258px, 1fr)); gap: 10px; }
.crew .empty {
  grid-column: 1 / -1; text-align: center; padding: 18px;
  font-size: 13.5px; font-weight: 700; opacity: .7;
  background: #fff8e6; border: 3px dashed #e2cfa5; border-radius: 14px;
}

.worker {
  display: flex; gap: 10px; align-items: flex-start;
  background: #fff8e6; border: 3px solid #e2cfa5; border-radius: 14px; padding: 10px 12px;
}
.worker.idle { border-color: #ddc07a; background: #fff3d8; }
.worker.lowmorale { border-color: var(--red); }
.worker .face { font-size: 30px; line-height: 1; }
.worker .info { flex: 1; min-width: 0; }
.worker .who { font-size: 14.5px; font-weight: 900; }
.worker .role { font-size: 11.5px; font-weight: 700; opacity: .72; }
.worker .stars { font-size: 11px; letter-spacing: 1px; color: var(--gold); }
.worker .line {
  display: flex; justify-content: space-between; gap: 8px;
  font-size: 11.5px; font-weight: 700; margin-top: 4px;
}
.worker .fire {
  border: none; background: #e6d5b0; color: var(--wood-dark);
  border-radius: 9px; padding: 5px 9px; cursor: pointer;
  font-size: 11px; font-weight: 800; font-family: inherit; white-space: nowrap;
}
.worker .fire:hover { background: var(--red); color: #fff; }
.worker .bar { margin-top: 5px; }

.covbadge {
  display: inline-flex; align-items: center; gap: 3px;
  font-size: 11px; font-weight: 800;
  background: #e7f3dd; border: 2px solid #a9d18c; color: #3d6b28;
  border-radius: 99px; padding: 1px 7px; margin: 2px 3px 0 0;
}

.menu-body, .help-body { padding: 16px; overflow-y: auto; }
.help-body p { font-size: 13.5px; line-height: 1.55; margin-bottom: 9px; font-weight: 600; }
.help-body ul { margin: 0 0 10px 18px; font-size: 13.5px; line-height: 1.7; font-weight: 600; }
.stats { display: flex; flex-direction: column; gap: 5px; margin-bottom: 12px; }

/* ---------- Ses kaydırıcıları ---------- */
.sliders { display: flex; flex-direction: column; gap: 9px; margin-bottom: 12px; }
.sliders label {
  display: flex; align-items: center; gap: 10px;
  font-size: 13.5px; font-weight: 800;
  background: #fff8e6; border: 2px solid #e2cfa5; border-radius: 10px;
  padding: 7px 11px;
}
.sliders label span { width: 74px; flex: none; }
.sliders input[type="range"] {
  flex: 1; -webkit-appearance: none; appearance: none;
  height: 10px; border-radius: 99px; background: #e2cfa5;
  border: 2px solid #cbb182; cursor: pointer;
}
.sliders input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none; appearance: none;
  width: 20px; height: 20px; border-radius: 50%;
  background: linear-gradient(var(--green), var(--green-dark));
  border: 2px solid var(--wood); box-shadow: 0 2px 0 var(--wood-dark);
}
.sliders input[type="range"]::-moz-range-thumb {
  width: 18px; height: 18px; border-radius: 50%;
  background: var(--green); border: 2px solid var(--wood);
}
.iconbtn.off { filter: grayscale(1) brightness(.92); }

/* ---------- Toast ---------- */
#toasts {
  position: absolute; bottom: 16px; left: 50%; transform: translateX(-50%);
  display: flex; flex-direction: column-reverse; gap: 8px; align-items: center;
  z-index: 30; pointer-events: none; width: min(560px, 92%);
}
.toast {
  background: linear-gradient(#fffaf0, var(--parch-2));
  border: 3px solid var(--wood); border-left-width: 9px;
  border-radius: 13px; padding: 9px 15px;
  font-size: 13.5px; font-weight: 700;
  box-shadow: 0 5px 0 var(--wood-dark), 0 10px 18px rgba(0,0,0,.25);
  animation: slideup .28s ease;
}
.toast.good { border-left-color: var(--green); }
.toast.bad  { border-left-color: var(--red); }
.toast.info { border-left-color: var(--blue); }
.toast.gold { border-left-color: var(--gold); }
.toast.out  { animation: fadeout .35s ease forwards; }
@keyframes slideup { from { transform: translateY(18px); opacity: 0 } }
@keyframes fadeout { to { transform: translateY(-8px); opacity: 0 } }

/* ---------- Uçan yazılar ---------- */
#floats { position: absolute; inset: 0; pointer-events: none; z-index: 25; overflow: hidden; }
.float {
  position: absolute; transform: translate(-50%, -50%);
  font-weight: 900; font-size: 17px;
  color: #2f7a2a; text-shadow: 0 2px 0 #fff, 0 0 8px rgba(255,255,255,.9);
  animation: rise2 1.5s ease-out forwards;
  white-space: nowrap;
}
.float.bad { color: #c0392b; }
.float.info { color: #1f6ea8; }
@keyframes rise2 { to { transform: translate(-50%, -110px); opacity: 0 } }

/* ---------- Yükleniyor ---------- */
#loading {
  position: absolute; inset: 0; z-index: 90;
  background: #7fc4e8; display: flex; flex-direction: column;
  align-items: center; justify-content: center; gap: 16px;
  font-weight: 800; color: #fff; text-shadow: 0 2px 4px rgba(0,0,0,.3);
  transition: opacity .4s;
}
#loading.gone { opacity: 0; pointer-events: none; }
.spinner {
  width: 46px; height: 46px; border-radius: 50%;
  border: 6px solid rgba(255,255,255,.35); border-top-color: #fff;
  animation: spin 1s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg) } }

/* ---------- Mobil ---------- */
@media (max-width: 720px) {
  .chip { font-size: 13px; padding: 5px 11px 5px 8px; }
  #panel { width: auto; left: 10px; right: 10px; top: auto; bottom: 10px; max-height: 52%; }
  #panel.hidden { transform: translateY(120%); }
  #toasts { bottom: auto; top: 120px; }
  #questBoard { width: 190px; top: auto; bottom: 10px; }
  #questBoard.collapsed { width: 150px; }
  .scorecard { flex-direction: column; }
  .scoreleft { width: auto; }
}

/* dar ekranda görev panosu sağ paneli ezmesin */
@media (max-height: 620px) {
  #questBoard { max-height: calc(100% - 90px); overflow-y: auto; }
}
