* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  padding: 0;
  width: 100%;
  min-height: 100%;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  background: #f3f4f6;
  color: #111827;
}

button,
textarea,
input {
  font: inherit;
}

button {
  cursor: pointer;
}

#app {
  min-height: 100vh;
}

/* Landing page */

.page {
  width: min(1100px, 100%);
  margin: 0 auto;
  padding: 40px 24px 60px;
}

.header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
  margin-bottom: 32px;
}

.logo {
  margin: 0;
  font-size: 32px;
  font-weight: 750;
  letter-spacing: -1px;
}

.logo span {
  font-weight: 400;
}

.primary-button {
  border: 0;
  border-radius: 12px;
  padding: 12px 18px;
  background: #111827;
  color: white;
  font-weight: 650;
  transition: transform 0.15s, opacity 0.15s;
}

.primary-button:hover {
  opacity: 0.9;
}

.primary-button:active {
  transform: scale(0.97);
}

.secondary-button {
  border: 1px solid #d1d5db;
  border-radius: 10px;
  padding: 10px 16px;
  background: white;
  color: #111827;
  font-weight: 600;
}

.danger-button {
  border: 1px solid #fecaca;
  border-radius: 10px;
  padding: 10px 16px;
  background: #fff;
  color: #dc2626;
  font-weight: 600;
}

.section-title {
  margin: 0 0 14px;
  font-size: 18px;
}

.app-list {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(250px, 1fr));
  gap: 14px;
}

.app-card {
  display: flex;
  flex-direction: column;
  min-height: 150px;
  padding: 18px;
  border: 1px solid #e5e7eb;
  border-radius: 16px;
  background: white;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.04);
}

.app-card-name {
  margin: 0 0 8px;
  font-size: 18px;
  font-weight: 700;
  word-break: break-word;
}

.app-card-date {
  flex: 1;
  margin: 0 0 18px;
  color: #6b7280;
  font-size: 13px;
}

.card-actions {
  display: flex;
  gap: 8px;
}

.card-actions button {
  flex: 1;
  padding: 8px 6px;
  font-size: 13px;
  white-space: nowrap;
}

.landing-links {
  margin-top: 36px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
}

.landing-link {
  color: #4b5563;
  font-size: 14px;
  font-weight: 500;
  text-decoration: underline;
  text-underline-offset: 3px;
  transition: color 0.15s;
}

.landing-link:hover {
  color: #111827;
}

.empty-state {
  padding: 50px 20px;
  border: 2px dashed #d1d5db;
  border-radius: 16px;
  text-align: center;
  color: #6b7280;
  background: rgba(255, 255, 255, 0.5);
}

/* Editor */

.editor-page {
  width: min(1400px, 100%);
  margin: 0 auto;
  padding: 24px;
}

.editor-header {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  gap: 16px;
  margin-bottom: 20px;
}

.editor-header-left {
  display: flex;
  align-items: center;
  min-width: 0;
}

.back-button {
  border: 0;
  background: transparent;
  color: #4b5563;
  padding: 8px 12px;
  font-size: 16px;
  font-weight: 600;
  border-radius: 8px;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 4px;
  transition: color 0.15s, background-color 0.15s;
}

.back-button:hover {
  color: #111827;
  background: #e5e7eb;
}

