:root {
  --bg: #f4f6f3;
  --surface: #ffffff;
  --surface-2: #edf2ef;
  --ink: #14211d;
  --muted: #64736e;
  --line: #d9e1dc;
  --accent: #0f766e;
  --accent-soft: #dff3ef;
  --warning: #a05f00;
  --danger: #b91c1c;
  --shadow: 0 10px 28px rgba(17, 32, 27, 0.1);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

* {
  box-sizing: border-box;
}

html {
  scroll-behavior: smooth;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: "Yu Gothic", "Hiragino Kaku Gothic ProN", Meiryo, system-ui, sans-serif;
  -webkit-text-size-adjust: 100%;
}

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

button,
label,
summary,
.problem-card {
  -webkit-tap-highlight-color: transparent;
}

.app-shell {
  min-height: 100vh;
  padding-bottom: calc(76px + var(--safe-bottom));
}

.app-shell.is-home {
  padding-bottom: 0;
}

.mobile-header {
  position: sticky;
  top: 0;
  z-index: 30;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  padding: 12px 14px;
  background: rgba(244, 246, 243, 0.94);
  border-bottom: 1px solid var(--line);
  backdrop-filter: blur(12px);
}

.eyebrow {
  margin: 0 0 3px;
  color: var(--muted);
  font-size: 11px;
}

.mobile-header h1 {
  margin: 0;
  font-size: 17px;
  line-height: 1.35;
  word-break: keep-all;
}

.progress-pill {
  flex: 0 0 auto;
  min-width: 74px;
  padding: 8px 10px;
  border: 1px solid rgba(15, 118, 110, 0.22);
  background: var(--accent-soft);
  color: var(--accent);
  text-align: center;
}

.progress-pill span,
.progress-pill strong {
  display: block;
}

.progress-pill span {
  font-size: 18px;
  font-weight: 800;
}

.progress-pill strong {
  margin-top: 1px;
  font-size: 11px;
}

.quick-stats {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px;
  padding: 10px 12px 8px;
}

.quick-stats article {
  min-height: 64px;
  padding: 10px;
  background: var(--surface);
  border: 1px solid var(--line);
}

.quick-stats span {
  display: block;
  color: var(--muted);
  font-size: 12px;
}

.quick-stats strong {
  display: block;
  margin-top: 3px;
  font-size: 22px;
}

.question-tabs {
  position: sticky;
  top: 62px;
  z-index: 25;
  display: flex;
  gap: 8px;
  overflow-x: auto;
  padding: 8px 12px 10px;
  background: rgba(244, 246, 243, 0.96);
  border-bottom: 1px solid var(--line);
  scrollbar-width: none;
}

.question-tabs::-webkit-scrollbar {
  display: none;
}

.app-shell.is-home .question-tabs,
.app-shell.is-home .workspace,
.app-shell.is-home .bottom-bar {
  display: none;
}

.app-shell.is-admin .question-tabs,
.app-shell.is-admin .home-screen,
.app-shell.is-admin .workspace,
.app-shell.is-admin .bottom-bar {
  display: none;
}

.home-screen {
  display: grid;
  gap: 12px;
  padding: 12px;
}

.app-shell:not(.is-home) .home-screen {
  display: none;
}

.admin-screen {
  display: grid;
  gap: 12px;
  padding: 12px;
}

.app-shell:not(.is-admin) .admin-screen {
  display: none;
}

.access-panel,
.admin-card {
  display: grid;
  gap: 10px;
  padding: 12px;
  border: 1px solid var(--line);
  background: var(--surface);
  box-shadow: var(--shadow);
}

.access-panel h2,
.admin-heading h2,
.admin-card h3 {
  margin: 0;
}

.access-panel label,
.admin-card label {
  display: grid;
  gap: 5px;
  color: var(--muted);
  font-size: 12px;
}

.access-panel input,
.admin-card input,
.admin-card select,
.admin-card textarea {
  width: 100%;
  min-height: 46px;
  border: 1px solid var(--line);
  background: #fbfcfb;
  color: var(--ink);
  padding: 10px 11px;
  border-radius: 0;
}

.access-panel button,
.admin-card button,
.admin-heading button {
  min-height: 48px;
  border: 1px solid rgba(15, 118, 110, 0.35);
  background: #10231f;
  color: #fff;
  font-weight: 900;
}

.access-panel button + button,
.admin-heading button {
  background: var(--surface);
  color: var(--ink);
}

#activeLearnerText,
.empty-text {
  margin: 0;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.5;
}

.admin-heading {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 12px;
}

.learner-list,
.assignment-list,
.learner-picker {
  display: grid;
  gap: 8px;
}

.learner-row,
.assignment-row,
.picker-line {
  border: 1px solid var(--line);
  background: #fbfcfb;
}

.learner-row {
  display: grid;
  gap: 8px;
  padding: 10px;
}

.learner-row strong,
.learner-row span {
  display: block;
}

.learner-row span,
.assignment-row span,
.assignment-row p,
.admin-label {
  color: var(--muted);
  font-size: 12px;
}

.picker-line {
  display: grid;
  grid-template-columns: 22px 1fr;
  align-items: center;
  gap: 8px;
  min-height: 44px;
  padding: 8px 10px;
  color: var(--ink);
}

.picker-line input {
  width: 18px;
  height: 18px;
  accent-color: var(--accent);
}

.assignment-row {
  display: grid;
  gap: 4px;
  padding: 10px;
}

.assignment-row p {
  margin: 0;
}

.home-heading {
  padding: 6px 2px 0;
}

.home-heading h2 {
  margin: 0;
  font-size: 22px;
  line-height: 1.35;
}

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

.genre-card {
  display: grid;
  gap: 6px;
  width: 100%;
  min-height: 118px;
  padding: 14px;
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--ink);
  text-align: left;
  box-shadow: var(--shadow);
}

