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

:root {
  --bg-deep:   #0d1a2e;
  --bg-mid:    #16294a;
  --panel:     rgba(6, 12, 24, 0.5);
  --divider-a: #3a2414;
  --divider-b: #6e4526;
  --gold:      #ffd66b;
  --text:      #f4ecdc;
  --muted:     #a9b4c6;
  --ok:        #7cff8a;
  --bad:       #ff7a6b;
  --tabbar-h:  64px;
  --cookie-size: 260px;
}

html, body {
  height: 100%;
}

body {
  font-family: "Trebuchet MS", "Segoe UI", system-ui, sans-serif;
  color: var(--text);
  background:
    radial-gradient(ellipse at 50% 45%, rgba(80, 130, 210, 0.3), transparent 60%),
    repeating-linear-gradient(45deg, rgba(255,255,255,0.015) 0 12px, transparent 12px 24px),
    linear-gradient(160deg, var(--bg-mid), var(--bg-deep));
  background-attachment: fixed;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
  touch-action: manipulation;          /* kein Doppeltipp-Zoom beim schnellen Klicken */
  -webkit-tap-highlight-color: transparent;
  overflow: hidden;
}

h1, h2, h3, #cookie-count, .bakery-name, .mini-count {
  font-family: Georgia, "Times New Roman", serif;
}

/* ================= Layout: Gebäude | Cookie | Shop ================= */
/* Beide Seiten gleich breit -> der Cookie steht genau in der Bildschirmmitte */
.game {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(340px, 1.25fr) minmax(0, 1fr);
  height: 100vh;
  height: 100dvh;
}

.panel {
  min-width: 0;
  overflow-y: auto;
  background: var(--panel);
}

.info-panel {
  display: flex;
  flex-direction: column;
  border-right: 10px solid transparent;
  border-image: linear-gradient(90deg, var(--divider-a), var(--divider-b) 45%, var(--divider-a)) 1;
}

.shop-panel {
  padding: 0.8rem 0.8rem 1.5rem;
  border-left: 10px solid transparent;
  border-image: linear-gradient(90deg, var(--divider-a), var(--divider-b) 55%, var(--divider-a)) 1;
}

h2 {
  text-align: center;
  font-size: 1.7rem;
  color: var(--gold);
  text-shadow: 0 2px 0 #6b3a14;
  padding: 0.8rem 0 0.4rem;
}

h3 {
  font-size: 0.85rem;
  text-transform: uppercase;
  letter-spacing: 0.12em;
  color: var(--muted);
  margin: 0.6rem 0 0.4rem;
}

/* ================= Mitte: der Cookie ================= */
.center {
  position: relative;
  min-width: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  overflow: hidden;
  overflow: clip; /* verhindert, dass der Bereich beim Klicken seitlich verrutscht */
}

#particles {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
}

.center > :not(#particles):not(#toasts) {
  position: relative;
  z-index: 1;
}

.center h1 {
  margin-top: 0.9rem;
  font-size: 2.4rem;
  color: var(--gold);
  letter-spacing: 0.02em;
  text-align: center;
  text-shadow: 0 3px 0 #6b3a14, 0 0 18px rgba(255, 200, 90, 0.35);
}

.ticker {
  width: 100%;
  margin-top: 0.5rem;
  padding: 0.45rem 1rem;
  font-size: 0.88rem;
  font-style: italic;
  text-align: center;
  color: #e7dcc7;
  background: rgba(0, 0, 0, 0.35);
  border-block: 1px solid rgba(255, 255, 255, 0.08);
  min-height: 2.2rem;
}

#news { display: inline-block; animation: newsIn 0.6s ease-out; }
@keyframes newsIn { from { opacity: 0; translate: 0 6px; } }

.bakery-name {
  margin-top: 0.9rem;
  padding: 0.3rem 1.1rem;
  font-size: 1.1rem;
  background: rgba(0, 0, 0, 0.35);
  border-radius: 999px;
  cursor: pointer;
  text-shadow: 0 2px 2px #000;
  max-width: 92%;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.bakery-name:hover { background: rgba(0, 0, 0, 0.5); }

.banner {
  width: 100%;
  margin-top: 0.7rem;
  padding: 0.6rem 1rem;
  text-align: center;
  background: linear-gradient(90deg, transparent, rgba(0, 0, 0, 0.55) 15%, rgba(0, 0, 0, 0.55) 85%, transparent);
}

#cookie-count {
  font-size: 2.1rem;
  font-weight: bold;
  text-shadow: 0 2px 0 #000, 0 0 12px rgba(0, 0, 0, 0.8);
}

