* {
  box-sizing: border-box;
}

:root {
  --bg: #f6f4f1;
  --bg-alt: #eeece7;
  --card: #ffffff;
  --ink: #1f1b16;
  --muted: #70665a;
  --border: #e7e1d8;
  --accent: #bc5a3f;
  --accent-ink: #fff;
  --success: #1f8f5f;
  --warning: #d27c2c;
  --danger: #c5423f;
  --radius: 18px;
  --radius-sm: 12px;
  --control-height: 56px;
  --shadow: 0 12px 28px rgba(28, 22, 16, 0.06);
  --shadow-hover: 0 14px 34px rgba(28, 22, 16, 0.1);
}

body {
  margin: 0;
  font-family: "IBM Plex Sans", "Segoe UI", sans-serif;
  background: linear-gradient(160deg, var(--bg), var(--bg-alt));
  color: var(--ink);
}

body::before {
  content: "";
  position: fixed;
  inset: 0;
  background-image:
    radial-gradient(circle at 8% 12%, rgba(255, 255, 255, 0.72), transparent 40%),
    radial-gradient(circle at 90% 14%, rgba(255, 255, 255, 0.5), transparent 45%),
    radial-gradient(circle at 64% 84%, rgba(255, 255, 255, 0.48), transparent 46%);
  opacity: 0.8;
  pointer-events: none;
}

.app {
  position: relative;
  max-width: 1140px;
  margin: 0 auto;
  padding: 38px 24px 88px;
}

.header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 18px;
  padding-bottom: 18px;
  margin-bottom: 26px;
  border-bottom: 1px solid rgba(131, 112, 93, 0.2);
}

.header-main {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

h1 {
  margin: 0;
  font-family: "Fraunces", "Times New Roman", serif;
  font-size: clamp(30px, 4vw, 42px);
  letter-spacing: 0.24px;
  line-height: 1.18;
}

.subtitle {
  margin: 0;
  color: var(--muted);
  font-size: 14px;
  line-height: 1.5;
}

h2 {
  margin: 0;
  font-size: 13px;
  text-transform: uppercase;
  letter-spacing: 0.14em;
  color: var(--muted);
}

.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 24px;
  margin-bottom: 16px;
  box-shadow: var(--shadow);
  position: relative;
  overflow: hidden;
}

.card:hover {
  box-shadow: var(--shadow-hover);
}

.card::after {
  content: "";
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 3px;
  background: linear-gradient(90deg, rgba(188, 90, 63, 0.58), transparent 62%);
  border-top-left-radius: var(--radius);
  border-top-right-radius: var(--radius);
}

.section-head {
  margin-bottom: 16px;
}

.section-desc {
  margin: 6px 0 0;
  color: var(--muted);
  font-size: 13px;
}

.grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 12px;
}

label {
  display: flex;
  flex-direction: column;
  font-size: 13px;
  gap: 6px;
  color: #5f554a;
  font-weight: 500;
}

input,
textarea {
  font-family: "IBM Plex Sans", "Segoe UI", sans-serif;
  font-size: 14px;
  color: var(--ink);
  background: #fff;
  border: 1px solid #ddd4c8;
  border-radius: var(--radius-sm);
  padding: 11px 12px;
  transition: border-color 0.2s ease, box-shadow 0.2s ease, background-color 0.2s ease;
}

input:focus,
textarea:focus {
  outline: none;
  border-color: rgba(188, 90, 63, 0.68);
  box-shadow: 0 0 0 3px rgba(188, 90, 63, 0.14);
  background: #fffefd;
}

textarea {
  min-height: 320px;
  line-height: 1.55;
}

.output-mode {
  display: none;
}

input[type="file"] {
  height: var(--control-height);
  padding: 8px;
  background: #fdfbf8;
}

input[type="file"]::file-selector-button {
  margin-right: 12px;
  border: 1px solid var(--border);
  background: #fff;
  color: var(--ink);
  border-radius: 10px;
  padding: 7px 12px;
  cursor: pointer;
}

input[type="file"]::file-selector-button:hover {
  border-color: #d6c9b8;
}

