/* ══════════════════════════════════════════════════
   Cat Scroller Adventure — Styles
   ══════════════════════════════════════════════════ */

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

html, body {
  width: 100%;
  height: 100%;
  min-height: 100%;
  overflow: hidden;
  background: #0a0a14;
  touch-action: none;
  overscroll-behavior: none;
}

body {
  color: #e8e4d9;
  font-family: 'Trebuchet MS', 'Segoe UI', sans-serif;
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
  -webkit-tap-highlight-color: transparent;
}

@supports (height: 100dvh) {
  html, body {
    height: 100dvh;
    min-height: 100dvh;
  }
}

body.mobile {
  width: var(--app-width, 100vw);
  height: var(--app-height, 100vh);
}

canvas, .btn, .hb, .lcell, .tcb {
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
  -webkit-user-drag: none;
}

/* ── Canvas ── */
#game {
  position: fixed;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  display: block;
  image-rendering: auto;
  border-radius: 8px;
  box-shadow: 0 0 40px rgba(0,0,0,.6);
}

body.mobile #game {
  border-radius: 0;
}

body.ios #game {
  box-shadow: 0 0 24px rgba(0,0,0,.45);
}

/* ── Screens (overlays) ── */
.screen {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: none;
  align-items: center;
  justify-content: center;
  background: rgba(5, 5, 15, .88);
  backdrop-filter: blur(8px);
  padding:
    max(12px, env(safe-area-inset-top))
    max(12px, env(safe-area-inset-right))
    max(12px, env(safe-area-inset-bottom))
    max(12px, env(safe-area-inset-left));
  overflow-y: auto;
  width: var(--app-width, 100vw);
  height: var(--app-height, 100vh);
}
.screen.active { display: flex; }

.rotate-lock {
  position: fixed;
  inset: 0;
  z-index: 80;
  display: none;
  align-items: center;
  justify-content: center;
  padding:
    max(16px, env(safe-area-inset-top))
    max(16px, env(safe-area-inset-right))
    max(16px, env(safe-area-inset-bottom))
    max(16px, env(safe-area-inset-left));
  background: rgba(5, 5, 15, .95);
  backdrop-filter: blur(10px);
  width: var(--app-width, 100vw);
  height: var(--app-height, 100vh);
}

.rotate-lock[hidden] {
  display: none !important;
}

.rotate-lock.on {
  display: flex !important;
}

.rotate-card {
  width: min(520px, calc(100vw - 28px));
}

/* ── Cards ── */
.card {
  width: min(540px, calc(100vw - 24px));
  background: linear-gradient(170deg, #1e2040 0%, #161830 50%, #121428 100%);
  border: 2px solid rgba(248, 183, 57, .25);
  border-radius: 18px;
  padding: 28px 24px;
  box-shadow:
    0 20px 60px rgba(0, 0, 0, .5),
    0 0 30px rgba(248, 183, 57, .06),
    inset 0 1px 0 rgba(255,255,255,.05);
  text-align: center;
  max-height: 92vh;
  overflow-y: auto;
}

.card h2 {
  font: 700 28px/1.1 Georgia, serif;
  color: #f8b739;
  margin-bottom: 10px;
  text-shadow: 0 2px 12px rgba(248, 183, 57, .3);
  letter-spacing: .5px;
}

.card p {
  color: #9a9ab0;
  font-size: 13px;
  margin-bottom: 14px;
  line-height: 1.5;
}

/* ── Cat emoji title ── */
.title-cat {
  font-size: 68px;
  margin-bottom: 6px;
  filter: drop-shadow(0 4px 12px rgba(248, 183, 57, .2));
  animation: catBounce 2s ease-in-out infinite;
}
@keyframes catBounce {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(-6px); }
}

.title-sub {
  color: #666;
  font-size: 11px;
  margin-top: 10px;
  line-height: 1.6;
}

