/* Grundlage: Schriften, Farben und Bausteine, die jeder Bildschirm benutzt.
   Vorbild ist die osmanische Buchmalerei (Tezhip): Gold auf Lapisblau, dazu Pergament als Lesefläche. */

@font-face { font-family: "Cormorant Garamond"; font-weight: 600; font-style: normal; font-display: swap; src: url("../assets/fonts/cormorant-600.woff2") format("woff2"); }
@font-face { font-family: "Cormorant Garamond"; font-weight: 600; font-style: italic; font-display: swap; src: url("../assets/fonts/cormorant-600i.woff2") format("woff2"); }
@font-face { font-family: "Alegreya"; font-weight: 400; font-style: normal; font-display: swap; src: url("../assets/fonts/alegreya-400.woff2") format("woff2"); }
@font-face { font-family: "Alegreya"; font-weight: 400; font-style: italic; font-display: swap; src: url("../assets/fonts/alegreya-400i.woff2") format("woff2"); }
@font-face { font-family: "Alegreya"; font-weight: 700; font-style: normal; font-display: swap; src: url("../assets/fonts/alegreya-700.woff2") format("woff2"); }
@font-face { font-family: "Alegreya Sans"; font-weight: 500; font-style: normal; font-display: swap; src: url("../assets/fonts/alegreya-sans-500.woff2") format("woff2"); }
@font-face { font-family: "Alegreya Sans"; font-weight: 700; font-style: normal; font-display: swap; src: url("../assets/fonts/alegreya-sans-700.woff2") format("woff2"); }
@font-face { font-family: "Aref Ruqaa"; font-weight: 700; font-style: normal; font-display: swap; src: url("../assets/fonts/aref-ruqaa-700.woff2") format("woff2"); }

:root {
  --lapis-950: #070d18;
  --lapis-900: #0b1524;
  --lapis-800: #111f33;
  --lapis-700: #182b45;
  --lapis-600: #21395a;
  --gold-100: #f8e7b4;
  --gold-300: #e8c877;
  --gold-500: #c9a24b;
  --gold-700: #8e6c27;
  --teal: #2f9e95;
  --teal-soft: #6fd0c0;
  --ember: #d9694a;
  --ember-soft: #f0977b;
  --paper-50: #fbf4e4;
  --paper-100: #f4e9d3;
  --paper-200: #e9d9b9;
  --paper-300: #d8c39a;
  --ink: #2a1f14;
  --ink-soft: #6a5640;
  --rubric: #9c3522;
  --line: rgba(201, 162, 75, .3);
  --line-strong: rgba(232, 200, 119, .6);

  --display: "Cormorant Garamond", "Palatino Linotype", "Book Antiqua", Palatino, Georgia, serif;
  --text: "Alegreya", "Palatino Linotype", "Book Antiqua", Palatino, Georgia, serif;
  --label: "Alegreya Sans", "Segoe UI", "Helvetica Neue", Arial, sans-serif;
  --arabic: "Aref Ruqaa", "Traditional Arabic", "Noto Naskh Arabic", "Geeza Pro", serif;

  --top: 68px;
  --dock: 60px;
  --stats-h: 66px;
  --safe-t: env(safe-area-inset-top, 0px);
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-l: env(safe-area-inset-left, 0px);
  --safe-r: env(safe-area-inset-right, 0px);
  --shadow: 0 10px 28px rgba(2, 6, 14, .5);

  /* Stern-und-Kreuz-Muster, die häufigste Fliese der islamischen Baukunst. */
  --tile: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='80' height='80' viewBox='0 0 80 80'%3E%3Cpath d='M80 40L68.3 51.7V68.3H51.7L40 80L28.3 68.3H11.7V51.7L0 40L11.7 28.3V11.7H28.3L40 0L51.7 11.7H68.3V28.3z' fill='none' stroke='%23e8c877' stroke-opacity='.07'/%3E%3Cpath d='M60 40L54.1 45.9V54.1H45.9L40 60L34.1 54.1H25.9V45.9L20 40L25.9 34.1V25.9H34.1L40 20L45.9 25.9H54.1V34.1z' fill='%23e8c877' fill-opacity='.022' stroke='%23e8c877' stroke-opacity='.05'/%3E%3C/svg%3E");
  /* Zierleiste nach dem Unwan, dem Kopfstück einer Handschrift. */
  --unwan: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='28' height='14' viewBox='0 0 28 14'%3E%3Crect width='28' height='14' fill='%23182b45'/%3E%3Cpath d='M14 1l2.2 3.8L20 7l-3.8 2.2L14 13l-2.2-3.8L8 7l3.8-2.2z' fill='%23e8c877'/%3E%3Ccircle cx='14' cy='7' r='1.5' fill='%23182b45'/%3E%3Ccircle cx='0' cy='7' r='2' fill='%232f9e95'/%3E%3Ccircle cx='28' cy='7' r='2' fill='%232f9e95'/%3E%3C/svg%3E");
  --grain: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='220' height='220'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='.8' numOctaves='3'/%3E%3CfeColorMatrix values='0 0 0 0 .35 0 0 0 0 .25 0 0 0 0 .12 0 0 0 .09 0'/%3E%3C/filter%3E%3Crect width='220' height='220' filter='url(%23n)'/%3E%3C/svg%3E");
}

