/* ═══════════════════════════════════════════
   style.css — Matrix Multiplication Calculator
   matrixmultiplicationcalculator.net
═══════════════════════════════════════════ */

/* ── Reset & Tokens ── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg:            #f5f6f8;
  --surface:       #ffffff;
  --surface-2:     #f0f2f7;
  --surface-3:     #e8ecf7;
  --border:        #dde1ee;
  --border-strong: #c4cae2;
  --focus:         #3a5cf5;
  --text:          #141928;
  --text-2:        #4a5070;
  --text-3:        #7a82a0;
  --accent:        #3a5cf5;
  --accent-h:      #2946d8;
  --accent-bg:     #eef1fe;
  --green:         #10b981;
  --green-bg:      #ecfdf5;
  --green-bdr:     #a7f3d0;
  --green-txt:     #064e3b;
  --amber-bg:      #fffbeb;
  --amber-bdr:     #fde68a;
  --amber-txt:     #78350f;
  --danger:        #ef4444;
  --shadow:        0 1px 3px rgba(20,25,40,.06), 0 1px 2px rgba(20,25,40,.04);
  --r:             14px;
  --r-sm:          8px;
  --r-xs:          6px;
  --sans:          'DM Sans', system-ui, sans-serif;
  --mono:          'DM Mono', monospace;
}

html { scroll-behavior: smooth; }

body {
  background: var(--bg);
  color: var(--text);
  font-family: var(--sans);
  font-size: 16px;
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
}

/* ── Layout ── */
.site-wrap {
  max-width: 860px;
  margin: 0 auto;
  padding: 0 16px 80px;
}

/* ── Nav ── */
.site-nav {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 0;
  border-bottom: 1px solid var(--border);
}

.nav-brand {
  font-size: 0.88rem;
  font-weight: 700;
  color: var(--accent);
  text-decoration: none;
}

.nav-links { display: flex; gap: 20px; list-style: none; }
.nav-links a {
  font-size: 0.82rem;
  font-weight: 500;
  color: var(--text-3);
  text-decoration: none;
  transition: color .15s;
}
.nav-links a:hover { color: var(--accent); }

/* ── Header ── */
.site-header { padding: 32px 0 24px; text-align: center; }

.site-header h1 {
  font-size: clamp(1.6rem, 5vw, 2.25rem);
  font-weight: 700;
  letter-spacing: -0.03em;
  color: var(--text);
  line-height: 1.2;
}

.site-header h1 em { font-style: normal; color: var(--accent); }
.site-header .sub { margin-top: 8px; color: var(--text-2); font-size: 0.95rem; }

.feature-pills {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 6px;
  margin-top: 14px;
}

.pill {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 99px;
  padding: 4px 12px;
  font-size: 0.78rem;
  font-weight: 500;
  color: var(--text-2);
}

/* ── Card ── */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r);
  box-shadow: var(--shadow);
  padding: 24px;
  width: 100%;
}

.card + .card { margin-top: 18px; }

.card-label {
  font-size: 0.72rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-3);
  margin-bottom: 16px;
}

/* ── Setup ── */
.setup-row { display: flex; flex-wrap: wrap; gap: 14px; align-items: flex-end; }

.field { display: flex; flex-direction: column; gap: 5px; }
.field label { font-size: 0.8rem; font-weight: 500; color: var(--text-2); }

select, input[type="number"], input[type="text"] {
  height: 40px;
  padding: 0 12px;
  border: 1.5px solid var(--border);
  border-radius: var(--r-xs);
  font-family: var(--sans);
  font-size: 0.9rem;
  color: var(--text);
  background: var(--surface);
  outline: none;
  transition: border-color .15s, box-shadow .15s;
}

select {
  appearance: none;
  -webkit-appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%237a82a0' stroke-width='2.5' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpolyline points='6 9 12 15 18 9'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 10px center;
  padding-right: 30px;
  cursor: pointer;
}

select:focus, input:focus {
  border-color: var(--focus);
  box-shadow: 0 0 0 3px rgba(58,92,245,.12);
}

.size-pair { display: flex; align-items: center; gap: 6px; }
.size-pair input { width: 58px; text-align: center; }
.size-sep { font-weight: 600; color: var(--text-3); }
.sizes-wrap { display: flex; flex-wrap: wrap; gap: 14px; }

