/**
 * Copyright 2024 Sebastian Rasor <https://www.sebastianrasor.com/contact>
 *
 * This file is part of www.sebastianrasor.com
 *
 * www.sebastianrasor.com is free software: you can redistribute it and/or 
 * modify it under the terms of the GNU Affero General Public License as
 * published by the Free Software Foundation, either version 3 of the License,
 * or (at your option) any later version.
 *
 * www.sebastianrasor.com is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of 
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Affero
 * General Public License for more details.
 *
 * You should have received a copy of the GNU Affero General Public License
 * along with www.sebastianrasor.com. If not, see
 * <https://www.gnu.org/licenses/>.
 */

:root {
  --gap: 2rem;
  --min-width: min(calc(100vw - 3rem), calc(32ch + var(--gap)));
  --padding: 1ch;
  --primary: #000;
  --secondary: #fff;
}

@media (prefers-color-scheme: dark) {
  :root {
    --primary: #fff;
    --secondary: #000;
  }
}

html,
body {
  height: 100%;
  margin: 0;
}

body {
  background: var(--secondary);
  color: var(--primary);
  display: flex;
  flex-direction: column;
  font-family: 'Atkinson Hyperlegible', sans-serif;
  font-size: calc(14pt + 0.5vw);
  user-select: none;
  -webkit-user-select: none; /* Safari */
}

a {
  color: var(--primary);
}

article {
  margin: auto;
  min-width: var(--min-width);
  padding: var(--padding);
  width: 50%;
}

main {
  align-items: center;
  display: flex;
  flex-grow: 1;
  justify-content: center;
  overflow: auto;
}

/* This monstrosity selects the last visible element of main */
main > *:nth-last-child(1 of :not([hidden])) {
  padding-bottom: calc(var(--gap) + 3ch + 0.667em)
}

form {
  align-items: center;
  display: flex;
  flex-direction: column;
  gap: var(--gap);
  margin: auto;
  min-width: var(--min-width);
  padding: var(--padding);
  width: 50%;
}

.button {
  background-color: var(--primary);
  border: 1px var(--primary) solid;
  color: var(--secondary);
  cursor: pointer;
  font-weight: bold;
  height: 0.667em;
  line-height: 0.667em;
  padding: var(--padding);
  text-decoration-line: none;
}

/* These properties aren't currently available, but use them when they are */
@supports (text-box-edge: cap alphabetic) and (text-box-trim: both) {
  .button {
    height: unset;
    line-height: unset;
    text-box-edge: cap alphabetic;
    text-box-trim: both;
  }
}

.button-disabled {
  background-color: var(--secondary);
  border: 1px var(--primary) solid;
  color: #757575;
  cursor: default;
}

input,
textarea {
  all: unset;
  border-bottom: 1px var(--primary) solid;
}

input:not(.button):read-only,
textarea:read-only {
  pointer-events: none;
}

textarea {
  border-right: 1px var(--primary) solid;
  overflow-wrap: break-word;
}

textarea:read-only {
  color: transparent;
  overflow: hidden;
  overflow-wrap: unset;
}

.input-container {
  display: grid;
  width: 100%;
}

.input-container * {
  grid-column: 1;
  grid-row: 1;
  width: 100%;
}

.horizontal-container {
  display: flex;
  flex-direction: row;
  flex-wrap: wrap;
  gap: var(--gap);
  justify-content: space-between;
  width: 100%;
}

.horizontal-container
.input-container {
  flex: 16ch;
}

input + label,
textarea + label {
  color: #757575;
  pointer-events: none;
  transform-origin: bottom left;
  transition: color 0.25s, transform 0.25s, width 0.25s;
}

input:focus + label,
input:not(:placeholder-shown) + label,
textarea:focus + label,
textarea:not(:read-only, :placeholder-shown) + label {
  color: var(--primary);
  cursor: default;
  transform: scale(75%) translate(0, 100%);
  transition: color 0.25s, transform 0.25s, width 0.25s;
  width: calc(100% + (100% / 3));
}

nav {
  background: var(--secondary);
  bottom: var(--padding);
  box-shadow: 0 0 0.5ch 1ch var(--secondary);
  display: flex;
  gap: var(--padding);
  justify-content: center;
  left: 50%;
  position: fixed;
  transform: translate(-50%);
}

[hidden],
.cf-turnstile {
  display: none;
  position: absolute;
}
