:root {
  --paper: #ece3cf;
  --paper-2: #f6efdd;
  --surface: #fbf6ea;
  --ink: #1a160f;
  --ink-soft: #736a55;
  --rule: #cabf9f;
  --red: #cf3a22;
  --red-deep: #a3290f;
  --accent-soft: #f3ddd2;
  --tile: #f7f0df;
  --tile-edge: #cdbf9a;
  --tile-shadow: #b7a877;
  --radius: 10px;
  --space: 1rem;
  --shadow: 0 1px 0 #fff8, 0 10px 30px -18px #4a3c1a99;
  --disp: "Fraunces", Georgia, "Times New Roman", serif;
  --mono: "Space Mono", ui-monospace, "Cascadia Mono", "Consolas", monospace;

  /* page backdrop (overridable per theme) */
  --bg-glow: #f4ecd8;
  --bg-edge: #e4d9bf;
  --grain-opacity: 0.5;

  /* reading font for words, inputs and toolbar (overridable per font choice) */
  --word-font: var(--mono);
}

/* ---- font choices (highly legible, crisp letterforms) ------------------ */
:root[data-font="mono"]      { --word-font: "Space Mono", ui-monospace, "Cascadia Mono", "Consolas", monospace; }
:root[data-font="lucida"]    { --word-font: "Lucida Console", "Lucida Sans Typewriter", "DejaVu Sans Mono", monospace; }
:root[data-font="consolas"]  { --word-font: "Consolas", "Cascadia Mono", "SFMono-Regular", Menlo, monospace; }
:root[data-font="jetbrains"] { --word-font: "JetBrains Mono", ui-monospace, "Consolas", monospace; }
:root[data-font="atkinson"]  { --word-font: "Atkinson Hyperlegible", system-ui, "Segoe UI", sans-serif; }

/* ---- color themes (high contrast, easy on the eye) --------------------- */
/* "Klassisch" — the original white / black / red look */
:root[data-theme="klassisch"] {
  --paper: #ffffff;
  --paper-2: #f3f3f3;
  --surface: #ffffff;
  --ink: #111111;
  --ink-soft: #565656;
  --rule: #d2d2d2;
  --red: #d11a0e;
  --red-deep: #a50f06;
  --accent-soft: #fbdcd7;
  --tile: #ffffff;
  --tile-edge: #cccccc;
  --tile-shadow: #b3b3b3;
  --bg-glow: #ffffff;
  --bg-edge: #efefef;
  --grain-opacity: 0.22;
  --shadow: 0 1px 0 #fff, 0 10px 30px -18px rgba(0, 0, 0, 0.35);
}

/* "Nacht" — dark, restful, warm amber accent */
:root[data-theme="nacht"] {
  --paper: #14161b;
  --paper-2: #1b1f27;
  --surface: #1f242d;
  --ink: #f1ede2;
  --ink-soft: #a3a092;
  --rule: #353b47;
  --red: #ffb05c;
  --red-deep: #ffc885;
  --accent-soft: #3a2c19;
  --tile: #232932;
  --tile-edge: #3a414e;
  --tile-shadow: #0b0d11;
  --bg-glow: #1c212a;
  --bg-edge: #0d0f13;
  --grain-opacity: 0.35;
  --shadow: 0 1px 0 rgba(255, 255, 255, 0.04), 0 14px 36px -20px rgba(0, 0, 0, 0.8);
}

/* "Tinte" — cool ink on cool paper */
:root[data-theme="tinte"] {
  --paper: #e9eef5;
  --paper-2: #f6f9fd;
  --surface: #ffffff;
  --ink: #0f1f33;
  --ink-soft: #566779;
  --rule: #c1cedd;
  --red: #1f6feb;
  --red-deep: #1551b5;
  --accent-soft: #d4e3fb;
  --tile: #ffffff;
  --tile-edge: #c1cedd;
  --tile-shadow: #9fb2c9;
  --bg-glow: #f4f8fc;
  --bg-edge: #dbe5f0;
  --grain-opacity: 0.3;
  --shadow: 0 1px 0 #fff, 0 12px 30px -18px rgba(20, 50, 90, 0.4);
}

* { box-sizing: border-box; }

body {
  margin: 0;
  padding: 0 clamp(0.8rem, 2vw, 2.5rem) 4rem;
  background:
    radial-gradient(120% 80% at 50% -10%, var(--bg-glow) 0%, var(--paper) 55%, var(--bg-edge) 100%) fixed,
    var(--paper);
  color: var(--ink);
  font-family: var(--word-font);
  font-size: 15px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  transition: background-color 200ms ease, color 200ms ease;
}

/* faint paper grain */
body::before {
  content: "";
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 0;
  opacity: var(--grain-opacity);
  background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='120' height='120'><filter id='n'><feTurbulence type='fractalNoise' baseFrequency='.9' numOctaves='2'/><feColorMatrix type='saturate' values='0'/></filter><rect width='100%25' height='100%25' filter='url(%23n)' opacity='.05'/></svg>");
}

main {
  position: relative;
  z-index: 1;
  max-width: min(100%, 110rem);
  margin-inline: auto;
}

/* ---- masthead ---------------------------------------------------------- */
.masthead {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: var(--space);
  flex-wrap: wrap;
  border-bottom: 2px solid var(--ink);
  padding: 1.6rem 0 0.6rem;
  margin-bottom: 1.4rem;
}

.masthead__title {
  display: grid;
  gap: 0.2rem;
}

.masthead h1 {
  margin: 0;
  font-family: var(--disp);
  font-weight: 900;
  font-size: clamp(2rem, 1rem + 4vw, 3.2rem);
  letter-spacing: -0.02em;
  line-height: 0.9;
}

.stand {
  margin: 0;
  color: var(--ink-soft);
  font-size: 0.82rem;
}

