:root {
  color-scheme: light;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  color: #20242a;
  background: #f3f5f7;
  --border: #d8dde3;
  --muted: #66717e;
  --blue: #2878c7;
  --blue-soft: #e8f2fc;
  --amber: #b86f00;
  --cell: #ffffff;
  --variables: #f8f9fa;
  --shadow: 0 12px 36px rgb(37 48 61 / 8%);
}

* {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  clip-path: inset(50%);
  white-space: nowrap;
}

body {
  margin: 0;
  min-width: 20rem;
  min-height: 100vh;
}

button,
select,
input {
  font: inherit;
}

.app-shell {
  width: min(96vw, 90rem);
  margin: 0 auto;
  padding: clamp(1rem, 2vw, 2rem) 0;
}

.app-header {
  display: flex;
  align-items: end;
  justify-content: space-between;
  gap: 2rem;
  margin-bottom: 1rem;
}

.eyebrow {
  margin: 0 0 0.25rem;
  color: var(--blue);
  font-size: 0.78rem;
  font-weight: 750;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

h1 {
  margin: 0;
  font-size: clamp(1.55rem, 2.6vw, 2.35rem);
  letter-spacing: -0.035em;
}

.subtitle {
  margin: 0.35rem 0 0;
  color: var(--muted);
}

.load-controls,
.transport,
.autoplay {
  display: flex;
  align-items: center;
  gap: 0.55rem;
  flex-wrap: wrap;
}

.load-controls > label:first-child,
.autoplay label {
  color: var(--muted);
  font-size: 0.84rem;
  font-weight: 650;
}

select,
.button {
  min-height: 2.35rem;
  border: 1px solid var(--border);
  border-radius: 0.45rem;
}

select {
  padding: 0 2rem 0 0.65rem;
  color: #26313c;
  background: var(--cell);
}

.button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0.45rem 0.85rem;
  font-weight: 680;
  cursor: pointer;
  transition: background 120ms ease, border-color 120ms ease, transform 120ms ease;
}

.button:hover:not(:disabled) {
  border-color: #9aa8b6;
  transform: translateY(-1px);
}

.button:focus-visible,
select:focus-visible,
.code-scroll:focus-visible,
.console-output:focus-visible {
  outline: 3px solid rgb(40 120 199 / 28%);
  outline-offset: 2px;
}

.button.primary {
  border-color: var(--blue);
  color: #fff;
  background: var(--blue);
}

.button.secondary {
  color: #2f3a45;
  background: #fff;
}

.button.compact {
  min-height: 2rem;
  padding: 0.3rem 0.65rem;
  font-size: 0.82rem;
}

.run-button {
  border-color: #197044;
  color: #fff;
  background: #197044;
}

.button:disabled {
  opacity: 0.46;
  cursor: not-allowed;
}

#file-input {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  clip-path: inset(50%);
  white-space: nowrap;
}

.error-message {
  margin: 0 0 1rem;
  padding: 0.8rem 1rem;
  border: 1px solid #e3aaaa;
  border-radius: 0.5rem;
  color: #8a2020;
  background: #fff1f1;
}

.renderer {
  overflow: hidden;
  border: 1px solid var(--border);
  border-radius: 0.75rem;
  background: var(--cell);
  box-shadow: var(--shadow);
}

.workspace {
  display: grid;
  grid-template-columns: minmax(0, 3fr) minmax(14rem, 1fr);
  min-height: clamp(21rem, 53vh, 38rem);
}

.panel {
  min-width: 0;
  background: var(--cell);
}

.panel-header {
  display: flex;
  min-height: 3.25rem;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: 0.65rem 1rem;
  border-bottom: 1px solid var(--border);
}

.panel-header h2 {
  display: inline;
  margin: 0;
  font-size: 0.94rem;
  letter-spacing: 0.01em;
}

.code-header > div,
.trace-meta {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  min-width: 0;
}

.prompt {
  color: var(--blue);
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 0.84rem;
  font-weight: 700;
}

#filename {
  overflow: hidden;
  color: var(--muted);
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 0.78rem;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.phase-badge {
  flex: none;
  padding: 0.2rem 0.5rem;
  border-radius: 999px;
  color: #38536c;
  background: #edf1f5;
  font-size: 0.74rem;
  font-weight: 720;
}

.phase-badge.arrival {
  color: #835100;
  background: #fff0cf;
}

.phase-badge.executed {
  color: #17613b;
  background: #e3f5e9;
}

