:root {
  --ink: #111111;
  --muted: #222222;
  --paper: #e7dcc8;
  --card: #fffdf8;
  --line: #c4c4c4;
  --green: #0c6b43;
  --green-soft: #e5f6ed;
  --red: #a11d18;
  --red-soft: #fdeceb;
  --amber: #8a4508;
  --amber-soft: #fff3df;
  --blue: #1a4f8b;
  --blue-soft: #e7f0fb;
  --code: #f4f7fb;
  --shadow: 0 8px 22px rgba(20, 32, 51, 0.07);
  --dock: 76px;
  --safe-top: env(safe-area-inset-top);
  --safe-bot: env(safe-area-inset-bottom);
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
html { font-size: 19px; }
body {
  font-family: Tahoma, "Leelawadee UI", "Sukhumvit Set", "Thonburi", sans-serif;
  font-weight: 400;
  font-size: 1rem;
  line-height: 1.7;
  color: #111111;
  background: var(--paper);
  min-height: 100dvh;
  -webkit-font-smoothing: subpixel-antialiased;
  -webkit-text-size-adjust: 100%;
}

button, input, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
code {
  font-family: Consolas, "Courier New", Tahoma, "Leelawadee UI", monospace;
  font-size: 0.95em;
  font-weight: 700;
  background: #f3ead8;
  color: #111111;
  border: 1px solid #bdbdbd;
  padding: 0.05em 0.35em;
  border-radius: 6px;
}
pre {
  margin: 0;
  overflow: auto;
  -webkit-overflow-scrolling: touch;
  background: #fffdf8;
  color: #111111;
  border: 2px solid #222222;
  border-radius: 14px;
  padding: 14px 16px;
  font-family: Consolas, "Courier New", Tahoma, "Leelawadee UI", monospace;
  font-size: 17px;
  font-weight: 700;
  line-height: 1.6;
}
pre code { background: transparent; color: inherit; padding: 0; }

.wrap {
  width: min(860px, calc(100% - 28px));
  margin: 0 auto;
  padding: calc(18px + var(--safe-top)) 0 calc(24px + var(--dock) + var(--safe-bot));
}
.home-wrap { padding-bottom: calc(28px + var(--safe-bot)); }

.banner {
  background: var(--card);
  color: var(--ink);
  border: 1px solid var(--line);
  border-left: 6px solid var(--green);
  border-radius: 18px;
  padding: 16px 18px;
  margin-bottom: 18px;
}
.banner p { margin: 0 0 8px; color: #111; font-weight: 700; }
.banner strong {
  display: block;
  font-size: 1.35rem;
  letter-spacing: 0.01em;
  word-break: break-all;
  color: var(--ink);
}
.banner button {
  margin-top: 8px;
  background: var(--green-soft);
  color: var(--green);
  border: 1px solid #b7dcc8;
  border-radius: 999px;
  min-height: 44px;
  padding: 0 16px;
}

h1 { font-size: 1.7rem; line-height: 1.3; margin: 0 0 8px; font-weight: 700; color: #111; }
h2 { margin: 0 0 8px; font-size: 1.28rem; font-weight: 700; color: #111; line-height: 1.35; }
.h-main { color: #0b5c38; }
.h-sub { color: #154a86; }
.em, .point { color: #8a3200; }
.color-key { display: flex; flex-wrap: wrap; gap: 8px 14px; margin: 0 0 12px; }
.key-item { font-weight: 700; font-size: 0.95rem; }
.key-item::before {
  content: "";
  display: inline-block;
  width: 12px;
  height: 12px;
  border-radius: 3px;
  margin-right: 6px;
  vertical-align: -1px;
  background: currentColor;
}
.lead { color: #111; margin: 0 0 18px; line-height: 1.7; }

.field { display: flex; flex-direction: column; gap: 6px; margin-bottom: 16px; }
.field span { font-weight: 650; }
.field input {
  min-height: 52px;
  border-radius: 14px;
  border: 1px solid var(--line);
  background: var(--card);
  padding: 0 14px;
  font-size: 19px;
  font-weight: 700;
  color: #111;
}

.tracks { display: grid; gap: 12px; }
@media (min-width: 800px) {
  .tracks { grid-template-columns: 1fr 1fr; }
}
.track {
  text-align: left;
  background: var(--card);
  border: 2px solid var(--line);
  border-radius: 18px;
  padding: 16px;
  min-height: 120px;
  box-shadow: var(--shadow);
}
.track.on { border-color: var(--green); background: var(--green-soft); }
.track b { display: block; font-size: 1.2rem; margin-bottom: 4px; }
.track small { color: #111; line-height: 1.55; display: block; }

.row { display: flex; flex-wrap: wrap; gap: 10px; margin-top: 16px; }
.btn {
  min-height: 52px;
  border-radius: 14px;
  border: 1px solid var(--line);
  background: var(--card);
  padding: 0 18px;
}
.btn.primary { background: var(--green); color: white; border-color: var(--green); }
.btn.ghost { background: transparent; }
.btn:disabled { opacity: 0.45; }

.rules { margin: 18px 0 0; padding-left: 18px; color: #111; }
.rules li { margin: 6px 0; }

.topbar {
  position: sticky;
  top: 0;
  z-index: 5;
  background: rgba(231, 220, 200, 0.96);
  backdrop-filter: blur(10px);
  padding: 10px 0 8px;
  margin: 0 0 8px;
}
.topbar .meta { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.chip {
  display: inline-flex;
  align-items: center;
  min-height: 28px;
  padding: 0 10px;
  border-radius: 999px;
  background: #efe4d0;
  color: var(--ink);
  font-size: 0.95rem;
  font-weight: 700;
}
.chip.junior { background: var(--blue-soft); color: var(--blue); }
.chip.senior { background: var(--amber-soft); color: var(--amber); }
.chip.advance { background: #f3e8f8; color: #5c2d6e; }
.progress {
  height: 8px;
  background: #dde3eb;
  border-radius: 99px;
  margin-top: 10px;
  overflow: hidden;
}
.progress > span { display: block; height: 100%; background: var(--green); width: 0; }

.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 20px;
  padding: 16px;
  box-shadow: var(--shadow);
}
.prompt { font-size: 1.12rem; line-height: 1.7; font-weight: 700; white-space: pre-wrap; margin: 0 0 12px; color: #111; }
.prompt + .prompt { margin-top: 0; }
.card pre { margin: 10px 0 14px; }
.preface {
  background: var(--code);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 12px;
  margin-bottom: 12px;
}
.preface h3 { margin: 0 0 8px; font-size: 1rem; color: #111; font-weight: 700; }

.options { display: flex; flex-direction: column; gap: 10px; }
.option {
  display: flex;
  gap: 12px;
  align-items: flex-start;
  text-align: left;
  width: 100%;
  min-height: 56px;
  padding: 12px;
  border-radius: 16px;
  border: 2px solid var(--line);
  background: #fff;
}
.option .key {
  flex: 0 0 36px;
  height: 36px;
  border-radius: 10px;
  display: grid;
  place-items: center;
  background: #e8eef6;
  color: var(--ink);
  font-weight: 750;
}
.option .txt { padding-top: 6px; line-height: 1.6; font-weight: 700; color: #111; }
.option.on { border-color: var(--green); background: var(--green-soft); }
.option.on .key { background: var(--green); color: white; }
.option.good { border-color: var(--green); background: var(--green-soft); }
.option.bad { border-color: var(--red); background: var(--red-soft); }
.option:disabled { cursor: default; }

textarea {
  width: 100%;
  min-height: 220px;
  font-size: 18px;
  line-height: 1.6;
  font-weight: 700;
  color: #111;
  border-radius: 16px;
  border: 1px solid var(--line);
  padding: 14px;
  background: #fff;
  resize: vertical;
}

.dock {
  position: fixed;
  left: 0; right: 0; bottom: 0;
  background: rgba(255, 253, 248, 0.96);
  border-top: 1px solid var(--line);
  padding: 10px 14px calc(10px + var(--safe-bot));
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  justify-content: center;
  z-index: 6;
}
.dock .btn { flex: 1; max-width: 220px; }

.sheet-head { display: flex; justify-content: space-between; align-items: center; gap: 8px; }
.skill-label { margin: 16px 0 8px; color: #111; font-weight: 700; }
.grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(52px, 1fr));
  gap: 8px;
}
.cell {
  min-height: 52px;
  border-radius: 12px;
  border: 1px solid var(--line);
  background: white;
  font-weight: 700;
}
.cell.done { background: var(--green-soft); border-color: #b7d8c6; }
.cell.now { outline: 3px solid var(--green); }
.cell.bad { background: var(--red-soft); border-color: #efc3b6; }
.cell.good { background: var(--green-soft); border-color: #b7d8c6; }
.cell.write { font-style: italic; }

.score {
  font-size: 3rem;
  line-height: 1;
  margin: 8px 0;
}
.bar { height: 12px; background: #dde3eb; border-radius: 99px; overflow: hidden; margin: 8px 0 4px; }
.bar > span { display: block; height: 100%; background: var(--green); }
.pass { color: var(--green); font-weight: 750; }
.wait { color: var(--amber); font-weight: 750; }
.fail { color: var(--red); font-weight: 750; }
.case { border: 1px solid #d9cbb6; border-radius: 12px; padding: 10px 12px; margin: 8px 0; background: #fffdf8; }
.case.pass { border-color: #b7d8c6; background: var(--green-soft); }
.case.fail { border-color: #efc3b6; background: var(--red-soft); }
.note { color: #111; line-height: 1.65; }

.lesson {
  width: 100%;
  text-align: left;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 14px 16px;
  margin-bottom: 10px;
}
.lesson b { display: block; margin-bottom: 4px; }
.lesson p { margin: 8px 0 0; color: #111; line-height: 1.65; }
.rubric {
  margin-top: 14px;
  background: var(--code);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 12px;
}
.rubric h3 { margin: 0 0 8px; font-size: 1rem; }
.grades { display: flex; gap: 8px; margin-top: 10px; }
.grades .btn.on { background: var(--ink); color: white; border-color: var(--ink); }

.reason { margin-top: 12px; color: var(--green); font-weight: 650; }
.explain {
  margin-top: 14px;
  padding: 12px 14px;
  background: #f4faf6;
  border: 1px solid #b7d8c6;
  border-radius: 12px;
}
.explain h3 { margin: 0 0 8px; color: #0b5c38; }
.explain p { margin: 8px 0; color: #111; font-weight: 700; line-height: 1.7; }
.explain pre { margin: 8px 0 0; }

.seg {
  display: inline-flex;
  background: #ddd0b8;
  border-radius: 14px;
  padding: 4px;
  gap: 4px;
  margin: 4px 0 16px;
}
.seg-btn {
  min-height: 44px;
  min-width: 76px;
  border: 0;
  border-radius: 10px;
  background: transparent;
  color: #111;
  font-weight: 700;
}
.seg-btn.on { background: var(--ink); color: #fff; box-shadow: none; }

.lesson-grid { display: grid; gap: 10px; }
@media (min-width: 760px) { .lesson-grid { grid-template-columns: 1fr 1fr; } }
.lesson-card {
  text-align: left;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 14px 16px;
  box-shadow: var(--shadow);
}
.lesson-card p { margin: 6px 0 8px; color: #111; font-weight: 700; }
.lesson-top { display: flex; justify-content: space-between; align-items: flex-start; gap: 10px; }
.lesson-top h2 { margin: 0; }
.bar.small { height: 6px; margin: 0; }

.goal {
  background: var(--green-soft);
  color: var(--ink);
  border: 1px solid #b7dcc8;
  border-radius: 18px;
  padding: 14px 16px;
  margin-bottom: 14px;
}
.goal h2.h-sub { color: #154a86; }
.goal p { margin: 6px 0; line-height: 1.7; color: #111; font-weight: 700; }
.goal .note { color: #111; font-weight: 700; }

.lesson-section { margin-bottom: 14px; }
.lesson-p { line-height: 1.75; margin: 10px 0; font-size: 1.08rem; font-weight: 700; color: #111; }
.lesson-ul { margin: 8px 0; padding-left: 22px; }
.lesson-ul li { margin: 8px 0; line-height: 1.75; font-weight: 700; }
.lesson-ul li::marker { color: #8a3200; }
.lesson-section pre { margin-top: 12px; }
.lesson-section h3 { margin: 18px 0 8px; font-size: 1.15rem; }

.trap { display: grid; gap: 6px; padding: 10px 0; }
.trap + .trap { border-top: 1px solid var(--line); }
.trap p { margin: 0; line-height: 1.55; color: var(--ink); border-radius: 10px; padding: 8px 10px; }
.trap-wrong { background: var(--red-soft); }
.trap-right { background: var(--green-soft); }
.trap-wrong b { color: #7a100c; }
.trap-right b { color: #08522f; }

.selfq { border-top: 1px solid var(--line); padding: 6px 0 10px; }
.selfa {
  background: var(--green-soft);
  color: var(--ink);
  border: 1px solid #b7dcc8;
  border-radius: 12px;
  padding: 10px 12px;
  line-height: 1.55;
  margin: 4px 0 0;
}

.check {
  display: flex;
  gap: 12px;
  align-items: center;
  width: 100%;
  text-align: left;
  min-height: 52px;
  padding: 8px 4px;
  background: transparent;
  border: 0;
  border-top: 1px solid var(--line);
}
.check .box {
  flex: 0 0 28px;
  height: 28px;
  border-radius: 8px;
  border: 2px solid var(--line);
  display: grid;
  place-items: center;
  font-weight: 800;
  color: white;
}
.check .chip { flex: 0 0 auto; }
.check.on .box { background: var(--green); border-color: var(--green); }
.check.on span:last-child { color: var(--ink); text-decoration: line-through; text-decoration-color: #7d8794; }
