:root {
  color-scheme: light;
  --bg: #f7f7f8;
  --panel: #ffffff;
  --ink: #1d1d1f;
  --muted: #74747a;
  --line: #e2e2e5;
  --soft: #f1f1f3;
  --useful: #32d74b;
  --useless: #ffd60a;
  --wrong: #ff453a;
  --focus: #0a84ff;
  font-family: "Google Sans", "Product Sans", Arial, Helvetica, sans-serif;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--ink);
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

body.auth-open,
body.modal-open {
  overflow: hidden;
}

body.admin-gate {
  visibility: hidden;
}

button,
input,
select,
textarea {
  font: inherit;
}

button {
  cursor: pointer;
}

.shell {
  width: min(760px, calc(100% - 32px));
  margin: 0 auto;
  padding: 22px 0 56px;
}

.topbar,
.intro,
.feed-header,
.lesson-footer,
.form-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}

.topbar {
  min-height: 48px;
  flex-wrap: wrap;
  justify-content: space-between;
  padding-bottom: 18px;
/*  border-bottom: 1px solid var(--line);*/
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  justify-content: flex-start;
  margin: 0;
  color: var(--ink);
  font-weight: 700;
  text-decoration: none;
}

.brand-logo {
  height: 60px;
  object-fit: contain;
  flex: 0 0 auto;
}

.auth-actions {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 8px;
  min-height: 38px;
}

.user-chip {
  display: inline-flex;
  max-width: 120px;
  min-height: 34px;
  align-items: center;
  min-width: 0;
  padding: 0 10px;
  color: var(--ink);
  font-size: 0.92rem;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.intro {
  padding: 42px 0 28px;
  align-items: flex-end;
}

.eyebrow {
  margin: 0 0 10px;
  color: var(--muted);
  font-size: 0.86rem;
  font-weight: 700;
  letter-spacing: 0;
  text-transform: uppercase;
}

h1,
h2 {
  margin: 0;
  letter-spacing: 0;
}

h1 {
  max-width: 540px;
  min-height: 5.1em;
  font-family: "IBM Plex Serif", Georgia, "Times New Roman", serif;
  font-size: clamp(2rem, 5vw, 3.75rem);
  line-height: 1.02;
  font-weight: 500;
}

h1 span {
  color: black;
  display: block;
}

h2 {
  font-size: 1rem;
}

.primary {
  min-height: 40px;
  padding: 0 18px;
  border: 1px solid var(--ink);
  border-radius: 8px;
  background: var(--ink);
  color: #fff;
  font-weight: 700;
}

#composeButton {
  right: 20px;
  bottom: 20px;
  position: fixed;
  display: inline-flex;
  flex: 0 0 auto;
  align-items: center;
  justify-content: center;
  gap: 10px;
  min-width: 190px;
  min-height: 48px;
  padding: 0 22px;
  font-size: 1.05rem;
  white-space: nowrap;
  z-index: 9;
  overflow: hidden;
  isolation: isolate;
}

#composeButton::after {
  content: "";
  position: absolute;
  inset: -40% auto -40% -35%;
  width: 34%;
  transform: skewX(-18deg);
  background: linear-gradient(
    90deg,
    transparent,
    rgb(255 255 255 / 0.18),
    transparent
  );
  animation: compose-shine 4.8s ease-in-out infinite;
  pointer-events: none;
}

#composeButton > * {
  position: relative;
  z-index: 1;
}

@keyframes compose-shine {
  0%,
  68% {
    transform: translateX(0) skewX(-18deg);
    opacity: 0;
  }
  74% {
    opacity: 1;
  }
  88%,
  100% {
    transform: translateX(460%) skewX(-18deg);
    opacity: 0;
  }
}

.button-icon {
  display: inline-grid;
  width: 20px;
  height: 20px;
  place-items: center;
}

.button-icon svg {
  width: 20px;
  height: 20px;
  fill: none;
  stroke: currentColor;
  stroke-linecap: round;
  stroke-width: 2.3;
}

.primary:hover,
.primary:focus-visible {
  background: #333336;
}