.genre-card:active {
  border-color: var(--accent);
  background: var(--accent-soft);
}

.genre-kicker,
.genre-card > span {
  color: var(--muted);
  font-size: 12px;
}

.genre-card strong {
  font-size: 18px;
  line-height: 1.35;
}

.genre-metrics {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 4px;
}

.genre-metrics span {
  min-height: 24px;
  padding: 3px 8px;
  border: 1px solid var(--line);
  background: #fbfcfb;
  color: var(--muted);
  font-size: 12px;
}

.question-tabs button {
  flex: 0 0 auto;
  min-width: 72px;
  min-height: 48px;
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--ink);
  padding: 7px 10px;
}

.question-tabs button.active {
  border-color: var(--accent);
  background: #10231f;
  color: #fff;
}

.question-tabs strong,
.question-tabs span {
  display: block;
}

.question-tabs strong {
  font-size: 15px;
}

.question-tabs span {
  margin-top: 1px;
  font-size: 11px;
  color: currentColor;
  opacity: 0.72;
}

.workspace {
  display: grid;
  gap: 12px;
  padding: 12px;
}

.viewer,
.study-actions,
.answer-panel,
.focus-details,
.filters,
.note-section,
.question-list-section {
  background: var(--surface);
  border: 1px solid var(--line);
  box-shadow: var(--shadow);
}

.viewer {
  overflow: hidden;
}

.viewer-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 10px;
  padding: 12px;
  border-bottom: 1px solid var(--line);
}

.viewer-header p,
.viewer-header h2 {
  margin: 0;
}

.viewer-header p {
  color: var(--muted);
  font-size: 12px;
  line-height: 1.4;
}

.viewer-header h2 {
  margin-top: 3px;
  font-size: 16px;
  line-height: 1.45;
  overflow-wrap: anywhere;
}

.icon-button {
  flex: 0 0 auto;
  display: grid;
  place-items: center;
  min-width: 46px;
  min-height: 46px;
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--ink);
  font-size: 22px;
}

.image-stage {
  overflow: auto;
  min-height: 0;
  max-height: 54vh;
  padding: 10px;
  background: #e8ece8;
  overscroll-behavior: contain;
}

.image-stage img {
  display: block;
  width: 100%;
  max-width: none;
  height: auto;
  margin: 0 auto;
  background: #fff;
  box-shadow: 0 6px 20px rgba(14, 26, 22, 0.16);
}

.study-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  padding: 10px;
}

.toggle-card,
.confidence-card,
.jump-card,
.home-card-button {
  display: grid;
  align-items: center;
  min-height: 54px;
  border: 1px solid var(--line);
  background: #fbfcfb;
  padding: 9px 10px;
}

.toggle-card {
  grid-template-columns: 24px 1fr;
  gap: 8px;
  color: var(--ink);
  font-weight: 700;
}

.toggle-card input {
  width: 20px;
  height: 20px;
  accent-color: var(--accent);
}

.confidence-card {
  grid-column: 1 / -1;
  gap: 6px;
  color: var(--muted);
  font-size: 12px;
}

.confidence-card input {
  width: 100%;
  accent-color: var(--accent);
}

.jump-card,
.home-card-button {
  grid-column: 1 / -1;
  place-items: center;
  border-color: rgba(15, 118, 110, 0.35);
  background: #10231f;
  color: #fff;
  font-weight: 900;
}

.home-card-button {
  background: var(--surface);
  color: var(--ink);
}

.answer-panel {
  padding: 10px;
}

.viewer .answer-panel {
  border-width: 1px 0 0;
  box-shadow: none;
}

.answer-heading {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 9px;
}

.answer-heading h2,
.answer-heading p {
  margin: 0;
}

.answer-heading h2 {
  flex: 0 0 auto;
  font-size: 16px;
}

.grade-result {
  color: var(--muted);
  font-size: 13px;
  line-height: 1.45;
  text-align: right;
}

.grade-result.correct {
  color: var(--accent);
  font-weight: 800;
}

.grade-result.wrong {
  color: var(--danger);
  font-weight: 800;
}

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

.answer-choice {
  min-height: 58px;
  border: 1px solid var(--line);
  background: #fbfcfb;
  color: var(--ink);
  font-size: 20px;
  font-weight: 900;
}

