:root {
  color-scheme: light;
  --bg: #f4f1ea;
  --ink: #1d2228;
  --muted: #69717c;
  --line: #d8d1c4;
  --panel: #fffdf8;
  --accent: #0b6b69;
  --accent-dark: #084d4b;
  --danger: #b42318;
  --warn: #9a6700;
  --shadow: 0 24px 70px rgba(29, 34, 40, 0.12);
  font-family: ui-sans-serif, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* {
  box-sizing: border-box;
}

body {
  min-height: 100vh;
  margin: 0;
  color: var(--ink);
  background:
    linear-gradient(90deg, rgba(11, 107, 105, 0.08) 1px, transparent 1px),
    linear-gradient(rgba(11, 107, 105, 0.08) 1px, transparent 1px),
    var(--bg);
  background-size: 32px 32px;
}

button,
input,
textarea {
  font: inherit;
}

button {
  min-height: 44px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0 16px;
  color: var(--ink);
  background: #ffffff;
  cursor: pointer;
  transition: transform 160ms ease, border-color 160ms ease, background 160ms ease;
}

button:hover:not(:disabled) {
  border-color: #a9a092;
  transform: translateY(-1px);
}

button:disabled {
  cursor: not-allowed;
  opacity: 0.48;
}

[hidden] {
  display: none !important;
}

.shell {
  width: min(1180px, calc(100% - 32px));
  min-height: 100vh;
  margin: 0 auto;
  padding: 40px 0;
  display: flex;
  align-items: center;
}

.auth-panel {
  width: min(720px, 100%);
  margin: 0 auto;
  padding: 28px;
  display: grid;
  grid-template-columns: 1fr minmax(280px, 340px);
  gap: 28px;
  border: 1px solid rgba(29, 34, 40, 0.1);
  border-radius: 14px;
  background: rgba(255, 253, 248, 0.9);
  box-shadow: var(--shadow);
  backdrop-filter: blur(16px);
}

.auth-copy {
  max-width: 420px;
  margin: 16px 0 0;
  color: var(--muted);
  line-height: 1.7;
}

.auth-form {
  display: grid;
  gap: 14px;
}

.auth-form label {
  display: grid;
  gap: 7px;
  color: var(--muted);
  font-size: 14px;
}

.auth-actions {
  display: grid;
  grid-template-columns: 1fr;
  gap: 10px;
}

.workspace {
  width: 100%;
  padding: 22px;
  border: 1px solid rgba(29, 34, 40, 0.1);
  border-radius: 14px;
  background: rgba(255, 253, 248, 0.82);
  box-shadow: var(--shadow);
  backdrop-filter: blur(16px);
}

.topbar,
.panel-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}

.panel-actions,
.summary-heading {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 8px;
}

.panel-actions {
  flex-wrap: wrap;
}

.topbar {
  padding: 6px 4px 22px;
}

.topbar-actions {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  flex-wrap: wrap;
  gap: 10px;
}

.user-email {
  max-width: 220px;
  color: var(--muted);
  font-size: 14px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.eyebrow {
  margin: 0 0 5px;
  color: var(--accent);
  font-size: 12px;
  font-weight: 750;
  letter-spacing: 0;
  text-transform: uppercase;
}

h1,
h2 {
  margin: 0;
  letter-spacing: 0;
}

h1 {
  font-size: clamp(30px, 5vw, 56px);
  line-height: 1;
}

h2 {
  font-size: 22px;
}

.status-pill {
  flex: 0 0 auto;
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 9px 12px;
  color: var(--muted);
  background: #ffffff;
  font-size: 14px;
}

.status-pill.ready {
  color: var(--accent-dark);
  border-color: rgba(11, 107, 105, 0.35);
  background: rgba(11, 107, 105, 0.08);
}

.status-pill.error {
  color: var(--danger);
  border-color: rgba(180, 35, 24, 0.28);
  background: rgba(180, 35, 24, 0.07);
}

.grid {
  display: grid;
  grid-template-columns: minmax(320px, 0.85fr) minmax(360px, 1.15fr);
  gap: 18px;
}

.panel {
  min-height: 560px;
  padding: 22px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--panel);
}

.recorder-panel {
  display: flex;
  flex-direction: column;
  gap: 22px;
}

.timer {
  min-width: 96px;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #f7f3eb;
  font-variant-numeric: tabular-nums;
  text-align: center;
}

.meter {
  height: 170px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: #f7f3eb;
  overflow: hidden;
}

.meter span {
  width: 10px;
  height: 22px;
  border-radius: 999px;
  background: var(--accent);
  opacity: 0.32;
  transform-origin: center;
  transition: height 120ms ease, opacity 120ms ease;
}

