:root {
  --paper: #f5f2eb;
  --paper-raised: #fffdf8;
  --ink: #20251f;
  --muted: #667367;
  --moss: #385844;
  --moss-dark: #284433;
  --moss-pale: #dfe8df;
  --line: #d9ded5;
  --clay: #9a4d3e;
  --shadow: 0 14px 34px rgba(39, 54, 42, 0.08);
}

* { box-sizing: border-box; }
html { color-scheme: light; }
body {
  margin: 0;
  min-height: 100vh;
  background: radial-gradient(circle at top right, #eef2e9 0, transparent 34rem), var(--paper);
  color: var(--ink);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}
button, textarea, select, input { font: inherit; }
button { -webkit-tap-highlight-color: transparent; }
.hidden { display: none !important; }

.shell { width: min(1120px, calc(100% - 32px)); margin: 0 auto; padding: 34px 0 64px; }
.topbar { display: flex; align-items: center; justify-content: space-between; gap: 18px; margin-bottom: 20px; }
.brand { display: flex; align-items: center; gap: 12px; }
.brand-mark {
  width: 42px; height: 42px; border-radius: 14px; display: grid; place-items: center;
  color: white; background: var(--moss); font-size: 28px; transform: rotate(-18deg); box-shadow: var(--shadow);
}
.brand h1 { margin: 0; font: 650 30px/1.05 Georgia, "Times New Roman", serif; letter-spacing: -0.02em; }
.brand p { margin: 4px 0 0; color: var(--muted); font-size: 14px; }

.notice {
  margin-bottom: 18px; padding: 12px 14px; border: 1px solid #cdd8cc; border-radius: 14px;
  background: rgba(237, 244, 235, 0.86); color: #38513e; font-size: 13px; line-height: 1.5;
}
.layout { display: grid; grid-template-columns: minmax(0, 1fr) 330px; gap: 20px; align-items: start; }
.card { background: color-mix(in srgb, var(--paper-raised) 95%, white); border: 1px solid var(--line); border-radius: 20px; box-shadow: var(--shadow); }
.workspace { padding: 20px; }
.sidebar { display: grid; gap: 16px; }
.settings-card, .status-card, .history-card { padding: 17px; }

.field-heading, .range-heading, .history-heading { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.field-heading { margin-bottom: 9px; }
.field-heading label, .settings-card > label, .range-heading label { font-weight: 700; font-size: 12px; text-transform: uppercase; letter-spacing: .055em; color: var(--muted); }
#characterCount, output { font: 600 12px/1 ui-monospace, SFMono-Regular, Menlo, monospace; color: var(--moss); }
textarea {
  width: 100%; min-height: 330px; resize: vertical; border: 1px solid var(--line); border-radius: 15px;
  padding: 16px; background: #fffefa; color: var(--ink); font-size: 15.5px; line-height: 1.65; outline: none;
}
textarea:focus, select:focus, input:focus { border-color: #7b9a82; box-shadow: 0 0 0 3px rgba(56, 88, 68, .11); }
.file-row { display: flex; align-items: center; flex-wrap: wrap; gap: 10px; margin-top: 10px; }
#textFile { position: absolute; width: 1px; height: 1px; opacity: 0; pointer-events: none; }
.file-button, .text-button { color: var(--moss); font-weight: 700; font-size: 13px; cursor: pointer; }
.file-button { padding: 8px 11px; border: 1px dashed #9aaa9c; border-radius: 10px; background: #f6faf5; }
.text-button { margin-left: auto; padding: 6px; border: 0; background: transparent; }
.text-button:hover, .file-button:hover { color: var(--moss-dark); text-decoration: underline; }

.actions { display: flex; flex-wrap: wrap; gap: 10px; margin-top: 18px; }
.primary-button, .secondary-button, .ghost-button {
  border-radius: 12px; padding: 11px 15px; border: 1px solid transparent; font-weight: 750; font-size: 14px; cursor: pointer;
  transition: transform .12s ease, background .12s ease, opacity .12s ease;
}
.primary-button { display: inline-flex; align-items: center; gap: 9px; color: white; background: var(--moss); }
.primary-button:hover { background: var(--moss-dark); transform: translateY(-1px); }
.secondary-button, .ghost-button { color: var(--ink); background: #fffefa; border-color: var(--line); }
.secondary-button:hover, .ghost-button:hover { background: #f1f5ef; }
button:disabled { opacity: .45; cursor: not-allowed; transform: none !important; }
.full { width: 100%; margin-top: 10px; }

.progress-wrap { margin-top: 16px; display: grid; grid-template-columns: 1fr auto; gap: 10px; align-items: center; }
.progress-track { height: 8px; border-radius: 999px; background: #e4e8e1; overflow: hidden; }
.progress-bar { width: 0; height: 100%; border-radius: inherit; background: var(--moss); transition: width .2s ease; }
#progressText { color: var(--muted); font-size: 12px; min-width: 105px; text-align: right; }
.error { margin: 14px 0 0; padding: 11px 13px; color: #7e332a; background: #fbe9e5; border: 1px solid #efc7bf; border-radius: 12px; font-size: 13px; line-height: 1.5; }
.player-card { margin-top: 16px; padding: 14px; border: 1px solid #ccd8cc; border-radius: 15px; background: #f3f7f1; }
.player-card > div { margin-bottom: 10px; }
.player-card strong { font-size: 14px; }
.player-card p { margin: 3px 0 0; color: var(--muted); font-size: 12px; }
audio { display: block; width: 100%; }
.technical-note { margin: 17px 2px 0; color: var(--muted); font-size: 12.5px; line-height: 1.55; }

.settings-card h2, .history-card h2 { margin: 0 0 13px; font-size: 14px; }
.settings-card select { width: 100%; margin: 7px 0 16px; }
select {
  border: 1px solid var(--line); border-radius: 10px; padding: 10px 11px; background: #fffefa; color: var(--ink); outline: none;
}
input[type="range"] { width: 100%; accent-color: var(--moss); }
.mini-note { margin: 8px 0 0; color: var(--muted); font-size: 11.5px; line-height: 1.45; }
hr { border: 0; border-top: 1px solid var(--line); margin: 18px 0; }
.status-row { display: flex; gap: 10px; align-items: flex-start; }
.status-dot { flex: 0 0 auto; width: 10px; height: 10px; margin-top: 5px; border-radius: 50%; background: #a7aea7; box-shadow: 0 0 0 4px rgba(167,174,167,.15); }
.status-dot.ok { background: #4b8b5b; box-shadow: 0 0 0 4px rgba(75,139,91,.15); }
.status-dot.bad { background: #b25848; box-shadow: 0 0 0 4px rgba(178,88,72,.15); }
.status-card strong { display: block; font-size: 13px; }
.status-card p { margin: 4px 0 6px; color: var(--muted); font-size: 11.5px; line-height: 1.4; }
.status-card .text-button { margin-left: 14px; }
.history-heading h2 { margin: 0; }
.history-heading .text-button { margin: 0; }
.history-list { display: grid; gap: 7px; margin-top: 12px; max-height: 300px; overflow: auto; }
.history-empty { color: var(--muted); font-size: 12px; line-height: 1.45; }
.history-item { display: grid; grid-template-columns: 1fr auto; gap: 7px; align-items: start; padding: 9px; border-radius: 10px; background: #f6f5f0; border: 1px solid #e7e8e2; }
.history-load { border: 0; padding: 0; background: transparent; color: inherit; text-align: left; cursor: pointer; min-width: 0; }
.history-title { display: block; overflow: hidden; white-space: nowrap; text-overflow: ellipsis; font-size: 12px; font-weight: 700; }
.history-meta { display: block; margin-top: 3px; color: var(--muted); font-size: 10.5px; }
.history-delete { border: 0; background: transparent; color: var(--clay); cursor: pointer; font-size: 15px; }

.update-button {
  position: fixed; right: max(18px, env(safe-area-inset-right)); bottom: max(18px, env(safe-area-inset-bottom)); z-index: 20;
  border: 0; border-radius: 999px; padding: 13px 18px; color: white; background: #274b35; box-shadow: 0 14px 32px rgba(25,55,35,.28); font-weight: 800; cursor: pointer;
}

@media (max-width: 850px) {
  .layout { grid-template-columns: 1fr; }
  .sidebar { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .history-card { grid-column: 1 / -1; }
}
@media (max-width: 610px) {
  .shell { width: min(100% - 20px, 1120px); padding-top: 18px; }
  .topbar { align-items: flex-start; }
  .brand h1 { font-size: 26px; }
  .brand p { font-size: 12px; }
  .workspace { padding: 13px; }
  .sidebar { grid-template-columns: 1fr; }
  .history-card { grid-column: auto; }
  textarea { min-height: 300px; }
  .actions > button { flex: 1 1 145px; }
}
