/* ========================================
   DoodleCraft — Design System
   ======================================== */

/* Google Fonts */
@import url('https://fonts.googleapis.com/css2?family=Cinzel:wght@400;600;700&family=Playfair+Display:ital,wght@0,400;0,600;1,400&family=Caveat:wght@400;500;600;700&family=Henny+Penny&display=swap');

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

/* ── CSS Custom Properties ── */
:root {
  /* Colors - Light Mode */
  --primary: #740001; /* Gryffindor Red */
  --primary-hover: #5c0000;
  --primary-light: #AE0001;
  --secondary: #1A472A; /* Slytherin Green */
  --secondary-hover: #11321d;
  --secondary-light: #2a623d;
  --accent-blue: #0E1A40; /* Ravenclaw Blue */
  --accent-blue-hover: #0a1330;
  --accent-yellow: #D3A625; /* Gold */
  --accent-green: #2a623d;
  --accent-orange: #ECB939; /* Hufflepuff */
  --accent-red: #740001;

  --bg-primary: #f4ecd8; /* Parchment */
  --bg-secondary: #eaddc5;
  --bg-tertiary: #dfcdb0;
  --bg-card: #f9f5eb;
  --bg-card-hover: #f1e6d0;
  --bg-canvas: #f9f5eb;
  --bg-toolbar: #f4ecd8;
  --bg-overlay: rgba(20, 15, 10, 0.7);
  --bg-nav: rgba(244, 236, 216, 0.9);

  --text-primary: #1a1510; /* Ink */
  --text-secondary: #4a3e30;
  --text-muted: #7d6e5a;
  --text-inverse: #f4ecd8;

  --border: #d0c0a8;
  --border-light: #dfcdb0;
  --border-focus: var(--accent-yellow);

  --shadow-xs: 0 1px 2px rgba(45,45,58,0.05);
  --shadow-sm: 0 2px 8px rgba(45,45,58,0.08);
  --shadow-md: 0 4px 16px rgba(45,45,58,0.10);
  --shadow-lg: 0 8px 32px rgba(45,45,58,0.14);
  --shadow-xl: 0 16px 48px rgba(45,45,58,0.18);

  /* Spacing */
  --space-2xs: 2px;
  --space-xs: 4px;
  --space-sm: 8px;
  --space-md: 16px;
  --space-lg: 24px;
  --space-xl: 32px;
  --space-2xl: 48px;
  --space-3xl: 64px;
  --space-4xl: 96px;

  /* Radius */
  --radius-xs: 4px;
  --radius-sm: 8px;
  --radius-md: 12px;
  --radius-lg: 16px;
  --radius-xl: 24px;
  --radius-2xl: 32px;
  --radius-full: 9999px;

  /* Transitions */
  --ease-out: cubic-bezier(0.16, 1, 0.3, 1);
  --ease-in-out: cubic-bezier(0.65, 0, 0.35, 1);
  --transition-fast: 150ms var(--ease-out);
  --transition: 250ms var(--ease-out);
  --transition-slow: 400ms var(--ease-out);

  /* Fonts */
  --font-display: 'Cinzel', serif;
  --font-body: 'Playfair Display', serif;
  --font-handwritten: 'Caveat', cursive;
  --font-doodle: 'Henny Penny', cursive;

  /* Layout */
  --nav-height: 64px;
  --toolbar-width: 64px;
  --panel-width: 280px;
  --topbar-height: 52px;
  --max-width: 1280px;
}