.meter.active span {
  animation: pulse 950ms ease-in-out infinite;
  opacity: 0.82;
}

.meter span:nth-child(2n) {
  animation-delay: 90ms;
}

.meter span:nth-child(3n) {
  animation-delay: 180ms;
}

.meter span:nth-child(4n) {
  animation-delay: 260ms;
}

@keyframes pulse {
  0%,
  100% {
    height: 24px;
  }
  50% {
    height: 112px;
  }
}

.controls {
  display: grid;
  grid-template-columns: 1.2fr 0.8fr 1fr;
  gap: 10px;
}

.mode-switch {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  padding: 4px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: #f7f3eb;
}

.mode-switch button {
  border-color: transparent;
  background: transparent;
}

.mode-switch button.selected {
  color: #ffffff;
  background: var(--accent);
}

.primary {
  color: #ffffff;
  border-color: var(--accent);
  background: var(--accent);
  font-weight: 750;
}

.primary:hover:not(:disabled) {
  border-color: var(--accent-dark);
  background: var(--accent-dark);
}

.dot {
  display: inline-block;
  width: 9px;
  height: 9px;
  margin-right: 7px;
  border-radius: 999px;
  background: #ffddd6;
  vertical-align: 1px;
}

.upload-row,
.settings {
  display: grid;
  gap: 10px;
}

.upload-row {
  padding-top: 4px;
}

.settings-shell {
  border: 1px solid var(--line);
  border-radius: 10px;
  background: #fbfaf6;
}

.settings-shell summary {
  min-height: 44px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 12px;
  color: var(--ink);
  cursor: pointer;
  font-size: 14px;
  font-weight: 750;
}

.settings-shell summary::after {
  content: "展开";
  color: var(--muted);
  font-size: 13px;
  font-weight: 650;
}

.settings-shell[open] summary {
  border-bottom: 1px solid var(--line);
}

.settings-shell[open] summary::after {
  content: "收起";
}

label {
  color: var(--muted);
  font-size: 14px;
  font-weight: 650;
}

input[type="file"] {
  width: 100%;
  padding: 12px;
  border: 1px dashed #b9b0a3;
  border-radius: 8px;
  background: #ffffff;
  color: var(--ink);
}

.settings {
  grid-template-columns: 1fr 1fr;
  padding: 12px;
}

.settings label {
  display: grid;
  gap: 7px;
}

.settings input,
.settings select,
.settings textarea {
  min-width: 0;
  min-height: 42px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0 12px;
  color: var(--ink);
  background: #ffffff;
}

.settings select {
  appearance: none;
}

.settings textarea {
  min-height: 76px;
  padding: 10px 12px;
  resize: vertical;
  line-height: 1.5;
}

.settings .wide {
  grid-column: 1 / -1;
}

.settings-actions {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 8px;
}

.toggle-row {
  min-height: 42px;
  display: flex;
  align-items: center;
  gap: 9px;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #ffffff;
}

.toggle-row input {
  min-height: 0;
  width: 16px;
  height: 16px;
  padding: 0;
}

.result-panel {
  display: grid;
  grid-template-rows: auto auto minmax(160px, 0.8fr) auto auto auto;
  gap: 14px;
}

.message {
  min-height: 42px;
  display: flex;
  align-items: center;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--muted);
  background: #f7f3eb;
}

.message.error {
  color: var(--danger);
  border-color: rgba(180, 35, 24, 0.28);
  background: rgba(180, 35, 24, 0.07);
}

.message.busy {
  color: var(--warn);
}

textarea {
  width: 100%;
  min-height: 210px;
  resize: vertical;
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 16px;
  color: var(--ink);
  background: #ffffff;
  line-height: 1.65;
}

.summary-block {
  display: grid;
  gap: 10px;
}

.summary-heading {
  justify-content: space-between;
}

#summary {
  min-height: 130px;
  background: #fbfaf6;
}

#polishedText {
  min-height: 180px;
  border-color: rgba(11, 107, 105, 0.35);
  background: #f9fffc;
}

.summary-block.compact {
  padding-top: 2px;
}

.rewrite-row {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 8px;
}

.rewrite-row input,
.history-search {
  min-width: 0;
  min-height: 42px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0 12px;
  color: var(--ink);
  background: #ffffff;
}

.accuracy-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.confidence-badge {
  display: inline-flex;
  align-items: center;
  min-height: 32px;
  padding: 0 10px;
  border: 1px solid var(--line);
  border-radius: 999px;
  color: var(--muted);
  background: #ffffff;
  font-size: 13px;
}

