/* ============================================================
   Nano Glagolitic — refined Croatian "illuminated manuscript"
   aesthetic. Parchment & ink, crimson + gold pleter accents.
   ============================================================ */

@font-face {
  font-family: "Noto Sans Glagolitic";
  src: url("./glagolitic.woff2") format("woff2");
  font-display: swap;
  unicode-range: U+2C00-2C5F;
}

:root {
  /* Type */
  --font-display: "Iowan Old Style", "Palatino Linotype", Palatino,
    "Book Antiqua", "Hoefler Text", Garamond, Georgia, serif;
  --font-body: "Iowan Old Style", "Palatino Linotype", Palatino, Georgia,
    "Times New Roman", serif;
  --font-glag: "Noto Sans Glagolitic", "Segoe UI Historic", serif;

  /* Light theme — parchment & crimson */
  --bg: #f1e9d9;
  --bg-glow: #fbf6ea;
  --surface: #fcf8ef;
  --surface-2: #f6efde;
  --ink: #2a2118;
  --ink-soft: #6f6452;
  --line: #e3d6bb;
  --line-strong: #d8c69f;
  --crimson: #8a1f20;
  --crimson-bright: #a8332b;
  --gold: #b08a4c;
  --gold-soft: #c7a667;
  --focus: rgba(168, 51, 43, 0.28);
  --shadow: 0 1px 2px rgba(58, 42, 22, 0.06),
    0 14px 38px -18px rgba(58, 42, 22, 0.28);
  --toast-bg: #2a2118;
  --toast-ink: #f6efde;
}

[data-theme="dark"] {
  /* Dark theme — deep ink & ember */
  --bg: #16120c;
  --bg-glow: #211a10;
  --surface: #1f1810;
  --surface-2: #261d12;
  --ink: #ece0c9;
  --ink-soft: #a99a7e;
  --line: #352a1b;
  --line-strong: #46371f;
  --crimson: #c4463c;
  --crimson-bright: #d9594b;
  --gold: #cba968;
  --gold-soft: #d8bd80;
  --focus: rgba(216, 189, 128, 0.3);
  --shadow: 0 1px 2px rgba(0, 0, 0, 0.4), 0 18px 44px -20px rgba(0, 0, 0, 0.7);
  --toast-bg: #ece0c9;
  --toast-ink: #1f1810;
}

* { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  min-height: 100vh;
  min-height: 100dvh;
  font-family: var(--font-body);
  color: var(--ink);
  background:
    radial-gradient(140% 90% at 50% -10%, var(--bg-glow), transparent 55%),
    var(--bg);
  background-attachment: fixed;
  padding:
    calc(env(safe-area-inset-top) + 1.1rem)
    calc(env(safe-area-inset-right) + 1.1rem)
    calc(env(safe-area-inset-bottom) + 1.1rem)
    calc(env(safe-area-inset-left) + 1.1rem);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 1.1rem;
  transition: background-color 0.4s ease, color 0.4s ease;
}

.skip-link {
  position: absolute;
  left: -999px;
}
.skip-link:focus {
  left: 1rem;
  top: 1rem;
  z-index: 50;
  background: var(--surface);
  color: var(--ink);
  padding: 0.5rem 0.9rem;
  border-radius: 8px;
  box-shadow: var(--shadow);
}

/* ---------- Header ---------- */
.app-header {
  position: relative;
  width: 100%;
  max-width: 680px;
  text-align: center;
  padding: 1.4rem 3.2rem 0.6rem;
}

.mark {
  width: 52px;
  height: 52px;
  color: var(--gold);
  filter: drop-shadow(0 2px 5px rgba(0, 0, 0, 0.12));
  opacity: 0;
  animation: rise 0.7s ease 0.05s forwards;
}
.mark-boss { fill: var(--crimson); }

