@warning-red: #EA0027;
@orangered: #FF4500;
@orange: #FF8717;
@yellow: #FFD635;
@highlight: #FFF03E;
@gold: #D8C161;
@lime: #C7E223;
@green: #7CD344;
@teal: #25B79F;
@dark-teal: #008985;
// @link-blue: #218BB2;
// style guide @link-blue is #24A0ED, but that's too zesty for reddit.com
// using the @alien-blue color for links here instead
@link-blue: #0079D3;
@periwinkle: #9494FF;
@white: #FFFFFF;
@off-white: #FCFCF7;
@eggshell: #F2F1E9;
@pale-grey: #E5E3DA;
@grey: #B5B3AC;
@semi-black: #222222;

// non-styleguide colors:
@ui-blue: #336699;
@ads-blue: #6093BF;
@ads-grey: #F8F8F8;
@dark-grey: #808080;
@text-grey: #706f6f;

@base-font-keyword: small;
@base-font-keyword-size: 13; // small == 13px;

// all of the font sizes used between comments, sidebar, and wiki
@font-x-small: 12;
@font-small: 14;
@font-medium: 16;
@font-large: 18;
@font-x-large: 20;
@font-xx-large: 24;
@font-xxx-large: 32;

// line heights to go with the font sizes
@line-x-small: 15;
@line-small: 20;
@line-medium: 20;
@line-large: 25;
@line-x-large: 25;
@line-xx-large: 30;
@line-xxx-large: 40;

// margins used, don't necessarily correlate directly with font sizes
@margin-x-small: 5;
@margin-small: 10;
@margin-medium: 15;
@margin-large: 20;
@margin-x-large: 25;
@margin-xx-large: 30;
@margin-xxx-large: 40;


.md-font-size(@base, @font, @line) {
  font-size: (@font / @base) * 1em;
  line-height: (@line / @font) * 1em;
}

.md-margins(@font, @top, @bottom) {
  margin-top: (@top / @font) * 1em;
  margin-bottom: (@bottom / @font) * 1em;
}

.md-base-font-size(@font-size) {
  font-size: (@font-size / @base-font-keyword-size) * 1em;
}


.md-container {
  font-size: @base-font-keyword;
}

.md {
  h1, h2, h3, h4, h5, h6 {
    &:extend(.md .-headers all);
  }

  th, td {
    &:extend(.md .-cells all);
  }

  ul, ol {
    &:extend(.md .-lists all);
  }

  .-lists, pre, blockquote, table, p {
    &:extend(.md .-blocks all);
  }

  p, pre > code, th, td, li {
    &:extend(.md .-text all);
  }

  max-width: 60em;
  color: @semi-black;

  .-headers {
    border: 0;
    color: inherit;
    -webkit-font-smoothing: antialiased;

    code {
      font-size: inherit;
    }
  }

  blockquote,
  del {
    color: @text-grey;
  }

  a {
    color: @link-blue;
    text-decoration: none;
  }

  h6 {
    text-decoration: underline;
  }

  em {
    font-style: italic;
    font-weight: inherit;
  }

  th,
  strong,
  .-headers {
    font-weight: 600;
    font-style: inherit;
  }

  h2,
  h4 {
    font-weight: 500;
  }

  &,
  h6 {
    font-weight: 400;
  }

  * {
    margin-left: 0;
    margin-right: 0;
  }

  tr,
  code,
  .-cells,
  .-lists,
  .-blocks,
  .-headers {
    margin: 0;
    padding: 0;
  }

  hr {
    border: 0;
    color: transparent;
    background: @pale-grey;
    height: 2px;
    padding: 0;
  }

  blockquote {
    border-left: 2px solid @pale-grey;
  }

  code,
  pre {
    border: 1px solid darken(@off-white, 10%);
    background-color: @off-white;
    border-radius: 2px;
  }

  code {
    margin: 0 2px;
    white-space: nowrap;
  }

  pre {
    overflow: auto;

    code {
      white-space: pre;
      background-color: transparent;
      border: 0;
      display: block;
      padding: 0 !important;
    }
  }

  // can't rely on &:extend here, doesn't apply the align rules
  td, th {
    border: 1px solid @pale-grey;
    text-align: left;

    &[align=center] {
      text-align: center;
    }

    &[align=right] {
      text-align: right;
    }
  }

  img {
    max-width: 100%;
  }

  ul {
    list-style-type: disc;
  }

  ol {
    list-style-type: decimal;
  }

  blockquote {
    // -2 to compensate for border
    padding: 0 ((@margin-small - 2) * 1px);
  }

  code {

    padding: 0 ((@margin-x-small - 1) * 1px);
  }

  pre,
  .-cells {
    padding: ((@margin-x-small - 1) * 1px) ((@margin-small - 1) * 1px);
  }

  .-lists {
    padding-left: (@margin-x-large * 1px);
  }

  sup {
    font-size: 0.86em;
    line-height: 0;
  }

  li li,
  li p {
    font-size: 1em !important;
  }
}


