/* =========================================================
   Aacoustic — Modern white theme (calculators)
   Shared by calc_db, calc_dist and tiers_en_bande
   ========================================================= */

:root {
  /* Colors */
  --color-bg: #ffffff;
  --color-surface: #ffffff;
  --color-surface-subtle: #f8fafc;
  --color-surface-soft: #f1f5f9;
  --color-border: #e2e8f0;
  --color-border-strong: #cbd5e1;

  --color-text: #0f172a;
  --color-text-muted: #475569;
  --color-text-soft: #64748b;

  --color-primary: #2563eb;
  --color-primary-hover: #1d4ed8;
  --color-primary-soft: #eff6ff;
  --color-accent: #0ea5e9;
  --color-success: #10b981;
  --color-success-hover: #059669;
  --color-danger: #dc2626;
  --color-danger-soft: #fef2f2;

  /* Effects */
  --shadow-sm: 0 1px 2px rgba(15, 23, 42, 0.05);
  --shadow-md: 0 4px 16px rgba(15, 23, 42, 0.06);
  --shadow-lg: 0 12px 32px rgba(15, 23, 42, 0.08);
  --ring: 0 0 0 3px rgba(37, 99, 235, 0.20);
  --ring-success: 0 0 0 3px rgba(16, 185, 129, 0.20);

  /* Geometry */
  --radius-sm: 8px;
  --radius-md: 12px;
  --radius-lg: 18px;

  /* Motion */
  --ease: cubic-bezier(0.4, 0, 0.2, 1);
}

* { box-sizing: border-box; }

html, body { height: 100%; }

body {
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto,
    'Helvetica Neue', Arial, sans-serif;
  background-color: var(--color-surface-subtle);
  color: var(--color-text);
  margin: 0;
  padding: 0;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

img { max-width: 100%; height: auto; display: block; }

/* =========================================================
   Header
   ========================================================= */
.header {
  background: linear-gradient(180deg, var(--color-surface) 0%, var(--color-surface-subtle) 100%);
  color: var(--color-text);
  border-bottom: 1px solid var(--color-border);
  padding: 18px clamp(16px, 4vw, 40px);
  position: sticky;
  top: 0;
  z-index: 10;
  backdrop-filter: saturate(180%) blur(8px);
  box-shadow: var(--shadow-sm);
}

.header-content {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 16px;
  flex-wrap: wrap;
  max-width: 1180px;
  margin: 0 auto;
}

.header h1 {
  margin: 0;
  font-size: clamp(1.05rem, 2.2vw, 1.4rem);
  font-weight: 700;
  letter-spacing: -0.01em;
  color: var(--color-text);
}

.header nav {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  align-items: center;
}

.nav-button {
  background-color: var(--color-surface);
  color: var(--color-text);
  padding: 8px 14px;
  border-radius: var(--radius-sm);
  text-decoration: none;
  font-size: 0.9rem;
  font-weight: 500;
  border: 1px solid var(--color-border);
  transition: background-color 0.2s var(--ease), color 0.2s var(--ease),
    border-color 0.2s var(--ease), transform 0.15s var(--ease);
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.nav-button:hover {
  background-color: var(--color-primary-soft);
  color: var(--color-primary);
  border-color: var(--color-primary);
}

.nav-button:focus-visible {
  outline: none;
  box-shadow: var(--ring);
  border-color: var(--color-primary);
}

.nav-button:active { transform: translateY(1px); }

.home-icon {
  height: 22px;
  width: 22px;
  display: inline-block;
}

/* =========================================================
   Layout
   ========================================================= */
.container {
  width: 100%;
  max-width: 880px;
  margin: 32px auto;
  padding: 0 clamp(16px, 4vw, 24px);
}

/* =========================================================
   Cards
   ========================================================= */
.card {
  background-color: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sm);
  padding: clamp(20px, 3vw, 32px);
  margin-bottom: 24px;
  transition: box-shadow 0.25s var(--ease);
}

.card:hover { box-shadow: var(--shadow-md); }

.card h2 {
  margin: 0 0 16px;
  font-size: 1.15rem;
  font-weight: 600;
  color: var(--color-text);
  letter-spacing: -0.005em;
  display: flex;
  align-items: center;
  gap: 10px;
}

.card h2::before {
  content: "";
  width: 4px;
  height: 18px;
  background: linear-gradient(180deg, var(--color-primary), var(--color-accent));
  border-radius: 2px;
}

/* Math formula display — clean, borderless, centered */
.formula {
  padding: 4px 0;
  color: var(--color-text);
  text-align: center;
  font-size: 1.05rem;
}

.formula > p:first-child {
  color: var(--color-text-soft);
  font-size: 0.88rem;
  font-weight: 500;
  margin: 0 0 8px;
  text-align: left;
  letter-spacing: 0.02em;
  text-transform: uppercase;
}

.formula p { margin: 0; }
.formula p + p { margin-top: 8px; }
.formula mjx-container { margin: 0 auto !important; }

/* =========================================================
   Forms
   ========================================================= */
.form-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
  align-items: end;
}

