/* ============ עיר האנרגיה ============ */
* { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --sea: #4a9d97;
  --sea-dark: #3c8a85;
  --deep: #17454e;
  --deep2: #1d565f;
  --card: #ffffff;
  --ink: #2b3a4a;
  --accent: #ff8a3c;
  --good: #3fae4c;
  --bad: #e2574c;
  --gold: #f2b230;
}

html, body { height: 100%; }

body {
  font-family: "Varela Round", "Segoe UI", "Arial Hebrew", Arial, sans-serif;
  color: var(--ink);
  background-color: var(--sea);
  background-image:
    url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='260' height='260'%3E%3Cg stroke='%23ffffff' stroke-opacity='.13' stroke-width='3' stroke-linecap='round' fill='none'%3E%3Cpath d='M24 44q11-9 22 0t22 0'/%3E%3Cpath d='M150 100q11-9 22 0t22 0'/%3E%3Cpath d='M60 180q11-9 22 0t22 0'/%3E%3Cpath d='M190 224q9-7 18 0'/%3E%3Cpath d='M10 240q9-7 18 0'/%3E%3C/g%3E%3Cg fill='%23ffffff' fill-opacity='.07'%3E%3Ccircle cx='110' cy='26' r='2.5'/%3E%3Ccircle cx='34' cy='120' r='2'/%3E%3Ccircle cx='226' cy='160' r='2.5'/%3E%3C/g%3E%3C/svg%3E"),
    linear-gradient(180deg, #55aaa3 0%, #4a9d97 45%, #3d8b85 100%);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  user-select: none;
}

/* ============ HEADER ============ */
#topbar {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 8px 16px;
  background: rgba(17,55,63,.45);
  backdrop-filter: blur(6px);
  box-shadow: 0 2px 12px rgba(10,35,40,.25);
  z-index: 30;
}

.brand {
  font-size: 20px;
  font-weight: 800;
  color: #fff;
  text-shadow: 0 2px 6px rgba(10,35,40,.4);
  white-space: nowrap;
}

#meters {
  display: flex;
  gap: 10px;
  flex: 1;
  justify-content: center;
}

.meter {
  background: var(--deep2);
  border: 1.5px solid rgba(255,255,255,.22);
  color: #fff;
  border-radius: 16px;
  padding: 6px 12px;
  min-width: 152px;
  box-shadow: 0 3px 10px rgba(10,35,40,.35);
  transition: transform .2s;
}
.meter.pulse { animation: meterPulse .5s; }
@keyframes meterPulse {
  0%,100% { transform: scale(1); }
  50% { transform: scale(1.12); }
}

.m-top {
  display: flex;
  align-items: center;
  gap: 5px;
  font-size: 13px;
  font-weight: 700;
  margin-bottom: 4px;
}
.m-icon { font-size: 16px; }
.m-val { margin-inline-start: auto; font-size: 14px; }

