/* ==========================================================================
   Modern Engineering Scale Calculator - Stylesheet (Free & Open Source)
   Mobile-Optimized & Fully Responsive
   ========================================================================== */

:root {
  --primary: #2563eb;
  --primary-hover: #1d4ed8;
  --primary-light: #eff6ff;
  --primary-border: #bfdbfe;
  --indigo: #1e1b4b;
  --slate-900: #0f172a;
  --slate-800: #1e293b;
  --slate-700: #334155;
  --slate-600: #475569;
  --slate-500: #64748b;
  --slate-400: #94a3b8;
  --slate-200: #e2e8f0;
  --slate-100: #f1f5f9;
  --slate-50: #f8fafc;
  
  --real-color-1: #10b981;
  --real-color-2: #059669;
  --scale-color-1: #3b82f6;
  --scale-color-2: #1d4ed8;

  --card-bg: #ffffff;
  --radius-sm: 8px;
  --radius-md: 12px;
  --radius-lg: 16px;
  --radius-full: 9999px;

  --shadow-sm: 0 1px 2px 0 rgb(0 0 0 / 0.05);
  --shadow-md: 0 4px 6px -1px rgb(0 0 0 / 0.1), 0 2px 4px -2px rgb(0 0 0 / 0.1);
  --shadow-lg: 0 10px 25px -3px rgb(0 0 0 / 0.08), 0 4px 6px -4px rgb(0 0 0 / 0.05);
  --shadow-xl: 0 20px 30px -10px rgb(30 41 59 / 0.12);
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  -webkit-tap-highlight-color: transparent;
}

