:root {
  --bg: #ffffff;
  --ink: #1b1a17;
  --ink-soft: #4a4740;
  --muted: #6f6b64;
  --faint: #757169;
  --line: #e7e5e0;
  --rule: #f0eeea;
  --accent: #b4462a;
  --accent-dark: #97381e;
  --accent-wash: #f7e9e3;
  --danger: #b42318;
  --radius: 14px;
  --font: ui-sans-serif, system-ui, -apple-system, "Segoe UI", "PingFang SC",
    "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
  --ease: cubic-bezier(0.2, 0.8, 0.3, 1);
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
}

body {
  min-height: 100vh;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--font);
  font-size: 15px;
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
}

::selection {
  background: var(--accent-wash);
  color: var(--ink);
}

.shell {
  width: min(620px, 100% - 40px);
  margin: 0 auto;
  padding: 56px 0 44px;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
}

/* ---------------------------------- 标题区 ---------------------------------- */

.masthead h1 {
  margin: 0;
  font-size: 24px;
  font-weight: 640;
  line-height: 1.3;
  letter-spacing: -0.02em;
}

.masthead p {
  margin: 7px 0 0;
  color: var(--muted);
  font-size: 13.5px;
  line-height: 1.55;
}

/* ----------------------------------- 纸张 ----------------------------------- */

.sheet {
  margin-top: 26px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--bg);
  box-shadow: 0 1px 2px rgb(24 22 18 / 4%);
}

/* ---------------------------------- 输入区 ---------------------------------- */

.compose {
  padding: 18px 20px 13px;
  border-radius: var(--radius) var(--radius) 0 0;
}

/* 焦点框贴近文字区域，与纸张边框留出间隙，避免看起来像双框 */
.compose-field {
  margin: -9px;
  padding: 9px;
  border-radius: 10px;
  transition: box-shadow 180ms var(--ease);
}

.compose-field:focus-within {
  box-shadow: inset 0 0 0 1px rgb(180 70 42 / 26%);
}

textarea {
  display: block;
  width: 100%;
  min-height: 168px;
  padding: 0;
  border: 0;
  background: transparent;
  color: inherit;
  font: inherit;
  font-size: 15.5px;
  line-height: 1.7;
  caret-color: var(--accent);
  resize: vertical;
  outline: none;
}

textarea::placeholder {
  color: var(--faint);
  opacity: 1;
}

.compose-foot {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-top: 12px;
}

.compose-tools {
  display: flex;
  align-items: center;
  gap: 16px;
}

.hint {
  color: var(--faint);
  font-size: 12.5px;
  font-variant-numeric: tabular-nums;
}

/* ---------------------------------- 设置区 ---------------------------------- */

.settings {
  display: flex;
  flex-direction: column;
  gap: 17px;
  padding: 17px 20px 20px;
  border-top: 1px solid var(--rule);
}

.grid-2 {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 20px;
}

.field {
  display: flex;
  flex-direction: column;
  gap: 7px;
  min-width: 0;
}

.field > label {
  display: flex;
  align-items: baseline;
  gap: 6px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 500;
  letter-spacing: 0.01em;
}

.field output {
  color: var(--ink);
  font-size: 13px;
  font-weight: 560;
  font-variant-numeric: tabular-nums;
}

/* --------------------------------- 下拉选择 --------------------------------- */

.select-wrap {
  position: relative;
}

.select-wrap::after {
  content: "";
  position: absolute;
  right: 13px;
  top: 50%;
  width: 6px;
  height: 6px;
  border-right: 1.5px solid var(--muted);
  border-bottom: 1.5px solid var(--muted);
  transform: translateY(-70%) rotate(45deg);
  pointer-events: none;
  transition: border-color 150ms var(--ease);
}

select {
  width: 100%;
  height: 38px;
  padding: 0 30px 0 12px;
  border: 1px solid #e3e1dc;
  border-radius: 9px;
  background: var(--bg);
  color: inherit;
  font: inherit;
  font-size: 13.5px;
  appearance: none;
  cursor: pointer;
  transition: border-color 150ms var(--ease), box-shadow 150ms var(--ease);
}

.select-wrap:hover::after {
  border-color: var(--ink-soft);
}

select:hover {
  border-color: #d3d0c8;
}

/* ---------------------------------- 滑块 ---------------------------------- */

input[type="range"] {
  --fill: 50%;
  -webkit-appearance: none;
  appearance: none;
  width: 100%;
  height: 36px;
  margin: 0;
  background:
    linear-gradient(to right, var(--accent) 0 var(--fill), transparent var(--fill))
      center / 100% 3px no-repeat,
    linear-gradient(#e9e7e2, #e9e7e2) center / 100% 3px no-repeat;
  cursor: pointer;
}

input[type="range"]::-webkit-slider-runnable-track {
  height: 3px;
  background: transparent;
}

input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 14px;
  height: 14px;
  margin-top: -5.5px;
  border: 2px solid var(--accent);
  border-radius: 50%;
  background: var(--bg);
  box-shadow: 0 1px 2px rgb(24 22 18 / 16%);
  transition: box-shadow 150ms var(--ease), border-color 150ms var(--ease);
}

input[type="range"]:hover::-webkit-slider-thumb {
  border-color: var(--accent-dark);
  box-shadow: 0 1px 2px rgb(24 22 18 / 16%), 0 0 0 4px rgb(180 70 42 / 10%);
}

input[type="range"]::-moz-range-track {
  height: 3px;
  background: transparent;
}

