/* ============================================================
   Aspect Ratio & viewBox Calculator — styles
   Dark, utilitarian developer-tool aesthetic.
   ============================================================ */

:root {
  --bg: #0d1117;
  --bg-raise: #141b24;
  --bg-inset: #0a0e13;
  --line: #232c38;
  --line-soft: #1b2330;
  --text: #dbe4ee;
  --text-dim: #8b98a9;
  --text-faint: #5b6776;
  --accent: #5ac8fa;
  --accent-deep: #2b8fc7;
  --accent-soft: rgba(90, 200, 250, 0.12);
  --good: #4ade80;
  --warn: #fbbf24;
  --err: #f87171;
  --mono: "SF Mono", ui-monospace, "Cascadia Code", Menlo, Consolas, monospace;
  --sans: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --radius: 10px;
  --radius-sm: 7px;
  --focus-ring: 0 0 0 2px var(--bg), 0 0 0 4px var(--accent);
}

* { box-sizing: border-box; }

html, body { overflow-x: clip; }

html { color-scheme: dark; }

body {
  margin: 0;
  background:
    radial-gradient(1200px 500px at 80% -10%, rgba(90, 200, 250, 0.05), transparent 60%),
    var(--bg);
  color: var(--text);
  font-family: var(--sans);
  font-size: 16px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

.mono {
  font-family: var(--mono);
  font-variant-numeric: tabular-nums;
  letter-spacing: -0.01em;
}

.wrap { max-width: 1180px; margin: 0 auto; padding: 0 20px; }

/* ---------- header ---------- */

.site-head {
  border-bottom: 1px solid var(--line-soft);
  padding: 26px 0 22px;
  margin-bottom: 26px;
}
.brand { display: flex; align-items: center; gap: 14px; }
.brand-mark { width: 42px; height: 24px; color: var(--accent); flex: none; }
h1 {
  margin: 0;
  font-size: 1.32rem;
  font-weight: 650;
  letter-spacing: -0.015em;
}
.amp { color: var(--accent); font-weight: 400; }
.tagline { margin: 2px 0 0; color: var(--text-dim); font-size: 0.86rem; }

/* ---------- workbench panes ---------- */

.workbench {
  display: grid;
  grid-template-columns: minmax(0, 5fr) minmax(0, 6fr);
  gap: 18px;
  align-items: start;
}

.pane {
  background: var(--bg-raise);
  border: 1px solid var(--line-soft);
  border-radius: var(--radius);
  padding: 20px;
}

.pane-title {
  display: flex;
  align-items: center;
  gap: 10px;
  margin: 0 0 16px;
  font-size: 0.78rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.09em;
  color: var(--text-dim);
}
.pane-num {
  display: inline-grid;
  place-items: center;
  width: 20px;
  height: 20px;
  border-radius: 6px;
  background: var(--accent-soft);
  color: var(--accent);
  font-family: var(--mono);
  font-size: 0.72rem;
}

/* ---------- input fields ---------- */

.field-row { display: flex; align-items: flex-start; gap: 10px; }
.field { flex: 1; min-width: 0; }
.field-sep { color: var(--text-faint); padding-top: 30px; font-size: 1.05rem; }

label {
  display: block;
  font-size: 0.78rem;
  font-weight: 600;
  color: var(--text-dim);
  margin-bottom: 6px;
  letter-spacing: 0.02em;
}

input {
  width: 100%;
  background: var(--bg-inset);
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  color: var(--text);
  font-family: var(--mono);
  font-variant-numeric: tabular-nums;
  font-size: 1.02rem;
  padding: 10px 12px;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}
input::placeholder { color: var(--text-faint); }
input:hover { border-color: #2e3a4a; }
input:focus { outline: none; border-color: var(--accent-deep); box-shadow: var(--focus-ring); }
input[aria-invalid="true"] { border-color: var(--err); }
input[aria-invalid="true"]:focus { box-shadow: 0 0 0 2px var(--bg), 0 0 0 4px var(--err); }

.field-err {
  margin: 6px 0 0;
  font-size: 0.78rem;
  color: var(--err);
}

/* ---------- presets ---------- */

.presets { margin-top: 18px; }
.presets-label {
  display: block;
  font-size: 0.78rem;
  font-weight: 600;
  color: var(--text-dim);
  margin-bottom: 8px;
}
.preset-row { display: flex; flex-wrap: wrap; gap: 7px; }

.preset-btn {
  background: var(--bg-inset);
  border: 1px solid var(--line);
  border-radius: 999px;
  color: var(--text-dim);
  font-family: var(--mono);
  font-size: 0.82rem;
  padding: 6px 13px;
  cursor: pointer;
  transition: color 0.15s, border-color 0.15s, background 0.15s, transform 0.1s;
}
.preset-btn:hover { color: var(--text); border-color: #344254; }
.preset-btn:active { transform: scale(0.97); }
.preset-btn:focus-visible { outline: none; box-shadow: var(--focus-ring); }
.preset-btn[aria-pressed="true"] {
  background: var(--accent-soft);
  border-color: var(--accent-deep);
  color: var(--accent);
}

/* ---------- preview ---------- */

.preview-block { margin-top: 22px; }
.preview-head {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  margin-bottom: 8px;
}
.preview-title { font-size: 0.78rem; font-weight: 600; color: var(--text-dim); }
.preview-dims { font-size: 0.8rem; color: var(--text-faint); }

.preview-stage {
  position: relative;
  background:
    linear-gradient(var(--line-soft) 1px, transparent 1px) 0 0 / 24px 24px,
    linear-gradient(90deg, var(--line-soft) 1px, transparent 1px) 0 0 / 24px 24px,
    var(--bg-inset);
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  height: 240px;
  resize: vertical;
  overflow: hidden;
  min-height: 120px;
  max-height: 480px;
  display: grid;
  place-items: center;
  padding: 18px;
}

.preview-box {
  position: relative;
  max-width: 100%;
  max-height: 100%;
  background: linear-gradient(160deg, rgba(90, 200, 250, 0.22), rgba(43, 143, 199, 0.10));
  border: 1.5px solid var(--accent);
  border-radius: 4px;
  display: grid;
  place-items: center;
  transition: width 0.35s cubic-bezier(0.22, 1, 0.36, 1),
              height 0.35s cubic-bezier(0.22, 1, 0.36, 1);
  will-change: width, height;
}
.preview-box::after {
  content: "";
  position: absolute;
  inset: 0;
  background:
    linear-gradient(var(--accent) 0 0) top left / 10px 1.5px,
    linear-gradient(var(--accent) 0 0) top left / 1.5px 10px,
    linear-gradient(var(--accent) 0 0) bottom right / 10px 1.5px,
    linear-gradient(var(--accent) 0 0) bottom right / 1.5px 10px;
  background-repeat: no-repeat;
  opacity: 0.9;
}
.preview-ratio {
  font-size: 0.95rem;
  font-weight: 600;
  color: var(--accent);
  background: rgba(13, 17, 23, 0.75);
  padding: 3px 9px;
  border-radius: 999px;
  backdrop-filter: blur(2px);
  white-space: nowrap;
}
.preview-note {
  margin: 8px 0 0;
  font-size: 0.76rem;
  color: var(--text-faint);
}

/* ---------- ratio readout ---------- */

.ratio-readout {
  margin-top: 18px;
  border-top: 1px dashed var(--line);
  padding-top: 12px;
  display: grid;
  gap: 6px;
}
.rr-row { display: flex; justify-content: space-between; gap: 12px; align-items: baseline; }
.rr-key { font-size: 0.8rem; color: var(--text-dim); flex: none; }
.rr-val { font-size: 0.86rem; color: var(--text); text-align: right; overflow-wrap: anywhere; }

/* ---------- output pane ---------- */

.pct-hero {
  background: var(--bg-inset);
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  padding: 14px 16px;
  margin-bottom: 16px;
}
.pct-main { display: flex; justify-content: space-between; align-items: baseline; gap: 12px; }
.pct-label { font-size: 0.8rem; color: var(--text-dim); font-family: var(--mono); }
.pct-value { font-size: 1.7rem; font-weight: 650; color: var(--accent); }
.pct-exact-row {
  display: flex;
  gap: 8px;
  align-items: baseline;
  margin-top: 4px;
  overflow-wrap: anywhere;
}
.pct-exact-label { font-size: 0.72rem; color: var(--text-faint); text-transform: uppercase; letter-spacing: 0.08em; flex: none; }
.pct-exact { font-size: 0.82rem; color: var(--text-dim); overflow-wrap: anywhere; }
.pct-drift {
  margin: 8px 0 0;
  font-size: 0.78rem;
  color: var(--warn);
  border-top: 1px dashed var(--line);
  padding-top: 8px;
}

.snippet {
  background: var(--bg-inset);
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  margin-bottom: 12px;
  overflow: hidden;
  transition: border-color 0.4s ease, box-shadow 0.4s ease;
}
.snippet.flash {
  border-color: var(--accent-deep);
  box-shadow: 0 0 0 1px var(--accent-deep), 0 0 18px rgba(90, 200, 250, 0.12);
}
.snippet-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 8px 10px 8px 14px;
  border-bottom: 1px solid var(--line-soft);
}
.snippet-name { font-size: 0.78rem; font-weight: 600; color: var(--text-dim); }
.snippet-name code { font-family: var(--mono); font-size: 0.76rem; }
.snippet-code {
  margin: 0;
  padding: 12px 14px;
  font-size: 0.8rem;
  line-height: 1.55;
  overflow-x: auto;
  color: #a9d8f0;
  white-space: pre;
}

.copy-btn {
  flex: none;
  min-width: 64px;
  min-height: 30px;
  background: transparent;
  border: 1px solid var(--line);
  border-radius: 6px;
  color: var(--text-dim);
  font-family: var(--sans);
  font-size: 0.76rem;
  font-weight: 600;
  cursor: pointer;
  transition: color 0.15s, border-color 0.15s, background 0.15s;
}
.copy-btn:hover { color: var(--text); border-color: #344254; background: rgba(255, 255, 255, 0.03); }
.copy-btn:focus-visible { outline: none; box-shadow: var(--focus-ring); }
.copy-btn.copied {
  color: var(--good);
  border-color: rgba(74, 222, 128, 0.5);
  background: rgba(74, 222, 128, 0.08);
}

/* ---------- reverse mode ---------- */

.reverse, .reference {
  margin-top: 18px;
  background: var(--bg-raise);
  border: 1px solid var(--line-soft);
  border-radius: var(--radius);
  padding: 20px;
}
.rev-sub { margin: -8px 0 16px; font-size: 0.84rem; color: var(--text-dim); }
.rev-sub code { font-size: 0.78rem; background: var(--bg-inset); padding: 1px 6px; border-radius: 4px; border: 1px solid var(--line-soft); }

.rev-grid {
  display: grid;
  grid-template-columns: minmax(0, 1.2fr) minmax(0, 1fr) minmax(0, 1.2fr);
  gap: 14px;
  align-items: start;
}
.rev-result {
  background: var(--bg-inset);
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  padding: 10px 14px;
  display: grid;
  gap: 2px;
  align-self: start;
  margin-top: 24px;
  transition: border-color 0.4s ease, box-shadow 0.4s ease;
}
.rev-result.flash { border-color: var(--accent-deep); box-shadow: 0 0 0 1px var(--accent-deep); }
.rev-result-label { font-size: 0.72rem; color: var(--text-faint); text-transform: uppercase; letter-spacing: 0.08em; }
.rev-result-value { font-size: 1.35rem; font-weight: 650; color: var(--accent); overflow-wrap: anywhere; }
.rev-result-dims { font-size: 0.8rem; color: var(--text-dim); overflow-wrap: anywhere; }

/* ---------- reference table ---------- */

.table-scroll { overflow-x: auto; }
.ref-table { width: 100%; border-collapse: collapse; font-size: 0.86rem; }
.ref-table th {
  text-align: left;
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-faint);
  font-weight: 600;
  padding: 8px 12px;
  border-bottom: 1px solid var(--line);
}
.ref-table th.num, .ref-table td.num { text-align: right; }
.ref-table td {
  padding: 8px 12px;
  border-bottom: 1px solid var(--line-soft);
  color: var(--text-dim);
}
.ref-table tbody tr { cursor: pointer; transition: background 0.12s; }
.ref-table tbody tr:hover { background: rgba(90, 200, 250, 0.05); }
.ref-table tbody tr:last-child td { border-bottom: none; }
.ref-table td.ratio-cell { color: var(--text); font-weight: 600; }
.ref-shape {
  display: inline-block;
  border: 1.5px solid var(--accent-deep);
  background: rgba(90, 200, 250, 0.15);
  border-radius: 2px;
  vertical-align: middle;
}

/* ---------- footer / toast ---------- */

.site-foot {
  margin: 26px 0 40px;
  color: var(--text-faint);
  font-size: 0.8rem;
  border-top: 1px solid var(--line-soft);
  padding-top: 16px;
}

.toast {
  position: fixed;
  left: 50%;
  bottom: 26px;
  transform: translate(-50%, 12px);
  background: #17202b;
  border: 1px solid var(--accent-deep);
  color: var(--accent);
  font-size: 0.82rem;
  padding: 9px 16px;
  border-radius: 999px;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s ease, transform 0.2s ease;
  box-shadow: 0 8px 30px rgba(0, 0, 0, 0.45);
  z-index: 50;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }

/* ---------- responsive ---------- */

@media (max-width: 900px) {
  .workbench { grid-template-columns: 1fr; }
  .rev-grid { grid-template-columns: 1fr 1fr; }
  .rev-result { grid-column: 1 / -1; margin-top: 0; }
}

@media (max-width: 560px) {
  .wrap { padding: 0 14px; }
  .site-head { padding: 20px 0 16px; }
  h1 { font-size: 1.12rem; }
  .pane, .reverse, .reference { padding: 16px 14px; }
  .rev-grid { grid-template-columns: 1fr; }
  .preview-stage { height: 200px; }
  .pct-value { font-size: 1.45rem; }
  .copy-btn { min-height: 40px; min-width: 76px; font-size: 0.84rem; }
  .preset-btn { padding: 8px 14px; font-size: 0.86rem; }
  input { font-size: 1rem; padding: 12px; }
  .snippet-code { font-size: 0.76rem; }
}

@media (prefers-reduced-motion: reduce) {
  .preview-box { transition: none; }
  .snippet, .rev-result { transition: none; }
  .toast { transition: opacity 0.2s ease; }
}
