/* ── Tokens de diseño ─────────────────────────────────────────────────────── */
:root {
  --bg:        #0f0f0f;
  --surface:   #161616;
  --surface2:  #1e1e1e;
  --border:    #2a2a2a;
  --border2:   #363636;
  --text:      #e4e4e4;
  --muted:     #5a5a5a;
  --muted2:    #888;

  --c-id:    #60a5fa;
  --c-kw:    #c084fc;
  --c-int:   #fb923c;
  --c-real:  #fbbf24;
  --c-hex:   #34d399;
  --c-exp:   #22d3ee;
  --c-arith: #f472b6;
  --c-logic: #a3e635;
  --c-relat: #f87171;
  --c-err:   #ef4444;

  --radius:  10px;
  --radius-sm: 6px;
  --t: 200ms;
}

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

html { font-size: 16px; -webkit-text-size-adjust: 100%; }

body {
  background: var(--bg);
  color: var(--text);
  font-family: 'Inter', system-ui, sans-serif;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 24px 16px 48px;
  line-height: 1.5;
}

/* ── Layout shell ─────────────────────────────────────────────────────────── */
.shell {
  width: 100%;
  max-width: 600px;
  display: flex;
  flex-direction: column;
  gap: 24px;
}

/* ── Header ───────────────────────────────────────────────────────────────── */
header {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.header-academic {
  display: flex;
  flex-direction: column;
  gap: 5px;
}

.header-course {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 6px;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.03em;
}

.header-institution,
.header-subject,
.header-group,
.header-student {
  display: inline-flex;
  align-items: center;
  gap: 5px;
}
.header-institution svg,
.header-subject svg,
.header-group svg,
.header-student svg {
  width: 13px;
  height: 13px;
  flex-shrink: 0;
}

.header-institution {
  color: var(--c-exp);
}

.header-subject {
  color: #a78bfa; /* purple suave */
}

.header-group {
  color: var(--muted2);
  background: var(--surface);
  border: 1px solid var(--border);
  font-family: 'JetBrains Mono', monospace;
  font-size: 10px;
  padding: 2px 7px;
  border-radius: 5px;
  letter-spacing: 0.08em;
  font-weight: 700;
}

.header-dot { color: var(--border2); }

.header-student {
  font-size: 13px;
  font-weight: 600;
  color: var(--text);
  letter-spacing: -0.01em;
}

/* Title + examples button row */
.header-row {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
}

header h1 {
  font-size: clamp(20px, 5vw, 26px);
  font-weight: 600;
  letter-spacing: -0.02em;
  line-height: 1.2;
}

header p {
  font-size: 13px;
  color: var(--muted2);
  margin-top: 3px;
}

/* ── Input card ───────────────────────────────────────────────────────────── */
.input-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.input-label {
  font-size: 11px;
  font-weight: 600;
  color: var(--muted2);
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.input-row {
  display: flex;
  gap: 8px;
  align-items: stretch;
}

#cadena {
  flex: 1;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text);
  font-family: 'JetBrains Mono', monospace;
  font-size: clamp(15px, 4vw, 18px);
  padding: 12px 14px;
  outline: none;
  transition: border-color var(--t), box-shadow var(--t);
  width: 0; /* flex will size it */
}

#cadena:focus {
  border-color: var(--border2);
  box-shadow: 0 0 0 3px rgba(255,255,255,0.04);
}

#cadena.accepted  { border-color: currentColor; }
#cadena.rejected  { border-color: var(--c-err); }

#btn-analyze {
  background: var(--text);
  color: var(--bg);
  border: none;
  border-radius: var(--radius-sm);
  font-family: 'Inter', sans-serif;
  font-size: 13px;
  font-weight: 600;
  padding: 0 18px;
  cursor: pointer;
  white-space: nowrap;
  transition: opacity var(--t), transform var(--t);
  flex-shrink: 0;
}

#btn-analyze:hover  { opacity: 0.85; }
#btn-analyze:active { transform: scale(0.97); }

/* State trace below input */
.state-trace {
  font-family: 'JetBrains Mono', monospace;
  font-size: 10px;
  color: var(--muted);
  min-height: 14px;
  overflow-x: auto;
  white-space: nowrap;
  padding-bottom: 2px;
}

