/* ==========================================================================
   Chagokchak - Pure Arcade 100dvh Stage + Scrollable Content
   ========================================================================== */

:root {
  --primary-accent: #6366F1;
  --primary-hover: #4F46E5;
  --secondary-accent: #06B6D4;
  --highlight: #10B981;
  --danger-accent: #EF4444;
  --danger-hover: #DC2626;

  --board-bg: #0B0F19;
  --board-grid: rgba(255, 255, 255, 0.04);
  --board-border: #1E293B;

  --panel-bg: rgba(30, 41, 59, 0.75);
  --panel-border: rgba(148, 163, 184, 0.15);

  --radius-sm: 6px;
  --radius-md: 10px;
  --radius-lg: 14px;
}

body.chagokchak-page-body {
  margin: 0;
  padding: 0;
  background-color: #0F172A;
  color: #F8FAFC;
  overflow-x: hidden;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}

/* ==========================================================================
   1. STRICT 100DVH SINGLE SCREEN GAME STAGE
   ========================================================================== */
.chagokchak-stage-wrapper {
  height: 100dvh;
  min-height: 100dvh;
  max-height: 100dvh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  position: relative;
  box-sizing: border-box;
}

/* Navigation Bar */
.subpage-nav {
  height: 44px;
  padding: 0 1rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-bottom: 1px solid rgba(148, 163, 184, 0.12);
  background: rgba(15, 23, 42, 0.95);
  backdrop-filter: blur(8px);
  z-index: 30;
  flex-shrink: 0;
}

.back-link {
  color: var(--text-secondary);
  text-decoration: none;
  font-size: 0.85rem;
  font-weight: 500;
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  transition: color 0.15s ease;
}

.back-link:hover {
  color: var(--primary-accent);
}

.subpage-nav-title {
  font-size: 0.95rem;
  font-weight: 700;
  color: #F8FAFC;
  letter-spacing: -0.01em;
  margin: 0;
}

.ctrl-btn-top {
  background: rgba(30, 41, 59, 0.8);
  border: 1px solid rgba(148, 163, 184, 0.2);
  color: var(--text-secondary);
  padding: 0.25rem 0.7rem;
  border-radius: 9999px;
  font-size: 0.78rem;
  cursor: pointer;
  font-weight: 600;
  transition: all 0.15s ease;
}

.ctrl-btn-top:hover {
  color: #fff;
  border-color: var(--primary-accent);
}

/* Chagokchak App Container inside Stage */
.chagokchak-app-container {
  flex: 1;
  min-height: 0;
  max-width: 1000px;
  width: 100%;
  margin: 0 auto;
  padding: 0.4rem 1rem 0.6rem;
  box-sizing: border-box;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  align-items: center;
  overflow: hidden;
}

/* 3-Column Layout */
.chagokchak-layout {
  flex: 1;
  min-height: 0;
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 1.25rem;
  width: 100%;
}

/* Side Columns */
.chagokchak-side-col {
  width: 130px;
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  justify-content: center;
}

.panel-box {
  background: var(--panel-bg);
  border: 1px solid var(--panel-border);
  border-radius: var(--radius-md);
  padding: 0.6rem 0.5rem;
  box-shadow: 0 4px 15px rgba(0, 0, 0, 0.2);
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
}

.panel-label {
  font-size: 0.65rem;
  font-weight: 800;
  letter-spacing: 0.1em;
  color: var(--text-secondary);
  text-transform: uppercase;
  margin-bottom: 0.25rem;
}

.stat-value {
  font-family: 'Inter', monospace;
  font-size: 1.35rem;
  font-weight: 800;
  color: #F8FAFC;
  line-height: 1.1;
}

.stat-value.accent {
  color: var(--secondary-accent);
  text-shadow: 0 0 10px rgba(6, 182, 212, 0.4);
}

.stat-value.highlight {
  color: var(--highlight);
}

.key-hint {
  font-size: 0.62rem;
  color: #64748B;
  margin-top: 0.25rem;
}

.canvas-wrapper {
  background: rgba(11, 15, 25, 0.85);
  border: 1px solid rgba(148, 163, 184, 0.12);
  border-radius: var(--radius-sm);
  display: flex;
  align-items: center;
  justify-content: center;
}

.hold-canvas-wrap {
  width: 90px;
  height: 90px;
}

#hold-canvas {
  width: 90px;
  height: 90px;
  display: block;
}

.next-canvas-wrap {
  width: 90px;
  height: 240px;
}

#next-canvas {
  width: 90px;
  height: 240px;
  display: block;
}

/* Center Matrix Column */
.chagokchak-matrix-col {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  height: 100%;
  max-height: 100%;
}

.matrix-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  width: 100%;
  margin-bottom: 0.35rem;
  min-height: 22px;
}

.matrix-status-pill {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  padding: 0.15rem 0.55rem;
  background: rgba(30, 41, 59, 0.8);
  border: 1px solid rgba(148, 163, 184, 0.15);
  border-radius: 9999px;
  font-size: 0.7rem;
  font-weight: 700;
  color: #94A3B8;
}

