/* ─── Reset ──────────────────────────────── */
*, *::before, *::after {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

html {
  font-size: 16px;
  -webkit-text-size-adjust: 100%;
  -webkit-tap-highlight-color: transparent;
}

body {
  font-family: var(--font-body);
  font-size: var(--text-base);
  line-height: 1.6;
  color: var(--text-primary);
  background-color: var(--bg-primary);
  min-height: 100dvh;
  overflow-x: hidden;
  -webkit-font-smoothing: antialiased;
}

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

button {
  font: inherit;
  color: inherit;
  background: none;
  border: none;
  cursor: pointer;
}

img, svg {
  display: block;
  max-width: 100%;
}

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

ul, ol {
  list-style: none;
}

/* ─── Layout ─────────────────────────────── */
#app {
  display: flex;
  flex-direction: column;
  min-height: 100dvh;
}

.app-header {
  position: sticky;
  top: 0;
  z-index: 100;
  height: var(--header-height);
  background: var(--bg-elevated);
  border-bottom: 1px solid var(--border-subtle);
  padding: 0 var(--space-md);
  padding-top: var(--safe-area-top);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
}

.header-content {
  max-width: var(--max-width);
  margin: 0 auto;
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.header-back {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  border: none;
  background: none;
  color: var(--accent-primary);
  cursor: pointer;
  border-radius: var(--radius-sm, 6px);
  padding: 0;
  margin-right: var(--space-xs, 4px);
  -webkit-tap-highlight-color: transparent;
  transition: background 0.15s ease;
}

.header-back:active {
  background: var(--bg-hover, rgba(255,255,255,0.08));
}

.is-hidden {
  display: none !important;
}

.header-back svg {
  width: 22px;
  height: 22px;
}

.header-logo {
  font-family: var(--font-display);
  font-size: var(--text-xl);
  font-weight: var(--weight-bold);
  color: var(--accent-primary);
}

/* ─── ISBN Result Preview ────────────── */
.isbn-result {
  background: var(--bg-secondary, var(--bg-elevated));
  border-radius: var(--radius-lg, 12px);
  padding: var(--space-md);
  border: 1px solid var(--border-subtle, var(--border-primary));
}

.isbn-result__hero {
  display: flex;
  gap: var(--space-md);
  margin-bottom: var(--space-md);
}

.isbn-result__cover {
  width: 120px;
  min-height: 170px;
  object-fit: cover;
  border-radius: var(--radius-md, 8px);
  background: var(--bg-tertiary, #1a1a1a);
  flex-shrink: 0;
}

.isbn-result__info {
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.isbn-result__title {
  font-size: var(--text-lg, 1.125rem);
  font-weight: var(--weight-bold, 700);
  color: var(--text-primary);
  line-height: 1.3;
  margin-bottom: 2px;
}

.isbn-result__subtitle {
  font-size: var(--text-sm, 0.875rem);
  color: var(--text-secondary);
  margin-bottom: var(--space-xs, 4px);
}

.isbn-result__author {
  font-size: var(--text-sm, 0.875rem);
  color: var(--text-secondary);
  margin-bottom: var(--space-sm, 8px);
}

.isbn-result__meta {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-sm, 8px);
  font-size: var(--text-xs, 0.75rem);
  color: var(--text-tertiary);
}

.isbn-result__meta span {
  background: var(--bg-tertiary, rgba(255,255,255,0.06));
  padding: 2px 8px;
  border-radius: var(--radius-sm, 4px);
}

.isbn-result__desc {
  margin-bottom: var(--space-md);
}

.isbn-result__desc h3 {
  font-size: var(--text-sm, 0.875rem);
  font-weight: var(--weight-semibold, 600);
  color: var(--text-primary);
  margin-bottom: var(--space-xs, 4px);
}

.isbn-result__desc p {
  font-size: var(--text-sm, 0.875rem);
  color: var(--text-secondary);
  line-height: 1.6;
  display: -webkit-box;
  -webkit-line-clamp: 6;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.isbn-result__details {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: var(--space-sm, 8px);
}

.isbn-result__detail {
  font-size: var(--text-sm, 0.875rem);
  color: var(--text-primary);
}

.isbn-result__label {
  display: block;
  font-size: var(--text-xs, 0.75rem);
  color: var(--text-tertiary);
  margin-bottom: 2px;
}

/* ─── View Back Button ───────────────── */
.view-back-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  border: none;
  background: none;
  color: var(--accent-primary);
  font-size: var(--text-sm, 0.875rem);
  font-family: inherit;
  cursor: pointer;
  padding: var(--space-xs, 4px) 0;
  margin-bottom: var(--space-sm, 8px);
  -webkit-tap-highlight-color: transparent;
}

.view-back-btn svg {
  width: 18px;
  height: 18px;
  flex-shrink: 0;
}

.view-back-btn:active {
  opacity: 0.6;
}

.app-main {
  flex: 1;
  max-width: var(--max-width);
  margin: 0 auto;
  width: 100%;
  padding: var(--space-md);
  padding-bottom: calc(var(--nav-height) + var(--safe-area-bottom) + var(--space-md));
}

/* Hide header & nav on auth pages (login/register) — pure CSS, no JS dependency */
#app:has(.auth-page) .bottom-nav,
#app:has(.auth-page) .app-header {
  display: none !important;
}

#app:has(.auth-page) .app-main,
#app:has(.bottom-nav.is-hidden) .app-main {
  padding-bottom: var(--space-md);
  padding-top: var(--space-xl);
}

