:root {
  --bg-color: #f5f4ef;
  --panel-color: rgba(255, 255, 255, 0.82);
  --panel-strong: #ffffff;
  --border-color: rgba(29, 33, 41, 0.12);
  --border-strong: rgba(29, 33, 41, 0.2);
  --text-color: #1d2129;
  --muted-color: #6b7280;
  --accent-color: #1f5fbf;
  --accent-soft: rgba(31, 95, 191, 0.1);
  --success-color: #0f766e;
  --warning-color: #c2410c;
  --error-color: #b42318;
  --shadow-lg: 0 24px 80px rgba(15, 23, 42, 0.08);
  --shadow-md: 0 18px 40px rgba(15, 23, 42, 0.08);
  --radius-xl: 28px;
  --radius-lg: 20px;
  --radius-md: 14px;
  --max-width: 1160px;
  --drawer-width: min(420px, calc(100vw - 24px));
}

* {
  box-sizing: border-box;
}

html {
  font-size: 16px;
  width: 100%;
  overflow-x: hidden;
}

body {
  margin: 0;
  width: 100%;
  min-height: 100vh;
  overflow-x: hidden;
  color: var(--text-color);
  background:
    radial-gradient(circle at top, rgba(31, 95, 191, 0.08), transparent 32%),
    linear-gradient(180deg, #f6f5f0 0%, #eeede7 100%);
  font-family: "Segoe UI", "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei",
    sans-serif;
}

img {
  display: block;
  max-width: 100%;
}

button,
textarea {
  font: inherit;
}

.hidden {
  display: none !important;
}

.page-shell {
  position: relative;
  width: min(100%, var(--max-width));
  margin: 0 auto;
  padding: 28px 20px 40px;
  min-width: 0;
}

.topbar {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 20px;
  min-width: 0;
}

.topbar > * {
  min-width: 0;
}

.topbar-copy {
  min-width: 0;
}

.brand-mark {
  display: flex;
  align-items: center;
  gap: 14px;
  margin-bottom: 10px;
}

.brand-icon {
  width: 56px;
  height: 56px;
  flex: 0 0 auto;
  object-fit: cover;
  border-radius: 16px;
  box-shadow: 0 10px 24px rgba(15, 23, 42, 0.14);
}

.eyebrow {
  margin: 0;
  color: var(--muted-color);
  font-family: "Georgia", "Times New Roman", "Songti SC", "STSong", serif;
  font-size: 1rem;
  font-weight: 600;
  letter-spacing: 0.02em;
  text-transform: none;
}

.page-title {
  margin: 0;
  max-width: 680px;
  font-family: "Georgia", "Times New Roman", serif;
  font-size: clamp(1.8rem, 3.6vw, 2.8rem);
  line-height: 1.12;
  font-weight: 600;
  overflow-wrap: anywhere;
}

.result-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 38px;
  padding: 8px 14px;
  border: 1px solid var(--border-color);
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.74);
  color: var(--muted-color);
  font-size: 0.92rem;
  line-height: 1.4;
  max-width: 100%;
  white-space: normal;
  overflow-wrap: anywhere;
  backdrop-filter: blur(10px);
}

.main-layout {
  display: grid;
  gap: 24px;
  min-width: 0;
}

.hero-panel,
.result-panel,
.history-drawer {
  border: 1px solid var(--border-color);
  border-radius: var(--radius-xl);
  background: var(--panel-color);
  box-shadow: var(--shadow-lg);
  backdrop-filter: blur(16px);
  min-width: 0;
}

.hero-panel,
.result-panel {
  transition:
    padding 220ms ease,
    margin 220ms ease,
    border-radius 220ms ease,
    box-shadow 220ms ease;
}

.hero-panel {
  padding: 18px;
}

.panel-head {
  margin-bottom: 10px;
}

.panel-head h2,
.result-header h2,
.card-head h3,
.history-drawer-head h2 {
  margin: 0;
  font-family: "Georgia", "Times New Roman", serif;
  font-weight: 600;
}

