/*!
 * hayal.css — a classless stylesheet for quiet writing
 * -----------------------------------------------------
 * "hayal" (Tr.) — dream, reverie, imagination.
 *
 * A serif, paper-toned stylesheet for anonymous blogs, journals and
 * notebooks of thought. Built on bare HTML elements — no classes
 * required. Its ornament (a small repeating diamond) is drawn from
 * the geometric tessellation of Islamic and Ottoman manuscript
 * decoration; its palette from aged vellum, walnut ink, İznik tile
 * turquoise and manuscript rubrication red.
 *
 * Usage: <link rel="stylesheet" href="hayal.css">
 * Theme: follows prefers-color-scheme automatically. Force a theme
 *        with <html data-theme="dark"> or <html data-theme="light">.
 *
 * License: MIT. Use it, change it, give it away.
 */

/* ---------------------------------------------------------------
   1. Type
   --------------------------------------------------------------- */

@import url('https://fonts.googleapis.com/css2?family=Cormorant+Garamond:ital,wght@0,500;0,600;0,700;1,500&family=Vollkorn:ital,wght@0,400;0,500;0,600;1,400&display=swap');

/* ---------------------------------------------------------------
   2. Tokens — light theme (default)
   --------------------------------------------------------------- */

:root {
  --hayal-bg: #e9dcc3;
  --hayal-bg-alt: #e1d2b3;
  --hayal-ink: #2c2116;
  --hayal-ink-soft: #5c4a38;
  --hayal-accent: #0f6e7c;
  --hayal-accent-deep: #0b5560;
  --hayal-rubric: #9c3b2e;
  --hayal-gold: #a9822e;
  --hayal-border: #c9b98f;

  --hayal-font-display: 'Cormorant Garamond', 'Palatino Linotype', Georgia, serif;
  --hayal-font-body: 'Vollkorn', Georgia, 'Times New Roman', serif;

  --hayal-motif: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='40' height='20' viewBox='0 0 40 20'%3E%3Cpath d='M20 3 L27 10 L20 17 L13 10 Z' fill='none' stroke='%23A9822E' stroke-width='1.3'/%3E%3Ccircle cx='4' cy='10' r='1.4' fill='%23A9822E'/%3E%3Ccircle cx='36' cy='10' r='1.4' fill='%23A9822E'/%3E%3C/svg%3E");

  color-scheme: light;
}

/* Automatic dark theme — "manuscript by lamplight" */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --hayal-bg: #1b1712;
    --hayal-bg-alt: #241e17;
    --hayal-ink: #ede0c8;
    --hayal-ink-soft: #c4b393;
    --hayal-accent: #4fb8c4;
    --hayal-accent-deep: #7dd0da;
    --hayal-rubric: #d97052;
    --hayal-gold: #c9a227;
    --hayal-border: #4a3f2e;

    --hayal-motif: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='40' height='20' viewBox='0 0 40 20'%3E%3Cpath d='M20 3 L27 10 L20 17 L13 10 Z' fill='none' stroke='%23C9A227' stroke-width='1.3'/%3E%3Ccircle cx='4' cy='10' r='1.4' fill='%23C9A227'/%3E%3Ccircle cx='36' cy='10' r='1.4' fill='%23C9A227'/%3E%3C/svg%3E");

    color-scheme: dark;
  }
}

/* Explicit override, independent of system preference */
:root[data-theme="dark"] {
  --hayal-bg: #1b1712;
  --hayal-bg-alt: #241e17;
  --hayal-ink: #ede0c8;
  --hayal-ink-soft: #c4b393;
  --hayal-accent: #4fb8c4;
  --hayal-accent-deep: #7dd0da;
  --hayal-rubric: #d97052;
  --hayal-gold: #c9a227;
  --hayal-border: #4a3f2e;
  --hayal-motif: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='40' height='20' viewBox='0 0 40 20'%3E%3Cpath d='M20 3 L27 10 L20 17 L13 10 Z' fill='none' stroke='%23C9A227' stroke-width='1.3'/%3E%3Ccircle cx='4' cy='10' r='1.4' fill='%23C9A227'/%3E%3Ccircle cx='36' cy='10' r='1.4' fill='%23C9A227'/%3E%3C/svg%3E");
  color-scheme: dark;
}