/* ─── Bottom Navigation ──────────────────── */
.bottom-nav {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  z-index: 100;
  height: calc(var(--nav-height) + var(--safe-area-bottom));
  padding-bottom: var(--safe-area-bottom);
  background: var(--bg-elevated);
  border-top: 1px solid var(--border-subtle);
  display: flex;
  align-items: center;
  justify-content: space-around;
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
}

.nav-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  padding: var(--space-xs) var(--space-sm);
  color: var(--text-tertiary);
  transition: color var(--duration-fast) var(--ease-out);
  -webkit-tap-highlight-color: transparent;
}

.nav-item.is-active {
  color: var(--accent-primary);
}

.nav-icon {
  width: 22px;
  height: 22px;
}

.nav-label {
  font-size: var(--text-xs);
  font-weight: var(--weight-medium);
}

/* ─── Loading ────────────────────────────── */
.loading-spinner {
  width: 32px;
  height: 32px;
  border: 3px solid var(--border-subtle);
  border-top-color: var(--accent-primary);
  border-radius: var(--radius-full);
  animation: spin 0.8s linear infinite;
  margin: var(--space-2xl) auto;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

/* ─── Forms ──────────────────────────────── */
.form-group {
  display: flex;
  flex-direction: column;
  gap: var(--space-xs);
}

.form-label {
  font-size: var(--text-sm);
  font-weight: var(--weight-medium);
  color: var(--text-secondary);
}

.form-input {
  width: 100%;
  padding: var(--space-sm) var(--space-md);
  background: var(--bg-input);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md);
  color: var(--text-primary);
  font-size: var(--text-base);
  transition: border-color var(--duration-fast) var(--ease-out);
  outline: none;
}

.form-input:focus {
  border-color: var(--accent-primary);
}

.form-input.has-error {
  border-color: var(--error);
}

.form-error {
  font-size: var(--text-xs);
  color: var(--error);
}

/* ─── Buttons ────────────────────────────── */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-xs);
  padding: var(--space-sm) var(--space-lg);
  border-radius: var(--radius-md);
  font-size: var(--text-sm);
  font-weight: var(--weight-semibold);
  transition: all var(--duration-fast) var(--ease-out);
  cursor: pointer;
  border: none;
  white-space: nowrap;
}

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

.btn--primary:hover {
  background: var(--accent-hover);
}

.btn--secondary {
  background: var(--bg-tertiary);
  color: var(--text-primary);
}

.btn--ghost {
  background: transparent;
  color: var(--accent-primary);
}

.btn--danger {
  background: var(--error);
  color: #fff;
}

.btn--full {
  width: 100%;
}

.btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

/* ─── Page Layout ────────────────────────── */
.page-title {
  font-family: var(--font-display);
  font-size: var(--text-2xl);
  font-weight: var(--weight-bold);
  color: var(--text-primary);
  margin-bottom: var(--space-lg);
}

.page-subtitle {
  font-size: var(--text-sm);
  color: var(--text-secondary);
  margin-top: calc(-1 * var(--space-sm));
  margin-bottom: var(--space-lg);
}

/* ─── Empty State ────────────────────────── */
.empty-state {
  text-align: center;
  padding: var(--space-3xl) var(--space-md);
  color: var(--text-tertiary);
}

.empty-state svg {
  width: 64px;
  height: 64px;
  margin: 0 auto var(--space-md);
  opacity: 0.3;
}

.empty-state p {
  font-size: var(--text-sm);
}

/* ─── Utilities ──────────────────────────── */
.hidden { display: none !important; }
.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  border: 0;
}

