:root {
  color-scheme: light;
  --bg: #f5f7fb;
  --surface: #ffffff;
  --text: #172033;
  --muted: #667085;
  --line: #d9e0ea;
  --primary: #2563eb;
  --primary-strong: #1d4ed8;
  --checked: #16a34a;
  --checked-strong: #15803d;
  --shadow: 0 12px 30px rgba(15, 23, 42, 0.08);
}

[data-theme="dark"] {
  color-scheme: dark;
  --bg: #101418;
  --surface: #1a2027;
  --text: #eef2f7;
  --muted: #aab4c0;
  --line: #2d3744;
  --primary: #60a5fa;
  --primary-strong: #3b82f6;
  --checked: #22c55e;
  --checked-strong: #16a34a;
  --shadow: 0 12px 30px rgba(0, 0, 0, 0.28);
}

* {
  box-sizing: border-box;
}

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

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

.topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px clamp(16px, 4vw, 32px);
  background: color-mix(in srgb, var(--surface) 92%, transparent);
  border-bottom: 1px solid var(--line);
  backdrop-filter: blur(12px);
}

.brand {
  font-weight: 800;
}

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

.logout-form {
  margin: 0;
}

.logout-link {
  padding: 9px 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  color: var(--muted);
  font-size: 14px;
  font-weight: 800;
}

.logout-link:hover {
  background: var(--bg);
}

.theme-toggle,
.icon-button {
  width: 40px;
  height: 40px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  color: var(--text);
  font-size: 18px;
  cursor: pointer;
}

.container {
  width: min(1040px, 100%);
  margin: 0 auto;
  padding: 28px clamp(14px, 4vw, 28px) 48px;
}

.page-head,
.detail-head {
  display: flex;
  gap: 16px;
  align-items: flex-start;
  justify-content: space-between;
  margin-bottom: 22px;
}

h1 {
  margin: 0;
  font-size: clamp(26px, 5vw, 40px);
  line-height: 1.15;
}

p {
  margin: 8px 0 0;
  color: var(--muted);
}

.create-form,
.login-card,
.answer-panel,
.empty-state {
  padding: 18px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.login-card label,
.create-form label {
  display: block;
  margin-bottom: 10px;
  color: var(--muted);
  font-weight: 700;
}

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

input,
textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--bg);
  color: var(--text);
  font: inherit;
}

input {
  min-height: 46px;
  padding: 0 14px;
}

textarea {
  padding: 12px;
  resize: vertical;
}

button {
  border: 0;
  border-radius: 8px;
  background: var(--primary);
  color: #ffffff;
  font: inherit;
  font-weight: 800;
  cursor: pointer;
}

button:hover {
  background: var(--primary-strong);
}

.create-row button,
.login-card button,
.memo-actions button {
  min-height: 46px;
  padding: 0 18px;
}

.login-wrap {
  display: grid;
  min-height: calc(100vh - 160px);
  place-items: center;
}

.login-card {
  width: min(440px, 100%);
}

.login-card h1 {
  font-size: 30px;
}

.login-card input {
  margin-bottom: 14px;
}

.login-card button {
  width: 100%;
}

.form-error {
  margin: 16px 0;
  padding: 12px;
  border: 1px solid #fca5a5;
  border-radius: 8px;
  background: color-mix(in srgb, #ef4444 14%, var(--surface));
  color: var(--text);
  font-weight: 700;
}

.exam-list {
  display: grid;
  gap: 12px;
  margin-top: 18px;
}

.exam-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 18px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.exam-link {
  flex: 1;
  min-width: 0;
}

.exam-link strong,
.exam-link span {
  display: block;
}

.exam-link span {
  margin-top: 4px;
  color: var(--muted);
  font-size: 14px;
}

.delete-btn {
  flex-shrink: 0;
  min-height: 36px;
  padding: 0 14px;
  background: #dc2626;
  font-size: 13px;
}

.delete-btn:hover {
  background: #b91c1c;
}

.count-pill {
  min-width: 72px;
  padding: 8px 10px;
  border-radius: 999px;
  background: var(--bg);
  color: var(--text) !important;
  text-align: center;
  font-weight: 800;
}

.back-link {
  display: inline-block;
  margin-bottom: 10px;
  color: var(--muted);
  font-weight: 700;
}

.stat-group {
  display: flex;
  gap: 8px;
}

.stat-box {
  min-width: 88px;
  padding: 14px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  text-align: center;
  box-shadow: var(--shadow);
}

.stat-box span {
  display: block;
  color: var(--muted);
  font-size: 14px;
}

.stat-box strong {
  display: block;
  margin-top: 4px;
  font-size: 24px;
}

.stat-box [data-flagged-count] {
  font-size: 36px;
  font-weight: 800;
  color: #ffffff;
}

.toolbar {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 16px;
}

.filter-button {
  min-height: 36px;
  padding: 0 14px;
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--text);
}