body {
  font-family: 'Plus Jakarta Sans', system-ui, -apple-system, sans-serif;
  background-color: #f1f5f9;
  background-image: 
    radial-gradient(#cbd5e1 0.75px, transparent 0.75px), 
    linear-gradient(to bottom, #f8fafc 0%, #edf2f7 100%);
  background-size: 24px 24px, 100% 100%;
  color: var(--slate-800);
  line-height: 1.5;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

/* Header */
.site-header {
  background: rgba(255, 255, 255, 0.95);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--slate-200);
  position: sticky;
  top: 0;
  z-index: 50;
}

.header-inner {
  max-width: 1200px;
  margin: 0 auto;
  padding: 0.75rem 1.25rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
}

.brand {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.brand-icon {
  width: 38px;
  height: 38px;
  border-radius: var(--radius-md);
  background: linear-gradient(135deg, #1e3a8a, #2563eb);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 4px 10px rgba(37, 99, 235, 0.25);
  flex-shrink: 0;
}

.brand-text {
  display: flex;
  flex-direction: column;
}

.brand-title {
  font-weight: 800;
  font-size: 1.15rem;
  letter-spacing: 1px;
  color: var(--indigo);
}

.brand-tag {
  font-size: 0.7rem;
  font-weight: 600;
  color: var(--slate-500);
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.header-badges {
  display: flex;
  gap: 0.5rem;
  align-items: center;
  flex-wrap: wrap;
}

.badge-free {
  font-size: 0.75rem;
  font-weight: 700;
  color: #047857;
  background: #d1fae5;
  border: 1px solid #a7f3d0;
  padding: 0.28rem 0.65rem;
  border-radius: var(--radius-full);
}

.badge-dstu {
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--primary);
  background: var(--primary-light);
  border: 1px solid var(--primary-border);
  padding: 0.28rem 0.65rem;
  border-radius: var(--radius-full);
}

/* Main Content */
.main-content {
  max-width: 1200px;
  margin: 0 auto;
  padding: 1.75rem 1.25rem 3rem;
  flex: 1;
  width: 100%;
}

.intro-section {
  text-align: center;
  max-width: 760px;
  margin: 0 auto 1.8rem;
}

.page-title {
  font-size: 2rem;
  font-weight: 800;
  color: var(--indigo);
  letter-spacing: -0.5px;
  margin-bottom: 0.5rem;
}

.page-subtitle {
  font-size: 1rem;
  color: var(--slate-600);
  line-height: 1.5;
}

/* Layout Grid */
.calculator-layout {
  display: grid;
  grid-template-columns: 1fr 420px;
  gap: 1.75rem;
  align-items: start;
}

/* Cards */
.card {
  background: var(--card-bg);
  border-radius: var(--radius-lg);
  border: 1px solid rgba(226, 232, 240, 0.85);
  box-shadow: var(--shadow-lg);
  padding: 1.6rem;
}

/* Direction Bar (Swap Google Translate style) */
.direction-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: var(--slate-100);
  border: 1px solid var(--slate-200);
  border-radius: var(--radius-md);
  padding: 0.4rem;
  margin-bottom: 1.4rem;
  gap: 0.5rem;
}

.direction-tab {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.45rem;
  min-height: 44px;
  padding: 0.5rem 0.6rem;
  background: #ffffff;
  border: 1px solid var(--slate-200);
  border-radius: var(--radius-sm);
  box-shadow: var(--shadow-sm);
  font-weight: 700;
  font-size: 0.88rem;
  color: var(--indigo);
  cursor: pointer;
  transition: all 0.2s ease;
  font-family: inherit;
}

.direction-tab.active {
  border-color: var(--primary-border);
  background: #ffffff;
}

.direction-tab:hover {
  background: var(--slate-50);
}

.dir-icon {
  font-size: 1.1rem;
}

.swap-btn {
  background: var(--primary);
  color: #fff;
  border: none;
  width: 44px;
  height: 44px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  box-shadow: 0 4px 10px rgba(37, 99, 235, 0.35);
  transition: transform 0.4s cubic-bezier(0.34, 1.56, 0.64, 1), background-color 0.2s;
  flex-shrink: 0;
}

.swap-btn:hover {
  background: var(--primary-hover);
  transform: scale(1.08);
}

.swap-btn:active {
  transform: scale(0.92);
}

.swap-btn.flipped .swap-icon {
  transform: rotate(180deg);
}

.swap-icon {
  transition: transform 0.4s ease;
}

/* Form Controls */
.form-group {
  margin-bottom: 1.25rem;
}

.section-label-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 0.5rem;
}

.input-label {
  font-weight: 700;
  font-size: 0.9rem;
  color: var(--slate-700);
}

.scale-type-tag {
  font-size: 0.72rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  padding: 0.2rem 0.55rem;
  border-radius: var(--radius-full);
  background: #e0e7ff;
  color: #3730a3;
}

.scale-type-tag.enlarge {
  background: #fef3c7;
  color: #92400e;
}

.scale-type-tag.neutral {
  background: #f3f4f6;
  color: #374151;
}

/* Scale Input Pair */
.scale-inputs-wrap {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  background: var(--slate-50);
  border: 1px solid var(--slate-200);
  padding: 0.75rem;
  border-radius: var(--radius-md);
}

.scale-input-box {
  flex: 1;
  display: flex;
  flex-direction: column;
}

.scale-sublabel {
  font-size: 0.72rem;
  font-weight: 600;
  color: var(--slate-500);
  margin-bottom: 0.25rem;
  text-transform: uppercase;
}

.scale-inputs-wrap input {
  width: 100%;
  padding: 0.65rem 0.8rem;
  font-size: 1.15rem;
  font-weight: 700;
  color: var(--slate-800);
  border: 1px solid var(--slate-200);
  border-radius: var(--radius-sm);
  background: #ffffff;
  outline: none;
  font-family: 'JetBrains Mono', monospace;
  transition: border-color 0.2s, box-shadow 0.2s;
  min-height: 44px;
}

.scale-inputs-wrap input:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.15);
}

.scale-divider {
  font-size: 1.6rem;
  font-weight: 800;
  color: var(--slate-400);
  padding-top: 1rem;
}

/* Presets */
.presets-section {
  margin-top: 0.85rem;
}

.presets-label {
  display: block;
  font-size: 0.75rem;
  font-weight: 700;
  color: var(--slate-500);
  margin-bottom: 0.4rem;
}

.presets-scroll {
  display: flex;
  flex-direction: column;
  gap: 0.45rem;
}