/* ---- settings (font + theme pickers) ----------------------------------- */
.settings {
  display: flex;
  gap: 0.9rem;
  flex-wrap: wrap;
  align-items: flex-end;
}

.control {
  display: grid;
  gap: 0.35rem;
}

.control__label {
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.16em;
  color: var(--ink-soft);
}

.select {
  position: relative;
  display: inline-flex;
}

.select select {
  appearance: none;
  -webkit-appearance: none;
  font-family: var(--word-font);
  font-size: 0.85rem;
  font-weight: 700;
  color: var(--ink);
  background: var(--surface);
  border: 1.5px solid var(--ink);
  border-radius: 999px;
  padding: 0.42rem 2.2rem 0.42rem 0.95rem;
  cursor: pointer;
  transition: border-color 150ms ease, box-shadow 150ms ease;
}

.select select:hover { border-color: var(--red); }

.select select:focus-visible {
  outline: none;
  border-color: var(--red);
  box-shadow: 0 0 0 3px var(--accent-soft);
}

/* keep the native dropdown list readable in every theme */
.select select option {
  background: var(--surface);
  color: var(--ink);
}

/* custom chevron */
.select::after {
  content: "";
  position: absolute;
  right: 1rem;
  top: 50%;
  width: 0.5rem;
  height: 0.5rem;
  pointer-events: none;
  border-right: 2px solid var(--ink);
  border-bottom: 2px solid var(--ink);
  transform: translateY(-65%) rotate(45deg);
}

/* ---- inputs ------------------------------------------------------------ */
#search {
  display: grid;
  gap: var(--space);
}

.field {
  display: grid;
  gap: 0.35rem;
}

.field__label {
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.16em;
  color: var(--ink-soft);
}

.field input {
  width: 100%;
  padding: 0.7rem 0.85rem;
  font: inherit;
  font-size: 1.1rem;
  color: var(--ink);
  background: var(--surface);
  border: 1px solid var(--rule);
  border-radius: var(--radius);
  transition: border-color 150ms ease, box-shadow 150ms ease;
}

.field input::placeholder { color: var(--ink-soft); opacity: 0.75; }

.field input:focus {
  outline: none;
  border-color: var(--red);
  box-shadow: 0 0 0 3px var(--accent-soft);
}

#bank { letter-spacing: 0.18em; text-transform: uppercase; }

.status {
  min-height: 1.25rem;
  margin: 1rem 0 0;
  color: var(--red);
  font-size: 0.9rem;
}

/* ---- toolbar (sort + summary) ------------------------------------------ */
.toolbar {
  display: flex;
  align-items: center;
  gap: 1rem;
  flex-wrap: wrap;
  padding: 0.6rem 0 1.3rem;
}

.toolbar[hidden] { display: none; }

.toolbar__label {
  font-size: 0.72rem;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: var(--ink-soft);
}

.seg[hidden] { display: none; }

.seg {
  display: inline-flex;
  border: 1.5px solid var(--ink);
  border-radius: 999px;
  overflow: hidden;
  background: var(--surface);
}

.seg button {
  font-family: var(--word-font);
  font-size: 0.82rem;
  font-weight: 700;
  border: 0;
  background: transparent;
  color: var(--ink);
  padding: 0.42rem 0.95rem;
  cursor: pointer;
}

.seg button[aria-pressed="true"] { background: var(--ink); color: var(--paper-2); }

.summary { margin-left: auto; color: var(--ink-soft); font-size: 0.82rem; }
.summary b { color: var(--ink); }

/* ---- result columns (one per length, longest first) -------------------- */
.cols {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-start;
  gap: 1rem;
  align-items: flex-start;
  padding-bottom: 0.5rem;
}

.col {
  flex: 0 0 auto;
  display: flex;
  flex-direction: column;
  background: var(--surface);
  border: 1px solid var(--rule);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

.col__head {
  position: sticky;
  top: 0;
  display: flex;
  align-items: baseline;
  justify-content: center;
  padding: 0.55rem 0.8rem;
  background: var(--paper-2);
  border-bottom: 1px solid var(--rule);
}

.col__len {
  font-family: var(--disp);
  font-weight: 900;
  font-size: 1.5rem;
  line-height: 1;
}

.col__body {
  padding: 0.35rem 0.35rem 0.6rem;
}

.row {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 0.5rem;
  padding: 0.12rem 0.5rem;
  border-radius: 5px;
}

.row:hover { background: var(--paper); }

.word { font-size: 1.05rem; letter-spacing: 0.12em; }

.sc {
  font-size: 0.72rem;
  color: var(--ink-soft);
  font-variant-numeric: tabular-nums;
  min-width: 1.6rem;
  text-align: right;
}

/* Blanko-filled letters: loud and underlined */
.blank {
  color: var(--red);
  font-weight: 700;
  text-decoration: underline 2px var(--red);
  text-underline-offset: 3px;
}

/* ---- support / donation footer ----------------------------------------- */
.support {
  margin-top: 3rem;
  padding-top: 1.2rem;
  border-top: 1px solid var(--rule);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  flex-wrap: wrap;
}

.support__text {
  margin: 0;
  max-width: 46ch;
  color: var(--ink-soft);
  font-size: 0.82rem;
  line-height: 1.6;
}

.support__link {
  flex: 0 0 auto;
  font-weight: 700;
  font-size: 0.85rem;
  color: var(--red-deep);
  text-decoration: none;
  white-space: nowrap;
  padding: 0.45rem 0.95rem;
  border: 1.5px solid var(--red);
  border-radius: 999px;
  transition: background-color 150ms ease, color 150ms ease;
}

.support__link:hover,
.support__link:focus-visible {
  background: var(--red);
  color: var(--paper-2);
  outline: none;
}
