:root {
  --paper: #fffef8;
  --ink: #151515;
  --muted: #5f6368;
  --rule: #a4c268;
  --blue: #2f73d9;
  --green: #38a169;
  --grade-1: #e53935;
  --grade-2: #f3c400;
  --grade-3: #43a047;
  --grade-4: #039be5;
  --grade-5: #1565c0;
  --grade-6: #8e24aa;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  color: var(--ink);
  background: #dfe8ee;
  font-family: "Hiragino Sans", "Yu Gothic", "Meiryo", system-ui, sans-serif;
}

.toolbar {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  justify-content: center;
  gap: 8px;
  padding: 10px;
  background: rgba(255, 255, 255, 0.94);
  border-bottom: 1px solid #d7dde3;
  backdrop-filter: blur(10px);
}

.tool-btn,
.tool-link {
  min-width: 44px;
  min-height: 40px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: 1px solid #b9c2cc;
  border-radius: 8px;
  padding: 0 12px;
  background: #fff;
  color: #22313f;
  font-size: 0.95rem;
  font-weight: 800;
  line-height: 1;
  text-decoration: none;
  cursor: pointer;
}

.tool-btn.active {
  border-color: var(--blue);
  background: var(--blue);
  color: #fff;
}

.page-shell {
  width: min(100%, 1120px);
  margin: 0 auto;
  padding: 18px;
}

.worksheet {
  border: 1px solid #d4d0c8;
  background: var(--paper);
  box-shadow: 0 18px 45px rgba(40, 50, 60, 0.22);
  padding: clamp(18px, 4vw, 42px);
}

.menu-panel {
  max-width: 820px;
  margin: 0 auto;
}

.menu-head {
  margin-bottom: 24px;
}

.menu-title {
  display: block;
  font-size: clamp(2rem, 5vw, 3.5rem);
  font-weight: 900;
  line-height: 1.1;
}

.menu-subtitle {
  display: block;
  margin-top: 8px;
  color: var(--muted);
  font-size: 1rem;
  font-weight: 700;
}

.section-row {
  border: 1px solid #d6dde5;
  border-radius: 8px;
  overflow: hidden;
  background: #fff;
}

.section-row + .section-row {
  margin-top: 10px;
}

.section-toggle,
.page-row {
  width: 100%;
  border: 0;
  background: #fff;
  color: var(--ink);
  cursor: pointer;
  text-align: left;
}

.section-toggle {
  display: grid;
  grid-template-columns: 32px minmax(100px, 1fr) minmax(120px, 1fr) auto;
  gap: 12px;
  align-items: center;
  min-height: 62px;
  padding: 0 16px;
}

.section-toggle:hover,
.page-row:hover {
  background: #f3f7fb;
}

.section-caret {
  width: 28px;
  height: 28px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  background: #e7eef8;
  color: var(--blue);
  font-size: 1.25rem;
  font-weight: 900;
}

.section-title {
  font-size: 1.25rem;
  font-weight: 900;
}

.section-subtitle,
.section-count,
.page-meta,
.empty-section {
  color: var(--muted);
  font-size: 0.9rem;
  font-weight: 700;
}

.section-count {
  justify-self: end;
}

.page-list {
  border-top: 1px solid #e2e8f0;
}

.page-row {
  display: grid;
  grid-template-columns: minmax(120px, 0.45fr) minmax(0, 1fr);
  gap: 16px;
  align-items: center;
  min-height: 54px;
  padding: 0 20px 0 60px;
  border-top: 1px solid #edf2f7;
}

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

.page-title {
  font-size: 1.1rem;
  font-weight: 900;
}

.empty-section {
  display: block;
  padding: 16px 20px 18px 60px;
}

.practice-head {
  display: flex;
  align-items: center;
  gap: 16px;
  margin-bottom: 24px;
}

.back-btn {
  border: 1px solid #b9c2cc;
  border-radius: 8px;
  background: #fff;
  min-height: 40px;
  padding: 0 14px;
  color: #22313f;
  font-weight: 900;
  cursor: pointer;
}

.back-btn:hover {
  background: #f3f7fb;
}

.practice-title {
  display: block;
  font-size: clamp(1.5rem, 3vw, 2.4rem);
  font-weight: 900;
  line-height: 1.1;
}

.practice-subtitle {
  display: block;
  margin-top: 4px;
  color: var(--muted);
  font-size: 0.95rem;
  font-weight: 700;
}

.practice-list {
  display: grid;
  gap: 28px;
}

.practice-row {
  display: grid;
  grid-template-columns: 116px minmax(0, 1fr);
  gap: 28px;
  align-items: start;
}

.rep-counter {
  display: grid;
  grid-template-columns: 28px 56px 28px;
  gap: 4px;
  align-items: center;
  justify-content: start;
}