#cps {
  font-size: 0.95rem;
  color: var(--muted);
}

#cps.frenzy { color: var(--gold); font-weight: bold; }

.cookie-wrap {
  position: relative;
  flex: 1;
  width: 100%;
  min-height: 0;
  display: grid;
  place-items: center;
}

/* Strahlen und Cursor-Kreis exakt mittig hinter dem Cookie */
.shine,
#cursor-ring {
  position: absolute;
  left: 50%;
  top: 50%;
  translate: -50% -50%;
}

/* Lichtstrahlen hinter dem Cookie */
.shine {
  width: calc(var(--cookie-size) * 2.15);
  height: calc(var(--cookie-size) * 2.15);
  border-radius: 50%;
  background: repeating-conic-gradient(rgba(255, 245, 210, 0.22) 0deg 9deg, transparent 9deg 22.5deg);
  -webkit-mask: radial-gradient(circle, #000 15%, transparent 68%);
          mask: radial-gradient(circle, #000 15%, transparent 68%);
  animation: spin 40s linear infinite;
  pointer-events: none;
}

.shine-b {
  width: calc(var(--cookie-size) * 1.75);
  height: calc(var(--cookie-size) * 1.75);
  opacity: 0.6;
  animation-duration: 28s;
  animation-direction: reverse;
}

@keyframes spin { to { rotate: 360deg; } }

#cookie {
  position: relative;
  width: var(--cookie-size);
  height: var(--cookie-size);
  background: none;
  border: none;
  border-radius: 50%;
  cursor: pointer;
  filter: drop-shadow(0 14px 22px rgba(0, 0, 0, 0.6));
  transition: scale 0.12s ease-out;
  touch-action: manipulation;
}

#cookie svg {
  width: 100%;
  height: 100%;
  display: block;
  pointer-events: none;
}

@media (hover: hover) {
  #cookie:hover { scale: 1.06; }
}
#cookie:active,
#cookie.pressed { scale: 0.95; }

#cookie:focus-visible {
  outline: 3px solid var(--gold);
  outline-offset: 6px;
}

/* Kreisende Cursor um den Cookie */
#cursor-ring {
  width: 0;
  height: 0;
  animation: spin 90s linear infinite;
  pointer-events: none;
}

.ring-cursor {
  position: absolute;
  left: 0;
  top: 0;
  width: 0;
  height: 0;
}

.ring-cursor span {
  position: absolute;
  left: -10px;
  top: -12px;
  font-size: 20px;
  line-height: 1;
  filter: drop-shadow(0 2px 2px rgba(0, 0, 0, 0.6));
  animation: poke 2.4s ease-in-out infinite;
}

@keyframes poke {
  0%, 80%, 100% { translate: 0 0; }
  90%           { translate: 0 7px; }
}

/* Meldungen (Goldkeks usw.) */
#toasts {
  position: absolute;
  bottom: 1.2rem;
  left: 50%;
  translate: -50% 0;
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
  width: min(90%, 320px);
  pointer-events: none;
  z-index: 5;
}

.toast {
  padding: 0.6rem 0.9rem;
  background: rgba(10, 10, 20, 0.88);
  border: 1px solid var(--gold);
  border-radius: 8px;
  text-align: center;
  box-shadow: 0 6px 18px rgba(0, 0, 0, 0.5);
  animation: toastIn 0.25s ease-out, toastOut 0.4s ease-in 3.6s forwards;
}

.toast b { color: var(--gold); display: block; font-family: Georgia, serif; }
.toast small { color: var(--muted); }

@keyframes toastIn  { from { opacity: 0; translate: 0 12px; } }
@keyframes toastOut { to   { opacity: 0; translate: 0 -8px; } }

/* ================= Links: Gebäude-Ansicht ================= */
#buildings-view {
  flex: 1;
  padding: 0.4rem 0.6rem 0.6rem;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.empty-view {
  margin: auto;
  max-width: 260px;
  text-align: center;
  color: var(--muted);
  font-style: italic;
}