/* ── Dim status ── */
.dim-warn {
  display: none; align-items: center; gap: 8px;
  background: var(--amber-bg); border: 1px solid var(--amber-bdr);
  color: var(--amber-txt); border-radius: var(--r-xs);
  padding: 10px 14px; font-size: 0.85rem; margin-top: 14px;
}
.dim-warn.on { display: flex; }

.dim-ok {
  display: none; align-items: center; gap: 8px;
  background: var(--green-bg); border: 1px solid var(--green-bdr);
  color: var(--green-txt); border-radius: var(--r-xs);
  padding: 10px 14px; font-size: 0.85rem; margin-top: 14px;
}
.dim-ok.on { display: flex; }

/* ── Matrix grid ── */
.matrices-scroll { overflow-x: auto; padding-bottom: 4px; -webkit-overflow-scrolling: touch; }
.matrices-row { display: flex; align-items: center; min-width: min-content; }
.matrix-block { display: flex; flex-direction: column; align-items: center; gap: 6px; }
.matrix-lbl { font-size: 0.78rem; font-weight: 600; color: var(--text-3); letter-spacing: .04em; }
.bracket-wrap { display: flex; align-items: stretch; }
.bracket { display: flex; align-items: center; padding: 2px; }
.bracket svg { height: 100%; min-height: 36px; }
.cell-grid { display: grid; gap: 4px; padding: 4px 0; }

.cell {
  width: 52px; height: 40px;
  border: 1.5px solid var(--border); border-radius: var(--r-xs);
  text-align: center; font-family: var(--mono); font-size: 0.88rem;
  font-weight: 500; color: var(--text); background: var(--surface-2);
  outline: none; transition: border-color .15s, box-shadow .15s, background .15s;
  -moz-appearance: textfield;
}
.cell::-webkit-inner-spin-button, .cell::-webkit-outer-spin-button { -webkit-appearance: none; }
.cell:focus { border-color: var(--focus); background: var(--surface); box-shadow: 0 0 0 3px rgba(58,92,245,.12); }

.matrix-op {
  display: flex; align-items: center; padding: 0 14px;
  font-size: 1.5rem; font-weight: 300; color: var(--text-3);
  user-select: none; flex-shrink: 0;
}

.matrix-dim-tag { font-size: 0.72rem; color: var(--text-3); font-family: var(--mono); text-align: center; }

/* ── Buttons ── */
.btn {
  display: inline-flex; align-items: center; justify-content: center;
  gap: 6px; height: 42px; padding: 0 22px; border: none;
  border-radius: var(--r-xs); font-family: var(--sans); font-size: 0.9rem;
  font-weight: 600; cursor: pointer;
  transition: background .15s, transform .1s, box-shadow .15s;
  white-space: nowrap; outline: none;
}
.btn:active { transform: scale(0.97); }