.title {
  font-family: var(--font-display);
  font-weight: 600;
  font-size: clamp(2.05rem, 7.5vw, 2.9rem);
  letter-spacing: 0.012em;
  margin: 0.25rem 0 0;
  color: var(--ink);
  opacity: 0;
  animation: rise 0.7s ease 0.14s forwards;
}

.subtitle {
  margin: 0.4rem 0 0;
  font-size: 0.86rem;
  letter-spacing: 0.32em;
  text-transform: uppercase;
  color: var(--crimson);
  opacity: 0;
  animation: rise 0.7s ease 0.24s forwards;
}
[data-theme="dark"] .subtitle { color: var(--gold-soft); }
.subtitle .arrow {
  color: var(--gold);
  letter-spacing: 0;
  padding: 0 0.15em;
}

/* ---------- Theme toggle ---------- */
.theme-toggle {
  position: absolute;
  top: 1.1rem;
  right: 0;
  width: 46px;
  height: 46px;
  border-radius: 50%;
  border: 1px solid var(--line-strong);
  background: var(--surface);
  color: var(--ink);
  cursor: pointer;
  display: grid;
  place-items: center;
  box-shadow: var(--shadow);
  transition: transform 0.18s ease, border-color 0.25s ease,
    background-color 0.4s ease, color 0.4s ease;
}
.theme-toggle:hover { transform: rotate(-12deg) scale(1.05); border-color: var(--gold); }
.theme-toggle:active { transform: scale(0.94); }
.theme-toggle:focus-visible { outline: 3px solid var(--focus); outline-offset: 2px; }
.theme-toggle .ic { width: 23px; height: 23px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; position: absolute; transition: opacity 0.3s ease, transform 0.4s ease; }
.theme-toggle .ic-moon { opacity: 0; transform: scale(0.5) rotate(-40deg); }
[data-theme="dark"] .theme-toggle .ic-sun { opacity: 0; transform: scale(0.5) rotate(40deg); }
[data-theme="dark"] .theme-toggle .ic-moon { opacity: 1; transform: none; color: var(--gold-soft); }

/* ---------- Alphabet map button (header, top-left) ---------- */
.map-open {
  position: absolute;
  top: 1.1rem;
  left: 0;
  width: 46px;
  height: 46px;
  border-radius: 50%;
  border: 1px solid var(--line-strong);
  background: var(--surface);
  color: var(--ink);
  cursor: pointer;
  display: grid;
  place-items: center;
  box-shadow: var(--shadow);
  transition: transform 0.18s ease, border-color 0.25s ease,
    background-color 0.4s ease, color 0.4s ease;
}
.map-open:hover { transform: rotate(12deg) scale(1.05); border-color: var(--gold); }
.map-open:active { transform: scale(0.94); }
.map-open:focus-visible { outline: 3px solid var(--focus); outline-offset: 2px; }
.map-open .ic {
  width: 23px;
  height: 23px;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

/* ---------- Alphabet map modal ---------- */
.map-modal {
  position: fixed;
  inset: 0;
  z-index: 60;
  display: grid;
  place-items: center;
  padding:
    calc(env(safe-area-inset-top) + 1.1rem)
    calc(env(safe-area-inset-right) + 1.1rem)
    calc(env(safe-area-inset-bottom) + 1.1rem)
    calc(env(safe-area-inset-left) + 1.1rem);
}
/* Author display:grid would otherwise defeat the hidden attribute. */
.map-modal[hidden] { display: none; }
.map-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(26, 18, 8, 0.45);
  -webkit-backdrop-filter: blur(3px);
  backdrop-filter: blur(3px);
  opacity: 0;
  transition: opacity 0.25s ease;
}
[data-theme="dark"] .map-backdrop { background: rgba(0, 0, 0, 0.6); }

.map-panel {
  position: relative;
  width: 100%;
  max-width: 560px;
  max-height: min(84vh, 84dvh);
  overflow: auto;
  background: var(--surface);
  border: 1px solid var(--line-strong);
  border-radius: 18px;
  box-shadow: var(--shadow);
  padding: 1rem 1.1rem 1.1rem;
  opacity: 0;
  transform: translateY(14px) scale(0.98);
  transition: opacity 0.25s ease, transform 0.25s ease,
    background-color 0.4s ease, border-color 0.4s ease;
}
.map-modal.open .map-backdrop { opacity: 1; }
.map-modal.open .map-panel { opacity: 1; transform: none; }

