/* CalcHub — Modern Calculator Suite */
/* Mobile-first, dark/light mode, clean ad-friendly layout */

:root {
  --bg: #ffffff;
  --bg-secondary: #f8f9fa;
  --bg-card: #ffffff;
  --text: #1a1a2e;
  --text-secondary: #6c757d;
  --border: #e2e8f0;
  --accent: #2563eb;
  --accent-hover: #1d4ed8;
  --accent-light: #dbeafe;
  --success: #16a34a;
  --error: #dc2626;
  --shadow: 0 1px 3px rgba(0,0,0,0.1);
  --shadow-lg: 0 4px 12px rgba(0,0,0,0.1);
  --radius: 8px;
  --radius-lg: 12px;
  --max-width: 1200px;
  --font: system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
  --font-mono: 'SF Mono', 'Cascadia Code', 'Consolas', monospace;
}

[data-theme="dark"] {
  --bg: #0f172a;
  --bg-secondary: #1e293b;
  --bg-card: #1e293b;
  --text: #e2e8f0;
  --text-secondary: #94a3b8;
  --border: #334155;
  --accent: #3b82f6;
  --accent-hover: #60a5fa;
  --accent-light: #1e3a5f;
  --shadow: 0 1px 3px rgba(0,0,0,0.3);
  --shadow-lg: 0 4px 12px rgba(0,0,0,0.4);
}

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

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

body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  line-height: 1.6;
  min-height: 100vh;
  transition: background 0.2s, color 0.2s;
}

a { color: var(--accent); text-decoration: none; }
a:hover { color: var(--accent-hover); text-decoration: underline; }

/* --- Header --- */
.site-header {
  background: var(--bg-card);
  border-bottom: 1px solid var(--border);
  padding: 0.75rem 1rem;
  position: sticky;
  top: 0;
  z-index: 100;
}

.header-inner {
  max-width: var(--max-width);
  margin: 0 auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
}

.site-logo {
  font-size: 1.25rem;
  font-weight: 700;
  color: var(--text);
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.site-logo:hover { text-decoration: none; color: var(--accent); }

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

.header-nav a {
  color: var(--text-secondary);
  font-size: 0.875rem;
  padding: 0.375rem 0.75rem;
  border-radius: var(--radius);
}

.header-nav a:hover {
  background: var(--bg-secondary);
  color: var(--text);
  text-decoration: none;
}

.theme-toggle {
  background: none;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 0.375rem 0.5rem;
  cursor: pointer;
  font-size: 1rem;
  color: var(--text);
  line-height: 1;
}

.theme-toggle:hover { background: var(--bg-secondary); }
[data-theme="dark"] .theme-toggle { border-color: var(--text-secondary); }

/* --- Layout --- */
.page-wrapper {
  max-width: var(--max-width);
  margin: 0 auto;
  padding: 1.5rem 1rem;
}

.content-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 1.5rem;
}

@media (min-width: 1024px) {
  .content-grid {
    grid-template-columns: 1fr 300px;
  }
}

.main-content { min-width: 0; }

/* --- Ad Slots --- */
.ad-slot {
  background: var(--bg-secondary);
  border: 1px dashed var(--border);
  border-radius: var(--radius);
  padding: 1rem;
  text-align: center;
  color: var(--text-secondary);
  font-size: 0.75rem;
  min-height: 90px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.ad-slot-banner { min-height: 90px; margin-bottom: 1.5rem; }
.ad-slot-sidebar { min-height: 250px; position: sticky; top: 5rem; }
.ad-slot-inline { min-height: 100px; margin: 1.5rem 0; }

/* --- Calculator Card --- */
.calc-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 1.5rem;
  box-shadow: var(--shadow);
}

.calc-card h1 {
  font-size: 1.5rem;
  font-weight: 700;
  margin-bottom: 0.25rem;
  line-height: 1.3;
}

.calc-subtitle {
  color: var(--text-secondary);
  font-size: 0.9375rem;
  margin-bottom: 1.25rem;
}

/* --- Form Elements --- */
.form-group {
  margin-bottom: 1rem;
}

.form-group label {
  display: block;
  font-size: 0.875rem;
  font-weight: 600;
  margin-bottom: 0.375rem;
  color: var(--text);
}

.form-group .hint {
  font-size: 0.75rem;
  color: var(--text-secondary);
  font-weight: 400;
}

.input-row {
  display: flex;
  gap: 0.75rem;
}

.input-row .form-group { flex: 1; }

input[type="number"],
input[type="text"],
input[type="date"],
select {
  width: 100%;
  padding: 0.625rem 0.75rem;
  font-size: 1rem;
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  transition: border-color 0.15s, box-shadow 0.15s;
  -moz-appearance: textfield;
}

input:focus, select:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-light);
}

