/* LIFE — base styles, fonts and shared controls */

@font-face {
  font-family: "Cormorant Garamond";
  src: url("../assets/fonts/cormorant-garamond-latin-400-normal.woff2") format("woff2");
  font-weight: 400;
  font-style: normal;
  font-display: swap;
}
@font-face {
  font-family: "Cormorant Garamond";
  src: url("../assets/fonts/cormorant-garamond-latin-500-normal.woff2") format("woff2");
  font-weight: 500;
  font-style: normal;
  font-display: swap;
}
@font-face {
  font-family: "Cormorant Garamond";
  src: url("../assets/fonts/cormorant-garamond-latin-600-normal.woff2") format("woff2");
  font-weight: 600;
  font-style: normal;
  font-display: swap;
}
@font-face {
  font-family: "Cormorant Garamond";
  src: url("../assets/fonts/cormorant-garamond-latin-500-italic.woff2") format("woff2");
  font-weight: 500;
  font-style: italic;
  font-display: swap;
}
@font-face {
  font-family: "EB Garamond";
  src: url("../assets/fonts/eb-garamond-latin-400-normal.woff2") format("woff2");
  font-weight: 400;
  font-style: normal;
  font-display: swap;
}
@font-face {
  font-family: "EB Garamond";
  src: url("../assets/fonts/eb-garamond-latin-500-normal.woff2") format("woff2");
  font-weight: 500;
  font-style: normal;
  font-display: swap;
}
@font-face {
  font-family: "EB Garamond";
  src: url("../assets/fonts/eb-garamond-latin-400-italic.woff2") format("woff2");
  font-weight: 400;
  font-style: italic;
  font-display: swap;
}

:root {
  color-scheme: dark;

  --ink: #0b1119;
  --ink-2: #111a25;
  --glass: rgba(16, 24, 34, 0.62);
  --glass-strong: rgba(14, 21, 30, 0.82);
  --line: rgba(255, 240, 215, 0.16);
  --line-strong: rgba(255, 236, 205, 0.42);
  --text: #f7f2e9;
  --muted: #b9c2cc;
  --faint: #8a97a5;
  --gold: #e9d3a4;
  --gold-2: #c9a76a;
  --gold-glow: rgba(255, 205, 130, 0.45);
  --danger: #ffb4b4;

  --serif-display: "Cormorant Garamond", "Iowan Old Style", Georgia, serif;
  --serif-text: "EB Garamond", "Iowan Old Style", Georgia, serif;
  --sans: -apple-system, BlinkMacSystemFont, "Segoe UI", system-ui, sans-serif;

  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --safe-left: env(safe-area-inset-left, 0px);
  --safe-right: env(safe-area-inset-right, 0px);

  --story-size: 19px;

  background: var(--ink);
  color: var(--text);
  font-family: var(--sans);
  -webkit-text-size-adjust: 100%;
  -webkit-tap-highlight-color: transparent;
}

body[data-text-size="small"] { --story-size: 17px; }
body[data-text-size="large"] { --story-size: 22px; }

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  min-height: 100%;
}