.filter-button.active {
  border-color: var(--primary);
  background: var(--primary);
  color: #ffffff;
}

.toolbar-gap {
  flex: 1;
}

.save-status-text {
  font-size: 13px;
  color: var(--checked);
  font-weight: 700;
}

.save-button {
  min-height: 36px;
  padding: 0 20px;
  background: var(--checked);
}

.save-button:hover {
  background: var(--checked-strong);
}

.save-button:disabled {
  opacity: 0.6;
  cursor: not-allowed;
}

.problem-cols {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 6px;
  align-items: start;
}

.problem-col {
  display: flex;
  flex-direction: column;
  gap: 3px;
  min-width: 0;
}

.problem-item {
  display: flex;
  align-items: center;
  gap: 4px;
  flex-shrink: 0;
  padding: 5px 7px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
}

.problem-item.answered {
  border-color: var(--checked-strong);
}

.problem-item.hidden {
  display: none;
}

.pnum {
  font-size: 13px;
  font-weight: 700;
  min-width: 20px;
  text-align: center;
  color: var(--text);
  line-height: 1;
}

.answer-inline {
  display: flex;
  gap: 3px;
}

.ans-btn {
  width: 30px;
  height: 30px;
  font-size: 16px;
  border: 1px solid var(--line);
  background: var(--bg);
  color: var(--text);
  padding: 0;
  display: flex;
  align-items: center;
  justify-content: center;
}

.ans-btn:hover {
  border-color: var(--primary);
  background: color-mix(in srgb, var(--primary) 12%, var(--surface));
}

.ans-btn.selected {
  border-color: var(--checked-strong);
  background: var(--checked);
  color: #ffffff;
}

.star-btn {
  width: 28px;
  height: 28px;
  font-size: 15px;
  border: 1px solid var(--line);
  background: var(--bg);
  color: var(--muted);
  padding: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  margin-left: 2px;
}

.star-btn:hover {
  border-color: #eab308;
  color: #eab308;
  background: var(--bg);
}

.star-btn.starred {
  border-color: #ca8a04;
  background: #eab308;
  color: #ffffff;
}

.empty-state {
  display: grid;
  gap: 6px;
  color: var(--muted);
}

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

/* Calculator */
.calc-card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 20px;
  box-shadow: var(--shadow);
  margin-bottom: 24px;
}

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

.calc-row:last-of-type {
  border-bottom: none;
}

.calc-row-failed {
  background: color-mix(in srgb, #dc2626 8%, var(--surface));
  margin: 0 -20px;
  padding: 14px 20px;
}

.calc-label {
  display: flex;
  flex-direction: column;
  gap: 3px;
}

.calc-num {
  font-size: 12px;
  color: var(--muted);
  font-weight: 700;
}

.calc-name {
  font-weight: 700;
}

.calc-input-group {
  display: flex;
  align-items: center;
  gap: 10px;
}

.calc-input {
  width: 64px;
  min-height: 42px;
  text-align: center;
  font-size: 18px;
  font-weight: 800;
}

.calc-score-text {
  min-width: 44px;
  font-weight: 700;
  color: var(--muted);
  font-size: 15px;
}

.calc-row-tag {
  min-width: 36px;
  font-size: 13px;
  font-weight: 700;
  text-align: right;
}

.calc-submit {
  width: 100%;
  margin-top: 20px;
  min-height: 50px;
  font-size: 16px;
}

.calc-result {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 24px;
  box-shadow: var(--shadow);
  display: flex;
  flex-direction: column;
  gap: 20px;
}

.result-verdict {
  text-align: center;
}

.verdict-badge {
  display: inline-block;
  padding: 12px 52px;
  border-radius: 999px;
  font-size: 32px;
  font-weight: 800;
  letter-spacing: 2px;
}

.badge-pass {
  background: var(--checked);
  color: #ffffff;
}

.badge-fail {
  background: #dc2626;
  color: #ffffff;
}

.result-table {
  width: 100%;
  border-collapse: collapse;
}

.result-table th,
.result-table td {
  padding: 10px 12px;
  text-align: left;
  border-bottom: 1px solid var(--line);
  font-size: 14px;
}

.result-table th {
  color: var(--muted);
  font-size: 13px;
}

.result-table tfoot tr td {
  border-bottom: none;
  border-top: 2px solid var(--line);
}

.result-row-fail {
  background: color-mix(in srgb, #dc2626 10%, var(--surface));
}

.tag-pass {
  color: var(--checked);
  font-weight: 700;
}

.tag-fail {
  color: #dc2626;
  font-weight: 700;
}

.reasons-box {
  padding: 16px;
  background: color-mix(in srgb, #dc2626 10%, var(--surface));
  border: 1px solid #dc2626;
  border-radius: 8px;
}

.reasons-box p {
  margin: 4px 0;
  font-weight: 700;
  color: var(--text);
}

@media (max-width: 720px) {
  .page-head,
  .detail-head {
    display: grid;
  }

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