:root {
  color-scheme: light;
  --ink: #1d2824;
  --muted: #68726e;
  --paper: #f6f3ed;
  --card: #fffdf9;
  --line: #dcd8cf;
  --accent: #ee6c4d;
  --accent-dark: #c8492f;
  --mint: #b9e4d0;
  --mint-dark: #397c65;
  --shadow: 0 12px 34px rgba(34, 45, 41, .09);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* { box-sizing: border-box; }
html { background: var(--paper); -webkit-tap-highlight-color: transparent; }
body { margin: 0; min-width: 280px; min-height: 100dvh; color: var(--ink); background: var(--paper); }
button, input { font: inherit; }
button { color: inherit; }
button:focus-visible, label:focus-within { outline: 3px solid rgba(238, 108, 77, .35); outline-offset: 3px; }
[hidden] { display: none !important; }

.topbar {
  min-height: 70px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  max-width: 760px;
  margin: 0 auto;
  padding: max(14px, env(safe-area-inset-top)) 20px 10px;
}
.top-actions { display: flex; align-items: center; gap: 8px; }
#loony-auth-slot:empty { display: none; }

.brand { display: inline-flex; align-items: center; gap: 10px; color: var(--ink); text-decoration: none; font-size: 17px; font-weight: 800; letter-spacing: -.03em; }
.brand-mark { width: 34px; height: 34px; display: flex; align-items: center; justify-content: center; gap: 2px; border-radius: 11px; background: var(--ink); }
.brand-mark i { width: 2px; height: 10px; border-radius: 2px; background: var(--mint); }
.brand-mark i:nth-child(2), .brand-mark i:nth-child(4) { height: 17px; }
.brand-mark i:nth-child(3) { height: 23px; background: var(--accent); }

.icon-button, .round-button { width: 44px; height: 44px; border: 1px solid var(--line); border-radius: 50%; background: rgba(255,255,255,.6); display: grid; place-items: center; cursor: pointer; }
.icon-button svg, .round-button svg { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
#settings-button svg { fill: currentColor; stroke: none; width: 20px; }

main { max-width: 760px; margin: 0 auto; padding: 0 20px calc(32px + env(safe-area-inset-bottom)); }
.empty-view { padding-top: clamp(28px, 7vh, 72px); }
.hero-copy { text-align: center; max-width: 620px; margin: auto; }
.eyebrow { margin: 0 0 8px; color: var(--accent-dark); text-transform: uppercase; letter-spacing: .14em; font-size: 11px; font-weight: 850; }
h1, h2, p { text-wrap: balance; }
h1 { margin: 0; font-family: Georgia, "Times New Roman", serif; font-size: clamp(42px, 10.5vw, 68px); line-height: .99; letter-spacing: -.055em; font-weight: 600; }
h1 em { color: var(--accent); font-weight: inherit; }
.intro { max-width: 450px; margin: 22px auto 0; color: var(--muted); font-size: 16px; line-height: 1.55; }

.drop-zone { margin: 34px auto 0; min-height: 220px; max-width: 540px; padding: 30px 24px; border: 1.5px dashed #a6aaa4; border-radius: 28px; background: rgba(255,253,249,.7); display: flex; flex-direction: column; align-items: center; justify-content: center; cursor: pointer; transition: .2s ease; }
.drop-zone.dragging { border-color: var(--accent); background: #fff8f3; transform: scale(1.01); }
.upload-icon { width: 56px; height: 56px; margin-bottom: 16px; border-radius: 18px; background: var(--mint); display: grid; place-items: center; }
.upload-icon svg { width: 28px; fill: none; stroke: var(--ink); stroke-width: 1.7; stroke-linecap: round; stroke-linejoin: round; }
.drop-zone strong { font-size: 18px; }
.drop-zone > span:not(.upload-icon) { margin-top: 4px; color: var(--muted); font-size: 14px; }
.drop-zone small { margin-top: 18px; color: var(--mint-dark); font-size: 12px; font-weight: 700; }

.or-divider { max-width: 540px; margin: 14px auto; display: flex; align-items: center; gap: 12px; color: #929994; font-size: 11px; font-weight: 800; text-transform: uppercase; letter-spacing: .12em; }
.or-divider::before, .or-divider::after { content: ""; height: 1px; flex: 1; background: var(--line); }
.record-button { width: 100%; max-width: 540px; min-height: 68px; margin: 0 auto; padding: 10px 18px; border: 0; border-radius: 20px; background: var(--ink); color: #fff; display: flex; align-items: center; justify-content: center; gap: 13px; cursor: pointer; box-shadow: var(--shadow); }
.record-button:disabled { opacity: .62; cursor: wait; }
.record-dot { width: 22px; height: 22px; border: 5px solid #ffdcd4; border-radius: 50%; background: var(--accent); box-shadow: 0 0 0 5px rgba(238,108,77,.16); }
.record-button > span:last-child { display: flex; flex-direction: column; text-align: left; }
.record-button strong { font-size: 15px; }
.record-button small { margin-top: 2px; color: #cbd3cf; font-size: 10px; }
.saved-presets-button { margin: 12px auto 0; padding: 10px 16px; border: 0; background: transparent; color: var(--accent-dark); display: block; font-size: 13px; font-weight: 800; cursor: pointer; }

.how-it-works { max-width: 590px; margin: 34px auto 0; display: flex; align-items: center; justify-content: space-between; }
.how-it-works > div { display: flex; align-items: center; gap: 9px; }
.how-it-works b { width: 28px; height: 28px; display: grid; place-items: center; flex: none; border-radius: 50%; background: #e6e2d9; font-size: 12px; }
.how-it-works span { display: flex; flex-direction: column; }
.how-it-works strong { font-size: 12px; }
.how-it-works small { color: var(--muted); font-size: 10px; margin-top: 2px; }
.how-it-works > i { width: 35px; height: 1px; background: var(--line); }

.loading-view { min-height: calc(100dvh - 120px); display: flex; flex-direction: column; align-items: center; justify-content: center; text-align: center; }
.loading-view h2 { margin: 24px 0 6px; font-family: Georgia, serif; font-size: 30px; }
.loading-view p { color: var(--muted); margin: 0; }
.spinner { width: 68px; height: 68px; border: 7px solid #e1ddd5; border-top-color: var(--accent); border-radius: 50%; animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(1turn); } }

.recording-view { min-height: calc(100dvh - 110px); padding: 35px 0; display: flex; flex-direction: column; align-items: center; justify-content: center; text-align: center; }
.recording-view h1 { font-size: clamp(46px, 13vw, 68px); }
.record-meter { width: min(310px, 86vw); height: 120px; margin: 34px 0 18px; padding: 0 18px; border-radius: 30px; background: var(--ink); display: flex; align-items: center; justify-content: center; gap: 7px; overflow: hidden; }
.record-meter i { width: 7px; height: 70px; border-radius: 8px; background: var(--mint); transform: scaleY(.12); transition: transform 60ms linear; }
.record-meter i:nth-child(3n + 2) { background: var(--accent); }
.record-timer { font-size: 34px; font-weight: 850; font-variant-numeric: tabular-nums; letter-spacing: -.04em; }
.record-status { margin: 7px 0 0; color: var(--muted); font-size: 13px; }
.record-status span { width: 8px; height: 8px; margin-right: 5px; border-radius: 50%; background: var(--accent); display: inline-block; animation: recordPulse 1s ease-in-out infinite alternate; }
@keyframes recordPulse { to { opacity: .32; } }
.record-actions { width: min(420px, 100%); margin-top: 30px; display: grid; grid-template-columns: .75fr 1.25fr; gap: 10px; }
.record-actions .secondary-button, .record-actions .primary-button { margin: 0; }
.stop-recording { display: flex; align-items: center; justify-content: center; gap: 8px; }
.stop-recording > span { width: 10px; height: 10px; border-radius: 2px; background: var(--accent); }

.buttons-view { padding-top: 20px; }
.file-summary { min-height: 68px; padding: 10px 12px; border: 1px solid var(--line); border-radius: 20px; background: rgba(255,255,255,.5); display: flex; align-items: center; gap: 12px; }
.file-summary .round-button { width: 42px; height: 42px; border: 0; background: #e8e4dc; flex: none; }
.file-copy { min-width: 0; display: flex; flex: 1; flex-direction: column; }
.file-copy span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 14px; font-weight: 750; }
.file-copy small { margin-top: 3px; color: var(--muted); font-size: 11px; }
.text-button { padding: 9px 6px; border: 0; background: transparent; color: var(--accent-dark); font-size: 12px; font-weight: 800; cursor: pointer; }

.mode-switch { width: 100%; margin: 18px 0 0; padding: 4px; border-radius: 16px; background: #e9e5dd; display: grid; grid-template-columns: 1fr 1fr; gap: 4px; }
.mode-switch button { min-height: 42px; border: 0; border-radius: 13px; background: transparent; color: var(--muted); font-size: 13px; font-weight: 800; cursor: pointer; }
.mode-switch button.active { background: var(--card); color: var(--ink); box-shadow: 0 3px 10px rgba(34,45,41,.09); }
.preset-actions { margin-top: 10px; display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.preset-actions button { min-height: 46px; border: 1px solid var(--line); border-radius: 15px; background: rgba(255,255,255,.55); color: var(--ink); font-size: 12px; font-weight: 800; cursor: pointer; }
.preset-actions button:first-child { border-color: var(--ink); background: var(--ink); color: white; }
.edit-tools { margin-top: 12px; display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.edit-tools > button { min-height: 64px; padding: 10px 12px; border: 1px solid var(--line); border-radius: 17px; background: rgba(255,255,255,.5); display: flex; align-items: center; gap: 10px; text-align: left; cursor: pointer; }
.edit-tools svg { width: 23px; height: 23px; flex: none; fill: none; stroke: var(--accent-dark); stroke-width: 1.65; stroke-linecap: round; stroke-linejoin: round; }
.edit-tools span { min-width: 0; display: flex; flex-direction: column; }
.edit-tools strong { font-size: 12px; }
.edit-tools small { margin-top: 3px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--muted); font-size: 9px; }
.edit-tools button.working { opacity: .62; pointer-events: none; }

.section-heading { margin: 36px 2px 22px; display: flex; align-items: end; justify-content: space-between; gap: 16px; }
.section-heading h1 { font-size: clamp(38px, 9vw, 58px); }
.stop-button { height: 42px; padding: 0 15px; border: 0; border-radius: 14px; background: #fae1da; color: #9e3624; font-size: 13px; font-weight: 800; display: flex; align-items: center; gap: 7px; cursor: pointer; }
.stop-button span { width: 9px; height: 9px; border-radius: 2px; background: currentColor; }

.phrase-list { display: grid; gap: 12px; }
.phrase-card { position: relative; min-height: 126px; border: 1px solid var(--line); border-radius: 22px; background: var(--card); box-shadow: 0 4px 15px rgba(34,45,41,.035); overflow: visible; transition: transform .16s ease, border-color .16s ease, box-shadow .16s ease; }
.phrase-card.playing { border-color: #66a58f; box-shadow: 0 9px 27px rgba(57,124,101,.14); transform: translateY(-1px); }
.play-phrase { width: calc(100% - 58px); min-height: 124px; padding: 14px 10px 12px 16px; border: 0; border-radius: inherit; background: transparent; display: grid; grid-template-columns: 52px minmax(0, 1fr); align-items: center; column-gap: 15px; row-gap: 8px; text-align: left; cursor: pointer; }
.play-icon { width: 52px; height: 52px; display: grid; place-items: center; flex: none; border-radius: 17px; background: var(--mint); color: var(--ink); }
.play-icon svg { width: 28px; fill: currentColor; }
.playing-bars { height: 28px; display: none; align-items: center; gap: 3px; }
.playing-bars i { width: 3px; height: 13px; border-radius: 4px; background: currentColor; animation: bounce .65s ease-in-out infinite alternate; }
.playing-bars i:nth-child(2) { height: 24px; animation-delay: -.28s; }
.playing-bars i:nth-child(3) { height: 17px; animation-delay: -.46s; }
.playing .play-shape { display: none; }
.playing .playing-bars { display: flex; }
@keyframes bounce { to { transform: scaleY(.4); } }
.phrase-copy { min-width: 0; display: flex; flex-direction: column; }
.phrase-copy strong { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 17px; }
.phrase-copy small { margin-top: 6px; color: var(--muted); font-variant-numeric: tabular-nums; font-size: 12px; }
.waveform-shell { position: relative; grid-column: 1 / -1; width: 100%; height: 32px; display: block; }
.waveform-bars { position: absolute; inset: 0; display: flex; align-items: center; gap: 2px; overflow: hidden; }
.waveform-bars i { min-width: 2px; height: var(--wave-height, 20%); flex: 1; border-radius: 3px; background: #c2c9c4; transition: background-color .12s ease; }
.playing .waveform-bars i { background: #91c8b4; }
.waveform-playhead { position: absolute; z-index: 2; left: 0; top: -2px; bottom: -2px; width: 2px; border-radius: 2px; background: var(--accent); opacity: 0; transform: translateX(-1px); pointer-events: none; }
.waveform-playhead i { position: absolute; left: 50%; top: -2px; width: 7px; height: 7px; border-radius: 50%; background: var(--accent); transform: translateX(-50%); }
.playing .waveform-playhead { opacity: 1; }
.more-button { position: absolute; right: 8px; top: 20px; width: 46px; height: 46px; border: 0; border-radius: 14px; background: transparent; display: grid; place-items: center; cursor: pointer; }
.more-button svg { width: 22px; fill: var(--muted); }
.phrase-actions { position: absolute; z-index: 5; right: 10px; top: 65px; width: 185px; padding: 7px; border: 1px solid var(--line); border-radius: 15px; background: #fff; box-shadow: var(--shadow); }
.phrase-actions button { width: 100%; padding: 11px 10px; border: 0; border-radius: 10px; background: transparent; text-align: left; font-size: 13px; cursor: pointer; }
.phrase-actions button:active { background: var(--paper); }
.phrase-actions button[data-action="delete"] { color: #a43b2a; }
.phrase-card:first-child [data-action="merge"] { display: none; }
.buttons-view[data-mode="use"] .more-button { display: none; }
.buttons-view[data-mode="use"] #resplit-button { visibility: hidden; }
.buttons-view[data-mode="use"] .play-phrase { width: 100%; padding-right: 16px; }
.buttons-view[data-mode="edit"] .phrase-card { border-style: dashed; }
.progress-track { position: absolute; left: 18px; right: 18px; bottom: 0; height: 3px; overflow: hidden; border-radius: 3px; }
.progress-track span { display: block; width: 0; height: 100%; background: var(--accent); }

.secondary-button, .primary-button { width: 100%; min-height: 54px; border-radius: 17px; font-weight: 800; cursor: pointer; }
.secondary-button { margin-top: 18px; border: 1px solid var(--line); background: transparent; display: flex; align-items: center; justify-content: center; gap: 8px; }
.secondary-button svg { width: 19px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; }
.primary-button { border: 0; background: var(--ink); color: white; }

dialog { width: min(100% - 24px, 520px); max-height: calc(100dvh - 24px); padding: 0; border: 0; border-radius: 28px; background: var(--card); color: var(--ink); box-shadow: 0 24px 80px rgba(25,35,31,.25); }
dialog::backdrop { background: rgba(26,34,31,.45); backdrop-filter: blur(3px); }
.settings-sheet { padding: 12px 22px calc(24px + env(safe-area-inset-bottom)); }
.sheet-handle { width: 42px; height: 4px; margin: 0 auto 15px; border-radius: 4px; background: var(--line); }
.sheet-title { display: flex; align-items: center; justify-content: space-between; }
.sheet-title h2 { margin: 0; font-family: Georgia, serif; font-size: 31px; }
.range-row { display: block; margin-top: 25px; }
.range-row > span { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.range-row strong { font-size: 14px; }
.range-row output { padding: 5px 9px; border-radius: 9px; background: #e9e5de; color: var(--muted); font-size: 11px; font-weight: 800; }
.range-row input { width: 100%; margin: 16px 0 9px; accent-color: var(--accent); }
.range-row small { display: block; color: var(--muted); line-height: 1.4; font-size: 11px; }
.select-row { display: block; margin-top: 25px; }
.select-row > span { display: block; margin-bottom: 10px; }
.select-row strong { font-size: 14px; }
.select-row select { width: 100%; min-height: 48px; padding: 0 12px; border: 1px solid var(--line); border-radius: 13px; background: #fff; color: var(--ink); }
.select-row small { display: block; margin-top: 8px; color: var(--muted); font-size: 11px; }
.settings-sheet .primary-button { margin-top: 28px; }

.split-help { margin: 18px 0 0; color: var(--muted); font-size: 13px; line-height: 1.5; }
.split-range-row { display: block; margin-top: 24px; }
.split-range-row > span { display: flex; justify-content: space-between; align-items: center; }
.split-range-row strong { font-size: 14px; }
.split-range-row output { padding: 5px 9px; border-radius: 9px; background: #e9e5de; color: var(--muted); font-size: 11px; font-weight: 800; }
.split-wave-editor { position: relative; height: 148px; margin: 18px 0 6px; border: 1px solid #cfcac1; border-radius: 18px; background: #222c28; display: block; overflow: hidden; box-shadow: inset 0 0 0 1px rgba(255,255,255,.05); }
.split-wave-editor::after { content: ""; position: absolute; z-index: 0; left: 12px; right: 12px; top: 50%; height: 1px; background: rgba(255,255,255,.16); }
.split-waveform { position: absolute; z-index: 1; inset: 16px 12px; display: flex; align-items: center; gap: 2px; }
.split-waveform i { min-width: 2px; height: var(--wave-height, 20%); flex: 1; border-radius: 3px; background: #9abaaa; opacity: .82; transition: background-color .08s linear, opacity .08s linear; }
.split-waveform i.before-split { background: var(--accent); opacity: 1; }
.split-marker { position: absolute; z-index: 2; left: 50%; top: 7px; bottom: 7px; width: 3px; border-radius: 3px; background: #fff; box-shadow: 0 0 0 1px rgba(29,40,36,.18), 0 0 12px rgba(0,0,0,.24); transform: translateX(-1px); pointer-events: none; }
.split-marker i { position: absolute; left: 50%; top: -1px; width: 13px; height: 13px; border: 3px solid #fff; border-radius: 50%; background: var(--accent); box-shadow: 0 1px 5px rgba(0,0,0,.3); transform: translateX(-50%); }
.split-range-row input { position: absolute; z-index: 3; inset: 0; width: 100%; height: 100%; margin: 0; opacity: .001; cursor: ew-resize; }
.split-previews { margin-top: 20px; display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.split-previews button { min-height: 66px; padding: 10px; border: 1px solid var(--line); border-radius: 16px; background: #fff; display: flex; align-items: center; gap: 9px; text-align: left; cursor: pointer; }
.mini-play { width: 34px; height: 34px; border-radius: 11px; background: var(--mint); display: grid; place-items: center; flex: none; font-size: 11px; }
.split-previews button > span:last-child { min-width: 0; display: flex; flex-direction: column; }
.split-previews strong { font-size: 12px; }
.split-previews small { margin-top: 3px; color: var(--muted); font-size: 10px; }

.presets-sheet { min-height: 260px; }
.preset-account-note { margin: 16px 0 0; color: var(--muted); font-size: 12px; line-height: 1.45; }
.preset-list { margin-top: 16px; display: grid; gap: 10px; }
.preset-empty { padding: 24px 14px; border: 1px dashed var(--line); border-radius: 17px; color: var(--muted); text-align: center; font-size: 13px; }
.preset-row { padding: 13px; border: 1px solid var(--line); border-radius: 17px; background: #fff; display: grid; grid-template-columns: minmax(0,1fr) auto; align-items: center; gap: 10px; }
.preset-row-copy { min-width: 0; display: flex; flex-direction: column; }
.preset-row-copy strong { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 14px; }
.preset-row-copy small { margin-top: 4px; color: var(--muted); font-size: 10px; }
.preset-row-actions { display: flex; gap: 6px; }
.preset-row-actions button { min-height: 38px; padding: 0 11px; border: 0; border-radius: 11px; background: var(--mint); color: var(--ink); font-size: 11px; font-weight: 800; cursor: pointer; }
.preset-row-actions button[data-delete] { background: #fae1da; color: #9e3624; }
.preset-loading { opacity: .55; pointer-events: none; }

.toast { position: fixed; z-index: 30; left: 50%; bottom: calc(22px + env(safe-area-inset-bottom)); max-width: calc(100% - 30px); padding: 12px 18px; border-radius: 13px; background: var(--ink); color: white; box-shadow: var(--shadow); font-size: 13px; transform: translate(-50%, 130px); opacity: 0; transition: .25s ease; pointer-events: none; }
.toast.show { transform: translate(-50%, 0); opacity: 1; }

@media (max-width: 520px) {
  .topbar { min-height: 62px; padding-inline: 16px; }
  #loony-auth-slot { max-width: 122px; }
  main { padding-inline: 16px; }
  .empty-view { padding-top: 28px; }
  .drop-zone { min-height: 210px; margin-top: 28px; }
  .how-it-works { margin-top: 28px; }
  .how-it-works { align-items: flex-start; }
  .how-it-works > div { flex-direction: column; text-align: center; gap: 5px; flex: 1; }
  .how-it-works > i { margin-top: 14px; width: 16px; flex: none; }
  .how-it-works small { display: none; }
  .buttons-view { padding-top: 10px; }
  .section-heading { margin-top: 29px; }
  .buttons-view[data-mode="edit"] .section-heading { margin-top: 23px; }
  dialog { align-self: end; width: 100%; max-width: none; max-height: calc(100dvh - 12px); margin: auto 0 0; border-radius: 28px 28px 0 0; }
}

@media (min-width: 700px) {
  .phrase-list { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .phrase-card:first-child:last-child { grid-column: 1 / -1; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { scroll-behavior: auto !important; animation-duration: .01ms !important; transition-duration: .01ms !important; }
}
