:root {
  --bg: #101018;
  --text: #fff;
  --text-muted: rgba(255, 255, 255, 0.72);
  --surface: rgba(12, 12, 22, 0.78);
  --surface-strong: rgba(12, 12, 22, 0.94);
  --border: rgba(255, 255, 255, 0.14);
  --accent: #f2c76b;
  --accent-strong: #e0a93a;
  --on-accent: #1c1405;
  --radius: 14px;
  --font: "Noto Sans", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --safe-top: env(safe-area-inset-top, 0px);
  color-scheme: dark;
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
body {
  margin: 0;
  background: var(--bg) center / cover no-repeat;
  color: var(--text);
  font-family: var(--font);
  -webkit-tap-highlight-color: transparent;
}
canvas { display: block; }

#container {
  position: fixed;
  z-index: 1;
  inset: 0;
  height: 100dvh;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto;
  justify-items: center;
  align-items: center;
  gap: 16px;
  padding: calc(24px + var(--safe-top)) 16px calc(16px + var(--safe-bottom));
}

#title {
  margin: 16px 0 0;
  font-size: clamp(1.75rem, 6vw, 3rem);
  font-weight: 700;
  line-height: 1.1;
  text-align: center;
  text-shadow: 0 2px 12px rgba(0, 0, 0, 0.6);
  text-wrap: balance;
}
#date {
  display: block;
  margin-top: 6px;
  font-size: 0.5em;
  font-weight: 400;
  color: var(--text-muted);
  letter-spacing: 0.02em;
}

/* The reading is a scrollable glass card that never pushes the controls off-screen. */
#prediction-text {
  align-self: stretch;
  justify-self: center;
  width: min(100%, 720px);
  max-height: 100%;
  min-height: 0;
  overflow-y: auto;
  overscroll-behavior: contain;
  padding: 16px 18px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  -webkit-backdrop-filter: blur(8px);
  backdrop-filter: blur(8px);
  font-size: 1.05rem;
  line-height: 1.55;
  text-wrap: pretty;
  transition: opacity 0.4s ease, transform 0.4s ease, visibility 0.4s;
  scrollbar-width: thin;
  scrollbar-color: rgba(255, 255, 255, 0.5) transparent;
}
#prediction-text:empty { display: none; }
#prediction-text.is-hidden { opacity: 0; transform: translateY(8px); visibility: hidden; pointer-events: none; }
#prediction-text strong { color: var(--accent); font-weight: 600; }
#prediction-text:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

#card-info {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  width: min(100%, 360px);
  text-align: center;
}

#card-name {
  display: inline-flex;
  align-items: center;
  gap: 12px;
  min-height: 44px;
  padding: 0 12px;
  border: none;
  border-radius: 999px;
  background: none;
  color: var(--text);
  font: 600 2rem/1.1 var(--font);
  text-shadow: 0 2px 12px rgba(0, 0, 0, 0.6);
  cursor: default;
}
#card-name:empty { display: none; }
#card-name:disabled { opacity: 1; cursor: default; }
/* After the reveal the rune name toggles the reading, so it gets a visible affordance. */
#card-name:not(:disabled) { cursor: pointer; }
#card-name:not(:disabled)::after {
  content: "";
  width: 10px;
  height: 10px;
  margin-top: -4px;
  border: solid currentColor;
  border-width: 0 2px 2px 0;
  transform: rotate(-135deg);
  transition: transform 0.2s ease;
}
#card-name[aria-expanded="false"]::after { transform: rotate(45deg); margin-top: -10px; }
#card-name:not(:disabled):hover { background: rgba(0, 0, 0, 0.25); }

.button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  min-height: 48px;
  padding: 10px 20px;
  border: 1px solid transparent;
  border-radius: 12px;
  font: 600 1.05rem/1.2 var(--font);
  text-align: center;
  text-decoration: none;
  cursor: pointer;
  transition: background-color 0.15s ease, transform 0.1s ease, opacity 0.15s ease;
}
.button:active:not(:disabled) { transform: scale(0.98); }
.button:disabled { cursor: progress; opacity: 0.6; }
.button-primary {
  background: linear-gradient(180deg, var(--accent), var(--accent-strong));
  color: var(--on-accent);
  box-shadow: 0 6px 18px rgba(224, 169, 58, 0.3);
}
.button-primary:hover:not(:disabled) { background: var(--accent); }
.button-secondary {
  background: var(--surface);
  border-color: var(--border);
  color: var(--text);
  -webkit-backdrop-filter: blur(8px);
  backdrop-filter: blur(8px);
}
.button-secondary:hover:not(:disabled) { background: var(--surface-strong); }
button:focus-visible, a:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
#show-prediction { min-height: 52px; font-size: 1.15rem; }
#show-prediction[aria-busy="true"] { cursor: progress; }

