:root {
  --ink: #251f19;
  --muted: #74695e;
  --paper: #fbf8f1;
  --panel: #fffdf8;
  --line: #ded4c5;
  --accent: #2f7d64;
  --accent-strong: #145543;
  --sun: #d38b26;
  --berry: #a74857;
  --sky: #3f6d9a;
  --shadow: 0 18px 50px rgba(58, 45, 32, 0.12);
  color-scheme: light;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

html {
  min-height: 100%;
  background: var(--paper);
}

body {
  min-height: 100vh;
  margin: 0;
  color: var(--ink);
  background:
    linear-gradient(135deg, rgba(47, 125, 100, 0.12), transparent 34%),
    linear-gradient(315deg, rgba(211, 139, 38, 0.13), transparent 36%),
    var(--paper);
}

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

button {
  min-height: 42px;
  border: 1px solid var(--line);
  border-radius: 7px;
  padding: 0 14px;
  color: var(--ink);
  background: #fffaf0;
  cursor: pointer;
  transition: transform 150ms ease, border-color 150ms ease, background 150ms ease;
}

button:hover {
  border-color: rgba(47, 125, 100, 0.55);
  transform: translateY(-1px);
}

button:focus-visible,
input:focus-visible,
textarea:focus-visible,
select:focus-visible {
  outline: 3px solid rgba(63, 109, 154, 0.28);
  outline-offset: 2px;
}

input,
textarea,
select {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 7px;
  padding: 12px 13px;
  color: var(--ink);
  background: #fffdf8;
}

textarea {
  resize: vertical;
}

.app-shell {
  display: grid;
  grid-template-columns: 310px minmax(0, 1fr);
  min-height: 100vh;
}

.sidebar {
  position: sticky;
  top: 0;
  height: 100vh;
  padding: 24px;
  border-right: 1px solid rgba(117, 95, 73, 0.2);
  background: rgba(255, 252, 246, 0.78);
  backdrop-filter: blur(18px);
}

.brand-block {
  display: grid;
  grid-template-columns: 56px 1fr;
  gap: 14px;
  align-items: center;
}

.brand-mark {
  display: grid;
  width: 56px;
  height: 56px;
  place-items: center;
  border-radius: 8px;
  color: #fff;
  background: linear-gradient(145deg, var(--accent), var(--sky));
  font-size: 28px;
  font-weight: 800;
  box-shadow: var(--shadow);
}

.eyebrow {
  margin: 0 0 5px;
  color: var(--accent-strong);
  font-size: 12px;
  font-weight: 800;
  letter-spacing: 0;
  text-transform: uppercase;
}

h1,
h2,
h3,
p {
  margin-top: 0;
}

h1 {
  margin-bottom: 0;
  font-size: 22px;
  line-height: 1.12;
}

h2 {
  margin-bottom: 0;
  font-size: 42px;
  line-height: 1.05;
}

h3 {
  margin-bottom: 0;
  font-size: 18px;
}

.nav-stack {
  display: grid;
  gap: 10px;
  margin: 34px 0;
}

.nav-button {
  justify-content: flex-start;
  width: 100%;
  background: transparent;
  text-align: left;
}

.nav-button.active {
  border-color: rgba(47, 125, 100, 0.45);
  color: #fff;
  background: var(--accent);
}

.goal-card,
.cloud-card,
.panel-block,
.search-panel,
.book-card {
  border: 1px solid rgba(117, 95, 73, 0.22);
  border-radius: 8px;
  background: rgba(255, 253, 248, 0.88);
  box-shadow: var(--shadow);
}

.goal-card {
  padding: 16px;
}

.cloud-card {
  display: grid;
  gap: 10px;
  margin-top: 16px;
  padding: 16px;
}

.cloud-card p {
  margin-bottom: 0;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.45;
}

.auth-form,
.profile-panel {
  display: grid;
  gap: 9px;
}

.secondary-button {
  background: rgba(255, 253, 248, 0.78);
}

.creator-credit {
  margin-top: 16px;
  padding: 13px 2px 0;
  border-top: 1px solid rgba(117, 95, 73, 0.18);
  color: var(--muted);
  font-size: 12px;
  line-height: 1.45;
}

.creator-credit span {
  display: block;
  margin-bottom: 2px;
  font-weight: 750;
}

.creator-credit a {
  color: var(--accent-strong);
  font-weight: 850;
  text-decoration: none;
}

.creator-credit a:hover {
  text-decoration: underline;
}

.goal-topline,
.section-title-row,
.page-header,
.timer-actions,
.timer-controls,
.book-actions,
.dialog-actions,
.compact-input-row,
.stats-strip {
  display: flex;
  align-items: center;
}

.goal-topline,
.section-title-row,
.page-header {
  justify-content: space-between;
  gap: 16px;
}

.goal-topline span,
.field-label,
.search-panel label,
.log-form label,
.dialog-main label {
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
}

.meter,
.progress-line {
  overflow: hidden;
  width: 100%;
  height: 9px;
  border-radius: 999px;
  background: #eadfce;
}

.meter {
  margin: 14px 0;
}

.meter span,
.progress-line span {
  display: block;
  width: 0%;
  height: 100%;
  border-radius: inherit;
  background: linear-gradient(90deg, var(--accent), var(--sun));
  transition: width 220ms ease;
}

.compact-input-row {
  gap: 8px;
  margin-top: 8px;
}

.compact-input-row input {
  min-width: 0;
}

.icon-button {
  flex: 0 0 auto;
}

.main-panel {
  min-width: 0;
  padding: 34px;
}

.view {
  display: none;
}

.view.active {
  display: block;
}

.page-header {
  margin-bottom: 24px;
}

.stats-strip {
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 8px;
}

.stats-strip div {
  min-width: 86px;
  padding: 10px 13px;
  border: 1px solid rgba(117, 95, 73, 0.2);
  border-radius: 8px;
  background: rgba(255, 253, 248, 0.72);
  text-align: right;
}

.stats-strip span {
  display: block;
  font-size: 22px;
  font-weight: 850;
}

.stats-strip small {
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}

.search-panel {
  padding: 18px;
}

.search-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 120px;
  gap: 10px;
  margin-top: 9px;
}

