:root {
  --bg: #fff8ee;
  --accent: #ff8a5c;
  --accent-dark: #e06a3c;
  --text: #3a2e2e;
  --card-bg: #ffffff;
  --moral-bg: #fff1d6;
}

* { box-sizing: border-box; }

html {
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
}

body {
  margin: 0;
  font-family: "Hiragino Maru Gothic ProN", "UD Digi Kyokasho", "Yu Gothic", sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.8;
  overflow-wrap: break-word;
}

h1, h2, p, label, .q, .hint, .story-title, .story-body, .story-note, summary {
  line-height: 1.8;
}

.app-header {
  background: var(--accent);
  color: white;
  padding: 24px 16px;
  text-align: center;
}

.app-header h1 {
  margin: 0;
  font-size: 1.8rem;
  cursor: pointer;
}

.app-header h1:focus-visible {
  outline: 2px solid white;
  outline-offset: 4px;
}

.subtitle {
  margin: 4px 0 0;
  font-size: 0.95rem;
  opacity: 0.95;
}

main {
  max-width: 640px;
  margin: 0 auto;
  padding: 16px;
}

.selector-card, .content-card, .moral-card, .calendar-card {
  background: var(--card-bg);
  border-radius: 16px;
  padding: 16px;
  margin-bottom: 16px;
  box-shadow: 0 2px 8px rgba(0,0,0,0.06);
}

.calendar-card {
  background: #fff4ec;
  border: 2px solid var(--accent);
}

.calendar-card h2 {
  margin-top: 0;
  font-size: 1.2rem;
  color: var(--accent-dark);
}

.date-row {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 12px;
}

.date-row input[type="date"] {
  flex: 1;
  font-size: 1.05rem;
  padding: 10px;
  border-radius: 10px;
  border: 2px solid #eee;
  background: white;
  font-family: inherit;
  color: var(--text);
}

.date-row button {
  min-height: 44px;
  padding: 0 16px;
  font-size: 1rem;
  font-weight: bold;
  font-family: inherit;
  color: white;
  background: var(--accent-dark);
  border: none;
  border-radius: 10px;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}

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

.daily-subject:last-child { margin-bottom: 0; }

.daily-subject-label {
  font-weight: bold;
  margin-bottom: 6px;
  color: var(--accent-dark);
}

.picker-group {
  margin-bottom: 16px;
}

.picker-group:last-child { margin-bottom: 0; }

.picker-label {
  font-weight: bold;
  margin-bottom: 8px;
  color: var(--accent-dark);
}

.grade-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
}

.grade-grid-jr {
  margin-top: 8px;
}

.grade-grid-yoji {
  grid-template-columns: 1fr;
  margin-bottom: 12px;
}

.yoji-btn {
  min-height: 52px;
  font-size: 1.05rem;
  background: #fff4ec;
  border-color: var(--accent);
}

.yoji-btn.active {
  background: var(--accent);
  border-color: var(--accent-dark);
  color: white;
}

.grade-btn {
  min-height: 56px;
  font-size: 1.3rem;
  font-weight: bold;
  font-family: inherit;
  color: var(--text);
  background: #fafafa;
  border: 2px solid #eee;
  border-radius: 12px;
  cursor: pointer;
  display: flex;
  align-items: baseline;
  justify-content: center;
  gap: 2px;
  padding: 8px;
  -webkit-tap-highlight-color: transparent;
}

.grade-btn .grade-unit {
  font-size: 0.85rem;
  font-weight: normal;
}

.grade-btn.active {
  background: var(--accent);
  border-color: var(--accent-dark);
  color: white;
}

.subject-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
}

.subject-btn {
  min-height: 76px;
  font-family: inherit;
  color: var(--text);
  background: #fafafa;
  border: 2px solid #eee;
  border-radius: 12px;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 4px;
  padding: 8px;
  -webkit-tap-highlight-color: transparent;
}

.subject-icon {
  font-size: 1.8rem;
  line-height: 1;
}

.subject-name {
  font-size: 0.9rem;
  font-weight: bold;
}

.subject-btn.active {
  background: var(--accent);
  border-color: var(--accent-dark);
  color: white;
}

.content-card h2 {
  margin-top: 0;
  color: var(--accent-dark);
  font-size: 1.3rem;
}

.item {
  background: #fafafa;
  border-radius: 12px;
  padding: 12px 14px;
  margin-bottom: 10px;
}

.item .q {
  font-weight: bold;
  font-size: 1.15rem;
}

.item .hint {
  color: #6b6b6b;
  font-size: 0.9rem;
  margin-top: 6px;
}

.item details {
  margin-top: 8px;
}

