:root {
  --cp-bg-a: #e7eef4;
  --cp-bg-b: #d5dee8;
  --cp-ink: #152033;
  --cp-muted: #5b6b80;
  --cp-card: #f7f9fc;
  --cp-card-border: rgba(21, 32, 51, 0.08);
  --cp-line: #e2b422;
  --cp-exit: #0f9f6e;
  --cp-asphalt: #3a4554;
}

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

html,
body {
  margin: 0;
  padding: 0;
  width: 100%;
  height: 100%;
  overflow: hidden;
  background: var(--cp-bg-b);
  color: var(--cp-ink);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
  -webkit-tap-highlight-color: transparent;
}

.cp-atmosphere {
  position: fixed;
  inset: 0;
  pointer-events: none;
  background:
    radial-gradient(85% 50% at 50% -8%, #f5f8fb 0%, transparent 62%),
    linear-gradient(180deg, #e8eef3 0%, #d9e1ea 100%);
  z-index: 0;
}

.cp-app {
  position: relative;
  z-index: 1;
  width: 100%;
  height: 100%;
  min-height: min(100vh, 100dvh);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: space-between;
  padding: calc(10px + env(safe-area-inset-top, 0px)) calc(14px + env(safe-area-inset-right, 0px)) calc(12px + env(safe-area-inset-bottom, 0px)) calc(14px + env(safe-area-inset-left, 0px));
  gap: 8px;
}

/* ==========================================================================
   HUD — parking tickets
   ========================================================================== */
.cp-hud {
  width: min(100%, 480px);
  display: flex;
  align-items: stretch;
  gap: 8px;
  flex-shrink: 0;
}

.cp-chip {
  position: relative;
  border-radius: 14px;
  border: 1px solid var(--cp-card-border);
  background: var(--cp-card);
  padding: 6px 10px 6px 14px;
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  justify-content: center;
  min-height: 52px;
  box-shadow: 0 8px 20px rgba(21, 32, 51, 0.08);
  overflow: hidden;
}

.cp-chip::before {
  content: "";
  position: absolute;
  left: 0;
  top: 8px;
  bottom: 8px;
  width: 4px;
  border-radius: 0 2px 2px 0;
  background: var(--cp-line);
}

.cp-chip-label {
  font-size: 9px;
  font-weight: 800;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--cp-muted);
}

.cp-chip-value {
  font-size: 19px;
  font-weight: 800;
  line-height: 1.1;
  color: var(--cp-ink);
  margin-top: 1px;
}

.cp-chip-sub {
  font-size: 9px;
  font-weight: 800;
  letter-spacing: 0.1em;
  color: var(--cp-muted);
}

.cp-chip-badge {
  font-size: 9px;
  font-weight: 800;
  letter-spacing: 0.08em;
  color: var(--cp-muted);
  margin-top: 1px;
}

.cp-chip-level {
  flex: 1.35;
}

.cp-chip-moves {
  flex: 1;
}

.cp-chip-stars {
  flex: 0 0 auto;
  flex-direction: row;
  align-items: center;
  gap: 4px;
  padding: 6px 12px 6px 14px;
  min-width: 64px;
}

.cp-chip-stars::before {
  background: var(--cp-line);
}

.cp-chip-star-icon {
  color: #d97706;
  font-size: 16px;
  line-height: 1;
}

.cp-chip-stars .cp-chip-value {
  margin-top: 0;
  font-size: 18px;
  color: var(--cp-ink);
}

/* ==========================================================================
   Board
   ========================================================================== */
.cp-board-wrap {
  width: min(100%, 540px);
  flex: 1;
  min-height: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  margin: 0;
  position: relative;
}

.cp-canvas-3d {
  width: min(94vw, calc(min(100vh, 100dvh) - 200px), 520px);
  height: min(94vw, calc(min(100vh, 100dvh) - 200px), 520px);
  max-width: 100%;
  max-height: 100%;
  display: block;
  touch-action: none;
  border-radius: 22px;
  box-shadow:
    0 18px 40px rgba(21, 32, 51, 0.22),
    0 0 0 6px #c5ced8,
    0 0 0 7px rgba(21, 32, 51, 0.12);
  outline: none;
  background: var(--cp-asphalt);
}

.cp-hint {
  position: absolute;
  left: 50%;
  bottom: 14px;
  transform: translateX(-50%);
  margin: 0;
  padding: 8px 14px;
  border-radius: 999px;
  background: rgba(247, 249, 252, 0.94);
  color: var(--cp-ink);
  font-size: 13px;
  font-weight: 800;
  letter-spacing: 0.04em;
  box-shadow: 0 8px 20px rgba(21, 32, 51, 0.16);
  pointer-events: none;
  z-index: 2;
}

.cp-hint[hidden] {
  display: none !important;
}

/* ==========================================================================
   Bottom actions
   ========================================================================== */
.cp-actions {
  width: min(100%, 480px);
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  padding: 4px 0;
  flex-shrink: 0;
}

.cp-action-btn {
  height: 48px;
  border-radius: 14px;
  font-size: 13px;
  font-weight: 800;
  letter-spacing: 0.06em;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  cursor: pointer;
  transition: transform 0.1s ease, background 0.15s ease, opacity 0.2s ease;
}

.cp-action-btn-main {
  flex: 1.35;
  max-width: 220px;
  border: none;
  background: #1f2937;
  color: #f8fafc;
  box-shadow: 0 8px 18px rgba(21, 32, 51, 0.22);
}

.cp-action-btn-main:active:not(:disabled) {
  transform: scale(0.96);
  background: #111827;
}

.cp-action-btn-quiet {
  flex: 0.85;
  max-width: 140px;
  border: 1px solid rgba(21, 32, 51, 0.12);
  background: transparent;
  color: var(--cp-muted);
  box-shadow: none;
}

.cp-action-btn-quiet:active:not(:disabled) {
  transform: scale(0.96);
  background: rgba(21, 32, 51, 0.06);
  color: var(--cp-ink);
}

.cp-action-btn:disabled {
  opacity: 0.38;
  cursor: not-allowed;
}

/* ==========================================================================
   Modals
   ========================================================================== */
.cp-modal-overlay {
  position: fixed;
  inset: 0;
  z-index: 100;
  background: rgba(21, 32, 51, 0.42);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  animation: fadeIn 0.2s ease;
}

.cp-modal-overlay[hidden] {
  display: none !important;
}

.cp-modal-card {
  width: min(100%, 340px);
  background: #f7f9fc;
  border: 1px solid var(--cp-card-border);
  border-radius: 24px;
  padding: 24px 20px;
  text-align: center;
  box-shadow: 0 24px 48px rgba(21, 32, 51, 0.22);
  animation: scaleUp 0.25s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

.cp-modal-eyebrow {
  font-size: 12px;
  font-weight: 800;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--cp-exit);
  margin: 0 0 8px;
}

.cp-modal-title {
  font-size: 22px;
  font-weight: 900;
  color: var(--cp-ink);
  margin: 0 0 8px;
}

.cp-modal-copy {
  font-size: 14px;
  color: var(--cp-muted);
  line-height: 1.45;
  margin: 0 0 20px;
}

.cp-stars-row {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  margin: 14px 0 10px;
}

.cp-star {
  font-size: 38px;
  line-height: 1;
  color: #cbd5e1;
  transform: scale(0.6);
  opacity: 0;
  display: inline-block;
}

.cp-star.is-earned {
  color: #d97706;
  animation: starPop 0.4s cubic-bezier(0.175, 0.885, 0.32, 1.275) forwards;
}

.cp-star.is-empty {
  color: #cbd5e1;
  opacity: 0.7;
  transform: scale(1);
}

@keyframes starPop {
  0% { transform: scale(0.2); opacity: 0; }
  60% { transform: scale(1.25); opacity: 1; }
  100% { transform: scale(1); opacity: 1; }
}

.cp-modal-summary {
  font-size: 13px;
  color: var(--cp-muted);
  margin: 6px 0 12px;
}

.cp-modal-summary b {
  color: var(--cp-ink);
}

.cp-modal-total {
  font-size: 15px;
  font-weight: 800;
  letter-spacing: 0.08em;
  color: var(--cp-muted);
  margin: 0 0 20px;
}

.cp-modal-total span {
  color: #d97706;
  font-size: 18px;
}

.cp-modal-actions {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.cp-btn-primary {
  width: 100%;
  height: 50px;
  border-radius: 16px;
  border: none;
  background: #1f2937;
  color: #fff;
  font-size: 15px;
  font-weight: 900;
  letter-spacing: 0.06em;
  display: flex;
  align-items: center;
  justify-content: center;
  text-decoration: none;
  cursor: pointer;
  box-shadow: 0 8px 18px rgba(21, 32, 51, 0.2);
  transition: transform 0.1s ease;
}

.cp-btn-primary:active {
  transform: scale(0.96);
}

.cp-btn-secondary {
  width: 100%;
  height: 44px;
  border-radius: 14px;
  border: 1px solid rgba(21, 32, 51, 0.12);
  background: transparent;
  color: var(--cp-ink);
  font-size: 14px;
  font-weight: 800;
  letter-spacing: 0.06em;
  cursor: pointer;
}

@keyframes fadeIn {
  from { opacity: 0; }
  to { opacity: 1; }
}

@keyframes scaleUp {
  from { transform: scale(0.85); opacity: 0; }
  to { transform: scale(1); opacity: 1; }
}

.cp-victory-confetti {
  position: fixed;
  inset: 0;
  z-index: 90;
  overflow: hidden;
  pointer-events: none;
}

.cp-victory-confetti[hidden] {
  display: none;
}

.cp-victory-confetti span {
  position: absolute;
  top: -5%;
  opacity: 0;
  will-change: transform, opacity;
  animation: cpConfettiFall 1400ms cubic-bezier(0.22, 0.8, 0.36, 1) forwards;
}

.cp-confetti-rectangle {
  width: 9px;
  height: 15px;
  border-radius: 2px;
}

.cp-confetti-circle {
  width: 10px;
  height: 10px;
  border-radius: 50%;
}

.cp-confetti-ribbon {
  width: 7px;
  height: 20px;
  border-radius: 1px;
}

@keyframes cpConfettiFall {
  0% {
    opacity: 0;
    transform: translate3d(0, -6vh, 0) rotate(0deg) scale(0.6);
  }
  15% {
    opacity: 1;
  }
  75% {
    opacity: 0.9;
  }
  100% {
    opacity: 0;
    transform: translate3d(var(--confetti-drift, 0px), 112vh, 0) rotate3d(1, 1, 0, var(--confetti-rot, 720deg)) scale(0.9);
  }
}

/* ==========================================================================
   Responsive
   ========================================================================== */
@media (max-height: 720px) {
  .cp-chip {
    min-height: 46px;
    padding: 4px 8px 4px 12px;
  }
  .cp-chip-value {
    font-size: 17px;
  }
  .cp-action-btn {
    height: 44px;
    font-size: 12px;
  }
}

@media (min-width: 600px) {
  .cp-app {
    padding: calc(18px + env(safe-area-inset-top, 0px)) calc(24px + env(safe-area-inset-right, 0px)) calc(20px + env(safe-area-inset-bottom, 0px)) calc(24px + env(safe-area-inset-left, 0px));
    gap: 14px;
  }

  .cp-hud,
  .cp-actions {
    width: min(100%, 560px);
    gap: 12px;
  }

  .cp-chip {
    min-height: 64px;
    padding: 8px 14px 8px 16px;
    border-radius: 18px;
  }

  .cp-chip-label {
    font-size: 11px;
  }

  .cp-chip-value {
    font-size: clamp(22px, 2.4vw, 28px);
  }

  .cp-chip-sub,
  .cp-chip-badge {
    font-size: 11px;
  }

  .cp-chip-stars {
    min-width: 84px;
  }

  .cp-board-wrap {
    width: min(100%, 720px);
  }

  .cp-canvas-3d {
    width: min(88vw, calc(min(100vh, 100dvh) - 240px), 680px);
    height: min(88vw, calc(min(100vh, 100dvh) - 240px), 680px);
    border-radius: 28px;
  }

  .cp-hint {
    font-size: 15px;
    padding: 10px 18px;
  }

  .cp-action-btn {
    height: 56px;
    font-size: 15px;
    border-radius: 16px;
  }

  .cp-action-btn-main {
    max-width: 280px;
  }

  .cp-action-btn-quiet {
    max-width: 180px;
  }

  .cp-modal-card {
    width: min(100%, 400px);
    padding: 32px 28px;
    border-radius: 28px;
  }

  .cp-modal-title {
    font-size: 26px;
  }

  .cp-modal-copy {
    font-size: 16px;
  }

  .cp-btn-primary {
    height: 56px;
    font-size: 16px;
  }
}

@media (min-width: 900px) {
  .cp-hud,
  .cp-actions {
    width: min(100%, 680px);
  }

  .cp-board-wrap {
    width: min(100%, 920px);
  }

  .cp-canvas-3d {
    width: min(90vw, calc(min(100vh, 100dvh) - 240px), 880px);
    height: min(90vw, calc(min(100vh, 100dvh) - 240px), 880px);
  }
}

@media (min-width: 1024px) {
  .cp-app {
    padding: calc(22px + env(safe-area-inset-top, 0px)) calc(32px + env(safe-area-inset-right, 0px)) calc(24px + env(safe-area-inset-bottom, 0px)) calc(32px + env(safe-area-inset-left, 0px));
    gap: 18px;
  }

  .cp-hud,
  .cp-actions {
    width: min(100%, 760px);
    gap: 14px;
  }

  .cp-chip {
    min-height: 72px;
    padding: 10px 16px 10px 18px;
    border-radius: 20px;
  }

  .cp-chip-label {
    font-size: 12px;
  }

  .cp-chip-value {
    font-size: clamp(26px, 2.2vw, 32px);
  }

  .cp-chip-sub,
  .cp-chip-badge {
    font-size: 12px;
  }

  .cp-board-wrap {
    width: min(100%, 1100px);
  }

  .cp-canvas-3d {
    width: min(92vw, calc(min(100vh, 100dvh) - 220px), 1080px);
    height: min(92vw, calc(min(100vh, 100dvh) - 220px), 1080px);
    border-radius: 32px;
  }

  .cp-action-btn {
    height: 62px;
    font-size: 16px;
    border-radius: 18px;
  }

  .cp-modal-card {
    width: min(100%, 460px);
    padding: 36px 32px;
  }
}

@media (orientation: landscape) and (min-width: 700px) {
  .cp-app {
    padding-top: calc(14px + env(safe-area-inset-top, 0px));
    padding-bottom: calc(14px + env(safe-area-inset-bottom, 0px));
    gap: 10px;
  }

  .cp-hud,
  .cp-actions {
    width: min(100%, 560px);
  }

  .cp-chip {
    min-height: 54px;
  }

  .cp-canvas-3d {
    width: min(70vh, 58vw, calc(min(100vh, 100dvh) - 180px), 640px);
    height: min(70vh, 58vw, calc(min(100vh, 100dvh) - 180px), 640px);
  }

  .cp-action-btn {
    height: 52px;
  }
}

@media (orientation: landscape) and (min-width: 1000px) {
  .cp-hud,
  .cp-actions {
    width: min(100%, 680px);
  }

  .cp-canvas-3d {
    width: min(86vh, 54vw, calc(min(100vh, 100dvh) - 150px), 900px);
    height: min(86vh, 54vw, calc(min(100vh, 100dvh) - 150px), 900px);
  }

  .cp-action-btn {
    height: 56px;
  }
}