.card-head p,
.history-summary {
  margin: 8px 0 0;
  color: var(--muted-color);
  line-height: 1.6;
}

.notice-banner {
  margin-bottom: 14px;
  padding: 12px 14px;
  border-radius: var(--radius-md);
  border: 1px solid rgba(191, 33, 49, 0.14);
  background: rgba(180, 35, 24, 0.06);
  color: var(--error-color);
}

.paste-zone {
  position: relative;
  display: grid;
  place-items: center;
  min-height: 210px;
  padding: 20px;
  overflow: hidden;
  border: 2px dashed rgba(29, 33, 41, 0.2);
  border-radius: var(--radius-lg);
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.78), rgba(255, 255, 255, 0.56)),
    repeating-linear-gradient(
      135deg,
      rgba(29, 33, 41, 0.02) 0,
      rgba(29, 33, 41, 0.02) 14px,
      transparent 14px,
      transparent 28px
    );
  text-align: center;
  outline: none;
  transition:
    transform 180ms ease,
    border-color 180ms ease,
    box-shadow 180ms ease,
    min-height 220ms ease,
    padding 220ms ease;
}

.paste-zone:focus,
.paste-zone:hover {
  transform: translateY(-1px);
  border-color: rgba(31, 95, 191, 0.48);
  box-shadow: inset 0 0 0 1px rgba(31, 95, 191, 0.18);
}

.paste-zone.is-disabled {
  opacity: 0.66;
}

.paste-zone.is-processing {
  border-color: rgba(31, 95, 191, 0.48);
  background:
    linear-gradient(180deg, rgba(245, 248, 255, 0.95), rgba(255, 255, 255, 0.7)),
    repeating-linear-gradient(
      135deg,
      rgba(31, 95, 191, 0.04) 0,
      rgba(31, 95, 191, 0.04) 16px,
      transparent 16px,
      transparent 32px
    );
}

.paste-ornament {
  position: absolute;
  inset: 28px;
  pointer-events: none;
}

.paste-ornament span {
  position: absolute;
  width: 84px;
  height: 84px;
  border-color: rgba(31, 95, 191, 0.18);
  border-style: solid;
}

.paste-ornament span:nth-child(1) {
  top: 0;
  left: 0;
  border-width: 2px 0 0 2px;
  border-top-left-radius: 16px;
}

.paste-ornament span:nth-child(2) {
  right: 0;
  top: 0;
  border-width: 2px 2px 0 0;
  border-top-right-radius: 16px;
}

.paste-ornament span:nth-child(3) {
  right: 0;
  bottom: 0;
  border-width: 0 2px 2px 0;
  border-bottom-right-radius: 16px;
}

.paste-zone-copy {
  position: relative;
  z-index: 1;
}

.paste-title {
  margin: 0 0 6px;
  font-family: "Georgia", "Times New Roman", serif;
  font-size: clamp(1.5rem, 3.6vw, 2.2rem);
  font-weight: 600;
}

.paste-hint {
  margin: 0;
  max-width: 420px;
  color: var(--muted-color);
  line-height: 1.6;
}

.feedback-panel {
  margin-top: 10px;
  padding: 11px 14px;
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  background: rgba(255, 255, 255, 0.76);
}

.file-input {
  position: fixed;
  left: -9999px;
  width: 1px;
  height: 1px;
  opacity: 0;
  pointer-events: none;
}

.input-actions {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
  margin-top: 12px;
}

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

.loading-spinner {
  width: 18px;
  height: 18px;
  border: 2px solid rgba(31, 95, 191, 0.18);
  border-top-color: var(--accent-color);
  border-radius: 50%;
  animation: spin 0.9s linear infinite;
}

.loading-text,
.feedback-text,
.preview-empty {
  color: var(--muted-color);
}

