:root {
  --bg: #f4f4f6;
  --surface: #ffffff;
  --border: #e3e3e8;
  --text: #1f1f24;
  --muted: #6b6b76;
  --accent: #9b45b3;
  --accent-soft: #f3e6f7;
  --warn-bg: #fff6e0;
  --warn-text: #7a5a00;
  --danger: #b3261e;
  --radius: 12px;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Hiragino Sans", "Noto Sans JP", sans-serif;
  -webkit-text-size-adjust: 100%;
}

button {
  font: inherit;
  cursor: pointer;
}

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

/* Layout: one column, centred on wide screens; the header bar spans the page. */
.app-header .inner,
.app-main,
.credits {
  max-width: 640px;
  margin: 0 auto;
}

.app-header {
  position: sticky;
  top: 0;
  z-index: 1;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}

.app-header .inner {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 12px 16px;
}

.logo {
  width: 28px;
  height: 28px;
  border-radius: 6px;
}

.app-header h1 {
  flex: 1;
  margin: 0;
  font-size: 18px;
}

.sync {
  font-size: 12px;
  color: var(--muted);
}

.badge {
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 11px;
  background: var(--warn-bg);
  color: var(--warn-text);
}

.menu {
  position: relative;
}

.menu summary {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  border: 1px solid var(--border);
  border-radius: 50%;
  list-style: none;
  cursor: pointer;
}

.menu summary::-webkit-details-marker {
  display: none;
}

.menu-items {
  position: absolute;
  top: calc(100% + 4px);
  right: 0;
  display: flex;
  flex-direction: column;
  gap: 4px;
  min-width: 200px;
  padding: 8px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.08);
}

.menu-items .repo {
  margin: 0 4px 4px;
  font-size: 12px;
  color: var(--muted);
  word-break: break-all;
}

.app-main {
  display: flex;
  flex-direction: column;
  gap: 12px;
  padding: 12px 16px 24px;
}

.notice {
  margin: 0;
  padding: 8px 12px;
  border-radius: var(--radius);
  font-size: 13px;
  background: var(--accent-soft);
  color: var(--accent);
}

.notice.error {
  background: var(--warn-bg);
  color: var(--warn-text);
}

.card {
  margin: 0;
  padding: 12px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}

.muted {
  font-size: 14px;
  color: var(--muted);
}

/* Buttons */
.btn {
  padding: 10px 14px;
  border: 1px solid var(--border);
  border-radius: 10px;
  font-size: 15px;
  background: var(--surface);
  color: var(--text);
}

.btn.primary {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}

.btn.small {
  padding: 6px 10px;
  font-size: 13px;
}

.btn.text {
  padding: 6px 4px;
  border: none;
  background: none;
  color: var(--muted);
}

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

.btn:disabled {
  opacity: 0.4;
  cursor: default;
}

/* Inputs use 16px so iOS does not zoom in on focus. */
input {
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 10px;
  font-size: 16px;
  color: var(--text);
}

.search {
  display: flex;
  gap: 8px;
}

.search input {
  flex: 1;
  min-width: 0;
}

.settings {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.settings h2 {
  margin: 0;
  font-size: 16px;
}

.settings label {
  display: flex;
  flex-direction: column;
  gap: 4px;
  font-size: 13px;
  color: var(--muted);
}

/* Book details */
.result {
  display: flex;
  gap: 12px;
}

.cover {
  display: flex;
  flex: none;
  align-items: center;
  justify-content: center;
  width: 72px;
  height: 104px;
  border-radius: 6px;
  object-fit: cover;
  background: #e9e9ee;
  font-size: 24px;
  font-weight: 700;
  color: #b9b9c3;
}

.cover.small {
  width: 40px;
  height: 58px;
  border-radius: 4px;
  font-size: 16px;
}

.meta {
  min-width: 0;
}

.title {
  margin: 0;
  font-size: 16px;
  font-weight: 700;
  line-height: 1.35;
}

.volume {
  margin: 2px 0 0;
  font-size: 13px;
  color: var(--accent);
}

.sub {
  margin: 4px 0 0;
  font-size: 13px;
  color: var(--muted);
}

.hint {
  margin: 10px 0 0;
  padding: 6px 10px;
  border-radius: 8px;
  font-size: 12px;
  background: var(--warn-bg);
  color: var(--warn-text);
}

.owned {
  margin: 10px 0 0;
  font-size: 13px;
  font-weight: 600;
  color: var(--accent);
}

.update {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-top: 10px;
  padding: 6px 6px 6px 10px;
  border-radius: 8px;
  font-size: 13px;
  background: var(--accent-soft);
}

.actions {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
  margin-top: 10px;
}

/* Equal-width options, so the control keeps its shape whatever is selected. */
.segment {
  display: inline-grid;
  grid-template-columns: repeat(3, 5.5em);
  overflow: hidden;
  border: 1px solid var(--border);
  border-radius: 10px;
}

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

.segment button + button {
  border-left: 1px solid var(--border);
}

.segment button.on {
  background: var(--accent);
  color: #fff;
}

/* Library */
.filters {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.filters input {
  width: 100%;
}

.filter-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
}

/* Equal-width status filters, so the row keeps its shape. On phones they take a
   row of their own and the sort menu moves to the next one. */
.chips {
  display: grid;
  flex: 1 1 100%;
  grid-template-columns: repeat(4, 1fr);
  overflow: hidden;
  border: 1px solid var(--border);
  border-radius: 10px;
}

@media (min-width: 480px) {
  .chips {
    flex: 0 1 auto;
    grid-template-columns: repeat(4, 4.2em);
  }
}

.chips button {
  padding: 6px 0;
  border: none;
  font-size: 13px;
  background: var(--surface);
  color: var(--text);
}

.chips button + button {
  border-left: 1px solid var(--border);
}

.chips button.on {
  background: var(--accent);
  color: #fff;
}

.order {
  margin-left: auto;
  padding: 6px 8px;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 13px;
  background: var(--surface);
  color: var(--text);
}

.section-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  margin: 4px 2px 0;
}