.map-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.6rem;
  margin-bottom: 0.75rem;
}
.map-title {
  font-family: var(--font-display);
  font-size: 0.9rem;
  font-weight: 600;
  letter-spacing: 0.22em;
  text-transform: uppercase;
  color: var(--gold);
  margin: 0;
  padding-left: 0.2rem;
}
.map-close { flex: 0 0 auto; }

.map-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(88px, 1fr));
  gap: 0.45rem;
}
.map-cell {
  display: flex;
  align-items: baseline;
  justify-content: center;
  gap: 0.55rem;
  padding: 0.55rem 0.4rem;
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-radius: 11px;
  transition: background-color 0.4s ease, border-color 0.4s ease;
}
.map-glag {
  font-family: var(--font-glag);
  font-size: 1.45rem;
  line-height: 1;
  color: var(--crimson);
}
[data-theme="dark"] .map-glag { color: var(--gold-soft); }
.map-lat {
  font-family: var(--font-body);
  font-size: 1.05rem;
  line-height: 1;
  color: var(--ink-soft);
}

.map-cell-digraph .map-glag { font-size: 1.18rem; letter-spacing: 0.03em; }

.map-note {
  margin: 0.85rem 0 0;
  text-align: center;
  font-size: 0.78rem;
  letter-spacing: 0.06em;
  color: var(--ink-soft);
}
.map-note .arrow { color: var(--gold); }

/* ---------- Main / panes ---------- */
.app-main {
  width: 100%;
  max-width: 680px;
  display: flex;
  flex-direction: column;
}

/* ---------- Slovo dana (letter of the day) ---------- */
.slovo {
  display: flex;
  align-items: center;
  gap: 0.8rem;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 18px;
  box-shadow: var(--shadow);
  padding: 0.6rem 0.9rem 0.6rem 0.6rem;
  margin-bottom: 0.85rem;
  opacity: 0;
  animation: rise 0.6s ease 0.26s forwards;
  transition: background-color 0.4s ease, border-color 0.4s ease;
}
.slovo-glyph {
  font-family: var(--font-glag);
  font-size: 1.55rem;
  line-height: 1;
  color: var(--crimson);
  background:
    linear-gradient(160deg, var(--surface-2), var(--surface));
  border: 1px solid var(--line-strong);
  border-radius: 13px;
  padding: 0.7rem 0.75rem;
  white-space: nowrap;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.25);
  transition: color 0.4s ease, background-color 0.4s ease, border-color 0.4s ease;
}
[data-theme="dark"] .slovo-glyph {
  color: var(--gold-soft);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.05);
}
.slovo-info {
  display: flex;
  flex-direction: column;
  gap: 0.18rem;
  min-width: 0;
}
.slovo-label {
  font-family: var(--font-display);
  font-size: 0.68rem;
  font-weight: 600;
  letter-spacing: 0.26em;
  text-transform: uppercase;
  color: var(--gold);
}
.slovo-latin {
  font-family: var(--font-display);
  font-size: 1.12rem;
  font-weight: 600;
  color: var(--ink);
  letter-spacing: 0.04em;
}
.slovo-name {
  margin-left: auto;
  flex: 0 0 auto;
  font-family: var(--font-display);
  font-size: 0.74rem;
  font-weight: 600;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--crimson);
  background: color-mix(in srgb, var(--gold) 14%, transparent);
  border: 1px solid var(--line-strong);
  border-radius: 999px;
  padding: 0.34rem 0.75rem;
  transition: color 0.4s ease, border-color 0.4s ease;
}
[data-theme="dark"] .slovo-name { color: var(--gold-soft); }
@supports not (background: color-mix(in srgb, red 10%, transparent)) {
  .slovo-name { background: var(--surface-2); }
}

