/* Atölye Kralı - arayüz stilleri */
:root {
  --cream: #fff6e8;
  --cream-2: #f6e6cc;
  --ink: #3a2a1e;
  --ink-soft: #7a604a;
  --copper: #e8833a;
  --copper-dark: #b85c1c;
  --copper-light: #ffb35c;
  --teal: #2e7d7a;
  --good: #4caf50;
  --warn: #f2b33d;
  --bad: #e2533b;
  --panel-shadow: 0 6px 18px rgba(43, 31, 23, .28);
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body {
  margin: 0; height: 100%; overflow: hidden;
  overscroll-behavior: none;
  font-family: system-ui, -apple-system, Roboto, "Segoe UI", "Noto Sans", sans-serif;
  color: var(--ink);
  user-select: none; -webkit-user-select: none;
  -webkit-touch-callout: none;
}

body { background: linear-gradient(180deg, #9fcbe0 0%, #f7d9b0 55%, #f3c89a 100%); }
body.mode-mg { background: linear-gradient(180deg, #5a4232 0%, #3a2a20 100%); }

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

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

#ui { position: absolute; inset: 0; pointer-events: none; }
#ui > * { pointer-events: auto; }
#ui > #floaters, #ui > #bubble, #ui > .fps { pointer-events: none; }

.hidden { display: none !important; }

button { font: inherit; color: inherit; border: 0; cursor: pointer; touch-action: manipulation; }

/* ÜST BAR */
.top {
  position: absolute; left: 0; right: 0; top: 0;
  padding: calc(var(--safe-top) + 10px) 12px 0;
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
  pointer-events: none !important;
}
.top > * { pointer-events: auto; }

.money-pill {
  display: flex; align-items: center; gap: 8px;
  background: rgba(43, 31, 23, .82); color: #fff3df;
  padding: 6px 16px 6px 7px; border-radius: 999px;
  box-shadow: var(--panel-shadow);
  min-width: 140px;
}
.money-pill .coin { width: 34px; height: 34px; flex: none; }
.money-text { display: flex; flex-direction: column; line-height: 1.05; }
#money { font-size: 22px; font-weight: 800; font-variant-numeric: tabular-nums; letter-spacing: .2px; }
#rate { font-size: 12px; color: #ffcf8a; font-weight: 600; }
.money-pill.bump #money { animation: bump .25s ease-out; }
@keyframes bump { 40% { transform: scale(1.12); } }

.icon-btn {
  width: 46px; height: 46px; border-radius: 14px;
  background: rgba(43, 31, 23, .82); color: #fff3df;
  display: grid; place-items: center;
  box-shadow: var(--panel-shadow);
}
.icon-btn svg { width: 26px; height: 26px; }
.icon-btn:active { transform: scale(.94); }

/* ALT PANEL (ATÖLYE) */
.bottom-panel {
  position: absolute; left: 0; right: 0; bottom: 0;
  padding: 0 12px calc(var(--safe-bottom) + 14px);
  display: flex; flex-direction: column; gap: 10px;
  pointer-events: none !important;
}
.bottom-panel > * { pointer-events: auto; }

.tip {
  align-self: center; max-width: 92%;
  background: var(--cream); color: var(--ink);
  padding: 10px 14px; border-radius: 14px; font-size: 14px; font-weight: 600; text-align: center;
  box-shadow: var(--panel-shadow);
  animation: floaty 2.4s ease-in-out infinite;
}
@keyframes floaty { 50% { transform: translateY(-4px); } }

.machine-card {
  display: flex; gap: 12px; align-items: center;
  background: var(--cream); border-radius: 18px; padding: 10px 14px;
  box-shadow: var(--panel-shadow);
}
.mc-icon { width: 48px; height: 48px; border-radius: 12px; background: var(--cream-2); display: grid; place-items: center; flex: none; }
.mc-icon svg { width: 38px; height: 38px; }
.mc-body { flex: 1; min-width: 0; }
.mc-title { font-size: 15px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.mc-status { display: flex; justify-content: space-between; font-size: 12.5px; color: var(--ink-soft); margin: 2px 0 6px; gap: 8px; }
.mc-rate { color: var(--teal); font-weight: 700; white-space: nowrap; }

.bar { height: 10px; border-radius: 99px; background: #e8d6b8; overflow: hidden; }
.bar.thin { height: 7px; }
.bar > i { display: block; height: 100%; width: 0%; border-radius: 99px; background: linear-gradient(90deg, var(--teal), #49a79f); }

.cta {
  display: flex; align-items: center; justify-content: center; gap: 12px;
  min-height: 64px; border-radius: 20px;
  background: linear-gradient(180deg, var(--copper-light), var(--copper) 55%, var(--copper-dark));
  color: #fff; text-shadow: 0 1px 0 rgba(0, 0, 0, .25);
  box-shadow: 0 5px 0 #8f4412, var(--panel-shadow);
  transition: transform .08s;
}
.cta:active { transform: translateY(3px); box-shadow: 0 2px 0 #8f4412, var(--panel-shadow); }
.cta svg { width: 34px; height: 34px; flex: none; }
.cta-text { display: flex; flex-direction: column; align-items: flex-start; line-height: 1.15; }
.cta-text b { font-size: 20px; }
.cta-text small { font-size: 12.5px; opacity: .92; }
.cta.pulse { animation: pulse 1.6s ease-in-out infinite; }
@keyframes pulse { 50% { box-shadow: 0 5px 0 #8f4412, 0 0 0 8px rgba(255, 179, 92, .35), var(--panel-shadow); } }

/* Baloncuk (makinenin üstünde "Dokun!") */
.bubble {
  position: absolute; left: 0; top: 0;
  background: var(--cream); color: var(--copper-dark); font-weight: 800; font-size: 15px;
  padding: 7px 13px; border-radius: 12px; box-shadow: var(--panel-shadow);
  transform: translate(-50%, -100%); white-space: nowrap;
}
.bubble::after {
  content: ""; position: absolute; left: 50%; bottom: -7px; margin-left: -7px;
  border: 7px solid transparent; border-bottom: 0; border-top-color: var(--cream);
}
.bubble.bob { animation: bob 1.2s ease-in-out infinite; }
@keyframes bob { 50% { margin-top: -6px; } }

/* Uçan yazılar (+2 gibi) */
#floaters { position: absolute; inset: 0; overflow: hidden; }
.floater {
  position: absolute; left: 0; top: 0;
  font-weight: 800; font-size: 18px; color: #fff;
  text-shadow: 0 2px 0 #7a3f12, 0 0 6px rgba(0, 0, 0, .35);
  white-space: nowrap; will-change: transform, opacity;
  display: flex; align-items: center; gap: 3px;
}
.floater svg { width: 18px; height: 18px; }

/* USTA DOKUNUŞU */
.mg { position: absolute; inset: 0; pointer-events: none !important; }
.mg > * { pointer-events: auto; }
.mg-top {
  position: absolute; left: 0; right: 0; top: 0;
  padding: calc(var(--safe-top) + 66px) 12px 0;
  display: flex; flex-direction: column; gap: 8px; align-items: stretch;
  pointer-events: none !important;
}
.mg-top > * { pointer-events: auto; }
.back-btn {
  position: absolute; left: 12px; top: calc(var(--safe-top) + 66px);
  display: none;
}
.order-card {
  background: rgba(255, 246, 232, .96); border-radius: 16px; padding: 9px 12px 10px;
  box-shadow: var(--panel-shadow);
}
.order-head { font-size: 13.5px; color: var(--ink-soft); display: flex; align-items: baseline; white-space: pre; }
.order-head b { color: var(--ink); }
.order-value { margin-left: auto; font-weight: 800; color: var(--copper-dark); }
.blueprint {
  margin: 6px 0 7px; height: 64px; border-radius: 10px;
  background:
    linear-gradient(rgba(255,255,255,.07) 1px, transparent 1px) 0 0 / 10px 10px,
    linear-gradient(90deg, rgba(255,255,255,.07) 1px, transparent 1px) 0 0 / 10px 10px,
    #24527a;
  overflow: hidden;
}
.blueprint svg { width: 100%; height: 100%; display: block; }

.mg-bottom {
  position: absolute; left: 0; right: 0; bottom: 0;
  padding: 0 12px calc(var(--safe-bottom) + 14px);
  display: flex; flex-direction: column; gap: 10px;
  pointer-events: none !important;
}
.gauge {
  background: rgba(255, 246, 232, .94); border-radius: 16px; padding: 9px 12px 12px;
  box-shadow: var(--panel-shadow);
}
.gauge-label { font-size: 13.5px; color: var(--ink-soft); margin-bottom: 7px; }
.gauge-label b { color: var(--ink); }
.gauge-label b.slow { color: #8a7a6a; }
.gauge-label b.ideal { color: #2f8f3a; }
.gauge-label b.fast { color: #c98a10; }
.gauge-label b.bad { color: var(--bad); }
.gauge-track { position: relative; height: 14px; border-radius: 99px; overflow: visible; display: flex; }
.gauge-track .z { display: block; height: 100%; }
.z-slow { width: 22.5%; background: #cbbca8; border-radius: 99px 0 0 99px; }
.z-ideal { width: 37.5%; background: #6cc070; }
.z-fast { width: 17.5%; background: #f2c14a; }
.z-bad { width: 22.5%; background: #e8664e; border-radius: 0 99px 99px 0; }
#needle {
  position: absolute; top: -5px; left: 0; width: 6px; height: 24px; margin-left: -3px;
  background: var(--ink); border-radius: 3px; box-shadow: 0 0 0 2px #fff;
  transition: left .06s linear;
}
.mg-hint {
  align-self: center; display: flex; align-items: center; gap: 10px;
  color: #fff3df; font-size: 14px; font-weight: 600; text-shadow: 0 1px 2px rgba(0,0,0,.5);
  background: rgba(43, 31, 23, .55); padding: 8px 14px; border-radius: 999px;
}
.swipe-dot {
  width: 14px; height: 14px; border-radius: 50%; background: #ffcf8a; flex: none;
  animation: swipe 1.3s ease-in-out infinite;
}
@keyframes swipe { 0%, 100% { transform: translateX(-10px); } 50% { transform: translateX(10px); } }

.streak {
  position: absolute; right: 12px; top: calc(var(--safe-top) + 66px + 128px);
  background: linear-gradient(180deg, #ffcf5a, #f29a2e); color: #5a2a00; font-weight: 800;
  padding: 6px 12px; border-radius: 12px; box-shadow: var(--panel-shadow); font-size: 14px;
}

.reward {
  position: absolute; left: 50%; top: 42%;
  transform: translate(-50%, -50%);
  display: flex; flex-direction: column; align-items: center; gap: 4px;
  pointer-events: none !important;
}
.reward.show { animation: rewardIn .9s cubic-bezier(.2, 1.4, .4, 1) both; }
@keyframes rewardIn {
  0% { transform: translate(-50%, -30%) scale(.5); opacity: 0; }
  25% { transform: translate(-50%, -50%) scale(1.08); opacity: 1; }
  80% { transform: translate(-50%, -55%) scale(1); opacity: 1; }
  100% { transform: translate(-50%, -75%) scale(.95); opacity: 0; }
}
.stars { display: flex; gap: 6px; }
.stars svg { width: 44px; height: 44px; fill: #5a4636; stroke: #2b1f17; stroke-width: 1; }
.stars svg.on { fill: #ffcf3a; filter: drop-shadow(0 0 6px rgba(255, 200, 60, .8)); }
.stars svg:nth-child(2) { transform: translateY(-8px) scale(1.15); }
.reward-title { font-size: 28px; font-weight: 900; color: #fff; text-shadow: 0 3px 0 #7a3f12, 0 0 12px rgba(0,0,0,.5); }
.reward-money { display: flex; align-items: center; gap: 6px; font-size: 26px; font-weight: 900; color: #ffe08a; text-shadow: 0 2px 0 #7a3f12; }
.reward-money svg { width: 30px; height: 30px; }

/* Geri butonu: sol üst, para göstergesinin yerine (mg modunda) */
body.mode-mg .money-pill { min-width: 0; }
body.mode-mg .back-btn {
  display: flex; position: fixed; left: auto; right: 68px; top: calc(var(--safe-top) + 10px);
  align-items: center; gap: 4px; height: 46px; padding: 0 14px 0 8px; border-radius: 14px;
  background: var(--cream); color: var(--ink); font-weight: 700; box-shadow: var(--panel-shadow);
}
.back-btn svg { width: 22px; height: 22px; }

/* MODALLAR */
.modal {
  position: absolute; inset: 0; background: rgba(20, 12, 6, .55);
  display: flex; align-items: flex-end; justify-content: center;
  padding: 12px 12px calc(var(--safe-bottom) + 12px);
  animation: fadeIn .15s;
}
@keyframes fadeIn { from { opacity: 0; } }
.sheet {
  width: 100%; max-width: 480px; background: var(--cream); border-radius: 22px;
  padding: 18px 18px 16px; box-shadow: var(--panel-shadow);
  display: flex; flex-direction: column; gap: 10px;
  max-height: 88vh; overflow-y: auto;
  animation: sheetIn .22s cubic-bezier(.2, 1, .4, 1);
}
.sheet.small { max-width: 360px; align-self: center; }
@keyframes sheetIn { from { transform: translateY(30px); opacity: 0; } }
.sheet h2 { margin: 0 0 4px; font-size: 22px; }
.sheet .row {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  min-height: 48px; padding: 4px 2px; border-bottom: 1px solid #ead8bb; font-weight: 600;
}
.sheet select {
  font: inherit; font-weight: 600; color: var(--ink); background: #fff;
  border: 2px solid #e4cfae; border-radius: 12px; padding: 8px 10px; min-width: 150px;
}
.note { margin: -4px 0 0; font-size: 12px; color: var(--ink-soft); }
.switch {
  appearance: none; -webkit-appearance: none; width: 52px; height: 30px; border-radius: 99px;
  background: #d6c3a5; position: relative; transition: background .15s; flex: none; margin: 0;
}
.switch::after {
  content: ""; position: absolute; top: 3px; left: 3px; width: 24px; height: 24px; border-radius: 50%;
  background: #fff; box-shadow: 0 1px 3px rgba(0,0,0,.3); transition: transform .15s;
}
.switch:checked { background: var(--teal); }
.switch:checked::after { transform: translateX(22px); }
.sheet button { min-height: 48px; border-radius: 14px; font-weight: 700; background: #ecdcc2; }
.sheet button.primary { background: var(--copper); color: #fff; }
.sheet button.danger { background: #f3d2c8; color: #a8321c; }
.sheet button:active { transform: scale(.98); }
.btn-row { display: flex; gap: 10px; }
.btn-row button { flex: 1; }
.ver { font-size: 12px; color: var(--ink-soft); text-align: center; }
#confirmText { margin: 4px 0 8px; font-weight: 600; text-align: center; }

.fps {
  position: absolute; left: 8px; bottom: calc(var(--safe-bottom) + 4px);
  font: 700 11px ui-monospace, monospace; color: #fff; background: rgba(0,0,0,.55);
  padding: 2px 6px; border-radius: 6px; z-index: 5;
}
.toast {
  position: absolute; left: 50%; top: calc(var(--safe-top) + 70px); transform: translateX(-50%);
  background: rgba(43, 31, 23, .9); color: #fff3df; padding: 10px 16px; border-radius: 12px;
  font-size: 14px; font-weight: 600; max-width: 90%; text-align: center; box-shadow: var(--panel-shadow);
}

#fade {
  position: fixed; inset: 0; background: #2b1f17; opacity: 0; pointer-events: none;
  transition: opacity .22s ease; z-index: 50;
}
#fade.on { opacity: 1; }

@media (min-width: 600px) {
  .bottom-panel, .mg-bottom { left: 50%; right: auto; width: 480px; transform: translateX(-50%); }
  .mg-top { left: 50%; right: auto; width: 480px; transform: translateX(-50%); }
}