.item summary {
  cursor: pointer;
  color: var(--accent-dark);
  font-weight: bold;
}

.item .answer {
  margin-top: 8px;
  padding: 8px 10px;
  background: #fff2ea;
  border-radius: 8px;
  font-size: 1.05rem;
  font-weight: bold;
}

.feedback-row {
  margin-top: 10px;
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 8px;
}

.feedback-label {
  font-size: 0.9rem;
  color: #6b6b6b;
  width: 100%;
}

.fb-btn {
  min-height: 40px;
  padding: 0 14px;
  font-size: 0.95rem;
  font-weight: bold;
  font-family: inherit;
  border: 2px solid #eee;
  border-radius: 10px;
  background: #ffffff;
  color: var(--text);
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}

.fb-correct.picked { background: #e3f5e3; border-color: #6cc16c; }
.fb-wrong.picked { background: #fde3e3; border-color: #e08a8a; }

.feedback-msg {
  margin-top: 6px;
  font-weight: bold;
  color: var(--accent-dark);
  min-height: 1.2em;
}

.explain-toggle {
  margin-top: 8px;
  display: block;
  width: 100%;
  text-align: left;
  background: none;
  border: none;
  color: var(--accent-dark);
  font-family: inherit;
  font-size: 0.9rem;
  font-weight: bold;
  text-decoration: underline;
  cursor: pointer;
  padding: 4px 0;
  -webkit-tap-highlight-color: transparent;
}

.explanation {
  margin-top: 8px;
  padding: 10px 12px;
  background: #eef7ff;
  border: 2px solid #bcdcff;
  border-radius: 10px;
}

.explanation.hidden { display: none; }

.explanation-title {
  font-weight: bold;
  color: #2a6bb0;
  margin-bottom: 6px;
}

.explanation-section { margin-top: 8px; }
.explanation-section:first-of-type { margin-top: 0; }

.explanation-label {
  font-size: 0.85rem;
  font-weight: bold;
  color: #4a7fae;
  margin-bottom: 2px;
}

.explanation-body { font-size: 1rem; }

.explanation.flash { animation: flash-bg 1.2s ease; }
@keyframes flash-bg {
  0% { box-shadow: 0 0 0 4px rgba(255,138,92,0.6); }
  100% { box-shadow: 0 0 0 0 rgba(255,138,92,0); }
}

.placeholder {
  text-align: center;
  color: #999;
  padding: 24px 0;
}

.moral-card {
  background: var(--moral-bg);
}

.moral-card h2 {
  margin-top: 0;
  font-size: 1.2rem;
}

.moral-card .story-title {
  font-weight: bold;
  font-size: 1.1rem;
  margin-bottom: 8px;
}

.moral-card .story-body {
  font-size: 1.1rem;
}

.moral-card .story-note {
  margin-top: 10px;
  font-size: 0.85rem;
  color: #8a6a3a;
}

.app-footer {
  text-align: center;
  padding: 20px;
  font-size: 0.85rem;
  color: #999;
}

.header-home-link {
  color: inherit;
  text-decoration: none;
  display: inline-block;
}

.header-home-link:focus-visible h1 {
  outline: 2px solid white;
  outline-offset: 4px;
}

.back-link {
  text-align: center;
  margin: 4px 0 16px;
}

.breadcrumb {
  font-size: 0.78rem;
  color: #8a8a8a;
  margin-bottom: 10px;
}

.breadcrumb a {
  color: #8a8a8a;
}

.breadcrumb span {
  color: var(--accent-dark);
}

.back-link a {
  color: var(--accent-dark);
  font-size: 0.95rem;
}

.story-nav {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 16px;
}

.story-nav a {
  flex: 1;
  font-size: 0.85rem;
  color: var(--accent-dark);
  text-decoration: none;
  padding: 10px 12px;
  border: 2px solid #eee;
  border-radius: 10px;
  background: var(--card-bg);
}

.story-nav-next {
  text-align: right;
}

.applicable-grades {
  margin-top: 10px;
  font-size: 0.8rem;
  color: #8a6a3a;
}

.moral-card .story-list {
  list-style: none;
  margin: 0;
  padding: 0;
}

.moral-card .story-list li {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 10px;
  padding: 10px 0;
  border-bottom: 1px solid #f0e4c8;
}

.moral-card .story-list li:last-child {
  border-bottom: none;
}

.moral-card .story-list a {
  color: var(--text);
  font-size: 1rem;
  font-weight: bold;
  text-decoration: none;
}

.moral-card .story-list a:hover {
  color: var(--accent-dark);
}

.grade-tag {
  font-size: 0.78rem;
  color: #8a6a3a;
  white-space: nowrap;
}