.state-trace span {
  display: inline-block;
}
.state-trace .arrow {
  margin: 0 3px;
  opacity: 0.35;
}
.state-trace .final-state {
  color: var(--muted2);
  font-weight: 700;
}

/* ── Result card ──────────────────────────────────────────────────────────── */
.result-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  display: none;
  flex-direction: column;
  gap: 12px;
  animation: fadeIn 0.18s ease;
}
.result-card.visible { display: flex; }

@keyframes fadeIn {
  from { opacity: 0; transform: translateY(4px); }
  to   { opacity: 1; transform: translateY(0); }
}

.result-header {
  display: flex;
  align-items: center;
  gap: 10px;
}

.verdict {
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  padding: 3px 10px;
  border-radius: 999px;
  flex-shrink: 0;
}
.verdict.ok  { background: rgba(52,211,153,0.12); color: #34d399; }
.verdict.err { background: rgba(239,68,68,0.12);  color: var(--c-err); }

.result-token {
  font-size: clamp(14px, 3.5vw, 16px);
  font-weight: 600;
}

.result-desc {
  font-size: 12px;
  color: var(--muted2);
}

.result-meta {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.meta-row {
  display: flex;
  gap: 8px;
  font-size: 12px;
  align-items: baseline;
}

.meta-key {
  color: var(--muted);
  font-family: 'JetBrains Mono', monospace;
  font-size: 10px;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  min-width: 60px;
  flex-shrink: 0;
}

.meta-val {
  font-family: 'JetBrains Mono', monospace;
  word-break: break-all;
}

/* Token color chips */
.chip {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 4px;
  font-size: 11px;
  font-family: 'JetBrains Mono', monospace;
  font-weight: 600;
}
.chip.id    { color: var(--c-id);    background: rgba(96,165,250,0.1); }
.chip.kw    { color: var(--c-kw);    background: rgba(192,132,252,0.1); }
.chip.int   { color: var(--c-int);   background: rgba(251,146,60,0.1); }
.chip.real  { color: var(--c-real);  background: rgba(251,191,36,0.1); }
.chip.hex   { color: var(--c-hex);   background: rgba(52,211,153,0.1); }
.chip.exp   { color: var(--c-exp);   background: rgba(34,211,238,0.1); }
.chip.arith { color: var(--c-arith); background: rgba(244,114,182,0.1); }
.chip.logic { color: var(--c-logic); background: rgba(163,230,53,0.1); }
.chip.relat { color: var(--c-relat); background: rgba(248,113,113,0.1); }
.chip.err   { color: var(--c-err);   background: rgba(239,68,68,0.1); }

/* Input color ring by token type */
#cadena.t-id    { border-color: var(--c-id); }
#cadena.t-kw    { border-color: var(--c-kw); }
#cadena.t-int   { border-color: var(--c-int); }
#cadena.t-real  { border-color: var(--c-real); }
#cadena.t-hex   { border-color: var(--c-hex); }
#cadena.t-exp   { border-color: var(--c-exp); }
#cadena.t-arith { border-color: var(--c-arith); }
#cadena.t-logic { border-color: var(--c-logic); }
#cadena.t-relat { border-color: var(--c-relat); }
#cadena.t-err   { border-color: var(--c-err); }

/* ── Error details ────────────────────────────────────────────────────────── */
.err-type-badge {
  font-family: 'JetBrains Mono', monospace;
  font-size: 11px;
  padding: 2px 8px;
  border-radius: 4px;
  background: rgba(239,68,68,0.1);
  color: var(--c-err);
  font-weight: 600;
}

/* ── History ──────────────────────────────────────────────────────────────── */
.history-section {
  display: none;
  flex-direction: column;
  gap: 8px;
}
.history-section.visible { display: flex; }

.history-label {
  font-size: 11px;
  font-weight: 600;
  color: var(--muted);
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.history-list {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.history-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 12px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: border-color var(--t), background var(--t);
  font-size: 13px;
}
.history-item:hover {
  border-color: var(--border2);
  background: var(--surface2);
}

.history-item .h-input {
  font-family: 'JetBrains Mono', monospace;
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 13px;
}

.history-item .h-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  flex-shrink: 0;
}
.history-item .h-dot.ok  { background: #34d399; }
.history-item .h-dot.err { background: var(--c-err); }

.history-item .h-type {
  font-size: 11px;
  color: var(--muted2);
  flex-shrink: 0;
}

/* ── Divider ──────────────────────────────────────────────────────────────── */
.divider {
  height: 1px;
  background: var(--border);
}

/* ── Footer ───────────────────────────────────────────────────────────────── */
footer {
  font-size: 11px;
  color: var(--muted);
  text-align: center;
  margin-top: 8px;
}

/* ── Scrollbar ────────────────────────────────────────────────────────────── */
::-webkit-scrollbar { width: 4px; height: 4px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border2); border-radius: 2px; }

/* ── Desktop refinements ─────────────────────────────────────────────────── */
@media (min-width: 640px) {
  body { padding: 48px 24px 72px; }

  .input-card, .result-card { padding: 20px; }

  #cadena { font-size: 20px; padding: 14px 16px; }

  #btn-analyze { font-size: 14px; padding: 0 24px; }

  .result-token { font-size: 18px; }
}

/* ── Header row with examples button ─────────────────────────────────────── */
.header-row {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
}

.btn-examples {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: var(--surface2);
  border: 1px solid #22d3ee55;
  border-radius: 999px;
  color: #22d3ee;
  font-family: 'Inter', sans-serif;
  font-size: 12px;
  font-weight: 600;
  padding: 5px 12px 5px 10px;
  cursor: pointer;
  flex-shrink: 0;
  position: relative;
  animation: btn-neon-pulse 2s ease-in-out infinite;
  transition: transform 0.15s;
}

.btn-examples::before {
  content: '';
  position: absolute;
  inset: -5px;
  border-radius: 999px;
  border: 1.5px solid #22d3ee;
  opacity: 0;
  animation: neon-ring 2s ease-out infinite;
  pointer-events: none;
}
.btn-examples::after {
  content: '';
  position: absolute;
  inset: -5px;
  border-radius: 999px;
  border: 1.5px solid #22d3ee;
  opacity: 0;
  animation: neon-ring 2s ease-out 0.7s infinite;
  pointer-events: none;
}

.btn-examples:hover {
  animation: none;
  border-color: #22d3ee;
  box-shadow: 0 0 12px #22d3ee66;
  transform: scale(1.04);
}
.btn-examples:hover::before,
.btn-examples:hover::after { display: none; }

.btn-examples svg { flex-shrink: 0; }

@keyframes btn-neon-pulse {
  0%, 100% { box-shadow: 0 0 6px #22d3ee44,  0 0 14px #22d3ee22; }
  50%       { box-shadow: 0 0 14px #22d3ee99, 0 0 28px #22d3ee44; }
}

@keyframes neon-ring {
  0%   { transform: scale(1);    opacity: 0.6; }
  100% { transform: scale(1.55); opacity: 0;   }
}

/* ── Modal overlay ────────────────────────────────────────────────────────── */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.75);
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
  display: flex;
  align-items: flex-end;
  justify-content: center;
  z-index: 100;
  padding: 0;
  animation: overlayIn 0.18s ease;
}
.modal-overlay[hidden] { display: none; }

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

.modal {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 16px 16px 0 0;
  width: 100%;
  max-width: 680px;
  max-height: 90dvh;
  overflow-y: auto;
  padding: 20px 16px 32px;
  display: flex;
  flex-direction: column;
  gap: 16px;
  animation: modalSlideUp 0.22s cubic-bezier(0.32, 0.72, 0, 1);
}

@keyframes modalSlideUp {
  from { transform: translateY(40px); opacity: 0; }
  to   { transform: translateY(0);    opacity: 1; }
}

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

.modal-title {
  font-size: 15px;
  font-weight: 600;
  letter-spacing: -0.01em;
}

.btn-close {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 30px;
  height: 30px;
  border-radius: 50%;
  background: var(--surface2);
  border: 1px solid var(--border);
  color: var(--muted2);
  cursor: pointer;
  transition: color var(--t), border-color var(--t);
}
.btn-close:hover { color: var(--text); border-color: var(--border2); }

.modal-subtitle {
  font-size: 12px;
  color: var(--muted);
  margin-top: -8px;
}

/* ── Modal grid ───────────────────────────────────────────────────────────── */
.modal-grid {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.modal-card {
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px;
  display: grid;
  grid-template-columns: 200px 1fr;
  gap: 12px;
  align-items: start;
}

.modal-card-left {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.modal-card-head {
  display: flex;
  align-items: center;
  gap: 10px;
}

.modal-icon {
  width: 34px;
  height: 34px;
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}
.modal-icon svg { width: 16px; height: 16px; }

.modal-card-title {
  display: flex;
  flex-direction: column;
  gap: 1px;
  min-width: 0;
}

.modal-letter {
  font-family: 'JetBrains Mono', monospace;
  font-size: 10px;
  font-weight: 700;
  opacity: 0.7;
}

.modal-cat-name {
  font-size: 13px;
  font-weight: 600;
  line-height: 1.2;
}

.modal-cat-desc {
  font-size: 12px;
  color: var(--muted2);
  line-height: 1.5;
}

/* Mobile: stack vertically */
@media (max-width: 520px) {
  .modal-card {
    grid-template-columns: 1fr;
  }
}

/* ── Example rows ─────────────────────────────────────────────────────────── */
.modal-pills {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.pill-row {
  display: flex;
  align-items: center;
  gap: 6px;
  border-radius: 6px;
  border: 1px solid transparent;
  overflow: hidden;
}

.pill {
  font-family: 'JetBrains Mono', monospace;
  font-size: 12px;
  font-weight: 700;
  padding: 5px 10px;
  cursor: pointer;
  border: none;
  border-radius: 0;
  flex: 1;
  text-align: left;
  transition: opacity var(--t);
  background: transparent;
}
.pill:hover  { opacity: 0.75; }
.pill:active { opacity: 0.5; }

.btn-copy {
  flex-shrink: 0;
  width: 28px;
  height: 28px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: transparent;
  border: none;
  cursor: pointer;
  color: inherit;
  opacity: 0.4;
  border-radius: 4px;
  transition: opacity var(--t);
  margin-right: 2px;
}
.btn-copy:hover   { opacity: 0.9; }
.btn-copy.copied  { opacity: 1; }
.btn-copy svg     { width: 13px; height: 13px; }

/* Modal icon + pill colors using .c-* */
.c-id    { color: var(--c-id);    background: rgba(96,165,250,0.1);  border-color: rgba(96,165,250,0.2); }
.c-kw    { color: var(--c-kw);    background: rgba(192,132,252,0.1); border-color: rgba(192,132,252,0.2); }
.c-int   { color: var(--c-int);   background: rgba(251,146,60,0.1);  border-color: rgba(251,146,60,0.2); }
.c-real  { color: var(--c-real);  background: rgba(251,191,36,0.1);  border-color: rgba(251,191,36,0.2); }
.c-hex   { color: var(--c-hex);   background: rgba(52,211,153,0.1);  border-color: rgba(52,211,153,0.2); }
.c-exp   { color: var(--c-exp);   background: rgba(34,211,238,0.1);  border-color: rgba(34,211,238,0.2); }
.c-arith { color: var(--c-arith); background: rgba(244,114,182,0.1); border-color: rgba(244,114,182,0.2); }
.c-logic { color: var(--c-logic); background: rgba(163,230,53,0.1);  border-color: rgba(163,230,53,0.2); }
.c-relat { color: var(--c-relat); background: rgba(248,113,113,0.1); border-color: rgba(248,113,113,0.2); }
.c-err   { color: var(--c-err);   background: rgba(239,68,68,0.1);   border-color: rgba(239,68,68,0.2); }

/* ── Desktop modal ────────────────────────────────────────────────────────── */
@media (min-width: 640px) {
  .modal-overlay {
    align-items: center;
    padding: 24px;
  }
  .modal {
    border-radius: 16px;
    max-height: 80dvh;
    padding: 24px;
  }
}

/* ── Reduced motion ───────────────────────────────────────────────────────── */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}
