/**
 * UNIVERSAL.CSS
 * Pure semantic HTML styling
 * 
 * Spacing principle: margin-bottom only, no collisions
 * Colors from clrs.cc
 */

/* ==========================================================================
   VARIABLES
   ========================================================================== */

:root {
  /* CLRS.cc Palette */
  --navy:    #001f3f;
  --blue:    #0074D9;
  --aqua:    #7FDBFF;
  --teal:    #39CCCC;
  --olive:   #3D9970;
  --green:   #2ECC40;
  --lime:    #01FF70;
  --yellow:  #FFDC00;
  --orange:  #FF851B;
  --red:     #FF4136;
  --maroon:  #85144b;
  --fuchsia: #F012BE;
  --purple:  #B10DC9;
  --black:   #111111;
  --gray:    #AAAAAA;
  --silver:  #DDDDDD;
  --white:   #FFFFFF;
  
  /* Semantic colors */
  --color-text: var(--black);
  --color-text-muted: var(--gray);
  --color-bg: var(--white);
  --color-bg-subtle: #f8f8f8;
  --color-accent: var(--blue);
  --color-accent-hover: var(--navy);
  --color-focus: rgba(0, 116, 217, 0.5);
  --color-selection: rgba(0, 116, 217, 0.3);
  
  /* Spacing - eine Einheit für alles */
  --space: 1.5rem;
  --space-s: 0.75rem;
  --space-l: 3.5rem;
  
  /* Typography */
  --text-sm: 0.875rem;
  --text-base: 1.0625rem;
  --text-lg: 1.25rem;
  --text-xl: 1.5rem;
  --text-2xl: 1.875rem;
  --text-3xl: 2.25rem;
  
  --leading-tight: 1.3;
  --leading-normal: 1.6;
  
  --measure: 700px;
  
  --font-body: system-ui, -apple-system, sans-serif;
  --font-mono: ui-monospace, monospace;
  
  /* Forms */
  --border-radius: 6px;
  --select-arrow: url("data:image/svg+xml;charset=utf-8,%3Csvg xmlns='http://www.w3.org/2000/svg' height='63' width='117' fill='%23111111'%3E%3Cpath d='M115 2c-1-2-4-2-5 0L59 53 7 2a4 4 0 00-5 5l54 54 2 2 3-2 54-54c2-1 2-4 0-5z'/%3E%3C/svg%3E");
}

/* Dark mode */
@media (prefers-color-scheme: dark) {
  :root {
    --color-text: var(--silver);
    --color-text-muted: var(--gray);
    --color-bg: #1a1a1a;
    --color-bg-subtle: #242424;
    --color-accent: var(--aqua);
    --color-accent-hover: var(--teal);
    --color-focus: rgba(127, 219, 255, 0.5);
    --color-selection: rgba(127, 219, 255, 0.3);
    --select-arrow: url("data:image/svg+xml;charset=utf-8,%3Csvg xmlns='http://www.w3.org/2000/svg' height='63' width='117' fill='%23DDDDDD'%3E%3Cpath d='M115 2c-1-2-4-2-5 0L59 53 7 2a4 4 0 00-5 5l54 54 2 2 3-2 54-54c2-1 2-4 0-5z'/%3E%3C/svg%3E");
  }
}

/* ==========================================================================
   RESET
   ========================================================================== */

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

/* ==========================================================================
   SELECTION & SCROLLBAR
   ========================================================================== */

::selection {
  background-color: var(--color-selection);
  color: var(--color-text);
}

::-moz-selection {
  background-color: var(--color-selection);
  color: var(--color-text);
}

html {
  scrollbar-color: var(--gray) var(--color-bg);
  scrollbar-width: thin;
}

::-webkit-scrollbar {
  height: 10px;
  width: 10px;
}

::-webkit-scrollbar-track {
  background: var(--color-bg-subtle);
  border-radius: var(--border-radius);
}

::-webkit-scrollbar-thumb {
  background: var(--gray);
  border-radius: var(--border-radius);
}

::-webkit-scrollbar-thumb:hover {
  background: var(--color-text-muted);
}

/* ==========================================================================
   DOCUMENT
   ========================================================================== */

html {
  font-size: 100%;
  scroll-behavior: smooth;
}

body {
  font-family: var(--font-body);
  font-size: var(--text-base);
  line-height: var(--leading-normal);
  color: var(--color-text);
  background-color: var(--color-bg);
  max-width: var(--measure);
  margin-inline: auto;
  padding: var(--space-l) var(--space);
  -webkit-font-smoothing: antialiased;
}

