:root {
  color-scheme: light dark;
  --accent: #d96b2e;
  --background: #f2f2f7;
  --surface: #ffffff;
  --text: #1c1c1e;
  --secondary: #6c6c70;
  --separator: rgba(60, 60, 67, 0.18);
  --fill: rgba(118, 118, 128, 0.12);
  --selected: #ffffff;
  --danger: #e5383b;
  --radius: 12px;
  --gutter: 16px;
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  -webkit-text-size-adjust: 100%;
}

@media (prefers-color-scheme: dark) {
  :root {
    --accent: #f08447;
    --background: #000000;
    --surface: #1c1c1e;
    --text: #f2f2f7;
    --secondary: #a1a1a6;
    --separator: rgba(84, 84, 88, 0.6);
    --fill: rgba(118, 118, 128, 0.24);
    --selected: #636366;
    --danger: #ff5a5f;
  }
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  min-height: 100%;
  background: var(--background);
  color: var(--text);
}

body {
  font-size: 17px;
  line-height: 1.35;
  -webkit-tap-highlight-color: transparent;
}

a {
  color: inherit;
  text-decoration: none;
}

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

button {
  cursor: pointer;
}

.view {
  max-width: 640px;
  margin: 0 auto;
  padding: env(safe-area-inset-top) calc(var(--gutter) + env(safe-area-inset-right)) calc(32px + env(safe-area-inset-bottom))
    calc(var(--gutter) + env(safe-area-inset-left));
}

.muted {
  color: var(--secondary);
  margin: 0;
}

/* ---------- Icons ---------- */

.icon {
  display: inline-flex;
  width: 1.15em;
  height: 1.15em;
  flex: none;
}

.icon svg {
  width: 100%;
  height: 100%;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

/* ---------- Headers ---------- */

.page-header {
  padding-top: 12px;
}

.title-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.large-title {
  font-size: 34px;
  font-weight: 700;
  letter-spacing: -0.02em;
  margin: 8px 0 12px;
}

.icon-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background: var(--surface);
  color: var(--accent);
  font-size: 20px;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.12);
}

.nav-bar {
  position: sticky;
  top: 0;
  z-index: 1;
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  min-height: 52px;
  margin: 0 calc(-1 * var(--gutter));
  padding: env(safe-area-inset-top) var(--gutter) 0;
  background: color-mix(in srgb, var(--background) 85%, transparent);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
}

.nav-button {
  display: inline-flex;
  align-items: center;
  gap: 2px;
  justify-self: start;
  padding: 8px 0;
  border: 0;
  background: none;
  color: var(--accent);
  font-size: 17px;
}

.nav-button:disabled {
  color: var(--secondary);
  opacity: 0.6;
  cursor: default;
}

.nav-end {
  grid-column: 3;
  justify-self: end;
}

.nav-title {
  font-weight: 600;
}

.strong {
  font-weight: 600;
}

/* ---------- Search and shelves ---------- */

.search {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 0 10px;
  margin-bottom: 12px;
  border-radius: 10px;
  background: var(--fill);
  color: var(--secondary);
}

.search input {
  flex: 1;
  min-width: 0;
  padding: 8px 0;
  border: 0;
  outline: none;
  background: none;
  color: var(--text);
}

.segmented {
  display: flex;
  padding: 2px;
  border-radius: 9px;
  background: var(--fill);
}

.segment {
  flex: 1;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-width: 0;
  padding: 7px 4px;
  border: 0;
  border-radius: 7px;
  background: none;
  font-size: 14px;
  font-weight: 500;
  white-space: nowrap;
}

.segment.selected {
  background: var(--selected);
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.12);
  font-weight: 600;
}

.count {
  color: var(--secondary);
  font-size: 12px;
  font-variant-numeric: tabular-nums;
}

/* ---------- Grouped lists ---------- */

.group {
  list-style: none;
  margin: 0;
  padding: 0;
  overflow: hidden;
  border-radius: var(--radius);
  background: var(--surface);
}

.page-header + div > .group {
  margin-top: 20px;
}

.group.padded {
  padding: 12px;
}

.group.spaced {
  margin-top: 24px;
}

.group-title {
  margin: 24px 16px 6px;
  color: var(--secondary);
  font-size: 13px;
  font-weight: 400;
  text-transform: uppercase;
  letter-spacing: 0.02em;
}

.group li + li,
.group.fields > * + * {
  border-top: 0.5px solid var(--separator);
}