.search-row button,
#mark-read,
#start-timer,
#save-note,
#save-progress,
.log-form button[type="submit"] {
  border-color: transparent;
  color: #fff;
  background: var(--accent);
}

.category-panel {
  margin: 16px 0 26px;
  padding: 16px;
  border: 1px solid rgba(117, 95, 73, 0.18);
  border-radius: 8px;
  background: rgba(255, 253, 248, 0.62);
}

.compact-title-row {
  margin-bottom: 10px;
}

.quick-row,
.tabs {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin: 16px 0 26px;
}

.compact-tabs {
  margin: 0 0 14px;
}

.category-panel .quick-row {
  margin: 0;
}

.quick-row button,
.tab {
  min-height: 38px;
  color: var(--accent-strong);
  background: rgba(255, 253, 248, 0.78);
}

.quick-row button.active,
.tab.active,
.timer-controls button.active {
  border-color: rgba(47, 125, 100, 0.55);
  color: #fff;
  background: var(--accent);
}

.section-title-row {
  margin-bottom: 14px;
}

.section-title-row span,
.muted-line,
.book-meta,
.book-author {
  color: var(--muted);
}

.book-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(245px, 1fr));
  gap: 16px;
}

.book-card {
  position: relative;
  display: grid;
  grid-template-columns: 82px minmax(0, 1fr);
  gap: 14px;
  min-height: 182px;
  padding: 14px;
}

.card-open {
  position: absolute;
  inset: 0;
  z-index: 1;
  min-height: 0;
  border: 0;
  background: transparent;
  transform: none;
}

.card-open:hover {
  transform: none;
}

.cover-frame {
  position: relative;
  overflow: hidden;
  display: grid;
  width: 82px;
  aspect-ratio: 2 / 3;
  place-items: center;
  border-radius: 7px;
  color: #fff;
  background: linear-gradient(145deg, var(--sky), var(--berry));
  text-align: center;
}

.cover-frame img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.cover-frame .cover-fallback {
  padding: 10px;
  font-size: 12px;
  font-weight: 800;
  line-height: 1.2;
}

.cover-frame.large {
  width: 176px;
  max-width: 100%;
}

.book-info {
  position: relative;
  z-index: 2;
  display: flex;
  min-width: 0;
  flex-direction: column;
  pointer-events: none;
}

.book-author,
.book-meta {
  margin-bottom: 6px;
  font-size: 13px;
  line-height: 1.35;
}

.book-title {
  display: -webkit-box;
  overflow: hidden;
  margin-bottom: 8px;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 2;
  font-size: 18px;
  line-height: 1.18;
}

.progress-line {
  height: 7px;
  margin-top: auto;
}

.book-actions {
  position: relative;
  z-index: 2;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 11px;
  pointer-events: auto;
}

.book-actions button {
  min-height: 32px;
  padding: 0 9px;
  font-size: 12px;
  font-weight: 750;
}

.empty-state {
  grid-column: 1 / -1;
  padding: 28px;
  border: 1px dashed rgba(117, 95, 73, 0.36);
  border-radius: 8px;
  color: var(--muted);
  background: rgba(255, 253, 248, 0.55);
  text-align: center;
}

.habit-layout {
  display: block;
}

.habit-tabs {
  margin: -8px 0 16px;
}

.habit-panel {
  display: none;
}