/* ── Buttons ── */
.btn {
  display: inline-block;
  border: 2px solid #f8b739;
  background: linear-gradient(180deg, #f8b739 0%, #e69520 100%);
  color: #1a1c2e;
  padding: 12px 30px;
  font: 700 14px/1 'Trebuchet MS', sans-serif;
  border-radius: 12px;
  cursor: pointer;
  letter-spacing: 1px;
  transition: all .2s ease;
  margin: 4px;
  text-transform: uppercase;
  box-shadow: 0 4px 15px rgba(248, 183, 57, .2);
}
.btn:hover {
  filter: brightness(1.15);
  transform: translateY(-2px);
  box-shadow: 0 6px 20px rgba(248, 183, 57, .35);
}
.btn:active {
  transform: translateY(1px);
  box-shadow: 0 2px 8px rgba(248, 183, 57, .15);
}

.btn:focus-visible,
.btn.gp-focus,
.hb:focus-visible,
.hb.gp-focus {
  outline: none;
  filter: brightness(1.08);
  transform: translateY(-2px);
  box-shadow: 0 0 0 2px rgba(255,255,255,.15), 0 0 0 4px rgba(248, 183, 57, .55), 0 8px 24px rgba(248, 183, 57, .2);
}

.btn.sec {
  background: transparent;
  color: #f8b739;
  border-color: rgba(248, 183, 57, .35);
  box-shadow: none;
}
.btn.sec:hover {
  background: rgba(248, 183, 57, .1);
  border-color: rgba(248, 183, 57, .6);
}

.btn.red {
  border-color: #ff6b6b;
  background: linear-gradient(180deg, #ff6b6b, #e04040);
  color: #fff;
  box-shadow: 0 4px 15px rgba(255, 107, 107, .2);
}
.btn.red:hover {
  box-shadow: 0 6px 20px rgba(255, 107, 107, .35);
}

.btn.grn {
  border-color: #6bcb77;
  background: linear-gradient(180deg, #6bcb77, #4aa85a);
  color: #fff;
  box-shadow: 0 4px 15px rgba(107, 203, 119, .2);
}
.btn.grn:hover {
  box-shadow: 0 6px 20px rgba(107, 203, 119, .35);
}

.btn:disabled {
  opacity: .35;
  cursor: default;
  transform: none !important;
  box-shadow: none !important;
}

.btn-group {
  display: flex;
  flex-direction: column;
  gap: 6px;
  align-items: center;
  margin-top: 8px;
}

/* ── Level grid ── */
.lgrid {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 8px;
  margin: 16px 0;
}

.lcell {
  aspect-ratio: 1;
  border: 2px solid #333;
  border-radius: 12px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  font-size: 18px;
  font-weight: 700;
  cursor: pointer;
  background: #14162a;
  transition: all .2s ease;
  padding: 4px;
  position: relative;
  overflow: hidden;
}

.lcell.u {
  border-color: #f8b739;
  color: #f8b739;
  background: linear-gradient(180deg, #1a1c38, #14162a);
}
.lcell.u:hover {
  background: rgba(248, 183, 57, .12);
  transform: scale(1.06);
  box-shadow: 0 0 15px rgba(248, 183, 57, .15);
}

.lcell:focus-visible,
.lcell.gp-focus {
  outline: none;
  transform: scale(1.06);
  box-shadow: 0 0 0 2px rgba(255,255,255,.15), 0 0 0 4px rgba(248, 183, 57, .55), 0 0 18px rgba(248, 183, 57, .22);
}

.lcell.l {
  border-color: #252540;
  color: #444;
  cursor: not-allowed;
  opacity: .6;
}

.lcell.c {
  border-color: #6bcb77;
  color: #6bcb77;
  background: linear-gradient(180deg, rgba(107,203,119,.08), transparent);
}

.lcell small {
  font-size: 8px;
  margin-top: 2px;
  opacity: .8;
}

/* ── Shop grid ── */
.sgrid {
  display: flex;
  flex-direction: column;
  gap: 7px;
  margin: 12px 0;
  max-height: 42vh;
  overflow-y: auto;
  padding-right: 4px;
}
.sgrid::-webkit-scrollbar { width: 4px; }
.sgrid::-webkit-scrollbar-track { background: transparent; }
.sgrid::-webkit-scrollbar-thumb { background: #333; border-radius: 4px; }

.srow {
  display: flex;
  align-items: center;
  gap: 10px;
  border: 2px solid #282840;
  border-radius: 12px;
  padding: 10px 14px;
  background: #14162a;
  transition: all .2s ease;
}
.srow:hover { background: #1a1c38; }

.srow.eq {
  border-color: #f8b739;
  background: rgba(248, 183, 57, .06);
  box-shadow: 0 0 12px rgba(248, 183, 57, .1);
}
.srow.own { border-color: #6bcb77; }

.sprev {
  width: 46px;
  height: 46px;
  border-radius: 10px;
  background: linear-gradient(135deg, #1e2048, #2a2d55);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 28px;
  flex-shrink: 0;
}

.sinfo { flex: 1; text-align: left; }
.sinfo b { font-size: 13px; color: #f8b739; }
.sinfo small { display: block; font-size: 10px; color: #777; margin-top: 2px; }

/* ── HUD ── */
.hud {
  position: fixed;
  top: max(0px, env(safe-area-inset-top));
  left: max(0px, env(safe-area-inset-left));
  right: max(0px, env(safe-area-inset-right));
  z-index: 20;
  display: none;
  padding: 6px 10px;
  pointer-events: none;
  gap: 4px;
}
.hud.on { display: flex; }

.hl, .hc, .hr { display: flex; align-items: center; gap: 5px; }
.hl { flex: 1; }
.hc { flex: 0 0 auto; }
.hr { flex: 1; justify-content: flex-end; }

.hi {
  background: rgba(0, 0, 0, .6);
  border-radius: 8px;
  padding: 4px 8px;
  font-size: 11px;
  font-weight: 700;
  color: #fff;
  display: flex;
  align-items: center;
  gap: 3px;
  white-space: nowrap;
  backdrop-filter: blur(4px);
  border: 1px solid rgba(255,255,255,.06);
}

.hb {
  pointer-events: auto;
  cursor: pointer;
  border: none;
  background: rgba(0, 0, 0, .6);
  color: #fff;
  border-radius: 8px;
  padding: 4px 8px;
  font-size: 13px;
  backdrop-filter: blur(4px);
  border: 1px solid rgba(255,255,255,.06);
  transition: background .15s;
}
.hb:hover { background: rgba(255,255,255,.15); }

.hprog {
  position: fixed;
  top: max(0px, env(safe-area-inset-top));
  left: max(0px, env(safe-area-inset-left));
  right: max(0px, env(safe-area-inset-right));
  height: 3px;
  z-index: 21;
  pointer-events: none;
}
.hprog div {
  height: 100%;
  background: linear-gradient(90deg, #f8b739, #6bcb77);
  transition: width .3s ease;
  border-radius: 0 2px 2px 0;
  box-shadow: 0 0 8px rgba(248, 183, 57, .3);
}

/* ── Touch controls ── */
.tc {
  position: fixed;
  inset: 0;
  z-index: 15;
  display: none;
  pointer-events: none;
  touch-action: none;
  width: var(--app-width, 100vw);
  height: var(--app-height, 100vh);
}
.tc.on { display: block; }

.tcl {
  position: absolute;
  left: max(10px, env(safe-area-inset-left));
  bottom: max(10px, env(safe-area-inset-bottom));
  display: flex;
  gap: 8px;
  pointer-events: auto;
  touch-action: none;
}

.tcb {
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  touch-action: none;
  -webkit-tap-highlight-color: transparent;
  -webkit-touch-callout: none;
  border: 2px solid rgba(255, 255, 255, .2);
  pointer-events: auto;
  transition: background .1s, transform .1s;
}

.tcm {
  width: 60px;
  height: 60px;
  background: rgba(255, 255, 255, .1);
  font-size: 22px;
  color: rgba(255, 255, 255, .6);
}
.tcm.p {
  background: rgba(255, 255, 255, .3);
  transform: scale(.95);
}

.tcj {
  position: absolute;
  right: max(16px, env(safe-area-inset-right));
  bottom: max(12px, env(safe-area-inset-bottom));
  width: 78px;
  height: 78px;
  background: rgba(248, 183, 57, .15);
  border-color: rgba(248, 183, 57, .35);
  font-size: 20px;
  color: rgba(248, 183, 57, .8);
  pointer-events: auto;
  touch-action: none;
}
.tcj.p {
  background: rgba(248, 183, 57, .4);
  transform: scale(.95);
}

.tcp {
  position: absolute;
  right: max(16px, env(safe-area-inset-right));
  top: max(50px, calc(env(safe-area-inset-top) + 18px));
  width: 44px;
  height: 44px;
  background: rgba(0, 0, 0, .4);
  font-size: 16px;
  color: rgba(255, 255, 255, .6);
  pointer-events: auto;
  touch-action: none;
}

/* ── Result stats ── */
.rst {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  gap: 7px;
  margin: 12px 0;
}

.rsb {
  background: linear-gradient(180deg, #1a1c38, #14162a);
  border: 1px solid #282840;
  border-radius: 10px;
  padding: 10px 8px;
  text-align: center;
}
.rsb b {
  display: block;
  font-size: 19px;
  color: #f8b739;
}
.rsb small {
  font-size: 9px;
  color: #666;
  text-transform: uppercase;
  letter-spacing: .5px;
}

/* ── Section dividers in shop ── */
.shop-section {
  font-size: 11px;
  color: #666;
  padding: 6px 0;
  border-bottom: 1px solid #1e2040;
  text-transform: uppercase;
  letter-spacing: 1px;
}

/* ── Coin display ── */
.coin-display {
  font-size: 15px;
  color: #f8b739;
  font-weight: 700;
  margin: 6px 0 10px;
}

/* ── Animations ── */
@keyframes fadeIn {
  from { opacity: 0; transform: translateY(10px); }
  to { opacity: 1; transform: translateY(0); }
}

.screen.active .card {
  animation: fadeIn .25s ease-out;
}

@keyframes pulse {
  0%, 100% { box-shadow: 0 0 0 0 rgba(248, 183, 57, .3); }
  50% { box-shadow: 0 0 0 8px rgba(248, 183, 57, 0); }
}

@media (max-width: 900px) and (orientation: landscape) {
  .tcm {
    width: 68px;
    height: 68px;
    font-size: 24px;
  }

  .tcj {
    width: 92px;
    height: 92px;
    font-size: 24px;
  }
}
