:root {
  --paper: #f4f1e8;
  --paper-2: #eae6da;
  --ink: #171815;
  --muted: #676960;
  --line: #cbc7bb;
  --blue: #3157e1;
  --blue-soft: #dfe5ff;
  --good: #377b45;
  --bad: #a83b33;
  --card: rgba(255,255,255,.58);
  color-scheme: light;
}

html[data-theme="dark"] {
  --paper: #171916;
  --paper-2: #22251f;
  --ink: #f4f1e8;
  --muted: #a7aa9e;
  --line: #3b3e37;
  --blue: #819aff;
  --blue-soft: #27345f;
  --good: #75c487;
  --bad: #ef8178;
  --card: rgba(255,255,255,.04);
  color-scheme: dark;
}

* { box-sizing: border-box; }
.fonts-loading body { visibility: hidden; }
html { scroll-behavior: smooth; }
body {
  margin: 0;
  color: var(--ink);
  background: var(--paper);
  font-family: "Manrope", system-ui, sans-serif;
}

button, input, textarea, select { font: inherit; color: inherit; }
a { color: inherit; }

.site-header {
  width: min(1180px, calc(100% - 40px));
  min-height: 76px;
  margin: auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-bottom: 1px solid var(--line);
}

.wordmark {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  font-weight: 700;
  letter-spacing: -.035em;
  text-decoration: none;
}

.logo-mark {
  width: 28px;
  height: 28px;
  display: block;
  flex: 0 0 auto;
}

.header-actions { display: flex; align-items: center; gap: 12px; }
.all-tools { color: var(--muted); font-size: .82rem; font-weight: 700; text-decoration: none; }
.theme-button {
  width: 38px;
  height: 38px;
  display: grid;
  place-items: center;
  padding: 0;
  border: 1px solid var(--line);
  border-radius: 50%;
  background: transparent;
  cursor: pointer;
}
.theme-icon { font-family: Georgia,serif; font-size: 1.2rem; line-height: 1; }

.tool-hero {
  width: min(880px, calc(100% - 40px));
  margin: 72px auto 42px;
  text-align: center;
}
.crumbs { margin-bottom: 20px; color: var(--muted); font-size: .8rem; }
.crumbs a { text-decoration: none; }
.tool-hero h1 {
  margin: 0;
  font-size: clamp(2.8rem, 7vw, 5.7rem);
  line-height: .96;
  letter-spacing: -.07em;
}
.tool-hero p {
  max-width: 650px;
  margin: 24px auto 0;
  color: var(--muted);
  font-size: 1.05rem;
  line-height: 1.65;
}

.ad-wrap {
  width: 100%;
  margin: 24px auto;
  display: grid;
  justify-items: center;
  overflow: hidden;
}
.ad-label {
  margin-bottom: 6px;
  color: var(--muted);
  font-size: .62rem;
  font-weight: 700;
  letter-spacing: .08em;
  text-transform: uppercase;
}
.ad-native { width: min(980px, calc(100% - 28px)); min-height: 90px; }

.tool-layout {
  width: min(880px, calc(100% - 40px));
  margin: 38px auto 90px;
  display: grid;
  grid-template-columns: minmax(0,1fr);
  align-items: start;
}
.tool-panel {
  min-width: 0;
  padding: clamp(20px,4vw,42px);
  border: 1px solid var(--line);
  border-radius: 18px;
  background: var(--card);
}

.drop-zone {
  min-height: 220px;
  display: grid;
  place-items: center;
  padding: 28px;
  border: 2px dashed var(--line);
  border-radius: 14px;
  background: var(--paper);
  text-align: center;
  cursor: pointer;
}
.drop-zone.dragging { border-color: var(--blue); background: var(--blue-soft); }
.drop-zone strong { display: block; margin-bottom: 7px; font-size: 1.05rem; }
.drop-zone span { color: var(--muted); font-size: .86rem; }
.drop-zone input { position: absolute; width: 1px; height: 1px; opacity: 0; }