body {
  min-height: 100vh;
  min-height: 100dvh;
  background:
    radial-gradient(ellipse at 50% -10%, #223246 0, transparent 55%),
    var(--ink);
  overscroll-behavior-y: none;
}

button,
textarea,
input,
select {
  font: inherit;
  color: inherit;
}

/* ---------- Buttons ---------- */

button {
  border: 1px solid var(--line-strong);
  border-radius: 12px;
  padding: 12px 20px;
  min-height: 46px;
  background: linear-gradient(180deg, rgba(70, 70, 72, 0.55), rgba(28, 30, 34, 0.7));
  color: var(--text);
  font-family: var(--serif-display);
  font-size: 19px;
  font-weight: 500;
  letter-spacing: 0.04em;
  cursor: pointer;
  transition:
    border-color 0.2s,
    box-shadow 0.25s,
    background 0.2s,
    transform 0.15s,
    opacity 0.2s;
  touch-action: manipulation;
}

button:hover:not(:disabled) {
  border-color: rgba(255, 236, 205, 0.8);
  box-shadow: 0 0 22px rgba(255, 205, 130, 0.22);
}

button:active:not(:disabled) {
  transform: scale(0.985);
}

button:focus-visible {
  outline: none;
  border-color: var(--gold);
  box-shadow: 0 0 0 2px rgba(233, 211, 164, 0.5), 0 0 22px var(--gold-glow);
}

button:disabled {
  opacity: 0.42;
  cursor: not-allowed;
}

button.gold {
  background: linear-gradient(180deg, #f3e2bd, #d8bb83);
  border-color: #f6e7c6;
  color: #201a12;
  font-weight: 600;
}

button.gold:hover:not(:disabled) {
  background: linear-gradient(180deg, #f8ebcd, #e0c48f);
}

button.ghost {
  background: rgba(20, 26, 34, 0.55);
}

button.danger {
  background: rgba(80, 30, 36, 0.55);
  border-color: rgba(255, 180, 180, 0.35);
  color: #ffdcdc;
}

button.small {
  min-height: 40px;
  padding: 8px 15px;
  font-size: 17px;
}

/* ---------- Inputs ---------- */

textarea,
input[type="text"],
select {
  width: 100%;
  border-radius: 12px;
  background: rgba(8, 13, 19, 0.7);
  color: var(--text);
  border: 1px solid var(--line);
  padding: 14px 16px;
  outline: none;
  font-family: var(--serif-text);
  font-size: 18px;
  transition: border-color 0.2s, box-shadow 0.2s;
}

/* iOS zooms into inputs under 16px; keep them at 16px+. */
select {
  width: auto;
  min-width: 128px;
  padding: 10px 14px;
  font-family: var(--serif-display);
  font-size: 18px;
}

textarea:focus,
input:focus,
select:focus {
  border-color: rgba(233, 211, 164, 0.7);
  box-shadow: 0 0 0 3px rgba(233, 211, 164, 0.12);
}

textarea {
  min-height: 110px;
  resize: vertical;
  line-height: 1.5;
}

::placeholder {
  color: #7d8996;
  opacity: 1;
}

/* ---------- Utilities ---------- */

.hidden {
  display: none !important;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
}

.stack {
  display: grid;
  gap: 14px;
}

.row {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  align-items: center;
}

.center-row {
  justify-content: center;
  margin-top: 22px;
}

.center-text {
  text-align: center;
}

.muted {
  color: var(--muted);
}

.kicker {
  text-transform: uppercase;
  letter-spacing: 0.32em;
  color: var(--gold);
  font-family: var(--serif-display);
  font-size: 13px;
  font-weight: 600;
}

.title {
  font-family: var(--serif-display);
  font-weight: 500;
  font-size: clamp(30px, 6vw, 42px);
  letter-spacing: 0.01em;
  line-height: 1.1;
  margin: 8px 0 18px;
}

/* ---------- Notice toast ---------- */

#notice {
  position: fixed;
  left: 50%;
  bottom: calc(18px + var(--safe-bottom));
  transform: translate(-50%, 20px);
  max-width: min(560px, calc(100vw - 32px));
  padding: 12px 18px;
  border-radius: 12px;
  background: var(--glass-strong);
  border: 1px solid var(--line-strong);
  color: var(--gold);
  font-family: var(--serif-display);
  font-size: 18px;
  text-align: center;
  white-space: pre-wrap;
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  box-shadow: 0 12px 40px rgba(0, 0, 0, 0.45);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.3s, transform 0.3s;
  z-index: 60;
}

#notice.show {
  opacity: 1;
  transform: translate(-50%, 0);
}

/* While the game screen is busy the compose box sits at the bottom,
   so lift the toast above it. */
body[data-screen="game"] #notice {
  top: calc(14px + var(--safe-top));
  bottom: auto;
  transform: translate(-50%, -20px);
}

body[data-screen="game"] #notice.show {
  transform: translate(-50%, 0);
}

.modal-note {
  margin: 0 0 6px;
  font-family: var(--serif-text);
  font-size: 17px;
  line-height: 1.5;
  color: var(--muted);
  text-align: center;
}

/* ---------- Busy veil (menus) ---------- */

.veil {
  position: fixed;
  inset: 0;
  display: grid;
  place-items: center;
  background: radial-gradient(ellipse at center, rgba(8, 12, 18, 0.72), rgba(4, 6, 10, 0.92));
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.5s;
  z-index: 50;
}

body.is-busy:not([data-screen="game"]):not([data-screen="book"]) .veil {
  opacity: 1;
  pointer-events: auto;
}

body.is-busy:not([data-screen="game"]):not([data-screen="book"]) #notice {
  opacity: 0;
}

.veil-inner {
  text-align: center;
}

.veil-mark {
  font-family: var(--serif-display);
  font-size: 64px;
  font-weight: 400;
  letter-spacing: 0.42em;
  margin-right: -0.42em;
  background: linear-gradient(180deg, #fff8ea, #d9b97f);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}

.veil-line {
  width: 180px;
  height: 1px;
  margin: 10px auto 18px;
  background: linear-gradient(90deg, transparent, var(--gold), transparent);
  animation: shimmer 2.2s ease-in-out infinite;
}

.veil-text {
  font-family: var(--serif-display);
  font-style: italic;
  font-size: 22px;
  color: var(--muted);
  animation: breathe 2.6s ease-in-out infinite;
}

@keyframes shimmer {
  0%, 100% { opacity: 0.35; transform: scaleX(0.6); }
  50% { opacity: 1; transform: scaleX(1); }
}

@keyframes breathe {
  0%, 100% { opacity: 0.6; }
  50% { opacity: 1; }
}

/* ---------- Modal ---------- */

.modalcover {
  position: fixed;
  inset: 0;
  background: rgba(3, 8, 14, 0.72);
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
  display: grid;
  place-items: center;
  z-index: 40;
  padding: 20px;
}

.modal {
  background: var(--glass-strong);
  border: 1px solid var(--line-strong);
  border-radius: 20px;
  padding: 24px;
  width: min(400px, 100%);
  box-shadow: 0 30px 80px rgba(0, 0, 0, 0.55);
}

.modal h2 {
  font-family: var(--serif-display);
  font-weight: 500;
  font-size: 30px;
  text-align: center;
  margin: 0 0 16px;
  letter-spacing: 0.08em;
}

.modal .stack {
  gap: 9px;
  margin-bottom: 9px;
}

.modal button {
  width: 100%;
}

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