/* ============================================================
   RESET
   ============================================================ */
*, *::before, *::after {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

:root {
  --bg:         #0a0a0a;
  --bg-soft:    #101010;
  --bg-elev:    #161616;
  --line:       #1e1e1e;
  --line-soft:  #262626;
  --fg:         #e8e8e8;
  --fg-mute:    #7a7a7a;
  --fg-faint:   #454545;
  --accent:     #f5a623;
  --accent-dim: #f5a62318;
  --danger:     #ff5c5c;
  --radius:     10px;
  --radius-sm:  8px;
  --mono: 'SF Mono', 'JetBrains Mono', 'Fira Code', 'Menlo', 'Consolas', monospace;
  --sans: -apple-system, BlinkMacSystemFont, 'Inter', 'Segoe UI', Roboto, sans-serif;
}

html, body {
  height: 100%;
}

body {
  background: var(--bg);
  color: var(--fg);
  font-family: var(--sans);
  font-size: 14px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

/* ============================================================
   TOPBAR
   ============================================================ */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 18px 28px;
  flex-shrink: 0;
}

.logo {
  display: flex;
  align-items: center;
  gap: 10px;
  text-decoration: none;
  color: var(--fg);
}

.logo-mark {
  width: 26px;
  height: 26px;
  display: grid;
  place-items: center;
  background: var(--accent);
  color: #0a0a0a;
  font-weight: 800;
  font-size: 14px;
  border-radius: 6px;
  letter-spacing: -0.5px;
}

.logo-text {
  font-size: 15px;
  font-weight: 600;
  letter-spacing: -0.2px;
}

.nav {
  display: flex;
  gap: 22px;
}

.nav a {
  color: var(--fg-mute);
  text-decoration: none;
  font-size: 13px;
  transition: color 0.15s ease;
}

.nav a:hover { color: var(--fg); }

/* ============================================================
   STAGE (área principal)
   ============================================================ */
.stage {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 0 28px 28px;
  min-height: 0;
  gap: 18px;
}

/* ============================================================
   EDITOR SHELL
   ============================================================ */
.editor-shell {
  position: relative;
  width: 100%;
  max-width: 780px;
  flex: 1;
  min-height: 0;
  max-height: 560px;
  background: var(--bg-soft);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  transition: border-color 0.2s ease, background 0.2s ease;
  overflow: hidden;
}

.editor-shell:focus-within {
  border-color: var(--line-soft);
}

/* Modo output: aspecto ligeramente distinto */
.editor-shell[data-mode="output"] {
  background: #0c0c0c;
  border-color: #2a2a2a;
}

.editor-shell[data-mode="output"] .editor {
  color: #7ee787;
  cursor: default;
}

/* ============================================================
   EDITOR
   ============================================================ */
.editor {
  width: 100%;
  height: 100%;
  background: transparent;
  color: var(--fg);
  border: none;
  outline: none;
  resize: none;
  padding: 22px 24px 46px;
  font-family: var(--mono);
  font-size: 13px;
  line-height: 1.65;
  tab-size: 2;
  overflow: auto;
  transition: color 0.15s ease;
}

.editor::placeholder {
  color: var(--fg-faint);
}

.editor::-webkit-scrollbar { width: 10px; height: 10px; }
.editor::-webkit-scrollbar-track { background: transparent; }
.editor::-webkit-scrollbar-thumb {
  background: var(--line-soft);
  border-radius: 5px;
  border: 2px solid var(--bg-soft);
  background-clip: padding-box;
}
.editor::-webkit-scrollbar-thumb:hover {
  background: #383838;
  background-clip: padding-box;
  border: 2px solid var(--bg-soft);
}

/* ============================================================
   CONTADOR
   ============================================================ */
.editor-corner {
  position: absolute;
  bottom: 12px;
  right: 18px;
  pointer-events: none;
}

.counter {
  font-family: var(--mono);
  font-size: 10.5px;
  color: var(--fg-faint);
  letter-spacing: 0.2px;
}

.editor-shell[data-mode="output"] .counter {
  color: #3d5f45;
}

/* ============================================================
   ACCIONES
   ============================================================ */
.actions {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  max-width: 780px;
  justify-content: flex-end;
}

/* Empuja el botón principal a la derecha si hay fantasmas */
.actions .btn-primary {
  margin-left: auto;
}

.actions:has(.btn-ghost:not([hidden])) .btn-primary {
  margin-left: 0;
}

/* Fallback sin :has() */
@supports not selector(:has(*)) {
  .actions .btn-primary {
    margin-left: auto;
  }
}

.btn-primary,
.btn-ghost {
  font-family: var(--sans);
  font-size: 13.5px;
  font-weight: 500;
  border: none;
  cursor: pointer;
  transition: all 0.15s ease;
  outline: none;
  letter-spacing: 0.1px;
}

.btn-primary {
  background: var(--accent);
  color: #0a0a0a;
  padding: 10px 22px;
  border-radius: var(--radius-sm);
  font-weight: 600;
}

.btn-primary:hover:not(:disabled) {
  background: #ffb83d;
  transform: translateY(-1px);
  box-shadow: 0 6px 18px var(--accent-dim);
}

.btn-primary:active:not(:disabled) {
  transform: translateY(0);
}

.btn-primary:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.btn-primary.is-loading {
  color: transparent;
  position: relative;
}

.btn-primary.is-loading::after {
  content: '';
  position: absolute;
  inset: 0;
  margin: auto;
  width: 14px;
  height: 14px;
  border: 2px solid #0a0a0a;
  border-top-color: transparent;
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
}

@keyframes spin { to { transform: rotate(360deg); } }

.btn-ghost {
  background: transparent;
  color: var(--fg-mute);
  padding: 8px 14px;
  border-radius: var(--radius-sm);
}

.btn-ghost:hover {
  background: var(--bg-elev);
  color: var(--fg);
}

/* ============================================================
   TOAST
   ============================================================ */
.toast {
  position: fixed;
  bottom: 26px;
  left: 50%;
  transform: translate(-50%, 20px);
  background: var(--bg-elev);
  border: 1px solid var(--line-soft);
  color: var(--fg);
  padding: 10px 18px;
  border-radius: var(--radius-sm);
  font-size: 13px;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s ease, transform 0.2s ease;
  z-index: 100;
  white-space: nowrap;
}

.toast.show {
  opacity: 1;
  transform: translate(-50%, 0);
}

.toast.success { border-color: #2a4a30; color: #7ee787; }
.toast.error   { border-color: #4a2020; color: var(--danger); }

@media (max-width: 640px) {
  .topbar { padding: 14px 18px; }
  .stage  { padding: 0 18px 18px; }
  .editor { padding: 18px 18px 40px; font-size: 12.5px; }
  .nav { gap: 16px; }
  .nav a { font-size: 12.5px; }
  .actions { flex-wrap: wrap; }
  .btn-primary { padding: 10px 18px; }
}