.secondary,
.text-button {
  min-height: 36px;
  border-radius: 8px;
  font-weight: 700;
  white-space: nowrap;
}

.icon-only {
  flex: 0 0 42px;
  width: 42px;
  min-width: 42px;
  padding: 0;
}

.icon-only svg {
  width: 20px;
  height: 20px;
  fill: none;
  stroke: currentColor;
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-width: 2;
}

.secondary {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0 14px;
  border: 1px solid var(--line);
  background: var(--panel);
  color: var(--ink);
  text-decoration: none;
}

.text-button {
  padding: 0;
  border: 0;
  background: transparent;
  color: var(--focus);
}

.auth-panel {
  display: none;
  position: fixed;
  z-index: 10;
  inset: 0;
  place-items: center;
  padding: 20px;
  border: 0;
  background: rgb(247 247 248 / 0.96);
  backdrop-filter: blur(12px);
}

.auth-panel.open {
  display: grid;
}

.auth-shell {
  position: relative;
  display: grid;
  width: min(440px, 100%);
  gap: 22px;
  padding: 32px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
}

.icon-button {
  display: inline-grid;
  width: 36px;
  height: 36px;
  place-items: center;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: #fff;
  color: var(--muted);
}

.icon-button svg {
  width: 18px;
  height: 18px;
  fill: none;
  stroke: currentColor;
  stroke-linecap: round;
  stroke-width: 2.2;
}

.auth-close {
  position: absolute;
  top: 18px;
  right: 18px;
}

.auth-copy {
  padding-right: 42px;
}

.auth-copy h2 {
  font-size: 2rem;
  line-height: 1.05;
  font-weight: 740;
}

.auth-copy p,
.form-message {
  margin: 8px 0 0;
  color: var(--muted);
  font-size: 0.92rem;
  line-height: 1.4;
}

.form-message.error {
  min-height: 42px;
  padding: 10px 12px;
  border: 1px solid rgb(255 69 58 / 0.32);
  border-radius: 8px;
  background: rgb(255 69 58 / 0.08);
  color: #b42318;
}

.form-message.success {
  min-height: 42px;
  padding: 10px 12px;
  border: 1px solid rgb(48 209 88 / 0.32);
  border-radius: 8px;
  background: rgb(48 209 88 / 0.08);
  color: #167a2d;
}

.auth-form {
  align-self: center;
  padding: 0;
}

.auth-fields {
  display: grid;
  gap: 12px;
}

.field:first-child {
  display: none;
}

.auth-panel.signup .field:first-child {
  display: block;
}

.reset-field {
  display: none;
}

.auth-panel.reset .auth-fields .field:nth-child(3) {
  display: none;
}

.auth-panel.reset .reset-field {
  display: block;
}

.field label {
  margin-bottom: 7px;
}

input,
select,
textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 8px;
  outline: none;
  background: #fff;
  color: var(--ink);
}

input {
  min-height: 44px;
  padding: 0 14px;
}

select {
  min-height: 44px;
  margin-bottom: 14px;
  padding: 0 38px 0 14px;
  appearance: none;
  background:
    linear-gradient(45deg, transparent 50%, var(--muted) 50%) calc(100% - 18px) 50% / 6px 6px
      no-repeat,
    linear-gradient(135deg, var(--muted) 50%, transparent 50%) calc(100% - 14px) 50% / 6px 6px
      no-repeat,
    #fff;
  color: var(--ink);
}

.composer {
  display: none;
  position: fixed;
  z-index: 9;
  inset: 0;
  place-items: center;
  padding: 20px;
  border: 0;
  background: rgb(247 247 248 / 0.96);
  backdrop-filter: blur(12px);
}

.composer.open {
  display: grid;
}

.composer-shell {
  bottom: 0;
  position: relative;
  display: grid;
  width: min(520px, 100%);
  gap: 22px;
  padding: 0;
/*  border: 1px solid var(--line);*/
  border-radius: 8px;
/*  background: var(--panel);*/
}

.composer-close {
  position: absolute;
  top: 18px;
  right: 0;
}

