* {
  box-sizing: border-box;
}

:root {
  --color-0: #00FF7F;
  --color-1: #00FFFF;
  --color-2: #00BFFF;
  --color-3: #1E90FF;
  --color-4: #6495ED;
  --color-5: #40E0D0;
  --color-6: #3CB371;
  --color-red: #ff6b6b;
  --color-red-dark: #e05555;
  --substitution-bg: #3d1010;
  --substitution-highlight: #5a1818;
  --source-bg: #3d3d10;
  --bg-color: #1a1a1a;
  --panel-bg: #242424;
  --text-color: #e0e0e0;
  --text-muted: #888;
  --border-color: #333;
}

body {
  font-family: 'SF Mono', 'Monaco', 'Inconsolata', 'Roboto Mono', monospace;
  background: var(--bg-color);
  color: var(--text-color);
  margin: 0;
  padding: 0;
  height: 100vh;
  display: flex;
  flex-direction: column;
}

.header {
  padding: 0.9375rem 1.25rem;
  border-bottom: 0.0625rem solid var(--border-color);
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-shrink: 0;

  h1 {
    margin: 0;
    font-size: 1rem;
    font-weight: 500;
    color: var(--color-2);
  }
}

.header-actions {
  display: flex;
  gap: 0.625rem;
}

.header-btn {
  background: var(--panel-bg);
  border: none;
  color: var(--text-muted);
  padding: 0.375rem 0.75rem 0.625rem 0.75rem;
  cursor: pointer;
  font-family: inherit;
  font-size: 0.75rem;
  transition: all 0.2s;
  box-shadow: 0.125rem 0.125rem 0 rgba(0, 191, 255, 0.3);

  &:hover {
    color: var(--color-2);
    box-shadow: 0.1875rem 0.1875rem 0 rgba(0, 191, 255, 0.5);
  }

  &.primary {
    background: var(--color-0);
    color: #000;
    font-weight: 500;
    box-shadow: 0.125rem 0.125rem 0 rgba(0, 255, 127, 0.5);

    &:hover {
      background: var(--color-5);
      box-shadow: 0.1875rem 0.1875rem 0 rgba(64, 224, 208, 0.6);
    }
  }

  &.clear-btn {
    background: var(--color-red);
    color: #000;
    font-weight: 500;
    box-shadow: 0.125rem 0.125rem 0 rgba(255, 107, 107, 0.5);

    &:hover {
      background: var(--color-red-dark);
      box-shadow: 0.1875rem 0.1875rem 0 rgba(224, 85, 85, 0.6);
    }
  }
}

.conversation {
  flex: 1;
  overflow-y: auto;
  padding: 1.25rem;
  display: flex;
  flex-direction: column;
  gap: 1rem;

  &::-webkit-scrollbar {
    width: 0.5rem;
  }

  &::-webkit-scrollbar-track {
    background: var(--bg-color);
  }

  &::-webkit-scrollbar-thumb {
    background: var(--border-color);

    &:hover {
      background: var(--text-muted);
    }
  }
}

.message {
  background: var(--panel-bg);
  border: none;
  padding: 1rem;
  position: relative;
  box-shadow: 0.1875rem 0.1875rem 0 rgba(0, 191, 255, 0.2);

  &.system-message {
    background: transparent;
    border: 0.0625rem dashed var(--border-color);
    box-shadow: none;
    color: var(--text-muted);
    font-size: 0.8125rem;
    text-align: center;
  }
}

.message-header {
  display: flex;
  align-items: center;
  gap: 0.625rem;
  margin-bottom: 0.75rem;
  font-size: 0.75rem;
  color: var(--text-muted);
}

.step-badge {
  background: var(--color-2);
  color: #000;
  padding: 0.125rem 0.5rem;
  font-weight: 600;
  font-size: 0.6875rem;
}

.reduction-info {
  color: var(--text-muted);
}

.discarded-arg {
  display: inline-flex;
  align-items: center;
  gap: 0.25rem;
  background: var(--substitution-bg);
  padding: 0.125rem 0.375rem;
  margin-left: 0.5rem;
  font-size: 0.6875rem;
  color: #e0e0e0;
  cursor: help;
  box-shadow: 0.0625rem 0.0625rem 0 rgba(139, 0, 0, 0.4);
  border: 0.0625rem solid #6a2020;

  .discarded-label {
    color: #ff6b6b;
    font-weight: 500;
  }

  code {
    background: rgba(0, 0, 0, 0.3);
    padding: 0.0625rem 0.25rem;
    font-family: inherit;
    max-width: 9.375rem;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }
}

.expression-content {
  font-size: 1rem;
  line-height: 1.6;
  overflow-x: auto;
  padding: 0.5rem 0;
}