* { box-sizing: border-box; }
html { font-size: 16px; -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  min-height: 100vh;
  min-height: 100dvh;
  color: var(--paper-100);
  font-family: var(--text);
  font-size: 1.0625rem;
  line-height: 1.5;
  font-variant-numeric: lining-nums;
  background-color: var(--lapis-900);
  background-image: radial-gradient(ellipse 90% 60% at 50% -10%, rgba(47, 158, 149, .13), transparent 70%), var(--tile);
  background-attachment: fixed;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
}
button { font: inherit; color: inherit; cursor: pointer; }
button:disabled { cursor: not-allowed; }
:focus-visible { outline: 2px solid var(--gold-300); outline-offset: 2px; }
h1, h2, h3, h4 { font-weight: 600; line-height: 1.15; margin: 0; }
small { font-size: inherit; }

* { scrollbar-width: thin; scrollbar-color: rgba(201, 162, 75, .4) transparent; }

.ic { width: 1.25em; height: 1.25em; flex: none; fill: none; stroke: currentColor; stroke-width: 1.7; stroke-linecap: round; stroke-linejoin: round; }

.rosette { width: 1.5em; height: 1.5em; flex: none; }
.ro-petals path { fill: var(--gold-300); }
.ro-ring { fill: var(--lapis-700); stroke: var(--gold-300); stroke-width: 1.5; }
.ro-star { fill: var(--gold-500); }
.ro-core { fill: var(--paper-100); }

/* ───── Schaltflächen ───── */
.primary {
  display: inline-flex; align-items: center; justify-content: center; gap: .5rem;
  min-height: 46px; padding: .55rem 1.35rem;
  font-family: var(--label); font-weight: 700; font-size: 1rem; letter-spacing: .02em;
  color: #2a1c08;
  background: linear-gradient(180deg, var(--gold-100), var(--gold-300) 45%, var(--gold-500));
  border: 1px solid var(--gold-700); border-radius: 5px;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, .55), 0 3px 10px rgba(0, 0, 0, .3);
  transition: filter .15s, transform .1s;
}
.primary:hover:not(:disabled) { filter: brightness(1.08); }
.primary:active:not(:disabled) { transform: translateY(1px); }
.primary:disabled { opacity: .45; filter: saturate(.4); }
.primary.wide { width: 100%; }

.small {
  min-height: 42px; padding: .3rem .8rem; font-family: var(--label); font-weight: 500; font-size: .94rem;
  color: var(--paper-100); background: rgba(255, 255, 255, .05);
  border: 1px solid var(--line-strong); border-radius: 5px;
  transition: background .15s, border-color .15s;
}
.small:hover:not(:disabled) { background: rgba(232, 200, 119, .16); }
.small:disabled { opacity: .45; }

.tool {
  display: inline-flex; align-items: center; justify-content: center; gap: .4rem;
  min-width: 40px; min-height: 40px; padding: .25rem .5rem;
  font-family: var(--label); font-weight: 500; font-size: .875rem;
  color: var(--paper-200); background: rgba(255, 255, 255, .04);
  border: 1px solid var(--line); border-radius: 6px;
  transition: background .15s, color .15s, border-color .15s;
}
.tool:hover { background: rgba(232, 200, 119, .15); color: var(--gold-100); border-color: var(--line-strong); }