/* ==========================================================================
   UNIVERSAL SPACING
   Alles nur margin-bottom, keine Additionen
   ========================================================================== */

h1, h2, h3, h4, h5, h6,
p, ul, ol, dl, figure, blockquote, pre, table, hr,
article, section, time, address {
  margin-block: 0 var(--space);
}

/* Letztes Kind: kein Abstand unten */
:last-child {
  margin-block-end: 0;
}

/* Größere Abstände für Strukturelemente */
header, main, footer {
  margin-block: 0 var(--space-l);
}

header:last-child, 
main:last-child, 
footer:last-child {
  margin-block-end: 0;
}

/* ==========================================================================
   STRUCTURE
   ========================================================================== */

header:has(nav),
header:has(ul) {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  align-items: center;
  gap: var(--space);
}

nav {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space);
  margin-block: 0;
}

nav a {
  color: var(--color-text);
  text-decoration: none;
  font-size: var(--text-sm);
  font-weight: 500;
}

nav a:hover {
  color: var(--color-accent);
}

/* Nav im Content-Bereich: Abstand */
main nav {
  margin-block: var(--space) 0;
}

footer {
  color: var(--color-text-muted);
  font-size: var(--text-sm);
}

footer:has(nav),
footer:has(ul) {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  align-items: center;
  gap: var(--space);
}

aside {
  font-size: var(--text-sm);
  color: var(--color-text-muted);
}

/* ==========================================================================
   HEADINGS
   ========================================================================== */

h1, h2, h3, h4, h5, h6 {
  font-weight: 600;
  line-height: var(--leading-tight);
  text-wrap: balance;
}

h1 {
  font-size: var(--text-3xl);
  font-weight: 700;
  letter-spacing: -0.02em;
}

h2 {
  font-size: var(--text-2xl);
  letter-spacing: -0.01em;
}

h3 {
  font-size: var(--text-xl);
}

h4 {
  font-size: var(--text-lg);
}

h5 {
  font-size: var(--text-base);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

h6 {
  font-size: var(--text-base);
  color: var(--color-text-muted);
}

/* ==========================================================================
   TEXT
   ========================================================================== */

strong, b {
  font-weight: 600;
}

small {
  font-size: var(--text-sm);
}

/* Badge-Style für sup (z.B. "NEU", "PRO") */
sup {
  background-color: var(--color-accent);
  border-radius: var(--border-radius);
  color: var(--white);
  font-size: xx-small;
  font-weight: bold;
  padding: 0.2rem 0.4rem;
  margin-left: 0.2rem;
  vertical-align: top;
}

time {
  font-size: var(--text-sm);
  color: var(--color-text-muted);
}

mark {
  background-color: var(--yellow);
  padding-inline: 0.15em;
}

abbr[title] {
  text-decoration: underline dotted;
  cursor: help;
}

/* ==========================================================================
   LINKS
   ========================================================================== */

a {
  color: var(--color-accent);
  text-decoration: underline;
  text-underline-offset: 0.2em;
}

a:hover {
  color: var(--color-accent-hover);
}

a:focus-visible {
  outline: 2px solid var(--color-accent);
  outline-offset: 2px;
}

/* ==========================================================================
   LISTS
   ========================================================================== */

ul, ol {
  padding-inline-start: var(--space);
}

li {
  margin-block-end: var(--space-s);
}

li:last-child {
  margin-block-end: 0;
}

li > ul, li > ol {
  margin-block-start: var(--space-s);
}

ul ul { list-style-type: circle; }
ul ul ul { list-style-type: square; }
ol ol { list-style-type: lower-alpha; }

/* Structure lists: no bullets */
nav ul, nav ol,
header ul, header ol,
footer ul, footer ol {
  list-style: none;
  padding-inline-start: 0;
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-s) var(--space);
  margin-block: 0;
}

nav li, header li, footer li {
  margin-block-end: 0;
}

/* Link-only lists */
ul:has(> li > a:only-child),
ol:has(> li > a:only-child) {
  list-style: none;
  padding-inline-start: 0;
}

article ul:has(> li > a:only-child) {
  list-style-type: disc;
  padding-inline-start: var(--space);
}

/* Definition lists */
dl {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: var(--space-s) var(--space);
}

dt {
  font-weight: 600;
}

dd {
  margin: 0;
}

/* ==========================================================================
   QUOTES
   ========================================================================== */

blockquote {
  padding-inline-start: var(--space);
  color: var(--color-text-muted);
  font-style: italic;
}

