:root {
  --bg: #ffffff;
  --bg-elev: #ffffff;
  --bg-soft: #f7f9f9;
  --text: #0f1419;
  --muted: #536471;
  --border: #eff3f4;
  --border-strong: #cfd9de;
  --accent: #2f9d7e;
  --accent-soft: #e5f5ef;
  --like: #f91880;
  --good: #c2416b;
  --ok: #1f9d55;
  --ng: #d9423a;
  --header: rgba(255, 255, 255, 0.85);
  --shadow: 0 2px 12px rgba(0, 0, 0, 0.15);
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #16181c;
    --bg-elev: #1e2126;
    --bg-soft: #1e2126;
    --text: #e7e9ea;
    --muted: #8b98a5;
    --border: #2b2f36;
    --border-strong: #3a3f47;
    --accent: #4fc39f;
    --accent-soft: #1d3a31;
    --good: #f08bab;
    --header: rgba(22, 24, 28, 0.85);
    --shadow: 0 2px 16px rgba(0, 0, 0, 0.5);
    color-scheme: dark;
  }
}

:root[data-theme="dark"] {
  --bg: #16181c;
  --bg-elev: #1e2126;
  --bg-soft: #1e2126;
  --text: #e7e9ea;
  --muted: #8b98a5;
  --border: #2b2f36;
  --border-strong: #3a3f47;
  --accent: #4fc39f;
  --accent-soft: #1d3a31;
  --good: #f08bab;
  --header: rgba(22, 24, 28, 0.85);
  --shadow: 0 2px 16px rgba(0, 0, 0, 0.5);
  color-scheme: dark;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  overscroll-behavior-y: contain;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, "Hiragino Sans", "Hiragino Kaku Gothic ProN", "Noto Sans JP", "Segoe UI", sans-serif;
  font-size: 15px;
  line-height: 1.6;
  -webkit-text-size-adjust: 100%;
  -webkit-tap-highlight-color: transparent;
}

button {
  font: inherit;
  color: inherit;
  background: none;
  border: 0;
  padding: 0;
  cursor: pointer;
}

button:disabled { cursor: default; }

.app {
  max-width: 600px;
  margin: 0 auto;
  min-height: 100vh;
  border-left: 1px solid var(--border);
  border-right: 1px solid var(--border);
}

@media (max-width: 600px) {
  .app { border: 0; }
}

/* ---------- header ---------- */
.top {
  position: sticky;
  top: 0;
  z-index: 10;
  background: var(--header);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--border);
  padding-top: env(safe-area-inset-top);
}

.bar {
  display: flex;
  align-items: center;
  gap: 12px;
  height: 53px;
  padding: 0 16px;
}

.bar h1 {
  flex: 1;
  margin: 0;
  font-size: 19px;
  font-weight: 800;
}

.icon-btn {
  width: 36px;
  height: 36px;
  display: grid;
  place-items: center;
  border-radius: 50%;
  color: var(--text);
}

.icon-btn svg { width: 22px; height: 22px; }
.icon-btn:hover { background: var(--bg-soft); }

.tabs { display: flex; }

.tabs button {
  flex: 1;
  height: 50px;
  color: var(--muted);
  font-weight: 500;
  position: relative;
}

.tabs button[aria-selected="true"] { color: var(--text); font-weight: 700; }

.tabs button[aria-selected="true"]::after {
  content: "";
  position: absolute;
  left: 50%;
  bottom: 0;
  transform: translateX(-50%);
  width: 56px;
  height: 4px;
  border-radius: 2px;
  background: var(--accent);
}

/* ---------- avatar ---------- */
.avatar {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background: var(--c);
  color: #fff;
  display: grid;
  place-items: center;
  font-weight: 700;
  font-size: 17px;
  flex-shrink: 0;
  user-select: none;
}

.avatar.small { width: 32px; height: 32px; font-size: 14px; }

/* ---------- posts ---------- */
.thread, #feed > article, section > article {
  border-bottom: 1px solid var(--border);
}

.post {
  display: flex;
  gap: 12px;
  padding: 12px 16px;
}

.thread > .post:first-child { padding-bottom: 4px; }

.avatar-col {
  display: flex;
  flex-direction: column;
  align-items: center;
}

.avatar-col.has-line::after {
  content: "";
  flex: 1;
  width: 2px;
  margin-top: 4px;
  margin-bottom: -8px;
  background: var(--border-strong);
}

