:root {
  --bg: #fcfcf9;
  --panel: #ffffff;
  --line: #e8e6df;
  --text: #18181b;
  --muted: #6b7280;
  --soft: #f3f2ee;
  --accent: #111111;
  --ok: #1f7a4d;
  --bad: #a33a3a;
  --radius: 18px;
}

* {
  box-sizing: border-box;
}

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

a {
  color: inherit;
}

.layout {
  display: grid;
  grid-template-columns: 240px 1fr;
  min-height: 100vh;
}

.sidebar {
  border-right: 1px solid var(--line);
  padding: 28px 18px;
  background: rgba(255, 255, 255, 0.7);
}

.brand {
  font-size: 24px;
  font-weight: 700;
  margin-bottom: 28px;
  color: inherit;
  text-decoration: none;
  display: inline-block;
}

.brand:hover {
  text-decoration: underline;
}

.brand:visited {
  color: inherit;
}

.brand:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.nav-section {
  font-size: 0.85rem;
  color: var(--muted);
  margin-bottom: 10px;
}

.nav-item {
  display: block;
  padding: 12px 14px;
  border-radius: 12px;
  color: var(--text);
  text-decoration: none;
  margin-bottom: 8px;
}

.nav-item.active,
.nav-item:hover {
  background: var(--soft);
}

.nav-button {
  width: 100%;
  margin-top: 8px;
  padding: 12px 14px;
  border: 0;
  border-radius: 12px;
  background: var(--soft);
  color: var(--text);
  text-align: left;
  cursor: pointer;
}

.topbar-button {
  width: auto;
  margin-top: 0;
  transition: background-color 0.1s ease, color 0.1s ease;
}

.topbar-button:hover {
  background: #f97316;
  color: white;
}

.content {
  max-width: none;
  width: 100%;
  padding: 28px 40px 56px;
}

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

.topbar-title {
  font-size: 0.95rem;
  color: var(--muted);
}

.topbar-right {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  flex-wrap: wrap;
  gap: 12px;
  margin-left: auto;
}

.topbar-pill,
.user-badge,
.topbar-link {
  border: 1px solid var(--line);
  background: var(--panel);
  padding: 10px 16px;
  border-radius: 999px;
  font-size: 0.95rem;
  text-decoration: none;
}

.topbar-link.active,
.topbar-link:hover {
  background: var(--soft);
}

.hero h1 {
  margin: 0 0 8px;
  font-size: 3rem;
  line-height: 1.05;
}

.hero p {
  margin: 0 0 28px;
  color: var(--muted);
  font-size: 1.1rem;
  max-width: 68ch;
}

.card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 24px;
  margin-bottom: 22px;
  overflow: hidden;
}

.passage {
  margin: 0;
  font-size: 1.06rem;
  line-height: 1.9;
}

.inline-form {
  display: block;
}

.inline-blank {
  display: inline-flex;
  align-items: baseline;
  gap: 0.03em;
  white-space: nowrap;
}

.inline-prefix {
  display: inline;
}

.letter-group {
  display: inline-flex;
  gap: 0.16em;
  vertical-align: baseline;
}

.letter-box,
input {
  width: 0.82em;
  min-width: 0.82em;
  height: 1.02em;
  padding: 0;
  margin: 0;
  border: 0;
  border-bottom: 1.4px solid #a8a29e;
  border-radius: 0;
  background: transparent;
  color: var(--text);
  font-size: 0.98em;
  line-height: 1;
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
  text-align: center;
  vertical-align: baseline;
  outline: none;
}

.letter-box:focus,
input:focus {
  border-bottom-color: #111111;
  box-shadow: none;
}

.actions {
  display: flex;
  justify-content: flex-start;
  margin-top: 24px;
}

.button-primary,
.button-link,
.auth-form input {
  font-size: 1rem;
}

.button-primary,
.button-link {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 140px;
  padding: 14px 20px;
  border: 0;
  border-radius: 999px;
  background: var(--accent);
  color: white;
  text-decoration: none;
  font-size: 1rem;
  cursor: pointer;
}

.result-grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  gap: 24px;
  align-items: start;
}

.result-main,
.result-side {
  margin-bottom: 0;
}

.section-gap {
  margin-top: 24px;
}

.section-title {
  margin: 0 0 16px;
  font-size: 1.05rem;
}

.pos-summary {
  display: grid;
  gap: 12px;
}

.pos-card {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 14px 16px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: #fcfcfb;
}

.pos-card > :first-child {
  min-width: 0;
}

.pos-name {
  font-weight: 600;
  margin-bottom: 4px;
}

.pos-stats {
  color: var(--muted);
  font-size: 0.95rem;
}

.pos-percentage {
  flex: 0 0 auto;
  font-size: 1.5rem;
  font-weight: 700;
  line-height: 1;
}

.answers-list {
  padding: 10px;
}

.answer-row {
  display: grid;
  grid-template-columns: 44px 1fr 52px;
  gap: 14px;
  align-items: center;
  padding: 14px;
  border-radius: 14px;
}

.answer-row + .answer-row {
  margin-top: 8px;
}

.answer-row.correct {
  background: #f4fbf7;
}

.answer-row.wrong {
  background: #fff6f6;
}

.answer-index {
  width: 44px;
  height: 44px;
  border-radius: 999px;
  background: var(--soft);
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 600;
}

.answer-obscured {
  font-weight: 600;
  margin-bottom: 4px;
}

.answer-meta {
  color: var(--muted);
  font-size: 0.95rem;
  line-height: 1.5;
}

.answer-pos {
  display: inline-block;
  margin-left: 8px;
  color: var(--muted);
  font-size: 0.88rem;
  font-weight: 500;
}

.answer-status {
  font-weight: 700;
}

.correct .answer-status {
  color: var(--ok);
}

.wrong .answer-status {
  color: var(--bad);
}

.auth-page {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
}

.auth-card {
  width: min(100%, 420px);
}

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

.auth-form input {
  width: 100%;
  min-width: 0;
  height: auto;
  padding: 14px 16px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: #fff;
  text-align: left;
  font-family: inherit;
}

.auth-error {
  color: var(--bad);
  margin: 0 0 12px;
}

.auth-meta {
  color: var(--muted);
  margin-top: 14px;
}

.history-overview {
  display: grid;
  gap: 6px;
}

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

.history-row {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 20px;
  padding: 14px 0;
  border-top: 1px solid var(--line);
}

.history-row:first-child {
  border-top: 0;
}

.history-score {
  font-weight: 700;
}

.history-date,
.history-pos {
  color: var(--muted);
}

.history-pos {
  text-align: right;
  display: grid;
  gap: 4px;
}

@media (max-width: 900px) {
  .layout {
    grid-template-columns: 1fr;
  }

  .sidebar {
    border-right: 0;
    border-bottom: 1px solid var(--line);
  }

  .content {
    padding: 24px 16px 40px;
  }

  .hero h1 {
    font-size: 2.2rem;
  }

  .topbar {
    margin-bottom: 24px;
  }

  .topbar-right {
    width: 100%;
    justify-content: flex-start;
  }

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

  .pos-card,
  .history-row {
    flex-direction: column;
    align-items: flex-start;
  }

  .answer-row {
    grid-template-columns: 1fr;
    align-items: flex-start;
  }

  .history-pos {
    text-align: left;
  }

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