.link { background: none; border: 0; color: var(--gold-300); text-decoration: underline; text-underline-offset: 3px; padding: 0; }
.link-dark { display: inline-flex; align-items: center; gap: .35rem; background: none; border: 0; padding: .2rem 0; color: #1d6b66; font-family: var(--label); font-weight: 500; font-size: .95rem; text-align: start; text-decoration: underline; text-underline-offset: 3px; }

/* Ein Fachwort: gepunktet unterstrichen, dahinter ein kleines i. Ein Klick öffnet die Erklärung. */
.term { background: none; border: 0; padding: 0; color: inherit; font: inherit; border-bottom: 1px dotted currentColor; cursor: help; }
.term::after {
  content: "i"; display: inline-grid; place-items: center; width: 1.05em; height: 1.05em; margin-inline-start: .18em;
  vertical-align: .32em; border: 1px solid currentColor; border-radius: 50%;
  font: italic 700 .62em/1 var(--text); opacity: .7;
}
.term:hover::after, .term:focus-visible::after { opacity: 1; }

.term-tip {
  position: fixed; z-index: 70; width: max-content; max-width: min(360px, calc(100vw - 20px));
  color: var(--ink); background: linear-gradient(180deg, var(--paper-50), var(--paper-100));
  border: 1px solid var(--gold-700); border-radius: 8px; padding: .7rem .9rem .6rem;
  font-family: var(--text); font-size: .97rem; line-height: 1.4; box-shadow: var(--shadow);
}
.term-tip-head { display: flex; align-items: center; justify-content: space-between; gap: .6rem; }
.term-tip-head strong { font-family: var(--display); font-size: 1.2rem; color: var(--lapis-800); }
.term-tip p { margin: .3rem 0 .4rem; }
.term-tip-x { display: grid; place-items: center; min-width: 32px; min-height: 32px; padding: 0; background: none; border: 0; color: var(--ink-soft); }
.term-tip-x:hover { color: var(--ink); }
.term-tip-x svg, .term-tip .link-dark svg { width: 18px; height: 18px; }

/* ───── Flächen ───── */
.panel {
  background: linear-gradient(180deg, rgba(33, 57, 90, .62), rgba(17, 31, 51, .86));
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: .85rem 1rem;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, .05), 0 6px 18px rgba(2, 6, 14, .28);
}
.panel h3 {
  display: flex; align-items: center; gap: .5rem; margin-bottom: .6rem;
  font-family: var(--label); font-weight: 700; font-size: .78rem; letter-spacing: .13em; text-transform: uppercase;
  color: var(--gold-300);
}
.panel h3::before { content: ""; width: .45rem; height: .45rem; background: var(--gold-300); transform: rotate(45deg); flex: none; }

.bar { display: block; height: 5px; background: rgba(255, 255, 255, .1); border-radius: 3px; overflow: hidden; }
.bar i { display: block; height: 100%; border-radius: 3px; background: linear-gradient(90deg, var(--gold-500), var(--gold-300)); }

.notice {
  max-width: 620px; margin: 0 auto 1.2rem; padding: .6rem .9rem; font-size: .95rem;
  color: var(--paper-100); background: rgba(217, 105, 74, .16); border: 1px solid var(--ember); border-radius: 6px;
}