.presets-group {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.35rem;
}

.preset-group-title {
  font-size: 0.72rem;
  font-weight: 700;
  color: var(--slate-400);
  min-width: 95px;
}

.preset-pill {
  border: 1px solid var(--slate-200);
  background: #ffffff;
  padding: 0.35rem 0.7rem;
  min-height: 34px;
  border-radius: var(--radius-full);
  font-size: 0.82rem;
  font-weight: 600;
  color: var(--slate-700);
  cursor: pointer;
  transition: all 0.15s ease;
  font-family: 'JetBrains Mono', monospace;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.preset-pill:hover {
  border-color: var(--primary);
  color: var(--primary);
  background: var(--primary-light);
}

.preset-pill.active {
  background: var(--primary);
  border-color: var(--primary);
  color: #ffffff;
  box-shadow: 0 2px 6px rgba(37, 99, 235, 0.3);
}

.divider {
  height: 1px;
  background: var(--slate-200);
  margin: 1.25rem 0;
}

/* Value input + Unit */
.input-with-select {
  display: flex;
  gap: 0.6rem;
}

.input-with-select input {
  flex: 1.4;
  padding: 0.75rem 1rem;
  font-size: 1.2rem;
  font-weight: 700;
  color: var(--slate-900);
  border: 1px solid var(--slate-300);
  border-radius: var(--radius-md);
  background: #ffffff;
  outline: none;
  font-family: 'JetBrains Mono', monospace;
  transition: border-color 0.2s, box-shadow 0.2s;
  min-height: 48px;
}

.input-with-select input:focus,
.full-select:focus,
.input-with-select select:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.15);
}

.input-with-select select,
.full-select {
  flex: 1;
  padding: 0.75rem 0.9rem;
  font-size: 1rem;
  font-weight: 600;
  color: var(--slate-700);
  border: 1px solid var(--slate-300);
  border-radius: var(--radius-md);
  background: #ffffff;
  outline: none;
  cursor: pointer;
  min-height: 48px;
  font-family: inherit;
}

.full-select {
  width: 100%;
}

/* Result Card */
.result-card {
  background: linear-gradient(135deg, #eff6ff 0%, #e0e7ff 100%);
  border: 1px solid #bfdbfe;
  border-radius: var(--radius-md);
  padding: 1.35rem;
  margin-top: 1.4rem;
  box-shadow: 0 4px 12px rgba(37, 99, 235, 0.08);
}

.result-top {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 0.35rem;
}

.result-caption {
  font-size: 0.82rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: #1e40af;
}

.copy-btn {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  background: #ffffff;
  border: 1px solid #93c5fd;
  color: #1d4ed8;
  font-weight: 700;
  font-size: 0.78rem;
  padding: 0.35rem 0.75rem;
  min-height: 34px;
  border-radius: var(--radius-full);
  cursor: pointer;
  transition: all 0.2s ease;
  box-shadow: var(--shadow-sm);
  font-family: inherit;
}

.copy-btn:hover {
  background: #1d4ed8;
  color: #ffffff;
  border-color: #1d4ed8;
}

.result-value-row {
  display: flex;
  align-items: baseline;
  gap: 0.5rem;
  margin: 0.2rem 0;
  flex-wrap: wrap;
}

.result-number {
  font-size: 2.2rem;
  font-weight: 800;
  color: #1e3a8a;
  font-family: 'JetBrains Mono', monospace;
  letter-spacing: -0.5px;
  word-break: break-all;
}

.result-unit {
  font-size: 1.2rem;
  font-weight: 700;
  color: #2563eb;
}

.result-secondary {
  font-size: 0.95rem;
  font-weight: 600;
  color: #3b82f6;
  margin-top: 0.1rem;
}

.result-formula {
  font-size: 0.82rem;
  color: #64748b;
  margin-top: 0.6rem;
  padding-top: 0.6rem;
  border-top: 1px dashed #bfdbfe;
  font-family: 'JetBrains Mono', monospace;
  word-break: break-word;
}

/* Visualizer Bars */
.visualizer-box {
  margin-top: 1.6rem;
  background: var(--slate-50);
  border: 1px solid var(--slate-200);
  border-radius: var(--radius-md);
  padding: 1.2rem;
}

.visualizer-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 0.9rem;
  gap: 0.5rem;
  flex-wrap: wrap;
}

