:root {
  --bg: #f6f4ef;
  --surface: #ffffff;
  --surface-alt: #efece4;
  --border: #ddd7ca;
  --text: #2b2620;
  --muted: #7a7264;
  --accent: #a8542a;
  --accent-text: #ffffff;
  --danger: #b3352c;
  --success: #2f6f4f;
  --radius: 10px;
  --shadow: 0 1px 2px rgba(43, 38, 32, 0.06), 0 8px 24px rgba(43, 38, 32, 0.06);
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #17161a;
    --surface: #201f24;
    --surface-alt: #26252b;
    --border: #35333b;
    --text: #ece9e3;
    --muted: #9d978c;
    --accent: #d98247;
    --accent-text: #1b1a1e;
    --danger: #e0665c;
    --success: #6fbf95;
    --shadow: 0 1px 2px rgba(0, 0, 0, 0.4), 0 8px 24px rgba(0, 0, 0, 0.35);
  }
}

* {
  box-sizing: border-box;
}

/* Author display rules below would otherwise beat the [hidden] attribute. */
[hidden] {
  display: none !important;
}

html,
body {
  height: 100%;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, Helvetica, Arial,
    sans-serif;
  font-size: 16px;
  line-height: 1.55;
}

.muted {
  color: var(--muted);
  font-size: 0.875rem;
}

/* Layout */

.layout {
  display: grid;
  grid-template-columns: minmax(240px, 320px) 1fr;
  height: 100vh;
}

.sidebar {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  padding: 1rem;
  background: var(--surface);
  border-right: 1px solid var(--border);
  min-height: 0;
}

.sidebar-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
}

.sidebar-header h1 {
  font-size: 1.25rem;
  margin: 0;
  letter-spacing: 0.02em;
}

.sidebar-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-top: 1px solid var(--border);
  padding-top: 0.75rem;
}

.content {
  overflow-y: auto;
  padding: 2rem clamp(1rem, 4vw, 3rem);
  min-width: 0;
}

/* Sidebar list */

.search {
  width: 100%;
  padding: 0.5rem 0.75rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--bg);
  color: inherit;
  font: inherit;
}

.search:focus-visible,
.editor:focus-visible,
input:focus-visible,
button:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.recipe-list {
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
  overflow-y: auto;
  flex: 1;
  min-height: 0;
  margin: 0 -0.25rem;
  padding: 0 0.25rem;
}

.recipe-item {
  display: flex;
  flex-direction: column;
  gap: 0.15rem;
  text-align: left;
  padding: 0.55rem 0.7rem;
  border: 1px solid transparent;
  border-radius: var(--radius);
  background: none;
  color: inherit;
  font: inherit;
  cursor: pointer;
}

.recipe-item:hover {
  background: var(--surface-alt);
}

.recipe-item.active {
  background: var(--surface-alt);
  border-color: var(--border);
}

.recipe-item-title {
  font-weight: 600;
}

.recipe-item-excerpt {
  color: var(--muted);
  font-size: 0.8rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.list-empty {
  padding: 0.5rem 0.7rem;
}

/* Buttons */

.button {
  padding: 0.45rem 0.85rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface-alt);
  color: inherit;
  font: inherit;
  font-size: 0.9rem;
  cursor: pointer;
}

.button:hover {
  border-color: var(--muted);
}

.button:disabled {
  opacity: 0.6;
  cursor: progress;
}

.button.primary {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--accent-text);
  font-weight: 600;
}

.button.danger {
  color: var(--danger);
}

.button.link {
  background: none;
  border: none;
  color: var(--muted);
  text-decoration: underline;
  padding: 0;
  font-size: 0.85rem;
}

/* Recipe pane */

.empty-state {
  max-width: 32rem;
  margin-top: 15vh;
}

.recipe {
  max-width: 52rem;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  min-height: calc(100vh - 4rem);
}

.recipe-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 1rem;
  flex-wrap: wrap;
  border-bottom: 1px solid var(--border);
  padding-bottom: 1rem;
  margin-bottom: 1.5rem;
}

.recipe-header h2 {
  margin: 0;
  font-size: 1.6rem;
}

.recipe-header .muted {
  margin: 0.25rem 0 0;
}

.actions {
  display: flex;
  gap: 0.5rem;
  flex-wrap: wrap;
}

.recipe-body {
  overflow-wrap: anywhere;
}

.recipe-body h1 {
  font-size: 1.6rem;
}

.recipe-body h2 {
  font-size: 1.2rem;
  margin-top: 2rem;
}

.recipe-body img {
  max-width: 100%;
  border-radius: var(--radius);
}

.recipe-body table {
  border-collapse: collapse;
}

.recipe-body th,
.recipe-body td {
  border: 1px solid var(--border);
  padding: 0.35rem 0.6rem;
}

.recipe-body blockquote {
  margin: 1rem 0;
  padding-left: 1rem;
  border-left: 3px solid var(--border);
  color: var(--muted);
}

.recipe-body code {
  background: var(--surface-alt);
  padding: 0.1rem 0.3rem;
  border-radius: 4px;
}

.editor {
  flex: 1;
  min-height: 60vh;
  width: 100%;
  padding: 1rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  color: inherit;
  font-family: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, monospace;
  font-size: 0.95rem;
  line-height: 1.6;
  resize: vertical;
  tab-size: 2;
}

/* Login */

.centered {
  display: grid;
  place-items: center;
  min-height: 100vh;
  padding: 1rem;
}

.login-card {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  width: min(22rem, 100%);
  padding: 2rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

.login-card h1 {
  margin: 0;
  font-size: 1.5rem;
}

.login-card p.muted {
  margin: 0 0 1rem;
}

.login-card label {
  font-size: 0.85rem;
  color: var(--muted);
}

.login-card input {
  padding: 0.55rem 0.75rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--bg);
  color: inherit;
  font: inherit;
  margin-bottom: 0.5rem;
}

.error {
  color: var(--danger);
  font-size: 0.9rem;
  margin: 0.5rem 0 0;
}

/* Toast */

.toast {
  position: fixed;
  bottom: 1.25rem;
  left: 50%;
  transform: translateX(-50%);
  margin: 0;
  padding: 0.6rem 1.1rem;
  border-radius: var(--radius);
  background: var(--surface);
  border: 1px solid var(--border);
  box-shadow: var(--shadow);
  font-size: 0.9rem;
}

.toast.success {
  border-color: var(--success);
  color: var(--success);
}

.toast.error {
  border-color: var(--danger);
  color: var(--danger);
}

@media (max-width: 720px) {
  .layout {
    grid-template-columns: 1fr;
    height: auto;
  }

  .sidebar {
    border-right: none;
    border-bottom: 1px solid var(--border);
  }

  .recipe-list {
    max-height: 40vh;
  }

  .recipe {
    min-height: 0;
  }
}
