/*!
 * monospaced.css v1.0.0
 * A super simple, monospaced, flat stylesheet for simple pages.
 * https://github.com/andrearufo/monospaced.css
 * (c) Andrea Rufo - https://www.andrearufo.it - GPL-3.0
 */

@use 'sass:color';
@use 'reset';

@import url('https://fonts.googleapis.com/css2?family=IBM+Plex+Mono:ital,wght@0,400;0,700;1,400&display=swap');

// -----------------------------------------------------------------------------
// Settings: override with `@use 'monospaced' with ($link-color: red);`
// -----------------------------------------------------------------------------

$font-family-base: 'IBM Plex Mono', ui-monospace, monospace !default;
$font-size-base: 1rem !default;
$line-height-base: 1.4 !default;

$background-color: #fff !default;
$font-color: #666 !default;
$light-color: color.adjust($font-color, $lightness: 50%) !default;
$border-color: #8c8c8c !default;
$link-color: #0f4c81 !default;
$link-hover-color: color.adjust($link-color, $lightness: -10%) !default;
$alert-color: #ffeaa7 !default;

$enable-dark-mode: true !default;
$dark-background-color: #1b1b1b !default;
$dark-font-color: #c8c8c8 !default;
$dark-light-color: #333 !default;
$dark-border-color: #777 !default;
$dark-link-color: #6fa8dc !default;
$dark-link-hover-color: #9cc3e6 !default;
$dark-alert-color: #4a3f17 !default;

$spacer: 1rem !default;
$breakpoint: 768px !default;
$input-height: 3rem !default;

// -----------------------------------------------------------------------------
// Helpers
// -----------------------------------------------------------------------------

@mixin responsive($size) {
  @if $size == large {
    @media (min-width: $breakpoint) {
      @content;
    }
  } @else {
    @media (max-width: ($breakpoint - 0.02px)) {
      @content;
    }
  }
}

// -----------------------------------------------------------------------------
// Theme (CSS custom properties, overridable at runtime)
// -----------------------------------------------------------------------------

:root {
  --mono-bg: #{$background-color};
  --mono-color: #{$font-color};
  --mono-light: #{$light-color};
  --mono-border: #{$border-color};
  --mono-link: #{$link-color};
  --mono-link-hover: #{$link-hover-color};
  --mono-alert: #{$alert-color};

  color-scheme: light;
}

@if $enable-dark-mode {
  @media (prefers-color-scheme: dark) {
    :root {
      --mono-bg: #{$dark-background-color};
      --mono-color: #{$dark-font-color};
      --mono-light: #{$dark-light-color};
      --mono-border: #{$dark-border-color};
      --mono-link: #{$dark-link-color};
      --mono-link-hover: #{$dark-link-hover-color};
      --mono-alert: #{$dark-alert-color};

      color-scheme: dark;
    }
  }
}

// -----------------------------------------------------------------------------
// Base
// -----------------------------------------------------------------------------

*,
*::before,
*::after {
  box-sizing: border-box;
}

body {
  background-color: var(--mono-bg);
  color: var(--mono-color);
  font-family: $font-family-base;
  font-size: $font-size-base;
  line-height: $line-height-base;
  accent-color: var(--mono-link);
}

:focus-visible {
  outline: 2px solid var(--mono-link);
  outline-offset: 2px;
}

.container {
  max-width: $breakpoint;
  margin: ($spacer * 4) auto;
  padding: $spacer;
}

// -----------------------------------------------------------------------------
// Typography
// -----------------------------------------------------------------------------

h1,
h2,
h3,
h4,
h5,
h6 {
  font-weight: 700;
  margin: ($spacer * 2) 0 $spacer;
}

// Markdown-like `#` prefixes for headings
$hashes: '';
@for $i from 1 through 6 {
  $hashes: $hashes + '#';

  h#{$i}::before {
    content: $hashes;
    padding-right: $spacer;
  }
}

p,
ul,
ol,
blockquote,
pre,
table {
  margin-bottom: $spacer;
}

a {
  color: var(--mono-link);
  text-decoration: none;

  &:hover {
    color: var(--mono-link-hover);
    text-decoration: underline;
  }
}

b,
strong {
  font-weight: 700;
}

em,
i {
  font-style: italic;
}

blockquote {
  border-left: 2px solid var(--mono-border);
  padding-left: $spacer;
}

code {
  background: var(--mono-light);
  padding: 2px 6px;
}

pre {
  background: var(--mono-light);
  padding: $spacer;
  overflow-x: auto;

  code {
    background: none;
    padding: 0;
  }
}

hr {
  border: 0;
  border-top: 1px solid var(--mono-light);
  margin: ($spacer * 2) 0;
}

img {
  display: block;
  max-width: 100%;
  height: auto;
}

// -----------------------------------------------------------------------------
// Lists
// -----------------------------------------------------------------------------

li {
  position: relative;
  padding-left: $spacer * 2;

  &::before {
    position: absolute;
    top: 0;
    left: 0;
  }
}

ul > li::before {
  content: '-';
}

ol {
  counter-reset: item;

  > li {
    counter-increment: item;

    &::before {
      content: counter(item) '.';
    }
  }
}

// -----------------------------------------------------------------------------
// Tables
// -----------------------------------------------------------------------------

table {
  width: 100%;
}

th,
td {
  padding: ($spacer * 0.5) $spacer;
  border-bottom: 1px solid var(--mono-light);
  text-align: left;
}

th {
  font-weight: 700;
}

// -----------------------------------------------------------------------------
// Forms
// -----------------------------------------------------------------------------

input,
button,
textarea,
select {
  margin: 0;
  color: inherit;
  font: inherit;
}

label,
input,
textarea,
select {
  display: block;
  width: 100%;
}

label {
  padding: $spacer;
}

input,
select {
  height: $input-height;
  padding: 0 $spacer;
}

textarea {
  min-height: $input-height * 3;
  padding: $spacer;
  resize: vertical;
}

input,
textarea,
select {
  background: var(--mono-bg);
  border: 1px solid var(--mono-border);
  border-radius: 0;

  &:disabled {
    background: var(--mono-light);
    cursor: not-allowed;
  }
}

input[type='checkbox'],
input[type='radio'] {
  display: inline-block;
  width: auto;
  height: auto;
  margin-right: $spacer * 0.5;
}

.btn {
  display: block;
  width: 100%;
  padding: 0 $spacer;
  border: 1px solid var(--mono-link);
  background: transparent;
  color: var(--mono-link);
  line-height: $input-height;
  text-align: center;
  cursor: pointer;

  &:hover {
    background: var(--mono-link);
    color: var(--mono-bg);
    text-decoration: none;
  }

  &:disabled {
    opacity: 0.5;
    cursor: not-allowed;
  }
}

button {
  @extend .btn;
}

// -----------------------------------------------------------------------------
// Components
// -----------------------------------------------------------------------------

.block {
  margin-bottom: $spacer;
}

.alert {
  background: var(--mono-alert);
  padding: $spacer;
}

.card {
  padding: $spacer;
  margin: $spacer 0;
  border: 1px solid var(--mono-light);
}

// -----------------------------------------------------------------------------
// Utilities
// -----------------------------------------------------------------------------

.transition {
  transition: all 0.3s;
}

@each $align in left, center, right {
  .text-#{$align} {
    text-align: $align;
  }

  .text-#{$align}-large {
    @include responsive(large) {
      text-align: $align;
    }
  }

  .text-#{$align}-small {
    @include responsive(small) {
      text-align: $align;
    }
  }
}