.post-main { flex: 1; min-width: 0; }

.post-head {
  display: flex;
  align-items: baseline;
  gap: 4px;
  white-space: nowrap;
  overflow: hidden;
}

.post-head .name { font-weight: 700; }
.post-head .handle, .post-head .dot, .post-head .time { color: var(--muted); }
.post-head .handle { overflow: hidden; text-overflow: ellipsis; }
.post-head .time { flex-shrink: 0; }

.replying { color: var(--muted); font-size: 14px; }
.accent { color: var(--accent); }

.post-body {
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  margin-top: 2px;
}

.note { margin-top: 6px; color: var(--muted); font-size: 13px; }

.chip {
  display: inline-block;
  margin: 4px 0 2px;
  padding: 0 8px;
  border-radius: 999px;
  font-size: 12px;
  line-height: 20px;
  background: var(--accent-soft);
  color: var(--accent);
  font-weight: 600;
}

.chip.muted { background: var(--bg-soft); color: var(--muted); border: 1px solid var(--border); }
.chip.good { background: color-mix(in srgb, var(--good) 14%, transparent); color: var(--good); }

.lesson {
  margin-top: 8px;
  padding: 10px 12px;
  border-radius: 12px;
  border-left: 3px solid var(--accent);
  background: var(--accent-soft);
}

.lesson-label { font-size: 12px; font-weight: 700; color: var(--accent); }

.actions {
  display: flex;
  gap: 40px;
  margin-top: 8px;
  margin-left: -8px;
}

.act {
  display: inline-flex;
  align-items: center;
  gap: 2px;
  color: var(--muted);
  min-height: 34px;
  padding: 0 8px;
  border-radius: 999px;
}

.act svg { width: 19px; height: 19px; display: block; }
.act .count { font-size: 13px; min-width: 1ch; }
.act.like.on { color: var(--like); }
.act.like.on svg path { fill: currentColor; }
.act.save.on { color: var(--accent); }
.act.save.on svg path { fill: currentColor; }

/* stats */
.stat-card {
  margin-top: 8px;
  padding: 16px 20px;
  border: 1px solid var(--border-strong);
  border-radius: 16px;
}

.stat-label, .stat-sub { color: var(--muted); font-size: 14px; }
.stat-value { display: flex; align-items: baseline; gap: 4px; margin: 2px 0; }
.stat-value .num { font-size: 40px; font-weight: 800; line-height: 1.2; }
.stat-value .unit { font-size: 16px; }

/* next move */
.pill {
  margin-top: 10px;
  padding: 6px 20px;
  border-radius: 999px;
  background: var(--text);
  color: var(--bg);
  font-weight: 700;
}

.pill.done { background: var(--accent-soft); color: var(--accent); }

/* quiz */
.quiz-choices { display: flex; flex-direction: column; gap: 8px; margin-top: 10px; }

.quiz-choice {
  text-align: left;
  padding: 10px 14px;
  border: 1px solid var(--border-strong);
  border-radius: 12px;
}

.quiz-choice:not(:disabled):active { background: var(--bg-soft); }
.quiz-choice.correct { border-color: var(--ok); background: color-mix(in srgb, var(--ok) 14%, transparent); }
.quiz-choice.wrong { border-color: var(--ng); background: color-mix(in srgb, var(--ng) 12%, transparent); }
.quiz-choice:disabled { color: var(--text); }

.quiz-reveal { margin-top: 8px; font-size: 14px; }
.quiz-prev { font-size: 12px; color: var(--muted); margin-top: 4px; }

.quiz-expl {
  margin-top: 10px;
  padding: 12px 14px;
  border-radius: 12px;
  background: var(--bg-soft);
  font-size: 14px;
}

.quiz-answer { font-weight: 700; margin-bottom: 4px; }
.quiz-result { font-weight: 800; }
.quiz-result.ok { color: var(--ok); }
.quiz-result.ng { color: var(--ng); }

.link { color: var(--accent); font-weight: 600; }
.link:disabled { opacity: 0.4; }

/* ---------- misc ---------- */
.banner {
  display: flex;
  gap: 12px;
  align-items: flex-start;
  margin: 12px 16px;
  padding: 12px 16px;
  border-radius: 16px;
  background: var(--accent-soft);
  font-size: 14px;
}

.banner .link { flex-shrink: 0; }

.empty { padding: 40px 24px; color: var(--muted); text-align: center; }

