:root {
  --paper: #f4f0e8;
  --card: #fffdfb;
  --ink: #1a2330;
  --muted: #5e675f;
  --line: #e4ddd2;
  --green: #1c3d34;
  --green-soft: #e7f0eb;
  --locked: #8a847c;
  --header-h: 0px;
  --footer-h: 0px;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  color-scheme: light;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  padding: 0;
  max-width: 100%;
  overflow-x: hidden;
  background: var(--paper);
  color: var(--ink);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  font-size: 16px;
  line-height: 1.4;
}

button,
input {
  font: inherit;
  color: inherit;
}

button {
  appearance: none;
  -webkit-appearance: none;
}

[hidden] {
  display: none !important;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

.header {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  z-index: 20;
  padding: calc(10px + var(--safe-top)) 16px 12px;
  background: rgba(244, 240, 232, 0.94);
  border-bottom: 1px solid var(--line);
  backdrop-filter: blur(10px);
}

.header-top {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
}

.kicker {
  margin: 0;
  font-size: 12px;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--muted);
}

h1 {
  margin: 2px 0 0;
  font-family: Palatino, "Palatino Linotype", "Iowan Old Style", Georgia, serif;
  font-size: 28px;
  font-weight: 600;
  line-height: 1.15;
}

.langs {
  display: flex;
  flex-shrink: 0;
  gap: 4px;
  padding-top: 2px;
}

.lang-btn,
.filter-btn,
.sort-btn,
.jump-custom,
.field-clear,
.custom-add,
.custom-clear,
.chip button,
.submit,
.card {
  -webkit-tap-highlight-color: transparent;
}

.lang-btn {
  min-width: 36px;
  min-height: 36px;
  padding: 0 8px;
  border: 0;
  border-radius: 999px;
  background: transparent;
  color: var(--muted);
}

.lang-btn[aria-pressed="true"] {
  background: var(--green);
  color: #f7f4ee;
}

.intro {
  margin: 10px 0 4px;
  color: var(--ink);
  font-size: 15px;
  line-height: 1.45;
}

.levels-note {
  margin: 0 0 10px;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.45;
}

.notice {
  margin: 0 0 8px;
  color: var(--ink);
  font-size: 13px;
  line-height: 1.4;
}

.consent-block {
  margin: 0 0 10px;
  padding: 8px 10px;
  border-radius: 12px;
  background: #efe4cf;
}

.notice a {
  color: var(--green);
}

.search {
  position: relative;
}

.search label {
  display: block;
}

.search input,
.custom-row input {
  width: 100%;
  min-height: 48px;
  padding: 12px 44px 12px 14px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: var(--card);
  font-size: 16px;
}

.search input::-webkit-search-cancel-button,
.search input::-webkit-search-decoration {
  -webkit-appearance: none;
  appearance: none;
}

.search input:focus,
.custom-row input:focus {
  outline: 2px solid var(--green);
  border-color: transparent;
}

.field-clear {
  position: absolute;
  top: 50%;
  right: 6px;
  width: 36px;
  height: 36px;
  margin-top: -18px;
  border: 0;
  border-radius: 999px;
  background: transparent;
  color: var(--muted);
  font-size: 22px;
  line-height: 1;
}

.filters {
  display: flex;
  gap: 8px;
  margin-top: 10px;
  overflow-x: auto;
  overscroll-behavior-x: contain;
  scrollbar-width: none;
}

.filters::-webkit-scrollbar {
  display: none;
}

.filter-btn {
  flex: 0 0 auto;
  min-height: 36px;
  padding: 0 14px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--card);
  color: var(--ink);
}

.filter-btn[aria-pressed="true"] {
  border-color: var(--green);
  background: var(--green);
  color: #f7f4ee;
}

.sorts {
  display: flex;
  flex: 1 1 auto;
  gap: 8px;
  min-width: 0;
  overflow-x: auto;
  overscroll-behavior-x: contain;
  scrollbar-width: none;
}

.sorts::-webkit-scrollbar {
  display: none;
}