.counter-btn {
  width: 28px;
  height: 40px;
  border: 1px solid #bec8d2;
  border-radius: 8px;
  background: #fff;
  color: #22313f;
  font-size: 1.4rem;
  font-weight: 900;
  line-height: 1;
  cursor: pointer;
}

.counter-btn:hover {
  background: #f3f7fb;
}

.count-mark {
  width: 56px;
  height: 56px;
  display: flex;
  align-items: center;
  justify-content: center;
  border: 2px solid var(--rule);
  color: #22313f;
  background:
    linear-gradient(90deg, transparent calc(50% - 0.5px), rgba(170, 170, 170, 0.34) 50%, transparent calc(50% + 0.5px)),
    linear-gradient(transparent calc(50% - 0.5px), rgba(170, 170, 170, 0.34) 50%, transparent calc(50% + 0.5px)),
    #fffefb;
  font-size: 1.8rem;
  font-weight: 900;
  line-height: 1;
}

.rep-counter.complete .count-mark {
  border-color: var(--green);
  color: var(--green);
  background: #e8f8ef;
}

.kanji-item {
  display: grid;
  grid-template-columns: 64px minmax(0, 1fr);
  gap: 22px;
  align-items: start;
}

.kanji-label {
  font-size: clamp(2rem, 3.4vw, 3.2rem);
  font-weight: 900;
  line-height: 1;
  text-align: center;
}

.reading-lines {
  display: grid;
  gap: 14px;
}

.reading-line {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: 18px;
  min-height: 36px;
}

.reading-cue {
  min-width: 58px;
  color: var(--ink);
  font-size: clamp(1.2rem, 2vw, 1.8rem);
  font-weight: 700;
}

.segment {
  position: relative;
  display: inline-flex;
  flex-direction: column;
  align-items: center;
  justify-content: flex-end;
  min-height: 2.7em;
  color: var(--ink);
  font-size: clamp(1.2rem, 1.9vw, 1.75rem);
  font-weight: 900;
  line-height: 1.1;
  white-space: nowrap;
}

.segment.grade-1 { color: var(--grade-1); }
.segment.grade-2 { color: var(--grade-2); }
.segment.grade-3 { color: var(--grade-3); }
.segment.grade-4 { color: var(--grade-4); }
.segment.grade-5 { color: var(--grade-5); }
.segment.grade-6 { color: var(--grade-6); }

.furigana {
  min-height: 1em;
  color: #222;
  font-size: 0.46em;
  font-weight: 500;
  line-height: 1;
}

body:not(.show-furigana) .furigana {
  visibility: hidden;
}

.english {
  display: none;
  max-width: 150px;
  margin-top: 3px;
  color: #315f83;
  font-size: 0.42em;
  font-weight: 700;
  line-height: 1.15;
  text-align: center;
  white-space: normal;
}

body.show-english .english {
  display: block;
}

.review {
  display: grid;
  grid-template-columns: 1fr 1fr;
  margin-top: 40px;
  border: 1px solid #222;
  background: rgba(255, 255, 255, 0.45);
}

.review-box {
  min-height: 118px;
  padding: 14px 18px;
}

.review-box + .review-box {
  border-left: 1px solid #222;
}

.review-word {
  display: inline-flex;
  flex-direction: column;
  align-items: center;
  margin: 0 20px 10px 0;
  color: var(--grade-1);
  font-size: clamp(1.05rem, 1.55vw, 1.35rem);
  font-weight: 900;
  line-height: 1.1;
}

.load-error {
  padding: 32px;
  color: #8a1f11;
  font-size: 1.1rem;
  font-weight: 700;
}

@media (max-width: 760px) {
  .page-shell {
    padding: 8px;
  }

  .worksheet {
    padding: 18px 14px 26px;
  }

  .section-toggle {
    grid-template-columns: 32px minmax(0, 1fr) auto;
  }

  .section-subtitle {
    display: none;
  }

  .page-row {
    grid-template-columns: 1fr;
    gap: 4px;
    padding: 12px 16px 12px 60px;
  }

  .practice-head {
    align-items: flex-start;
  }

  .practice-row {
    grid-template-columns: 92px minmax(0, 1fr);
    gap: 12px;
  }

  .rep-counter {
    grid-template-columns: 24px 44px 24px;
  }

  .counter-btn {
    width: 24px;
    height: 36px;
  }

  .count-mark {
    width: 44px;
    height: 44px;
    font-size: 1.45rem;
  }

  .kanji-item {
    grid-template-columns: 44px minmax(0, 1fr);
    gap: 10px;
  }

  .reading-line {
    gap: 14px;
  }

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

  .review-box + .review-box {
    border-left: 0;
    border-top: 1px solid #222;
  }
}
