/*
see https://www.joshwcomeau.com/css/custom-css-reset/
*/

/* 1. Box-sizing model */

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

html {
    scroll-behavior: smooth;
    /* 3. Enable keyword animations */
    interpolate-size: allow-keywords;
}

* {
    /* 2. Remove default margin */
    margin: 0;

    /*
        3. Add accessible line-height 
        see https://kittygiraudel.com/2020/05/18/using-calc-to-figure-out-optimal-line-height/
    */
    line-height: calc(2px + 2ex + 2px);
}

body {
    /* 4. Improve text rendering */
    -webkit-font-smoothing: antialiased;
}

/* 5. Improve media defaults */

img, picture, video, canvas, svg {
    display: block;
    max-width: 100%;
}

/* 6. Inherit fonts for form controls */

input, button, textarea, select {
    font: inherit;
}

/* 7. Avoid text overflows */

p {
    text-wrap: pretty;
    overflow-wrap: break-word;
    hyphens: auto;
}

/* 8. Improve line wrapping */

h1, h2, h3, h4, h5, h6 {
    text-wrap: balance;
    overflow-wrap: break-word;
}

/*
  9. Create a root stacking context

  __OPTIONAL__

  see https://www.joshwcomeau.com/css/custom-css-reset/#nine-root-stacking-context-10
  see https://www.joshwcomeau.com/css/stacking-contexts/
*/

#root {
    isolation: isolate;
}

/* see https://gomakethings.com/how-to-animate-scrolling-to-anchor-links-with-one-line-of-css/#accessibility-concerns */

@media (prefers-reduced-motion: reduce) {
    html {
        scroll-behavior: auto;
    }
}

@keyframes spinner {
  to {
    transform: rotate(360deg);
  }
}

substrate-button button, substrate-button a.btn {
  color: #000;
  cursor: pointer;
  background: none;
  border: 1px solid;
  outline: 1px solid rgba(0, 0, 0, 0);
  padding: .5rem 2rem;
  font-size: 1rem;
  text-decoration: none;
  transition: all .2s;
  transform: translateY(1px);
}

:is(substrate-button button, substrate-button a.btn):focus {
  outline: 1px solid;
}

:is(substrate-button button, substrate-button a.btn):hover {
  outline: 1px solid;
  transform: translateY(0);
}

:is(substrate-button button, substrate-button a.btn):active {
  transform: translateY(2px);
}

:is(substrate-button button, substrate-button a.btn):disabled {
  cursor: not-allowed;
  opacity: .4;
}

:is(substrate-button button, substrate-button a.btn):disabled:hover {
  outline-color: rgba(0, 0, 0, 0);
  transform: translateY(1px);
}

:is(substrate-button button, substrate-button a.btn).spinning {
  opacity: .4;
}

:is(substrate-button button, substrate-button a.btn).spinning .btn-content {
  visibility: hidden;
}

:is(substrate-button button, substrate-button a.btn).spinning:hover {
  cursor: initial;
}

:is(substrate-button button, substrate-button a.btn).spinning:after {
  content: "";
  box-sizing: border-box;
  background: none;
  border-top: 2px solid #000;
  border-right: 2px solid rgba(0, 0, 0, 0);
  border-radius: 50%;
  width: 16px;
  height: 16px;
  margin: auto;
  animation: .6s linear infinite spinner;
  position: absolute;
  top: 0;
  bottom: 0;
  left: 0;
  right: 0;
}

body {
    margin: 0;
    font-family: 'Gill Sans', 'Gill Sans MT', Calibri, 'Trebuchet MS', sans-serif;
    background: #f6f7fb;
}

.page {
    width: min(1200px, 100% - 2rem);
    margin: 2rem auto;
    display: grid;
    gap: 1rem;
}

h1, h2 {
    margin: 0 0 0.5rem;
}

.columns,
.result {
    background: white;
    border: 1px solid #d9dce4;
    padding: 1rem;
}

.columns {
    display: grid;
    gap: 1rem;
    grid-template-columns: 1fr 1fr;
}

.column {
    display: grid;
    gap: 0.5rem;
    align-content: start;
}

.editor {
    width: 100%;
    min-height: 220px;
    border: 1px solid #c9d0dc;
    padding: 0.75rem;
    background: #fcfdff;
    font: inherit;
    resize: vertical;
}

textarea.editor {
    font-family: 'Courier New', Courier, monospace;
}

.controls {
    display: flex;
    align-items: center;
    gap: 0.5rem;

    & substrate-button {
        margin-top: 1.5rem;
    }
}

.output,
.error {
    margin: 0 0 1rem;
    padding: 0.75rem;
    border: 1px solid #d9dce4;
    background: #f9fafc;
    white-space: pre-wrap;
    overflow-wrap: anywhere;
}

.error {
    border-color: #d14a4a;
    background: #fff1f1;
    color: #8f1d1d;
}

.live {
    border: 1px dashed #c1c7d3;
    padding: 0.75rem;
}

@media (max-width: 900px) {
    .columns {
        grid-template-columns: 1fr;
    }

    .editor {
        min-height: 180px;
    }
}
