/* Reset and base styles */
:root {
  --primary-color: #2c3e50;
  --secondary-color: #34495e;
  --accent-color: #3498db;
  --light-gray: #f5f7fa;
  --text-color: #333;
  --border-radius: 8px;
  --box-shadow: 0 4px 6px rgba(0,0,0,0.1);
  --transition-speed: 0.3s;
}

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

body, html {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background-color: var(--light-gray);
  color: var(--text-color);
  margin: 0;
  padding: 0;
  width: 100%;
  /* Ensure completely natural scrolling with no constraints */
  min-height: 100%;
  height: auto;
}

/* Ensure iframes have no default styling that could cause gaps */
iframe {
  border: none;
  margin: 0;
  padding: 0;
  display: block;
  outline: none;
  background: transparent;
}

/* Typography */
h1, h2 {
  color: var(--primary-color);
  margin-bottom: 15px;
}

a {
  color: var(--accent-color);
  text-decoration: none;
  transition: color var(--transition-speed);
}

a:hover {
  text-decoration: underline;
}

/* Buttons */
button {
  background-color: var(--primary-color);
  color: white;
  border: none;
  border-radius: var(--border-radius);
  padding: 12px 20px;
  cursor: pointer;
  font-size: 16px;
  transition: background-color var(--transition-speed);
  box-shadow: var(--box-shadow);
}

button:hover {
  background-color: var(--secondary-color);
}

button:focus {
  outline: 3px solid var(--accent-color);
}

/* Main UI Layout */
#editorUI, #installUI {
  background-color: var(--light-gray);
  width: 100%;
  min-height: 100vh; /* Ensure minimum full screen height */
  /* No height constraints - allow natural scrolling */
}

#loadingUI {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100vh;
  height: 100dvh;
  background-color: white;
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  z-index: 1000;
}

.loading-spinner {
  width: 50px;
  height: 50px;
  border: 5px solid var(--light-gray);
  border-top: 5px solid var(--accent-color);
  border-radius: 50%;
  animation: spin 1s linear infinite;
  margin-bottom: 20px;
}

@keyframes spin {
  0% { transform: rotate(0deg); }
  100% { transform: rotate(360deg); }
}

/* Container and Layout */
.container {
  max-width: 900px;
  margin: 0 auto;
  padding: 40px 20px;
  padding-top: max(40px, env(safe-area-inset-top) + 20px);
  padding-bottom: 40px; /* No safe area - let content extend to device bottom */
}

header {
  text-align: center;
  margin-bottom: 30px;
}

.editor-card {
  background-color: white;
  border-radius: var(--border-radius);
  padding: 30px;
  box-shadow: var(--box-shadow);
  margin-bottom: 0; /* No safe area margin */
}

/* Form Elements */
.editor-label {
  display: block;
  font-weight: bold;
  margin-bottom: 8px;
  color: var(--primary-color);
}

textarea {
  width: 100%;
  height: 300px;
  padding: 15px;
  border: 1px solid #ddd;
  border-radius: var(--border-radius);
  font-family: monospace;
  resize: vertical;
  transition: border-color var(--transition-speed);
  font-size: 14px;
}

textarea:focus {
  border-color: var(--accent-color);
  outline: none;
  box-shadow: 0 0 0 2px rgba(52, 152, 219, 0.3);
}

.button-container {
  display: flex;
  gap: 10px;
  margin-top: 20px;
  flex-wrap: wrap;
}

.input-group {
  display: flex;
  gap: 10px;
}

#gistUrl {
  flex: 1;
  padding: 10px 15px;
  border: 1px solid #ddd;
  border-radius: var(--border-radius);
  transition: border-color var(--transition-speed);
}

#gistUrl:focus {
  border-color: var(--accent-color);
  outline: none;
  box-shadow: 0 0 0 2px rgba(52, 152, 219, 0.3);
}

/* App and Preview Views - Full Screen */
#appView {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100vh;
  height: 100dvh;
  background: white;
  z-index: 999;
}

#appFrame {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
}

#previewView {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100vh;
  height: 100dvh;
  z-index: 1000;
  background: white;
  display: flex;
  flex-direction: column;
}

#closePreviewBtn {
  position: relative;
  width: 100%;
  height: 44px;
  min-height: 44px;
  line-height: 44px;
  padding: 0;
  padding-top: env(safe-area-inset-top);
  height: calc(44px + env(safe-area-inset-top));
  background: #3498db;
  color: white;
  border: none;
  font-weight: bold;
  border-radius: 0;
  flex-shrink: 0;
  z-index: 1001;
}

#previewFrame {
  position: relative;
  width: 100%;
  flex: 1;
  min-height: 0;
}