.tab-tools {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 10px 16px;
  color: var(--muted);
  font-size: 14px;
  border-bottom: 1px solid var(--border);
}

.loading { display: grid; place-items: center; padding: 24px; }

.spinner {
  width: 26px;
  height: 26px;
  border-radius: 50%;
  border: 3px solid var(--accent-soft);
  border-top-color: var(--accent);
}

.spinner.static, .ptr.spinning .spinner { animation: spin 0.8s linear infinite; }

@keyframes spin { to { transform: rotate(360deg); } }

.ptr {
  position: fixed;
  top: calc(env(safe-area-inset-top) + 64px);
  left: 50%;
  z-index: 9;
  margin-left: -20px;
  width: 40px;
  height: 40px;
  display: grid;
  place-items: center;
  border-radius: 50%;
  background: var(--bg-elev);
  box-shadow: var(--shadow);
  opacity: 0;
  pointer-events: none;
}

.new-pill {
  position: fixed;
  top: calc(env(safe-area-inset-top) + 116px);
  left: 50%;
  transform: translateX(-50%);
  z-index: 11;
  padding: 6px 16px;
  border-radius: 999px;
  background: var(--accent);
  color: #fff;
  font-weight: 700;
  box-shadow: var(--shadow);
}

.appear { animation: appear 0.35s ease; }

@keyframes appear {
  from { opacity: 0; transform: translateY(-8px); }
  to { opacity: 1; transform: none; }
}

.fab {
  position: fixed;
  right: max(20px, calc(50% - 300px + 20px));
  bottom: calc(env(safe-area-inset-bottom) + 24px);
  z-index: 10;
  width: 56px;
  height: 56px;
  display: grid;
  place-items: center;
  border-radius: 50%;
  background: var(--accent);
  color: #fff;
  box-shadow: var(--shadow);
}

.fab svg { width: 26px; height: 26px; }
.fab:active { transform: scale(0.95); }

/* ---------- sheets ---------- */
dialog.sheet {
  width: min(600px, 100%);
  max-width: 100%;
  max-height: 100%;
  margin: 0 auto auto;
  padding: 0;
  padding-top: env(safe-area-inset-top);
  border: 0;
  border-radius: 0 0 16px 16px;
  background: var(--bg);
  color: var(--text);
}

dialog.sheet::backdrop { background: rgba(91, 112, 131, 0.4); }

@media (min-width: 640px) {
  dialog.sheet { margin-top: 48px; border-radius: 16px; }
}

.sheet-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 10px 16px;
}

.primary {
  padding: 6px 18px;
  border-radius: 999px;
  background: var(--accent);
  color: #fff;
  font-weight: 700;
}

.primary:disabled { opacity: 0.5; }

.secondary {
  padding: 8px 16px;
  border-radius: 999px;
  border: 1px solid var(--border-strong);
  font-weight: 600;
}

.compose-reply { padding: 0 16px 8px 68px; color: var(--muted); font-size: 14px; }
.compose-reply .quote { color: var(--muted); font-size: 13px; margin-top: 2px; }

.compose-body { display: flex; gap: 12px; padding: 4px 16px; }

.compose-body textarea {
  flex: 1;
  min-height: 120px;
  border: 0;
  outline: 0;
  resize: none;
  background: transparent;
  color: var(--text);
  font: inherit;
  font-size: 19px;
  line-height: 1.5;
}

.compose-foot {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
  padding: 10px 16px 16px;
  border-top: 1px solid var(--border);
}

.moods { display: flex; gap: 6px; flex-wrap: wrap; }

.mood-chip, .theme-opt {
  padding: 4px 12px;
  border-radius: 999px;
  border: 1px solid var(--border-strong);
  font-size: 13px;
  color: var(--muted);
}

.mood-chip[aria-pressed="true"], .theme-opt[aria-pressed="true"] {
  border-color: var(--accent);
  background: var(--accent-soft);
  color: var(--accent);
  font-weight: 700;
}

.count { color: var(--muted); font-size: 13px; }
.count.over { color: var(--ng); }

.settings-body { padding: 0 16px 20px; }
.settings-body h2 { font-size: 15px; margin: 18px 0 6px; }
.muted { color: var(--muted); font-size: 14px; margin: 0 0 8px; }
.row { display: flex; gap: 8px; flex-wrap: wrap; }
.segmented { display: flex; gap: 6px; }
.theme-opt { padding: 6px 16px; font-size: 14px; }