.status-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: #10B981;
  box-shadow: 0 0 6px #10B981;
}

.combo-b2b-display {
  font-size: 0.72rem;
  font-weight: 800;
  color: #F59E0B;
}

.matrix-viewport {
  position: relative;
  background: var(--board-bg);
  border: 2px solid var(--board-border);
  border-radius: var(--radius-md);
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.5), 0 0 20px rgba(99, 102, 241, 0.12);
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  height: calc(100dvh - 130px);
  max-height: 520px;
  min-height: 300px;
  aspect-ratio: 1 / 2;
}

#matrix-canvas {
  height: 100%;
  width: auto;
  aspect-ratio: 1 / 2;
  display: block;
  image-rendering: pixelated;
}

/* Overlays */
.matrix-overlay {
  position: absolute;
  inset: 0;
  background: rgba(11, 15, 25, 0.88);
  backdrop-filter: blur(4px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 20;
  transition: opacity 0.2s ease;
}

.matrix-overlay.hidden {
  display: none !important;
}

.overlay-card {
  background: #1E293B;
  border: 1px solid rgba(148, 163, 184, 0.2);
  border-radius: var(--radius-md);
  padding: 1.25rem 1rem;
  text-align: center;
  max-width: 220px;
  box-shadow: 0 10px 25px rgba(0, 0, 0, 0.4);
}

.overlay-card .overlay-title,
.overlay-card h2 {
  font-size: 1.2rem;
  font-weight: 800;
  color: #F8FAFC;
  margin: 0 0 0.35rem 0;
}

.overlay-card p {
  font-size: 0.78rem;
  color: #94A3B8;
  margin: 0 0 1rem 0;
}

.play-btn {
  background: var(--primary-accent);
  color: white;
  border: none;
  padding: 0.65rem 1.2rem;
  border-radius: 8px;
  font-size: 0.88rem;
  font-weight: 700;
  cursor: pointer;
  width: 100%;
  transition: all 0.15s ease;
  box-shadow: 0 4px 12px rgba(99, 102, 241, 0.3);
}

.play-btn:hover {
  background: var(--primary-hover);
  transform: translateY(-1px);
}

.play-btn.danger {
  background: var(--danger-accent);
  box-shadow: 0 4px 12px rgba(239, 68, 68, 0.3);
}

.final-stats {
  font-size: 0.8rem;
  color: #E2E8F0;
  margin-bottom: 1rem;
  line-height: 1.5;
}

/* Desktop Compact 1-line Controls Bar */
.keyboard-guide {
  width: 100%;
  max-width: 700px;
  padding: 0.35rem 0.75rem;
  background: rgba(30, 41, 59, 0.5);
  border: 1px solid rgba(148, 163, 184, 0.1);
  border-radius: 9999px;
  margin-top: 0.35rem;
  flex-shrink: 0;
}

.guide-grid {
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 0.8rem;
  flex-wrap: wrap;
}

.guide-item {
  font-size: 0.7rem;
  color: #94A3B8;
  display: inline-flex;
  align-items: center;
  gap: 0.25rem;
}

.key-badge {
  background: rgba(15, 23, 42, 0.8);
  border: 1px solid rgba(148, 163, 184, 0.2);
  padding: 0.1rem 0.35rem;
  border-radius: 4px;
  font-family: monospace;
  font-size: 0.68rem;
  font-weight: 700;
  color: #F8FAFC;
}

/* Hidden by default on Desktop */
.mobile-top-strip {
  display: none;
}

.touch-controls {
  display: none;
}

/* ==========================================================================
   📱 Mobile Viewport Optimization (max-width: 768px)
   ========================================================================== */
@media (max-width: 768px) {
  .subpage-nav {
    height: 38px;
    padding: 0 0.75rem;
  }

  .nav-extra-actions a[href*="sitemap"] {
    display: none !important;
  }

  .subpage-nav-title {
    font-size: 0.85rem;
  }

  .back-link {
    font-size: 0.78rem;
  }

  .ctrl-btn-top {
    padding: 0.2rem 0.55rem;
    font-size: 0.72rem;
  }

  .chagokchak-app-container {
    padding: 0.25rem 0.5rem;
    justify-content: space-between;
  }

  /* Mobile Top Status Strip */
  .mobile-top-strip {
    display: flex !important;
    width: 100%;
    max-width: 360px;
    height: 42px;
    background: rgba(30, 41, 59, 0.85);
    border: 1px solid rgba(148, 163, 184, 0.15);
    border-radius: 8px;
    padding: 2px 8px;
    align-items: center;
    justify-content: space-between;
    flex-shrink: 0;
    box-sizing: border-box;
  }

  .mobile-strip-item {
    display: flex;
    align-items: center;
    gap: 4px;
  }

  .mobile-slot-label {
    font-size: 0.6rem;
    font-weight: 800;
    color: #94A3B8;
  }

  #mobile-hold-canvas, #mobile-next-canvas {
    width: 34px !important;
    height: 34px !important;
    background: rgba(11, 15, 25, 0.7);
    border: 1px solid rgba(148, 163, 184, 0.12);
    border-radius: 4px;
    display: block;
  }

  .mobile-strip-stats {
    display: flex;
    align-items: center;
    gap: 8px;
  }

  .m-stat-pill {
    display: flex;
    align-items: baseline;
    gap: 4px;
  }

  .m-stat-label {
    font-size: 0.58rem;
    font-weight: 700;
    color: #64748B;
  }

  .m-stat-val {
    font-family: 'Inter', monospace;
    font-size: 0.95rem;
    font-weight: 800;
    color: #06B6D4;
  }

  .m-stat-row-sub {
    display: flex;
    gap: 4px;
  }

  .m-sub-badge {
    background: rgba(15, 23, 42, 0.6);
    border: 1px solid rgba(148, 163, 184, 0.1);
    padding: 1px 4px;
    border-radius: 4px;
    font-size: 0.6rem;
    color: #94A3B8;
  }

  .m-sub-badge strong {
    color: #F8FAFC;
  }

  /* Hide Desktop Side Columns & Key Guide on mobile */
  .chagokchak-side-col {
    display: none !important;
  }

  .keyboard-guide {
    display: none !important;
  }

  /* Center Game Area */
  .chagokchak-layout {
    flex: 1;
    min-height: 0;
    padding: 2px 0;
    margin: 0;
    align-items: center;
    justify-content: center;
  }

  .chagokchak-matrix-col {
    height: 100%;
    max-height: 100%;
  }

  .matrix-header {
    display: none;
  }

  .matrix-viewport {
    height: 100% !important;
    max-height: calc(100dvh - 215px) !important;
    min-height: 220px !important;
    aspect-ratio: 1 / 2;
    border-width: 1.5px;
    border-radius: 8px;
  }

  #matrix-canvas {
    height: 100% !important;
    width: auto !important;
    aspect-ratio: 1 / 2 !important;
  }

  .overlay-card {
    max-width: 170px;
    padding: 1rem 0.8rem;
  }

  .overlay-card .overlay-title,
  .overlay-card h2 {
    font-size: 1.05rem;
    margin: 0 0 0.35rem 0;
  }

  .overlay-card p {
    font-size: 0.7rem;
    margin-bottom: 0.75rem;
  }

  .play-btn {
    padding: 0.5rem 0.8rem;
    font-size: 0.8rem;
  }

  /* Bottom Touch Controls (Fixed ~120px) */
  .touch-controls {
    display: flex !important;
    width: 100%;
    max-width: 360px;
    height: 120px;
    flex-shrink: 0;
    justify-content: space-between;
    align-items: center;
    padding: 2px 4px;
    box-sizing: border-box;
    margin-top: 2px;
    touch-action: none;
    user-select: none;
    -webkit-user-select: none;
  }

  .touch-cluster-dpad {
    display: flex;
    gap: 4px;
    align-items: center;
  }

  .touch-btn {
    width: 44px;
    height: 44px;
    min-width: 42px;
    min-height: 42px;
    border-radius: 10px;
    background: #1E293B;
    border: 1px solid rgba(148, 163, 184, 0.25);
    color: #F8FAFC;
    touch-action: none;
    user-select: none;
    -webkit-tap-highlight-color: transparent;
    cursor: pointer;
    box-shadow: 0 3px 8px rgba(0, 0, 0, 0.35);
    display: flex;
    align-items: center;
    justify-content: center;
    transition: transform 0.05s ease, background-color 0.05s ease;
  }

  .touch-btn:active, .touch-btn.active {
    transform: scale(0.92);
    background: #6366F1;
    color: #FFF;
    border-color: #6366F1;
  }

  .touch-btn-arrow {
    font-size: 1.15rem;
    font-weight: 700;
  }

  .touch-cluster-actions {
    display: flex;
    flex-direction: column;
    gap: 6px;
    align-items: flex-end;
  }

  .touch-action-row-top, .touch-action-row-bottom {
    display: flex;
    gap: 6px;
  }

  .touch-btn-hold {
    width: 54px;
    height: 38px;
    font-size: 0.68rem;
    font-weight: 800;
    color: #67E8F9;
    background: rgba(6, 182, 212, 0.15);
    border-color: rgba(6, 182, 212, 0.35);
  }

  .touch-btn-drop {
    width: 68px;
    height: 38px;
    font-size: 0.68rem;
    font-weight: 800;
    color: #C7D2FE;
    background: rgba(99, 102, 241, 0.2);
    border-color: rgba(99, 102, 241, 0.4);
  }

  .touch-btn-rot {
    width: 58px;
    height: 42px;
    font-size: 0.82rem;
    font-weight: 800;
    color: #F8FAFC;
  }

  .touch-btn-rot-primary {
    background: rgba(99, 102, 241, 0.28);
    border-color: rgba(99, 102, 241, 0.5);
    color: #A5B4FC;
  }
}