.row {
  position: relative;
  min-height: 64px;
  border-radius: 6px;
  padding: 1.6rem 0.5rem 0.5rem 0.6rem;
  display: flex;
  flex-wrap: wrap;
  align-content: center;
  gap: 2px 3px;
  overflow: hidden;
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.08), inset 0 -18px 30px rgba(0, 0, 0, 0.35);
}

.row .row-label {
  position: absolute;
  left: 0;
  top: 0;
  padding: 0.2rem 0.6rem;
  border-bottom-right-radius: 6px;
  font-size: 0.65rem;
  font-weight: bold;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  background: rgba(0, 0, 0, 0.35);
  color: rgba(255, 255, 255, 0.75);
}

.row .unit {
  font-size: 26px;
  line-height: 1;
  filter: drop-shadow(0 3px 2px rgba(0, 0, 0, 0.45));
  animation: bob 2.8s ease-in-out infinite;
}

.row .more {
  align-self: center;
  margin-left: 0.3rem;
  font-weight: bold;
  color: rgba(255, 255, 255, 0.8);
}

@keyframes bob {
  0%, 100% { translate: 0 0; }
  50%      { translate: 0 -3px; }
}

.stats-bar {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 0.3rem 1.1rem;
  padding: 0.5rem 1rem;
  font-size: 0.8rem;
  color: var(--muted);
  background: rgba(0, 0, 0, 0.35);
}

.stats-bar b { color: var(--text); }

.panel-footer {
  padding: 0.7rem;
  text-align: center;
}

.reset {
  background: rgba(0, 0, 0, 0.3);
  border: 1px solid rgba(255, 255, 255, 0.2);
  color: var(--muted);
  padding: 0.4rem 0.9rem;
  border-radius: 6px;
  cursor: pointer;
  font: inherit;
  font-size: 0.8rem;
}

.reset:hover { background: rgba(0, 0, 0, 0.5); color: var(--text); }

/* ================= Rechts: Shop ================= */
.mini-count { display: none; }

#upgrades {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
}

.hint {
  font-size: 0.8rem;
  color: var(--muted);
  font-style: italic;
}

.upgrade {
  width: 52px;
  height: 52px;
  display: grid;
  place-items: center;
  color: inherit;
  font: inherit;
  border-radius: 6px;
  cursor: pointer;
  border: 2px solid #c9a35a;
  background: linear-gradient(160deg, #3d4f6e, #1d2840);
  box-shadow: inset 0 0 0 2px rgba(0, 0, 0, 0.4);
  transition: transform 0.1s, filter 0.15s;
}

.upgrade .u-icon { font-size: 26px; line-height: 1; }
.upgrade .u-info { display: none; }

@media (hover: hover) {
  .upgrade:hover { transform: translateY(-2px); }
}
.upgrade.cant { filter: grayscale(0.7) brightness(0.6); border-color: #555; }

.buildings-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-top: 0.8rem;
}

.amount {
  display: flex;
  gap: 3px;
}

.amount button {
  font: inherit;
  font-size: 0.8rem;
  padding: 0.2rem 0.6rem;
  background: rgba(255, 255, 255, 0.06);
  color: var(--muted);
  border: 1px solid rgba(255, 255, 255, 0.15);
  border-radius: 4px;
  cursor: pointer;
}

.amount button.active {
  background: var(--gold);
  color: #2a1a08;
  border-color: var(--gold);
  font-weight: bold;
}

#shop {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.item {
  position: relative;
  display: flex;
  align-items: center;
  gap: 0.7rem;
  width: 100%;
  padding: 0.45rem 0.6rem;
  min-height: 64px;
  color: inherit;
  font: inherit;
  text-align: left;
  cursor: pointer;
  background: linear-gradient(90deg, rgba(120, 90, 60, 0.45), rgba(70, 50, 35, 0.45));
  border: 1px solid rgba(255, 220, 160, 0.25);
  border-radius: 4px;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.1);
  transition: background 0.15s, filter 0.15s;
}

@media (hover: hover) {
  .item:hover:not(.cant) {
    background: linear-gradient(90deg, rgba(150, 115, 75, 0.6), rgba(90, 65, 45, 0.6));
  }
}

