/* ========================================================================
   SONOLINK — base.css
   Reset · RTL · Typography · Safe area · Layout primitives
   ======================================================================== */

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

html, body {
  height: 100%;
  width: 100%;
  overflow-x: hidden;
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
}

html {
  font-size: 16px;
  scroll-behavior: smooth;
}

body {
  font-family: 'Tajawal', system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
  font-weight: 400;
  line-height: 1.5;
  color: var(--text);
  background: var(--bg);
  direction: rtl;
  text-align: right;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  overscroll-behavior: contain;
  touch-action: manipulation;
  user-select: none;
  -webkit-user-select: none;
  -webkit-tap-highlight-color: transparent;
  padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
}

/* Inputs are selectable */
input, textarea {
  user-select: text;
  -webkit-user-select: text;
  font-family: inherit;
  color: inherit;
  background: transparent;
  border: none;
  outline: none;
}

button {
  font-family: inherit;
  color: inherit;
  background: none;
  border: none;
  cursor: pointer;
  outline: none;
}

img, svg, canvas { display: block; max-width: 100%; }

a { color: inherit; text-decoration: none; }

/* Mono blocks */
.mono, code, kbd, .pin-display, .id-preview__value, .app-placeholder__id {
  font-family: 'JetBrains Mono', 'Courier New', monospace;
  font-feature-settings: 'liga' 0, 'calt' 0;
  letter-spacing: 0.02em;
}

/* ========== Screen container ========== */

.screen {
  position: fixed;
  inset: 0;
  display: flex;
  flex-direction: column;
  opacity: 0;
  pointer-events: none;
  transition: opacity 280ms ease;
  padding-top: env(safe-area-inset-top);
  padding-bottom: env(safe-area-inset-bottom);
  z-index: 10;
}

.screen.active {
  opacity: 1;
  pointer-events: auto;
}

/* ========== Background layers ========== */

#matrix-bg {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  z-index: 1;
  opacity: 0.35;
  pointer-events: none;
}

.grain-overlay {
  position: fixed;
  inset: 0;
  z-index: 2;
  pointer-events: none;
  opacity: 0.04;
  background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='200' height='200'><filter id='n'><feTurbulence type='fractalNoise' baseFrequency='0.9' numOctaves='2' stitchTiles='stitch'/><feColorMatrix values='0 0 0 0 1 0 0 0 0 1 0 0 0 0 1 0 0 0 0.5 0'/></filter><rect width='100%' height='100%' filter='url(%23n)'/></svg>");
  mix-blend-mode: overlay;
}

.scanlines {
  position: fixed;
  inset: 0;
  z-index: 3;
  pointer-events: none;
  background: repeating-linear-gradient(
    180deg,
    rgba(255, 255, 255, 0) 0,
    rgba(255, 255, 255, 0) 2px,
    rgba(255, 255, 255, 0.015) 3px,
    rgba(255, 255, 255, 0) 4px
  );
  opacity: 0.6;
}

body[data-fx-matrix="off"] #matrix-bg { display: none; }
body[data-fx-scanlines="off"] .scanlines { display: none; }

/* ========== Top bar ========== */

.top-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 14px 18px;
  min-height: 56px;
  background: linear-gradient(180deg, rgba(0, 0, 0, 0.5), rgba(0, 0, 0, 0));
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
}

.top-bar__title {
  display: flex;
  align-items: center;
  gap: 10px;
  font-weight: 700;
  font-size: 1rem;
  color: var(--text);
  flex: 1;
  justify-content: center;
}

.top-bar--app .top-bar__title {
  justify-content: flex-start;
}

.pin-title {
  font-family: 'JetBrains Mono', monospace;
  letter-spacing: 0.2em;
  color: var(--accent);
  font-size: 0.875rem;
}

/* ========== Bottom hint ========== */

