  :root {
    --bg: #f6eedb; --surface: #fffaf0; --border: #c9ad76;
    --gold: #7a5a10; --gold-dim: #7d6534; --text: #241805;
    --text-dim: #64522f; --success: #2f6b2f; --danger: #9a3232;
    --radius: 10px;
  }
  * { margin: 0; padding: 0; box-sizing: border-box; }
  html { width: 100%; overflow-x: hidden; -webkit-text-size-adjust: 100%; text-size-adjust: 100%; }
  body { font-family: 'Georgia', serif; background: var(--bg); color: var(--text); min-height: 100vh; min-height: 100dvh; width: 100%; overflow-x: hidden; -webkit-font-smoothing: antialiased; }
  img, video, canvas { max-width: 100%; height: auto; }
  input, select, button, textarea { font-size: 16px; /* prevents iOS zoom on focus */ }

  /* ── Login ── */
  #login-screen {
    display: flex; flex-direction: column; align-items: center;
    justify-content: center; min-height: 100vh; min-height: 100dvh; padding: 20px;
  }
  #login-screen h1 { font-size: 22px; color: var(--gold); letter-spacing: 2px; font-weight: normal; margin-bottom: 8px; }
  #login-screen p { font-size: 13px; color: var(--text-dim); margin-bottom: 24px; text-align: center; }
  .pin-input {
    width: 200px; text-align: center; font-size: 28px; letter-spacing: 12px;
    background: var(--surface); border: 1px solid var(--border); color: var(--text);
    padding: 12px; border-radius: var(--radius); outline: none;
    -webkit-text-security: disc;
  }
  .pin-input:focus { border-color: var(--gold); }
  .pin-error {
    color: var(--danger); font-size: 14px; margin-top: 16px; min-height: 20px;
    text-align: center; max-width: 300px; line-height: 1.4;
  }
  .pin-error:not(:empty) {
    background: rgba(163, 61, 61, 0.08); border: 1px solid rgba(163, 61, 61, 0.35);
    padding: 10px 14px; border-radius: var(--radius);
  }
  .login-status {
    color: var(--text-dim); font-size: 13px; margin-top: 12px; min-height: 20px;
    display: flex; align-items: center; gap: 8px;
  }

  .login-form-inner { width: 260px; display: flex; flex-direction: column; gap: 8px; }
  .login-form-inner input {
    width: 100%; background: var(--surface); border: 1px solid var(--border);
    color: var(--text); padding: 10px 12px; border-radius: var(--radius);
    font-family: inherit; font-size: 16px; outline: none;
  }
  .login-form-inner input:focus { border-color: var(--gold); }
  .login-form-inner .btn { margin-top: 4px; }
  .login-divider {
    display: flex; align-items: center; width: 260px; margin: 18px 0 10px 0;
    color: var(--text-dim);
  }
  .login-divider::before, .login-divider::after {
    content: ''; flex: 1; border-bottom: 1px solid var(--border);
  }
  .login-divider span { padding: 0 10px; font-size: 11px; letter-spacing: 1px; }
  .btn-ghost {
    background: transparent; border: 1px solid var(--border); color: var(--text-dim);
  }
  .btn-google {
    background: #fff; color: #3c4043; border: 1px solid #dadce0;
    display: flex; align-items: center; justify-content: center;
    font-weight: 500; letter-spacing: 0.2px;
  }
  .btn-google:hover { background: #f8f9fa; }

  #library-picker, #library-create { display: none; flex-direction: column; align-items: center; gap: 10px; }
  #library-picker.open, #library-create.open { display: flex; }
  #library-picker h2, #library-create h2 { color: var(--gold); font-size: 18px; font-weight: normal; }
  #library-picker .sub, #library-create .sub { color: var(--text-dim); font-size: 12px; margin-bottom: 10px; }
  #library-picker .lib-btn {
    width: 280px; padding: 14px; background: var(--surface);
    border: 1px solid var(--border); color: var(--text); border-radius: var(--radius);
    font-family: inherit; cursor: pointer; text-align: left;
  }
  #library-picker .lib-btn:hover { border-color: var(--gold); }
  #library-picker .lib-btn .name { font-size: 15px; color: var(--gold); }
  #library-picker .lib-btn .role { font-size: 10px; color: var(--text-dim); margin-top: 2px; text-transform: uppercase; letter-spacing: 1px; }

  /* ── App ── */
  #app-screen { display: none; }

  header {
    background: linear-gradient(180deg, var(--surface), var(--bg));
    border-bottom: 2px solid var(--border);
    padding: 14px 20px; text-align: center;
  }
  header h1 { font-size: 18px; color: var(--gold); letter-spacing: 2px; font-weight: normal; }

  .tabs { display: flex; border-bottom: 1px solid var(--border); }
  .tab {
    flex: 1; padding: 12px; text-align: center; background: none;
    border: none; color: var(--text-dim); font-family: inherit;
    font-size: 14px; cursor: pointer; border-bottom: 2px solid transparent;
  }
  .tab.active { color: var(--gold); border-bottom-color: var(--gold); }

  .section { display: none; padding: 20px; padding-bottom: 60px; }
  .section.active { display: block; }

  /* Upload */
  .upload-zone {
    border: 2px dashed var(--border); border-radius: var(--radius);
    padding: 32px 20px; text-align: center; cursor: pointer;
    transition: border-color 0.2s; margin-bottom: 16px;
  }
  .upload-zone.dragover { border-color: var(--gold); }
  .upload-zone svg { width: 48px; height: 48px; stroke: var(--gold-dim); margin-bottom: 8px; }
  .upload-zone p { color: var(--text-dim); font-size: 14px; }
  .upload-zone .hint { font-size: 11px; margin-top: 6px; }

  .preview-strip {
    display: flex; gap: 8px; overflow-x: auto; padding: 8px 0;
    scrollbar-width: thin; scrollbar-color: var(--border) transparent;
  }
  .preview-thumb { position: relative; flex-shrink: 0; }
  .preview-thumb img {
    height: 80px; border-radius: 6px; border: 1px solid var(--border); object-fit: cover;
  }
  .preview-thumb .remove {
    position: absolute; top: -6px; right: -6px; width: 22px; height: 22px;
    background: var(--danger); color: white; border: none; border-radius: 50%;
    font-size: 14px; cursor: pointer; display: flex; align-items: center; justify-content: center;
  }

  label { display: block; font-size: 12px; color: var(--gold-dim); margin: 14px 0 4px; letter-spacing: 0.5px; }
  select, input, textarea {
    width: 100%; background: var(--surface); border: 1px solid var(--border);
    color: var(--text); padding: 10px 12px; border-radius: var(--radius);
    font-family: inherit; font-size: 16px; outline: none;
    -webkit-appearance: none; appearance: none;
  }
  select:focus, input:focus, textarea:focus { border-color: var(--gold); }
  textarea { resize: vertical; min-height: 60px; }

  .btn {
    display: block; width: 100%; padding: 14px; border: none;
    border-radius: var(--radius); font-family: inherit; font-size: 15px;
    font-weight: bold; cursor: pointer; letter-spacing: 0.5px;
    transition: transform 0.1s, opacity 0.2s; margin-top: 16px;
  }
  .btn:active { transform: scale(0.98); }
  .btn-gold { background: linear-gradient(135deg, #e3be74, #c99b3f); color: #2e2008; }
  .btn-green { background: linear-gradient(135deg, #2a6a2a, var(--success)); color: #e0ffe0; }
  .btn-red { background: var(--danger); color: #ffe0e0; font-size: 13px; padding: 10px; }
  .btn-secondary { background: var(--surface); border: 1px solid var(--border); color: var(--gold); }
  .btn:disabled { opacity: 0.4; cursor: not-allowed; }

  /* Cards */
  .card {
    background: var(--surface); border: 1px solid var(--border);
    border-radius: var(--radius); padding: 16px; margin-bottom: 14px;
    cursor: pointer; transition: border-color 0.15s;
  }
  .card:active { border-color: var(--gold); }
  .card-title { font-size: 16px; color: var(--gold); margin-bottom: 4px; }
  .card-meta { font-size: 11px; color: var(--text-dim); }
  .card-photos { display: flex; gap: 6px; margin: 10px 0; flex-wrap: wrap; }
  .card-photos img { height: 56px; border-radius: 4px; border: 1px solid var(--border); object-fit: cover; }

  .status-badge {
    display: inline-block; font-size: 10px; padding: 2px 8px; border-radius: 10px;
    text-transform: uppercase; letter-spacing: 1px; font-weight: bold;
  }
  .status-pending { background: #f1e0b4; color: #8a6420; }
  .status-reviewed { background: #d5ecdf; color: #1f7a54; }
  .status-approved { background: #d7e6f0; color: #21678a; }
  .status-submitted { background: #dcedd6; color: #2f7a2f; }

  /* Modal */
  .modal-overlay {
    display: none; position: fixed; inset: 0; background: rgba(59,42,20,0.55);
    z-index: 1000; overflow-y: auto; padding: 20px;
  }
  .modal-overlay.open { display: block; }
  .modal {
    background: var(--bg); border: 1px solid var(--border);
    border-radius: var(--radius); padding: 20px; max-width: 500px; margin: 0 auto;
  }
  .modal h2 { color: var(--gold); font-size: 18px; margin-bottom: 4px; font-weight: normal; }
  .modal .modal-sub { font-size: 11px; color: var(--text-dim); margin-bottom: 12px; }
  .modal-photos { display: flex; gap: 6px; margin: 10px 0; overflow-x: auto; }
  .modal-photos img { height: 80px; border-radius: 6px; cursor: pointer; border: 1px solid var(--border); }

  /* Toast */
  .toast {
    position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%);
    background: var(--success); color: white; padding: 12px 24px;
    border-radius: var(--radius); font-size: 14px; z-index: 2000;
    opacity: 0; transition: opacity 0.3s; pointer-events: none; text-align: center;
  }
  .toast.show { opacity: 1; }

  .empty-state { text-align: center; padding: 40px 20px; color: var(--text-dim); }
  .empty-state svg { width: 64px; height: 64px; stroke: var(--border); margin-bottom: 12px; }

  /* Library View */
  .breadcrumb { font-size: 13px; color: var(--text-dim); margin-bottom: 16px; }
  .breadcrumb span { cursor: pointer; color: var(--gold-dim); }
  .breadcrumb span:hover { color: var(--gold); text-decoration: underline; }

  .room-grid { display: grid; grid-template-columns: 1fr; gap: 14px; }
  .room-card {
    background: linear-gradient(135deg, var(--surface), #f0e3c6);
    border: 1px solid var(--border); border-radius: var(--radius);
    padding: 24px 20px; cursor: pointer; transition: border-color 0.15s, transform 0.1s;
    text-align: center;
  }
  .room-card:active { border-color: var(--gold); transform: scale(0.98); }
  .room-card h3 { color: var(--gold); font-size: 18px; font-weight: normal; margin-bottom: 6px; }
  .room-card p { color: var(--text-dim); font-size: 12px; }
  .mini-shelf-vis { margin-top: 10px; }
  .mini-shelf-row { display: flex; align-items: flex-end; min-height: 22px; border-bottom: 2px solid #8B6914; padding: 2px 0; position: relative; }
  .mini-shelf-num { position: absolute; right: 2px; bottom: 2px; font-size: 8px; color: var(--text-dim); opacity: 0.6; }
  .mini-spine { display: inline-block; height: 18px; min-width: 4px; border-radius: 1px; margin-right: 1px; }

  .bookshelf-list { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
  .bookshelf-card {
    background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
    padding: 16px; cursor: pointer; text-align: center; transition: border-color 0.15s;
  }
  .bookshelf-card:active { border-color: var(--gold); }
  .bookshelf-card h4 { color: var(--gold); font-weight: normal; font-size: 15px; }
  .bookshelf-card p { color: var(--text-dim); font-size: 11px; margin-top: 4px; }

  .bookshelf-visual {
    background: linear-gradient(180deg, #f0e4c8 0%, #e6d5ae 100%);
    border: 2px solid #c9ab72; border-radius: 6px; padding: 0 6px;
    margin-bottom: 16px;
  }
  .shelf-row {
    min-height: 170px; border-bottom: 4px solid #6b4420;
    background: linear-gradient(180deg, transparent 90%, #4a2a10 95%, #6b4420 100%);
    display: flex; align-items: flex-end; padding: 4px 2px 0; gap: 3px;
    position: relative; flex-wrap: nowrap; overflow-x: auto;
    -webkit-overflow-scrolling: touch;
  }
  .shelf-row:last-child { border-bottom: none; }
  .shelf-label {
    position: absolute; right: 4px; top: 4px; font-size: 9px;
    color: var(--text-dim); opacity: 0.5;
  }
  .book-spine {
    display: flex; align-items: center; justify-content: center;
    writing-mode: vertical-rl; text-orientation: mixed;
    height: 160px; padding: 6px 2px;
    border-radius: 2px 2px 0 0; cursor: pointer;
    font-size: 9px; font-weight: bold; color: #fff;
    text-shadow: 0 1px 2px rgba(0,0,0,0.7);
    flex-shrink: 0; transition: transform 0.15s;
    overflow: hidden;
    border-top: 1px solid rgba(255,255,255,0.15);
    border-left: 1px solid rgba(255,255,255,0.1);
    border-right: 1px solid rgba(0,0,0,0.2);
    line-height: 1.2;
  }
  .spine-text {
    overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
    max-height: 100%; text-align: center;
  }
  .book-spine:hover { transform: translateY(-4px); z-index: 1; }
  .shelf-books {
    display: flex; align-items: flex-end; gap: 3px;
    flex-wrap: nowrap; overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    flex: 1; min-width: 0;
  }
  .shelf-empty { font-size: 11px; color: var(--text-dim); opacity: 0.3; padding: 20px 0; text-align: center; width: 100%; }

  .book-detail-overlay {
    display: none; position: fixed; inset: 0; background: rgba(59,42,20,0.55);
    z-index: 1000; overflow-y: auto; padding: 20px;
  }
  .book-detail-overlay.open { display: block; }
  .book-detail {
    background: var(--bg); border: 1px solid var(--border);
    border-radius: var(--radius); padding: 20px; max-width: 500px; margin: 0 auto;
  }
  .book-detail h2 { color: var(--gold); font-size: 18px; font-weight: normal; margin-bottom: 4px; }
  .book-detail .author { color: var(--text-dim); font-size: 13px; margin-bottom: 12px; }
  .book-detail .field-row { display: flex; justify-content: space-between; padding: 6px 0; border-bottom: 1px solid var(--border); font-size: 13px; }
  .book-detail .field-label { color: var(--gold-dim); }
  .book-detail .field-value { color: var(--text); text-align: right; max-width: 60%; }
  .book-detail .photo-thumb { height: 100px; border-radius: 6px; cursor: pointer; border: 1px solid var(--border); margin-top: 12px; }

  .lib-stats { display: flex; gap: 12px; margin-bottom: 16px; flex-wrap: wrap; }
  .lib-stat { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 10px 14px; text-align: center; flex: 1; min-width: 80px; }
  .lib-stat .num { font-size: 22px; color: var(--gold); }
  .lib-stat .lbl { font-size: 10px; color: var(--text-dim); margin-top: 2px; }
  .export-bar { display: flex; gap: 8px; margin-bottom: 16px; }

  /* Catalog search */
  .lib-search { margin-bottom: 12px; }
  .lib-search input {
    -webkit-appearance: none; appearance: none;
  }

  /* Lending */
  .loan-chip {
    display: inline-block; background: #f1e0b4; color: #8a6420;
    border: 1px solid var(--border); border-radius: 10px; padding: 4px 12px;
    font-size: 12px; cursor: pointer; align-self: center;
  }
  .loan-banner {
    background: #f1e0b4; color: #8a6420; border: 1px solid var(--border);
    border-radius: var(--radius); padding: 10px 12px; font-size: 13px;
    margin-bottom: 12px;
  }
  .loan-tag { font-size: 11px; color: #8a6420; margin-top: 4px; }

  /* Compact book rows (loans view, search results) */
  .book-row { display: flex; gap: 12px; align-items: center; }
  .book-row-thumb {
    width: 44px; height: 62px; object-fit: cover; border-radius: 4px;
    border: 1px solid var(--border); background: #efe3c8; flex-shrink: 0;
  }
  .book-row-main { min-width: 0; flex: 1; }
  .book-row-main .card-title { overflow: hidden; text-overflow: ellipsis; }

  .spinner { display: inline-block; width: 18px; height: 18px; border: 2px solid var(--border);
    border-top-color: var(--gold); border-radius: 50%; animation: spin 0.6s linear infinite; }
  @keyframes spin { to { transform: rotate(360deg); } }

  /* Responsive — small screens */
  @media screen and (max-width: 480px) {
    .section { padding: 14px; padding-bottom: 60px; }
    header { padding: 10px 14px; }
    header h1 { font-size: 15px; letter-spacing: 1px; }
    .tab { font-size: 13px; padding: 10px 6px; }
    .room-card { padding: 16px 14px; }
    .room-card-name { font-size: 14px; }
    .modal { padding: 14px; }
    .book-spine { font-size: 8px; height: 130px; }
    .shelf-row { min-height: 140px; }
    .shelf-label { font-size: 8px; }
    .book-detail { padding: 14px; }
  }

  /* Responsive — tablets and wider phones */
  @media screen and (min-width: 600px) {
    .room-grid { grid-template-columns: 1fr 1fr; }
  }
  @media screen and (min-width: 900px) {
    .room-grid { grid-template-columns: 1fr 1fr 1fr; }
    .section { max-width: 900px; margin: 0 auto; }
  }