.form-grid > div { display: flex; flex-direction: column; min-width: 0; }

.form-grid.stacked { grid-template-columns: 1fr; }

label {
  display: block;
  width: 100%;
  font-size: 0.88rem;
  font-weight: 500;
  color: var(--color-text-muted);
  margin-bottom: 6px;
}

input {
  display: block;
  width: 100%;
  padding: 10px 14px;
  border: 1px solid var(--color-border);
  border-radius: var(--radius-sm);
  font-family: inherit;
  font-size: 0.95rem;
  color: var(--color-text);
  background-color: var(--color-surface);
  transition: border-color 0.2s var(--ease), box-shadow 0.2s var(--ease);
  -moz-appearance: textfield;
}

input::placeholder { color: var(--color-text-soft); }

input:hover { border-color: var(--color-border-strong); }

input:focus {
  outline: none;
  border-color: var(--color-primary);
  box-shadow: var(--ring);
}

/* Hide number input spinners for a cleaner look */
input[type="number"]::-webkit-outer-spin-button,
input[type="number"]::-webkit-inner-spin-button {
  -webkit-appearance: none;
  margin: 0;
}

/* =========================================================
   Buttons
   ========================================================= */
.button-calc {
  background: linear-gradient(180deg, var(--color-primary) 0%, var(--color-primary-hover) 100%);
  color: white;
  padding: 11px 22px;
  border: none;
  border-radius: var(--radius-sm);
  font-family: inherit;
  font-size: 0.95rem;
  font-weight: 600;
  letter-spacing: 0.01em;
  cursor: pointer;
  transition: transform 0.15s var(--ease), box-shadow 0.2s var(--ease),
    filter 0.2s var(--ease);
  box-shadow: 0 2px 6px rgba(37, 99, 235, 0.25);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  margin-top: 8px;
}

.button-calc:hover {
  filter: brightness(1.05);
  box-shadow: 0 4px 14px rgba(37, 99, 235, 0.32);
  transform: translateY(-1px);
}

.button-calc:focus-visible {
  outline: none;
  box-shadow: var(--ring), 0 4px 14px rgba(37, 99, 235, 0.32);
}

.button-calc:active { transform: translateY(0); }

.full-width { grid-column: span 2; }

@media (max-width: 600px) {
  .form-grid { grid-template-columns: 1fr; }
  .full-width { grid-column: auto; }
}

/* =========================================================
   Results
   ========================================================= */
#result {
  font-size: 1.05rem;
  font-weight: 600;
  color: var(--color-text);
  padding: 14px 18px;
  background: var(--color-primary-soft);
  border: 1px solid #c7d2fe;
  border-radius: var(--radius-md);
  min-height: 50px;
  display: flex;
  align-items: center;
  word-break: break-word;
}

#history {
  margin-top: 18px;
  padding: 14px 18px;
  background: var(--color-surface-subtle);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  font-size: 0.88rem;
  color: var(--color-text-muted);
  max-height: 220px;
  overflow-y: auto;
  font-family: 'JetBrains Mono', ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  line-height: 1.55;
}

#history div { padding: 2px 0; }

#history strong {
  color: var(--color-primary);
  font-weight: 600;
}