.feedback-text,
.preview-empty {
  margin: 8px 0 0;
  line-height: 1.5;
}

.hero-actions {
  margin-top: 14px;
}

.result-panel {
  padding: 18px;
}

.result-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 10px;
  min-width: 0;
}

.result-header > * {
  min-width: 0;
}

.result-meta {
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 0;
}

.result-grid {
  display: block;
  min-width: 0;
}

.card {
  display: flex;
  flex-direction: column;
  min-height: 100%;
  min-width: 0;
  padding: 14px;
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  background: var(--panel-strong);
  box-shadow: var(--shadow-md);
}

.formula-card {
  gap: 10px;
}

.formula-stage-wrapper {
  position: relative;
  min-width: 0;
  overflow: hidden;
}

.formula-stage-wrapper::after {
  content: "";
  position: absolute;
  top: 1px;
  right: 1px;
  width: 36px;
  height: calc(100% - 2px);
  border-top-right-radius: var(--radius-md);
  border-bottom-right-radius: var(--radius-md);
  background: linear-gradient(to right, rgba(255, 255, 255, 0), rgba(255, 255, 255, 0.96));
  pointer-events: none;
}

.formula-stage {
  display: flex;
  align-items: center;
  justify-content: flex-start;
  min-height: 120px;
  max-width: 100%;
  padding: 14px;
  overflow-x: auto;
  overflow-y: hidden;
  border: 1px solid rgba(31, 95, 191, 0.12);
  border-radius: var(--radius-md);
  background:
    radial-gradient(circle at top, rgba(31, 95, 191, 0.08), transparent 48%),
    linear-gradient(180deg, #ffffff 0%, #f8fafc 100%);
  -webkit-overflow-scrolling: touch;
}

.formula-render {
  min-width: max-content;
  padding-right: 32px;
  color: #111827;
}

.formula-render.has-placeholder {
  width: 100%;
  min-width: 0;
  padding-right: 0;
  color: var(--muted-color);
  text-align: center;
  line-height: 1.7;
}

.copy-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
}

.action-button,
.icon-button,
.mini-copy-button {
  transition:
    transform 160ms ease,
    box-shadow 160ms ease,
    background 160ms ease;
}

.action-button {
  padding: 11px 16px;
  border: 1px solid transparent;
  border-radius: 999px;
  background: var(--accent-color);
  color: #ffffff;
  cursor: pointer;
}

.action-button:hover:not(:disabled),
.icon-button:hover,
.mini-copy-button:hover:not(:disabled) {
  transform: translateY(-1px);
  box-shadow: 0 10px 24px rgba(31, 95, 191, 0.22);
}

.action-button.secondary {
  border-color: var(--border-strong);
  background: #ffffff;
  color: var(--text-color);
}

.action-button:disabled {
  opacity: 0.55;
  cursor: not-allowed;
  box-shadow: none;
}

.mini-copy-button {
  padding: 6px 12px;
  border: 1px solid rgba(31, 95, 191, 0.18);
  border-radius: 999px;
  background: rgba(31, 95, 191, 0.08);
  color: var(--accent-color);
  cursor: pointer;
  font-size: 0.88rem;
  line-height: 1.3;
}

.mini-copy-button:disabled {
  opacity: 0.5;
  cursor: not-allowed;
  box-shadow: none;
}

.text-result {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
  min-width: 0;
}

.text-block-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 6px;
}

.text-block label {
  color: var(--muted-color);
  font-size: 0.92rem;
}

.text-block textarea {
  width: 100%;
  min-height: 92px;
  padding: 10px;
  resize: vertical;
  border: 1px solid var(--border-color);
  border-radius: 12px;
  background: #fafaf8;
  color: var(--text-color);
  line-height: 1.6;
}

.next-input-wrap {
  margin: 0 0 12px;
}

.next-input-button {
  width: 100%;
  justify-content: center;
  padding: 12px 18px;
  font-size: 1rem;
  font-weight: 600;
  box-shadow: 0 16px 32px rgba(31, 95, 191, 0.18);
}