.sort-btn {
  flex: 0 0 auto;
  min-height: 36px;
  padding: 0 14px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: transparent;
  color: var(--muted);
}

.sort-btn[aria-pressed="true"] {
  border-color: var(--green);
  background: var(--card);
  color: var(--green);
}

.result-bar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
  margin-top: 10px;
}

.result-count {
  margin: 0;
  color: var(--muted);
  font-size: 14px;
  white-space: nowrap;
}

.jump-custom {
  flex: 0 1 auto;
  min-height: 36px;
  margin-left: auto;
  padding: 0;
  border: 0;
  background: transparent;
  color: var(--green);
  font-size: 14px;
  text-align: right;
}

.custom-row {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-top: 8px;
}

.custom-fields {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.custom-row input {
  flex: 1 1 180px;
  min-width: 0;
  padding-right: 14px;
}

.custom-limit {
  margin: 0;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.4;
}

.custom-note {
  margin: 0;
  padding: 8px 10px;
  border-radius: 10px;
  background: #efe4cf;
  color: var(--ink);
  font-size: 13px;
  line-height: 1.45;
}

.custom-add,
.custom-clear {
  flex: 0 0 auto;
  min-height: 44px;
  padding: 0 16px;
  border-radius: 999px;
  font-weight: 600;
}

.custom-add {
  border: 0;
  background: var(--green);
  color: #f7f4ee;
}

.custom-clear {
  border: 1px solid var(--line);
  background: transparent;
  color: var(--ink);
}

.main {
  padding: calc(var(--header-h) + 12px) 16px calc(var(--footer-h) + 20px);
}

.books {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.card {
  position: relative;
  width: 100%;
  margin: 0;
  padding: 14px 48px 14px 14px;
  border: 2px solid transparent;
  border-radius: 16px;
  background: var(--card);
  box-shadow: 0 1px 2px rgba(28, 40, 32, 0.06);
  text-align: left;
}

button.card {
  display: block;
  cursor: pointer;
}

.card.is-selected {
  border-color: var(--green);
  background: var(--green-soft);
}

.card.is-available,
.card.is-locked {
  background: #eceae4;
  color: var(--locked);
  box-shadow: none;
}

.card.is-locked {
  cursor: pointer;
}

.title-fr {
  margin: 0;
  font-family: Palatino, "Palatino Linotype", "Iowan Old Style", Georgia, serif;
  font-size: 20px;
  line-height: 1.25;
}

.subtitle,
.meta {
  margin: 4px 0 0;
  color: var(--muted);
  font-size: 14px;
}

.card.is-available .subtitle,
.card.is-available .meta,
.card.is-locked .subtitle,
.card.is-locked .meta {
  color: var(--locked);
}

.level-row {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 10px;
}

.pill {
  display: inline-flex;
  align-items: center;
  min-height: 24px;
  padding: 0 8px;
  border-radius: 999px;
  background: #efe8dc;
  color: var(--green);
  font-size: 12px;
  font-weight: 600;
}

.pill.is-available {
  background: #ddd9d2;
  color: #5c574f;
}

.mark {
  position: absolute;
  top: 14px;
  right: 14px;
  width: 22px;
  height: 22px;
  border: 1.5px solid #c8c2b8;
  border-radius: 999px;
  background: transparent;
}

.card.is-selected .mark {
  border-color: var(--green);
  background: var(--green) center / 14px 14px no-repeat
    url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16'%3E%3Cpath fill='none' stroke='%23f7f4ee' stroke-width='2' d='M3 8.5 6.2 12 13 4'/%3E%3C/svg%3E");
}

.empty {
  margin: 24px 0;
  text-align: center;
  color: var(--muted);
}

.footer {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 20;
  padding: 10px 16px calc(10px + var(--safe-bottom));
  background: rgba(255, 253, 251, 0.96);
  border-top: 1px solid var(--line);
  backdrop-filter: blur(10px);
}

.consent {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  margin: 0;
  color: var(--ink);
  font-size: 13px;
  line-height: 1.35;
}

.consent input {
  width: 20px;
  height: 20px;
  margin: 1px 0 0;
  flex: none;
  accent-color: var(--green);
}

.footer-row {
  display: flex;
  align-items: center;
  gap: 8px;
}

.footer.is-quiet .footer-row {
  justify-content: flex-end;
}

.footer.is-quiet .count,
.footer.is-quiet .chips {
  display: none;
}

.count {
  flex: 0 0 auto;
  margin: 0;
  font-size: 14px;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

.chips {
  display: flex;
  flex: 1 1 auto;
  gap: 6px;
  min-width: 0;
  overflow-x: auto;
  scrollbar-width: none;
}

.chips::-webkit-scrollbar {
  display: none;
}

.chip {
  display: inline-flex;
  flex: 0 0 auto;
  align-items: center;
  gap: 2px;
  max-width: 180px;
  min-height: 32px;
  padding: 0 4px 0 8px;
  border-radius: 999px;
  background: var(--green-soft);
  color: var(--green);
  font-size: 13px;
}

.chip-custom {
  max-width: 280px;
  background: #efe4cf;
  color: #5c4632;
}

.chip-icon {
  width: 14px;
  height: 14px;
  flex: none;
  background: center / 14px 14px no-repeat;
}

.chip-icon-check {
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16'%3E%3Cpath fill='none' stroke='%231c3d34' stroke-width='2' d='M3 8.5 6.2 12 13 4'/%3E%3C/svg%3E");
}

.chip-icon-pen {
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16'%3E%3Cpath fill='none' stroke='%235c4632' stroke-width='1.6' stroke-linejoin='round' d='M9.2 3.2 12.8 6.8 6 13.6H2.4V10z'/%3E%3Cpath fill='none' stroke='%235c4632' stroke-width='1.6' d='M8 4.4 11.6 8'/%3E%3C/svg%3E");
}

.chip span {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.chip button {
  border: 0;
  border-radius: 999px;
  background: transparent;
  color: var(--green);
  line-height: 1;
}

.chip-custom button {
  color: #5c4632;
}

.chip-remove {
  width: 32px;
  height: 32px;
  font-size: 18px;
}

.chip-title,
.chip-edit {
  height: 32px;
  padding: 0 4px;
  font-size: 13px;
}

.chip-title {
  max-width: 120px;
  overflow: hidden;
  font-weight: 600;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.chip-edit {
  font-size: 12px;
  font-weight: 600;
  text-decoration: underline;
  text-underline-offset: 2px;
}

.submit {
  flex: 0 0 auto;
  min-height: 44px;
  padding: 0 16px;
  border: 0;
  border-radius: 999px;
  background: var(--green);
  color: #f7f4ee;
  font-weight: 600;
}

.submit:disabled {
  background: #c9c3b8;
  color: #6d675f;
}

.thanks {
  padding-top: 8px;
}

.thanks h2,
.thanks h3 {
  margin: 0;
  font-family: Palatino, "Palatino Linotype", "Iowan Old Style", Georgia, serif;
}

.thanks h2 {
  font-size: 32px;
}

.thanks h3 {
  margin-top: 22px;
  font-size: 18px;
}

.thanks p {
  color: var(--muted);
}

.thanks ul {
  margin: 10px 0 0;
  padding: 0;
  list-style: none;
}

.thanks li {
  padding: 12px 0;
  border-bottom: 1px solid var(--line);
  font-family: Palatino, "Palatino Linotype", Georgia, serif;
  font-size: 18px;
}

.toast {
  position: fixed;
  left: 50%;
  bottom: calc(var(--footer-h) + 12px);
  z-index: 30;
  max-width: calc(100% - 32px);
  padding: 12px 16px;
  border-radius: 999px;
  background: var(--ink);
  color: #f7f4ee;
  font-size: 14px;
  opacity: 0;
  pointer-events: none;
  transform: translateX(-50%) translateY(8px);
  transition: opacity 0.2s ease, transform 0.2s ease;
}

.toast.is-on {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

body.is-done .tools,
body.is-done .footer {
  display: none;
}

@media (max-width: 380px) {
  .footer-row {
    flex-wrap: wrap;
  }

  .submit {
    width: 100%;
  }
}