.section-head h2 {
  margin: 0;
  font-size: 15px;
}

.section-head span {
  font-size: 12px;
  color: var(--muted);
}

.list {
  margin: 0;
  padding: 0;
  list-style: none;
}

.list li {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 12px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-top: none;
}

.list li:first-child {
  border-top: 1px solid var(--border);
  border-radius: var(--radius) var(--radius) 0 0;
}

.list li:last-child {
  border-radius: 0 0 var(--radius) var(--radius);
}

.list li:only-child {
  border-radius: var(--radius);
}

.list .meta {
  flex: 1;
}

.list .title {
  display: -webkit-box;
  overflow: hidden;
  font-size: 14px;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
}

.chip {
  flex: none;
  padding: 3px 8px;
  border-radius: 999px;
  font-size: 11px;
}

.chip.want {
  border: 1px solid var(--accent);
  color: var(--accent);
}

.chip.unread {
  background: var(--accent-soft);
  color: var(--accent);
}

.chip.done {
  background: #ececf0;
  color: var(--muted);
}

/* Rows are buttons that open the detail sheet. */
.row {
  display: flex;
  align-items: center;
  gap: 12px;
  width: 100%;
  padding: 0;
  border: none;
  background: none;
  text-align: left;
  color: inherit;
}

.row .meta {
  display: flex;
  flex: 1;
  flex-direction: column;
}

/* Detail sheet: from the bottom on phones, centred on wide screens. */
.backdrop {
  position: fixed;
  inset: 0;
  z-index: 5;
  background: rgba(0, 0, 0, 0.35);
}

.sheet {
  position: fixed;
  right: 0;
  bottom: 0;
  left: 0;
  z-index: 6;
  display: flex;
  flex-direction: column;
  gap: 12px;
  max-height: 85vh;
  overflow-y: auto;
  padding: 16px calc(16px + env(safe-area-inset-right, 0px))
    calc(16px + env(safe-area-inset-bottom, 0px)) calc(16px + env(safe-area-inset-left, 0px));
  background: var(--surface);
  border-radius: 20px 20px 0 0;
  box-shadow: 0 -8px 24px rgba(0, 0, 0, 0.12);
}

@media (min-width: 640px) {
  .sheet {
    top: 50%;
    right: auto;
    bottom: auto;
    left: 50%;
    width: 480px;
    transform: translate(-50%, -50%);
    border-radius: var(--radius);
  }
}

.sheet-head {
  display: flex;
  align-items: flex-start;
  gap: 12px;
}

.sheet-head .btn {
  margin-left: auto;
}

/* Keep the status buttons at their own width inside the column layout. */
.sheet > .segment {
  align-self: start;
}

.sheet label {
  display: flex;
  flex-direction: column;
  gap: 4px;
  font-size: 12px;
  color: var(--muted);
}

.sheet textarea {
  min-height: 72px;
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-family: inherit;
  font-size: 15px;
  color: var(--text);
  resize: vertical;
}

.tag-list {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
}

.tag {
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 11px;
  background: var(--accent-soft);
  color: var(--accent);
}

.credits {
  padding: 0 16px 24px;
  font-size: 11px;
  color: var(--muted);
}

.credits a {
  color: inherit;
}

/* Full-screen camera view shown while scanning. */
.scanner {
  position: fixed;
  inset: 0;
  z-index: 10;
  background: #000;
}

.scanner video {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

/* Frame to line the barcode up with; everything around it is dimmed. */
.scanner-guide {
  position: absolute;
  top: 50%;
  left: 50%;
  width: min(80vw, 420px);
  aspect-ratio: 2 / 1;
  transform: translate(-50%, -50%);
  border: 3px solid #fff;
  border-radius: 12px;
  box-shadow: 0 0 0 100vmax rgba(0, 0, 0, 0.45);
}

.scanner-hint {
  position: absolute;
  top: calc(env(safe-area-inset-top, 0px) + 16px);
  left: 16px;
  right: 16px;
  margin: 0;
  color: #fff;
  text-align: center;
}

.scanner-cancel {
  position: absolute;
  bottom: calc(env(safe-area-inset-bottom, 0px) + 24px);
  left: 50%;
  transform: translateX(-50%);
  padding: 12px 32px;
  border: none;
  border-radius: 999px;
  background: #fff;
  color: #000;
  font-size: 1rem;
}
