* { box-sizing: border-box; }
:root { --fs: 22px; --lh: 33px; }
html, body { height: 100%; margin: 0; }
body { height: 100dvh; }
body { display: flex; flex-direction: column; font-family: 'Trebuchet MS', 'Segoe UI', system-ui, sans-serif; background: #e9eef0; }

.banner {
  background: #2A3335; color: #fff; padding: 8px 14px;
  display: flex; align-items: center; gap: 12px; flex-wrap: wrap;
  box-shadow: 0 4px 8px rgba(0,0,0,.15); flex-shrink: 0; z-index: 10;
}

.logo { 
  margin: 0; 
  font-family: 'Trebuchet MS', 'Segoe UI', system-ui, sans-serif;
  font-size: 1.35rem; 
  white-space: nowrap; 
}

#levels, .levels-bar {
  display: flex; gap: 5px; flex-wrap: wrap; flex: 1;
  justify-content: center; align-items: center;
  min-width: 0;
}
.lvl {
  width: 38px; height: 38px; border-radius: 10px; border: none;
  font-weight: 800; font-size: 1rem; font-family: inherit;
  background: #4b5a5d; color: #fff;
  box-shadow: inset 0 -3px 0 rgba(0,0,0,.3); cursor: pointer;
  transition: transform .12s, filter .15s;
}
.lvl:hover { filter: brightness(1.2); transform: translateY(-1px); }
.lvl.done { background: #4CAF50; }
.lvl.cur { background: #DA498D; box-shadow: 0 0 0 3px #FFD23F; }
.lvl:disabled { opacity: .35; cursor: not-allowed; }
.actions { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.banner-button { padding: 9px 18px; font-size: 1.05rem; font-weight: 800; font-family: inherit; border-radius: 30px; border: none; color: #fff; cursor: pointer; box-shadow: inset 0 -4px 0 rgba(0,0,0,.3); transition: filter .2s; }
.banner-button:hover { filter: brightness(1.15); }
.lang-toggle { background: #29b6f6; min-width: 56px; padding: 9px 14px; letter-spacing: 1px; }
#stopBtn.pulse { animation: stopPulse .5s ease-in-out infinite; }
@keyframes stopPulse {
  0%, 100% { transform: scale(1); box-shadow: inset 0 -4px 0 rgba(0,0,0,.3), 0 0 0 0 rgba(229,57,53,.5); }
  50% { transform: scale(1.08); box-shadow: inset 0 -4px 0 rgba(0,0,0,.3), 0 0 0 10px rgba(229,57,53,0); }
}

.contentwrapper { flex: 1; display: flex; gap: 0; padding: 0; min-height: 0; }
.code-section, .visual-section { flex: 1 1 0; min-width: 0; display: flex; flex-direction: column; }
.code-section { background: #000; padding: 12px; }
.visual-section { position: relative; padding: 0; overflow: hidden; background: #c8e6c9; container-type: size; }

#editor { flex: 1; min-height: 170px; overflow: auto; display: flex; background: #000; border-radius: 15px; padding: 10px 0; font: var(--fs)/var(--lh) Consolas, 'Courier New', monospace; color: #ddd; cursor: text; }
#gutter { flex: 0 0 auto; position: sticky; left: 0; z-index: 2; background: #000; padding: 0 12px 0 14px; text-align: right; color: #777; user-select: none; }
#gutter div { height: var(--lh); }
#gutter .run { color: #fff; }
#stack { position: relative; flex: 1 0 auto; }
#hl, #code { margin: 0; padding: 0 48px 0 0; font: inherit; white-space: pre; tab-size: 4; }
#code { position: absolute; inset: 0; width: 100%; height: 100%; border: 0; outline: 0; resize: none; overflow: hidden; background: transparent; color: transparent; caret-color: #fff; }
#code::placeholder { color: #666; }
#code::selection { background: rgba(255,255,255,.25); }
.ln { min-height: var(--lh); }
.ln.cur { background: #141414; }
.caret { display: inline-block; width: 2px; height: calc(var(--lh) * .8); margin-right: -2px; vertical-align: middle; background: #fff; animation: blink 1s steps(1) infinite; }
.ln.run { background: #555; } .ln.pend { background: #333; }
.ln.err { background: #5a1a1a; box-shadow: inset 3px 0 #ff4d4d; }
.r { color: #1a9aa8; } .m { color: #7fc41a; } .a { color: #e0245e; } .k { color: #FFB200; } .p { color: #8a8a8a; } .c { color: #6a7a7a; }

#pad { position: relative; min-height: 78px; margin: 8px 0 14px; padding: 10px 0; border-radius: 16px; }
.pad-inner { position: absolute; top: 50%; transform: translate(-50%, -50%); display: flex; flex-wrap: wrap; gap: 8px; max-width: 100%; justify-content: center; }
#pad.on::after { content: ''; position: absolute; left: var(--ax); bottom: -12px; margin-left: -14px; border: 14px solid transparent; border-bottom: 0; border-top-color: var(--c); }
.pbtn { height: 52px; min-width: 58px; padding: 0 22px; font-size: 1.3rem; font-weight: 800; font-family: inherit; color: var(--c); background: #fff; border: none; border-radius: 30px; box-shadow: inset 0 -4px 0 rgba(0,0,0,.18); cursor: pointer; }
.pbtn:active { transform: scale(.92); box-shadow: none; }

.lower-section { display: flex; flex-wrap: wrap; gap: 10px; }
.action-button { padding: 13px 22px; font-size: 1.2rem; font-weight: 800; font-family: inherit; border-radius: 32px; border: none; color: #fff; cursor: pointer; box-shadow: inset 0 -4px 0 rgba(0,0,0,.3); transition: transform .15s, filter .2s; }
.action-button:hover:not(:disabled) { filter: brightness(1.15); }
.action-button:disabled { opacity: .3; filter: grayscale(1); cursor: not-allowed; }
.action-button.sel { transform: translateY(-3px); box-shadow: inset 0 -4px 0 rgba(0,0,0,.3), 0 4px 0 rgba(0,0,0,.25); }

/* Sahne: kare kare yeşil ızgara + kaya + bayrak */
#board {
  position: absolute; inset: 0; width: 100%; height: 100%;
  display: grid; grid-template: repeat(7, minmax(0, 1fr)) / repeat(7, minmax(0, 1fr));
  container-type: size; overflow: hidden; background: #6dbf5a;
  gap: 0;
  border: 3px solid #4a8c3c;
}
.cell {
  display: flex; align-items: center; justify-content: center;
  font-size: 9cqmin; position: relative; z-index: 1;
  border: 1px solid rgba(0,0,0,.08);
  box-sizing: border-box; min-width: 0; min-height: 0; overflow: hidden;
}
.g0 { background: #93d874; }
.g1 { background: #7ec85c; }

.it { filter: drop-shadow(0 3px 4px rgba(0,0,0,.4)); display: inline-block; font-size: 1.1em; line-height: 1; }
.it.rock { font-size: 1.15em; animation: none; }
.it.flag { font-size: 1.2em; animation: flagWave 1.2s ease-in-out infinite; transform-origin: 20% 90%; }
.it.hit { animation: wob .18s 3; }
.fl { font-size: 3.2cqmin; opacity: .7; animation: sway 3s ease-in-out infinite; }

#car { position: absolute; width: 14.2857%; height: 14.2857%; z-index: 4; transition: left .38s linear, top .38s linear; }
#car svg { width: 100%; height: 100%; transition: transform .3s; filter: drop-shadow(0 5px 5px rgba(0,0,0,.4)); }
#car.nt, #car.nt svg { transition: none; }
#car.shake { animation: sh .15s 3; }
#car.drive { animation: drive .38s linear infinite; }
#car.in { animation: carin .45s ease-out both; }
#car.win { animation: cwin .7s ease-in-out 2; }
@keyframes sh { 25% { translate: -6px 0; } 75% { translate: 6px 0; } }
@keyframes coneWobble { 0%, 100% { transform: rotate(-4deg); } 50% { transform: rotate(4deg); } }
@keyframes flagWave { 0%, 100% { transform: rotate(-9deg); } 50% { transform: rotate(9deg); } }
@keyframes sway { 0%, 100% { transform: rotate(-6deg); } 50% { transform: rotate(6deg); } }

.traffic-light {
  position: absolute; top: 12px; right: 14px; z-index: 6;
  width: 36px; padding: 8px 6px; background: #263238; border-radius: 10px;
  display: flex; flex-direction: column; align-items: center; gap: 6px;
  box-shadow: 0 4px 12px rgba(0,0,0,.4), inset 0 0 0 2px rgba(255,255,255,.08);
}
.tl-lamp { width: 22px; height: 22px; border-radius: 50%; background: #37474f; box-shadow: inset 0 2px 4px rgba(0,0,0,.4); transition: background .25s, box-shadow .25s; }
.traffic-light.red .tl-lamp.red { background: #e53935; box-shadow: 0 0 14px #e53935, 0 0 28px rgba(229,57,53,.5); }
.traffic-light.yellow .tl-lamp.yellow { background: #fdd835; box-shadow: 0 0 14px #fdd835, 0 0 28px rgba(253,216,53,.5); }
.traffic-light.green .tl-lamp.green { background: #43a047; box-shadow: 0 0 14px #43a047, 0 0 28px rgba(67,160,71,.5); }

#msg { position: absolute; left: 50%; bottom: 14px; transform: translateX(-50%); z-index: 6; min-height: 1.4em; font-size: 1.15rem; font-weight: bold; text-align: center; padding: 8px 20px; border-radius: 24px; background: rgba(0,0,0,.55); color: #fff; pointer-events: none; transition: opacity .2s; }
#msg:empty { opacity: 0; }
#msg.bad { background: rgba(198,40,40,.92); }
#msg.ok { background: rgba(46,125,50,.92); }

#overlay { position: fixed; inset: 0; background: rgba(0,0,0,.55); display: none; align-items: center; justify-content: center; z-index: 20; }
#overlay.on { display: flex; }
.card { background: #fff; border-radius: 22px; padding: 30px 38px; text-align: center; border: 4px solid #4CAF50; animation: cardIn .5s cubic-bezier(.34,1.56,.64,1) both; }
.card .big { font-size: 3.2rem; display: flex; justify-content: center; align-items: flex-end; gap: 6px; min-height: 1.3em; }
.card .action-button { margin: 6px; }

#guide { position: absolute; right: 16px; bottom: 16px; display: flex; flex-direction: column; align-items: flex-end; gap: 10px; max-width: min(440px, 92%); z-index: 5; pointer-events: none; }
#guide .bubble-row { display: flex; align-items: flex-end; gap: 12px; transition: opacity .25s, transform .25s; }
#guide.hidden .bubble-row { opacity: 0; transform: translateY(20px); pointer-events: none; }
#bubble { pointer-events: auto; position: relative; max-width: 400px; padding: 12px 16px; border-radius: 18px; background: #fff; color: #2A3335; font-size: 1.05rem; font-weight: 700; line-height: 1.35; box-shadow: 0 6px 18px rgba(0,0,0,.3); animation: pop .35s both; }
#bubble b { display: block; margin-bottom: 2px; font-weight: 800; color: #4CAF50; }
#bubble::after { content: ''; position: absolute; right: -10px; bottom: 26px; border: 10px solid transparent; border-right: 0; border-left-color: #fff; }
#robot { flex: 0 0 auto; width: 88px; height: auto; animation: hover 2.6s ease-in-out infinite; filter: drop-shadow(0 6px 8px rgba(0,0,0,.35)); }
#robot .eye { transform-box: fill-box; transform-origin: center; animation: eye 4s infinite; }
#robot .ant { animation: ant 1.2s ease-in-out infinite; }
.guide-toggle { pointer-events: auto; align-self: flex-end; padding: 8px 20px; border-radius: 30px; border: none; background: rgba(42,51,53,.9); color: #fff; font-family: inherit; font-weight: 800; font-size: 1rem; cursor: pointer; box-shadow: 0 4px 10px rgba(0,0,0,.35); transition: transform .15s, background .2s; }
.guide-toggle:hover { transform: scale(1.05); background: #e53935; }

#board.enter .cell { animation: pop .4s both; animation-delay: calc(var(--i) * 9ms); }
.cloud { position: absolute; z-index: 1; left: -30%; width: 24%; height: 7%; border-radius: 50px; background: rgba(255,255,255,.35); pointer-events: none; animation: cloud 42s linear infinite; }
.cloud.c1 { top: 12%; } .cloud.c2 { top: 64%; width: 16%; height: 5%; animation-delay: -21s; }
.fx { position: absolute; width: 14.2857%; height: 14.2857%; display: flex; align-items: center; justify-content: center; pointer-events: none; z-index: 5; font-size: 8cqmin; }
.fx.puff::after { content: ''; width: 34%; height: 34%; border-radius: 50%; background: rgba(255,255,255,.85); animation: puff .6s ease-out forwards; }
.fx.boom { animation: boom .7s ease-out forwards; }
.fx.conf { width: 2.4cqmin; height: 2.4cqmin; margin: 5.9cqmin; background: var(--c); border-radius: 2px; animation: conf 1.1s ease-out both; }
@keyframes pop { from { transform: scale(0); opacity: 0; } to { transform: scale(1); opacity: 1; } }
@keyframes carin { from { scale: 0; } to { scale: 1; } }
@keyframes drive { 50% { translate: 0 -5%; } }
@keyframes cwin { 50% { scale: 1.35; } }
@keyframes wob { 50% { transform: rotate(16deg); } }
@keyframes cloud { to { left: 110%; } }
@keyframes puff { from { transform: scale(.4); opacity: .7; } to { transform: scale(1.7); opacity: 0; } }
@keyframes boom { from { transform: scale(.2); opacity: 1; } to { transform: scale(1.9); opacity: 0; } }
@keyframes conf { to { transform: translate(var(--dx), var(--dy)) rotate(540deg); opacity: 0; } }
@keyframes hover { 50% { transform: translateY(-5px); } }
@keyframes eye { 0%, 92%, 100% { transform: scaleY(1); } 96% { transform: scaleY(.1); } }
@keyframes ant { 50% { opacity: .35; } }
@keyframes blink { 50% { opacity: 0; } }

.fx.radar svg { width: 100%; height: 100%; overflow: visible; }
.fx.radar path { fill: none; stroke: #f5c518; stroke-width: 3px; stroke-linecap: round; vector-effect: non-scaling-stroke; transform-origin: 50px 50px; opacity: 0; animation: radar .6s ease-out; }
.fx.radar path:nth-child(2) { animation-delay: .12s; }
.fx.radar path:nth-child(3) { animation-delay: .24s; }
.fx.radar.hit path { stroke: #e53935; }
@keyframes radar { from { transform: scale(.6); opacity: 1; } to { transform: scale(3); opacity: 0; } }

@media (prefers-reduced-motion: reduce) {
  #car, #car svg { transition: none; }
  .cloud, .it, .fl { animation: none !important; }
  #robot, #robot .eye, #robot .ant, #bubble { animation: none; }
}
@media (max-width: 1000px) and (orientation: portrait) {
  html, body { height: auto; }
  .contentwrapper { flex-direction: column; }
  .visual-section { container-type: normal; min-height: 0; }
  #board { position: relative; width: 100%; height: auto; aspect-ratio: 1; }
}

.it.fuel { animation: fuelBob 1.4s ease-in-out infinite; filter: drop-shadow(0 2px 4px rgba(0,0,0,.35)); }
.it.fuel.picked { animation: fuelPick .4s ease-in forwards; }
@keyframes fuelBob { 0%, 100% { transform: translateY(0); } 50% { transform: translateY(-12%); } }
@keyframes fuelPick { to { transform: scale(0) translateY(-40%); opacity: 0; } }

.it.bunny { animation: cow 1.8s ease-in-out infinite; }
@keyframes cow { 0%, 100% { transform: translateY(0); } 50% { transform: translateY(-7%) scale(1.06); } }
.it.flee { animation: flee .95s ease-in forwards; }
@keyframes flee { 35% { transform: translate(calc(var(--px) * 60%), calc(var(--py) * 60% - 50%)); } 100% { transform: translate(calc(var(--px) * 220%), calc(var(--py) * 220%)); opacity: 0; } }
.fx.alert { animation: alert .8s ease-out forwards; }
@keyframes alert { from { transform: translateY(0); opacity: 1; } to { transform: translateY(-90%); opacity: 0; } }
.fx.wave::after { content: ''; width: 70%; height: 70%; border: .8cqmin solid #fff; border-radius: 50%; animation: wave .7s ease-out backwards; animation-delay: inherit; }
@keyframes wave { from { transform: scale(.3); opacity: .9; } to { transform: scale(2.6); opacity: 0; } }

.cell.goal {
  background-color: #fff;
  background-image:
    linear-gradient(45deg, #222 25%, transparent 25%, transparent 75%, #222 75%, #222),
    linear-gradient(45deg, #222 25%, transparent 25%, transparent 75%, #222 75%, #222);
  background-size: 25% 25%;
  background-position: 0 0, 12.5% 12.5%;
}

/* ---- Yıldız animasyonu ---- */
.star { position: relative; display: inline-block; line-height: 1; }
.star.mid { font-size: 1.3em; margin-bottom: 6px; }
.star b { display: inline-block; font-weight: normal; opacity: 0; transform: scale(0) rotate(-200deg);
  filter: drop-shadow(0 0 0 rgba(255,210,63,0));
  animation: starIn .7s cubic-bezier(.34,1.56,.64,1) var(--d) forwards, starGlow 1.8s ease-in-out calc(var(--d) + .8s) infinite; }
.spark { position: absolute; left: 50%; top: 50%; width: 9px; height: 9px; margin: -4px 0 0 -4px; border-radius: 50%;
  background: var(--c); opacity: 0; animation: spark .8s ease-out calc(var(--d) + .25s) both; }
@keyframes starIn { 0% { opacity: 0; transform: scale(0) rotate(-200deg); } 60% { opacity: 1; transform: scale(1.45) rotate(20deg); } 100% { opacity: 1; transform: scale(1) rotate(0); } }
@keyframes starGlow { 0%, 100% { transform: scale(1); filter: drop-shadow(0 0 2px rgba(255,210,63,.4)); } 50% { transform: scale(1.12); filter: drop-shadow(0 0 12px rgba(255,210,63,.95)); } }
@keyframes spark { 0% { opacity: 1; transform: translate(0,0) scale(1); } 100% { opacity: 0; transform: translate(var(--dx), var(--dy)) scale(0); } }
@keyframes cardIn { from { transform: scale(.5) translateY(30px); opacity: 0; } to { transform: none; opacity: 1; } }
@media (prefers-reduced-motion: reduce) { .star b { animation: none; opacity: 1; transform: none; } .spark, .card { animation: none; } }

/* ---- Telefon dikeyse uyarı ---- */
#rotate { display: none; position: fixed; inset: 0; z-index: 100; background: #2A3335; color: #fff; flex-direction: column; align-items: center; justify-content: center; gap: 18px; padding: 24px; text-align: center; }
#rotate svg { width: 96px; height: 96px; }
#rotate .phone { transform-origin: 32px 32px; animation: rot 2.4s ease-in-out infinite; }
#rotate p { margin: 0; font-size: 1.4rem; font-weight: 800; }
@keyframes rot { 0%, 20% { transform: rotate(0); } 60%, 100% { transform: rotate(-90deg); } }
@media (orientation: portrait) and (max-width: 900px) and (pointer: coarse) { #rotate { display: flex; } }

/* ---- Mobil yatay / alçak ekranlar ---- */
@media (max-height: 560px) and (orientation: landscape) {
  :root { --fs: 15px; --lh: 22px; }
  .banner { padding: 4px max(8px, env(safe-area-inset-right)) 4px max(8px, env(safe-area-inset-left)); gap: 6px; flex-wrap: nowrap; }
  .logo { font-size: .95rem; }
  #levels, .levels-bar { flex-wrap: nowrap; overflow-x: auto; justify-content: flex-start; gap: 3px; scrollbar-width: none; }
  .lvl { width: 28px; height: 28px; min-width: 28px; font-size: .8rem; border-radius: 8px; }
  .actions { gap: 4px; flex-wrap: nowrap; }
  .banner-button { padding: 6px 10px; font-size: .8rem; box-shadow: inset 0 -3px 0 rgba(0,0,0,.3); }
  .lang-toggle { min-width: 40px; padding: 6px 8px; }
  .code-section { padding: 6px; }
  #editor { min-height: 60px; border-radius: 10px; padding: 6px 0; }
  #gutter { padding: 0 8px 0 10px; }
  #pad { min-height: 46px; margin: 4px 0 8px; padding: 4px 0; }
  .pad-inner { gap: 5px; }
  .pbtn { height: 36px; min-width: 40px; padding: 0 12px; font-size: .95rem; }
  #pad.on::after { bottom: -8px; border-width: 10px; margin-left: -10px; border-bottom: 0; }
  .lower-section { gap: 5px; }
  .action-button { padding: 8px 12px; font-size: .9rem; border-radius: 22px; }
  #msg { font-size: .85rem; padding: 4px 12px; bottom: 6px; }
  #guide { right: 6px; bottom: 6px; gap: 4px; max-width: 70%; }
  #bubble { max-width: 220px; padding: 6px 10px; font-size: .75rem; border-radius: 12px; }
  #robot { width: 46px; }
  .guide-toggle { padding: 4px 12px; font-size: .75rem; }
  .card { padding: 14px 22px; }
  .card .big { font-size: 2.2rem; }
  .card h2 { margin: 6px 0; font-size: 1.2rem; }
  .card .action-button { margin: 3px; }
}
@media (max-width: 760px) and (orientation: landscape) { .logo { display: none; } }