:root[data-theme="light"] { color-scheme: light; }

/* ---------------------------------------------------------------
   3. Reset & base
   --------------------------------------------------------------- */

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

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

body {
  display: flex;
  flex-direction: column;
  align-items: center;
  margin: 0;
  padding: 0 1.25rem;
  background-color: var(--hayal-bg);
  background-image: radial-gradient(circle at 1px 1px, rgba(0, 0, 0, 0.035) 1px, transparent 0);
  background-size: 22px 22px;
  color: var(--hayal-ink);
  font-family: var(--hayal-font-body);
  font-size: 1.125rem;
  line-height: 1.7;
  text-rendering: optimizeLegibility;
  transition: background-color 0.3s ease, color 0.3s ease;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) body {
    background-image: radial-gradient(circle at 1px 1px, rgba(255, 255, 255, 0.03) 1px, transparent 0);
  }
}
:root[data-theme="dark"] body {
  background-image: radial-gradient(circle at 1px 1px, rgba(255, 255, 255, 0.03) 1px, transparent 0);
}

/* ---------------------------------------------------------------
   4. Page rhythm — body's direct children form the column
   --------------------------------------------------------------- */

body > * {
  width: 100%;
  max-width: 42rem;
}

header, main, footer, article, section { margin-inline: auto; }

main { flex: 1; padding: 1rem 0 4rem; }

/* ---------------------------------------------------------------
   5. Header
   --------------------------------------------------------------- */

header {
  padding: 3.5rem 0 0;
  text-align: center;
}

header h1 {
  margin-bottom: 0.3rem;
}

header p {
  max-width: none;
  color: var(--hayal-ink-soft);
  font-style: italic;
  font-size: 1.05rem;
  letter-spacing: 0.01em;
}

header::after {
  content: "";
  display: block;
  width: 200px;
  height: 20px;
  margin: 1.75rem auto 0;
  background-image: var(--hayal-motif);
  background-repeat: repeat-x;
  background-size: 40px 20px;
  background-position: center;
}

/* ---------------------------------------------------------------
   6. Navigation
   --------------------------------------------------------------- */

nav {
  display: flex;
  justify-content: center;
  gap: 1.75rem;
  flex-wrap: wrap;
  margin: 1.75rem auto 0;
  padding-bottom: 1.5rem;
  font-family: var(--hayal-font-display);
  font-variant: small-caps;
  font-size: 1.15rem;
  letter-spacing: 0.02em;
}

nav a {
  color: var(--hayal-ink);
  text-decoration: none;
  border-bottom: 1px solid transparent;
  padding-bottom: 0.15em;
}

nav a:hover, nav a:focus-visible {
  color: var(--hayal-accent);
  border-bottom-color: var(--hayal-accent);
}

/* ---------------------------------------------------------------
   7. Headings
   --------------------------------------------------------------- */

h1, h2, h3, h4, h5, h6 {
  font-family: var(--hayal-font-display);
  font-weight: 600;
  line-height: 1.2;
  color: var(--hayal-ink);
  margin: 2.75rem 0 1rem;
}

h1 {
  font-size: clamp(2.2rem, 5vw, 3rem);
  font-weight: 700;
  letter-spacing: 0.005em;
  margin-top: 0;
}

h2 {
  font-size: clamp(1.5rem, 3.2vw, 1.9rem);
  padding-bottom: 0.4rem;
  border-bottom: 1px solid var(--hayal-border);
}

h3 { font-size: clamp(1.25rem, 2.5vw, 1.5rem); }
h4 { font-size: 1.2rem; font-style: italic; font-weight: 600; }
h5, h6 { font-size: 1.05rem; font-variant: small-caps; letter-spacing: 0.03em; }

h1 + p, h2 + p, h3 + p { margin-top: 0.5rem; }

/* ---------------------------------------------------------------
   8. Body copy
   --------------------------------------------------------------- */

p {
  margin: 0 0 1.35rem;
  max-width: 38rem;
}

