@import url('https://fonts.googleapis.com/css2?family=DM+Sans:ital,opsz,wght@0,9..40,400;0,9..40,500;0,9..40,600;0,9..40,700&display=swap');

:root {
  --bg: #0f1117;
  --surface: #1a1d27;
  --surface-2: #242836;
  --border: #2e3348;
  --text: #e8eaef;
  --muted: #8b92a8;
  --accent: #14b8a6;
  --accent-dim: #0d9488;
  --danger: #ef4444;
  --warning: #f59e0b;
  --success: #22c55e;
  --header-h: auto;
  --sidebar-w: 14rem;
}

* { box-sizing: border-box; }

html {
  font-family: 'DM Sans', system-ui, sans-serif;
  background: var(--bg);
  color: var(--text);
  -webkit-text-size-adjust: 100%;
}

body {
  margin: 0;
  min-height: 100vh;
  min-height: 100dvh;
}

body.nav-open { overflow: hidden; }

::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: var(--bg); }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }

/* Layout */
.app-layout {
  display: flex;
  flex: 1;
  min-height: 0;
  position: relative;
}

.app-main {
  flex: 1;
  min-width: 0;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}

.home-main {
  padding: 1.25rem;
  max-width: 48rem;
}

@media (min-width: 640px) {
  .home-main { padding: 2rem; }
}

/* Mobile nav toggle */
.nav-toggle {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 40px;
  height: 40px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface);
  color: var(--text);
  cursor: pointer;
  flex-shrink: 0;
}

.nav-toggle:active { background: var(--surface-2); }

/* Sidebar */
.sidebar-backdrop {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.55);
  z-index: 40;
}

.sidebar-backdrop.open { display: block; }

.sidebar {
  position: fixed;
  top: 0;
  left: 0;
  bottom: 0;
  width: min(var(--sidebar-w), 85vw);
  z-index: 50;
  background: var(--surface);
  border-right: 1px solid var(--border);
  padding: 1rem 0.75rem;
  padding-top: 4.5rem;
  overflow-y: auto;
  transform: translateX(-100%);
  transition: transform 0.25s ease;
}

.sidebar.open { transform: translateX(0); }

@media (min-width: 1024px) {
  .sidebar {
    position: sticky;
    top: 0;
    align-self: flex-start;
    height: calc(100dvh - var(--header-h, 73px));
    transform: none;
    padding-top: 1rem;
    flex-shrink: 0;
  }
  .sidebar-backdrop { display: none !important; }
}

/* Tool hero */
.tool-hero {
  position: relative;
  width: 100%;
  max-height: 220px;
  overflow: hidden;
  border-bottom: 1px solid var(--border);
  background: var(--surface);
}

.tool-hero img {
  width: 100%;
  height: 180px;
  object-fit: cover;
  display: block;
}

@media (min-width: 640px) {
  .tool-hero { max-height: 280px; }
  .tool-hero img { height: 220px; }
}

.tool-hero-caption {
  padding: 0.75rem 1rem 1rem;
  background: linear-gradient(to top, var(--surface), transparent);
  margin-top: -2rem;
  position: relative;
}

/* Tool grid */
.tool-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 0;
}

.tool-panel {
  padding: 1rem;
  border-bottom: 1px solid var(--border);
}

.panel-title {
  font-size: 0.875rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--muted);
  margin: 0 0 0.75rem;
}

@media (min-width: 1024px) {
  .tool-grid {
    grid-template-columns: minmax(260px, 320px) 1fr minmax(220px, 280px);
    grid-template-rows: auto;
    align-items: start;
  }
  .tool-panel {
    border-bottom: none;
    border-right: 1px solid var(--border);
    min-height: calc(100dvh - 300px);
    overflow-y: auto;
  }
  .tool-article-panel { border-right: none; }
}

@media (min-width: 1280px) {
  .tool-grid {
    grid-template-columns: 300px 1fr 260px;
  }
}

/* Photo visualizer */
.photo-dropzone {
  position: relative;
  min-height: 200px;
  height: 220px;
  border: 2px dashed var(--border);
  border-radius: 12px;
  overflow: hidden;
  cursor: pointer;
  background: var(--surface-2);
}

@media (min-width: 640px) {
  .photo-dropzone { height: 280px; min-height: 240px; }
}

.photo-dropzone:hover,
.photo-dropzone.drag-active {
  border-color: var(--accent);
}

.photo-upload-input {
  position: absolute;
  inset: 0;
  opacity: 0;
  cursor: pointer;
  z-index: 10;
  width: 100%;
  height: 100%;
}

.photo-placeholder {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: 1rem;
  color: var(--muted);
  pointer-events: none;
  z-index: 1;
}

.visualizer-stage {
  position: absolute;
  inset: 0;
  transform-style: preserve-3d;
  perspective: 800px;
}