.btn-primary { background: var(--accent); color: #fff; box-shadow: 0 2px 10px rgba(58,92,245,.28); }
.btn-primary:hover { background: var(--accent-h); box-shadow: 0 4px 14px rgba(58,92,245,.38); }

.btn-ghost { background: var(--surface-2); color: var(--text-2); border: 1.5px solid var(--border); }
.btn-ghost:hover { background: var(--surface-3); }

.btn-sm { height: 34px; padding: 0 14px; font-size: 0.82rem; }
.btn-row { display: flex; flex-wrap: wrap; gap: 10px; margin-top: 20px; align-items: center; }

/* ── Result ── */
.result-card {
  background: linear-gradient(135deg, #f0f3ff 0%, #fafbff 100%);
  border: 1.5px solid #c7d0fb; border-radius: var(--r); padding: 24px; margin-top: 18px;
}
.result-top { display: flex; align-items: center; gap: 10px; margin-bottom: 18px; flex-wrap: wrap; }
.result-title { font-size: 0.72rem; font-weight: 600; text-transform: uppercase; letter-spacing: .08em; color: var(--text-3); }

.badge-success {
  display: inline-flex; align-items: center; gap: 5px;
  background: var(--green-bg); border: 1px solid var(--green-bdr);
  color: var(--green-txt); border-radius: 99px; padding: 3px 11px;
  font-size: 0.78rem; font-weight: 600;
}

.equation-label { font-size: 0.88rem; font-weight: 600; color: var(--text-2); white-space: nowrap; padding-right: 12px; font-family: var(--mono); }
.result-row { display: flex; align-items: center; flex-wrap: wrap; gap: 8px; }
.result-bracket-wrap { display: flex; align-items: stretch; }
.result-grid { display: grid; gap: 4px; padding: 4px 0; }

.result-cell {
  min-width: 56px; height: 40px; padding: 0 8px; border-radius: var(--r-xs);
  display: flex; align-items: center; justify-content: center;
  font-family: var(--mono); font-size: 0.9rem; font-weight: 500;
  background: #dde4fd; border: 1.5px solid #b4c0fb; color: #2338a8;
}

/* ── Steps ── */
.steps-wrap { margin-top: 14px; }

.steps-toggle {
  width: 100%; display: flex; align-items: center; gap: 8px;
  padding: 12px 16px; background: var(--surface-2); border: 1px solid var(--border);
  border-radius: var(--r-xs); font-family: var(--sans); font-size: 0.88rem;
  font-weight: 600; color: var(--text); cursor: pointer; text-align: left; transition: background .15s;
}
.steps-toggle:hover { background: var(--surface-3); }
.steps-toggle .chev { transition: transform .2s; margin-left: auto; }
.steps-toggle.open .chev { transform: rotate(180deg); }

.steps-body {
  display: none; background: var(--surface); border: 1px solid var(--border);
  border-top: none; border-radius: 0 0 var(--r-xs) var(--r-xs); padding: 20px; overflow-x: auto;
}
.steps-body.open { display: block; }

.step-block { margin-bottom: 22px; }
.step-block:last-child { margin-bottom: 0; }
.step-heading { font-size: 0.78rem; font-weight: 600; text-transform: uppercase; letter-spacing: .06em; color: var(--text-3); margin-bottom: 10px; }
.step-desc { font-size: 0.82rem; color: var(--text-3); margin-bottom: 8px; font-style: italic; }

.step-table { border-collapse: collapse; font-family: var(--mono); font-size: 0.85rem; }
.step-table td { padding: 4px 8px 4px 0; vertical-align: middle; white-space: nowrap; color: var(--text-2); }
.step-table .idx { color: var(--accent); font-weight: 500; min-width: 72px; }
.step-table .eq  { color: var(--text-3); padding: 4px 10px; }
.step-table .ans { color: var(--text); font-weight: 600; padding-left: 10px; }

/* ── Content sections ── */
.content-section {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--r); padding: 32px 28px; margin-top: 18px;
}
.content-section h2 { font-size: 1.25rem; font-weight: 700; letter-spacing: -0.02em; color: var(--text); margin-bottom: 14px; line-height: 1.3; }
.content-section h3 { font-size: 1rem; font-weight: 600; color: var(--text); margin: 22px 0 10px; }
.content-section p { color: var(--text-2); font-size: 0.95rem; line-height: 1.75; margin-bottom: 12px; }
.content-section p:last-child { margin-bottom: 0; }
.content-section ul, .content-section ol { padding-left: 20px; color: var(--text-2); font-size: 0.95rem; line-height: 1.75; margin-bottom: 12px; }
.content-section li { margin-bottom: 4px; }

.rule-box { background: var(--accent-bg); border: 1.5px solid #c7d0fb; border-radius: var(--r-sm); padding: 16px 20px; margin: 18px 0; }
.rule-box strong { display: block; font-size: 1rem; font-weight: 700; color: var(--accent); margin-bottom: 6px; font-family: var(--mono); }
.rule-box p { margin: 0; color: var(--text-2); font-size: 0.9rem; }

.example-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); gap: 16px; margin: 16px 0; }
.example-box { background: var(--surface-2); border: 1px solid var(--border); border-radius: var(--r-sm); padding: 16px; }
.example-box h4 { font-size: 0.78rem; font-weight: 600; text-transform: uppercase; letter-spacing: .07em; color: var(--text-3); margin-bottom: 12px; }
.mono-block { font-family: var(--mono); font-size: 0.85rem; color: var(--text); line-height: 2; }
.mono-block .hi { color: var(--accent); font-weight: 600; }

.formula-steps { display: flex; flex-direction: column; gap: 6px; font-family: var(--mono); font-size: 0.85rem; background: var(--surface-2); border: 1px solid var(--border); border-radius: var(--r-sm); padding: 16px; margin: 14px 0; color: var(--text-2); }
.formula-steps .line { display: flex; align-items: baseline; gap: 8px; }
.formula-steps .lbl { color: var(--accent); min-width: 80px; font-weight: 500; }
.formula-steps .val { color: var(--text); }