.visualizer-title {
  font-size: 0.8rem;
  font-weight: 700;
  color: var(--slate-700);
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.visualizer-ratio-info {
  font-size: 0.8rem;
  font-weight: 700;
  color: var(--primary);
  background: #ffffff;
  padding: 0.25rem 0.55rem;
  border-radius: var(--radius-sm);
  border: 1px solid var(--slate-200);
  font-family: 'JetBrains Mono', monospace;
}

.bar-item {
  margin-bottom: 0.85rem;
}

.bar-item:last-child {
  margin-bottom: 0;
}

.bar-meta {
  display: flex;
  justify-content: space-between;
  font-size: 0.82rem;
  margin-bottom: 0.35rem;
  font-weight: 600;
  color: var(--slate-700);
}

.bar-value-tag {
  font-family: 'JetBrains Mono', monospace;
  font-weight: 700;
  color: var(--slate-600);
}

.bar-track {
  height: 40px;
  background: #e2e8f0;
  border-radius: var(--radius-sm);
  overflow: hidden;
  position: relative;
  box-shadow: inset 0 2px 4px rgba(0, 0, 0, 0.06);
}

.bar-fill {
  height: 100%;
  position: absolute;
  top: 0;
  left: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: width 0.35s cubic-bezier(0.4, 0, 0.2, 1);
  border-radius: var(--radius-sm);
  min-width: 6px;
}

.real-fill {
  background: linear-gradient(90deg, var(--real-color-1), var(--real-color-2));
  color: #ffffff;
}

.plan-fill {
  background: linear-gradient(90deg, var(--scale-color-1), var(--scale-color-2));
  color: #fef08a;
}

.bar-brand {
  font-weight: 800;
  font-size: 0.85rem;
  letter-spacing: 2px;
  color: #ffffff;
  user-select: none;
  text-shadow: 0 1px 3px rgba(0, 0, 0, 0.25);
}

/* Sidebar Column */
.sidebar-column {
  display: flex;
  flex-direction: column;
  gap: 1.4rem;
}

.info-card {
  padding: 1.4rem;
}

.card-heading {
  font-size: 1.1rem;
  font-weight: 800;
  color: var(--indigo);
  margin-bottom: 0.5rem;
  display: flex;
  align-items: center;
  gap: 0.45rem;
}

.heading-icon {
  font-size: 1.2rem;
}

.card-desc {
  font-size: 0.88rem;
  color: var(--slate-600);
  line-height: 1.55;
  margin-bottom: 1rem;
}

.steps-list {
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 0.85rem;
}

.steps-list li {
  display: flex;
  gap: 0.65rem;
  align-items: flex-start;
  font-size: 0.86rem;
  color: var(--slate-700);
  line-height: 1.45;
}

.step-num {
  width: 22px;
  height: 22px;
  border-radius: 50%;
  background: #dbeafe;
  color: #1e40af;
  font-weight: 800;
  font-size: 0.75rem;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  margin-top: 0.1rem;
}

.mini-chip {
  background: #e2e8f0;
  padding: 0.1rem 0.35rem;
  border-radius: 4px;
  font-weight: 700;
}

/* Standard Scales Table */
.scales-table-wrap {
  overflow-x: auto;
  border-radius: var(--radius-sm);
  border: 1px solid var(--slate-200);
}

.scales-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.82rem;
  text-align: left;
}

.scales-table th {
  background: var(--slate-100);
  color: var(--slate-700);
  font-weight: 700;
  padding: 0.6rem 0.75rem;
  border-bottom: 1px solid var(--slate-200);
}

.scales-table td {
  padding: 0.6rem 0.75rem;
  border-bottom: 1px solid var(--slate-200);
  color: var(--slate-600);
  line-height: 1.4;
}