button {
  font-family: "IBM Plex Sans", "Segoe UI", sans-serif;
  font-weight: 600;
  background: linear-gradient(135deg, #c26245, #b14f36);
  color: var(--accent-ink);
  border: none;
  height: var(--control-height);
  padding: 10px 16px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  box-shadow: 0 8px 16px rgba(188, 90, 63, 0.22);
  transition: transform 0.15s ease, box-shadow 0.2s ease, filter 0.2s ease;
}

button:hover {
  transform: translateY(-1px);
  box-shadow: 0 10px 20px rgba(188, 90, 63, 0.28);
  filter: saturate(1.04);
}

button:active {
  transform: translateY(0);
}

button.ghost {
  background: #fff;
  color: var(--ink);
  border: 1px solid var(--border);
  box-shadow: none;
}

button.ghost:hover {
  border-color: #ccbda9;
  background: #fcf9f5;
  transform: translateY(-1px);
}

.upload-btn {
  background: linear-gradient(135deg, #2e241d, #1f1813);
  border: 1px solid #1f1813;
  box-shadow: 0 8px 16px rgba(27, 21, 16, 0.26);
}

.switch-group {
  display: inline-flex;
  align-items: center;
  gap: 0;
  height: var(--control-height);
  padding: 0 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: #fff;
  color: var(--muted);
  font-size: 12px;
  text-transform: none;
  letter-spacing: 0;
}

.switch {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  cursor: pointer;
  user-select: none;
  font-size: 13px;
  letter-spacing: 0;
  text-transform: none;
  color: var(--ink);
}

.switch input {
  position: absolute;
  opacity: 0;
  pointer-events: none;
}

.switch .track {
  width: 42px;
  height: 24px;
  border-radius: 999px;
  background: #efe6dd;
  border: 1px solid #ddd2c4;
  position: relative;
  transition: all 0.2s ease;
}

.switch .track::after {
  content: "";
  position: absolute;
  top: 3px;
  left: 3px;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: #fff;
  box-shadow: 0 4px 10px rgba(32, 27, 22, 0.25);
  transition: transform 0.2s ease;
}

.switch input:checked + .track {
  background: #2d251f;
  border-color: #2d251f;
}

.switch input:checked + .track::after {
  transform: translateX(18px);
}

.switch-label {
  font-weight: 600;
  white-space: nowrap;
  line-height: 1;
}

.row {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
  margin-top: 12px;
}

.upload-row {
  align-items: stretch;
  max-width: 760px;
}

.upload-row #fileInput {
  flex: 0 0 220px;
  width: 220px;
  min-width: 220px;
}

.upload-row .upload-btn {
  flex: 0 0 auto;
}

.hint {
  font-size: 12px;
  color: var(--muted);
  min-height: 18px;
}

.tasks-list {
  display: grid;
  gap: 12px;
}

.task {
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 16px;
  background: linear-gradient(180deg, #fff, #fffcf8);
  box-shadow: 0 6px 14px rgba(30, 24, 18, 0.05);
}

.task-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 8px;
}

.task h4 {
  margin: 0;
  font-family: "Fraunces", "Times New Roman", serif;
  font-size: 19px;
  line-height: 1.3;
}

.status-chip {
  border-radius: 999px;
  font-size: 12px;
  font-weight: 600;
  padding: 4px 10px;
  white-space: nowrap;
  border: 1px solid transparent;
}

.status-chip.pending,
.status-chip.queued {
  background: #fdf4e9;
  border-color: #f3dcbf;
  color: #9a621f;
}

.status-chip.running,
.status-chip.processing,
.status-chip.translating {
  background: #edf6ff;
  border-color: #cde5ff;
  color: #276fb6;
}

.status-chip.done,
.status-chip.completed,
.status-chip.success {
  background: #ebf8f2;
  border-color: #cbe9dc;
  color: var(--success);
}

.status-chip.failed,
.status-chip.error {
  background: #fdeeee;
  border-color: #f6cccc;
  color: var(--danger);
}

.status-chip.paused {
  background: #f7f4ee;
  border-color: #e9decf;
  color: #75634f;
}

.task-meta {
  font-size: 12px;
  color: var(--muted);
  line-height: 1.6;
}

.task-meta-row {
  display: flex;
  gap: 16px;
  flex-wrap: wrap;
  margin: 2px 0 8px;
}

.progress-wrap {
  margin-top: 4px;
}

.progress-track {
  width: 100%;
  height: 8px;
  border-radius: 999px;
  background: #efe8dd;
  overflow: hidden;
}

.progress-value {
  height: 100%;
  border-radius: inherit;
  background: linear-gradient(90deg, #cf7456, #b34f35);
}

.task-actions {
  margin-top: 12px;
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.task-actions button {
  padding: 8px 12px;
  font-size: 13px;
}

.modal {
  position: fixed;
  inset: 0;
  background: rgba(20, 16, 12, 0.45);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  backdrop-filter: blur(6px);
}

.modal.hidden {
  display: none;
}

.modal-content {
  background: #fffdf9;
  padding: 24px;
  border-radius: var(--radius);
  max-width: 900px;
  width: 100%;
  max-height: 80vh;
  overflow: auto;
  border: 1px solid var(--border);
  box-shadow: 0 18px 40px rgba(20, 16, 12, 0.2);
}

.modal-content input,
.modal-content textarea {
  width: 100%;
}

.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  margin-bottom: 12px;
}

.glossary-title {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-bottom: 12px;
  font-size: 13px;
  color: #5f554a;
}

#glossaryText {
  min-height: 360px;
}

.reader-modal {
  max-width: 1100px;
}

.reader-controls {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  margin-bottom: 12px;
}

.reader-controls select {
  height: var(--control-height);
  border-radius: var(--radius-sm);
  border: 1px solid #ddd4c8;
  padding: 0 12px;
  font-size: 14px;
  min-width: 200px;
  background: #fff;
  color: var(--ink);
}

.reader-content {
  background: #fff;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 18px 20px;
  max-height: 60vh;
  overflow: auto;
  line-height: 1.7;
  color: #221c15;
}

.reader-content h1,
.reader-content h2,
.reader-content h3,
.reader-content h4,
.reader-content h5,
.reader-content h6 {
  font-family: "Fraunces", "Times New Roman", serif;
  margin: 1.4em 0 0.6em;
  line-height: 1.2;
}

.reader-content p {
  margin: 0 0 0.9em;
}

@media (max-width: 720px) {
  .app {
    padding: 26px 14px 76px;
  }

  .header {
    flex-direction: column;
    align-items: flex-start;
    gap: 10px;
  }

  .card {
    padding: 18px;
  }

  .row {
    align-items: stretch;
  }

  .row > * {
    width: 100%;
  }

  .upload-row #fileInput,
  .upload-row .upload-btn {
    min-width: 0;
  }

  .upload-row #fileInput {
    width: 100%;
    flex: 1 1 auto;
  }

  .switch-group {
    justify-content: space-between;
  }

  .upload-row {
    max-width: 100%;
  }

  .task-head {
    flex-direction: column;
    align-items: flex-start;
  }

  .task-actions button {
    flex: 1 1 calc(50% - 8px);
    min-width: 120px;
  }

  .modal-content {
    max-height: 90vh;
    padding: 18px;
  }
}
