$hiborder: rgba($teal, .3);

@mixin try-button {
  & {
    cursor: pointer;
    background: $teal;
    color: white;
    text-align: center;
    border: 0;
    outline: 0;
    border-radius: 3px;
    font-weight: bold;

    height: 26px;
    line-height: 26px - 2px;
    font-size: 13px;
  }

  &:focus,
  &:hover {
    background: lighten($teal, 10%);
  }

  &:active {
    background: darken($teal, 10%);
  }

  &::before {
    @include ion-icon('play');
    font-size: 12px;
    margin-right: 8px;
    position: relative;
    top: -1px;
  }
}

@mixin textarea {
  width: 100%;
  background: transparent;
  padding: 0;
  border: 0;
  outline: 0;
  font-size: 12px;
  font-family: $monospace;
  letter-spacing: -.05em;
  color: $blue;
  min-height: 1.7em;
  line-height: 1.5em;
  margin: 0;
  @include antialias;
}

@mixin code-block {
  padding: 0;
  background: $skyblue;
  border: solid 1px $hiborder;
  border-radius: 2px;
}

/*
 * Givens
 */

.example-givens {
  @include code-block;

  // "Dock" into the example
  border: 0;
  border-radius: 0;
  border-bottom: solid 1px $hiborder;
  position: relative;

  // eh, in case
  .example-output + & {
    border-top: solid 1px $hiborder;
    border-bottom: 0;
  }

  &.-hide {
    display: none;
  }

  > h3 {
    text-align: right;
    font-size: .9em;
    margin: 0;
    padding: 0;
    position: absolute;
    right: 12px;
    top: 12px;
    pointer-events: none;
  }
}

/*
 * .example-givens
 *   .example-given
 *   .example-given
 *
 * .example-block
 *   .example-example
 *     .code
 *     .try
 *     .secret
 *   .example-output
 *   .example-givens  <- will be placed here dynamically
 */

.example-block {
  margin-bottom: 16px;

  &.example-block {
    @include code-block;
  }

  > .example-example,
  > .example-output {
    padding: 8px;
  }
}

.example-given {
  font-size: 0;

  > textarea {
    @include textarea;
    padding: 16px;
    padding-bottom: 0;
    box-sizing: content-box;
    resize: none;
  }

  &.-hide {
    display: none;
  }
}

.example-example {
  display: flex;
  cursor: text;

  &:hover {
    box-shadow: inset 0 0 4px rgba($teal, .2);
  }

  // Focused
  .example-givens + & {
    background: darken($skyblue, 2%);
  }

   & + & {
    border-top: solid 1px rgba($blue, .2);
  }

  > .code {
    flex: 1 1 99%;
    padding-left: 8px;
  }

  > .code > textarea {
    @include textarea;
    resize: none;
  }

  > .code > textarea,
  > .code > .placeholder > pre {
    position: relative;
    top: 5px; // Compensate for line height
  }

  > .code > .placeholder > pre {
    @include textarea;
    padding: 0;
    margin: 0;
    padding-bottom: 8px;
    cursor: text;
  }

  > .code > .hint {
    font-style: italic;
    font-family: $serif;
    color: mix($blue, $gray, 20%);
    font-size: .83em;
  }

  > .code > .hint.-hide {
    display: none;
  }

  > .code > .hint::before {
    @include ion-icon('android-bulb');
    font-size: 16px;
    vertical-align: middle;
    margin-right: 8px;
    margin-top: -2px;
    color: $teal;
  }

  > .try {
    @include try-button;
    flex: 1 0 10px;
    white-space: nowrap;
    padding-left: 16px;
    padding-right: 16px;
    margin-left: 8px;
  }
}

.example-output {
  background-color: white;
  border-top: solid 1px $hiborder;
  padding-left: 16px;
  overflow: hidden;
  transition: background-color 250ms linear;

  &.example-output.example-output {
    padding: 4px 0;
  }

  &.-hide {
    display: none;
  }

  &.-highlight {
    transition: none;
    background-color: #fefef0;
  }
}

.example-block.-discreet {
  border-color: transparent;
  background: transparent;

  .try {
    opacity: 0;
  }

  &.-focus {
    border-color: $hiborder;
    .try { opacity: 1; }
  }
}