/* ─── Auth Layout ────────────────────────── */
.auth-page {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-height: 60vh;
  padding: var(--space-xl);
}

.auth-form {
  width: 100%;
  max-width: 400px;
  display: flex;
  flex-direction: column;
  gap: var(--space-md);
}

.auth-title {
  font-family: var(--font-display);
  font-size: var(--text-3xl);
  font-weight: var(--weight-bold);
  text-align: center;
  margin-bottom: var(--space-sm);
}

.auth-subtitle {
  text-align: center;
  color: var(--text-secondary);
  margin-bottom: var(--space-lg);
}

.auth-link {
  text-align: center;
  font-size: var(--text-sm);
  color: var(--text-secondary);
}

.auth-link a {
  color: var(--accent-primary);
  font-weight: var(--weight-medium);
}

/* ─── My Reviews ─────────────────────────── */
.my-review-card {
  display: flex;
  gap: var(--space-md);
  padding: var(--space-md);
  background: var(--bg-elevated);
  border-radius: var(--radius-lg);
  border: 1px solid var(--border-subtle);
  text-decoration: none;
  color: inherit;
  transition: transform 0.15s ease, box-shadow 0.15s ease;
}

.my-review-card:active {
  transform: scale(0.98);
}

.my-review-card__cover {
  flex-shrink: 0;
  width: 60px;
  height: 90px;
  border-radius: var(--radius-sm);
  overflow: hidden;
  background: var(--bg-tertiary);
}

.my-review-card__cover img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.my-review-card__body {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: var(--space-xs);
}

.my-review-card__book {
  font-family: var(--font-display);
  font-weight: var(--weight-semibold);
  font-size: var(--text-sm);
  color: var(--text-primary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.my-review-card__title {
  font-weight: var(--weight-semibold);
  font-size: var(--text-base);
  line-height: 1.3;
}

.my-review-card__text {
  font-size: var(--text-sm);
  color: var(--text-secondary);
  line-height: 1.5;
  display: -webkit-box;
  -webkit-line-clamp: 3;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.my-review-card__meta {
  display: flex;
  gap: var(--space-sm);
  font-size: var(--text-xs);
  color: var(--text-tertiary);
  margin-top: auto;
}

.my-review-card__spoiler {
  color: var(--status-warning);
  font-weight: var(--weight-medium);
}

.my-review-card + .my-review-card {
  margin-top: var(--space-sm);
}

/* ─── Shelf Add Book Button ──────────────── */
.shelf-add-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-xs);
  width: 100%;
  padding: var(--space-md);
  margin-bottom: var(--space-md);
  background: var(--bg-elevated);
  border: 2px dashed var(--border-subtle);
  border-radius: var(--radius-lg);
  color: var(--accent-primary);
  font-size: var(--text-sm);
  font-weight: var(--weight-semibold);
  cursor: pointer;
  transition: all var(--duration-fast) var(--ease-out);
}

.shelf-add-btn:active {
  transform: scale(0.98);
  background: var(--bg-tertiary);
}

/* ─── Fullscreen Modal ───────────────────── */
.modal--fullscreen {
  max-height: 92vh;
  min-height: 60vh;
}

.modal__header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: var(--space-md);
}

.modal__header .modal__title {
  margin-bottom: 0;
}

.modal__close {
  background: none;
  border: none;
  color: var(--text-secondary);
  cursor: pointer;
  padding: var(--space-xs);
  border-radius: var(--radius-sm);
  display: flex;
  align-items: center;
  justify-content: center;
}

.modal__close:active {
  background: var(--bg-tertiary);
}

/* ─── Add Book Result Items ──────────────── */
.add-book-item {
  display: flex;
  align-items: center;
  gap: var(--space-md);
  padding: var(--space-sm);
  border-radius: var(--radius-md);
  background: var(--bg-primary);
  border: 1px solid var(--border-subtle);
}

.add-book-item + .add-book-item {
  margin-top: var(--space-xs);
}

.add-book-item__cover {
  width: 44px;
  height: 66px;
  border-radius: var(--radius-sm);
  object-fit: cover;
  flex-shrink: 0;
  background: var(--bg-tertiary);
}

.add-book-item__info {
  flex: 1;
  min-width: 0;
}

.add-book-item__title {
  font-weight: var(--weight-semibold);
  font-size: var(--text-sm);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.add-book-item__author {
  font-size: var(--text-xs);
  color: var(--text-secondary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.add-book-item__btn {
  flex-shrink: 0;
  width: 36px;
  height: 36px;
  padding: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: var(--radius-full);
}