.m-bar {
  height: 9px;
  background: rgba(255,255,255,.22);
  border-radius: 6px;
  overflow: hidden;
}
.m-fill {
  height: 100%;
  width: 50%;
  border-radius: 6px;
  background: linear-gradient(90deg, #58c968, #2f9e46);
  transition: width .7s ease, background .4s;
}
.m-fill.warn { background: linear-gradient(90deg, #ffc44d, #f2a021); }
.m-fill.danger { background: linear-gradient(90deg, #ff7b6e, #d8402f); }

#pop-badge {
  background: var(--deep2);
  border: 1.5px solid rgba(255,255,255,.25);
  border-radius: 999px;
  padding: 8px 14px;
  font-size: 13.5px;
  font-weight: 700;
  color: #fff;
  white-space: nowrap;
  box-shadow: 0 3px 10px rgba(10,35,40,.35);
  display: flex;
  align-items: center;
  gap: 6px;
}
#pop-badge b { font-weight: 800; }
.pb-sep { opacity: .45; }

#btn-sound {
  border: 1.5px solid rgba(255,255,255,.35);
  background: var(--deep2);
  border-radius: 50%;
  width: 40px;
  height: 40px;
  font-size: 17px;
  cursor: pointer;
  box-shadow: 0 3px 10px rgba(10,35,40,.35);
  transition: transform .1s;
}
#btn-sound:hover { transform: scale(1.08); }

#wallet {
  background: linear-gradient(135deg, #ffe9a8, #ffd257);
  border: 2px solid #e0a92e;
  border-radius: 12px;
  padding: 7px 14px;
  font-size: 18px;
  font-weight: 800;
  color: #7a5410;
  white-space: nowrap;
  box-shadow: 0 2px 6px rgba(122,84,16,.25);
}

/* ============ LAYOUT ============ */
#layout {
  flex: 1;
  display: flex;
  min-height: 0;
  position: relative;
}

/* ============ SHOP ============ */
#shop {
  width: 300px;
  background: rgba(255,255,255,.85);
  backdrop-filter: blur(6px);
  padding: 12px;
  overflow-y: auto;
  box-shadow: 2px 0 12px rgba(43,58,74,.12);
  z-index: 20;
  display: flex;
  flex-direction: column;
  gap: 8px;
  transition: margin .3s;
}
#shop.hidden { display: none; }

#shop h2 { font-size: 18px; color: #1d6fa5; }
#shop-hint { font-size: 12px; color: #667; }

/* חנות דו־טורית: פס קטגוריות קבוע + מבני הקטגוריה לצדו */
.shop-flex {
  display: flex;
  gap: 8px;
  align-items: flex-start;
}
.cat-rail {
  display: flex;
  flex-direction: column;
  gap: 6px;
  width: 72px;
  flex-shrink: 0;
  position: sticky;
  top: 0;
}
.cat-tab {
  background: #fff;
  border: 2px solid #dde5ec;
  border-radius: 14px;
  padding: 7px 2px 5px;
  text-align: center;
  cursor: pointer;
  font-size: 11px;
  font-weight: 800;
  color: #556;
  transition: border-color .15s, background .15s;
}
.cat-tab:hover { border-color: var(--accent); }
.cat-tab.active {
  border-color: var(--accent);
  background: #fff7ef;
  color: #b35a1a;
  box-shadow: 0 0 0 2px rgba(255,138,60,.18);
}
.cat-tab svg { width: 40px; height: 40px; display: block; margin: 0 auto 2px; }

.item-pane {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

/* כרטיס מבנה */
.shop-sq {
  position: relative;
  background: #fff;
  border: 2px solid #dde5ec;
  border-radius: 14px;
  padding: 8px 8px 7px;
  text-align: center;
  cursor: pointer;
  transition: border-color .15s, transform .1s, box-shadow .15s;
}
.shop-sq:hover { border-color: var(--accent); transform: translateY(-1px); }
.shop-sq.selected {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(255,138,60,.25);
  background: #fff7ef;
}
.shop-sq.locked, .shop-sq.poor { opacity: .55; cursor: not-allowed; }
.shop-sq.locked:hover, .shop-sq.poor:hover { border-color: #dde5ec; transform: none; }
.shop-sq svg { width: 52px; height: 52px; }
.sq-name { font-size: 13px; font-weight: 800; margin-bottom: 5px; }

/* המחיר — סרט בפינה */
.sq-ribbon {
  position: absolute;
  top: 7px;
  inset-inline-start: 7px;
  background: linear-gradient(135deg, #fff3d1, #ffe9a8);
  border: 1px solid #e8c877;
  border-radius: 9px;
  padding: 1px 8px;
  font-size: 11.5px;
  font-weight: 800;
  color: #9a6d12;
}

/* צ'יפים של מדדים — סדר קבוע, 3 בשורה */
.sq-chips {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 3px;
}
.chip {
  font-size: 11px;
  font-weight: 800;
  border-radius: 8px;
  padding: 2.5px 2px;
  white-space: nowrap;
}
.chip.pos { background: #e8f7e8; color: #2f7f38; }
.chip.neg { background: #fdeae8; color: #c0392b; }
.chip.zero { background: #f2f5f8; color: #b6bec7; }

.shop-item {
  display: flex;
  align-items: center;
  gap: 8px;
  background: #fff;
  border: 2px solid #dde5ec;
  border-radius: 12px;
  padding: 6px 8px;
  cursor: pointer;
  transition: border-color .15s, transform .1s, box-shadow .15s;
  position: relative;
}
.shop-item:hover { border-color: var(--accent); transform: translateY(-1px); }
.shop-item.selected {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(255,138,60,.25);
  background: #fff7ef;
}
.shop-item.locked, .shop-item.poor { opacity: .55; cursor: not-allowed; }
.shop-item.locked:hover, .shop-item.poor:hover { border-color: #dde5ec; transform: none; }

.shop-item svg { width: 44px; height: 44px; flex-shrink: 0; }

.si-info { flex: 1; min-width: 0; }
.si-name { font-size: 13px; font-weight: 700; }
.si-cost { font-size: 12px; color: #9a6d12; font-weight: 700; }
.si-fx { font-size: 11px; display: flex; gap: 6px; flex-wrap: wrap; margin-top: 2px; }
.si-fx b.plus { color: var(--good); }
.si-fx b.minus { color: var(--bad); }
.si-lock {
  position: absolute;
  inset-inline-end: 8px;
  top: 6px;
  font-size: 11px;
  background: #34404d;
  color: #fff;
  border-radius: 8px;
  padding: 2px 7px;
}

.shop-actions {
  position: sticky;
  bottom: -12px;
  margin-top: auto;
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 10px 0 12px;
  background: rgba(255,255,255,.94);
  backdrop-filter: blur(4px);
  box-shadow: 0 -6px 12px rgba(43,58,74,.08);
  z-index: 5;
}

.tool-btn {
  border: 2px solid #c4cfda;
  background: #fff;
  border-radius: 12px;
  padding: 8px;
  font-size: 14px;
  font-weight: 700;
  cursor: pointer;
  font-family: inherit;
  color: var(--ink);
}
.tool-btn.selected {
  border-color: var(--bad);
  background: #ffefed;
  box-shadow: 0 0 0 3px rgba(226,87,76,.2);
}

/* ============ BOARD ============ */
#board-wrap {
  flex: 1;
  position: relative;
  overflow: hidden;
  display: flex;
  align-items: center;
  justify-content: center;
}

#board {
  position: relative;
}

.tile {
  position: absolute;
  width: 150px;
  height: 180px;
  pointer-events: none; /* רק המעוין עצמו לחיץ — מונע חטיפת קליקים בין משבצות */
}
.tile svg.ground { position: absolute; bottom: 0; left: 0; width: 150px; height: 75px; pointer-events: none; }
.tile .g-top { pointer-events: auto; }
.tile.hasb .g-top, .tile.placeable .g-top, .tile.demolish .g-top { cursor: pointer; }
.tile svg.bld {
  position: absolute;
  bottom: 12px;
  left: 25px;
  width: 100px;
  height: 110px;
  pointer-events: none;
  filter: drop-shadow(0 3px 3px rgba(30,50,40,.25));
  transition: transform .2s;
}
.tile.placeable .g-top { fill: #d8f0b8; }
.tile.placeable:hover .g-top { fill: #ffe9a8; }
.tile.demolish:hover .g-top { fill: #ffc4bd; }
.tile.hasb:hover svg.bld { transform: translateY(-3px); }
.tile.pop svg.bld { animation: popIn .45s cubic-bezier(.5,1.6,.5,1); }
@keyframes popIn {
  0% { transform: scale(.2) translateY(30px); }
  100% { transform: scale(1) translateY(0); }
}

/* אנימציות מבנים */
.smoke { animation: smokeFloat 2.4s ease-in-out infinite; }
.smoke.s2 { animation-delay: 1.2s; }
@keyframes smokeFloat {
  0% { transform: translateY(0); opacity: 1; }
  70% { opacity: .9; }
  100% { transform: translateY(-9px); opacity: 0; }
}
.rotor { animation: spin 3.2s linear infinite; }
.rotor.r2 { animation-duration: 4.1s; }
.wheel { animation: spin 10s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.flame { animation: flick .5s ease-in-out infinite alternate; transform-origin: 26px 36px; }
@keyframes flick { to { transform: scale(1.15); } }

/* אייקונים מרחפים */
.fly {
  position: fixed;
  z-index: 100;
  font-size: 22px;
  font-weight: 800;
  pointer-events: none;
  transition: transform 1.1s cubic-bezier(.4,.1,.6,1), opacity 1.1s;
  text-shadow: 0 1px 3px rgba(0,0,0,.25);
  display: flex;
  align-items: center;
  gap: 2px;
}
.fly small { font-size: 13px; background: rgba(255,255,255,.9); border-radius: 8px; padding: 0 4px; }
.fly small.plus { color: var(--good); }
.fly small.minus { color: var(--bad); }

/* כרטיס מידע על מבנה */
#tile-info {
  position: fixed;
  z-index: 80;
  width: 240px;
  background: var(--card);
  border-radius: 16px;
  padding: 12px 14px;
  box-shadow: 0 10px 30px rgba(20,40,60,.35);
  text-align: right;
  animation: modalIn .25s cubic-bezier(.4,1.4,.6,1);
}
.ti-head {
  display: flex;
  align-items: center;
  gap: 8px;
  font-weight: 800;
  font-size: 15px;
}
.ti-head svg { width: 42px; height: 42px; flex-shrink: 0; }
.ti-close {
  margin-inline-start: auto;
  border: none;
  background: #eef2f6;
  border-radius: 50%;
  width: 26px;
  height: 26px;
  cursor: pointer;
  font-weight: 700;
  font-family: inherit;
  color: #556;
}
.ti-close:hover { background: #ffdcd8; }
.ti-sub { font-size: 12px; color: #667; margin: 8px 0 6px; font-weight: 700; }
.ti-fx {
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 4px;
  font-size: 13px;
}
.ti-fx li {
  display: flex;
  justify-content: space-between;
  background: #f4f8fb;
  border-radius: 9px;
  padding: 5px 9px;
  font-weight: 700;
}
.ti-fx b.plus { color: var(--good); }
.ti-fx b.minus { color: var(--bad); }
.ti-cost { margin-top: 9px; font-size: 12px; color: #9a6d12; font-weight: 700; }

/* עננים */
.cloud {
  position: absolute;
  background: rgba(255,255,255,.85);
  border-radius: 999px;
  pointer-events: none;
  z-index: 25;
  filter: blur(1px);
  box-shadow: 22px 8px 0 -4px rgba(255,255,255,.8), -22px 10px 0 -6px rgba(255,255,255,.75);
  animation: drift linear infinite;
}
.cloud.c1 { width: 90px; height: 26px; top: 7%; animation-duration: 75s; }
.cloud.c2 { width: 60px; height: 19px; top: 18%; animation-duration: 105s; animation-delay: -40s; }
.cloud.c3 { width: 110px; height: 30px; top: 12%; animation-duration: 90s; animation-delay: -70s; opacity: .6; }
@keyframes drift {
  from { right: -140px; }
  to { right: calc(100% + 140px); }
}

/* שקיעה הדרגתית — מתחזקת עם השנים */
#daylight {
  position: absolute;
  inset: 0;
  pointer-events: none;
  z-index: 26;
  opacity: 0;
  transition: opacity 1.2s ease;
  background: linear-gradient(180deg,
    rgba(255,152,64,.42) 0%,
    rgba(240,100,90,.30) 45%,
    rgba(84,48,130,.42) 100%);
}

/* סירת מפרש בים */
.boat {
  position: absolute;
  width: 62px;
  top: 74%;
  z-index: 0;
  pointer-events: none;
  animation: sail 130s linear infinite;
}
.boat svg { animation: bob 3.2s ease-in-out infinite alternate; }
@keyframes sail {
  from { left: -90px; }
  to { left: calc(100% + 90px); }
}
@keyframes bob {
  from { transform: rotate(-2.5deg) translateY(0); }
  to { transform: rotate(2.5deg) translateY(-3px); }
}

/* טוסטים */
#toasts {
  position: absolute;
  top: 14px;
  right: 50%;
  transform: translateX(50%);
  display: flex;
  flex-direction: column;
  gap: 6px;
  z-index: 40;
  pointer-events: none;
}
.toast {
  background: rgba(29,58,74,.92);
  color: #fff;
  border-radius: 14px;
  padding: 9px 18px;
  font-size: 15px;
  font-weight: 700;
  box-shadow: 0 4px 14px rgba(0,0,0,.25);
  animation: toastIn .3s, toastOut .4s 2.8s forwards;
}
.toast.unlock { background: linear-gradient(135deg, #7c5cbf, #4d3a8f); }
@keyframes toastIn { from { transform: translateY(-16px); opacity: 0; } }
@keyframes toastOut { to { transform: translateY(-14px); opacity: 0; } }

/* ============ TIMELINE ============ */
#timeline-bar {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 10px 18px;
  background: rgba(17,55,63,.45);
  backdrop-filter: blur(6px);
  box-shadow: 0 -2px 12px rgba(10,35,40,.25);
  z-index: 30;
}

#timeline { flex: 1; }

#tl-track {
  display: flex;
  align-items: center;
  gap: 3px;
}
.tl-dot {
  flex: 1;
  height: 10px;
  border-radius: 6px;
  background: rgba(255,255,255,.55);
  position: relative;
  transition: background .3s;
}
.tl-dot.build5 { height: 16px; background: rgba(255,255,255,.75); }
.tl-dot.build5::after {
  content: "🔨";
  position: absolute;
  top: -18px;
  left: 50%;
  transform: translateX(-50%);
  font-size: 11px;
}
.tl-dot.done { background: linear-gradient(90deg, #58c968, #2f9e46); }
.tl-dot.current { background: var(--accent); box-shadow: 0 0 0 3px rgba(255,138,60,.35); }

#year-badge {
  font-size: 16px;
  font-weight: 800;
  background: var(--deep);
  border: 1.5px solid rgba(255,255,255,.25);
  color: #fff;
  border-radius: 999px;
  padding: 8px 16px;
  white-space: nowrap;
}

/* ============ BUTTONS ============ */
.cta {
  border: none;
  border-radius: 14px;
  background: linear-gradient(180deg, #ffa15c, #ff8a3c);
  color: #fff;
  font-size: 15px;
  font-weight: 800;
  font-family: inherit;
  padding: 10px 18px;
  cursor: pointer;
  box-shadow: 0 3px 0 #d96a20, 0 5px 10px rgba(217,106,32,.3);
  transition: transform .1s, box-shadow .1s;
}
.cta:hover { transform: translateY(-1px); }
.cta:active { transform: translateY(2px); box-shadow: 0 1px 0 #d96a20; }
.cta.big { font-size: 18px; padding: 12px 26px; }
.cta:disabled { opacity: .5; cursor: not-allowed; }

.hidden { display: none !important; }

/* ============ MODALS ============ */
#overlay {
  position: fixed;
  inset: 0;
  background: rgba(20,40,60,.55);
  backdrop-filter: blur(3px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 90;
}

.modal {
  background: var(--card);
  border-radius: 22px;
  padding: 28px 32px;
  max-width: 560px;
  width: calc(100% - 40px);
  max-height: 86vh;
  overflow-y: auto;
  text-align: center;
  box-shadow: 0 14px 50px rgba(0,0,0,.35);
  animation: modalIn .35s cubic-bezier(.4,1.4,.6,1);
}
@keyframes modalIn { from { transform: scale(.85) translateY(20px); opacity: 0; } }

.modal h1 { font-size: 30px; color: #1d6fa5; margin-bottom: 12px; }
.modal h2 { font-size: 22px; margin: 8px 0; }
.modal .intro { font-size: 15px; line-height: 1.8; margin-bottom: 16px; }
.choose-label { font-weight: 700; margin-bottom: 10px; }
.size-btns { display: flex; gap: 14px; justify-content: center; }

.decision-tag {
  display: inline-block;
  background: #f2e8ff;
  color: #6a3fb5;
  border-radius: 10px;
  padding: 4px 12px;
  font-size: 13px;
  font-weight: 800;
  margin-bottom: 6px;
}
#dec-desc { font-size: 15px; line-height: 1.7; color: #445; margin-bottom: 16px; }

#dec-illu {
  width: 96px;
  height: 96px;
  margin: 10px auto 2px;
  border-radius: 50%;
  background: radial-gradient(circle at 32% 28%, #fef4dd, #ffd9a8);
  border: 3px solid #f2b25e;
  box-shadow: 0 6px 18px rgba(242,178,94,.4);
  font-size: 52px;
  line-height: 92px;
  text-align: center;
  cursor: grab;
  user-select: none;
  touch-action: none;
  transition: transform .18s ease;
}
#dec-illu:active { cursor: grabbing; }

#dec-options {
  display: flex;
  gap: 12px;
  align-items: stretch;
}
.dec-opt {
  flex: 1;
  border: 2px solid #dde5ec;
  background: #fbfdff;
  border-radius: 16px;
  padding: 14px 10px;
  cursor: pointer;
  font-family: inherit;
  font-size: 15px;
  text-align: center;
  transition: border-color .15s, transform .12s, box-shadow .15s;
}
.dec-opt:first-child { background: #f3fbf3; border-color: #cde8cd; }
.dec-opt:hover { border-color: var(--accent); transform: translateY(-2px); }
.dec-opt.lean {
  border-color: var(--accent);
  transform: translateY(-4px) scale(1.05);
  box-shadow: 0 8px 20px rgba(255,138,60,.3);
}
.dec-opt .do-title { font-weight: 800; margin-bottom: 6px; font-size: 16px; }
.dec-opt .do-fx { font-size: 13px; display: flex; gap: 8px; flex-wrap: wrap; justify-content: center; }
.do-fx b.plus { color: var(--good); }
.do-fx b.minus { color: var(--bad); }

.dec-hint { font-size: 11.5px; color: #99a; margin-top: 12px; }

/* מסך סיום */
#end-stats {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 8px;
  margin: 16px 0;
}
.end-stat {
  background: #f4f8fb;
  border-radius: 12px;
  padding: 10px;
  font-size: 14px;
  font-weight: 700;
}
.end-stat .es-val { font-size: 20px; }

#end-score {
  font-size: 24px;
  font-weight: 900;
  color: var(--gold);
  background: #34404d;
  border-radius: 16px;
  padding: 14px;
  margin-bottom: 18px;
}
#end-score .stars { font-size: 30px; display: block; margin-top: 4px; }

/* ============ RESPONSIVE ============ */
@media (max-width: 900px) {
  #shop { width: 250px; }
  .cat-rail { width: 58px; }
  .cat-tab svg { width: 30px; height: 30px; }
}

/* מובייל: מדדים 2×2 */
@media (max-width: 700px) {
  #topbar { flex-wrap: wrap; gap: 8px; }
  .brand { font-size: 16px; }
  #meters {
    order: 5;
    width: 100%;
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 6px;
  }
  .meter { min-width: 0; }
  #dec-options { flex-direction: column; }
  #dec-illu { width: 76px; height: 76px; font-size: 40px; line-height: 72px; }
}
