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

/* Import modern fonts */
@import url('https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;600;700&display=swap');

/* CSS Custom Properties for viewport unit support detection */
:root {
  /* Feature detection for new viewport units */
  --viewport-height: 100vh; /* Fallback */
  --viewport-height: 100svh; /* Small Viewport Height - for consistent UI */
  --mobile-viewport-height: 100dvh; /* Dynamic - adapts to mobile browser changes */

  /* Design tokens */
  --brand-start: #4f46e5; /* indigo-600 */
  --brand-end: #06b6d4; /* cyan-500 */
  --glass-bg: rgba(255, 255, 255, 0.72);
  --glass-bg-soft: rgba(255, 255, 255, 0.14);
  --glass-border: rgba(0, 0, 0, 0.06);
  --glass-blur: 20px;
  --radius-lg: 24px;
  --radius-md: 16px;
  --radius-sm: 12px;
  --text-strong: #111827; /* gray-900 */
  --text-muted: rgba(17, 24, 39, 0.66);
}

body {
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto,
    sans-serif;
  margin: 0;
  padding: 0;
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  /* Modern gradient background */
  /* Fix mobile viewport height issues with new CSS units */
  min-height: 100vh; /* Fallback for older browsers */
  min-height: 100svh; /* Small Viewport Height - accounts for browser UI */
  overflow: hidden;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

.game-container {
  /* Full screen game area with proper mobile viewport handling */
  height: 100vh; /* Fallback for older browsers */
  height: 100svh; /* Small Viewport Height - prevents content clipping */
  width: 100vw;
  max-width: 100%;
  margin: 0 auto;
  position: relative;
  overflow: hidden;
}

/* Modern glassmorphism sidebar */
.ui-sidebar {
  position: absolute;
  top: 24px;
  right: 16px;
  z-index: 100;
  background: rgba(255, 255, 255, 0.1);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  border: 1px solid rgba(255, 255, 255, 0.2);
  border-radius: 16px;
  padding: 16px 12px;
  min-width: 85px;
  color: white;
  font-weight: 500;
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.3),
    inset 0 1px 0 rgba(255, 255, 255, 0.2);
  transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

.score-display {
  margin-bottom: 12px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.15);
  padding-bottom: 12px;
}

.height-info,
.best-info {
  margin-bottom: 12px;
  text-align: center;
  transition: transform 0.2s ease;
}

.height-info:hover,
.best-info:hover {
  transform: scale(1.05);
}

.label {
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 1.5px;
  color: rgba(255, 255, 255, 0.7);
  display: block;
  margin-bottom: 4px;
  text-transform: uppercase;
}

.value {
  font-size: 16px;
  font-weight: 700;
  color: #fff;
  display: block;
  text-shadow: 0 2px 4px rgba(0, 0, 0, 0.3);
}

.next-preview {
  text-align: center;
}

.next-preview .label {
  margin-bottom: 8px;
}

.preview-container {
  width: 54px;
  height: 54px;
  border: 1px solid rgba(255, 255, 255, 0.2);
  margin: 0 auto 10px auto;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(255, 255, 255, 0.08);
  border-radius: 12px;
  transition: all 0.3s ease;
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
}

.preview-container:hover {
  transform: scale(1.05);
  background: rgba(255, 255, 255, 0.15);
}

.sidebar-actions {
  display: grid;
  grid-template-columns: 1fr;
  gap: 8px;
}

/* Removed controls-info section for space saving */

.game-area {
  /* Full screen canvas area */
  width: 100%;
  height: 100%;
  position: relative;
  overflow: hidden;
}

#gameCanvas {
  display: block;
  cursor: pointer;
}

#gameCanvas.pendulum-active {
  cursor: crosshair;
}

.instructions {
  position: absolute;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%);
  background: rgba(255, 255, 255, 0.1);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  color: white;
  padding: 12px 20px;
  border-radius: 20px;
  border: 1px solid rgba(255, 255, 255, 0.2);
  text-align: center;
  pointer-events: none;
  transition: all 0.4s cubic-bezier(0.4, 0, 0.2, 1);
  font-size: 13px;
  font-weight: 500;
  z-index: 50;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.2);
}

.instructions.hidden {
  opacity: 0;
}

.pause-indicator {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  color: white;
  font-size: 28px;
  font-weight: 700;
  padding: 12px 24px;
  border-radius: 16px;
  background: rgba(0, 0, 0, 0.35);
  border: 1px solid rgba(255, 255, 255, 0.25);
  display: none;
  z-index: 200;
}

.mobile-controls {
  position: absolute;
  bottom: 16px;
  left: 50%;
  transform: translateX(-50%);
  display: none;
  gap: 10px;
  z-index: 60;
}

.control-btn {
  min-width: 64px;
  min-height: 44px;
  border-radius: 12px;
  border: 1px solid rgba(255, 255, 255, 0.2);
  background: rgba(255, 255, 255, 0.2);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  color: white;
  font-weight: 700;
  font-size: 14px;
}