.phase-badge.error {
  color: #8a2020;
  background: #ffe3e3;
}

.phase-badge.waiting_input {
  color: #725100;
  background: #fff2bd;
}

.phase-badge.editing {
  color: #38536c;
  background: #edf1f5;
}

.phase-badge.running {
  color: #835100;
  background: #fff0cf;
}

.code-panel {
  display: flex;
  min-height: 0;
  flex-direction: column;
  border-right: 1px solid var(--border);
}

.code-scroll {
  flex: 1;
  overflow: auto;
  padding: 0.8rem 0;
}

.editor-view {
  display: flex;
  min-height: 0;
  flex: 1;
  flex-direction: column;
}

.editor-code {
  display: grid;
  min-height: 20rem;
  flex: 1;
  grid-template-columns: auto minmax(0, 1fr);
  overflow: hidden;
  position: relative;
}

.completion-list {
  position: absolute;
  z-index: 5;
  width: max-content;
  min-width: 10rem;
  max-width: 18rem;
  max-height: 12rem;
  margin: 0;
  overflow: auto;
  padding: 0.25rem;
  border: 1px solid #b8c2cc;
  border-radius: 0.35rem;
  background: #fff;
  box-shadow: 0 6px 18px rgb(31 42 54 / 16%);
  color: #26313c;
  font: 0.9rem/1.4 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  list-style: none;
}

.completion-option {
  padding: 0.25rem 0.55rem;
  border-radius: 0.25rem;
  cursor: pointer;
}

.completion-option.selected {
  color: #fff;
  background: var(--blue);
}

.editor-line-numbers {
  min-width: 3rem;
  height: 100%;
  margin: 0;
  overflow: hidden;
  padding: 1rem 0.7rem 1rem 0.5rem;
  border-right: 1px solid #edf0f2;
  color: #8a949f;
  background: #fafbfc;
  font: clamp(0.9rem, 1.25vw, 1.05rem)/1.7 ui-monospace, SFMono-Regular, Menlo, Consolas, "Liberation Mono", monospace;
  text-align: right;
  user-select: none;
}

.source-editor {
  width: 100%;
  min-width: 0;
  min-height: 100%;
  resize: vertical;
  border: 0;
  outline: 0;
  padding: 1rem 1.25rem;
  color: #20252a;
  background: #fff;
  font: clamp(0.9rem, 1.25vw, 1.05rem)/1.7 ui-monospace, SFMono-Regular, Menlo, Consolas, "Liberation Mono", monospace;
  tab-size: 4;
  white-space: pre;
  overflow: auto;
}

.source-editor:focus {
  box-shadow: inset 3px 0 var(--blue);
}

.editor-tools {
  display: grid;
  grid-template-columns: minmax(13rem, 26rem) 1fr;
  align-items: end;
  gap: 1rem;
  padding: 0.75rem 1rem;
  border-top: 1px solid var(--border);
  background: #fafbfc;
}

.inputs-field {
  display: flex;
  min-width: 0;
  flex-direction: column;
  gap: 0.35rem;
}

.inputs-field label {
  color: #47525d;
  font-size: 0.82rem;
  font-weight: 700;
}

.inputs-field label span {
  color: var(--muted);
  font-weight: 450;
}

.inputs-field textarea {
  width: 100%;
  resize: vertical;
  border: 1px solid var(--border);
  border-radius: 0.4rem;
  padding: 0.5rem 0.65rem;
  color: #20252a;
  background: #fff;
  font: 0.86rem/1.45 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  white-space: pre;
}

.local-warning {
  justify-self: end;
  margin: 0 0 0.2rem;
  color: #8a5a0a;
  font-size: 0.78rem;
  text-align: right;
}

.code-lines {
  width: max-content;
  min-width: 100%;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, "Liberation Mono", monospace;
  font-size: clamp(0.88rem, 1.25vw, 1.05rem);
  line-height: 1.72;
}

.code-row {
  display: grid;
  width: 100%;
  min-width: max-content;
  grid-template-columns: 1.65rem 3.15rem auto;
  padding-right: 1.25rem;
  border-left: 3px solid transparent;
}

.code-row.active {
  border-left-color: var(--blue);
  background: var(--blue-soft);
}

.code-row.runtime-error {
  border-left-color: #c53636;
  background: #fff0f0;
}

.code-row.runtime-error .pointer {
  color: #c53636;
}

