:root {
  --bg-deep: #030712;
  --glass-bg: rgba(15, 23, 42, 0.78);
  --glass-border: rgba(56, 189, 248, 0.28);
  --cyan-glow: #38bdf8;
  --violet-glow: #a855f7;
  --text-main: #f8fafc;
  --text-muted: #94a3b8;
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
}

html, body {
  width: 100%;
  height: 100%;
  overflow: hidden;
  background: radial-gradient(circle at 50% 20%, #0f172a 0%, #030712 78%);
  color: var(--text-main);
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'SF Pro Display', sans-serif;
  touch-action: none;
}

/* ============================================================================
   PORTRAIT MODE (DEFAULT):
   - Row 1 (Center Col): Compact Top Status + Huge Square 3D Well
   - Row 2 (Bottom): Big Left Card (КАРМАН) + Big Right Card (ДАЛЕЕ / СБРОС)
   ============================================================================ */
.app-shell {
  width: 100%;
  height: 100dvh;
  max-width: 480px;
  margin: 0 auto;
  display: grid;
  grid-template-columns: 1fr 1fr;
  grid-template-rows: 1fr auto;
  grid-template-areas:
    "center center"
    "left   right";
  padding-top: calc(8px + var(--tg-safe-area-inset-top, env(safe-area-inset-top, 0px)) + var(--tg-content-safe-area-inset-top, 0px));
  padding-bottom: calc(10px + var(--tg-safe-area-inset-bottom, env(safe-area-inset-bottom, 0px)));
  padding-left: calc(10px + env(safe-area-inset-left, 0px));
  padding-right: calc(10px + env(safe-area-inset-right, 0px));
  gap: 8px;
  position: relative;
}

.center-col {
  grid-area: center;
  min-height: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: space-between;
  gap: 6px;
}

.side-col {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.left-col {
  grid-area: left;
}

.right-col {
  grid-area: right;
}

/* Compact subtle top status bar (centered so Telegram corner buttons don't cover it) */
.status-strip {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: rgba(15, 23, 42, 0.65);
  border: 1px solid rgba(56, 189, 248, 0.2);
  border-radius: 999px;
  padding: 4px 10px;
  gap: 8px;
  backdrop-filter: blur(10px);
}

.brand-mini {
  display: flex;
  align-items: center;
  gap: 6px;
}

.brand-dot {
  width: 10px;
  height: 10px;
  border-radius: 3px;
  background: linear-gradient(135deg, #38bdf8, #d946ef);
  box-shadow: 0 0 8px #38bdf8;
}

.brand-title {
  font-size: 13px;
  font-weight: 900;
  letter-spacing: 1.6px;
  color: #e2e8f0;
}

.stats-inline {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 11px;
  color: var(--text-muted);
}

.stats-inline b {
  color: #38bdf8;
  font-weight: 800;
  font-variant-numeric: tabular-nums;
}

.icon-btns {
  display: flex;
  align-items: center;
  gap: 4px;
}

.icon-pill {
  background: rgba(30, 41, 59, 0.8);
  border: 1px solid rgba(56, 189, 248, 0.25);
  color: #cbd5e1;
  font-size: 11px;
  font-weight: 700;
  padding: 3px 8px;
  border-radius: 999px;
  cursor: pointer;
}

.icon-pill.active {
  border-color: #38bdf8;
  color: #ffffff;
}

/* Main 3D Well Stage + Ultra-Compact Depth Radar */
.stage-area {
  flex: 1;
  width: 100%;
  min-height: 0;
  display: flex;
  gap: 5px;
  align-items: center;
  justify-content: center;
  position: relative;
  touch-action: none;
}

.depth-radar {
  width: 8px;
  height: 100%;
  background: rgba(15, 23, 42, 0.55);
  border-radius: 6px;
  padding: 2px 1px;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  gap: 2px;
}

.radar-slot {
  display: flex;
  align-items: center;
  flex: 1;
}

.radar-slot.almost-full {
  animation: pulseSlot 0.8s infinite alternate;
}

@keyframes pulseSlot {
  from { filter: brightness(1); }
  to { filter: brightness(1.65); }
}

.radar-bar-bg {
  width: 100%;
  height: 100%;
  background: rgba(2, 6, 23, 0.85);
  border-radius: 2px;
  overflow: hidden;
}

.radar-bar-fill {
  height: 100%;
  border-radius: 2px;
  transition: width 0.2s ease;
}

.well-wrapper {
  position: relative;
  background: #02050d;
  border: 1.5px solid rgba(56, 189, 248, 0.42);
  border-radius: 16px;
  box-shadow: 0 0 28px rgba(14, 165, 233, 0.15), inset 0 0 24px rgba(56, 189, 248, 0.08);
  overflow: hidden;
  display: flex;
  align-items: center;
  justify-content: center;
}

#well-canvas {
  width: 100%;
  height: 100%;
  display: block;
  touch-action: none;
  cursor: grab;
}

#well-canvas:active {
  cursor: grabbing;
}

.gesture-toast {
  position: absolute;
  bottom: 10px;
  left: 50%;
  transform: translateX(-50%) translateY(8px);
  background: rgba(14, 165, 233, 0.26);
  border: 1px solid rgba(56, 189, 248, 0.72);
  color: #f0f9ff;
  font-size: 11px;
  font-weight: 700;
  padding: 4px 12px;
  border-radius: 999px;
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.16s ease, transform 0.16s ease;
  backdrop-filter: blur(8px);
  white-space: nowrap;
}

.gesture-toast.active {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

/* Large Action Cards: КАРМАН (Hold) and ДАЛЕЕ (Next + Hard Drop) */
.action-card {
  width: 100%;
  height: 108px;
  background: linear-gradient(180deg, rgba(15, 23, 42, 0.85), rgba(9, 14, 28, 0.95));
  border: 1.5px solid rgba(56, 189, 248, 0.34);
  border-radius: 16px;
  padding: 7px 10px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: space-between;
  cursor: pointer;
  backdrop-filter: blur(12px);
  transition: transform 0.12s ease, border-color 0.18s ease, box-shadow 0.18s ease;
}

.action-card.drop-card {
  border-color: rgba(232, 121, 249, 0.42);
  background: linear-gradient(180deg, rgba(30, 20, 50, 0.82), rgba(12, 14, 30, 0.95));
}

.action-card:active {
  transform: scale(0.95);
  border-color: #38bdf8;
  box-shadow: 0 0 18px rgba(56, 189, 248, 0.35);
}

.action-card-top {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.action-title {
  font-size: 11px;
  font-weight: 900;
  letter-spacing: 0.7px;
  color: #e2e8f0;
}

.action-badge {
  font-size: 9px;
  font-weight: 800;
  padding: 2px 6px;
  border-radius: 6px;
  background: rgba(56, 189, 248, 0.16);
  color: #7dd3fc;
}

.drop-card .action-badge {
  background: rgba(232, 121, 249, 0.2);
  color: #f5d0fe;
}

/* Side Touchpads (Hidden in Portrait Mode, Shown in Landscape Mode) */
.side-pad-wrap {
  display: none;
}

/* ============================================================================
   LANDSCAPE MODE (Horizontal Phone):
   - Center: Full-height Square 3D Well (bottom to top)
   - Left Column: КАРМАН (above) + Left Rotation Field (below)
   - Right Column: ДАЛЕЕ / СБРОС (above) + Right Movement Field (below)
   ============================================================================ */
@media (orientation: landscape) and (min-aspect-ratio: 1/1) {
  .app-shell {
    max-width: 100vw;
    grid-template-columns: 1fr auto 1fr;
    grid-template-rows: 1fr;
    grid-template-areas: "left center right";
    padding-top: 6px;
    padding-bottom: calc(6px + var(--tg-safe-area-inset-bottom, env(safe-area-inset-bottom, 0px)));
    padding-left: calc(12px + env(safe-area-inset-left, 0px));
    padding-right: calc(12px + env(safe-area-inset-right, 0px));
    gap: 10px;
    align-items: stretch;
  }

  /* Leave top clearance on Left & Right wings so Telegram's Close / Menu widget buttons never overlap! */
  .side-col {
    padding-top: calc(36px + var(--tg-safe-area-inset-top, 0px));
    justify-content: flex-end;
    align-items: center;
    gap: 8px;
    min-height: 0;
  }

  .center-col {
    height: 100%;
    justify-content: center;
    gap: 4px;
  }

  .status-strip {
    padding: 2px 10px;
    height: 24px;
  }

  .brand-title {
    font-size: 11.5px;
  }

  .stats-inline {
    font-size: 10px;
  }

  .action-card {
    height: 82px;
    max-width: 185px;
    padding: 5px 8px;
  }

  .action-card canvas {
    height: 46px;
  }

  .side-pad-wrap {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    flex: 1;
    width: 100%;
    max-width: 185px;
    min-height: 0;
    position: relative;
    border-radius: 16px;
    background: rgba(2, 6, 23, 0.88);
    border: 1.5px solid rgba(56, 189, 248, 0.42);
    box-shadow: inset 0 0 18px rgba(56, 189, 248, 0.14);
    overflow: hidden;
  }

  .left-col .side-pad-wrap {
    border-color: rgba(168, 85, 247, 0.45);
    box-shadow: inset 0 0 18px rgba(168, 85, 247, 0.15);
  }

  .side-pad-canvas {
    width: 100%;
    height: 100%;
    display: block;
    touch-action: none;
    cursor: pointer;
  }

  .pad-top-label {
    position: absolute;
    top: 5px;
    left: 50%;
    transform: translateX(-50%);
    font-size: 8.5px;
    font-weight: 800;
    letter-spacing: 0.5px;
    color: rgba(226, 232, 240, 0.78);
    pointer-events: none;
    white-space: nowrap;
  }

  .pad-caption {
    position: absolute;
    bottom: 5px;
    left: 50%;
    transform: translateX(-50%);
    font-size: 8px;
    font-weight: 700;
    color: rgba(125, 211, 252, 0.8);
    pointer-events: none;
    white-space: nowrap;
  }
}

/* Overlays & Pre-Game Mode Lobby */
.overlay {
  position: absolute;
  inset: 0;
  background: rgba(3, 7, 18, 0.93);
  backdrop-filter: blur(14px);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 9px;
  padding: 14px;
  text-align: center;
  z-index: 30;
  overflow-y: auto;
}

.overlay.hidden {
  display: none;
}

.lobby-header {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
}

.overlay-title {
  font-size: 24px;
  font-weight: 900;
  letter-spacing: 3px;
  background: linear-gradient(90deg, #38bdf8, #a855f7, #f43f5e);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
}

.lobby-subtitle {
  font-size: 10.5px;
  color: #94a3b8;
}

.mode-cards {
  width: 100%;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.mode-card {
  width: 100%;
  text-align: left;
  background: rgba(15, 23, 42, 0.85);
  border: 1.5px solid rgba(56, 189, 248, 0.22);
  border-radius: 11px;
  padding: 7px 10px;
  cursor: pointer;
  transition: all 0.16s ease;
}

.mode-card.selected {
  background: rgba(14, 165, 233, 0.16);
  border-color: #38bdf8;
  box-shadow: 0 0 14px rgba(56, 189, 248, 0.25);
}

.mode-card-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 2px;
}

.mode-card-name {
  font-size: 12px;
  font-weight: 800;
  color: #f8fafc;
}

.mode-card-spec {
  font-size: 9.5px;
  font-weight: 700;
  color: #38bdf8;
  background: rgba(56, 189, 248, 0.14);
  padding: 2px 6px;
  border-radius: 99px;
}

.mode-card-desc {
  font-size: 10px;
  color: #94a3b8;
  line-height: 1.28;
}

.spectrum-preview {
  width: 100%;
  display: flex;
  flex-direction: column;
  gap: 3px;
  background: rgba(15, 23, 42, 0.65);
  border-radius: 8px;
  padding: 5px 9px;
  border: 1px solid rgba(148, 163, 184, 0.15);
}

.spectrum-labels {
  display: flex;
  justify-content: space-between;
  font-size: 8.5px;
  font-weight: 700;
  color: #94a3b8;
}

.spectrum-bar {
  height: 6px;
  border-radius: 3px;
  background: linear-gradient(90deg, #2563eb, #06b6d4, #10b981, #84cc16, #eab308, #f97316, #ef4444, #d946ef);
}

.overlay-score {
  font-size: 15px;
  color: #cbd5e1;
}

.btn-row {
  display: flex;
  gap: 8px;
  width: 100%;
  justify-content: center;
}

.btn-primary {
  background: linear-gradient(135deg, #0ea5e9, #6366f1, #a855f7);
  color: #ffffff;
  font-size: 13.5px;
  font-weight: 800;
  letter-spacing: 0.6px;
  border: none;
  padding: 11px 24px;
  border-radius: 999px;
  cursor: pointer;
  box-shadow: 0 0 20px rgba(56, 189, 248, 0.45);
  transition: transform 0.15s ease;
}

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

.btn-secondary {
  background: rgba(30, 41, 59, 0.9);
  border: 1px solid rgba(148, 163, 184, 0.35);
  color: #e2e8f0;
  font-size: 12.5px;
  font-weight: 700;
  padding: 11px 16px;
  border-radius: 999px;
  cursor: pointer;
}