input::-webkit-outer-spin-button,
input::-webkit-inner-spin-button {
  -webkit-appearance: none;
  margin: 0;
}

/* Input with prefix/suffix */
.input-with-affix {
  display: flex;
  align-items: stretch;
}

.input-prefix, .input-suffix {
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  padding: 0.625rem 0.75rem;
  font-size: 0.875rem;
  color: var(--text-secondary);
  display: flex;
  align-items: center;
  white-space: nowrap;
}

.input-prefix { border-right: none; border-radius: var(--radius) 0 0 var(--radius); }
.input-suffix { border-left: none; border-radius: 0 var(--radius) var(--radius) 0; }

.input-with-affix input {
  border-radius: 0;
  flex: 1;
}

.input-with-affix input:first-child { border-radius: var(--radius) 0 0 var(--radius); }
.input-with-affix input:last-child { border-radius: 0 var(--radius) var(--radius) 0; }

/* --- Range Slider --- */
input[type="range"] {
  width: 100%;
  height: 6px;
  -webkit-appearance: none;
  background: var(--border);
  border-radius: 3px;
  outline: none;
  margin: 0.5rem 0;
}

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

/* --- Result Display --- */
.result-box {
  background: var(--accent-light);
  border: 1px solid var(--accent);
  border-radius: var(--radius);
  padding: 1rem 1.25rem;
  margin-top: 1.25rem;
}

.result-label {
  font-size: 0.8125rem;
  font-weight: 600;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin-bottom: 0.25rem;
}

.result-value {
  font-size: 1.75rem;
  font-weight: 700;
  color: var(--accent);
  font-family: var(--font-mono);
}

.result-detail {
  font-size: 0.875rem;
  color: var(--text-secondary);
  margin-top: 0.375rem;
}

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

.result-grid .result-box { margin-top: 0; }

@media (max-width: 480px) {
  .result-grid { grid-template-columns: 1fr; }
  .input-row { flex-direction: column; gap: 0; }
  .btn-group { display: grid; grid-template-columns: repeat(3, 1fr); }
  input[type="number"], input[type="text"], input[type="date"], select {
    min-height: 44px;
    font-size: 16px; /* prevents iOS auto-zoom */
  }
}

/* --- Skip to Content --- */
.skip-link {
  position: absolute;
  top: -100%;
  left: 0;
  background: var(--accent);
  color: #fff;
  padding: 0.75rem 1.5rem;
  z-index: 200;
  font-weight: 600;
  border-radius: 0 0 var(--radius) 0;
}

.skip-link:focus {
  top: 0;
  outline: none;
}

/* --- Focus Indicators --- */
button:focus-visible, .btn:focus-visible, .category-btn:focus-visible,
.theme-toggle:focus-visible, .faq-question:focus-visible,
.sci-btn:focus-visible, .mode-btn:focus-visible, .remove-btn:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

/* --- Breakdown Table --- */
.breakdown-table {
  width: 100%;
  border-collapse: collapse;
  margin-top: 1rem;
  font-size: 0.875rem;
}

.breakdown-table th,
.breakdown-table td {
  padding: 0.625rem 0.75rem;
  text-align: left;
  border-bottom: 1px solid var(--border);
}

.breakdown-table th {
  font-weight: 600;
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-secondary);
  background: var(--bg-secondary);
}

.breakdown-table td { font-family: var(--font-mono); font-size: 0.8125rem; }
.breakdown-table tr:last-child td { border-bottom: none; font-weight: 700; }

/* --- Buttons --- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  padding: 0.625rem 1.25rem;
  font-size: 0.875rem;
  font-weight: 600;
  font-family: var(--font);
  border: none;
  border-radius: var(--radius);
  cursor: pointer;
  transition: background 0.15s, transform 0.1s;
}

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

.btn-primary {
  background: var(--accent);
  color: #fff;
}

.btn-primary:hover { background: var(--accent-hover); }

.btn-secondary {
  background: var(--bg-secondary);
  color: var(--text);
  border: 1px solid var(--border);
}

.btn-secondary:hover { background: var(--border); }

.btn-group { display: flex; gap: 0.5rem; margin-top: 1rem; flex-wrap: wrap; }

/* --- Content Sections (SEO) --- */
.content-section {
  margin-top: 2rem;
}

.content-section h2 {
  font-size: 1.25rem;
  font-weight: 700;
  margin-bottom: 0.75rem;
  padding-bottom: 0.5rem;
  border-bottom: 1px solid var(--border);
}

.content-section h3 {
  font-size: 1rem;
  font-weight: 600;
  margin: 1rem 0 0.5rem;
}

.content-section p {
  margin-bottom: 0.75rem;
  color: var(--text-secondary);
  line-height: 1.7;
}

