:root {
  color-scheme: light;
  --bg: #eef2f7;
  --panel: #ffffff;
  --panel-soft: #f8fafc;
  --text: #162033;
  --muted: #637083;
  --border: #d7dee8;
  --primary: #176b87;
  --primary-hover: #12546a;
  --danger: #b42318;
  --danger-bg: #fff1f0;
  --shadow: 0 14px 40px rgba(21, 32, 51, 0.1);
}

.settings-page {
  min-height: 100vh;
  padding: 28px;
  background: #f3f6fa;
}

.settings-shell {
  max-width: 920px;
  margin: 0 auto;
}

.settings-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 18px;
  padding-bottom: 16px;
  border-bottom: 1px solid var(--border);
}

.settings-header p {
  margin: 0 0 6px;
  color: #677996;
  font-size: 12px;
  letter-spacing: 1.4px;
}

.settings-header h1 {
  margin: 0;
  font-size: 28px;
}

.settings-card {
  display: grid;
  gap: 18px;
  border: 1px solid #edf1f6;
  border-radius: 8px;
  background: #fff;
  padding: 20px;
  box-shadow: var(--shadow);
}

input {
  width: 100%;
  height: 42px;
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 0 12px;
  color: var(--text);
  background: var(--panel-soft);
  outline: none;
}

input:focus {
  border-color: var(--primary);
  background: #fff;
  box-shadow: 0 0 0 3px rgba(23, 107, 135, 0.12);
}

.config-meta {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

.config-meta div {
  display: grid;
  gap: 6px;
  border-radius: 6px;
  background: #f8fafc;
  padding: 12px;
}

.config-meta span {
  color: var(--muted);
  overflow-wrap: anywhere;
}

.settings-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

.settings-actions button {
  height: 42px;
  border-radius: 6px;
  cursor: pointer;
}

#saveSettings {
  border: 0;
  background: var(--primary);
  color: #fff;
  font-weight: 700;
}

#reloadSettings {
  border: 1px solid var(--border);
  background: #fff;
  color: var(--text);
}

#saveSettings:disabled {
  cursor: wait;
  opacity: 0.72;
}

.settings-message {
  border-radius: 6px;
  padding: 12px;
  line-height: 1.6;
}

.settings-message.is-ok {
  border: 1px solid #b7ebd8;
  background: #f0fff9;
  color: #00766d;
}

.settings-message.is-error {
  border: 1px solid #ffccc7;
  background: var(--danger-bg);
  color: var(--danger);
}

@media (max-width: 900px) {
  .settings-page {
    padding: 16px;
  }

  .settings-header {
    align-items: stretch;
    flex-direction: column;
  }

  .config-meta,
  .settings-actions {
    grid-template-columns: 1fr;
  }
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--text);
  font-family:
    -apple-system, BlinkMacSystemFont, "Segoe UI", "Microsoft YaHei", sans-serif;
}

button,
input,
textarea {
  font: inherit;
}

a {
  color: inherit;
  text-decoration: none;
}

.page {
  min-height: 100vh;
  padding: 28px;
}

.workspace {
  max-width: 1360px;
  margin: 0 auto;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 18px;
}

.topbar h1 {
  margin: 0;
  font-size: 28px;
  font-weight: 700;
}

.topbar p {
  margin: 6px 0 0;
  color: var(--muted);
  font-size: 14px;
}

.top-actions {
  display: flex;
  align-items: center;
  gap: 10px;
}

.ghost-link,
.history-title-row button,
#practiceClear,
#clearHistory {
  border: 1px solid var(--border);
  border-radius: 6px;
  background: #fff;
  color: var(--text);
}

.ghost-link {
  display: inline-grid;
  min-width: 92px;
  height: 42px;
  place-items: center;
  padding: 0 14px;
  font-size: 14px;
}

#scoreButton {
  min-width: 112px;
  height: 42px;
  border: 0;
  border-radius: 6px;
  background: var(--primary);
  color: #fff;
  cursor: pointer;
  font-weight: 700;
}

#scoreButton:hover:not(:disabled) {
  background: var(--primary-hover);
}

#scoreButton:disabled {
  cursor: wait;
  opacity: 0.7;
}

.practice-page {
  min-height: 100vh;
  padding: 20px;
  background: #f3f6fa;
}

.email-page {
  min-height: 100vh;
  padding: 20px;
  background: #f3f6fa;
}

.practice-header,
.email-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  max-width: 1880px;
  margin: 0 auto 20px;
  padding-bottom: 16px;
  border-bottom: 1px solid var(--border);
}