#validationMessage {
  margin-top: 12px;
  padding: 10px 14px;
  background-color: var(--color-danger-soft);
  border: 1px solid #fecaca;
  border-radius: var(--radius-sm);
  color: var(--color-danger);
  font-size: 0.9rem;
  font-weight: 500;
}

#validationMessage:empty {
  display: none;
}

/* =========================================================
   Third-octave to Octave — card grid layout
   ========================================================= */
.octave-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
  gap: 14px;
}

.octave-card {
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  padding: 14px 16px;
  background: var(--color-surface-subtle);
  transition: border-color 0.2s var(--ease), box-shadow 0.2s var(--ease),
    background-color 0.2s var(--ease);
}

.octave-card.is-active {
  border-color: var(--color-primary);
  background: var(--color-surface);
  box-shadow: var(--shadow-sm);
}

.octave-card.has-error {
  border-color: var(--color-danger);
  background: var(--color-danger-soft);
}

.octave-card__header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 12px;
  padding-bottom: 10px;
  border-bottom: 1px dashed var(--color-border);
  gap: 10px;
}

.octave-card__title {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.octave-label {
  font-size: 0.7rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--color-text-soft);
}

.octave-freq {
  font-size: 1.15rem;
  font-weight: 700;
  color: var(--color-text);
  letter-spacing: -0.01em;
}

.octave-result {
  font-family: 'JetBrains Mono', ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 0.95rem;
  font-weight: 600;
  color: var(--color-primary);
  padding: 4px 12px;
  background: var(--color-primary-soft);
  border-radius: var(--radius-pill);
  white-space: nowrap;
  transition: opacity 0.2s var(--ease);
}

.octave-result.is-empty {
  color: var(--color-text-soft);
  background: transparent;
  border: 1px dashed var(--color-border);
}

.octave-result.is-error {
  color: var(--color-danger);
  background: transparent;
  border: 1px dashed #fecaca;
  font-family: inherit;
  font-size: 0.78rem;
  font-weight: 500;
  white-space: normal;
  text-align: center;
}

.octave-card__inputs {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
}

.third-input {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.third-input > span {
  font-size: 0.75rem;
  color: var(--color-text-soft);
  font-weight: 500;
  text-align: center;
}

.third-input input {
  padding: 8px 6px;
  text-align: center;
  font-size: 0.92rem;
  border-radius: var(--radius-sm);
  width: 100%;
}

/* Toolbar above the grid */
.octave-toolbar {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  margin-bottom: 14px;
  flex-wrap: wrap;
}

.button-ghost {
  background: transparent;
  color: var(--color-text-muted);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-sm);
  padding: 8px 14px;
  font-family: inherit;
  font-size: 0.88rem;
  font-weight: 500;
  cursor: pointer;
  transition: background-color 0.2s var(--ease), color 0.2s var(--ease),
    border-color 0.2s var(--ease);
}

.button-ghost:hover {
  background: var(--color-surface-soft);
  color: var(--color-text);
  border-color: var(--color-border-strong);
}

.button-ghost:focus-visible {
  outline: none;
  box-shadow: var(--ring);
  border-color: var(--color-primary);
}

/* =========================================================
   Responsive
   ========================================================= */
@media (max-width: 600px) {
  .header { padding: 14px 16px; border-radius: 0; }
  .header h1 { font-size: 1rem; }
  .nav-button { padding: 6px 10px; font-size: 0.85rem; }
  .container { margin: 20px auto; }
  .card { padding: 18px; margin-bottom: 16px; border-radius: 14px; }
  .button-calc { width: 100%; padding: 12px 16px; }
  .octave-grid { grid-template-columns: 1fr; gap: 10px; }
  .octave-card { padding: 12px 14px; }
  .octave-card__inputs { gap: 8px; }
  .third-input input { padding: 7px 4px; font-size: 0.88rem; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    transition: none !important;
    animation: none !important;
  }
}

/* =========================================================
   Tool actions (share) + theory section — roadmap §3, blocs 1 & 3
   ========================================================= */
.tool-actions {
  display: flex;
  justify-content: flex-end;
  margin: 4px 0 0;
}