.history-drawer {
  position: fixed;
  top: 18px;
  right: 18px;
  bottom: 18px;
  width: var(--drawer-width);
  padding: 20px;
  z-index: 30;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  transform: translateX(calc(100% + 24px));
  opacity: 0;
  pointer-events: none;
  transition:
    transform 220ms ease,
    opacity 220ms ease;
}

.history-drawer.is-open {
  transform: translateX(0);
  opacity: 1;
  pointer-events: auto;
}

.history-drawer-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 18px;
}

.history-drawer-head > * {
  min-width: 0;
}

.history-summary {
  margin-top: 10px;
}

.icon-button {
  width: 42px;
  height: 42px;
  border: 1px solid var(--border-color);
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.86);
  color: var(--text-color);
  cursor: pointer;
  font-size: 1.4rem;
  line-height: 1;
}

.history-empty {
  padding: 18px;
  border: 1px dashed var(--border-color);
  border-radius: var(--radius-md);
  color: var(--muted-color);
  line-height: 1.7;
}

.history-list {
  display: grid;
  gap: 12px;
  overflow-y: auto;
  padding-right: 4px;
}

.history-item {
  display: grid;
  grid-template-columns: 112px minmax(0, 1fr);
  gap: 14px;
  width: 100%;
  padding: 12px;
  border: 1px solid var(--border-color);
  border-radius: 16px;
  background: rgba(255, 255, 255, 0.86);
  text-align: left;
  cursor: pointer;
}

.history-item.is-active {
  border-color: rgba(31, 95, 191, 0.34);
  box-shadow: inset 0 0 0 1px rgba(31, 95, 191, 0.16);
}

.history-thumb {
  display: grid;
  place-items: center;
  min-height: 88px;
  overflow: hidden;
  border-radius: 12px;
  background:
    radial-gradient(circle at top, rgba(31, 95, 191, 0.08), transparent 48%),
    linear-gradient(180deg, #ffffff 0%, #f3f4f6 100%);
}

.history-thumb img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.history-thumb-empty {
  padding: 12px;
  color: var(--muted-color);
  font-size: 0.88rem;
}

.history-copy {
  min-width: 0;
}

.history-copy-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 12px;
  margin-bottom: 8px;
  color: var(--muted-color);
  font-size: 0.88rem;
}

.history-status {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 26px;
  padding: 4px 10px;
  border-radius: 999px;
  background: rgba(31, 95, 191, 0.08);
  color: var(--accent-color);
}

.history-latex {
  margin: 0;
  color: var(--text-color);
  line-height: 1.6;
  word-break: break-word;
}

.history-backdrop {
  position: fixed;
  inset: 0;
  z-index: 20;
  background: rgba(15, 23, 42, 0.18);
  backdrop-filter: blur(2px);
}

.kbd {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 32px;
  min-height: 28px;
  padding: 0 8px;
  border: 1px solid var(--border-color);
  border-bottom-width: 2px;
  border-radius: 8px;
  background: #ffffff;
  font-size: 0.92rem;
}

.noscript-tip {
  position: fixed;
  left: 16px;
  right: 16px;
  bottom: 16px;
  padding: 12px 14px;
  border-radius: 12px;
  background: #111827;
  color: #ffffff;
  line-height: 1.6;
}

.page-shell.has-result .topbar {
  margin-bottom: 10px;
}

.page-shell.has-result .brand-mark {
  gap: 10px;
  margin-bottom: 6px;
}

.page-shell.has-result .brand-icon {
  width: 38px;
  height: 38px;
  border-radius: 12px;
}

.page-shell.has-result .eyebrow {
  margin-bottom: 0;
  font-size: 0.96rem;
  letter-spacing: 0.02em;
}

.page-shell.has-result .page-title {
  font-size: clamp(1.45rem, 2.8vw, 2rem);
  line-height: 1.15;
}