article > p:first-of-type::first-letter {
  font-family: var(--hayal-font-display);
  font-size: 3.4em;
  font-weight: 600;
  float: left;
  line-height: 0.8;
  padding: 0.05em 0.1em 0 0;
  color: var(--hayal-rubric);
}

strong, b { font-weight: 700; color: var(--hayal-ink); }
em, i { font-style: italic; }

small { font-size: 0.85em; color: var(--hayal-ink-soft); }

sub, sup { font-size: 0.7em; }

time {
  font-style: italic;
  color: var(--hayal-ink-soft);
  font-size: 0.95em;
}

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

/* ---------------------------------------------------------------
   9. Links
   --------------------------------------------------------------- */

a {
  color: var(--hayal-accent);
  text-decoration: underline;
  text-decoration-color: color-mix(in srgb, var(--hayal-accent) 45%, transparent);
  text-decoration-thickness: 1px;
  text-underline-offset: 0.2em;
  transition: color 0.15s ease, text-decoration-color 0.15s ease;
}

a:hover, a:focus-visible {
  color: var(--hayal-accent-deep);
  text-decoration-color: currentColor;
}

a:focus-visible, button:focus-visible, input:focus-visible,
textarea:focus-visible, select:focus-visible, summary:focus-visible {
  outline: 2px solid var(--hayal-accent);
  outline-offset: 3px;
  border-radius: 2px;
}

/* ---------------------------------------------------------------
   10. Lists
   --------------------------------------------------------------- */

ul, ol {
  padding-left: 1.3em;
  margin: 0 0 1.35rem;
}

li { margin-bottom: 0.5rem; }

ul > li::marker {
  color: var(--hayal-accent);
}

ol > li::marker {
  color: var(--hayal-accent);
  font-family: var(--hayal-font-display);
  font-weight: 600;
}

dl { margin: 0 0 1.35rem; }
dt { font-weight: 700; color: var(--hayal-ink); }
dd { margin: 0 0 0.85rem 0; color: var(--hayal-ink-soft); }

/* ---------------------------------------------------------------
   11. Blockquote
   --------------------------------------------------------------- */

blockquote {
  position: relative;
  margin: 2.25rem 0;
  padding: 1.35rem 1.75rem;
  max-width: none;
  background: var(--hayal-bg-alt);
  border-left: 3px solid var(--hayal-gold);
  border-radius: 14px 5px 5px 5px;
  font-style: italic;
  color: var(--hayal-ink-soft);
}

blockquote p { max-width: none; }
blockquote p:last-of-type { margin-bottom: 0; }

blockquote cite {
  display: block;
  margin-top: 0.9rem;
  padding-top: 0.55rem;
  border-top: 1px solid var(--hayal-border);
  font-style: normal;
  font-size: 0.9em;
  color: var(--hayal-ink-soft);
}

/* ---------------------------------------------------------------
   12. Horizontal rule — the recurring motif
   --------------------------------------------------------------- */

hr {
  height: 18px;
  margin: 3rem auto;
  border: 0;
  max-width: 42rem;
  background-image: var(--hayal-motif);
  background-repeat: repeat-x;
  background-size: 40px 18px;
  background-position: center;
}

/* ---------------------------------------------------------------
   13. Tables
   --------------------------------------------------------------- */

table {
  width: 100%;
  max-width: none;
  border-collapse: collapse;
  margin: 0 0 1.75rem;
  font-size: 0.95em;
}

caption {
  text-align: left;
  font-style: italic;
  color: var(--hayal-ink-soft);
  margin-bottom: 0.5rem;
}

th, td {
  text-align: left;
  padding: 0.6em 0.9em;
  border-bottom: 1px solid var(--hayal-border);
}

th {
  font-family: var(--hayal-font-display);
  font-variant: small-caps;
  font-weight: 600;
  letter-spacing: 0.02em;
  border-bottom: 2px solid var(--hayal-gold);
}

tr:last-child td { border-bottom: none; }

/* ---------------------------------------------------------------
   14. Code
   --------------------------------------------------------------- */

code, kbd, samp, pre {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, 'Liberation Mono', monospace;
  font-size: 0.9em;
}

