/* ═══════════════════════════════════════════════════════════════
   sm-core.css — SenseMake.uk Shared Framework
   Foundation styles, design tokens, header bar, dark mode, toolbar
   ═══════════════════════════════════════════════════════════════ */

/* ── Design Tokens ─────────────────────────────────────────────── */
:root {
  /* Brand */
  --sm-indigo: #4f46e5;
  --sm-indigo-hover: #4338ca;
  --sm-indigo-light: #e0e7ff;

  /* Light mode (default) */
  --sm-bg: #f8fafc;
  --sm-surface: #ffffff;
  --sm-surface-raised: #ffffff;
  --sm-text: #0f172a;
  --sm-text-muted: #64748b;
  --sm-border: #e2e8f0;
  --sm-canvas-bg: #ffffff;

  /* Feedback */
  --sm-correct: #16a34a;
  --sm-correct-bg: #dcfce7;
  --sm-incorrect: #dc2626;
  --sm-incorrect-bg: #fee2e2;
  --sm-highlight: #f59e0b;
  --sm-highlight-bg: #fef3c7;

  /* Layout */
  --sm-header-height: 26px;
  --sm-banner-height: 0px;  /* Set to 26px by .sm-has-banner */
  --sm-top-offset: var(--sm-header-height); /* Total offset: header + banner */
  --sm-font: 'Lexend', system-ui, -apple-system, sans-serif;
  --sm-font-mono: ui-monospace, 'Cascadia Code', 'Fira Code', monospace;

  /* Touch */
  --sm-touch-min: 44px;

  /* Toolbar */
  --sm-toolbar-bg: rgba(15, 23, 42, 0.75);
  --sm-toolbar-bg-hover: rgba(15, 23, 42, 0.95);
  --sm-toolbar-text: #f1f5f9;

  /* Transitions */
  --sm-transition-fast: 0.15s ease;
  --sm-transition: 0.2s ease;
}

/* ── Dark Mode Tokens ──────────────────────────────────────────── */
[data-theme="dark"] {
  --sm-bg: #0f172a;
  --sm-surface: #1e293b;
  --sm-surface-raised: #283548;
  --sm-text: #f1f5f9;
  --sm-text-muted: #94a3b8;
  --sm-border: #334155;
  --sm-canvas-bg: #1e293b;

  --sm-correct-bg: #064e3b;
  --sm-incorrect-bg: #7f1d1d;
  --sm-highlight-bg: #78350f;

  --sm-toolbar-bg: rgba(30, 41, 59, 0.85);
  --sm-toolbar-bg-hover: rgba(30, 41, 59, 0.98);
}

/* Auto dark mode (when no explicit data-theme is set) */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]):not([data-theme="dark"]) {
    --sm-bg: #0f172a;
    --sm-surface: #1e293b;
    --sm-surface-raised: #283548;
    --sm-text: #f1f5f9;
    --sm-text-muted: #94a3b8;
    --sm-border: #334155;
    --sm-canvas-bg: #1e293b;
    --sm-correct-bg: #064e3b;
    --sm-incorrect-bg: #7f1d1d;
    --sm-highlight-bg: #78350f;
    --sm-toolbar-bg: rgba(30, 41, 59, 0.85);
    --sm-toolbar-bg-hover: rgba(30, 41, 59, 0.98);
  }
}

/* ── Reset ─────────────────────────────────────────────────────── */
*, *::before, *::after {
  box-sizing: border-box;
}

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