.code-row.waiting-input {
  border-left-color: #d19300;
  background: #fff8df;
}

.code-row.waiting-input .pointer {
  color: #a96800;
}

.input-request {
  display: grid;
  grid-template-columns: auto minmax(8rem, 1fr) auto;
  align-items: center;
  gap: 0.65rem;
  padding: 0.75rem 1rem;
  border-top: 1px solid #e4c86d;
  background: #fffbeb;
}

.input-request label {
  color: #614600;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-weight: 700;
}

.input-request input {
  min-width: 0;
  min-height: 2.35rem;
  border: 1px solid #c9ad51;
  border-radius: 0.4rem;
  padding: 0.45rem 0.65rem;
  background: #fff;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}

.input-button {
  border-color: #b07800;
  color: #fff;
  background: #b07800;
}

.pointer {
  color: var(--amber);
  text-align: right;
}

.line-number {
  padding-right: 0.85rem;
  color: #8a949f;
  text-align: right;
  user-select: none;
}

.source-line {
  white-space: pre;
}

.variables-panel {
  display: flex;
  min-height: 0;
  flex-direction: column;
  background: var(--variables);
}

.variables {
  flex: 1;
  overflow: auto;
  padding: 0.9rem 1rem 1rem;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 0.92rem;
}

.variable-row {
  display: flex;
  width: max-content;
  min-width: 100%;
  gap: 0.5rem;
  padding: 0.38rem 0.45rem;
  border-radius: 0.35rem;
  white-space: pre;
}

.variable-row.changed {
  background: #e6f4ea;
}

.module-row {
  padding: 0.38rem 0.45rem;
  color: #156bbb;
  font-weight: 700;
}

.variable-section-title {
  margin: 1rem 0 0.45rem;
  padding-top: 0.8rem;
  border-top: 1px solid var(--border);
  color: #2f3a45;
  font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  font-size: 0.88rem;
}

.variable-name {
  color: #156bbb;
  font-weight: 700;
}

.variable-equals {
  color: #7b858f;
}

.empty-state {
  margin: 0;
  color: #8a949f;
  font-size: 0.88rem;
  font-style: italic;
}

.console-panel {
  border-top: 1px solid var(--border);
}

.console-header {
  min-height: 2.7rem;
}

.console-header span {
  color: var(--muted);
  font-size: 0.76rem;
}

.console-output {
  height: clamp(8rem, 20vh, 14rem);
  margin: 0;
  overflow: auto;
  padding: 1rem 1.2rem;
  color: #20252a;
  background: #fcfcfd;
  font: 0.94rem/1.5 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  white-space: pre;
}

.console-output:empty::before {
  color: #9aa2aa;
  content: "La salida aparecerá al ejecutar una instrucción de I/O.";
  font-style: italic;
}

.player-controls {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  gap: 1rem;
  padding: 0.8rem 1rem;
  border-top: 1px solid var(--border);
  background: #f7f8fa;
}

.status {
  margin: 0;
  color: #4d5965;
  font-size: 0.86rem;
  font-weight: 650;
  text-align: center;
}

.autoplay {
  justify-content: flex-end;
}

@media (max-width: 850px) {
  .app-header {
    align-items: stretch;
    flex-direction: column;
    gap: 1rem;
  }

  .workspace {
    grid-template-columns: minmax(0, 1fr);
  }

  .code-panel {
    min-height: 21rem;
    border-right: 0;
  }

  .editor-tools {
    grid-template-columns: minmax(0, 1fr);
  }

  .local-warning {
    justify-self: start;
    text-align: left;
  }

  .variables-panel {
    min-height: 9rem;
    border-top: 1px solid var(--border);
  }

  .player-controls {
    grid-template-columns: 1fr;
  }

  .transport,
  .autoplay {
    justify-content: center;
  }

  .status {
    grid-row: 1;
  }
}

@media (max-width: 520px) {
  .app-shell {
    width: 100%;
    padding: 0;
  }

  .app-header {
    padding: 1rem;
  }

  .renderer {
    border-right: 0;
    border-left: 0;
    border-radius: 0;
  }

  .load-controls {
    align-items: stretch;
    flex-direction: column;
  }

  .load-controls > label:first-child {
    margin-bottom: -0.25rem;
  }

  .input-request {
    grid-template-columns: 1fr;
  }
}

@media (prefers-reduced-motion: reduce) {
  .button {
    transition: none;
  }
}