.pane {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 18px;
  box-shadow: var(--shadow);
  padding: 0.85rem 0.95rem 1rem;
  opacity: 0;
  animation: rise 0.6s ease 0.3s forwards;
  transition: background-color 0.4s ease, border-color 0.4s ease;
}

.pane-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 0.55rem;
  padding: 0 0.2rem;
}
.pane-label {
  font-family: var(--font-display);
  font-size: 0.82rem;
  letter-spacing: 0.22em;
  text-transform: uppercase;
  color: var(--gold);
  font-weight: 600;
}

.tools { display: flex; gap: 0.3rem; }
.tool {
  width: 40px;
  height: 40px;
  display: grid;
  place-items: center;
  border: 1px solid transparent;
  border-radius: 11px;
  background: transparent;
  color: var(--ink-soft);
  cursor: pointer;
  transition: color 0.18s ease, background-color 0.18s ease,
    border-color 0.18s ease, transform 0.12s ease;
  -webkit-tap-highlight-color: transparent;
}
.tool svg { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 1.7; stroke-linecap: round; stroke-linejoin: round; }
.tool:hover { color: var(--crimson); background: var(--surface-2); border-color: var(--line); }
.tool:active { transform: scale(0.9); }
.tool:focus-visible { outline: 3px solid var(--focus); outline-offset: 1px; }

/* ---------- Text fields ---------- */
.field {
  width: 100%;
  min-height: 168px;
  resize: vertical;
  border: 1px solid var(--line);
  border-radius: 13px;
  background: var(--surface-2);
  color: var(--ink);
  padding: 0.85rem 0.95rem;
  font-size: 1.18rem;
  line-height: 1.6;
  outline: none;
  transition: border-color 0.2s ease, box-shadow 0.2s ease,
    background-color 0.4s ease, color 0.4s ease;
}
/* Hrvatski pleter watermark — barely-visible interlace behind the text. */
.field {
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='76' height='76'%3E%3Cg fill='none' stroke='%23806038' stroke-opacity='0.05' stroke-width='2.2'%3E%3Ccircle cx='38' cy='38' r='24'/%3E%3Ccircle cx='0' cy='0' r='24'/%3E%3Ccircle cx='76' cy='0' r='24'/%3E%3Ccircle cx='0' cy='76' r='24'/%3E%3Ccircle cx='76' cy='76' r='24'/%3E%3C/g%3E%3C/svg%3E");
  background-size: 76px 76px;
}
[data-theme="dark"] .field {
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='76' height='76'%3E%3Cg fill='none' stroke='%23d8bd80' stroke-opacity='0.05' stroke-width='2.2'%3E%3Ccircle cx='38' cy='38' r='24'/%3E%3Ccircle cx='0' cy='0' r='24'/%3E%3Ccircle cx='76' cy='0' r='24'/%3E%3Ccircle cx='0' cy='76' r='24'/%3E%3Ccircle cx='76' cy='76' r='24'/%3E%3C/g%3E%3C/svg%3E");
}

.field::placeholder { color: var(--ink-soft); opacity: 0.6; }
.field:focus {
  border-color: var(--crimson);
  box-shadow: 0 0 0 4px var(--focus);
  background: var(--surface);
}
.field-latin { font-family: var(--font-body); }
.field-glag {
  font-family: var(--font-glag);
  font-size: 1.5rem;
  line-height: 1.7;
  letter-spacing: 0.02em;
}

/* ---------- Pleter divider ---------- */
.divider {
  position: relative;
  height: 30px;
  margin: 0.55rem auto;
  width: 78%;
  max-width: 360px;
  display: grid;
  place-items: center;
}
.braid {
  width: 100%;
  height: 22px;
  fill: none;
  stroke: var(--gold);
  stroke-width: 2.4;
  opacity: 0.65;
}
.divider-dot {
  position: absolute;
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: var(--crimson);
  box-shadow: 0 0 0 4px var(--surface), 0 0 0 5px var(--line-strong);
}

