*, *::before, *::after {
  box-sizing: border-box;
}

:root {
  --green: #1e7a46;
  --green-dark: #2b5d49;
  --bg: #f7f5f0;
  --card: #ffffff;
  --text: #1c1a17;
  --muted: #646f68;
  --line: #e3ded2;
  --danger: #b3261e;
  --warn-bg: #fdf0e4;
  --warn-text: #8a4b0f;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: system-ui, "Hiragino Sans", "Hiragino Kaku Gothic ProN", "Noto Sans JP", sans-serif;
  font-size: 16px;
  line-height: 1.6;
}

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

.app-header {
  position: sticky;
  top: 0;
  background: var(--card);
  border-bottom: 1px solid var(--line);
  padding: calc(env(safe-area-inset-top) + 10px) 16px 10px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  z-index: 40;
}

.app-title {
  font-size: 17px;
  font-weight: 700;
  margin: 0;
}

.icon-button {
  width: 44px;
  height: 44px;
  background: transparent;
  border: none;
  font-size: 20px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0;
}

#view-root {
  max-width: 720px;
  margin: 0 auto;
  padding: 16px 16px 96px;
}

@keyframes view-in {
  from {
    opacity: 0;
    transform: translateY(6px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.view {
  animation: view-in .18s ease-out;
}

@media (prefers-reduced-motion: reduce) {
  .view {
    animation: none;
  }
}

.tab-bar {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  background: var(--card);
  border-top: 1px solid var(--line);
  display: flex;
  padding-bottom: env(safe-area-inset-bottom);
  z-index: 50;
}

.tab-item {
  flex: 1;
  min-height: 56px;
  background: transparent;
  border: none;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  color: var(--muted);
  cursor: pointer;
  padding: 0;
}

.tab-icon {
  font-size: 20px;
  line-height: 1;
}

.tab-label {
  font-size: 11px;
  line-height: 1;
}

.tab-item.is-active {
  color: var(--green-dark);
  font-weight: 700;
  box-shadow: inset 0 2px 0 var(--green);
}

.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 16px;
  margin-bottom: 12px;
}

.big-number {
  font-size: 34px;
  font-weight: 800;
}

.btn-primary {
  display: block;
  width: 100%;
  min-height: 52px;
  background: var(--green);
  color: #ffffff;
  border: none;
  border-radius: 12px;
  font-size: 16px;
  font-weight: 700;
  cursor: pointer;
}

.btn-primary:active {
  transform: scale(.99);
}

.btn-primary:disabled {
  opacity: .45;
}

.btn-quiet {
  background: transparent;
  color: var(--green-dark);
  border: 1px solid var(--line);
  border-radius: 10px;
  min-height: 44px;
  padding: 0 14px;
  cursor: pointer;
}

.progress-track {
  height: 8px;
  background: var(--line);
  border-radius: 999px;
  overflow: hidden;
}

.progress-fill {
  height: 100%;
  background: var(--green);
  border-radius: 999px;
  transition: width .3s ease;
}

.subject-row {
  margin-bottom: 12px;
}

.subject-row-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.chips {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.chip {
  min-height: 40px;
  padding: 0 14px;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: var(--card);
  cursor: pointer;
  font-size: 14px;
  display: inline-flex;
  align-items: center;
}

.chip.is-selected {
  background: var(--green-dark);
  color: #ffffff;
  border-color: var(--green-dark);
}

.segmented {
  display: flex;
  background: #eceae2;
  border-radius: 10px;
  padding: 3px;
  gap: 3px;
}

.segmented button {
  flex: 1;
  min-height: 40px;
  border: none;
  background: transparent;
  border-radius: 8px;
  font-size: 14px;
  cursor: pointer;
}

.segmented button.is-selected {
  background: var(--card);
  font-weight: 700;
  box-shadow: 0 1px 3px rgba(0, 0, 0, .15);
}

.field-label {
  font-size: 13px;
  color: var(--muted);
  font-weight: 700;
  margin: 14px 0 6px;
}

.q-meta {
  font-size: 13px;
  color: var(--muted);
}

.q-progress {
  display: flex;
  align-items: center;
  gap: 8px;
}

.q-prompt {
  font-size: 17px;
  line-height: 1.75;
  white-space: pre-wrap;
  margin: 12px 0;
}

.q-blank {
  background: #fff3cd;
  padding: 0 6px;
  border-radius: 4px;
  font-weight: 700;
}

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

.choice-btn {
  text-align: left;
  min-height: 52px;
  padding: 12px 14px;
  background: var(--card);
  border: 1.5px solid var(--line);
  border-radius: 12px;
  font-size: 16px;
  cursor: pointer;
  line-height: 1.5;
  width: 100%;
}

.choice-btn.is-correct {
  border-color: var(--green);
  background: #e8f4ec;
}

.choice-btn.is-wrong {
  border-color: var(--danger);
  background: #fdecea;
}

.choice-btn:disabled {
  opacity: .85;
}

.answer-panel {
  background: #f0efe8;
  border-radius: 12px;
  padding: 14px;
  margin-top: 12px;
}

.answer-panel .ans-label {
  font-size: 12px;
  color: var(--muted);
  font-weight: 700;
}

.result-ok {
  color: var(--green-dark);
  font-weight: 800;
}

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

.written-input {
  width: 100%;
  box-sizing: border-box;
  font-size: 16px;
  padding: 12px;
  border: 1.5px solid var(--line);
  border-radius: 10px;
}

.rating-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 8px;
  margin-top: 12px;
}

.rating-btn {
  min-height: 58px;
  border-radius: 12px;
  border: 1.5px solid var(--line);
  background: var(--card);
  cursor: pointer;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 1px;
}

.rating-btn .r-label {
  font-size: 14px;
  font-weight: 700;
}

.rating-btn .r-hint {
  font-size: 11px;
  color: var(--muted);
}

.rating-btn[data-rating="again"] {
  border-color: #e0b184;
  background: var(--warn-bg);
}

.rating-btn:active {
  transform: scale(.98);
}

#update-toast {
  position: fixed;
  left: 12px;
  right: 12px;
  bottom: calc(76px + env(safe-area-inset-bottom));
  z-index: 60;
  background: #33302a;
  color: #ffffff;
  border-radius: 12px;
  padding: 12px 14px;
  display: flex;
  gap: 10px;
  align-items: center;
  box-shadow: 0 4px 16px rgba(0, 0, 0, .3);
}

#update-toast button {
  background: var(--green);
  color: #ffffff;
  border: none;
  border-radius: 8px;
  padding: 8px 14px;
  font-weight: 700;
  cursor: pointer;
  flex-shrink: 0;
}

.finish-stats {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 8px;
  text-align: center;
}

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

.center {
  text-align: center;
}

.is-hidden {
  display: none !important;
}