input[type="range"]::-moz-range-thumb {
  width: 10px;
  height: 10px;
  border: 2px solid var(--accent);
  border-radius: 50%;
  background: var(--bg);
}

/* -------------------------------- 焦点样式 -------------------------------- */

/* 输入区的焦点由 .compose:focus-within 的细内描边承担，
   textarea 自身不再画 2px 外框，避免一进入页面就出现红色边框 */
:where(select, button, a, input):focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

/* ---------------------------------- 动作区 ---------------------------------- */

.actions {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 14px 20px 18px;
  border-top: 1px solid var(--rule);
}

.primary {
  display: inline-flex;
  align-items: center;
  gap: 9px;
  height: 40px;
  padding: 0 18px;
  border: 0;
  border-radius: 9px;
  background: #16150f;
  color: #fbfaf8;
  font: inherit;
  font-size: 14px;
  font-weight: 600;
  letter-spacing: 0.005em;
  cursor: pointer;
  box-shadow: 0 1px 2px rgb(24 22 18 / 16%);
  transition: background-color 160ms var(--ease), transform 120ms var(--ease),
    opacity 160ms var(--ease);
}

.primary:hover:not(:disabled) {
  background: #29261d;
}

.primary:active:not(:disabled) {
  transform: translateY(1px);
}

.primary:disabled {
  cursor: progress;
  opacity: 0.62;
}

/* 深色按钮上的焦点环用墨色，比强调色更干净 */
.primary:focus-visible {
  outline: 2px solid #16150f;
  outline-offset: 2px;
}

.waves {
  display: none;
  align-items: flex-end;
  gap: 2px;
  height: 12px;
}

.waves i {
  width: 2.5px;
  border-radius: 1px;
  background: currentColor;
  animation: wave 880ms var(--ease) infinite;
}

.waves i:nth-child(1) {
  height: 5px;
}

.waves i:nth-child(2) {
  height: 11px;
  animation-delay: 130ms;
}

.waves i:nth-child(3) {
  height: 7px;
  animation-delay: 260ms;
}

.primary[data-busy="true"] .waves {
  display: inline-flex;
}

@keyframes wave {
  0%,
  100% {
    transform: scaleY(0.45);
  }
  50% {
    transform: scaleY(1);
  }
}

.status {
  color: var(--muted);
  font-size: 12.5px;
  font-variant-numeric: tabular-nums;
}

.status[data-tone="error"] {
  color: var(--danger);
}

/* ---------------------------------- 结果区 ---------------------------------- */

.result {
  padding: 16px 20px 16px;
  border-top: 1px solid var(--rule);
  animation: settle 200ms var(--ease) both;
}

@keyframes settle {
  from {
    opacity: 0;
    transform: translateY(4px);
  }
}

audio {
  display: block;
  width: 100%;
  height: 38px;
  color-scheme: light;
}

.result-foot {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-top: 10px;
}

/* ---------------------------------- 文本链接 --------------------------------- */

.link {
  padding: 2px 0;
  border: 0;
  background: none;
  color: var(--muted);
  font: inherit;
  font-size: 12.5px;
  text-decoration: none;
  text-underline-offset: 3px;
  cursor: pointer;
  transition: color 150ms var(--ease);
}

.link:hover {
  color: var(--ink);
  text-decoration: underline;
}

.foot {
  margin-top: 22px;
  color: var(--faint);
  font-size: 12px;
  line-height: 1.6;
  text-align: center;
}

.foot p {
  margin: 0;
  text-wrap: balance;
}

.install {
  margin-top: 9px;
  padding: 5px 13px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--bg);
  color: var(--muted);
  font: inherit;
  font-size: 12px;
  cursor: pointer;
  transition: border-color 150ms var(--ease), color 150ms var(--ease);
}

.install:hover {
  border-color: var(--accent);
  color: var(--accent);
}

/* ----------------------------------- 提示 ----------------------------------- */

.toast {
  position: fixed;
  left: 50%;
  bottom: 28px;
  max-width: min(460px, calc(100% - 36px));
  padding: 10px 16px;
  border-radius: 10px;
  background: #1f1d18;
  color: #fbfaf8;
  font-size: 13.5px;
  line-height: 1.5;
  box-shadow: 0 12px 28px -16px rgb(24 22 18 / 40%);
  transform: translate(-50%, 6px);
  opacity: 0;
  transition: opacity 180ms var(--ease), transform 180ms var(--ease);
  pointer-events: none;
}

.toast[data-visible="true"] {
  opacity: 1;
  transform: translate(-50%, 0);
}

/* ----------------------------------- 响应式 --------------------------------- */

@media (max-width: 560px) {
  .shell {
    width: calc(100% - 28px);
    padding: 30px 0 36px;
  }

  .masthead h1 {
    font-size: 22px;
  }

  .sheet {
    margin-top: 20px;
  }

  .grid-2 {
    grid-template-columns: 1fr;
    gap: 14px;
  }

  .settings {
    gap: 14px;
    padding: 15px 16px 18px;
  }

  .compose {
    padding: 15px 16px 12px;
  }

  .actions,
  .result {
    padding-left: 16px;
    padding-right: 16px;
  }

  textarea {
    min-height: 140px;
  }
}

/* 触屏设备没有 Ctrl，提示无意义；控件同时加大到易点按的高度 */
@media (hover: none) {
  .compose-tools .hint {
    display: none;
  }
}

@media (max-width: 560px) {
  select,
  .primary {
    height: 44px;
  }

  input[type="range"] {
    height: 44px;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}