/* ── Dark Mode ── */
body.dark-mode {
  --bg-primary: #0b0c10;
  --bg-secondary: #13151c;
  --bg-tertiary: #1c1f28;
  --bg-card: #151821;
  --bg-card-hover: #1e222e;
  --bg-canvas: #151821;
  --bg-toolbar: #101218;
  --bg-overlay: rgba(0, 0, 0, 0.8);
  --bg-nav: rgba(11, 12, 16, 0.9);

  --text-primary: #e6dfd5;
  --text-secondary: #a39c90;
  --text-muted: #756f66;
  --text-inverse: #0b0c10;

  --border: #2c3140;
  --border-light: #1f232e;
  --border-focus: var(--accent-yellow);

  --shadow-xs: 0 1px 2px rgba(0,0,0,0.5);
  --shadow-sm: 0 2px 8px rgba(0,0,0,0.6);
  --shadow-md: 0 4px 16px rgba(0,0,0,0.7);
  --shadow-lg: 0 8px 32px rgba(0,0,0,0.8);
  --shadow-xl: 0 16px 48px rgba(0,0,0,0.9);
}

/* ── Base ── */
html {
  font-size: 16px;
  scroll-behavior: smooth;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

body {
  font-family: var(--font-body);
  font-weight: 400;
  color: var(--text-primary);
  background: var(--bg-primary);
  line-height: 1.6;
  min-height: 100vh;
  overflow-x: hidden;
  transition: background var(--transition-slow), color var(--transition-slow);
}

a {
  color: var(--primary);
  text-decoration: none;
  transition: color var(--transition-fast);
}
a:hover { color: var(--primary-hover); }

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

h1, h2, h3, h4 {
  font-family: var(--font-display);
  font-weight: 400;
  line-height: 1.2;
  color: var(--text-primary);
}

h1 { font-size: clamp(2rem, 5vw, 3.5rem); }
h2 { font-size: clamp(1.5rem, 3vw, 2.25rem); }
h3 { font-size: clamp(1.125rem, 2vw, 1.5rem); }
h4 { font-size: 1.125rem; }

p { color: var(--text-secondary); }

::selection {
  background: var(--primary-light);
  color: var(--text-primary);
}

/* Scrollbar */
::-webkit-scrollbar { width: 8px; height: 8px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb {
  background: var(--border);
  border-radius: var(--radius-full);
}
::-webkit-scrollbar-thumb:hover { background: var(--text-muted); }

/* ── Navigation ── */
.main-nav {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  height: var(--nav-height);
  background: var(--bg-nav);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  border-bottom: 1px solid var(--border-light);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 var(--space-lg);
  z-index: 1000;
  transition: background var(--transition-slow), border-color var(--transition-slow);
}

.nav-brand {
  display: flex;
  align-items: center;
  gap: var(--space-sm);
  cursor: pointer;
  user-select: none;
}

.nav-logo {
  font-size: 1.75rem;
  animation: wiggle 3s ease-in-out infinite;
}

.nav-title {
  font-family: var(--font-display);
  font-size: 1.35rem;
  background: linear-gradient(135deg, var(--primary), var(--secondary));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

.nav-links {
  display: flex;
  align-items: center;
  gap: var(--space-xs);
}

.nav-link {
  font-family: var(--font-body);
  font-weight: 700;
  font-size: 0.95rem;
  color: var(--text-secondary);
  padding: var(--space-sm) var(--space-md);
  border-radius: var(--radius-md);
  transition: all var(--transition-fast);
  position: relative;
}

.nav-link:hover {
  color: var(--text-primary);
  background: var(--bg-tertiary);
}

.nav-link.active {
  color: var(--primary);
  background: var(--primary-light);
}

.nav-link.active::after {
  content: '';
  position: absolute;
  bottom: -1px;
  left: 50%;
  transform: translateX(-50%);
  width: 20px;
  height: 3px;
  background: var(--primary);
  border-radius: var(--radius-full);
}

.nav-actions {
  display: flex;
  align-items: center;
  gap: var(--space-sm);
}

/* ── Buttons ── */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-sm);
  font-family: var(--font-body);
  font-weight: 700;
  font-size: 0.95rem;
  padding: 10px 20px;
  border: 2px solid transparent;
  border-radius: var(--radius-lg);
  cursor: pointer;
  transition: all var(--transition);
  user-select: none;
  white-space: nowrap;
  text-decoration: none;
  position: relative;
  overflow: hidden;
}

.btn::after {
  content: '';
  position: absolute;
  inset: 0;
  background: linear-gradient(135deg, rgba(255,255,255,0.2), transparent);
  opacity: 0;
  transition: opacity var(--transition-fast);
}

.btn:hover::after { opacity: 1; }

.btn:active { transform: scale(0.96); }

.btn-primary {
  background: linear-gradient(135deg, var(--primary), var(--secondary));
  color: white;
  box-shadow: 0 4px 16px rgba(255, 107, 157, 0.3);
}
.btn-primary:hover {
  box-shadow: 0 6px 24px rgba(255, 107, 157, 0.45);
  transform: translateY(-2px);
}

.btn-secondary {
  background: var(--bg-card);
  color: var(--text-primary);
  border-color: var(--border);
}
.btn-secondary:hover {
  border-color: var(--primary);
  background: var(--bg-card-hover);
}

.btn-ghost {
  background: transparent;
  color: var(--text-secondary);
}
.btn-ghost:hover {
  background: var(--bg-tertiary);
  color: var(--text-primary);
}

.btn-icon {
  width: 40px;
  height: 40px;
  padding: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: var(--bg-card);
  border: 1.5px solid var(--border);
  border-radius: var(--radius-md);
  color: var(--text-secondary);
  font-size: 1.2rem;
  cursor: pointer;
  transition: all var(--transition-fast);
}
.btn-icon:hover {
  color: var(--text-primary);
  border-color: var(--primary);
  background: var(--primary-light);
  transform: scale(1.05);
}

.btn-lg {
  padding: 14px 32px;
  font-size: 1.1rem;
  border-radius: var(--radius-xl);
}

.btn-sm {
  padding: 6px 14px;
  font-size: 0.85rem;
  border-radius: var(--radius-sm);
}

/* ── Cards ── */
.card {
  background: var(--bg-card);
  border: 1.5px solid var(--border-light);
  border-radius: var(--radius-lg);
  padding: var(--space-lg);
  box-shadow: var(--shadow-sm);
  transition: all var(--transition);
}
.card:hover {
  box-shadow: var(--shadow-md);
  border-color: var(--border);
  transform: translateY(-2px);
}

/* ── Inputs ── */
input[type="text"],
input[type="email"],
input[type="password"],
textarea {
  font-family: var(--font-body);
  font-size: 0.95rem;
  color: var(--text-primary);
  background: var(--bg-card);
  border: 1.5px solid var(--border);
  border-radius: var(--radius-md);
  padding: 10px 14px;
  width: 100%;
  transition: all var(--transition-fast);
  outline: none;
}
input:focus, textarea:focus {
  border-color: var(--border-focus);
  box-shadow: 0 0 0 3px var(--primary-light);
}

input::placeholder, textarea::placeholder {
  color: var(--text-muted);
}

/* ── Range Slider ── */
input[type="range"] {
  -webkit-appearance: none;
  appearance: none;
  width: 100%;
  height: 6px;
  background: var(--border);
  border-radius: var(--radius-full);
  outline: none;
  cursor: pointer;
}
input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: var(--primary);
  border: 2px solid white;
  box-shadow: var(--shadow-sm);
  cursor: pointer;
  transition: transform var(--transition-fast);
}
input[type="range"]::-webkit-slider-thumb:hover {
  transform: scale(1.2);
}