.bottom-hint {
  margin-top: auto;
  padding: 16px 24px calc(20px + env(safe-area-inset-bottom));
  text-align: center;
  font-size: 0.75rem;
  color: var(--text-dim);
  letter-spacing: 0.02em;
}

/* ========== Utility ========== */

.hidden { display: none !important; }
.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

.dot {
  display: inline-block;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--text-dim);
}

.dot--live {
  background: var(--accent);
  box-shadow: 0 0 8px var(--accent);
  animation: pulse-dot 1.6s ease-in-out infinite;
}

@keyframes pulse-dot {
  0%, 100% { opacity: 1; transform: scale(1); }
  50% { opacity: 0.5; transform: scale(0.85); }
}

/* ========== Toast ========== */

.toast {
  position: fixed;
  bottom: calc(24px + env(safe-area-inset-bottom));
  left: 50%;
  transform: translateX(-50%) translateY(20px);
  background: var(--surface-2);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 12px 20px;
  border-radius: 12px;
  font-size: 0.875rem;
  font-weight: 500;
  z-index: 1000;
  opacity: 0;
  pointer-events: none;
  transition: opacity 240ms ease, transform 240ms ease;
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.4);
  max-width: 90vw;
}

.toast.show {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

.toast--error { border-color: var(--danger); color: var(--danger); }
.toast--success { border-color: var(--success); color: var(--success); }

/* ========== Boot screen ========== */

#screen-boot { justify-content: center; align-items: center; }

.boot-stack {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 18px;
  padding: 32px;
}

.boot-logo {
  position: relative;
  width: 96px;
  height: 96px;
  margin-bottom: 8px;
}

.boot-logo__ring {
  position: absolute;
  inset: 0;
  border-radius: 50%;
  border: 2px solid var(--accent);
  border-top-color: transparent;
  animation: spin 1.2s linear infinite;
}

.boot-logo__core {
  position: absolute;
  inset: 14px;
  border-radius: 50%;
  background: radial-gradient(circle at 30% 30%, var(--accent-soft), transparent 70%);
  border: 1px solid var(--accent);
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: 'JetBrains Mono', monospace;
  font-size: 1.75rem;
  font-weight: 700;
  color: var(--accent);
  text-shadow: 0 0 12px var(--accent);
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

.boot-title {
  font-family: 'JetBrains Mono', monospace;
  font-size: 2rem;
  font-weight: 700;
  letter-spacing: 0.3em;
  color: var(--text);
}

.boot-subtitle {
  font-family: 'JetBrains Mono', monospace;
  font-size: 0.75rem;
  letter-spacing: 0.2em;
  color: var(--text-dim);
}

.boot-status {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-top: 12px;
  font-size: 0.875rem;
  color: var(--text-dim);
}

.boot-status__dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--accent);
  animation: pulse-dot 1s ease-in-out infinite;
}

/* ---- Boot error overlay (visible recovery UI when init fails) ---- */
.boot-error {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  background: rgba(0, 0, 0, 0.7);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  z-index: 50;
  animation: fadeIn 220ms ease-out;
}

.boot-error__card {
  width: 100%;
  max-width: 420px;
  background: var(--surface-2);
  border: 1px solid var(--border-strong);
  border-radius: 16px;
  padding: 22px 20px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  text-align: center;
}

.boot-error__icon {
  font-size: 2.5rem;
  color: var(--warning, #ffd166);
  line-height: 1;
}

.boot-error__title {
  font-size: 1.0625rem;
  font-weight: 700;
  color: var(--text);
}

.boot-error__detail {
  font-size: 0.875rem;
  color: var(--text-dim);
  line-height: 1.55;
  word-break: break-word;
}

.boot-error__actions {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-top: 6px;
}

.boot-error__hint {
  font-size: 0.75rem;
  color: var(--text-faint);
  line-height: 1.5;
  margin-top: 4px;
}

@keyframes fadeIn {
  from { opacity: 0; }
  to   { opacity: 1; }
}