.habit-panel.active {
  display: grid;
  grid-template-columns: minmax(280px, 420px) minmax(280px, 1fr);
  gap: 16px;
  align-items: start;
}

.panel-block {
  padding: 18px;
}

.wide-panel {
  grid-column: 1 / -1;
}

.timer-face {
  display: grid;
  min-height: 150px;
  margin: 18px 0;
  place-items: center;
  border: 1px solid rgba(117, 95, 73, 0.2);
  border-radius: 8px;
  background: linear-gradient(145deg, rgba(63, 109, 154, 0.12), rgba(47, 125, 100, 0.12));
  font-size: 54px;
  font-weight: 900;
}

.timer-controls,
.timer-actions {
  flex-wrap: wrap;
  gap: 8px;
}

.timer-actions {
  margin-top: 10px;
}

.dashboard-grid,
.insight-grid,
.challenge-list {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 10px;
}

.dashboard-card,
.insight-card,
.challenge-card,
.prediction-item {
  padding: 13px;
  border: 1px solid rgba(117, 95, 73, 0.18);
  border-radius: 8px;
  background: #fffaf0;
}

.dashboard-card strong,
.insight-card strong,
.challenge-card strong {
  display: block;
  margin-bottom: 5px;
  font-size: 24px;
  line-height: 1;
}

.dashboard-card span,
.insight-card span,
.challenge-card span,
.prediction-item span,
.calendar-day small {
  color: var(--muted);
  font-size: 12px;
  font-weight: 750;
}

.dashboard-card p,
.prediction-item p,
.challenge-card p {
  margin-bottom: 0;
  color: var(--muted);
  line-height: 1.45;
}

.weekly-goal {
  display: grid;
  grid-template-columns: minmax(220px, 320px) minmax(0, 1fr);
  gap: 16px;
  align-items: end;
  margin-top: 16px;
  padding-top: 16px;
  border-top: 1px solid rgba(117, 95, 73, 0.16);
}

.weekly-goal label {
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
}

.log-form {
  display: grid;
  gap: 10px;
}

.log-grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  gap: 10px;
}

.history-summary {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 8px;
  margin-bottom: 12px;
}

.history-summary div {
  min-height: 74px;
  padding: 11px;
  border: 1px solid rgba(117, 95, 73, 0.18);
  border-radius: 8px;
  background: #fffaf0;
}

.history-summary strong {
  display: block;
  margin-bottom: 3px;
  font-size: 23px;
  line-height: 1;
}

.history-summary span {
  color: var(--muted);
  font-size: 12px;
  font-weight: 750;
}

.history-list {
  display: grid;
  gap: 9px;
}

.history-item {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 14px;
  padding: 12px;
  border: 1px solid rgba(117, 95, 73, 0.2);
  border-radius: 8px;
  background: rgba(255, 250, 240, 0.8);
}

.history-item strong {
  display: block;
  margin-bottom: 4px;
}

.history-item p {
  margin-bottom: 0;
  color: var(--muted);
  line-height: 1.45;
}

.history-time {
  color: var(--accent-strong);
  font-size: 13px;
  font-weight: 800;
  text-align: right;
  white-space: nowrap;
}

.calendar-grid {
  display: grid;
  grid-template-columns: repeat(7, minmax(0, 1fr));
  gap: 8px;
}

.calendar-day {
  min-height: 70px;
  padding: 9px;
  border: 1px solid rgba(117, 95, 73, 0.2);
  border-radius: 8px;
  background: rgba(255, 250, 240, 0.78);
}

.calendar-day strong {
  display: block;
  margin-bottom: 14px;
  font-size: 13px;
}

.calendar-day[data-level="1"] {
  background: rgba(47, 125, 100, 0.16);
}

.calendar-day[data-level="2"] {
  background: rgba(47, 125, 100, 0.28);
}

.calendar-day[data-level="3"] {
  color: #fff;
  background: var(--accent);
}

.calendar-day[data-level="3"] small {
  color: rgba(255, 255, 255, 0.82);
}

.prediction-list {
  display: grid;
  gap: 10px;
}

.prediction-item strong {
  display: block;
  margin-bottom: 5px;
}

.challenge-card .meter {
  margin: 10px 0 8px;
}

.group-tools {
  display: grid;
  grid-template-columns: minmax(180px, 1fr) minmax(220px, 1fr) minmax(220px, 1fr);
  gap: 12px;
  margin-bottom: 14px;
}

.group-tools form,
.group-tools div {
  display: grid;
  gap: 8px;
}

.group-tools label {
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
}

.group-share {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  align-items: center;
  margin-bottom: 14px;
  padding: 11px 12px;
  border: 1px solid rgba(47, 125, 100, 0.25);
  border-radius: 8px;
  background: rgba(47, 125, 100, 0.1);
}

.group-share span,
.group-share small {
  color: var(--muted);
  font-size: 12px;
  font-weight: 750;
}