/* ── Page System ── */
.page {
  display: none;
  min-height: calc(100vh - var(--nav-height));
  padding-top: var(--nav-height);
  animation: fadeIn 0.3s var(--ease-out);
}
.page.active {
  display: block;
}

#page-editor.active {
  display: flex;
}

/* ── Modal ── */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: var(--bg-overlay);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  z-index: 2000;
  display: none;
  align-items: center;
  justify-content: center;
  padding: var(--space-lg);
  animation: fadeIn 0.2s var(--ease-out);
}
.modal-overlay.active {
  display: flex;
}

.modal {
  background: var(--bg-card);
  border-radius: var(--radius-xl);
  padding: var(--space-2xl);
  max-width: 600px;
  width: 100%;
  max-height: 85vh;
  overflow-y: auto;
  box-shadow: var(--shadow-xl);
  position: relative;
  animation: scaleIn 0.3s var(--ease-out);
}

.modal-close {
  position: absolute;
  top: var(--space-md);
  right: var(--space-md);
  width: 36px;
  height: 36px;
  border: none;
  background: var(--bg-tertiary);
  border-radius: var(--radius-full);
  font-size: 1.3rem;
  color: var(--text-secondary);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all var(--transition-fast);
}
.modal-close:hover {
  background: var(--accent-red);
  color: white;
}