.control-btn.primary {
  background: linear-gradient(135deg, var(--brand-start), var(--brand-end));
  border: none;
  padding: 0 16px;
}

/* Pause UI (restored) */
.floating-pause-btn {
  position: absolute;
  top: 16px;
  left: 16px;
  z-index: 120;
  width: 40px;
  height: 40px;
  display: grid;
  place-items: center;
  color: #fff;
  background: transparent;
  border: none;
  border-radius: 12px;
  padding: 0;
}
.floating-pause-btn:hover {
  transform: scale(1.05);
}
.icon.icon-pause,
.icon.icon-play {
  display: inline-block;
  width: 18px;
  height: 18px;
  position: relative;
}
/* Pause icon (two vertical bars) */
.icon.icon-pause::before,
.icon.icon-pause::after {
  content: '';
  position: absolute;
  top: 0;
  bottom: 0;
  width: 6px;
  background: #fff;
  border-radius: 2px;
}
.icon.icon-pause::before {
  left: 0;
}
.icon.icon-pause::after {
  right: 0;
}
/* Play icon (triangle) for resume state */
.icon.icon-play {
  width: 0;
  height: 0;
  border-left: 14px solid #fff;
  border-top: 9px solid transparent;
  border-bottom: 9px solid transparent;
}
/* Dim backdrop when paused */
.paused-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.35);
  z-index: 110;
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.2s ease;
}
.paused-backdrop.visible {
  opacity: 1;
  pointer-events: auto;
  cursor: pointer;
}
@media (max-width: 768px) {
  .floating-pause-btn {
    top: 12px;
    left: 12px;
    width: 36px;
    height: 36px;
  }
}

.game-over-modal {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(0, 0, 0, 0.6);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  animation: fadeIn 0.3s ease;
}

.modal-content {
  background: rgba(255, 255, 255, 0.95);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  padding: 48px;
  border-radius: 24px;
  border: 1px solid rgba(255, 255, 255, 0.3);
  text-align: center;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.3),
    inset 0 1px 0 rgba(255, 255, 255, 0.4);
  max-width: 420px;
  width: 90%;
  transform: scale(0.9);
  animation: modalSlideIn 0.4s cubic-bezier(0.4, 0, 0.2, 1) forwards;
}

.modal-content h2 {
  color: #333;
  margin-bottom: 20px;
  font-size: 28px;
}

.new-record {
  color: #4caf50;
  font-weight: bold;
  margin-bottom: 20px;
  display: none;
}

.btn {
  padding: 14px 28px;
  border: none;
  border-radius: 12px;
  font-size: 16px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  position: relative;
  overflow: hidden;
}

.btn.small {
  padding: 8px 10px;
  font-size: 12px;
}

/* Unify buttons to brand gradient */
.restart-btn {
  background: linear-gradient(135deg, var(--brand-start), var(--brand-end));
  color: #fff;
  box-shadow: 0 6px 18px rgba(6, 182, 212, 0.32);
}

.restart-btn:hover {
  transform: translateY(-3px) scale(1.02);
  box-shadow: 0 10px 24px rgba(6, 182, 212, 0.4);
}

.restart-btn:active {
  transform: translateY(-1px) scale(0.98);
}

/* Start button brand gradient */

/* Desktop: Modern pillarbox layout */
@media (min-width: 769px) {
  body {
    display: flex;
    justify-content: center;
    align-items: center;
    background: radial-gradient(ellipse at center, #1a1a2e 0%, #0f0f23 100%);
  }

  .game-container {
    /* Maintain 9:16 aspect ratio on desktop with proper viewport units */
    width: min(100vh * 9/16, 100vw);
    height: min(100vw * 16/9, 100vh);
    /* Fallback for older browsers */
    width: min(100svh * 9/16, 100vw);
    height: min(100vw * 16/9, 100svh);
    /* Small Viewport Height for consistent desktop experience */
    max-width: 480px;
    max-height: 853px;
    box-shadow: 0 25px 80px rgba(0, 0, 0, 0.5),
      0 0 0 1px rgba(255, 255, 255, 0.1);
    border-radius: 24px;
    overflow: hidden;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    position: relative;
  }

  .game-container::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: linear-gradient(
      135deg,
      rgba(255, 255, 255, 0.1) 0%,
      rgba(255, 255, 255, 0.05) 100%
    );
    pointer-events: none;
    z-index: 1;
  }
}

/* Mobile optimizations with enhanced viewport handling */
@media (max-width: 768px) {
  /* Additional mobile viewport fixes */
  body {
    /* Use Dynamic Viewport Height for better mobile experience */
    min-height: 100dvh; /* Dynamic - adjusts as browser UI shows/hides */
  }

  .game-container {
    /* Dynamic height that adapts to mobile browser UI changes */
    height: 100dvh; /* Dynamic Viewport Height for mobile */
  }

  .ui-sidebar {
    right: 8px;
    top: 15px;
    padding: 8px 6px;
    min-width: 70px;
  }

  .value {
    font-size: 13px;
  }

  .preview-container {
    width: 45px;
    height: 45px;
  }

  .mobile-controls {
    display: flex;
  }
}