.content-section ul, .content-section ol {
  margin: 0.5rem 0 1rem 1.25rem;
  color: var(--text-secondary);
}

.content-section li { margin-bottom: 0.375rem; }

/* --- FAQ (Schema) --- */
.faq-section { margin-top: 2rem; }

.faq-item {
  border-bottom: 1px solid var(--border);
}

.faq-question {
  width: 100%;
  background: none;
  border: none;
  padding: 1rem 0;
  font-size: 0.9375rem;
  font-weight: 600;
  font-family: var(--font);
  color: var(--text);
  text-align: left;
  cursor: pointer;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 1rem;
}

.faq-question::after {
  content: '+';
  font-size: 1.25rem;
  font-weight: 400;
  color: var(--text-secondary);
  flex-shrink: 0;
  transition: transform 0.2s;
}

.faq-item.open .faq-question::after {
  content: '-';
}

.faq-answer {
  display: none;
  padding: 0 0 1rem;
  color: var(--text-secondary);
  line-height: 1.7;
  font-size: 0.9375rem;
}

.faq-item.open .faq-answer { display: block; }

/* --- Home Page Tools Grid --- */
.tools-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 1rem;
  margin-top: 1rem;
}

.tool-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 1.25rem;
  transition: box-shadow 0.2s, transform 0.15s;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.tool-card:hover {
  box-shadow: var(--shadow-lg);
  transform: translateY(-2px);
  text-decoration: none;
}

.tool-card .tool-icon {
  font-size: 2rem;
  line-height: 1;
}

.tool-card .tool-name {
  font-size: 1rem;
  font-weight: 600;
  color: var(--text);
}

.tool-card .tool-desc {
  font-size: 0.8125rem;
  color: var(--text-secondary);
  line-height: 1.5;
}

.tool-card .tool-tag {
  display: inline-block;
  font-size: 0.6875rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  padding: 0.125rem 0.5rem;
  border-radius: 9999px;
  background: var(--accent-light);
  color: var(--accent);
  margin-top: auto;
  align-self: flex-start;
}

/* --- Category Filter --- */
.category-filter {
  display: flex;
  gap: 0.375rem;
  flex-wrap: wrap;
  margin-bottom: 1rem;
}

.category-btn {
  padding: 0.375rem 0.75rem;
  font-size: 0.8125rem;
  font-weight: 500;
  border: 1px solid var(--border);
  border-radius: 9999px;
  background: var(--bg);
  color: var(--text-secondary);
  cursor: pointer;
  transition: all 0.15s;
  font-family: var(--font);
}

.category-btn:hover, .category-btn.active {
  background: var(--accent);
  color: #fff;
  border-color: var(--accent);
}

/* --- Footer --- */
.site-footer {
  max-width: var(--max-width);
  margin: 3rem auto 0;
  padding: 2rem 1rem;
  border-top: 1px solid var(--border);
  font-size: 0.8125rem;
  color: var(--text-secondary);
}

.footer-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: 1.5rem;
  margin-bottom: 1.5rem;
}

.footer-col h4 {
  font-size: 0.75rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text);
  margin-bottom: 0.75rem;
}

.footer-col a {
  display: block;
  color: var(--text-secondary);
  padding: 0.25rem 0;
  font-size: 0.8125rem;
}

.footer-col a:hover { color: var(--accent); }

.footer-bottom {
  text-align: center;
  padding-top: 1rem;
  border-top: 1px solid var(--border);
}

/* --- Share URL --- */
.share-section {
  margin-top: 1rem;
  padding-top: 1rem;
  border-top: 1px solid var(--border);
}

.share-url {
  display: flex;
  gap: 0.5rem;
}

.share-url input {
  flex: 1;
  font-size: 0.8125rem;
  font-family: var(--font-mono);
  background: var(--bg-secondary);
}

/* --- Scientific Calculator --- */
.sci-display {
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1rem 1.25rem;
  margin-bottom: 1rem;
  text-align: right;
  min-height: 80px;
  display: flex;
  flex-direction: column;
  justify-content: flex-end;
}

.sci-expr {
  font-size: 0.875rem;
  color: var(--text-secondary);
  word-break: break-all;
  min-height: 1.25rem;
}

.sci-result {
  font-size: 2rem;
  font-weight: 700;
  font-family: var(--font-mono);
  color: var(--text);
  word-break: break-all;
}

.sci-grid {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 0.375rem;
}

.sci-btn {
  padding: 0.75rem 0.25rem;
  font-size: 0.9375rem;
  font-weight: 600;
  font-family: var(--font);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--bg-card);
  color: var(--text);
  cursor: pointer;
  transition: background 0.1s;
  text-align: center;
}