blockquote cite {
  display: block;
  font-size: var(--text-sm);
  font-style: normal;
  margin-block-start: var(--space-s);
}

blockquote cite::before {
  content: "— ";
}

q::before { content: "„"; }
q::after { content: """; }

/* ==========================================================================
   CODE
   ========================================================================== */

code, kbd, samp {
  font-family: var(--font-mono);
  font-size: 0.9em;
  background-color: var(--color-bg-subtle);
  padding: 0.15em 0.4em;
  border-radius: 3px;
}

pre {
  font-family: var(--font-mono);
  font-size: var(--text-sm);
  line-height: 1.6;
  background-color: var(--color-bg-subtle);
  padding: var(--space);
  overflow-x: auto;
  border-radius: 4px;
}

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

/* ==========================================================================
   MEDIA
   ========================================================================== */

img, video {
  display: block;
  max-width: 100%;
  height: auto;
  border-radius: var(--border-radius);
}

figure {
  margin-inline: 0;
  margin-block: 0 var(--space);
}

figcaption {
  font-size: var(--text-sm);
  color: var(--color-text-muted);
  margin-block-start: var(--space-s);
}

/* ==========================================================================
   TABLES
   ========================================================================== */

table {
  width: 100%;
  border-collapse: collapse;
  font-size: var(--text-sm);
  margin-block: 0 var(--space);
  table-layout: fixed;
}

caption {
  font-size: var(--text-sm);
  color: var(--color-text-muted);
  text-align: left;
  margin-block-end: var(--space-s);
}

th, td {
  text-align: left;
  padding: 6px;
  vertical-align: top;
  word-wrap: break-word;
}

th {
  font-weight: 600;
}

thead {
  border-bottom: 1px solid var(--gray);
}

tfoot {
  border-top: 1px solid var(--gray);
}

tbody tr:nth-child(even) {
  background-color: var(--color-bg-subtle);
}

/* ==========================================================================
   FORMS
   ========================================================================== */

input, textarea, select, button {
  font: inherit;
  color: var(--color-text);
  border-radius: var(--border-radius);
  outline: none;
  transition: background-color 0.1s linear, box-shadow 0.1s linear;
}

input:not([type="checkbox"]):not([type="radio"]):not([type="range"]):not([type="color"]):not([type="submit"]):not([type="button"]):not([type="reset"]),
textarea,
select {
  display: block;
  width: 100%;
  padding: 8px 10px;
  margin-bottom: 6px;
  border: 1px solid var(--silver);
  border-radius: var(--border-radius);
  background-color: var(--color-bg);
  color: var(--color-text);
}

textarea {
  min-height: 150px;
  resize: vertical;
}

/* Focus states */
input:focus, textarea:focus, select:focus, button:focus {
  box-shadow: 0 0 0 2px var(--color-focus);
}

/* Placeholder */
::placeholder {
  color: var(--color-text-muted);
}

/* Select */
select {
  background: var(--color-bg) var(--select-arrow) calc(100% - 12px) 50% / 12px no-repeat;
  padding-right: 40px;
  cursor: pointer;
  -webkit-appearance: none;
  -moz-appearance: none;
  appearance: none;
}

select::-ms-expand {
  display: none;
}

select[multiple] {
  padding-right: var(--space);
  background-image: none;
  overflow-y: auto;
}

/* Buttons - minimal, nur Verbesserungen */
button, input[type="submit"], input[type="reset"], input[type="button"] {
  font: inherit;
  cursor: pointer;
  border-radius: var(--border-radius);
}

button:disabled, input:disabled, select:disabled, textarea:disabled {
  cursor: not-allowed;
  opacity: 0.5;
}

/* Checkbox & Radio */
input[type="checkbox"], input[type="radio"] {
  display: inline-block;
  width: 1.2em;
  height: 1.2em;
  vertical-align: middle;
  cursor: pointer;
  margin-right: var(--space-s);
}

input[type="radio"] {
  border-radius: 50%;
}

input[type="checkbox"]:checked, input[type="radio"]:checked {
  background-color: var(--color-accent);
}

/* Color input */
input[type="color"] {
  min-height: 2.5rem;
  padding: var(--space-s);
  cursor: pointer;
}

/* Range input */
input[type="range"] {
  -webkit-appearance: none;
  appearance: none;
  width: 100%;
  height: auto;
  padding: var(--space-s) 0;
  background: transparent;
}

input[type="range"]:focus {
  box-shadow: none;
}

input[type="range"]::-webkit-slider-runnable-track {
  width: 100%;
  height: 8px;
  background: var(--color-bg-subtle);
  border-radius: var(--border-radius);
}

input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  height: 20px;
  width: 20px;
  border-radius: 50%;
  background: var(--color-accent);
  margin-top: -6px;
  cursor: pointer;
}

input[type="range"]::-moz-range-track {
  width: 100%;
  height: 8px;
  background: var(--color-bg-subtle);
  border-radius: var(--border-radius);
}

input[type="range"]::-moz-range-thumb {
  height: 20px;
  width: 20px;
  border-radius: 50%;
  background: var(--color-accent);
  border: none;
  cursor: pointer;
}

/* Label */
label {
  display: inline-block;
  margin-block-end: var(--space-s);
  cursor: pointer;
}

/* Fieldset & Legend */
fieldset {
  border: 1px solid var(--color-bg-subtle);
  border-radius: var(--border-radius);
  padding: var(--space);
  margin-block: 0 var(--space);
}

legend {
  font-weight: 600;
  padding: 0 var(--space-s);
}

/* ==========================================================================
   DETAILS & SUMMARY
   ========================================================================== */

details {
  display: flex;
  flex-direction: column;
  background-color: var(--color-bg-subtle);
  padding: 0;
  margin-block: 0 var(--space);
  border-radius: var(--border-radius);
  overflow: hidden;
}

details[open] {
  padding: var(--space);
  padding-top: 0;
}

summary {
  display: list-item;
  background-color: var(--color-bg-subtle);
  padding: var(--space);
  cursor: pointer;
  font-weight: 600;
}

summary:hover {
  background-color: var(--silver);
}

summary:focus {
  box-shadow: 0 0 0 2px var(--color-focus);
  outline: none;
}

details[open] summary {
  margin-bottom: var(--space);
}

details > *:not(summary) {
  margin-block: 0 var(--space);
}

details > *:last-child {
  margin-block-end: 0;
}

/* ==========================================================================
   DIALOG
   ========================================================================== */

dialog {
  background-color: var(--color-bg);
  color: var(--color-text);
  border: none;
  border-radius: var(--border-radius);
  padding: var(--space-l);
  max-width: min(90vw, 500px);
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.15);
  animation: dialog-in 0.2s ease-out;
}

@keyframes dialog-in {
  from {
    opacity: 0;
    transform: translateY(10px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

dialog::backdrop {
  background: rgba(0, 0, 0, 0.5);
  backdrop-filter: blur(4px);
}

dialog > header:first-child {
  margin: calc(var(--space-l) * -1);
  margin-bottom: var(--space);
  padding: var(--space);
  background-color: var(--color-bg-subtle);
  text-align: center;
  font-weight: 600;
}

/* ==========================================================================
   SEPARATORS
   ========================================================================== */

hr {
  border: none;
  border-top: 1px solid var(--silver);
  margin-block: var(--space);
}

/* ==========================================================================
   ACCESSIBILITY
   ========================================================================== */

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    transition-duration: 0.01ms !important;
  }
  html {
    scroll-behavior: auto;
  }
}

.skip-link {
  position: absolute;
  top: -100%;
  left: var(--space);
  padding: var(--space-s) var(--space);
  background: var(--color-text);
  color: var(--color-bg);
  z-index: 9999;
}

.skip-link:focus {
  top: var(--space);
}

/* ==========================================================================
   RESPONSIVE
   ========================================================================== */

@media (max-width: 600px) {
  :root {
    --text-base: 1rem;
    --text-3xl: 1.75rem;
    --text-2xl: 1.5rem;
    --text-xl: 1.25rem;
    --space: 1.25rem;
    --space-l: 2rem;
  }
  
  body {
    padding: var(--space-l) var(--space);
  }
}

/* ==========================================================================
   PRINT
   ========================================================================== */

@media print {
  body {
    font-size: 11pt;
    max-width: none;
    padding: 0;
    color: #000;
    background: #fff;
  }
  
  body, button, code, details, input, pre, summary, textarea {
    background-color: #fff;
  }
  
  button, input, textarea {
    border: 1px solid #000;
  }
  
  h1, h2, h3, h4, h5, h6, strong {
    color: #000;
  }
  
  a {
    color: #000;
    text-decoration: underline;
  }
  
  a[href^="http"]::after {
    content: " (" attr(href) ")";
    font-size: 0.8em;
  }
  
  nav, footer, dialog {
    display: none;
  }
  
  details {
    border: 1px solid #000;
  }
  
  summary {
    background-color: #f2f2f2;
  }
}