.photo-bg {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.photo-bg.hidden { display: none; }

.blueprint-overlay {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1rem;
  pointer-events: none;
  transform-origin: center center;
  transition: opacity 0.15s ease;
}

.blueprint-overlay svg {
  width: 100%;
  height: 100%;
  max-height: 100%;
}

.overlay-sliders {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.75rem;
  margin-top: 0.75rem;
}

@media (min-width: 640px) {
  .overlay-sliders { grid-template-columns: repeat(4, 1fr); }
}

.slider-label {
  font-size: 0.75rem;
  color: var(--muted);
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
}

/* Home lists */
.home-tool-list {
  list-style: none;
  padding: 0;
  margin: 0;
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

.tool-list-item a {
  color: var(--accent);
  font-weight: 500;
  text-decoration: none;
  display: block;
}

.tool-list-item a:hover { text-decoration: underline; }

.tool-list-item span {
  display: block;
  font-size: 0.875rem;
  color: var(--muted);
  margin-top: 0.15rem;
}

/* Form controls */
input[type='range'] {
  -webkit-appearance: none;
  appearance: none;
  height: 4px;
  background: var(--border);
  border-radius: 2px;
  outline: none;
  width: 100%;
  min-height: 28px;
}

input[type='range']::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: var(--accent);
  cursor: pointer;
}

.tool-link.active,
a.tool-link.active {
  background: var(--accent-dim);
  color: white;
}

.compliance-error { color: var(--danger); }
.compliance-warning { color: var(--warning); }
.compliance-ok { color: var(--success); }

.metric-card {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0.75rem 1rem;
}

input, select {
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: 6px;
  padding: 0.625rem 0.75rem;
  width: 100%;
  font-size: 16px; /* prevents iOS zoom on focus */
}

input:focus, select:focus {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
}

/* Info icon & tooltips */
.info-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  border: 1px solid var(--muted);
  color: var(--muted);
  font-size: 11px;
  font-weight: 700;
  font-style: italic;
  font-family: Georgia, serif;
  cursor: help;
  flex-shrink: 0;
  position: relative;
  background: transparent;
  padding: 0;
  line-height: 1;
  touch-action: manipulation;
}

.info-icon:hover,
.info-icon:focus {
  border-color: var(--accent);
  color: var(--accent);
  outline: none;
}

.has-tooltip { position: relative; }

.tooltip-panel {
  display: none;
  position: absolute;
  z-index: 60;
  left: 0;
  right: auto;
  bottom: calc(100% + 8px);
  width: max-content;
  max-width: min(280px, 90vw);
  padding: 0.65rem 0.85rem;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 12px;
  line-height: 1.45;
  color: var(--text);
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.4);
  pointer-events: none;
  text-align: left;
  font-weight: 400;
  font-style: normal;
}

.has-tooltip:hover .tooltip-panel,
.has-tooltip:focus-within .tooltip-panel,
.info-icon:active .tooltip-panel {
  display: block;
}

.compliance-chip.has-tooltip {
  cursor: help;
  border-bottom: 1px dashed currentColor;
}

.compliance-chip .tooltip-panel {
  right: 0;
  left: auto;
  bottom: calc(100% + 6px);
}

.compliance-item {
  position: relative;
}

.compliance-item .tooltip-panel {
  left: 0;
  bottom: calc(100% + 6px);
}

.tooltip-panel strong {
  display: block;
  margin-bottom: 0.25rem;
  font-size: 12px;
}

.tooltip-panel p {
  margin: 0;
  color: var(--muted);
}

.tooltip-item.error strong { color: var(--danger); }
.tooltip-item.warning strong { color: var(--warning); }

.tool-article .article-title {
  margin-top: 0;
  font-size: 1.25rem;
  font-weight: 700;
  line-height: 1.35;
  color: #f3f4f6;
  margin-bottom: 1rem;
}

.tool-article h3 {
  font-size: 1.05rem;
  font-weight: 600;
  color: #5eead4;
  margin-top: 1.5rem;
  margin-bottom: 0.5rem;
}

.tool-article h4 {
  font-size: 0.95rem;
  font-weight: 600;
  color: #e5e7eb;
  margin-top: 1rem;
  margin-bottom: 0.35rem;
}

.tool-article p {
  font-size: 0.875rem;
  color: var(--muted);
  line-height: 1.7;
  margin-bottom: 0.75rem;
}

.tool-article ul,
.tool-article ol {
  font-size: 0.875rem;
  color: var(--muted);
  line-height: 1.7;
  margin: 0.5rem 0 1rem 1.25rem;
  padding: 0;
}

.tool-article li { margin-bottom: 0.35rem; }

.tool-article .formula {
  font-family: ui-monospace, monospace;
  font-size: 0.8125rem;
  background: #1a1d27;
  border: 1px solid var(--border);
  border-radius: 0.5rem;
  padding: 0.75rem 1rem;
  margin: 1rem 0;
  color: #d1d5db;
}

.tool-article .pro-tip {
  border-left: 3px solid var(--accent);
  padding: 0.5rem 0 0.5rem 1rem;
  margin: 1rem 0;
  font-size: 0.875rem;
  color: var(--muted);
  line-height: 1.6;
}

.tool-article .pro-tip strong { color: #5eead4; }

/* Touch: larger tap targets on mobile */
@media (max-width: 1023px) {
  .tool-link {
    padding: 0.625rem 0.5rem !important;
    min-height: 44px;
    display: flex;
    align-items: center;
  }

  .header-controls input {
    min-height: 36px;
  }

  .tooltip-panel {
    position: fixed;
    left: 1rem !important;
    right: 1rem !important;
    bottom: auto !important;
    top: 50%;
    transform: translateY(-50%);
    width: auto;
    max-width: none;
    z-index: 70;
  }
}
