:root {
  --bg: #f6f7f4;
  --panel: #ffffff;
  --ink: #202523;
  --muted: #65706a;
  --line: #dce3dd;
  --teal: #0f766e;
  --teal-soft: #d9f2ee;
  --coral: #d95f50;
  --amber: #b7791f;
  --green: #23835b;
  --blue: #3c6fb6;
  --shadow: 0 18px 40px rgba(36, 44, 39, 0.08);
  font-family: "Yu Gothic", "Hiragino Kaku Gothic ProN", Meiryo, system-ui, sans-serif;
}

* { box-sizing: border-box; }
body { margin: 0; min-width: 320px; color: var(--ink); background: var(--bg); }
button, input, textarea, select { font: inherit; }
button { min-height: 40px; border: 0; border-radius: 6px; padding: 0 14px; color: #fff; background: var(--teal); cursor: pointer; }
button:disabled { opacity: 0.5; cursor: not-allowed; }
button.ghost { color: var(--ink); background: #eef1ed; }
button.warn { background: var(--coral); }
button.secondary { background: var(--blue); }
button:focus-visible, input:focus-visible, textarea:focus-visible, select:focus-visible { outline: 3px solid rgba(15, 118, 110, 0.28); outline-offset: 2px; }

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  min-height: 76px;
  padding: 14px clamp(16px, 4vw, 42px);
  border-bottom: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.9);
  position: sticky;
  top: 0;
  z-index: 10;
}