/* ───── Fenster und Meldungen ───── */
#modal {
  position: fixed; inset: 0; z-index: 40; padding: 1.2rem;
  display: grid; place-items: center;
  background: rgba(4, 9, 18, .74);
  backdrop-filter: blur(3px);
}
#modal[hidden] { display: none; }
.sheet {
  position: relative; width: 100%; max-width: 640px; max-height: 86vh; max-height: 86dvh; overflow-y: auto;
  color: var(--ink);
  background: var(--grain), linear-gradient(180deg, var(--paper-50), var(--paper-100));
  border: 1px solid var(--gold-700); border-radius: 8px;
  padding: 1.5rem 1.6rem 1.3rem;
  box-shadow: inset 0 0 0 4px var(--paper-100), inset 0 0 0 5px var(--paper-300), 0 24px 60px rgba(0, 0, 0, .6);
  animation: sheet-in .22s ease-out;
}
@keyframes sheet-in { from { opacity: 0; transform: translateY(14px) scale(.985); } to { opacity: 1; transform: none; } }
.sheet h2 { font-family: var(--display); font-size: 2rem; color: var(--lapis-800); margin-bottom: .5rem; }
.sheet h3 { font-family: var(--label); font-weight: 700; font-size: .78rem; letter-spacing: .13em; text-transform: uppercase; color: var(--rubric); margin: 1.1rem 0 .4rem; }
.sheet p { margin: 0 0 .6rem; }
.sheet dt { font-weight: 700; margin-top: .6rem; color: var(--lapis-800); }
.sheet dd { margin: 0; font-size: .97rem; }
.sheet ul { padding-inline-start: 1.2rem; }
.sheet > .primary { margin-top: 1.1rem; min-width: 9rem; color: var(--gold-100); background: var(--lapis-700); border-color: var(--gold-700); box-shadow: inset 0 1px 0 rgba(255, 255, 255, .12); }
.sheet .small { color: var(--ink); background: var(--paper-50); border-color: var(--paper-300); }
.sheet .small:hover:not(:disabled) { border-color: var(--gold-700); background: #fff; }
.sheet-actions { display: flex; gap: .5rem; justify-content: flex-end; align-items: center; flex-wrap: wrap; margin-top: 1rem; }
.sheet-actions .primary { color: var(--gold-100); background: var(--lapis-700); box-shadow: none; }
.sheet-menu { display: grid; gap: .4rem; margin: .8rem 0 0; }
.sheet-item {
  display: flex; align-items: center; gap: .7rem; min-height: 50px; padding: .4rem .85rem; width: 100%; text-align: start;
  font-family: var(--label); font-weight: 500; font-size: 1.02rem;
  color: var(--ink); background: var(--paper-50); border: 1px solid var(--paper-300); border-radius: 6px;
  transition: border-color .15s, background .15s;
}
.sheet-item .ic { color: var(--gold-700); }
.sheet-item:hover { background: #fff; border-color: var(--gold-700); }
.sheet-item.danger, .sheet-item.danger .ic { color: var(--rubric); }
.slots { list-style: none; margin: 0; padding: 0; }
.slots li { display: flex; align-items: center; justify-content: space-between; gap: .8rem; flex-wrap: wrap; padding: .55rem 0; border-bottom: 1px solid var(--paper-300); }
.slots strong { display: block; font-weight: 700; color: var(--lapis-800); }
.slots span { font-size: .9rem; color: var(--ink-soft); }
.slot-buttons { display: flex; gap: .35rem; flex-wrap: wrap; }

#toast {
  position: fixed; left: 50%; bottom: calc(1.2rem + var(--safe-b)); transform: translate(-50%, 1rem);
  width: max-content; max-width: min(560px, calc(100vw - 1.5rem));
  color: var(--paper-50); background: var(--lapis-700);
  border: 1px solid var(--gold-500); border-radius: 8px; padding: .6rem 1rem;
  font-size: .97rem; line-height: 1.35; box-shadow: var(--shadow);
  opacity: 0; pointer-events: none; z-index: 50;
  transition: opacity .2s, transform .2s;
}
#toast.show { opacity: 1; transform: translate(-50%, 0); }

@media (pointer: coarse) {
  .small, .tool { min-height: 46px; min-width: 46px; }
}
@media (max-width: 979px) {
  #toast { bottom: calc(var(--dock) + .7rem + var(--safe-b)); }
}
@media (max-width: 640px) {
  #modal { padding: 0; place-items: end stretch; }
  .sheet { max-width: none; max-height: 90dvh; border-radius: 14px 14px 0 0; border-width: 1px 0 0; padding: 1.3rem 1.1rem calc(1.2rem + var(--safe-b)); box-shadow: 0 -12px 40px rgba(0, 0, 0, .55); animation-name: sheet-up; }
  .sheet > .primary { width: 100%; }
  @keyframes sheet-up { from { transform: translateY(100%); } to { transform: none; } }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; scroll-behavior: auto !important; }
}

/* Anleitung: Reiter oben, Farbfelder für die Beziehungsstufen. */
.guide-tabs { display: flex; flex-wrap: wrap; gap: .35rem; margin: .2rem 0 .9rem; }
.guide-tabs .small[aria-pressed="true"] { color: var(--gold-100); background: var(--lapis-700); border-color: var(--gold-700); font-weight: 700; }
.guide ul { margin: 0 0 .7rem; }
.guide li { margin-bottom: .3rem; }
.guide-swatch { display: inline-block; width: .9rem; height: .9rem; margin-inline-end: .45rem; vertical-align: -.1rem; border: 1px solid rgba(0, 0, 0, .35); border-radius: 3px; }