.answer-choice.selected {
  border-color: var(--accent);
  background: var(--accent-soft);
  color: var(--accent);
}

.answer-choice.correct-answer {
  border-color: var(--accent);
  background: var(--accent);
  color: #fff;
}

.answer-choice.wrong-answer {
  border-color: var(--danger);
  background: #fee2e2;
  color: var(--danger);
}

.focus-details {
  padding: 0;
}

.focus-details summary {
  min-height: 48px;
  padding: 13px 14px;
  cursor: pointer;
  font-weight: 800;
}

.focus-details h3 {
  margin: 0;
  padding: 0 14px 6px;
  font-size: 16px;
}

.focus-details p {
  margin: 0;
  padding: 0 14px 14px;
  color: var(--muted);
  font-size: 14px;
  line-height: 1.7;
}

.filters {
  display: grid;
  gap: 9px;
  padding: 10px;
}

.filters label,
.note-section label {
  display: grid;
  gap: 5px;
  color: var(--muted);
  font-size: 12px;
}

.filters input,
.filters select,
.note-section textarea {
  width: 100%;
  min-height: 46px;
  border: 1px solid var(--line);
  background: #fbfcfb;
  color: var(--ink);
  padding: 10px 11px;
  border-radius: 0;
}

.note-section {
  padding: 10px;
}

.note-section textarea {
  resize: vertical;
  line-height: 1.6;
}

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

.section-heading h2,
.section-heading p {
  margin: 0;
}

.section-heading h2 {
  font-size: 16px;
}

.section-heading p {
  color: var(--muted);
  font-size: 12px;
}

.problem-grid {
  display: grid;
  gap: 8px;
  padding: 10px;
}

.problem-card {
  min-height: 78px;
  border: 1px solid var(--line);
  background: #fbfcfb;
  padding: 10px;
  cursor: pointer;
}

.problem-card.active {
  border-color: var(--accent);
  box-shadow: inset 4px 0 0 var(--accent);
}

.problem-card header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 8px;
}

.problem-card strong {
  font-size: 15px;
}

.problem-card p {
  margin: 7px 0 0;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.45;
}

.badge {
  display: inline-flex;
  align-items: center;
  min-height: 24px;
  padding: 2px 8px;
  border: 1px solid var(--line);
  color: var(--muted);
  font-size: 12px;
  white-space: nowrap;
}

.badge.done {
  border-color: rgba(15, 118, 110, 0.35);
  background: rgba(15, 118, 110, 0.09);
  color: var(--accent);
}

.badge.correct {
  border-color: rgba(15, 118, 110, 0.35);
  background: rgba(15, 118, 110, 0.09);
  color: var(--accent);
}

.badge.wrong {
  border-color: rgba(185, 28, 28, 0.3);
  background: #fee2e2;
  color: var(--danger);
}

.badge.review {
  border-color: rgba(160, 95, 0, 0.35);
  background: rgba(160, 95, 0, 0.1);
  color: var(--warning);
}

.badge.paused {
  border-color: rgba(100, 115, 110, 0.35);
  background: #eef2ef;
  color: var(--muted);
}

.badge.bookmarked {
  border-color: rgba(185, 28, 28, 0.3);
  color: var(--danger);
}

.bottom-bar {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 40;
  display: grid;
  grid-template-columns: 1fr 56px 56px 1fr;
  gap: 8px;
  padding: 10px 12px calc(10px + var(--safe-bottom));
  background: rgba(16, 35, 31, 0.96);
  border-top: 1px solid rgba(255, 255, 255, 0.12);
}

.bottom-bar button {
  min-height: 48px;
  border: 1px solid rgba(255, 255, 255, 0.14);
  background: #ffffff;
  color: var(--ink);
  font-weight: 800;
}

.bottom-bar button:first-child,
.bottom-bar button:last-child {
  background: #58d6c8;
}

@media (min-width: 760px) {
  .mobile-header,
  .quick-stats,
  .question-tabs,
  .home-screen,
  .admin-screen,
  .workspace,
  .bottom-bar {
    max-width: 760px;
    margin-left: auto;
    margin-right: auto;
  }

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

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

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

  .learner-row {
    grid-template-columns: 160px 1fr 120px;
    align-items: center;
  }
}

@media (min-width: 1024px) {
  .app-shell {
    padding-bottom: 0;
  }

  .mobile-header,
  .quick-stats,
  .question-tabs,
  .home-screen,
  .admin-screen,
  .workspace {
    max-width: 980px;
  }

  .workspace {
    grid-template-columns: minmax(0, 1fr) 330px;
    align-items: start;
  }

  .viewer,
  .question-list-section {
    grid-column: 1;
  }

  .image-stage {
    max-height: 70vh;
  }

  .study-actions,
  .answer-panel,
  .focus-details,
  .filters,
  .note-section {
    grid-column: 2;
  }

  .bottom-bar {
    left: 50%;
    right: auto;
    width: 980px;
    transform: translateX(-50%);
    border-radius: 0;
  }
}