.practice-header p,
.email-header p,
.practice-result > p,
.practice-history > p,
.analysis-panel > p,
.chat-panel > p {
  margin: 0 0 6px;
  color: #677996;
  font-size: 12px;
  letter-spacing: 1.4px;
}

.title-row {
  display: flex;
  align-items: center;
  gap: 12px;
}

.title-row h1 {
  margin: 0;
  font-size: 28px;
  line-height: 1.2;
}

.title-row span {
  border-radius: 999px;
  padding: 5px 10px;
  background: #dff6ef;
  color: #00766d;
  font-size: 13px;
  font-weight: 700;
}

.practice-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
  max-width: 1880px;
  margin: 0 auto 16px;
}

.practice-card,
.practice-result,
.practice-history {
  display: grid;
  gap: 10px;
  background: #fff;
  border: 1px solid #edf1f6;
  border-radius: 8px;
  padding: 14px 12px 12px;
}

.practice-card span {
  font-weight: 700;
}

.practice-card textarea {
  min-height: 240px;
  background: #f8fafc;
}

.email-layout {
  display: grid;
  grid-template-columns: minmax(520px, 1.1fr) minmax(420px, 0.9fr);
  gap: 16px;
  max-width: 1880px;
  margin: 0 auto;
  align-items: start;
}

.email-form,
.analysis-panel,
.chat-panel {
  display: grid;
  gap: 14px;
  border: 1px solid #edf1f6;
  border-radius: 8px;
  background: #fff;
  padding: 16px;
}

.email-form textarea {
  min-height: 104px;
  background: #f8fafc;
}

.email-form textarea.large {
  min-height: 230px;
}

.email-form textarea.article-textarea {
  min-height: 320px;
}

.form-row {
  display: grid;
  gap: 12px;
}

.form-row.two {
  grid-template-columns: 1fr 1fr;
}

.form-row.three {
  grid-template-columns: 0.8fr 0.8fr 1fr;
  align-items: end;
}

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

.email-actions button,
#chatSend {
  height: 42px;
  border-radius: 6px;
  cursor: pointer;
}

#emailAnalyze,
#chatSend {
  border: 0;
  background: #22c995;
  color: #fff;
  font-weight: 700;
}

#emailClear {
  border: 1px solid var(--border);
  background: #fff;
  color: var(--text);
}

#emailAnalyze:disabled,
#chatSend:disabled {
  cursor: wait;
  opacity: 0.72;
}

.email-result {
  display: grid;
  gap: 16px;
}

.analysis-panel h2,
.chat-panel h2 {
  margin: 0;
  font-size: 22px;
}

.analysis-panel h2 {
  color: #1b3557;
}

.analysis-panel h2.is-correct {
  color: #00766d;
}

.analysis-panel h2.is-wrong {
  color: var(--danger);
}

.chat-messages {
  display: grid;
  gap: 10px;
  min-height: 220px;
  max-height: 420px;
  overflow: auto;
  border-radius: 6px;
  background: #f8fafc;
  padding: 12px;
}

.chat-empty {
  color: var(--muted);
}

.chat-message {
  display: grid;
  gap: 6px;
  border-radius: 6px;
  padding: 10px;
  line-height: 1.7;
  white-space: pre-wrap;
}

.chat-message.user {
  background: #edf7ff;
}

.chat-message.assistant {
  background: #f0fff9;
}

.chat-message strong {
  color: var(--text);
}

.chat-compose {
  display: grid;
  grid-template-columns: 1fr 96px;
  gap: 10px;
}

.chat-compose textarea {
  min-height: 82px;
  background: #f8fafc;
}

.score-chat-panel {
  margin-top: 14px;
  border: 0;
  box-shadow: none;
  padding: 0;
}

.blank-preview-card {
  display: grid;
  gap: 8px;
  border-radius: 6px;
  background: #f8fafc;
  padding: 12px;
}

.blank-preview {
  min-height: 42px;
  color: #53647c;
  line-height: 1.8;
  overflow-wrap: anywhere;
}

.blank-marker {
  display: inline-block;
  width: 54px;
  height: 1.15em;
  margin: 0 4px;
  border-bottom: 3px solid #22c995;
  vertical-align: -0.15em;
}

.single-row-actions {
  grid-template-columns: 1fr 1fr;
}

.skill-card {
  max-width: 1880px;
  margin: 0 auto 16px;
}

.skill-card textarea {
  min-height: 92px;
}

.practice-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
  max-width: 1880px;
  margin: 0 auto 20px;
}

#practiceSubmit,
#practiceClear,
#clearHistory {
  height: 40px;
  cursor: pointer;
}