/* State Management - Only apply constraints when iframe classes are active */
body.app-active,
body.preview-active {
  overflow: hidden !important;
  position: fixed !important;
  width: 100% !important;
  height: 100vh !important;
  height: 100dvh !important;
}

body.app-active #appView,
body.preview-active #previewView {
  height: 100vh !important;
  height: 100dvh !important;
  overflow: hidden !important;
}

/* Toast notification */
.toast {
  position: fixed;
  bottom: 30px;
  left: 50%;
  transform: translateX(-50%) translateY(100px);
  background-color: #27ae60;
  color: white;
  padding: 15px 25px;
  border-radius: var(--border-radius);
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
  opacity: 0;
  transition: all 0.3s ease;
  z-index: 1000;
  font-weight: 500;
  pointer-events: none;
  text-align: center;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
}

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

/* Installation UI */
.installation-instructions {
  background-color: #f9f9f9;
  border-radius: var(--border-radius);
  padding: 20px;
  margin-bottom: 20px;
}

.installation-instructions h3 {
  color: #3498db !important;
  margin-bottom: 15px;
  text-align: center;
  font-weight: 700;
  font-size: 1.3em;
}

.step-item {
  position: relative;
  padding-left: 35px;
  margin-bottom: 15px;
  line-height: 1.5;
}

.step-number {
  position: absolute;
  left: 0;
  top: 0;
  width: 24px;
  height: 24px;
  background-color: #3498db !important;
  color: white;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: bold;
  font-size: 14px;
  margin-right: 10px;
}

.ios-share-icon {
  vertical-align: middle;
  background-color: #007AFF;
  padding: 3px;
  border-radius: 5px;
  color: white;
}

.android-menu-icon {
  vertical-align: middle;
}

#desktop-instructions p {
  margin-bottom: 20px;
}

/* GitHub corner */
.github-corner {
  position: absolute;
  top: 0;
  right: 0;
  color: var(--accent-color);
  fill: var(--primary-color);
  z-index: 100;
}

.github-corner:hover {
  color: white;
}

.github-corner .octo-arm {
  transform-origin: 130px 106px;
}

.github-corner:hover .octo-arm {
  animation: octocat-wave 560ms ease-in-out;
}

@keyframes octocat-wave {
  0%, 100% { transform: rotate(0); }
  20%, 60% { transform: rotate(-25deg); }
  40%, 80% { transform: rotate(10deg); }
}

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

/* Mobile Responsive */
@media screen and (max-width: 768px) {
  .container {
    padding: 20px 15px;
    padding-top: max(20px, env(safe-area-inset-top) + 10px);
    padding-bottom: 20px; /* No safe area - let content extend to device bottom */
  }
  
  .editor-card {
    padding: 20px;
    margin-bottom: 20px; /* No safe area margin */
  }

  textarea {
    height: 250px;
  }
  
  .input-group {
    flex-direction: column;
  }
  
  .button-container {
    flex-direction: column;
  }
  
  button {
    width: 100%;
  }

  .github-corner {
    width: 60px;
    height: 60px;
  }
  
  .github-corner:hover .octo-arm {
    animation: none;
  }
  
  .github-corner .octo-arm {
    animation: octocat-wave 560ms ease-in-out;
  }

  /* Mobile iframe constraints - only when body classes are present */
  body.app-active,
  body.preview-active {
    height: 100vh !important;
    height: 100dvh !important;
    overflow: hidden !important;
    position: fixed !important;
  }
  
  body.app-active #appView,
  body.preview-active #previewView {
    height: 100vh !important;
    height: 100dvh !important;
    min-height: 100vh !important;
    min-height: 100dvh !important;
  }
}

/* iOS Safari Support - Only for iframe views when body classes are active */
@supports (-webkit-touch-callout: none) {
  body.app-active,
  body.preview-active {
    height: -webkit-fill-available !important;
  }
  
  body.app-active #appView,
  body.preview-active #previewView {
    height: -webkit-fill-available !important;
    min-height: -webkit-fill-available !important;
  }
  
  #appFrame,
  #previewFrame {
    height: 100%;
    -webkit-overflow-scrolling: touch;
  }
}

/* Accessibility */
@media (prefers-reduced-motion: reduce) {
  .loading-spinner {
    animation: none;
  }
  
  .toast {
    transition: none;
  }
  
  button, a, textarea, #gistUrl {
    transition: none;
  }
}

/* High contrast mode */
@media (prefers-contrast: more) {
  :root {
    --primary-color: #000;
    --secondary-color: #222;
    --accent-color: #0056b3;
    --text-color: #000;
  }
  
  a, button {
    text-decoration: underline;
  }
}