.confidence-badge.high {
  color: var(--accent-dark);
  border-color: rgba(11, 107, 105, 0.35);
  background: rgba(11, 107, 105, 0.08);
}

.confidence-badge.medium {
  color: var(--warn);
}

.confidence-badge.low {
  color: var(--danger);
}

.suggestions-list {
  display: grid;
  gap: 8px;
}

.suggestion-item {
  display: grid;
  gap: 6px;
  padding: 9px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #ffffff;
  font-size: 13px;
}

.suggestion-item button {
  min-height: 32px;
  justify-self: start;
  padding: 0 10px;
  font-size: 13px;
}

.diff-view {
  max-height: 180px;
  overflow: auto;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #ffffff;
  line-height: 1.75;
}

.diff-add {
  color: #075e54;
  background: rgba(11, 107, 105, 0.12);
}

.diff-del {
  color: #9f1239;
  background: rgba(180, 35, 24, 0.1);
  text-decoration: line-through;
}

.history-block {
  display: grid;
  gap: 10px;
  padding-top: 2px;
}

.history-list {
  max-height: 230px;
  display: grid;
  gap: 8px;
  overflow: auto;
  padding-right: 2px;
}

.history-item {
  display: grid;
  gap: 6px;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #ffffff;
}

.history-title {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  font-weight: 750;
}

.history-meta,
.history-preview {
  color: var(--muted);
  font-size: 13px;
  line-height: 1.45;
}

.history-actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.history-actions button {
  min-height: 34px;
  padding: 0 10px;
  font-size: 13px;
}

.history-empty {
  padding: 14px;
  border: 1px dashed var(--line);
  border-radius: 8px;
  color: var(--muted);
  background: #fbfaf6;
}

textarea:focus,
input:focus,
button:focus-visible {
  outline: 3px solid rgba(11, 107, 105, 0.18);
  outline-offset: 2px;
}

@media (max-width: 820px) {
  .shell {
    width: min(100% - 12px, 620px);
    padding: 8px 0 14px;
    align-items: flex-start;
  }

  .workspace {
    padding: 10px;
    border-radius: 12px;
  }

  .auth-panel {
    grid-template-columns: 1fr;
    gap: 18px;
    padding: 20px;
  }

  .auth-copy {
    margin-top: 12px;
  }

  .topbar {
    align-items: flex-start;
    flex-direction: column;
    gap: 12px;
    padding: 4px 4px 14px;
  }

  .topbar-actions {
    width: 100%;
    justify-content: flex-start;
    gap: 8px;
  }

  .user-email {
    max-width: calc(100% - 92px);
  }

  h1 {
    font-size: 31px;
    line-height: 1.06;
  }

  h2 {
    font-size: 20px;
  }

  button {
    min-height: 42px;
    padding: 0 12px;
  }

  .grid,
  .settings,
  .settings-actions,
  .rewrite-row,
  .accuracy-row,
  .panel-actions {
    grid-template-columns: 1fr;
  }

  .panel-actions {
    align-items: stretch;
    flex-direction: column;
  }

  .grid {
    gap: 12px;
  }

  .panel {
    min-height: auto;
    padding: 14px;
    border-radius: 10px;
  }

  .recorder-panel {
    gap: 14px;
  }

  .panel-heading {
    gap: 10px;
  }

  .recorder-panel .panel-heading {
    align-items: center;
  }

  .result-panel .panel-heading {
    align-items: stretch;
    flex-direction: column;
  }

  .timer {
    min-width: 86px;
    padding: 9px 10px;
  }

  .meter {
    height: 104px;
    gap: 6px;
  }

  .meter span {
    width: 9px;
  }

  .mode-switch {
    gap: 4px;
  }

  .controls {
    grid-template-columns: 1fr 1fr;
  }

  .controls .primary {
    grid-column: 1 / -1;
  }

  .upload-row {
    gap: 8px;
  }

  input[type="file"] {
    padding: 10px;
  }

  .settings-shell summary {
    min-height: 42px;
  }

  .settings {
    gap: 9px;
    padding: 10px;
  }

  .settings textarea {
    min-height: 68px;
  }

  .result-panel {
    gap: 12px;
  }

  textarea {
    min-height: 170px;
    padding: 13px;
  }

  #polishedText {
    min-height: 150px;
  }

  #summary {
    min-height: 112px;
  }

  .summary-heading {
    align-items: stretch;
    gap: 8px;
  }

  .summary-heading button {
    align-self: stretch;
  }

  .history-list {
    max-height: 280px;
  }
}

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