:root {
  --bg: #f6f7f4;
  --surface: #ffffff;
  --surface-2: #eef5f2;
  --text: #18201c;
  --muted: #66736c;
  --line: #dbe3dd;
  --accent: #2f7d68;
  --accent-dark: #1f604f;
  --warn: #b85c2e;
  --ok: #28724a;
  --shadow: 0 14px 30px rgba(30, 46, 38, 0.08);
}

* {
  box-sizing: border-box;
}

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

button,
input,
select,
textarea {
  font: inherit;
}

button {
  border: 0;
  border-radius: 8px;
  background: var(--text);
  color: #fff;
  min-height: 42px;
  padding: 0 16px;
  cursor: pointer;
}

button:hover {
  background: #0f1512;
}

button.primary {
  background: var(--accent);
}

button.primary:hover {
  background: var(--accent-dark);
}

button.ghost {
  background: #eef1ed;
  color: var(--text);
}

button.danger {
  background: #f5e5de;
  color: #8a3b21;
}

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

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 22px clamp(16px, 4vw, 40px);
  border-bottom: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.82);
  position: sticky;
  top: 0;
  z-index: 10;
  backdrop-filter: blur(10px);
}

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

.topbar-account {
  display: flex;
  align-items: center;
  gap: 8px;
}

.account-name {
  color: var(--muted);
  font-size: 13px;
  white-space: nowrap;
}

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

.app-nav {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
}

.nav-tab {
  min-height: 36px;
  border-radius: 8px;
  background: transparent;
  color: var(--text);
  padding: 0 10px;
}

.nav-tab:hover,
.nav-tab.active {
  background: var(--accent);
  color: #fff;
}

h1,
h2,
h3,
p {
  margin: 0;
}

h1 {
  font-size: clamp(24px, 3vw, 34px);
  letter-spacing: 0;
}

h2 {
  font-size: 20px;
}

h3 {
  font-size: 17px;
}

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

.health {
  border: 1px solid var(--line);
  border-radius: 999px;
  color: var(--muted);
  background: var(--surface);
  padding: 8px 12px;
  white-space: nowrap;
}

.page-shell {
  padding: 18px clamp(16px, 4vw, 40px) 40px;
}

.app-view {
  display: none;
}

.app-view.active {
  display: grid;
  gap: 18px;
}

.view-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
}

.panel {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
  padding: 18px;
}

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

.account-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  border-bottom: 1px solid var(--line);
  padding: 12px 0;
}

.account-row:last-child {
  border-bottom: 0;
}

.account-row p {
  margin-top: 5px;
}

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

.auth-screen {
  position: fixed;
  inset: 0;
  z-index: 30;
  display: grid;
  place-items: center;
  padding: 20px;
  background: #f6f7f4;
}

.auth-card {
  width: min(100%, 420px);
  display: grid;
  gap: 14px;
  padding: 28px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: var(--shadow);
}

.auth-card .field {
  margin: 0;
}

.auth-error {
  color: #8a3b21;
  font-size: 14px;
}

.upload-panel {
  max-width: 860px;
}

.workspace {
  display: grid;
  gap: 18px;
}

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

.dropzone {
  display: grid;
  place-items: center;
  gap: 8px;
  border: 1.5px dashed #9fb4aa;
  border-radius: 8px;
  min-height: 150px;
  background: var(--surface-2);
  cursor: pointer;
  text-align: center;
  color: var(--muted);
  margin-bottom: 14px;
}

.dropzone input {
  display: none;
}

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

.dropzone-icon {
  display: grid;
  place-items: center;
  width: 42px;
  height: 42px;
  border-radius: 999px;
  background: var(--accent);
  color: #fff;
  font-size: 28px;
  line-height: 1;
}

.preview-wrap {
  border: 1px solid var(--line);
  border-radius: 8px;
  overflow: hidden;
  margin-bottom: 14px;
  background: #f8faf8;
}

.preview-wrap img {
  display: block;
  width: 100%;
  max-height: 280px;
  object-fit: contain;
}

.form-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
}

.field {
  display: grid;
  gap: 6px;
  margin-bottom: 12px;
}

.field span {
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
}

input,
select,
textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--text);
  background: #fff;
  padding: 10px 11px;
  outline: none;
}

textarea {
  resize: vertical;
}

input:focus,
select:focus,
textarea:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(47, 125, 104, 0.14);
}

.button-row,
.filters,
.detail-actions {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  margin-bottom: 14px;
}

.button-row.compact {
  margin-bottom: 0;
}

.ocr-insight {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #f8fbfa;
  padding: 12px;
  margin-bottom: 14px;
}

.ocr-insight ul {
  margin: 8px 0 0;
  padding-left: 20px;
  color: var(--muted);
}

.ocr-insight p {
  margin-top: 8px;
  color: var(--muted);
}

.ocr-score {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
}

.ocr-score strong,
.ocr-score span {
  border-radius: 999px;
  padding: 5px 9px;
  font-size: 12px;
  background: #edf3f1;
  color: #31584d;
}

.ocr-score.review strong {
  background: #f7e8df;
  color: var(--warn);
}

.ocr-score.ok strong {
  background: #e4f2ea;
  color: var(--ok);
}

.filters input {
  flex: 1 1 220px;
}