.button-share {
  appearance: none;
  cursor: pointer;
  font: inherit;
  font-weight: 600;
  font-size: 0.92rem;
  color: var(--color-primary);
  background-color: var(--color-primary-soft);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-sm);
  padding: 8px 14px;
  transition: background-color 0.18s var(--ease), border-color 0.18s var(--ease),
    box-shadow 0.18s var(--ease);
}
.button-share:hover {
  border-color: var(--color-primary);
  background-color: #e0ecff;
}
.button-share:focus-visible {
  outline: none;
  box-shadow: var(--ring);
}

details.theory {
  padding: 0;
  overflow: hidden;
}
details.theory > summary {
  list-style: none;
  cursor: pointer;
  font-weight: 600;
  font-size: 1.05rem;
  color: var(--color-text);
  padding: 18px 22px;
  display: flex;
  align-items: center;
  gap: 10px;
  user-select: none;
}
details.theory > summary::-webkit-details-marker { display: none; }
details.theory > summary::before {
  content: "▸";
  color: var(--color-primary);
  font-size: 0.9em;
  transition: transform 0.18s var(--ease);
}
details.theory[open] > summary::before { transform: rotate(90deg); }
details.theory > summary:focus-visible {
  outline: none;
  box-shadow: var(--ring);
  border-radius: var(--radius-sm);
}
.theory-body {
  padding: 0 22px 20px;
  color: var(--color-text-muted);
  line-height: 1.6;
}
.theory-body p { margin: 0 0 12px; }
.theory-error {
  background-color: var(--color-danger-soft);
  border-left: 3px solid var(--color-danger);
  border-radius: var(--radius-sm);
  padding: 10px 14px;
  color: var(--color-text);
}

/* =========================================================
   Header: title group + discreet share button
   ========================================================= */
.header-title {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  min-width: 0;
}
.header-share {
  appearance: none;
  cursor: pointer;
  font: inherit;
  font-size: 0.82rem;
  font-weight: 600;
  color: var(--color-text-soft);
  background: none;
  border: none;
  padding: 5px 9px;
  border-radius: var(--radius-sm);
  display: inline-flex;
  align-items: center;
  gap: 5px;
  transition: color 0.15s var(--ease), background-color 0.15s var(--ease);
}
.header-share svg { display: block; }
.header-share:hover { color: var(--color-primary); background-color: var(--color-primary-soft); }
.header-share:focus-visible { outline: none; box-shadow: var(--ring); }
@media (max-width: 560px) {
  .header-share__label { display: none; }
}

/* App logo before the page title (matches the home page) */
.app-logo {
  width: 32px;
  height: 32px;
  flex-shrink: 0;
  border-radius: 8px;
  object-fit: contain;
  display: block;
}

/* Extra space below the last card so it is never clipped at the viewport bottom */
.container { margin-bottom: 96px; }

/* Small helper hint under an input */
.input-hint {
  display: block;
  margin-top: 6px;
  font-size: 0.8rem;
  color: var(--color-text-soft);
  line-height: 1.4;
}

/* Segmented control (source type) + select + secondary result */
.seg {
  display: inline-flex;
  border: 1px solid var(--color-border);
  border-radius: var(--radius-sm);
  overflow: hidden;
  background: var(--color-surface);
}
.seg-btn {
  appearance: none; cursor: pointer; font: inherit; font-weight: 600; font-size: 0.9rem;
  color: var(--color-text-muted); background: none; border: none; padding: 8px 16px;
  transition: background-color 0.15s var(--ease), color 0.15s var(--ease);
}
.seg-btn + .seg-btn { border-left: 1px solid var(--color-border); }
.seg-btn.is-active { background: var(--color-primary); color: #fff; }
.seg-btn:focus-visible { outline: none; box-shadow: var(--ring); }
.select-input {
  width: 100%; font: inherit; font-size: 1rem; padding: 10px 12px;
  border: 1px solid var(--color-border); border-radius: var(--radius-sm);
  background: var(--color-surface); color: var(--color-text); cursor: pointer;
}
.select-input:focus { outline: none; border-color: var(--color-primary); box-shadow: var(--ring); }
.result-sub { margin-top: 6px; font-size: 0.95rem; color: var(--color-text-muted); }
