/* Karton CSS - A classless theme inspired by cardboard aesthetics */

/* Normalize CSS */
@import 'https://cdn.jsdelivr.net/npm/normalize-css@2.3.1/normalize.min.css';

/* variables */
:root {
  --primary-background: #fdfaf6;
  --secondary-background: #dca;
  --text-color: #3e2e1e;
  --primary-color: #333;
  --secondary-color: #c43;
  --link-hover-border: #8c5e3c;
  --link-visited: #7a5e3c;
}

/* hide not defined WebComponents against FOUC */
:not(:defined) {
  visibility: hidden !important;
  display: none !important;
  opacity: 0 !important;
}

/* hide elements with the hidden attribute */
[hidden] {
  visibility: hidden;
}

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

html {
  font-size: 62.5%;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, "Noto Sans", sans-serif;
}

body {
  font-size: clamp(1.4rem, 1.2vw + 1rem, 1.8rem);
  line-height: 1.618;
  max-width: 42em;
  flex-direction: column;
  margin: auto;
  color: var(--text-color);
  padding: 16px;
  display: flex;
  background: linear-gradient(0deg, rgba(220, 220, 220, 0.9), rgba(220, 220, 220, 0.9)), url(https://cdn.jsdelivr.net/npm/kartoncss/karton-element.svg);
  background-size: 150px;
  background-repeat: repeat;
}

@media (max-width: 684px) {
  body { font-size: 1.6rem; }
}
@media (max-width: 382px) {
  body { font-size: 1.4rem; }
}

h1, h2, h3, h4, h5, h6 {
  line-height: 1.1;
  font-weight: 700;
  margin-top: 3rem;
  margin-bottom: 1.5rem;
  word-break: break-word;
}

h1 { font-size: 2.6em; }
h2 { font-size: 2.2em; }
h3 { font-size: 1.9em; }
h4 { font-size: 1.6em; }
h5 { font-size: 1.3em; }
h6 { font-size: 1.1em; }

p {
  margin: 0 0 2rem;
}

small, sub, sup {
  font-size: 75%;
}

hr {
  border-color: var(--primary-color);
  margin: 3rem 0;
}

a {
  text-decoration: none;
  color: var(--primary-color);
  border-bottom: 1px solid var(--primary-color);
}
a:hover {
  color: var(--secondary-color);
  border-bottom: 2px solid var(--link-hover-border);
}
a:visited {
  color: var(--link-visited);
}

a, button {
  transition: color 0.3s ease, background-color 0.3s ease, border-bottom-color 0.3s ease;
}

blockquote {
  padding: 1rem;
  margin-bottom: 2rem;
  border-left: 5px solid var(--primary-color);
  background-color: var(--secondary-background);
  border-radius: 4px;
}

blockquote p {
  margin: 0;
}

img, video {
  height: auto;
  max-width: 100%;
  margin-bottom: 2rem;
  display: block;
}

pre {
  background-color: var(--primary-background);
  padding: 1rem;
  overflow-x: auto;
  font-size: 0.9em;
  margin-bottom: 2rem;
  border-radius: 4px;
}

code, kbd, samp {
  font-size: 0.9em;
  padding: 0.2em 0.4em;
  background-color: var(--primary-background);
  border-radius: 3px;
}

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

.table, table {
  width: 100%;
  border-collapse: collapse;
  margin-bottom: 2rem;
}

th, td {
  padding: 0.75rem;
  border-bottom: 1px solid var(--secondary-background);
  text-align: left;
}

/* lists */
ul, ol {
  padding-left: 2rem;
  margin-bottom: 2rem;
}

li {
  margin-bottom: 0.5em;
}

dl {
  margin-bottom: 2.5rem;
  border-left: 4px solid var(--primary-color);
  padding-left: 1rem;
  background-color: var(--secondary-background);
  border-radius: 0.5rem;
}

dt {
  font-weight: 700;
  margin-top: 1.5rem;
  color: var(--primary-color);
}

dd {
  margin: 0 0 1.5rem 1rem;
  color: var(--text-color);
}

/* Forms */
input, textarea, select, button {
  font: inherit;
  color: var(--text-color);
  background-color: var(--secondary-background);
  border: 1px solid var(--primary-color);
  padding: 0.6rem 1rem;
  box-sizing: border-box;
  margin: 2.5px;
  border-radius: 4px;
}

input[type="text"],
input[type="email"],
input[type="password"],
input[type="search"],
input[type="url"],
input[type="tel"],
input[type="number"],
textarea,
select {
  width: 100%;
  box-sizing: border-box;
}

/* Exclude checkboxes and radios from full width */
input[type="checkbox"],
input[type="radio"] {
  width: auto;
  margin: 2.5px;
  margin-right: 0.5rem; /* optional spacing */
  vertical-align: middle;
}

input:focus, textarea:focus, select:focus, button:focus {
  outline: 2px solid var(--primary-color);
}

button, input[type="submit"], input[type="reset"], input[type="button"] {
  background-color: var(--primary-color);
  color: var(--primary-background);
  cursor: pointer;
  border: none;
  transition: background-color 0.2s;
  border-radius: 4px;
}

button:hover, input[type="submit"]:hover, input[type="reset"]:hover, input[type="button"]:hover {
  background-color: var(--secondary-color);
}

button:disabled,
input[type="submit"]:disabled,
input[type="reset"]:disabled,
input[type="button"]:disabled {
  background-color: var(--primary-color);
  color: var(--primary-background);
  opacity: 0.6;
  cursor: not-allowed;
  border-color: var(--primary-color);
  pointer-events: none;
}

fieldset {
  margin-bottom: 2rem;
  padding: 1rem;
  border: 1px solid var(--primary-color);
}

legend {
  font-weight: bold;
  padding: 0 0.5rem;
}

label {
  display: block;
  margin-bottom: 0.5rem;
  font-weight: 500;
}

label + input,
label + textarea,
label + select {
  margin-top: 0.25rem;
  margin-bottom: 1rem;
  display: block;
}

/* Form validation feedback */
input:valid,
textarea:valid,
select:valid {
  border-color: var(--primary-color);
}

input:invalid,
textarea:invalid,
select:invalid {
  border-color: #d54e53; /* warm red */
}

input:focus:invalid,
textarea:focus:invalid,
select:focus:invalid {
  outline: 2px solid #d54e53;
}

input:focus:valid,
textarea:focus:valid,
select:focus:valid {
  outline: 2px solid var(--primary-color);
}

/* Sticky header */
header {
  position: sticky;
  top: 0;
  background: var(--secondary-background);
  padding: 1rem 2rem;
  border-bottom: 1px solid var(--primary-color);
  z-index: 100;
  text-align: center;
  border-radius: 0 0 4px 4px;
}

/* Sticky footer */
footer {
  position: sticky;
  bottom: 0;
  background: var(--secondary-background);
  padding: 1rem 2rem;
  border-top: 1px solid var(--primary-color);
  z-index: 100;
  text-align: center;
  border-radius: 4px 4px 0 0;
}

/* Semantic Structural Elements */
section,
article,
aside,
main {
  scroll-margin-top: 14rem; /* So the section isn't flush with top */
  display: block;
  margin: 2rem 0;
  padding: 1rem 0;
  border-top: 1px solid var(--secondary-background);
  border-bottom: 1px solid var(--secondary-background);
}

/* Make main stand out slightly */
main {
  width: 100%;
  max-width: 38em;
  margin-left: auto;
  margin-right: auto;
  padding: 2rem 1rem;
  background-color: var(--secondary-background);
  border-radius: 0.5rem;
  box-shadow: 0 2px 4px rgba(0,0,0,0.05);
  flex-grow: 1;
  overflow-y: auto;
}

/* Article gets some extra padding */
article {
  padding: 1rem;
  border-radius: 0.4rem;
}

/* Aside is a lighter card */
aside {
  background: var(--secondary-background);
  padding: 1rem;
  border-left: 4px solid var(--primary-color);
  margin: 1rem 0;
  font-style: italic;
  color: var(--secondary-color);
}

/* Figure & figcaption */
figure {
  margin: 2rem 0;
  text-align: center;
}

figcaption {
  font-size: 0.9rem;
  color: var(--secondary-color);
  margin-top: 0.5rem;
}

/* Details & summary for collapsible content */
details {
  background: var(--secondary-background);
  padding: 1rem;
  border-radius: 0.5rem;
  margin-bottom: 2rem;
  border: 1px solid var(--secondary-background);
  cursor: pointer;
}

summary {
  font-weight: 600;
  cursor: pointer;
  outline: none;
  padding: 0.25rem 0.5rem;
  border-radius: 0.25rem;
  user-select: none;
}

summary::-webkit-details-marker {
  display: none;
}

details[open] summary {
  color: var(--primary-color);
}

summary:focus {
  outline: 2px solid var(--primary-color);
}

/* Mark: highlighted text */
mark {
  background-color: var(--primary-color);
  color: var(--primary-background);
  padding: 0.1em 0.3em;
  border-radius: 2px;
}

/* Time element */
time {
  font-style: italic;
  color: var(--secondary-color);
}

/* Progress bar */
progress {
  display: block;
  width: 100%;
  height: 1rem;
  appearance: none;
  -webkit-appearance: none;
  margin: 1rem 0;
  border-radius: 0.25rem;
  overflow: hidden;
  background-color: var(--secondary-background);
  border: 1px solid var(--secondary-background);
}

progress::-webkit-progress-bar {
  background-color: var(--secondary-background);
}

progress::-webkit-progress-value {
  background-color: var(--primary-color);
  border-radius: 0.25rem;
}

progress::-moz-progress-bar {
  background-color: var(--primary-color);
  border-radius: 0.25rem;
}

/* Meter */
meter {
  display: inline-block;
  width: 100px;
  height: 1rem;
  background: var(--secondary-background);
  border: 1px solid var(--secondary-background);
  border-radius: 0.25rem;
  overflow: hidden;
  vertical-align: middle;
}

meter::-webkit-meter-bar {
  background: var(--secondary-background);
}

meter::-webkit-meter-optimum-value {
  background: var(--primary-color);
  border-radius: 0.25rem;
}

meter::-webkit-meter-suboptimum-value {
  background: #e2b007;
  border-radius: 0.25rem;
}

meter::-webkit-meter-even-less-good-value {
  background: #d54e53;
  border-radius: 0.25rem;
}

/* Nav Bar */
nav {
  display: flex;
  justify-content: space-between;
  align-items: center;
  background: var(--secondary-background);
  padding: 1rem 2rem;
  /*border-bottom: 1px solid var(--primary-color);*/
  font-weight: bold;
}

nav a {
  color: var(--text-color);
  margin-left: 1.5rem;
  text-decoration: none;
}

nav a:hover {
  color: var(--primary-color);
  border-bottom: 2px solid var(--primary-color);
}

/* Modal/Dialog */
dialog {
  position: fixed;
  transform: translate(0%, 0%);
  background: var(--primary-background);
  padding: 2rem;
  border: none;
  border-radius: 8px;
  max-width: 90%;
  width: 90%;
  margin: auto;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
  color: var(--text-color);
  z-index: 1000;
}

dialog::backdrop {
  background: rgba(62, 46, 30, 0.5);
}

dialog button.close {
  float: right;
  font-size: 1.5rem;
  cursor: pointer;
  background: transparent;
  border: none;
  color: var(--text-color);
}

/* Responsive media containers */
iframe,
video,
embed,
object {
  max-width: 100%;
  height: auto;
  border-radius: 0.5rem;
  box-shadow: 0 2px 5px rgba(0,0,0,0.1);
  margin-bottom: 2.5rem;
  display: block;
}

/* Responsive video and iframe wrapper */
.media-wrapper {
  position: relative;
  padding-bottom: 56.25%; /* 16:9 aspect ratio */
  height: 0;
  overflow: hidden;
  max-width: 100%;
  margin-bottom: 2.5rem;
}

.media-wrapper iframe,
.media-wrapper video,
.media-wrapper embed,
.media-wrapper object {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  border-radius: 0.5rem;
  box-shadow: 0 2px 5px rgba(0,0,0,0.1);
}

:focus:not(:focus-visible) {
  outline: none;
}

/* Utility */
.card {
  background: var(--secondary-background);
  padding: 1.5rem;
  border-radius: 0.5rem;
  box-shadow: 0 2px 5px rgba(0, 0, 0, 0.05);
  margin-bottom: 2rem;
}

.alert {
  padding: 1rem 1.5rem;
  margin-bottom: 2rem;
  border-radius: 4px;
  border-left: 6px solid var(--primary-color);
  background-color: var(--secondary-background);
  color: var(--text-color);
}

.alert-info {
  border-color: #5d8c85;
  background-color: var(--secondary-background);
}

.alert-warning {
  border-color: #b8860b;
  background-color: var(--secondary-background);
}

.alert-error {
  border-color: #b22222;
  background-color: var(--secondary-background);
}

.text-center { text-align: center; }
.flex-center { display: flex; justify-content: center; align-items: center; }

.mx-1 { margin: 0 1rem; }
.my-1 { margin: 1rem 0; }
.mx-2 { margin: 0 2rem; }
.my-2 { margin: 2rem 0; }
.mx-3 { margin: 0 3rem; }
.my-3 { margin: 3rem 0; }
.mx-4 { margin: 0 4rem; }
.my-4 { margin: 4rem 0; }
.mx-5 { margin: 0 5rem; }
.my-5 { margin: 5rem 0; }
.mx-5 { margin: 0 6rem; }
.my-5 { margin: 6rem 0; }

.px-1 { padding: 0 1rem; }
.py-1 { padding: 1rem 0; }
.px-2 { padding: 0 2rem; }
.py-2 { padding: 2rem 0; }
.px-3 { padding: 0 3rem; }
.py-3 { padding: 3rem 0; }
.px-4 { padding: 0 4rem; }
.py-4 { padding: 4rem 0; }
.px-5 { padding: 0 5rem; }
.py-5 { padding: 5rem 0; }
.px-6 { padding: 0 6rem; }
.py-6 { padding: 6rem 0; }

/* dark mode */
@media (prefers-color-scheme: dark) {
  :root {
    --primary-background: #2b2a27;
    --secondary-background: #484540;
    --text-color: #e2d9c8;
    --primary-color: #c3a36e;
    --secondary-color: #a6865b;
    --link-hover-border: #d4b97a;
    --link-visited: #9e7d50;
  }
  
  body {
    background: linear-gradient(0deg, rgba(100, 100, 100, 0.8), rgba(100, 100, 100, 0.8)), url(https://cdn.jsdelivr.net/npm/kartoncss/karton-element.svg);
    background-size: 150px;
    background-repeat: repeat;
  }
}

.dark {
  --primary-background: #2b2a27;
  --secondary-background: #484540;
  --text-color: #e2d9c8;
  --primary-color: #c3a36e;
  --secondary-color: #a6865b;
  --link-hover-border: #d4b97a;
  --link-visited: #9e7d50;
}

body.dark {
  background: linear-gradient(0deg, rgba(100, 100, 100, 0.8), rgba(100, 100, 100, 0.8)), url(https://cdn.jsdelivr.net/npm/kartoncss/karton-element.svg);
  background-size: 150px;
  background-repeat: repeat;
}