.link .usertext .md {
  padding: (@margin-x-small * 1px) (@margin-small * 1px);
}

.commentarea .md {
  margin: (@margin-x-small * 1px) 0;
}


.md {
  @font-base: @font-small;
  @line-base: @line-small;

  .md-base-font-size(@font-base);

  h1,
  h2 {
    .md-font-size(@font-base, @font-large, @line-large);
    .md-margins(@font-large, @margin-medium, @margin-medium);
  }

  h3,
  h4 {
    .md-font-size(@font-base, @font-medium, @line-medium);
    .md-margins(@font-medium, @margin-small, @margin-small);
  }

  h5,
  h6 {
    .md-font-size(@font-base, @font-base, @line-base);
    .md-margins(@font-base, @margin-small, @margin-x-small);
  }

  .-blocks {
    .md-margins(@font-base, @margin-x-small, @margin-x-small);
  }

  .-text {
    .md-font-size(@font-base, @font-base, @line-base);
  }
}

.side .md {
  @font-base: @font-x-small;
  @line-base: @line-x-small;

  .md-base-font-size(@font-base);

  h1,
  h2 {
    .md-font-size(@font-base, @font-large, @line-large);
    .md-margins(@font-large, @margin-small, @margin-small);
  }

  h3,
  h4 {
    .md-font-size(@font-base, @font-medium, @line-medium);
    .md-margins(@font-medium, @margin-small, @margin-small);
  }

  h5,
  h6 {
    .md-font-size(@font-base, @font-small, @line-small);
    .md-margins(@font-small, @margin-small, @margin-x-small);
  }

  .-blocks {
    .md-margins(@font-base, @margin-x-small, @margin-x-small);
  }

  .-text {
    .md-font-size(@font-base, @font-base, @line-base);
  }
}

.wiki-page-content .md {
  @font-base: @font-small;
  @line-base: @line-small;

  h1 {
    .md-font-size(@font-base, @font-xxx-large, @line-xxx-large);
    .md-margins(@font-xxx-large, @margin-xxx-large, @margin-x-large);
  }

  h2 {
    .md-font-size(@font-base, @font-xx-large, @line-xx-large);
    .md-margins(@font-xx-large, @margin-xx-large, @margin-medium);
  }

  h3 {
    .md-font-size(@font-base, @font-x-large, @line-x-large);
    .md-margins(@font-x-large, @margin-large, @margin-small);
  }

  .-blocks {
    .md-margins(@font-base, @margin-x-small, @margin-small);
  }

  // Style changes for wiki pages
  h1,
  h6 {
    color: @text-grey;
    font-weight: 300;
  }

  h2 {
    color: @ui-blue;
  }

  h2,
  h3 {
    font-weight: 600;
  }

  h4 {
    font-style: italic;
  }

  h5 {
    text-decoration: underline;
  }

  h4,
  h5 {
    font-weight: 400;
  }

  h6 {
    .md-font-size(@font-base, @font-base, @line-base);
    .md-margins(@font-base, @margin-medium, @margin-x-small);

    text-decoration: none;
    text-transform: uppercase;
    letter-spacing: 1px;
  }
}


.md {
  &,
  .-cells,
  .-lists,
  .-blocks,
  .-headers {
    > :first-child {
      margin-top: 0;
    }

    > :last-child {
      margin-bottom: 0;
    }
  }

  li {
    > :first-child {
      margin-top: 0;
      
      &:last-child {
        margin-bottom: 0;
      }
    }
  }
}