.scales-table tr:last-child td {
  border-bottom: none;
}

/* Engineering Cheat Sheet Card */
.guide-card {
  padding: 1.4rem;
  background: #ffffff;
}

.guide-grid {
  display: flex;
  flex-direction: column;
  gap: 0.85rem;
  margin-top: 0.5rem;
}

.guide-item {
  background: var(--slate-50);
  border: 1px solid var(--slate-200);
  border-radius: var(--radius-sm);
  padding: 0.75rem 0.85rem;
}

.guide-badge {
  display: inline-block;
  font-size: 0.72rem;
  font-weight: 700;
  color: var(--primary);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  margin-bottom: 0.3rem;
}

.guide-item p {
  font-size: 0.84rem;
  color: var(--slate-700);
  line-height: 1.45;
}

/* Toast */
.toast {
  position: fixed;
  bottom: 24px;
  right: 24px;
  background: #0f172a;
  color: #ffffff;
  padding: 0.75rem 1.25rem;
  border-radius: var(--radius-full);
  display: flex;
  align-items: center;
  gap: 0.55rem;
  font-size: 0.88rem;
  font-weight: 600;
  box-shadow: 0 10px 25px rgba(0, 0, 0, 0.25);
  opacity: 0;
  transform: translateY(20px);
  pointer-events: none;
  transition: all 0.3s cubic-bezier(0.16, 1, 0.3, 1);
  z-index: 100;
  max-width: calc(100vw - 48px);
}

.toast.show {
  opacity: 1;
  transform: translateY(0);
}

.toast-icon {
  color: #34d399;
  font-weight: 800;
}

/* Footer */
.site-footer {
  background: #ffffff;
  border-top: 1px solid var(--slate-200);
  padding: 1.5rem 1.25rem;
  text-align: center;
  font-size: 0.82rem;
  color: var(--slate-500);
}

.footer-inner {
  max-width: 1200px;
  margin: 0 auto;
}

.footer-note {
  margin-top: 0.3rem;
  font-size: 0.74rem;
  color: var(--slate-400);
}

/* ==========================================================================
   Mobile & Tablet Media Queries
   ========================================================================== */

@media (max-width: 992px) {
  .calculator-layout {
    grid-template-columns: 1fr;
    gap: 1.5rem;
  }
}

@media (max-width: 640px) {
  .main-content {
    padding: 1.25rem 0.85rem 2.5rem;
  }

  .header-inner {
    padding: 0.65rem 0.85rem;
  }

  .brand-title {
    font-size: 1.05rem;
  }

  .page-title {
    font-size: 1.55rem;
  }

  .page-subtitle {
    font-size: 0.92rem;
  }

  .card {
    padding: 1.15rem;
    border-radius: var(--radius-md);
  }

  /* Direction Bar on mobile: compact horizontal or stack */
  .direction-bar {
    padding: 0.35rem;
    gap: 0.35rem;
  }

  .direction-tab {
    font-size: 0.78rem;
    padding: 0.45rem 0.35rem;
    min-height: 42px;
  }

  .dir-icon {
    font-size: 0.95rem;
  }

  .swap-btn {
    width: 40px;
    height: 40px;
  }

  /* Input fields stack vertically on mobile */
  .input-with-select {
    flex-direction: column;
    gap: 0.5rem;
  }

  .input-with-select input,
  .input-with-select select,
  .full-select {
    font-size: 16px; /* Prevents auto-zoom on iOS Safari */
    width: 100%;
  }

  .result-number {
    font-size: 1.85rem;
  }

  .result-unit {
    font-size: 1.1rem;
  }

  .preset-group-title {
    width: 100%;
    margin-bottom: 0.2rem;
  }

  .toast {
    bottom: 16px;
    right: 16px;
    left: 16px;
    justify-content: center;
  }
}

@media (max-width: 380px) {
  .direction-tab .dir-label {
    font-size: 0.74rem;
  }

  .scale-divider {
    font-size: 1.3rem;
  }

  .badge-free {
    display: none; /* Hide badge on extremely narrow phones to fit header */
  }
}