.group-share strong {
  color: var(--accent-strong);
  font-size: 18px;
}

.leaderboard-list {
  display: grid;
  gap: 9px;
}

.leaderboard-item {
  display: grid;
  grid-template-columns: 44px minmax(0, 1fr) auto;
  gap: 12px;
  align-items: center;
  padding: 12px;
  border: 1px solid rgba(117, 95, 73, 0.2);
  border-radius: 8px;
  background: rgba(255, 250, 240, 0.82);
}

.leaderboard-rank {
  display: grid;
  width: 34px;
  height: 34px;
  place-items: center;
  border-radius: 8px;
  color: #fff;
  background: var(--accent);
  font-weight: 850;
}

.leaderboard-name strong {
  display: block;
  margin-bottom: 3px;
}

.leaderboard-name span,
.leaderboard-score span {
  color: var(--muted);
  font-size: 12px;
  font-weight: 750;
}

.leaderboard-score {
  text-align: right;
}

.leaderboard-score strong {
  display: block;
  font-size: 22px;
}

.notes-list {
  display: grid;
  gap: 10px;
}

.note-item {
  padding: 12px;
  border: 1px solid rgba(117, 95, 73, 0.2);
  border-radius: 8px;
  background: #fffaf0;
}

.note-item strong {
  display: block;
  margin-bottom: 4px;
}

.note-item p {
  margin-bottom: 0;
  color: var(--muted);
  line-height: 1.45;
}

.note-meta {
  color: var(--accent-strong);
  font-size: 12px;
  font-weight: 800;
}

.note-editor,
.dialog-notes {
  display: grid;
  gap: 10px;
}

dialog {
  width: min(820px, calc(100vw - 28px));
  border: 0;
  border-radius: 8px;
  padding: 0;
  color: var(--ink);
  background: transparent;
}

dialog::backdrop {
  background: rgba(37, 31, 25, 0.42);
  backdrop-filter: blur(4px);
}

.dialog-card {
  position: relative;
  padding: 22px;
  border: 1px solid rgba(117, 95, 73, 0.24);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: 0 24px 70px rgba(37, 31, 25, 0.26);
}

.close-button {
  position: absolute;
  top: 12px;
  right: 12px;
  z-index: 2;
  min-width: 36px;
  min-height: 36px;
  padding: 0;
}

.dialog-content {
  display: grid;
  grid-template-columns: 176px minmax(0, 1fr);
  gap: 22px;
}

.dialog-main {
  display: grid;
  gap: 10px;
}

.dialog-main h3 {
  padding-right: 36px;
  font-size: 30px;
  line-height: 1.08;
}

.dialog-actions,
.progress-editor {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px;
}

.progress-editor {
  grid-template-columns: 1fr 1fr auto;
  align-items: end;
}

@media (max-width: 920px) {
  .app-shell {
    grid-template-columns: 1fr;
  }

  .sidebar {
    position: static;
    height: auto;
    padding: 18px;
    border-right: 0;
    border-bottom: 1px solid rgba(117, 95, 73, 0.2);
  }

  .brand-block {
    grid-template-columns: 48px 1fr;
  }

  .brand-mark {
    width: 48px;
    height: 48px;
  }

  .nav-stack {
    grid-template-columns: repeat(3, 1fr);
    margin: 20px 0;
  }

  .nav-button {
    justify-content: center;
    text-align: center;
  }

  .main-panel {
    padding: 22px 18px 34px;
  }

  .habit-panel.active {
    grid-template-columns: 1fr;
  }

  .dashboard-grid,
  .insight-grid,
  .group-tools,
  .challenge-list {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .page-header {
    align-items: flex-start;
    flex-direction: column;
  }

  .stats-strip {
    justify-content: flex-start;
  }
}

@media (max-width: 620px) {
  h1 {
    font-size: 20px;
  }

  h2 {
    font-size: 34px;
  }

  .search-row,
  .dialog-content,
  .dialog-actions,
  .progress-editor,
  .weekly-goal,
  .log-grid,
  .history-summary,
  .history-item,
  .leaderboard-item,
  .group-tools,
  .dashboard-grid,
  .insight-grid,
  .challenge-list {
    grid-template-columns: 1fr;
  }

  .history-time {
    text-align: left;
  }

  .leaderboard-score {
    text-align: left;
  }

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

  .book-card {
    grid-template-columns: 76px minmax(0, 1fr);
  }

  .cover-frame {
    width: 76px;
  }

  .cover-frame.large {
    width: 132px;
  }

  .timer-face {
    min-height: 130px;
    font-size: 42px;
  }

  .calendar-grid {
    gap: 6px;
  }

  .calendar-day {
    min-height: 58px;
    padding: 7px;
  }

  .calendar-day strong {
    margin-bottom: 8px;
  }
}