code {
  background: var(--hayal-bg-alt);
  padding: 0.15em 0.4em;
  border-radius: 4px;
  color: var(--hayal-rubric);
}

pre {
  background: var(--hayal-bg-alt);
  border-left: 3px solid var(--hayal-gold);
  border-radius: 4px;
  padding: 1.1rem 1.3rem;
  overflow-x: auto;
  max-width: none;
  margin: 0 0 1.75rem;
  line-height: 1.55;
}

pre code {
  background: none;
  padding: 0;
  color: var(--hayal-ink);
}

kbd {
  background: var(--hayal-bg-alt);
  border: 1px solid var(--hayal-border);
  border-bottom-width: 2px;
  border-radius: 4px;
  padding: 0.1em 0.45em;
}

/* ---------------------------------------------------------------
   15. Media
   --------------------------------------------------------------- */

img, video {
  max-width: 100%;
  height: auto;
  border-radius: 4px;
  display: block;
}

figure {
  margin: 2rem 0;
  max-width: none;
}

figcaption {
  margin-top: 0.6rem;
  font-size: 0.9em;
  font-style: italic;
  color: var(--hayal-ink-soft);
  text-align: center;
}

/* ---------------------------------------------------------------
   16. Mark / selection
   --------------------------------------------------------------- */

mark {
  background: color-mix(in srgb, var(--hayal-rubric) 22%, transparent);
  color: var(--hayal-ink);
  padding: 0.05em 0.2em;
  border-radius: 2px;
}

::selection {
  background: var(--hayal-accent);
  color: var(--hayal-bg);
}

/* ---------------------------------------------------------------
   17. Details / summary
   --------------------------------------------------------------- */

details {
  margin: 0 0 1.35rem;
  padding: 0.9rem 1.1rem;
  background: var(--hayal-bg-alt);
  border-radius: 6px;
  border: 1px solid var(--hayal-border);
}

summary {
  cursor: pointer;
  font-family: var(--hayal-font-display);
  font-weight: 600;
}

details[open] summary { margin-bottom: 0.6rem; }

/* ---------------------------------------------------------------
   18. Forms
   --------------------------------------------------------------- */

form { max-width: none; }

label {
  display: block;
  margin-bottom: 0.35rem;
  font-family: var(--hayal-font-display);
  font-weight: 600;
}

input, textarea, select {
  width: 100%;
  font-family: var(--hayal-font-body);
  font-size: 1rem;
  color: var(--hayal-ink);
  background: var(--hayal-bg-alt);
  border: 1px solid var(--hayal-border);
  border-radius: 4px;
  padding: 0.6em 0.8em;
  margin-bottom: 1.1rem;
}

input:focus, textarea:focus, select:focus {
  border-color: var(--hayal-accent);
}

button, input[type="submit"], input[type="button"] {
  width: auto;
  display: inline-block;
  font-family: var(--hayal-font-display);
  font-weight: 600;
  letter-spacing: 0.02em;
  background: var(--hayal-ink);
  color: var(--hayal-bg);
  border: none;
  border-radius: 3px 3px 1px 1px;
  padding: 0.6em 1.5em;
  cursor: pointer;
  transition: background-color 0.15s ease;
}

button:hover, input[type="submit"]:hover, input[type="button"]:hover {
  background: var(--hayal-accent-deep);
}

/* ---------------------------------------------------------------
   19. Footer
   --------------------------------------------------------------- */

footer {
  margin-top: auto;
  padding: 2.5rem 0 3.5rem;
  border-top: 1px solid var(--hayal-border);
  text-align: center;
  color: var(--hayal-ink-soft);
  font-size: 0.9rem;
}

footer a { color: var(--hayal-ink-soft); }

/* ---------------------------------------------------------------
   20. Accessibility & environment
   --------------------------------------------------------------- */

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

@media (max-width: 640px) {
  header { padding-top: 2.5rem; }
  blockquote { padding: 1.1rem 1.25rem; }
  article > p:first-of-type::first-letter { font-size: 2.8em; }
}

@media print {
  body { background: #fff; color: #000; }
  header::after, hr { background-image: none; border-top: 1px solid #999; height: 0; }
  nav, footer { display: none; }
}