.editor-title {
  margin: 0;
  font-size: 24px;
  text-align: center;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.editor-header-right {
  display: flex;
  justify-content: flex-end;
}

.modal-footer-actions {
  display: flex;
  justify-content: flex-start;
  padding-top: 4px;
}

.name-field {
  margin-bottom: 18px;
}

.name-field label {
  display: block;
  margin-bottom: 7px;
  font-size: 14px;
  font-weight: 700;
}

.name-input {
  width: 100%;
  max-width: 500px;
  padding: 12px 14px;
  border: 1px solid #d1d5db;
  border-radius: 10px;
  outline: none;
  background: white;
}

.name-input:focus,
.code-editor:focus {
  border-color: #6b7280;
  box-shadow: 0 0 0 3px rgba(107, 114, 128, 0.12);
}

.editors {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  gap: 14px;
}

.editor-panel {
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.editor-help-link-container {
  margin-bottom: 18px;
}

.editor-label {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 7px;
  font-size: 14px;
  font-weight: 700;
}

.editor-label-actions {
  display: flex;
  gap: 6px;
  align-items: center;
}

.label-button {
  border: 1px solid #d1d5db;
  border-radius: 6px;
  padding: 2px 8px;
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.15s;
  line-height: 1.4;
}

.copy-field-button {
  background: white;
  color: #374151;
}

.copy-field-button:hover {
  background: #f3f4f6;
  border-color: #9ca3af;
}

.copy-field-button.copied {
  background: #111827;
  color: white;
  border-color: #111827;
}

.clear-field-button {
  background: white;
  color: #dc2626;
  border-color: #fecaca;
}

.clear-field-button:hover {
  background: #fef2f2;
  border-color: #f87171;
}

.clear-field-button:active {
  background: #fee2e2;
}

.code-editor {
  width: 100%;
  min-height: 500px;
  resize: vertical;
  padding: 14px;
  border: 1px solid #d1d5db;
  border-radius: 12px;
  outline: none;
  background: #111827;
  color: #e5e7eb;
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
  font-size: 13px;
  line-height: 1.55;
  tab-size: 2;
}

.editor-footer {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  margin-top: 16px;
}

/* Running application */

.runner {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  background: white;
  z-index: 1000;
}

.runner iframe {
  display: block;
  width: 100%;
  height: 100%;
  border: 0;
}

.exit-floating-button,
.edit-floating-button {
  position: fixed;
  z-index: 1100;
  top: max(14px, env(safe-area-inset-top));
  left: max(14px, env(safe-area-inset-left));
  border: 0;
  border-radius: 999px;
  padding: 10px 18px;
  background: rgba(17, 24, 39, 0.88);
  color: white;
  font-weight: 650;
  box-shadow: 0 4px 18px rgba(0, 0, 0, 0.25);
  backdrop-filter: blur(8px);
}

.exit-floating-button:active,
.edit-floating-button:active {
  transform: scale(0.96);
}

/* Modal Dialog */

.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(17, 24, 39, 0.6);
  backdrop-filter: blur(4px);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  z-index: 2000;
  animation: fadeIn 0.15s ease-out;
}

.modal-card {
  background: white;
  width: min(600px, 100%);
  max-height: 90vh;
  overflow-y: auto;
  border-radius: 18px;
  box-shadow: 0 20px 40px rgba(0, 0, 0, 0.2);
  display: flex;
  flex-direction: column;
  animation: slideUp 0.15s ease-out;
}

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

@keyframes slideUp {
  from { transform: translateY(12px) scale(0.98); opacity: 0; }
  to { transform: translateY(0) scale(1); opacity: 1; }
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 20px 24px 14px;
  border-bottom: 1px solid #f3f4f6;
}

.modal-title {
  margin: 0;
  font-size: 20px;
  font-weight: 750;
  color: #111827;
}

.modal-close-button {
  border: 0;
  background: transparent;
  font-size: 26px;
  line-height: 1;
  color: #6b7280;
  padding: 4px 8px;
  border-radius: 8px;
  cursor: pointer;
  transition: color 0.15s, background-color 0.15s;
}

.modal-close-button:hover {
  color: #111827;
  background: #f3f4f6;
}

.modal-body {
  padding: 20px 24px 24px;
  display: flex;
  flex-direction: column;
  gap: 18px;
}

.modal-text {
  margin: 0;
  font-size: 15px;
  line-height: 1.6;
  color: #374151;
}

.prompt-section {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.prompt-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.prompt-title {
  font-size: 14px;
  font-weight: 700;
  color: #111827;
}

.copy-button {
  border: 1px solid #d1d5db;
  border-radius: 8px;
  padding: 5px 12px;
  font-size: 12px;
  font-weight: 600;
  background: white;
  color: #374151;
  cursor: pointer;
  transition: all 0.15s;
}

.copy-button:hover {
  background: #f3f4f6;
  border-color: #9ca3af;
}

.copy-button.copied {
  background: #111827;
  color: white;
  border-color: #111827;
}

.prompt-code {
  margin: 0;
  padding: 14px;
  background: #111827;
  color: #f3f4f6;
  border-radius: 12px;
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
  font-size: 13px;
  line-height: 1.55;
  white-space: pre-wrap;
  word-break: break-word;
}

/* Custom confirm dialog */

.confirm-dialog-overlay {
  align-items: center;
}

.confirm-dialog-card {
  background: white;
  width: min(360px, calc(100% - 32px));
  border-radius: 18px;
  box-shadow: 0 20px 40px rgba(0, 0, 0, 0.2);
  padding: 28px 24px 20px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  animation: slideUp 0.15s ease-out;
}

.confirm-dialog-title {
  margin: 0;
  font-size: 18px;
  font-weight: 750;
  color: #111827;
  text-align: center;
}

.confirm-dialog-message {
  margin: 0;
  font-size: 14px;
  color: #6b7280;
  text-align: center;
  line-height: 1.5;
}

.confirm-dialog-actions {
  display: flex;
  gap: 10px;
  margin-top: 8px;
}

.confirm-dialog-actions button {
  flex: 1;
}

/* Responsive */

@media (max-width: 850px) {
  .editors {
    grid-template-columns: 1fr;
  }

  .code-editor {
    min-height: 300px;
  }
}

@media (max-width: 600px) {
  .page {
    padding: 24px 16px 40px;
  }

  .header {
    align-items: flex-start;
  }

  .logo {
    font-size: 28px;
  }

  .primary-button {
    padding: 10px 14px;
  }

  .editor-page {
    padding: 16px;
  }

  .editor-header {
    grid-template-columns: 1fr auto 1fr;
    gap: 8px;
  }

  .editor-header-left {
    min-width: 0;
  }

  .back-button {
    padding: 6px 8px;
    font-size: 15px;
  }

  .editor-title {
    font-size: 18px;
    text-align: center;
  }

  .name-input,
  .code-editor {
    font-size: 16px;
  }

  .code-editor {
    min-height: 260px;
  }

  .editor-footer {
    position: sticky;
    bottom: 0;
    padding: 10px 0 max(10px, env(safe-area-inset-bottom));
    background: #f3f4f6;
  }
}