.item:active:not(.cant) { filter: brightness(1.2); }

.item.cant {
  cursor: default;
  filter: brightness(0.6);
}

.item .icon {
  width: 48px;
  height: 48px;
  flex-shrink: 0;
  display: grid;
  place-items: center;
  font-size: 32px;
  background: rgba(0, 0, 0, 0.25);
  border-radius: 6px;
}

.item.mystery .icon { filter: brightness(0) opacity(0.6); }

.item .info {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
}

.item .name {
  font-family: Georgia, serif;
  font-size: 1.15rem;
  font-weight: bold;
  text-shadow: 0 1px 2px #000;
}

.item .desc { display: none; }

.item .price {
  font-size: 0.9rem;
  font-weight: bold;
  color: var(--ok);
}

.item.cant .price { color: var(--bad); }

.item .owned {
  font-family: Georgia, serif;
  font-size: 2.2rem;
  font-weight: bold;
  color: rgba(255, 255, 255, 0.28);
  min-width: 2ch;
  text-align: right;
}

/* ================= Tooltip (nur mit Maus) ================= */
#tooltip {
  position: fixed;
  z-index: 50;
  width: 300px;
  padding: 0.7rem 0.85rem;
  font-size: 0.85rem;
  background: rgba(8, 10, 18, 0.95);
  border: 1px solid #c9a35a;
  border-radius: 6px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.6);
  pointer-events: none;
  display: none;
}

#tooltip .tt-head {
  display: flex;
  justify-content: space-between;
  gap: 0.5rem;
  align-items: baseline;
  margin-bottom: 0.3rem;
}

#tooltip .tt-name { font-family: Georgia, serif; font-size: 1.05rem; font-weight: bold; }
#tooltip .tt-price { color: var(--ok); font-weight: bold; white-space: nowrap; }
#tooltip .tt-price.bad { color: var(--bad); }
#tooltip .tt-desc { color: #d8d0c0; }
#tooltip .tt-quote { margin-top: 0.4rem; color: var(--muted); font-style: italic; font-size: 0.8rem; }
#tooltip ul { margin-top: 0.4rem; padding-left: 1rem; color: var(--muted); }
#tooltip ul b { color: var(--text); }

/* ================= Schwebende Zahlen ================= */
.float {
  position: fixed;
  z-index: 20;
  pointer-events: none;
  font-family: Georgia, serif;
  font-size: 1.4rem;
  font-weight: bold;
  color: #fff;
  text-shadow: 0 2px 3px #000;
  transform: translate(-50%, -50%);
  animation: floatUp 1.1s ease-out forwards;
}

@keyframes floatUp {
  to {
    transform: translate(-50%, calc(-50% - 90px));
    opacity: 0;
  }
}

/* ================= Goldkeks ================= */
#golden-layer {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 30;
}

.golden {
  position: absolute;
  width: 72px;
  height: 72px;
  padding: 0;
  border: none;
  background: none;
  cursor: pointer;
  pointer-events: auto;
  filter: sepia(1) saturate(5) hue-rotate(-8deg) brightness(1.25)
          drop-shadow(0 0 10px rgba(255, 215, 90, 0.9));
  animation: goldIn 1s ease-out, goldPulse 1.6s ease-in-out 1s infinite, goldOut 1.2s ease-in 11.8s forwards;
}

.golden svg { width: 100%; height: 100%; display: block; pointer-events: none; }

@keyframes goldIn    { from { opacity: 0; scale: 0.3; } }
@keyframes goldPulse { 50% { scale: 1.12; rotate: 8deg; } }
@keyframes goldOut   { to { opacity: 0; scale: 0.6; } }

/* ================= Leiste unten (nur Handy/Tablet) ================= */
.tabbar { display: none; }

/* =====================================================================
   Handy & Tablet: Cookie bildschirmfüllend in der Mitte,
   Gebäude und Shop über die Leiste unten
   ===================================================================== */