body {
  margin: 0;
  padding: 0;
  overflow: hidden;
  font-family: var(--sm-font);
  font-size: 14px;
  line-height: 1.5;
  color: var(--sm-text);
  background: var(--sm-bg);
  -webkit-tap-highlight-color: transparent;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

/* ── Header Bar (26px, always dark) ────────────────────────────── */
.sm-header {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  height: var(--sm-header-height);
  background: #000;
  border-bottom: 1px solid #333;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 12px;
  z-index: 1000;
  font-family: var(--sm-font);
  user-select: none;
}

.sm-back {
  display: flex;
  align-items: center;
  gap: 4px;
  text-decoration: none;
  color: #ccc;
  font-size: 11px;
  font-weight: 500;
  transition: color var(--sm-transition-fast);
  min-height: var(--sm-header-height);
  padding: 0 4px;
}
.sm-back:hover { color: #fff; }

.sm-back-icon {
  width: 14px;
  height: 14px;
  stroke: currentColor;
  fill: none;
  stroke-width: 2.5;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.sm-logo {
  font-size: 11px;
  font-weight: 600;
  color: #fff;
  letter-spacing: -0.02em;
  user-select: none;
}
.sm-logo-dot {
  color: #94a3b8;
}

/* Hide header in fullscreen */
:fullscreen .sm-header,
:-webkit-full-screen .sm-header {
  display: none;
}
:fullscreen .sm-app-canvas,
:-webkit-full-screen .sm-app-canvas {
  top: 0;
}

/* ── App Canvas ────────────────────────────────────────────────── */
.sm-app-canvas {
  position: fixed;
  top: var(--sm-top-offset);
  left: 0;
  right: 0;
  bottom: 0;
  background: var(--sm-bg);
  overflow: hidden;
}

/* ── Floating Toolbar ──────────────────────────────────────────── */
.sm-toolbar {
  position: fixed;
  bottom: 14px;
  right: 14px;
  z-index: 900;
  display: flex;
  align-items: center;
  gap: 2px;
  background: var(--sm-toolbar-bg);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  border-radius: 10px;
  padding: 3px;
  opacity: 0.55;
  transition: opacity var(--sm-transition);
  user-select: none;
}
.sm-toolbar:hover,
.sm-toolbar:focus-within,
.sm-toolbar.sm-toolbar-active {
  opacity: 1;
}

.sm-toolbar-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  border: none;
  border-radius: 7px;
  background: transparent;
  color: var(--sm-toolbar-text);
  cursor: pointer;
  padding: 0;
  transition: background var(--sm-transition-fast);
  position: relative;
}
.sm-toolbar-btn:hover {
  background: rgba(255, 255, 255, 0.15);
}
.sm-toolbar-btn:active {
  background: rgba(255, 255, 255, 0.25);
}
.sm-toolbar-btn:focus-visible {
  outline: 2px solid var(--sm-indigo);
  outline-offset: 1px;
}
.sm-toolbar-btn[disabled] {
  opacity: 0.3;
  cursor: default;
  pointer-events: none;
}

.sm-toolbar-sep {
  width: 1px;
  height: 18px;
  background: rgba(255, 255, 255, 0.2);
  margin: 0 2px;
}

/* Toolbar icon sizing */
.sm-toolbar-btn .sm-icon {
  width: 16px;
  height: 16px;
}

/* Tooltip */
.sm-toolbar-btn::after {
  content: attr(aria-label);
  position: absolute;
  bottom: calc(100% + 6px);
  left: 50%;
  transform: translateX(-50%);
  padding: 3px 8px;
  background: #0f172a;
  color: #f1f5f9;
  font-size: 10px;
  font-weight: 500;
  white-space: nowrap;
  border-radius: 4px;
  opacity: 0;
  pointer-events: none;
  transition: opacity var(--sm-transition-fast);
}
.sm-toolbar-btn:hover::after {
  opacity: 1;
}
/* Hide tooltips on touch devices */
@media (hover: none) {
  .sm-toolbar-btn::after { display: none; }
}

/* Small screens: shrink toolbar slightly */
@media (max-width: 480px) {
  .sm-toolbar {
    bottom: 8px;
    right: 8px;
    padding: 2px;
  }
  .sm-toolbar-btn {
    width: 36px;
    height: 36px;
  }
}

/* ── Fullscreen exit pill (shown inside fullscreen) ────────────── */
.sm-fs-exit {
  display: none;
}
:fullscreen .sm-fs-exit,
:-webkit-full-screen .sm-fs-exit {
  display: flex;
  position: fixed;
  top: 8px;
  right: 8px;
  z-index: 1001;
  align-items: center;
  gap: 4px;
  padding: 4px 10px;
  background: rgba(0, 0, 0, 0.7);
  color: #fff;
  border: none;
  border-radius: 6px;
  font-family: var(--sm-font);
  font-size: 10px;
  font-weight: 600;
  cursor: pointer;
  opacity: 0;
  transition: opacity 0.3s ease;
}
:fullscreen .sm-fs-exit:hover,
:-webkit-full-screen .sm-fs-exit:hover,
:fullscreen .sm-fs-exit:focus,
:-webkit-full-screen .sm-fs-exit:focus {
  opacity: 1;
}
/* Show briefly on fullscreen entry, then fade */
:fullscreen .sm-fs-exit.sm-fs-exit-flash,
:-webkit-full-screen .sm-fs-exit.sm-fs-exit-flash {
  opacity: 1;
}

/* ── Shared Banner (for locked/shared mode) ────────────────────── */
.sm-banner {
  display: none;
  position: fixed;
  top: var(--sm-header-height);
  left: 0;
  right: 0;
  z-index: 800;
  background: var(--sm-highlight-bg);
  color: var(--sm-text);
  text-align: center;
  font-size: 11px;
  font-weight: 600;
  padding: 4px 12px;
  border-bottom: 1px solid var(--sm-border);
}
.sm-banner.visible {
  display: block;
}

/* When banner is visible, increase top offset for everything */
.sm-has-banner {
  --sm-banner-height: 26px;
  --sm-top-offset: calc(var(--sm-header-height) + var(--sm-banner-height));
}

/* ── Icon base ─────────────────────────────────────────────────── */
.sm-icon {
  width: 20px;
  height: 20px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.5;
  stroke-linecap: round;
  stroke-linejoin: round;
  display: inline-block;
  vertical-align: middle;
  flex-shrink: 0;
}

/* ── Utility classes ───────────────────────────────────────────── */
.sm-visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

/* Theme transition (applied after initial load to prevent flash) */
.sm-theme-transition,
.sm-theme-transition *,
.sm-theme-transition *::before,
.sm-theme-transition *::after {
  transition: background-color 0.2s ease, color 0.2s ease, border-color 0.2s ease !important;
}