.expression-pre {
  margin: 0;
  font-family: inherit;
  font-size: inherit;
  white-space: pre-wrap;
  word-wrap: break-word;
}

.redex-line {
  margin-top: 0.5rem;
  padding-top: 0.5rem;
  border-top: 0.0625rem solid var(--border-color);
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  align-items: center;
}

.redex-label {
  font-size: 0.75rem;
  color: var(--text-muted);
  margin-right: 0.25rem;
}

.redex-choice {
  padding: 0.25rem 0.625rem;
  cursor: pointer;
  font-family: inherit;
  font-weight: 500;
  font-size: 0.75rem;
  border: none;
  transition: all 0.2s;

  &:hover {
    transform: translateY(-0.0625rem);
    filter: brightness(1.1);
  }

  &.depth-0 { background: var(--color-0); color: #000; box-shadow: 0.125rem 0.125rem 0 rgba(0, 255, 127, 0.5); }
  &.depth-1 { background: var(--color-1); color: #000; box-shadow: 0.125rem 0.125rem 0 rgba(0, 255, 255, 0.5); }
  &.depth-2 { background: var(--color-2); color: #fff; box-shadow: 0.125rem 0.125rem 0 rgba(0, 191, 255, 0.5); }
  &.depth-3 { background: var(--color-3); color: #fff; box-shadow: 0.125rem 0.125rem 0 rgba(30, 144, 255, 0.5); }
  &.depth-4 { background: var(--color-4); color: #fff; box-shadow: 0.125rem 0.125rem 0 rgba(100, 149, 237, 0.5); }
  &.depth-5 { background: var(--color-5); color: #000; box-shadow: 0.125rem 0.125rem 0 rgba(64, 224, 208, 0.5); }
  &.depth-6 { background: var(--color-6); color: #fff; box-shadow: 0.125rem 0.125rem 0 rgba(60, 179, 113, 0.5); }
}

.normal-form-badge {
  background: var(--color-6);
  color: #fff;
  padding: 0.25rem 0.625rem;
  font-size: 0.75rem;
  font-weight: 500;
  box-shadow: 0.125rem 0.125rem 0 rgba(60, 179, 113, 0.5);
}

.input-box {
  background: var(--panel-bg);
  grid-row: 1;
  border-top: 0.0625rem solid var(--border-color);

  &.examples-box {
    grid-column: 1;
  }

  &.main-box {
    grid-column: 3 / 5;
  }
}

#input-area {
  display: grid;
  grid-template-columns: auto 2rem auto 1fr;
  flex-shrink: 0;

  .examples-btn {
    grid-row: 1;
    grid-column: 1;
    margin: 0.75rem 1rem;
  }

  .reduce-btn {
    grid-row: 1;
    grid-column: 3;
    margin: 0.75rem 1rem;
  }

  input#lambda-input {
    grid-row: 1;
    grid-column: 4;
    margin: 0.75rem 1rem 0.75rem 0;
    padding: 0.75rem 1rem;
    background: var(--bg-color);
    border: none;
    font-family: inherit;
    font-size: 0.875rem;
    color: var(--text-color);
    box-shadow: inset 0.125rem 0.125rem 0 rgba(0, 0, 0, 0.3);

    &:focus {
      outline: none;
      box-shadow: inset 0.125rem 0.125rem 0 rgba(0, 0, 0, 0.3), 0 0 0 0.125rem var(--color-2);
    }

    &::placeholder {
      color: var(--text-muted);
    }
  }
}

.examples-btn,
.reduce-btn,
.header-btn {
  position: relative;
}

.keybind-badge {
  position: absolute;
  bottom: 0.125rem;
  left: 0.25rem;
  font-size: 0.5rem;
  font-weight: 400;
  opacity: 0.7;
  text-transform: uppercase;
  letter-spacing: 0.03em;
}

.examples-btn {
  padding: 0.75rem 1.25rem 1rem 1.25rem;
  background: var(--color-0);
  color: #000;
  border: none;
  cursor: pointer;
  font-family: inherit;
  font-weight: 500;
  transition: all 0.2s;
  box-shadow: 0.125rem 0.125rem 0 rgba(0, 255, 127, 0.5);

  &:hover {
    background: var(--color-5);
    box-shadow: 0.1875rem 0.1875rem 0 rgba(64, 224, 208, 0.6);
  }
}

.reduce-btn {
  padding: 0.75rem 1.25rem 1rem 1.25rem;
  background: var(--color-2);
  color: #000;
  border: none;
  cursor: pointer;
  font-family: inherit;
  font-weight: 500;
  transition: all 0.2s;
  box-shadow: 0.125rem 0.125rem 0 rgba(0, 191, 255, 0.5);

  &:hover {
    background: var(--color-3);
    color: #fff;
    box-shadow: 0.1875rem 0.1875rem 0 rgba(30, 144, 255, 0.5);
  }
}

.modal-overlay {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0, 0, 0, 0.7);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s;

  &.visible {
    opacity: 1;
    pointer-events: auto;
  }
}

.modal {
  background: var(--panel-bg);
  border: none;
  padding: 1.5rem;
  max-width: 37.5rem;
  width: 90%;
  max-height: 80vh;
  overflow-y: auto;
  box-shadow: 0.25rem 0.25rem 0 rgba(0, 191, 255, 0.4);

  h2 {
    margin: 0 0 1rem 0;
    font-size: 1rem;
    font-weight: 500;
    color: var(--color-2);
  }
}

.examples-list {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.example-item {
  background: var(--bg-color);
  border: none;
  padding: 0.75rem 1rem;
  cursor: pointer;
  transition: all 0.2s;
  box-shadow: 0.125rem 0.125rem 0 rgba(64, 224, 208, 0.3);

  &:hover {
    box-shadow: 0.1875rem 0.1875rem 0 rgba(64, 224, 208, 0.5);
  }

  .name {
    font-weight: 500;
    color: var(--text-color);
    margin-bottom: 0.25rem;
  }

  .desc {
    font-size: 0.75rem;
    color: var(--text-muted);
    margin-bottom: 0.375rem;
  }

  .expr {
    font-size: 0.75rem;
    color: var(--color-5);
  }
}

.paren {
  font-weight: bold;

  &.depth-0 { color: var(--color-0); }
  &.depth-1 { color: var(--color-1); }
  &.depth-2 { color: var(--color-2); }
  &.depth-3 { color: var(--color-3); }
  &.depth-4 { color: var(--color-4); }
  &.depth-5 { color: var(--color-5); }
  &.depth-6 { color: var(--color-6); }
}

.redex-indicator {
  display: inline;
  font-size: 0.625rem;
  padding: 0.0625rem 0.1875rem;
  margin-left: 0.0625rem;
  vertical-align: super;
  cursor: pointer;
  font-weight: bold;
  transition: all 0.2s;

  &:hover {
    filter: brightness(1.2);
  }

  &.depth-0 { background: var(--color-0); color: #000; box-shadow: 0.0625rem 0.0625rem 0 rgba(0, 255, 127, 0.5); }
  &.depth-1 { background: var(--color-1); color: #000; box-shadow: 0.0625rem 0.0625rem 0 rgba(0, 255, 255, 0.5); }
  &.depth-2 { background: var(--color-2); color: #fff; box-shadow: 0.0625rem 0.0625rem 0 rgba(0, 191, 255, 0.5); }
  &.depth-3 { background: var(--color-3); color: #fff; box-shadow: 0.0625rem 0.0625rem 0 rgba(30, 144, 255, 0.5); }
  &.depth-4 { background: var(--color-4); color: #fff; box-shadow: 0.0625rem 0.0625rem 0 rgba(100, 149, 237, 0.5); }
  &.depth-5 { background: var(--color-5); color: #000; box-shadow: 0.0625rem 0.0625rem 0 rgba(64, 224, 208, 0.5); }
  &.depth-6 { background: var(--color-6); color: #fff; box-shadow: 0.0625rem 0.0625rem 0 rgba(60, 179, 113, 0.5); }
}

.substitution-box {
  display: inline;
  background: var(--substitution-bg);
  padding: 0.125rem 0.25rem;
  box-shadow: 0.125rem 0.125rem 0 rgba(139, 0, 0, 0.4);
  cursor: pointer;
  border: 0.0625rem solid #6a2020;

  &.highlight {
    background: var(--substitution-highlight);
    box-shadow: 0.1875rem 0.1875rem 0 rgba(139, 0, 0, 0.6);
    border: 0.0625rem solid #8a3030;
  }
}

.func,
.arg {
  display: inline;
}

.source-highlight {
  background: var(--source-bg) !important;
  box-shadow: 0.125rem 0.125rem 0 rgba(154, 154, 0, 0.5) !important;
  padding: 0.25rem 0.375rem;
  border: 0.125rem solid #9a9a00;
  margin: 0.0625rem;
}

.source-hover {
  background: #4a4a15 !important;
  box-shadow: 0.25rem 0.25rem 0 rgba(200, 200, 0, 0.8) !important;
  border: 0.125rem solid #d4d400;
}

.param-use-box {
  display: inline;
  background: #102040;
  padding: 0.125rem 0.25rem;
  box-shadow: 0.125rem 0.125rem 0 rgba(30, 144, 255, 0.4);
  cursor: pointer;
  border: 0.0625rem solid #1e60a0;

  &.highlight {
    background: #183060;
    box-shadow: 0.1875rem 0.1875rem 0 rgba(30, 144, 255, 0.6);
    border: 0.0625rem solid #3080d0;
  }
}