.row {
  display: flex;
  align-items: center;
  gap: 12px;
  width: 100%;
  min-height: 48px;
  padding: 10px 16px;
  border: 0;
  background: none;
  text-align: left;
}

.row:active {
  background: var(--fill);
}

.row-text {
  display: flex;
  flex-direction: column;
  flex: 1;
  min-width: 0;
}

.row-title {
  overflow-wrap: anywhere;
}

.row-text .row-title {
  font-weight: 600;
}

.link-row .row-text .row-title {
  font-weight: 400;
}

.row-subtitle {
  color: var(--secondary);
  font-size: 15px;
}

.row-meta {
  margin-top: 2px;
  color: var(--secondary);
  font-size: 13px;
}

.row-hint,
.row-chevron {
  color: var(--secondary);
  font-size: 14px;
}

.row-chevron {
  opacity: 0.6;
}

.link-row {
  color: var(--accent);
}

.link-row > .icon:last-child {
  color: var(--secondary);
  font-size: 14px;
}

.accent {
  color: var(--accent);
}

.danger {
  justify-content: center;
  color: var(--danger);
}

/* Reading dates on a book's page: label on the left, date on the right. */
.dates {
  margin: 12px 4px 0;
  font-size: 15px;
}

.dates div {
  display: flex;
  justify-content: space-between;
  padding: 4px 0;
}

.dates dt {
  color: var(--secondary);
}

.dates dd {
  margin: 0;
  font-variant-numeric: tabular-nums;
}

/* Date fields in the edit form. */
.date-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 6px 16px;
}

.fields .date-row input {
  width: auto;
  padding: 6px 0;
  text-align: right;
  color: var(--accent);
}

.notes {
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

.book-heading {
  padding: 8px 4px 0;
}

.book-heading h1 {
  margin: 0 0 4px;
  font-size: 28px;
  line-height: 1.2;
  overflow-wrap: anywhere;
}

/* ---------- Forms ---------- */

.fields input,
.fields textarea,
.link-fields input {
  display: block;
  width: 100%;
  padding: 13px 16px;
  border: 0;
  outline: none;
  background: none;
}

.fields textarea {
  resize: vertical;
  min-height: 110px;
}

.link-editor {
  display: flex;
  align-items: center;
}

.link-fields {
  flex: 1;
  min-width: 0;
}

.link-fields input {
  padding: 10px 16px;
}

.link-fields .secondary-input {
  padding-top: 0;
  color: var(--secondary);
  font-size: 15px;
}

.remove-button {
  display: inline-flex;
  align-self: stretch;
  align-items: center;
  padding: 0 16px;
  border: 0;
  background: none;
  color: var(--secondary);
}

/* ---------- Empty state ---------- */

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

.empty .icon {
  font-size: 44px;
}

.empty h2 {
  margin: 12px 0 4px;
  color: var(--text);
  font-size: 20px;
}

.empty p {
  margin: 0;
}

.page-footer {
  margin-top: 32px;
  text-align: center;
}

.text-button {
  border: 0;
  background: none;
  color: var(--secondary);
  font-size: 15px;
  padding: 8px;
}

/* ---------- Sign in ---------- */

.login {
  display: flex;
  flex-direction: column;
  gap: 12px;
  max-width: 360px;
  margin: 0 auto;
  padding: calc(15vh + env(safe-area-inset-top)) 24px 24px;
  text-align: center;
}

.login h1 {
  margin: 4px 0 0;
  font-size: 30px;
}

.login-logo {
  align-self: center;
  display: inline-flex;
  padding: 16px;
  border-radius: 22px;
  background: var(--accent);
  color: #fff;
  font-size: 40px;
}

.login input {
  padding: 13px 16px;
  border: 0;
  border-radius: var(--radius);
  outline: none;
  background: var(--surface);
  font-size: 17px;
}

.form-error {
  min-height: 1.35em;
  margin: 0;
  color: var(--danger);
  font-size: 15px;
}

.button-primary {
  padding: 13px;
  border: 0;
  border-radius: var(--radius);
  background: var(--accent);
  color: #fff;
  font-weight: 600;
}

.button-primary:disabled {
  opacity: 0.6;
}

:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

/* ---------- Toast ---------- */

.toast {
  position: fixed;
  left: 50%;
  bottom: calc(24px + env(safe-area-inset-bottom));
  transform: translateX(-50%);
  max-width: calc(100% - 32px);
  padding: 12px 18px;
  border-radius: 14px;
  background: rgba(30, 30, 30, 0.92);
  color: #fff;
  font-size: 15px;
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.25);
}