.composer-close[hidden] {
  display: none;
}

.composer form {
  padding: 0;
}

.composer-label {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
}

.writing-counts {
  display: inline-flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 4px 10px;
  color: var(--muted);
  font-size: 0.88em;
  font-weight: 600;
}

.admin-panel {
  display: none;
  margin-bottom: 26px;
  padding: 18px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
}

.admin-panel.open {
  display: grid;
  gap: 18px;
}

.admin-header,
.admin-item,
.admin-item-actions {
  display: flex;
  align-items: center;
}

.admin-header,
.admin-item {
  justify-content: space-between;
  gap: 14px;
}

.admin-header h2,
.admin-create h3,
.admin-columns h3 {
  margin: 0;
  color: var(--ink);
}

.admin-create {
  display: grid;
  gap: 14px;
  padding: 0;
}

.admin-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
}

.admin-list {
  display: grid;
  gap: 8px;
  margin-top: 10px;
}

.admin-columns {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 18px;
}

.admin-item {
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
}

.admin-item-copy {
  display: grid;
  min-width: 0;
  gap: 4px;
}

.admin-item-copy strong,
.admin-item-copy span {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.admin-item-copy span {
  color: var(--muted);
  font-size: 0.84rem;
}

.admin-item-actions {
  flex: 0 0 auto;
  gap: 6px;
}

.secondary.danger {
  color: #b42318;
}

form {
  padding: 18px;
}

label {
  display: block;
  margin-bottom: 10px;
  color: var(--muted);
  font-size: 0.9rem;
  font-weight: 700;
}

textarea {
  resize: vertical;
  min-height: 136px;
  padding: 14px;
  line-height: 1.55;
}

input:focus-visible,
select:focus-visible,
textarea:focus-visible,
button:focus-visible {
  outline: 3px solid color-mix(in srgb, var(--focus), transparent 72%);
  outline-offset: 2px;
}

.form-row {
  gap: 6px;
  width: 100%;
  margin-top: 12px;
  color: var(--muted);
  font-size: 0.9rem;
}

.form-row button {
  width: 100%;
}

.auth-alt {
  display: inline-flex;
  width: 100%;
  align-items: baseline;
  justify-content: center;
  gap: 6px;
  margin: 14px 0 0;
  color: var(--muted);
  font-size: 0.92rem;
  line-height: 1.4;
}

.auth-alt .text-button {
  min-height: 0;
  font-size: inherit;
  font-weight: 700;
  line-height: inherit;
}

.auth-reset-link {
  margin-top: 8px;
}

.feed-header {
  padding: 18px 0 12px;
/*  border-top: 1px solid var(--line);*/
  color: var(--muted);
}

.feed-header h2 {
  display: none;
}

.feed-mode-tabs {
  display: flex;
  gap: 2px;
  padding: 2px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
}

.mode-tab {
  flex: 1;
  min-height: 28px;
  padding: 0 10px;
  border: 0;
  border-radius: 6px;
  background: transparent;
  color: var(--muted);
  font-size: 0.82rem;
  font-weight: 600;
}

.mode-tab.active {
  background: var(--soft);
  color: var(--ink);
}

.feed-summary {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 10px;
  color: var(--muted);
  font-weight: 600;
}

.scope-chip {
  min-height: 28px;
  max-width: 240px;
  padding: 0 10px;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: var(--panel);
  color: var(--ink);
  font-size: 0.78rem;
  font-weight: 700;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.scope-chip::after {
  content: " x";
  color: var(--muted);
  font-weight: 700;
}

.feed {
  display: grid;
  gap: 10px;
}

.lesson {
  position: relative;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
}

.lesson-card-actions {
  position: absolute;
  top: 10px;
  right: 10px;
  display: flex;
  gap: 4px;
}

.quiet-icon {
  display: inline-grid;
  width: 28px;
  height: 28px;
  place-items: center;
  border: 0;
  border-radius: 8px;
  background: transparent;
  color: color-mix(in srgb, var(--muted), transparent 18%);
}

.quiet-icon[hidden] {
  display: none;
}

.quiet-icon:hover,
.quiet-icon:focus-visible {
  background: var(--soft);
  color: var(--ink);
}

.quiet-icon.active {
  background: rgb(255 69 58 / 0.1);
  color: var(--wrong);
}

.quiet-icon svg {
  width: 16px;
  height: 16px;
  fill: none;
  stroke: currentColor;
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-width: 2;
}

.lesson-meta {
  display: flex;
  flex-wrap: wrap;
  flex-direction: column;
  align-items: flex-start;
  padding: 16px 50px 0 20px;
  color: var(--muted);
  font-family: "Google Sans", "Product Sans", Arial, Helvetica, sans-serif;
  font-size: 0.8rem;
  font-style: normal;
  font-weight: 500;
  line-height: 1.4;
}

.lesson-meta div {
  display: inline-block;
}

.author,
.lesson-category {
  display: inline;
  min-height: 0;
  padding: 0;
  border: 0;
  background: transparent;
  color: #4c4c52;
  font-size: inherit;
  font-weight: inherit;
  text-align: left;
}

.author:hover,
.lesson-category:hover {
  color: var(--ink);
  text-decoration: underline;
  text-underline-offset: 3px;
}

.lesson-text {
  margin: 0;
  padding: 14px 20px 22px;
  font-family: "IBM Plex Serif", Georgia, "Times New Roman", serif;
  font-size: 1.34rem;
  line-height: 1.55;
  word-break: break-word;
}

.lesson-footer {
  padding: 14px 20px 16px;
  border-top: 1px solid var(--line);
  color: var(--muted);
}

.vote-summary {
  display: grid;
  flex: 1;
  min-width: 220px;
  gap: 12px;
}

.vote-row {
  display: flex;
  align-items: center;
  gap: 12px;
}

.vote-bar {
  display: flex;
  width: 100%;
  height: 7px;
  overflow: hidden;
  border-radius: 999px;
  background: var(--soft);
}

.bar-part {
  min-width: 0;
  transition: flex-basis 160ms ease;
}

.bar-part.is-empty {
  display: none;
}

.bar-part.useful {
  background: var(--useful);
}

.bar-part.useless {
  background: var(--useless);
}

.bar-part.wrong {
  background: var(--wrong);
}

.vote-total {
  min-width: 64px;
  color: var(--muted);
  font-family: "Google Sans", "Product Sans", Arial, Helvetica, sans-serif;
  font-size: 0.86rem;
  font-weight: 650;
  text-align: right;
  white-space: nowrap;
}

.vote-actions {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
}

.vote-group {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.vote {
  position: relative;
  display: inline-flex;
  width: 36px;
  height: 36px;
  align-items: center;
  justify-content: center;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  color: var(--ink);
}

.vote-icon {
  display: grid;
  width: 19px;
  height: 19px;
  place-items: center;
}

.vote-icon svg {
  width: 19px;
  height: 19px;
  fill: none;
  stroke: currentColor;
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-width: 2;
}

.vote.selected {
  border-color: currentColor;
  background: #fff;
}

.vote.useful.selected {
  color: var(--useful);
  background: rgb(48 209 88 / 0.12);
}

.vote.useless.selected {
  color: var(--useless);
  background: rgb(255 214 10 / 0.18);
}

.vote.wrong.selected {
  color: var(--wrong);
  background: rgb(255 69 58 / 0.12);
}

.vote::after {
  position: absolute;
  z-index: 2;
  bottom: calc(100% + 8px);
  left: 50%;
  width: max-content;
  max-width: 160px;
  padding: 6px 8px;
  border-radius: 6px;
  background: var(--ink);
  color: #fff;
  content: attr(data-tooltip);
  font-size: 0.78rem;
  font-weight: 700;
  line-height: 1.2;
  opacity: 0;
  pointer-events: none;
  transform: translateX(-50%) translateY(3px);
  transition:
    opacity 120ms ease,
    transform 120ms ease;
}

.vote:hover::after,
.vote:focus-visible::after {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

time,
.empty {
  color: var(--muted);
  font-size: 0.9rem;
}

.lesson-meta .lesson-category::after,
.lesson-meta .author::after {
  content: none;
}

.empty {
  padding: 34px 0;
}

.load-sentinel {
  align-self: center;
  display: flex;
  min-height: 42px;
  align-items: center;
  justify-content: center;
  margin: 12px auto 0;
  padding: 0 16px;
  border: 2px solid black;
  border-radius: 8px;
  background: var(--panel);
  color: black;
  font-size: 0.9rem;
  font-weight: 700;
  text-align: center;
}

.load-sentinel.hidden {
  display: none;
}

.hidden {
  display: none !important;
}

.site-footer {
  display: flex;
  width: min(760px, calc(100% - 32px));
  flex-wrap: wrap;
  gap: 12px;
  margin: 0 auto;
  padding: 0 0 36px;
  color: var(--muted);
  font-size: 0.9rem;
}

.site-footer a {
  color: var(--muted);
  text-decoration: none;
}

.site-footer a:hover {
  color: var(--ink);
}

.site-footer nav a {
  margin: 5px;
}

.static-page {
  display: grid;
  gap: 16px;
  padding-top: 38px;
}

.static-page p {
  margin: 0;
  color: var(--muted);
  font-size: 1.05rem;
  line-height: 1.6;
}

.admin-page h1 {
  min-height: 0;
}

.admin-tabs {
  margin: 18px 0;
}

.admin-view {
  display: none;
}

.admin-view.active {
  display: grid;
  gap: 16px;
}

.admin-filter label {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  margin: 0;
}

.admin-filter input {
  width: auto;
  min-height: auto;
}

.admin-item.removed {
  background: var(--soft);
}

@media (max-width: 680px) {

  body {
    padding-bottom: 60px;
  }

  .shell {
    width: min(100% - 24px, 760px);
    padding-top: 14px;
  }

  .topbar,
  .intro {

  }

  .topbar {
    gap: 12px;
  }

  .brand img {
    height: 40px;
  }

  #composeButton {
    position: fixed;
    bottom: 20px;
    right: 20px;
    width: auto;
  }

  .composer.open {
    display: grid;
    align-items: flex-end;
  }

  .auth-shell {
    grid-template-columns: 1fr;
    min-height: auto;
    padding: 48px 22px 24px;
  }

  .auth-actions {
    justify-content: stretch;
  }

  .auth-actions > * {
    flex: 1;
    justify-content: center;
  }

  .auth-actions > .icon-only {
    flex: 0 0 42px;
  }

  .auth-fields {
    grid-template-columns: 1fr;
  }

  .admin-grid,
  .admin-columns {
    grid-template-columns: 1fr;
  }

  .admin-item {
    align-items: stretch;
    flex-direction: column;
  }

  .admin-item-actions {
    justify-content: flex-start;
  }

  .feed-mode-tabs,
  .primary,
  .secondary {
    width: 100%;
  }

  .feed-header {
    align-items: stretch;
    flex-direction: column;
    gap: 10px;
  }

  .feed-summary {
    justify-content: space-between;
    width: 100%;
    min-width: 0;
    height: 20px;
    text-align: right;
  }

  .scope-chip {
    max-width: min(220px, 58vw);
  }

  #lessonCount {
    flex: 0 0 auto;
    white-space: nowrap;
    margin-left: auto;
  }

  .secondary,
  .primary {
    justify-content: center;
  }

  .vote-summary {
    min-width: 0;
  }

  .vote-bar {
    width: 100%;
  }

  .intro {
    padding: 0 0 26px;
  }

  h1 {
    min-height: 3.1em;
  }

  .site-footer {
    width: min(100% - 24px, 760px);
    gap: 6px 14px;
    text-align: center;
  }

  .site-footer span {
    flex: 0 0 100%;
  }

  .site-footer nav {
    width: 100%;
    display: block;
    text-align: center;
  }

  .feed-header {
/*    align-items: stretch;*/
/*    flex-direction: column;*/
  }

  .mode-tab {
    flex: 1;
  }
}