.filters select {
  flex: 0 1 150px;
}

.practice-options {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 12px;
  align-items: end;
  margin-bottom: 14px;
}

.practice-set-picker {
  max-width: 520px;
}

.check-field {
  min-height: 42px;
  display: flex;
  align-items: center;
  gap: 8px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px 11px;
  color: var(--text);
  background: #fff;
  margin-bottom: 12px;
}

.check-field input {
  width: auto;
}

.ai-meta-strip {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #f8fbfa;
  padding: 10px;
  margin-bottom: 14px;
}

.ai-meta-strip span {
  border-radius: 999px;
  background: #edf3f1;
  color: #31584d;
  padding: 5px 9px;
  font-size: 12px;
  font-weight: 700;
}

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

.setting-row {
  display: flex;
  justify-content: space-between;
  gap: 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px;
  background: #fbfcfb;
}

.setting-row span {
  color: var(--muted);
}

.print-summary {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fbfcfb;
  padding: 14px;
}

.print-summary h3 {
  margin-bottom: 8px;
}

.stats-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 12px;
}

.stat {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 14px;
}

.stat strong {
  display: block;
  font-size: 26px;
}

.stat span {
  color: var(--muted);
  font-size: 13px;
}

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

.mistake-card {
  display: grid;
  grid-template-columns: 76px minmax(0, 1fr);
  gap: 12px;
  align-items: start;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  cursor: pointer;
}

.mistake-card:hover,
.mistake-card.active {
  border-color: var(--accent);
  background: #f8fbfa;
}

.thumb {
  width: 76px;
  height: 76px;
  border-radius: 8px;
  object-fit: cover;
  background: var(--surface-2);
  border: 1px solid var(--line);
}

.mistake-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin: 8px 0;
}

.tag {
  border-radius: 999px;
  background: #edf3f1;
  color: #31584d;
  padding: 4px 8px;
  font-size: 12px;
  font-weight: 700;
}

.tag.warn {
  background: #f7e8df;
  color: var(--warn);
}

.tag.ok {
  background: #e4f2ea;
  color: var(--ok);
}

.card-title {
  font-weight: 800;
  line-height: 1.35;
  word-break: break-word;
}

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

.detail-layout {
  display: grid;
  grid-template-columns: minmax(180px, 280px) minmax(0, 1fr);
  gap: 16px;
}

.detail-image {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface-2);
}

.detail-block {
  border-top: 1px solid var(--line);
  padding-top: 14px;
  margin-top: 14px;
}

.similar-list {
  display: grid;
  gap: 10px;
  margin-top: 12px;
}

.similar-item {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px;
  background: #fbfcfb;
}

.empty-state {
  min-height: 180px;
  display: grid;
  place-items: center;
  color: var(--muted);
  text-align: center;
}

.toast {
  position: fixed;
  left: 50%;
  bottom: 24px;
  transform: translateX(-50%);
  background: var(--text);
  color: #fff;
  padding: 10px 14px;
  border-radius: 8px;
  z-index: 30;
  box-shadow: var(--shadow);
}

.hidden {
  display: none !important;
}

.print-area {
  display: none;
}

.print-sheet {
  color: #111;
  background: #fff;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

.print-header {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  border-bottom: 2px solid #111;
  padding-bottom: 12px;
  margin-bottom: 18px;
}

.print-header p {
  font-size: 12px;
  font-weight: 700;
}

.print-header h1 {
  font-size: 24px;
}

.print-meta {
  display: grid;
  gap: 4px;
  min-width: 180px;
  font-size: 12px;
}

.print-section {
  margin: 18px 0;
}

.print-section h2 {
  font-size: 18px;
  border-left: 4px solid #111;
  padding-left: 8px;
  margin-bottom: 10px;
}

.print-question-box {
  border: 1px solid #444;
  border-radius: 6px;
  padding: 12px;
  min-height: 80px;
}

.print-question-list,
.print-answer-list {
  padding-left: 24px;
}

.print-question-list li,
.print-answer-list li {
  margin-bottom: 18px;
}

.print-question-text {
  font-size: 16px;
  line-height: 1.5;
}

.print-answer-space {
  height: 54px;
  border-bottom: 1px solid #777;
  margin-top: 10px;
}

.answer-sheet {
  break-before: page;
}

@media print {
  @page {
    size: A4;
    margin: 14mm;
  }

  body {
    background: #fff;
  }

  body > * {
    display: none !important;
  }

  #printArea {
    display: block !important;
  }

  .print-area,
  .print-area * {
    visibility: visible;
  }

  .print-sheet {
    display: block;
    box-shadow: none;
    page-break-after: always;
  }

  .print-sheet:last-child {
    page-break-after: auto;
  }

  .answer-sheet {
    page-break-before: always;
  }
}

@media (max-width: 980px) {
  .upload-panel {
    position: static;
  }

  .stats-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

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

  .topbar-side,
  .view-heading {
    align-items: flex-start;
    flex-direction: column;
  }

  .form-grid,
  .detail-layout,
  .practice-options {
    grid-template-columns: 1fr;
  }

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

  .mistake-card {
    grid-template-columns: 58px minmax(0, 1fr);
  }

  .thumb {
    width: 58px;
    height: 58px;
  }
}