#sharing_buttons {
  display: flex;
  flex-direction: column;
  gap: 10px;
  width: 100%;
}

#load-status {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  margin: 0;
  padding: 10px 14px;
  border-radius: 12px;
  background: var(--surface);
  line-height: 1.4;
}
#load-status[role="alert"] { border: 1px solid rgba(255, 120, 120, 0.5); }
#load-status.is-loading::before {
  content: "";
  flex: none;
  width: 16px;
  height: 16px;
  border: 2px solid rgba(255, 255, 255, 0.3);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

#rune-fallback {
  position: fixed;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  max-width: 70vw;
  max-height: 50vh;
  object-fit: contain;
  filter: drop-shadow(0 0 24px rgba(242, 199, 107, 0.35));
}

.burger-button {
  position: fixed;
  z-index: 30;
  left: 16px;
  bottom: calc(16px + var(--safe-bottom));
  display: grid;
  place-items: center;
  width: 52px;
  height: 52px;
  padding: 0;
  border: 1px solid var(--border);
  border-radius: 50%;
  background: var(--surface);
  color: var(--text);
  -webkit-backdrop-filter: blur(8px);
  backdrop-filter: blur(8px);
  cursor: pointer;
}
.burger-button:hover { background: var(--surface-strong); }
/* The dialog has its own close button, so the toggle steps aside instead of overlapping it. */
body.modal-open .burger-button { visibility: hidden; }
body.modal-open { overflow: hidden; }

.modal {
  position: fixed;
  z-index: 20;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: calc(16px + var(--safe-top)) 16px calc(16px + var(--safe-bottom));
  background: rgba(0, 0, 0, 0.6);
  -webkit-backdrop-filter: blur(6px);
  backdrop-filter: blur(6px);
  animation: fade-in 0.2s ease;
}
.modal-content {
  display: flex;
  flex-direction: column;
  gap: 12px;
  width: min(100%, 520px);
  max-height: 100%;
  overflow-y: auto;
  overscroll-behavior: contain;
  padding: 8px 16px 16px;
  border: 1px solid var(--border);
  border-radius: 18px;
  background: var(--surface-strong);
  animation: rise 0.25s ease;
}
@keyframes fade-in { from { opacity: 0; } }
@keyframes rise { from { transform: translateY(16px); opacity: 0; } }
.modal-header {
  position: sticky;
  top: -8px;
  z-index: 1;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin: -8px -16px 0;
  padding: 8px 8px 8px 16px;
  background: var(--surface-strong);
}
.modal-header h2 { margin: 0; font-size: 1.2rem; font-weight: 600; }
.icon-button {
  display: grid;
  place-items: center;
  flex: none;
  width: 44px;
  height: 44px;
  padding: 0;
  border: none;
  border-radius: 50%;
  background: transparent;
  color: var(--text-muted);
  cursor: pointer;
}
.icon-button:hover { background: rgba(255, 255, 255, 0.08); color: var(--text); }

.apps-list { display: flex; flex-direction: column; gap: 4px; margin: 0; padding: 0; list-style: none; }
.app-row {
  display: flex;
  align-items: center;
  gap: 12px;
  min-height: 64px;
  padding: 8px;
  border-radius: 12px;
  color: var(--text);
  text-decoration: none;
}
.app-row:hover { background: rgba(255, 255, 255, 0.06); }
.app-row img { flex: none; width: 52px; height: 52px; border-radius: 12px; object-fit: cover; background: rgba(255, 255, 255, 0.06); }
.app-row span { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.app-row strong { font-size: 1rem; font-weight: 600; }
.app-row small { color: var(--text-muted); font-size: 0.85rem; line-height: 1.35; }
#vk_group_link { border: 1px solid var(--border); background: rgba(242, 199, 107, 0.08); }

#additional_options { display: flex; flex-direction: column; gap: 8px; padding-top: 4px; }
#recommendApp.hidden, #favouritesApp.hidden { display: none; }

@media (max-width: 600px) {
  /* Reserve the corner used by the menu button so it never covers an action. */
  #container { padding-bottom: calc(80px + var(--safe-bottom)); gap: 12px; }
  #title { margin-top: 8px; }
  #card-name { font-size: 1.6rem; }
  #prediction-text { font-size: 1rem; padding: 14px 16px; }
}
@media (max-height: 640px) {
  #title { font-size: 1.5rem; margin-top: 0; }
  #card-name { font-size: 1.4rem; min-height: 40px; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: 0.01ms !important; animation-iteration-count: 1 !important; transition-duration: 0.01ms !important; }
}