@media (max-width: 999px) {
  :root { --cookie-size: min(62vw, 38dvh, 300px); }

  .game {
    display: block;
    height: 100dvh;
  }

  .center {
    height: calc(100dvh - var(--tabbar-h) - env(safe-area-inset-bottom));
  }

  .center h1 { font-size: 1.9rem; margin-top: 0.6rem; }
  .ticker { font-size: 0.8rem; padding: 0.35rem 0.8rem; }
  .bakery-name { font-size: 1rem; margin-top: 0.6rem; }
  #cookie-count { font-size: 1.8rem; }

  /* Gebäude & Shop als Vollbild-Seiten über dem Cookie */
  .panel {
    position: fixed;
    left: 0;
    right: 0;
    top: 0;
    bottom: calc(var(--tabbar-h) + env(safe-area-inset-bottom));
    z-index: 40;
    border: none;
    background: linear-gradient(160deg, var(--bg-mid), var(--bg-deep));
    overscroll-behavior: contain;
    -webkit-overflow-scrolling: touch;
    display: none;
  }

  body[data-tab="info"] .info-panel { display: flex; }
  body[data-tab="shop"] .shop-panel { display: block; }

  .shop-panel { padding: 0 0.7rem 1.2rem; }

  /* Cookie-Stand immer sichtbar beim Einkaufen */
  .mini-count {
    display: block;
    position: sticky;
    top: 0;
    z-index: 2;
    margin: 0 -0.7rem;
    padding: 0.55rem 1rem;
    text-align: center;
    font-size: 1.25rem;
    font-weight: bold;
    background: rgba(8, 14, 28, 0.95);
    border-bottom: 1px solid rgba(255, 214, 107, 0.3);
  }

  .mini-count small {
    display: block;
    font-family: "Trebuchet MS", system-ui, sans-serif;
    font-size: 0.75rem;
    font-weight: normal;
    color: var(--muted);
  }

  /* Verbesserungen als Liste mit Beschreibung (kein Hover auf dem Handy) */
  #upgrades { flex-direction: column; }

  .upgrade {
    width: 100%;
    height: auto;
    min-height: 56px;
    display: flex;
    align-items: center;
    gap: 0.7rem;
    padding: 0.45rem 0.6rem;
    text-align: left;
  }

  .upgrade .u-icon {
    width: 40px;
    flex-shrink: 0;
    text-align: center;
    font-size: 28px;
  }

  .upgrade .u-info {
    display: flex;
    flex-direction: column;
    min-width: 0;
  }

  .upgrade .u-info b { font-family: Georgia, serif; }
  .upgrade .u-info small { color: #d8d0c0; font-size: 0.8rem; }
  .upgrade .u-price { color: var(--ok); font-weight: bold; font-size: 0.85rem; }
  .upgrade.cant .u-price { color: var(--bad); }

  .item .desc {
    display: block;
    font-size: 0.75rem;
    color: #d8d0c0;
  }

  .amount button { padding: 0.35rem 0.8rem; font-size: 0.9rem; }

  #tooltip { display: none !important; }

  #toasts { bottom: 0.8rem; }

  /* Leiste unten */
  .tabbar {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 45;
    height: calc(var(--tabbar-h) + env(safe-area-inset-bottom));
    padding-bottom: env(safe-area-inset-bottom);
    background: linear-gradient(180deg, #4a2d18, #2c1a0d);
    border-top: 3px solid var(--divider-b);
    box-shadow: 0 -6px 18px rgba(0, 0, 0, 0.45);
  }

  .tabbar button {
    position: relative;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 2px;
    background: none;
    border: none;
    color: #d9c3a5;
    font: inherit;
    font-size: 0.78rem;
    cursor: pointer;
  }

  .tabbar button span { font-size: 1.5rem; line-height: 1; }

  .tabbar button.active {
    color: var(--gold);
    font-weight: bold;
    background: rgba(255, 214, 107, 0.1);
  }

  .tabbar .badge {
    display: none;
    position: absolute;
    top: 8px;
    left: calc(50% + 10px);
    width: 12px;
    height: 12px;
    border-radius: 50%;
    background: #ff5a4a;
    box-shadow: 0 0 0 2px #2c1a0d;
  }

  .tabbar .badge.on { display: block; }
}

/* Sehr kleine / niedrige Bildschirme */
@media (max-width: 999px) and (max-height: 620px) {
  .ticker { display: none; }
  .center h1 { font-size: 1.5rem; }
}

@media (prefers-reduced-motion: reduce) {
  .shine, #cursor-ring, .ring-cursor span, .row .unit { animation: none; }
}