/* Pendulum cable visualization */
.pendulum-cable {
  position: absolute;
  width: 3px;
  background: #654321;
  pointer-events: none;
  z-index: 10;
  box-shadow: 1px 0 2px rgba(0, 0, 0, 0.3);
  border-radius: 1px;
}

/* Pendulum anchor point */
.pendulum-anchor {
  position: absolute;
  width: 8px;
  height: 8px;
  background: #8b4513;
  border: 2px solid #654321;
  border-radius: 50%;
  pointer-events: none;
  z-index: 11;
  transform: translate(-50%, -50%);
}

/* Modern animations */
@keyframes fadeIn {
  from {
    opacity: 0;
  }
  to {
    opacity: 1;
  }
}

@keyframes modalSlideIn {
  from {
    opacity: 0;
    transform: scale(0.8) translateY(20px);
  }
  to {
    opacity: 1;
    transform: scale(1) translateY(0);
  }
}

@keyframes pulse {
  0%,
  100% {
    transform: scale(1);
  }
  50% {
    transform: scale(1.05);
  }
}

/* Block preview styles */
.block-preview {
  background: linear-gradient(135deg, #4caf50, #66bb6a);
  border-radius: 4px;
  box-shadow: 0 2px 8px rgba(76, 175, 80, 0.3);
  transition: all 0.2s ease;
}

.block-preview:hover {
  transform: scale(1.1);
  box-shadow: 0 4px 12px rgba(76, 175, 80, 0.4);
}

.block-preview.rectangle {
  width: 24px;
  height: 12px;
}

.block-preview.square {
  width: 18px;
  height: 18px;
}

.block-preview.long {
  width: 36px;
  height: 9px;
}

.block-preview.triangle {
  width: 0;
  height: 0;
  border-left: 9px solid transparent;
  border-right: 9px solid transparent;
  border-bottom: 18px solid #4caf50;
  background: none;
  box-shadow: none;
}

.block-preview.circle {
  width: 21px;
  height: 21px;
  border-radius: 50%;
}

/* Result: layout refresh */
.result-card-header {
  text-align: center;
  margin-bottom: 10px;
}
.result-body {
  display: grid;
  grid-template-columns: 1fr;
  gap: 16px;
}
.result-figure {
  text-align: center;
}
.result-actions {
  display: flex;
  justify-content: center;
}
.result-actions .restart-btn {
  min-width: 200px;
  padding: 14px 28px;
}

/* New glassy result card - unified light theme */
.modal-content.result-card {
  background: var(--glass-bg);
  color: var(--text-strong);
  border: 1px solid var(--glass-border);
  border-radius: var(--radius-lg);
  padding: 36px 28px;
  backdrop-filter: blur(var(--glass-blur));
  -webkit-backdrop-filter: blur(var(--glass-blur));
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.22),
    inset 0 1px 0 rgba(255, 255, 255, 0.55);
}

.result-card .result-title {
  font-size: 28px;
  font-weight: 800;
  letter-spacing: 0.5px;
  margin-bottom: 6px;
}

.result-card .result-subtitle {
  color: var(--text-muted);
  margin-bottom: 18px;
}

.result-card .result-height-label {
  font-size: 12px;
  letter-spacing: 1.5px;
  opacity: 0.85;
}

.result-card .result-height {
  font-size: 34px;
  font-weight: 900;
  margin: 6px 0 10px 0;
  color: #1d4ed8; /* blue-700 */
  text-shadow: none;
}

/* Result screen palette overrides - dark glass theme (disabled) */
/*
.game-over-modal .modal-content.result-card {
  background: rgba(18, 22, 48, 0.72);
  color: #eaf1ff;
  border: 1px solid rgba(255, 255, 255, 0.14);
}

.result-title {
  color: #ffffff;
}

.result-subtitle {
  color: rgba(234, 241, 255, 0.82);
}

.result-height {
  color: #aee4ff;
}

.new-record {
  color: #7cffcb;
}
*/

/* Light glass theme overrides for result screen */
.game-over-modal {
  background: rgba(0, 0, 0, 0.5);
}

.game-over-modal .modal-content.result-card {
  background: var(--glass-bg);
  color: var(--text-strong);
  border: 1px solid var(--glass-border);
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.22),
    inset 0 1px 0 rgba(255, 255, 255, 0.55);
}

.result-title {
  color: var(--text-strong);
}
.result-subtitle {
  color: var(--text-muted);
}
.result-height {
  color: #1d4ed8; /* blue-700 */
  text-shadow: none;
}
.new-record {
  color: #10b981; /* emerald-500 */
}