#practiceSubmit {
  border: 0;
  border-radius: 6px;
  background: #22c995;
  color: #fff;
  font-weight: 700;
}

#practiceSubmit:disabled {
  cursor: wait;
  opacity: 0.72;
}

.practice-result,
.practice-history {
  max-width: 1880px;
  margin: 0 auto 20px;
  padding: 18px 16px;
}

.practice-result h2,
.practice-history h2 {
  margin: 0 0 2px;
  font-size: 22px;
}

.practice-result h2 {
  color: #00766d;
}

.standard-list {
  display: grid;
  gap: 10px;
}

.standard-list article,
.history-item,
.history-empty,
.practice-status {
  border-radius: 6px;
  background: #f8fafc;
  padding: 12px;
}

.standard-list article {
  display: grid;
  gap: 7px;
}

.standard-list span {
  color: #53647c;
  line-height: 1.7;
  white-space: pre-wrap;
}

.stream-output-card {
  display: grid;
  gap: 8px;
  border-radius: 6px;
  background: #f8fafc;
  padding: 14px;
}

.stream-output-card span {
  color: #53647c;
  line-height: 1.8;
  white-space: pre-wrap;
}

.history-title-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.history-title-row button,
#clearHistory {
  padding: 0 12px;
}

.history-list {
  display: grid;
  gap: 10px;
}

.history-item {
  color: #53647c;
  line-height: 1.65;
}

.history-item div {
  display: flex;
  gap: 12px;
  margin-bottom: 4px;
}

.history-item strong {
  color: #00766d;
}

.history-item p {
  margin: 0;
}

.history-empty,
.practice-status {
  color: var(--muted);
}

.editor-grid {
  display: grid;
  grid-template-columns: minmax(360px, 0.95fr) minmax(420px, 1.05fr);
  gap: 18px;
  align-items: stretch;
}

.panel {
  min-height: calc(100vh - 128px);
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.input-panel {
  display: grid;
  grid-template-rows: repeat(2, minmax(120px, 0.75fr)) repeat(2, minmax(180px, 1.2fr));
  gap: 14px;
  padding: 18px;
}

label {
  display: grid;
  min-height: 0;
  gap: 8px;
}

label span {
  font-weight: 700;
  color: var(--text);
}

textarea {
  width: 100%;
  min-height: 0;
  resize: none;
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 12px 13px;
  line-height: 1.6;
  color: var(--text);
  background: var(--panel-soft);
  outline: none;
}

textarea:focus {
  border-color: var(--primary);
  background: #fff;
  box-shadow: 0 0 0 3px rgba(23, 107, 135, 0.12);
}

.result-panel {
  position: relative;
  padding: 20px;
  overflow: auto;
}

.result {
  max-width: 100%;
  font-size: 15px;
  line-height: 1.9;
  white-space: pre-wrap;
}

.result p {
  margin: 0 0 22px;
}

.result strong,
.score-line {
  font-weight: 700;
}

.score-line {
  color: #1b3557;
}

.empty-state,
.loading-state {
  min-height: calc(100vh - 170px);
  display: grid;
  place-content: center;
  gap: 10px;
  text-align: center;
  color: var(--muted);
}

.empty-state strong {
  color: var(--text);
  font-size: 20px;
}

.spinner {
  width: 34px;
  height: 34px;
  margin: 0 auto;
  border: 4px solid #dbe5ee;
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin 0.85s linear infinite;
}

.error-box {
  border: 1px solid #ffccc7;
  border-radius: 6px;
  padding: 12px 14px;
  color: var(--danger);
  background: var(--danger-bg);
  line-height: 1.6;
}

.hidden {
  display: none !important;
}

@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

@media (max-width: 900px) {
  .page {
    padding: 16px;
  }

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

  .top-actions,
  #scoreButton {
    width: 100%;
  }

  .top-actions {
    display: grid;
    grid-template-columns: 1fr;
  }

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

  .panel {
    min-height: auto;
  }

  .input-panel {
    grid-template-rows: none;
  }

  textarea {
    min-height: 132px;
  }

  textarea.tall {
    min-height: 190px;
  }

  .empty-state,
  .loading-state {
    min-height: 280px;
  }

  .practice-page {
    padding: 14px;
  }

  .email-page {
    padding: 14px;
  }

  .practice-header,
  .email-header,
  .history-title-row {
    align-items: stretch;
    flex-direction: column;
  }

  .practice-grid,
  .practice-actions,
  .email-layout,
  .form-row.two,
  .form-row.three,
  .chat-compose {
    grid-template-columns: 1fr;
  }

  .practice-card textarea {
    min-height: 190px;
  }
}