/* ── Toast ── */
.toast-container {
  position: fixed;
  bottom: var(--space-lg);
  right: var(--space-lg);
  z-index: 3000;
  display: flex;
  flex-direction: column;
  gap: var(--space-sm);
}

.toast {
  display: flex;
  align-items: center;
  gap: var(--space-sm);
  padding: var(--space-md) var(--space-lg);
  background: var(--bg-card);
  border: 1.5px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  font-family: var(--font-body);
  font-weight: 700;
  font-size: 0.9rem;
  color: var(--text-primary);
  animation: slideInRight 0.4s var(--ease-out);
  min-width: 250px;
}

.toast.toast-success { border-left: 4px solid var(--accent-green); }
.toast.toast-error { border-left: 4px solid var(--accent-red); }
.toast.toast-info { border-left: 4px solid var(--accent-blue); }

.toast.removing {
  animation: slideOutRight 0.3s var(--ease-out) forwards;
}

/* ── Gradient Text ── */
.text-gradient {
  background: linear-gradient(135deg, var(--primary), var(--secondary), var(--accent-blue));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

/* ── Separator ── */
.separator {
  width: 1px;
  height: 24px;
  background: var(--border);
  margin: 0 var(--space-xs);
}

.separator-h {
  height: 1px;
  background: var(--border);
  margin: var(--space-md) 0;
}

/* ── Tooltips ── */
[data-tooltip] {
  position: relative;
}
[data-tooltip]::before {
  content: attr(data-tooltip);
  position: absolute;
  bottom: calc(100% + 8px);
  left: 50%;
  transform: translateX(-50%) scale(0.85);
  padding: 4px 10px;
  background: var(--text-primary);
  color: var(--bg-primary);
  font-family: var(--font-body);
  font-size: 0.75rem;
  font-weight: 700;
  border-radius: var(--radius-sm);
  white-space: nowrap;
  pointer-events: none;
  opacity: 0;
  transition: all var(--transition-fast);
  z-index: 100;
}
[data-tooltip]:hover::before {
  opacity: 1;
  transform: translateX(-50%) scale(1);
}

/* ── Empty State ── */
.empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: var(--space-4xl) var(--space-lg);
  text-align: center;
}
.empty-state-icon {
  font-size: 4rem;
  margin-bottom: var(--space-lg);
  animation: float 3s ease-in-out infinite;
}
.empty-state h3 {
  margin-bottom: var(--space-sm);
}

/* ── Responsive ── */
@media (max-width: 768px) {
  .nav-links { display: none; }
  .main-nav { padding: 0 var(--space-md); }

  .mobile-nav {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    height: 60px;
    background: var(--bg-nav);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    border-top: 1px solid var(--border-light);
    display: flex;
    align-items: center;
    justify-content: space-around;
    z-index: 1000;
    padding: 0 var(--space-sm);
  }

  .mobile-nav .nav-link {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 2px;
    font-size: 0.7rem;
    padding: var(--space-xs) var(--space-sm);
  }
  .mobile-nav .nav-link .nav-icon {
    font-size: 1.25rem;
  }

  .page {
    padding-bottom: 70px;
  }
}

@media (min-width: 769px) {
  .mobile-nav { display: none; }
}