.sci-btn:hover { background: var(--bg-secondary); }
.sci-btn:active { transform: scale(0.97); }
.sci-btn.op { background: var(--accent-light); color: var(--accent); }
.sci-btn.op:hover { background: var(--accent); color: #fff; }
.sci-btn.fn { background: var(--bg-secondary); font-size: 0.8125rem; }
.sci-btn.eq { background: var(--accent); color: #fff; grid-column: span 2; }
.sci-btn.eq:hover { background: var(--accent-hover); }
.sci-btn.clear { background: var(--error); color: #fff; }
.sci-btn.clear:hover { opacity: 0.9; }

@media (max-width: 480px) {
  .sci-grid { grid-template-columns: repeat(4, 1fr); }
  .sci-btn { padding: 0.625rem 0.125rem; font-size: 0.8125rem; }
  .sci-result { font-size: 1.5rem; }
}

/* --- Mode Toggle (Scientific, BMI, etc.) --- */
.mode-toggle {
  display: flex;
  gap: 0.375rem;
  margin-bottom: 0.75rem;
}

.mode-btn {
  padding: 0.375rem 0.75rem;
  font-size: 0.75rem;
  font-weight: 600;
  border: 1px solid var(--border);
  border-radius: 9999px;
  background: var(--bg);
  color: var(--text-secondary);
  cursor: pointer;
  font-family: var(--font);
}

.mode-btn.active {
  background: var(--accent);
  color: #fff;
  border-color: var(--accent);
}

/* --- BMI Scale --- */
.bmi-scale {
  display: flex;
  margin-top: 1rem;
  border-radius: var(--radius);
  overflow: hidden;
  height: 32px;
  position: relative;
}

.bmi-range {
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.6875rem;
  font-weight: 600;
  color: #fff;
}

.bmi-marker {
  position: absolute;
  top: -6px;
  width: 3px;
  height: 44px;
  background: var(--text);
  border-radius: 2px;
  transition: left 0.3s;
}

/* --- Fraction Calculator --- */
.op-select {
  width: 60px;
  text-align: center;
  font-size: 1.25rem;
  font-weight: 700;
}

/* --- GPA Calculator --- */
.course-row {
  display: grid;
  grid-template-columns: 1fr 100px 80px 32px;
  gap: 0.5rem;
  align-items: end;
  margin-bottom: 0.5rem;
}

.course-row input, .course-row select {
  padding: 0.5rem;
  font-size: 0.875rem;
}

.remove-btn {
  background: none;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--error);
  cursor: pointer;
  font-size: 1rem;
  padding: 0.5rem;
  display: flex;
  align-items: center;
  justify-content: center;
}

.remove-btn:hover { background: var(--error); color: #fff; }

@media (max-width: 480px) {
  .course-row { grid-template-columns: 1fr 80px 65px 28px; gap: 0.25rem; }
  .course-row input, .course-row select { padding: 0.375rem; font-size: 0.8125rem; }
}

/* --- Active toggle button (reusable) --- */
.btn-toggle-active {
  background: var(--accent) !important;
  color: #fff !important;
  border-color: var(--accent) !important;
}

/* --- Landscape phone (short + wide) --- */
@media (max-height: 500px) and (orientation: landscape) {
  .site-header { padding: 0.375rem 1rem; position: relative; }
  .page-wrapper { padding: 0.75rem 1rem; }
  .calc-card { padding: 1rem; }
  .calc-card h1 { font-size: 1.25rem; margin-bottom: 0.125rem; }
  .calc-subtitle { font-size: 0.8125rem; margin-bottom: 0.75rem; }
  .form-group { margin-bottom: 0.625rem; }
  .result-box { padding: 0.75rem 1rem; margin-top: 0.75rem; }
  .result-value { font-size: 1.5rem; }
  .ad-slot-banner { min-height: 50px; margin-bottom: 0.75rem; }
  .content-grid { gap: 1rem; }
  /* Allow 2-col inputs in landscape */
  .input-row { flex-direction: row; gap: 0.75rem; }
  .result-grid { grid-template-columns: 1fr 1fr; }
}

/* --- Tablet landscape / small desktop --- */
@media (min-width: 768px) and (max-width: 1023px) {
  .content-grid { grid-template-columns: 1fr; }
  .tools-grid { grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); }
  .input-row { flex-direction: row; gap: 0.75rem; }
  .result-grid { grid-template-columns: 1fr 1fr; }
}

/* --- Print --- */
@media print {
  .site-header, .site-footer, .ad-slot, .theme-toggle, .share-section { display: none; }
  body { background: #fff; color: #000; }
  .calc-card { border: 1px solid #ccc; box-shadow: none; }
  .result-box { background: #f8f8f8; border-color: #ccc; }
  .breakdown-table th { background: #eee; }
  .breakdown-table td, .breakdown-table th { border-color: #ccc; }
}