.page-shell.has-result .hero-panel {
  padding: 10px 14px;
  border-radius: 22px;
}

.page-shell.has-result .panel-head {
  margin-bottom: 6px;
}

.page-shell.has-result .paste-zone {
  min-height: 56px;
  padding: 8px 12px;
  border-style: solid;
}

.page-shell.has-result .paste-ornament {
  display: none;
}

.page-shell.has-result .paste-title {
  margin-bottom: 0;
  font-size: clamp(0.96rem, 1.8vw, 1.1rem);
}

.page-shell.has-result .paste-hint {
  display: none;
}

.page-shell.has-result .feedback-panel {
  margin-top: 6px;
  padding: 8px 10px;
}

.page-shell.has-result .hero-actions {
  margin-top: 6px;
}

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

@media (max-width: 1200px) {
  .history-drawer {
    top: 12px;
    right: 12px;
    bottom: 12px;
  }
}

@media (max-width: 960px) {
  .topbar,
  .result-header {
    flex-direction: column;
    align-items: flex-start;
  }

  .result-meta {
    width: 100%;
    justify-content: space-between;
  }

  .result-grid,
  .text-result {
    grid-template-columns: 1fr;
  }

  .history-drawer {
    width: calc(100vw - 20px);
    top: 10px;
    right: 10px;
    bottom: 10px;
  }
}

@media (max-width: 640px) {
  .page-shell {
    padding: 16px 12px 24px;
  }

  .brand-mark {
    gap: 10px;
    margin-bottom: 8px;
  }

  .brand-icon {
    width: 42px;
    height: 42px;
    border-radius: 12px;
  }

  .page-title {
    font-size: 2rem;
  }

  .hero-panel,
  .result-panel,
  .card,
  .history-drawer {
    padding: 14px;
  }

  .paste-zone {
    min-height: 158px;
    padding: 14px;
  }

  .paste-ornament {
    inset: 14px;
  }

  .paste-ornament span {
    width: 62px;
    height: 62px;
  }

  .page-shell.has-result .paste-zone {
    min-height: 60px;
    padding: 8px 12px;
  }

  .copy-actions,
  .result-meta {
    flex-direction: column;
    align-items: stretch;
  }

  .action-button {
    width: 100%;
  }

  .input-actions {
    gap: 8px;
  }

  .result-badge {
    width: 100%;
    justify-content: flex-start;
    border-radius: 18px;
    text-align: left;
  }

  .result-header {
    gap: 8px;
    margin-bottom: 8px;
  }

  .formula-stage {
    min-height: 96px;
    padding: 12px;
  }

  .text-block textarea {
    min-height: 76px;
  }

  .next-input-wrap {
    margin-bottom: 10px;
  }

  .next-input-button {
    padding: 11px 16px;
  }

  .history-item {
    grid-template-columns: 1fr;
  }

  .history-thumb {
    min-height: 128px;
  }
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg-color: #121418;
    --panel-color: rgba(19, 23, 29, 0.84);
    --panel-strong: #171c23;
    --border-color: rgba(226, 232, 240, 0.12);
    --border-strong: rgba(226, 232, 240, 0.22);
    --text-color: #edf2f7;
    --muted-color: #a0aec0;
    --accent-soft: rgba(96, 165, 250, 0.14);
  }

  body {
    background:
      radial-gradient(circle at top, rgba(96, 165, 250, 0.12), transparent 28%),
      linear-gradient(180deg, #111418 0%, #181c22 100%);
  }

  .formula-stage-wrapper::after {
    background: linear-gradient(to right, rgba(23, 28, 35, 0), rgba(23, 28, 35, 0.96));
  }

  .action-button.secondary,
  .icon-button,
  .history-item {
    background: rgba(23, 28, 35, 0.92);
  }

  .text-block textarea,
  .history-thumb {
    background: rgba(17, 20, 24, 0.92);
  }
}