.dim-table { width: 100%; border-collapse: collapse; font-size: 0.88rem; margin: 14px 0; }
.dim-table th { text-align: left; padding: 8px 12px; background: var(--surface-2); color: var(--text-3); font-size: 0.75rem; font-weight: 600; text-transform: uppercase; letter-spacing: .06em; border-bottom: 1px solid var(--border); }
.dim-table td { padding: 9px 12px; border-bottom: 1px solid var(--border); color: var(--text-2); font-family: var(--mono); font-size: 0.85rem; }
.dim-table tr:last-child td { border-bottom: none; }
.dim-table .ok { color: var(--green); font-weight: 600; }
.dim-table .no { color: var(--danger); font-weight: 600; }

.faq-list { list-style: none; padding: 0; margin: 0; }
.faq-item { border-bottom: 1px solid var(--border); }
.faq-item:last-child { border-bottom: none; }
.faq-q { width: 100%; display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 16px 0; background: none; border: none; font-family: var(--sans); font-size: 0.95rem; font-weight: 600; color: var(--text); cursor: pointer; text-align: left; }
.faq-q svg { flex-shrink: 0; transition: transform .2s; color: var(--text-3); }
.faq-item.open .faq-q svg { transform: rotate(180deg); }
.faq-a { display: none; padding: 0 0 16px; font-size: 0.9rem; color: var(--text-2); line-height: 1.75; }
.faq-item.open .faq-a { display: block; }

.related-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 10px; margin-top: 14px; }
.related-card { display: flex; align-items: center; gap: 10px; background: var(--surface-2); border: 1px solid var(--border); border-radius: var(--r-sm); padding: 12px 14px; text-decoration: none; transition: background .15s, border-color .15s; }
.related-card:hover { background: var(--surface-3); border-color: var(--border-strong); }
.related-icon { width: 34px; height: 34px; border-radius: var(--r-xs); background: var(--accent-bg); display: flex; align-items: center; justify-content: center; flex-shrink: 0; color: var(--accent); }
.related-label { font-size: 0.85rem; font-weight: 600; color: var(--text); }
.related-sub { font-size: 0.75rem; color: var(--text-3); }

/* ── Footer ── */
.site-footer { border-top: 1px solid var(--border); margin-top: 48px; padding: 24px 0; display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 10px; }
.footer-copy { font-size: 0.82rem; color: var(--text-3); }
.footer-links { display: flex; gap: 16px; list-style: none; }
.footer-links a { font-size: 0.82rem; color: var(--text-3); text-decoration: none; transition: color .15s; }
.footer-links a:hover { color: var(--accent); }

/* ── Policy pages ── */
.policy-wrap { max-width: 740px; margin: 0 auto; padding: 0 16px 80px; }
.policy-header { padding: 36px 0 28px; border-bottom: 1px solid var(--border); margin-bottom: 32px; }
.policy-header h1 { font-size: clamp(1.5rem, 4vw, 2rem); font-weight: 700; letter-spacing: -0.025em; color: var(--text); }
.policy-header .meta { margin-top: 6px; font-size: 0.85rem; color: var(--text-3); }
.policy-body h2 { font-size: 1.1rem; font-weight: 700; color: var(--text); margin: 32px 0 10px; }
.policy-body h2:first-child { margin-top: 0; }
.policy-body p, .policy-body li { font-size: 0.95rem; color: var(--text-2); line-height: 1.8; margin-bottom: 12px; }
.policy-body ul, .policy-body ol { padding-left: 22px; margin-bottom: 14px; }
.policy-body a { color: var(--accent); text-decoration: none; }
.policy-body a:hover { text-decoration: underline; }
.policy-body .highlight-box { background: var(--accent-bg); border-left: 3px solid var(--accent); border-radius: 0 var(--r-xs) var(--r-xs) 0; padding: 14px 18px; margin: 18px 0; font-size: 0.9rem; color: var(--text-2); }

/* ── Responsive ── */
@media (max-width: 600px) {
  .card { padding: 16px; }
  .result-card { padding: 16px; }
  .content-section { padding: 22px 18px; }
  .cell { width: 44px; height: 36px; font-size: 0.82rem; }
  .result-cell { min-width: 48px; height: 36px; font-size: 0.82rem; }
  .matrix-op { padding: 0 8px; font-size: 1.2rem; }
  .site-nav { flex-direction: column; gap: 10px; align-items: flex-start; }
}

@media (max-width: 380px) {
  .cell { width: 38px; height: 34px; font-size: 0.78rem; }
  .result-cell { min-width: 42px; height: 34px; font-size: 0.78rem; }
}