.brand, .top-actions, .card-head, .queue-head, .material-head, .actions, .answer-tools { display: flex; align-items: center; gap: 10px; }
.top-actions, .queue-head, .material-head, .card-head { justify-content: space-between; }
.brand-mark { display: grid; place-items: center; width: 44px; height: 44px; border-radius: 8px; color: #fff; background: var(--teal); font-weight: 800; }
.brand strong, .brand span { display: block; }
.brand span, .muted, .meta, .field-label { color: var(--muted); font-size: 0.82rem; }

.layout {
  display: grid;
  grid-template-columns: minmax(250px, 300px) minmax(0, 1fr) minmax(220px, 280px);
  gap: 18px;
  width: min(1480px, 100%);
  margin: 0 auto;
  padding: 18px clamp(14px, 3vw, 30px) 28px;
}

.side-panel, .coach-panel { position: sticky; top: 94px; align-self: start; max-height: calc(100vh - 112px); overflow: auto; }
.search-box, .coach-card, .metric, .queue, .surface, .topic-button {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: var(--shadow);
}

.search-box { display: block; padding: 14px; }
.search-box span { display: block; margin-bottom: 6px; color: var(--muted); font-size: 0.82rem; font-weight: 800; }
.search-box input, textarea, select { width: 100%; border: 1px solid var(--line); border-radius: 6px; padding: 10px 11px; background: #fbfcfa; }

.tabs { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 4px; margin: 12px 0; padding: 4px; border: 1px solid var(--line); border-radius: 8px; background: #edf1ed; }
.tabs button { min-height: 34px; padding: 0 8px; color: var(--muted); background: transparent; }
.tabs button.active { color: var(--ink); background: #fff; box-shadow: 0 1px 6px rgba(0, 0, 0, 0.06); }

.material-list { display: grid; gap: 10px; }
.topic-button { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 10px; width: 100%; min-height: 84px; padding: 12px; color: var(--ink); text-align: left; }
.topic-button.active { border-color: var(--teal); box-shadow: 0 0 0 3px rgba(15, 118, 110, 0.16); }
.topic-title { display: block; overflow-wrap: anywhere; font-weight: 800; }
.dot { width: 12px; height: 12px; margin-top: 4px; border-radius: 999px; background: #c4cbc5; }
.dot.learning, .cell.learning { background: var(--amber); }
.dot.done, .cell.done, .heat.active { background: var(--green); }
.dot.due, .cell.due { background: var(--coral); }

.metrics { display: grid; grid-template-columns: repeat(4, minmax(120px, 1fr)); gap: 10px; margin-bottom: 12px; }
.metric { min-height: 84px; padding: 14px; }
.metric span { display: block; color: var(--muted); font-size: 0.78rem; font-weight: 800; }
.metric strong { display: flex; align-items: baseline; gap: 5px; flex-wrap: wrap; margin-top: 8px; font-size: clamp(1.35rem, 3vw, 2rem); line-height: 1; word-break: keep-all; }
.metric small { color: var(--muted); font-size: 0.8rem; font-weight: 800; }

.queue { margin-bottom: 12px; padding: 16px; }
.queue h2, .surface h1, .section h2 { margin: 0; }
.queue-items { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 8px; margin-top: 12px; }
.queue-item { min-height: 72px; border: 1px solid var(--line); border-radius: 8px; padding: 10px; color: var(--ink); background: #fbfcfa; }
.queue-item strong { display: block; overflow-wrap: anywhere; font-size: 0.88rem; }

.surface { overflow: hidden; }
.material-top { padding: clamp(18px, 3vw, 28px); border-bottom: 1px solid var(--line); }
.material-head { align-items: flex-start; }
.material-head h1 { max-width: 780px; overflow-wrap: anywhere; font-size: clamp(1.45rem, 3vw, 2.45rem); line-height: 1.12; letter-spacing: 0; }
.pill { flex: 0 0 auto; border-radius: 999px; padding: 6px 10px; color: #fff; background: var(--blue); font-size: 0.76rem; font-weight: 800; }
.pill.bug { background: var(--coral); }
.pill.run { background: var(--green); }
.objective { max-width: 980px; margin: 14px 0 0; line-height: 1.75; }
.section { padding: clamp(16px, 3vw, 26px); border-bottom: 1px solid var(--line); }
.section:last-child { border-bottom: 0; }
.section p, .section li { line-height: 1.78; }
.code { margin: 0; overflow: auto; border-radius: 8px; background: #202523; }
.code code { display: block; min-width: min-content; padding: 16px; color: #edf1ed; font-family: "Cascadia Code", Consolas, monospace; font-size: 0.88rem; line-height: 1.55; white-space: pre; }
textarea { min-height: 104px; resize: vertical; }
.code-editor {
  min-height: 300px;
  font-family: "Cascadia Code", Consolas, monospace;
  font-size: 0.9rem;
  line-height: 1.55;
  color: #edf1ed;
  background: #202523;
  tab-size: 4;
}
.run-output {
  max-height: 280px;
  margin: 10px 0 0;
  overflow: auto;
  border-radius: 6px;
  background: #202523;
}
.run-output code {
  display: block;
  padding: 12px;
  color: #edf1ed;
  font-family: "Cascadia Code", Consolas, monospace;
  font-size: 0.82rem;
  line-height: 1.5;
  white-space: pre;
}
.answer-tools { margin-top: 10px; flex-wrap: wrap; }
.check-result { margin-top: 10px; border: 1px solid var(--line); border-radius: 8px; padding: 12px 14px; color: var(--muted); background: #fbfcfa; }
.check-result strong { display: block; color: var(--ink); }
.check-result p { margin: 6px 0 0; }
.check-result.pass { border-color: rgba(35, 131, 91, 0.35); color: var(--ink); background: #eef8f2; }
.check-result.fail { border-color: rgba(217, 95, 80, 0.35); color: var(--ink); background: #fff3f0; }
.idea-row { display: grid; gap: 5px; margin-top: 10px; }
.idea-row div { display: flex; flex-wrap: wrap; gap: 6px; }
.idea-row div span { border-radius: 999px; padding: 4px 8px; color: var(--ink); background: rgba(255, 255, 255, 0.82); font-size: 0.78rem; font-weight: 800; }
.hint-list { display: grid; gap: 10px; padding: 0; margin: 10px 0 0; list-style: none; }
.hint-list li { border-left: 4px solid var(--amber); padding: 9px 0 9px 12px; background: #fffaf0; }
.actions { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 8px; }
.gate-copy { margin: 10px 0 0; color: var(--muted); font-size: 0.88rem; }
.callout { border-left: 4px solid var(--teal); padding: 12px 14px; background: var(--teal-soft); }
.remediation-frame { width: 100%; height: min(560px, 72vh); border: 1px solid var(--line); border-radius: 8px; background: #fff; }
.empty { padding: 20px; border: 1px dashed var(--line); border-radius: 8px; color: var(--muted); background: #fff; }

.coach-panel { display: grid; gap: 12px; }
.coach-card { padding: 14px; }
.card-head span { color: var(--muted); font-size: 0.82rem; font-weight: 800; }
.heatmap, .study-map { display: grid; gap: 5px; margin-top: 12px; }
.heatmap { grid-template-columns: repeat(14, minmax(9px, 1fr)); }
.study-map { grid-template-columns: repeat(6, minmax(18px, 1fr)); }
.heat, .cell { aspect-ratio: 1; border-radius: 4px; background: #e1e6e1; }
.heat.today { box-shadow: inset 0 0 0 2px var(--ink); }
.coach-advice { display: grid; gap: 8px; margin-top: 12px; }
.coach-advice p { margin: 0; border-left: 3px solid var(--teal); border-radius: 6px; padding: 9px 10px; color: #35403a; background: var(--teal-soft); font-size: 0.82rem; line-height: 1.65; }

.modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 40;
  display: grid;
  place-items: center;
  padding: 18px;
  overflow: auto;
  background: rgba(32, 37, 35, 0.5);
}

.modal {
  width: min(680px, 100%);
  border-radius: 10px;
  padding: clamp(20px, 4vw, 30px);
  background: var(--panel);
  box-shadow: 0 30px 70px rgba(0, 0, 0, 0.28);
}

.modal h2 { margin: 0 0 6px; }
.plan-group { margin-top: 18px; }
.field-label { display: block; margin-bottom: 8px; font-weight: 800; }
.choice-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 8px; }
.choice { display: flex; align-items: center; gap: 9px; min-width: 0; border: 1px solid var(--line); border-radius: 8px; padding: 11px 12px; background: #fbfcfa; cursor: pointer; }
.choice.selected { border-color: var(--teal); background: var(--teal-soft); }
.choice input { flex: 0 0 auto; width: 17px; height: 17px; accent-color: var(--teal); }
.choice span { min-width: 0; }
.choice strong { display: block; overflow-wrap: anywhere; font-size: 0.9rem; }
.plan-row { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; margin-top: 18px; }
.modal-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 24px; }

@media (max-width: 1120px) {
  .layout { grid-template-columns: minmax(230px, 280px) minmax(0, 1fr); }
  .coach-panel { grid-column: 1 / -1; grid-template-columns: repeat(3, minmax(0, 1fr)); position: static; max-height: none; }
}

@media (max-width: 820px) {
  .topbar { align-items: flex-start; flex-direction: column; }
  .layout, .metrics, .queue-items, .actions, .coach-panel, .plan-row { grid-template-columns: 1fr; }
  .side-panel { position: static; max-height: none; }
  .material-head { display: grid; }
  .pill { width: fit-content; }
}

/* S-1 growth loop: credential earn + share CTAs */
.credential-cta, .credential-earned { border: 1px solid rgba(47, 133, 90, 0.45); background: rgba(47, 133, 90, 0.07); }
.credential-earned h2::before, .credential-cta h2::before { content: "🏅 "; }
.share-actions { display: flex; flex-wrap: wrap; gap: 10px; margin-top: 10px; }
.share-actions .btn { display: inline-flex; align-items: center; min-height: 40px; padding: 0 14px; border-radius: 8px; color: #fff; background: var(--teal); text-decoration: none; font-weight: 600; }
.share-actions .btn.share-li { background: #0a66c2; }
.share-actions .btn.share-x { background: #111827; }