/* ---------- Footer ---------- */
.app-footer {
  width: 100%;
  max-width: 680px;
  text-align: center;
  margin-top: auto;
  padding-top: 0.4rem;
  font-size: 0.78rem;
  color: var(--ink-soft);
}
.app-footer .muted { opacity: 0.7; display: inline-block; }

/* ---------- Smart install prompt ---------- */
.install-banner {
  position: fixed;
  left: 50%;
  bottom: calc(env(safe-area-inset-bottom) + 1.2rem);
  transform: translate(-50%, 1.6rem);
  z-index: 45;
  display: flex;
  align-items: center;
  gap: 0.65rem;
  width: min(92vw, 480px);
  background: var(--surface);
  border: 1px solid var(--line-strong);
  border-radius: 16px;
  box-shadow: var(--shadow);
  padding: 0.65rem 0.6rem 0.65rem 0.95rem;
  opacity: 0;
  transition: opacity 0.25s ease, transform 0.25s ease,
    background-color 0.4s ease, border-color 0.4s ease;
}
.install-banner[hidden] { display: none; }
.install-banner.show { opacity: 1; transform: translate(-50%, 0); }
.install-text {
  margin: 0;
  font-size: 0.84rem;
  line-height: 1.35;
  color: var(--ink-soft);
}
.install-yes {
  flex: 0 0 auto;
  font-family: var(--font-display);
  font-size: 0.78rem;
  font-weight: 600;
  letter-spacing: 0.06em;
  color: #fdf8ee;
  background: var(--crimson);
  border: 1px solid transparent;
  border-radius: 999px;
  padding: 0.5rem 0.9rem;
  cursor: pointer;
  transition: background-color 0.2s ease, transform 0.12s ease;
}
.install-yes:hover { background: var(--crimson-bright); }
.install-yes:active { transform: scale(0.95); }
.install-yes:focus-visible { outline: 3px solid var(--focus); outline-offset: 2px; }
.install-dismiss {
  flex: 0 0 auto;
  width: 34px;
  height: 34px;
  display: grid;
  place-items: center;
  background: transparent;
  border: 1px solid transparent;
  border-radius: 10px;
  color: var(--ink-soft);
  cursor: pointer;
  transition: color 0.18s ease, background-color 0.18s ease;
}
.install-dismiss svg { width: 16px; height: 16px; fill: none; stroke: currentColor; stroke-width: 1.9; stroke-linecap: round; }
.install-dismiss:hover { color: var(--crimson); background: var(--surface-2); }
.install-dismiss:focus-visible { outline: 3px solid var(--focus); outline-offset: 1px; }

/* ---------- Toast ---------- */
.toast {
  position: fixed;
  left: 50%;
  bottom: calc(env(safe-area-inset-bottom) + 1.4rem);
  transform: translate(-50%, 1.5rem);
  background: var(--toast-bg);
  color: var(--toast-ink);
  font-size: 0.9rem;
  letter-spacing: 0.02em;
  padding: 0.65rem 1.15rem;
  border-radius: 999px;
  box-shadow: 0 10px 30px -8px rgba(0, 0, 0, 0.45);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.25s ease, transform 0.25s ease;
  z-index: 40;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }

/* ---------- Animations ---------- */
@keyframes rise {
  from { opacity: 0; transform: translateY(12px); }
  to { opacity: 1; transform: translateY(0); }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.001ms !important;
    animation-delay: 0ms !important;
    transition-duration: 0.001ms !important;
  }
  .mark, .title, .subtitle, .pane, .slovo { opacity: 1 !important; }
}

@media (max-width: 480px) {
  .app-header { padding-left: 2.6rem; padding-right: 2.6rem; }
  .field { min-height: 150px; }
  .map-grid { grid-template-columns: repeat(auto-fill, minmax(76px, 1fr)); }
}