.controls {
  display: grid;
  grid-template-columns: repeat(3,minmax(0,1fr));
  gap: 14px;
  margin-top: 20px;
}
.field { display: grid; gap: 7px; }
.field label { color: var(--muted); font-size: .76rem; font-weight: 700; }
.field input, .field select, .editor {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 10px;
  outline: 0;
  background: var(--paper);
}
.field input, .field select { height: 46px; padding: 0 12px; }
.field input:focus, .field select:focus, .editor:focus { border-color: var(--blue); box-shadow: 0 0 0 3px color-mix(in srgb,var(--blue) 14%,transparent); }

.button-row { display: flex; flex-wrap: wrap; gap: 9px; margin-top: 20px; }
.button {
  min-height: 44px;
  padding: 0 16px;
  border: 1px solid var(--line);
  border-radius: 9px;
  background: var(--paper);
  font-weight: 700;
  cursor: pointer;
}
.button:hover { border-color: var(--ink); }
.button.primary { color: white; border-color: var(--blue); background: var(--blue); }
.button:disabled { opacity: .45; cursor: not-allowed; }

.editor {
  min-height: 330px;
  padding: 16px;
  resize: vertical;
  line-height: 1.55;
  tab-size: 2;
}
.editor.code { font-family: ui-monospace,SFMono-Regular,Menlo,monospace; font-size: .84rem; }
.split-editors { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.editor-label { display: block; margin-bottom: 7px; color: var(--muted); font-size: .75rem; font-weight: 700; }

.result {
  margin-top: 22px;
  padding-top: 22px;
  border-top: 1px solid var(--line);
}
.result[hidden] { display: none; }
.result-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.preview {
  min-height: 180px;
  display: grid;
  place-items: center;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 12px;
  background:
    linear-gradient(45deg,var(--paper-2) 25%,transparent 25%),
    linear-gradient(-45deg,var(--paper-2) 25%,transparent 25%),
    linear-gradient(45deg,transparent 75%,var(--paper-2) 75%),
    linear-gradient(-45deg,transparent 75%,var(--paper-2) 75%);
  background-size: 20px 20px;
  background-position: 0 0,0 10px,10px -10px,-10px 0;
}
.preview img { max-width: 100%; max-height: 360px; object-fit: contain; }
.stats { display: flex; flex-wrap: wrap; gap: 8px 18px; margin: 14px 0; color: var(--muted); font-size: .82rem; }
.saving { color: var(--good); font-weight: 700; }
.status { min-height: 22px; margin-top: 12px; color: var(--muted); font-size: .82rem; }
.status.error { color: var(--bad); }

.calc-sections { display: grid; gap: 26px; }
.calc-section { padding-bottom: 24px; border-bottom: 1px solid var(--line); }
.calc-section:last-child { padding-bottom: 0; border-bottom: 0; }
.calc-section h2 { margin: 0 0 6px; font-size: 1.15rem; letter-spacing: -.03em; }
.calc-section > p { margin: 0 0 16px; color: var(--muted); font-size: .8rem; line-height: 1.55; }
.input-grid { display: grid; grid-template-columns: repeat(3,minmax(0,1fr)); gap: 13px; }
.input-grid.two { grid-template-columns: repeat(2,minmax(0,1fr)); }
.input-wrap { position: relative; }
.input-wrap input { padding-left: 28px; }
.input-wrap .prefix { position: absolute; left: 11px; top: 50%; color: var(--muted); font-size: .8rem; transform: translateY(-50%); pointer-events: none; }
.field small { color: var(--muted); font-size: .68rem; line-height: 1.4; }
.check-field { min-height: 46px; display: flex; align-items: center; gap: 9px; padding: 0 12px; border: 1px solid var(--line); border-radius: 10px; background: var(--paper); font-size: .78rem; font-weight: 700; }
.check-field input { width: 17px; height: 17px; }

.result-panel {
  margin-top: 24px;
  padding: 24px;
  border-radius: 14px;
  color: white;
  background: var(--blue);
}
.result-panel h2 { margin: 0 0 18px; font-size: 1rem; }
.result-cards { display: grid; grid-template-columns: repeat(3,1fr); gap: 10px; }
.result-card { min-width: 0; padding: 15px; border: 1px solid rgba(255,255,255,.22); border-radius: 10px; background: rgba(255,255,255,.08); }
.result-card span { display: block; margin-bottom: 7px; color: rgba(255,255,255,.72); font-size: .68rem; font-weight: 700; }
.result-card strong { display: block; font-size: clamp(1.15rem,3vw,1.75rem); letter-spacing: -.04em; overflow-wrap: anywhere; }
.result-card.feature { background: white; color: #171815; }
.result-card.feature span { color: #686a61; }
.result-card.feature strong { color: #3157e1; }
.breakdown { width: 100%; margin-top: 18px; border-collapse: collapse; font-size: .78rem; }
.breakdown th,.breakdown td { padding: 9px 0; border-bottom: 1px solid rgba(255,255,255,.18); text-align: left; }
.breakdown th { color: rgba(255,255,255,.72); font-weight: 500; }
.breakdown td { text-align: right; font-weight: 700; }
.breakdown tr:last-child th,.breakdown tr:last-child td { border-bottom: 0; }
.result-note { margin: 15px 0 0; color: rgba(255,255,255,.72); font-size: .72rem; line-height: 1.55; }
.warning { margin-top: 14px; padding: 12px; border-radius: 9px; color: #171815; background: #f6d984; font-size: .76rem; line-height: 1.5; }
.formula { padding: 15px; border: 1px solid var(--line); border-radius: 10px; background: var(--paper-2); font: .8rem/1.6 ui-monospace,SFMono-Regular,Menlo,monospace; overflow-wrap: anywhere; }
.source-list { font-size: .8rem; }
.source-list a { color: var(--blue); }

.audio-source-actions { display: flex; flex-wrap: wrap; gap: 9px; }
.file-button { position: relative; display: inline-grid; place-items: center; cursor: pointer; }
.file-button input { position: absolute; width: 1px; height: 1px; opacity: 0; pointer-events: none; }
.record-button span { color: var(--bad); }
.record-button.recording { border-color: var(--bad); background: color-mix(in srgb,var(--bad) 10%,var(--paper)); }
.record-button.recording span { animation: record-pulse 1s ease-in-out infinite; }
.privacy-note { margin: 12px 0 0; color: var(--muted); font-size: .72rem; }
.loop-editor { margin-top: 24px; padding-top: 24px; border-top: 1px solid var(--line); }
.audio-file-heading { display: flex; align-items: end; justify-content: space-between; gap: 20px; margin-bottom: 14px; }
.audio-file-heading div { min-width: 0; }
.audio-file-heading span { color: var(--muted); font-size: .7rem; }
.audio-file-heading strong { display: block; margin-top: 3px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: .92rem; }
.waveform-wrap { position: relative; overflow: hidden; border: 1px solid var(--line); border-radius: 12px; background: var(--paper); }
#waveform { display: block; width: 100%; height: 240px; }
.waveform-selection { position: absolute; inset-block: 0; border-inline: 2px solid var(--blue); background: color-mix(in srgb,var(--blue) 15%,transparent); pointer-events: none; }
.loop-range { display: grid; grid-template-columns: 1fr 1fr; gap: 18px; margin-top: 18px; }
.loop-range input[type="range"] { height: auto; padding: 0; accent-color: var(--blue); border: 0; box-shadow: none; }
.loop-range label { display: flex; justify-content: space-between; gap: 10px; }
.loop-range label strong { color: var(--ink); font-variant-numeric: tabular-nums; }
.loop-options { margin-top: 20px; }
.loop-duration { min-height: 46px; display: flex; align-items: center; padding: 0 12px; border: 1px solid var(--line); border-radius: 10px; background: var(--paper); font-weight: 700; font-variant-numeric: tabular-nums; }
.local-options { display: grid; grid-template-columns: repeat(2,minmax(0,1fr)); gap: 14px; margin-top: 20px; }
.local-options > .editor { grid-column: 1/-1; }
.palette { display: grid; grid-template-columns: repeat(auto-fit,minmax(110px,1fr)); gap: 10px; }
.swatch { overflow: hidden; padding: 0; border: 1px solid var(--line); border-radius: 10px; color: var(--ink); background: var(--paper); cursor: pointer; }
.swatch i { display: block; height: 76px; background: var(--swatch); }
.swatch span { display: block; padding: 10px; font: .76rem ui-monospace,SFMono-Regular,Menlo,monospace; }
.svg-preview { min-height: 180px; display: grid; place-items: center; margin-bottom: 14px; padding: 20px; border: 1px solid var(--line); border-radius: 10px; background: white; }
.svg-preview img { max-width: 100%; max-height: 240px; }
@keyframes record-pulse { 50% { opacity: .35; } }

.file-list { display: grid; gap: 9px; margin-top: 18px; }
.file-row {
  display: grid;
  grid-template-columns: minmax(0,1fr) 140px auto;
  gap: 10px;
  align-items: center;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--paper);
}
.file-name { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: .84rem; font-weight: 700; }
.file-row input { width: 100%; height: 38px; padding: 0 9px; border: 1px solid var(--line); border-radius: 7px; background: var(--card); }
.row-actions { display: flex; gap: 5px; }
.icon-button { width: 34px; height: 34px; border: 1px solid var(--line); border-radius: 7px; background: transparent; cursor: pointer; }

.diff-output { display: grid; gap: 5px; max-height: 500px; overflow: auto; }
.diff-line { padding: 9px 11px; border-radius: 7px; font: .8rem/1.45 ui-monospace,SFMono-Regular,Menlo,monospace; overflow-wrap: anywhere; }
.diff-line.added { color: var(--good); background: color-mix(in srgb,var(--good) 10%,transparent); }
.diff-line.removed { color: var(--bad); background: color-mix(in srgb,var(--bad) 10%,transparent); }
.diff-line.changed { color: var(--ink); background: var(--blue-soft); }

.content-section {
  width: min(880px, calc(100% - 40px));
  margin: 0 auto 80px;
  padding-top: 64px;
  border-top: 1px solid var(--line);
}
.content-section h2 { margin: 0 0 20px; font-size: clamp(1.8rem,4vw,2.8rem); letter-spacing: -.05em; }
.content-section h3 { margin-top: 32px; }
.content-section p, .content-section li { color: var(--muted); line-height: 1.75; }
.faq { display: grid; gap: 10px; }
.faq details { padding: 17px 0; border-bottom: 1px solid var(--line); }
.faq summary { font-weight: 700; cursor: pointer; }

footer {
  width: min(1180px, calc(100% - 40px));
  min-height: 130px;
  margin: auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 24px;
  border-top: 1px solid var(--line);
  color: var(--muted);
  font-size: .78rem;
}
footer a { text-decoration: none; }

@media (max-width: 900px) {
  .controls { grid-template-columns: 1fr 1fr; }
}
@media (max-width: 640px) {
  .site-header,.tool-layout,footer { width: min(100% - 28px,1180px); }
  .tool-hero,.content-section { width: min(100% - 28px,880px); }
  .all-tools { display: none; }
  .tool-hero { margin-top: 50px; }
  .tool-hero h1 { font-size: clamp(2.65rem,14vw,4rem); overflow-wrap: break-word; }
  .tool-hero p { font-size: .95rem; }
  .tool-panel { padding: 18px; border-radius: 14px; }
  .controls,.split-editors,.result-grid { grid-template-columns: 1fr; }
  .input-grid,.input-grid.two { grid-template-columns: 1fr 1fr; }
  .result-cards { grid-template-columns: 1fr 1fr; }
  .file-row { grid-template-columns: minmax(0,1fr) auto; }
  .file-row input { grid-column: 1/-1; grid-row: 2; }
  .editor { min-height: 250px; }
  .button { flex: 1 1 auto; }
  .audio-file-heading { align-items: flex-start; flex-direction: column; gap: 6px; }
  .loop-range { grid-template-columns: 1fr; }
  .local-options { grid-template-columns: 1fr; }
  footer { padding: 36px 0; align-items: flex-start; flex-direction: column; }
}

@media (max-width: 520px) {
  .input-grid,
  .result-cards {
    grid-template-columns: 1fr;
  }
}
@media (max-width: 390px) {
  .input-grid,.input-grid.two,.result-cards { grid-template-columns: 1fr; }
}
@media (prefers-reduced-motion:reduce) {
  * { scroll-behavior: auto!important; }
}
