:root {
  --olive: #3b4a2f;
  --gold: #c8a84b;
  --gold-light: #e8cc7a;
  --cream: #f5f0e8;
  --cream-dark: #e8dfc8;
  --red: #8b1a1a;
  --ink: #1a1a2e;
  --shadow: rgba(0, 0, 0, 0.4);
  --page-w: 420px;
  --page-h: 580px;
}

* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

body {
  background: radial-gradient(ellipse at center, #1a1a0a 0%, #0a0a0a 100%);
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  overflow-x: hidden;
  padding: 20px;
  /* font-family: 'Roboto', sans-serif; */
  font-family: 'Arial', sans-serif;
}

/* ── HEADER ── */
.header {
  text-align: center;
  margin-bottom: 28px;
}

.header h1 {
  color: var(--gold);
  font-size: 2rem;
  letter-spacing: 3px;
  text-transform: uppercase;
  text-shadow: 0 2px 20px rgba(200, 168, 75, 0.4);
}

.header p {
  color: #888;
  font-size: 0.85rem;
  letter-spacing: 2px;
  margin-top: 4px;
}

/* ── SEARCH BAR ── */
.search-bar {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 10px;
  margin-bottom: 20px;
  width: 100%;
  max-width: 680px;
}

#searchInput {
  flex: 1;
  padding: 8px 14px;
  background: rgba(255, 255, 255, 0.07);
  border: 1px solid var(--gold);
  border-radius: 4px;
  color: var(--cream);
  font-family: 'Rajdhani', sans-serif;
  font-size: 0.9rem;
  letter-spacing: 1px;
  outline: none;
  transition: border-color 0.2s, background 0.2s;
}

#searchInput::placeholder {
  color: rgba(200, 168, 75, 0.4);
}

#searchInput:focus {
  border-color: var(--gold-light);
  background: rgba(255, 255, 255, 0.12);
}

.search-nav {
  display: flex;
  align-items: center;
  gap: 6px;
  justify-content: space-between;
  white-space: nowrap;
  flex: 1;
}

#searchLabel {
  color: var(--gold);
  font-family: 'Rajdhani', sans-serif;
  font-size: 0.85rem;
  letter-spacing: 1px;
  min-width: 110px;
  text-align: center;
}

mark.search-highlight {
  background: #ff0000;
  color: #fff;
  border-radius: 2px;
  padding: 0 1px;
  font-style: inherit;
  font-weight: inherit;
}

@keyframes blink {
  0%, 100% {
    background-color: #1a2810;
  }
  50% {
    background-color: #1f2e14;
  }
}

/* ── LOADING OVERLAY ── */
.flipbook-loader {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 18px;
  background: rgba(10, 16, 6, 0.82);
  backdrop-filter: blur(4px);
  z-index: 50;
  transition: opacity 0.45s ease, visibility 0.45s ease;
}

.flipbook-scene.loaded .flipbook-loader {
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
}

/* Four-dot ring spinner */
.fl-spinner {
  position: relative;
  width: 48px;
  height: 48px;
}

.fl-spinner span {
  position: absolute;
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--gold);
  animation: fl-orbit 1.2s ease-in-out infinite;
}

.fl-spinner span:nth-child(1) { top: 0;    left: 50%; transform: translateX(-50%); animation-delay: 0s;    }
.fl-spinner span:nth-child(2) { top: 50%;  right: 0;  transform: translateY(-50%); animation-delay: 0.3s;  }
.fl-spinner span:nth-child(3) { bottom: 0; left: 50%; transform: translateX(-50%); animation-delay: 0.6s;  }
.fl-spinner span:nth-child(4) { top: 50%;  left: 0;   transform: translateY(-50%); animation-delay: 0.9s;  }

@keyframes fl-orbit {
  0%, 100% { opacity: 0.2; transform: translateX(-50%) scale(0.75); }
  50%       { opacity: 1;   transform: translateX(-50%) scale(1.15); }
}

.fl-spinner span:nth-child(2) { animation-name: fl-orbit-h; }
.fl-spinner span:nth-child(4) { animation-name: fl-orbit-h; }

@keyframes fl-orbit-h {
  0%, 100% { opacity: 0.2; transform: translateY(-50%) scale(0.75); }
  50%       { opacity: 1;   transform: translateY(-50%) scale(1.15); }
}

.fl-text {
  color: var(--gold);
  font-family: 'Rajdhani', sans-serif;
  font-size: 0.8rem;
  letter-spacing: 2px;
  text-transform: uppercase;
  opacity: 0.75;
}

/* ── FLIPBOOK CONTAINER ── */
.flipbook-scene{
  position: relative;
  display: flex;
  justify-content: center;
  min-height: 512px;
  background-color: #1a2810;
  animation: blink 1.5s ease-out infinite;
}

#flipbook {
  position: relative;
}

/* Each page rendered by StPageFlip */
.page {
  background: linear-gradient(135deg, #faf6ec 0%, #f0e8d0 50%, #e8dcc0 100%);
  overflow: hidden;
}

.page-measure {
  position: fixed;
  left: -10000px;
  top: 0;
  visibility: hidden;
  pointer-events: none;
  z-index: -1;
}

/* ── PAGE CONTENT STYLE ── */
.page-content {
  width: 100%;
  height: 100%;
  background: linear-gradient(135deg, #faf6ec 0%, #f0e8d0 50%, #e8dcc0 100%);
  position: relative;
  display: flex;
  flex-direction: column;
  box-shadow: inset 2px 0 8px rgba(0, 0, 0, 0.1), inset -2px 0 4px rgba(0, 0, 0, 0.05);
}

/* Page texture overlay */
.page-content::before {
  content: '';
  position: absolute;
  inset: 0;
  background-image: url("data:image/svg+xml,%3Csvg viewBox='0 0 200 200' xmlns='http://www.w3.org/2000/svg'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.9' numOctaves='4' stitchTiles='stitch'/%3E%3CfeColorMatrix type='saturate' values='0'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)' opacity='0.04'/%3E%3C/svg%3E");
  opacity: 0.5;
  pointer-events: none;
  z-index: 0;
}

/* ── PAGE HEADER BAR ── */
.page-header {
  background: linear-gradient(to right, var(--olive), #4a5c38);
  padding: 10px 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  position: relative;
  z-index: 1;
  border-bottom: 3px solid var(--gold);
}

.page-header .title {
  color: var(--gold);
  font-weight: 700;
  font-size: 0.75rem;
  letter-spacing: 2px;
  text-transform: uppercase;
}

.page-header .emblem {
  width: 32px;
  height: 32px;
  background: var(--gold);
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1rem;
  flex-shrink: 0;
}

/* ── TABLE ── */
.officers-table {
  flex: 1;
  min-height: 0;
  /* required: lets flex item shrink below content size */
  overflow: hidden;
  /* no scrolling; overflow rows move to the next page  */
  padding: 0;
  position: relative;
  z-index: 1;
  background: #e8dfc8;
}

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.65rem;
}

thead tr {
  background: var(--dept-heading-bg, var(--red));
}

thead th {
  color: white;
  font-weight: 700;
  letter-spacing: 1px;
  padding: 6px 6px;
  text-align: left;
  font-size: 0.6rem;
  text-transform: uppercase;
}

.col-rank {
  width: 70px;
}

.col-name {
  width: 150px;
}

.col-address {
  width: 230px;
}

.col-contact {
  width: 70px;
}

tbody tr {
  /* background: var(--dept-row-bg, transparent); */
  background-color: #e8dfc8;
  border-bottom: 1px solid rgba(60, 50, 20, 0.15);
  transition: background 0.2s;
}

tbody tr:hover {
  background: rgba(200, 168, 75, 0.1);
}

td {
  padding: 5px 6px;
  vertical-align: top;
  line-height: 1.4;
  color: var(--ink);
  font-size: 0.62rem;
}

/* Photo placeholder */
.photo-cell {
  width: 54px;
  text-align: center;
}

.army-number {
  display: block;
  margin-bottom: 4px;
  font-size: 0.48rem;
  line-height: 1.2;
  font-weight: 700;
  letter-spacing: 0.3px;
  color: var(--ink);
  word-break: break-word;
}

.army-number.empty {
  color: rgba(59, 74, 47, 0.45);
}

.photo-frame {
  width: 50px;
  height: 50px;
  margin: auto;
  position: relative;
  border-radius: 4px;
  overflow: hidden;
  border: 1px solid var(--gold);
  background: linear-gradient(135deg, var(--olive), #5a6c48);
}

.officer-photo {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  object-position: center top;
  z-index: 1;
  background: #d9d1bc;
}

.photo-placeholder {
  width: 100%;
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--gold);
  font-size: 1rem;
  margin: auto;
  position: relative;
  z-index: 0;
}

.rank-name-cell .rank {
  font-weight: 700;
  color: var(--ink);
  font-size: 0.63rem;
  display: block;
}

.rank-name-cell .name {
  font-weight: 600;
  color: var(--ink);
  font-size: 0.66rem;
  display: block;
  line-height: 1.3;
}

.rank-name-cell .honors {
  color: var(--red);
  font-size: 0.55rem;
  font-style: italic;
}

.name-cell .name {
  font-weight: 600;
  color: var(--ink);
  font-size: 0.66rem;
  display: block;
  line-height: 1.3;
}

.rank-cell {
  font-weight: 700;
  font-size: 0.6rem;
  color: var(--ink);
  line-height: 1.35;
}

/* ── CLICKABLE PHONE / EMAIL ── */
.phone-link {
  display: inline-flex;
  align-items: center;
  gap: 3px;
  color: var(--ink);
  text-decoration: none;
  font-weight: 600;
  font-size: 0.65rem;
  padding: 2px 4px;
  border-radius: 3px;
  border: 1px solid transparent;
  transition: all 0.2s;
  cursor: pointer;
  white-space: nowrap;
}

.empty-contact {
  color: #aaa;
  font-size: 0.6rem;
}

.phone-link:hover {
  color: var(--red);
  border-color: var(--red);
  background: rgba(139, 26, 26, 0.06);
}

.phone-link .icon {
  font-size: 0.55rem;
}

.email-link {
  display: inline-flex;
  align-items: center;
  gap: 3px;
  color: #1a4a8a;
  text-decoration: none;
  font-size: 0.62rem;
  padding: 2px 4px;
  border-radius: 3px;
  border: 1px solid transparent;
  transition: all 0.2s;
  cursor: pointer;
}

.email-link:hover {
  color: white;
  background: #1a4a8a;
  border-color: #1a4a8a;
}

/* Address */
.address-cell {
  font-size: 0.58rem;
  color: #444;
  line-height: 1.5;
}

.pin {
  color: var(--ink);
  font-weight: 600;
  font-size: 0.58rem;
}

/* ── PAGE FOOTER ── */
.page-footer {
  background: linear-gradient(to right, var(--olive), #4a5c38);
  padding: 5px 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  position: relative;
  z-index: 1;
  border-top: 2px solid var(--gold);
}

.page-footer .pg-num {
  color: var(--gold);
  font-size: 0.7rem;
  letter-spacing: 2px;
}

.page-footer .confidential {
  color: rgba(200, 168, 75, 0.5);
  font-size: 0.55rem;
  letter-spacing: 1px;
  text-transform: uppercase;
}

/* ── COVER PAGE ── */
.cover-page {
  width: 100%;
  height: 100%;
  background: linear-gradient(160deg, #1a2810 0%, #2a3c1c 40%, #1a2810 100%);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 30px 20px;
  position: relative;
  overflow: hidden;
}

.cover-page-image-only {
  background: #000;
  padding: 0;
  display: block;
}

.cover-page-image-only::before,
.cover-page-image-only::after {
  content: none;
}

.cover-art {
  width: min(82%, 290px);
  max-height: 210px;
  object-fit: contain;
  object-position: center;
  margin: 0 0 18px;
  filter: drop-shadow(0 10px 24px rgba(0, 0, 0, 0.35));
  position: relative;
  z-index: 1;
}

.cover-art-full-page {
  width: 100%;
  height: 100%;
  max-height: none;
  margin: 0;
  display: block;
  object-fit: cover;
  object-position: center;
  filter: none;
}

.cover-page::before {
  content: '';
  position: absolute;
  inset: 12px;
  border: 1px solid rgba(200, 168, 75, 0.3);
  border-radius: 2px;
  pointer-events: none;
}

.cover-page::after {
  content: '';
  position: absolute;
  inset: 16px;
  border: 1px solid rgba(200, 168, 75, 0.15);
  border-radius: 2px;
  pointer-events: none;
}

.cover-emblem {
  width: 80px;
  height: 80px;
  background: radial-gradient(circle, var(--gold) 0%, #8a6a20 100%);
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 2.5rem;
  margin-bottom: 20px;
  box-shadow: 0 0 30px rgba(200, 168, 75, 0.4);
  position: relative;
  z-index: 1;
}

.cover-title {
  color: var(--gold);
  font-size: 1.4rem;
  text-align: center;
  letter-spacing: 3px;
  text-transform: uppercase;
  line-height: 1.3;
  text-shadow: 0 2px 20px rgba(200, 168, 75, 0.3);
  margin-bottom: 8px;
  position: relative;
  z-index: 1;
}

.cover-sub {
  color: rgba(200, 168, 75, 0.6);
  font-size: 0.8rem;
  letter-spacing: 4px;
  text-transform: uppercase;
  text-align: center;
  margin-bottom: 30px;
  position: relative;
  z-index: 1;
}

.cover-divider {
  width: 60%;
  height: 1px;
  background: linear-gradient(to right, transparent, var(--gold), transparent);
  margin: 15px 0;
  position: relative;
  z-index: 1;
}

.cover-note {
  color: rgba(200, 168, 75, 0.5);
  font-size: 0.75rem;
  text-align: center;
  font-style: italic;
  line-height: 1.6;
  position: relative;
  z-index: 1;
}

.cover-corner {
  position: absolute;
  width: 30px;
  height: 30px;
  border-color: rgba(200, 168, 75, 0.3);
  border-style: solid;
}

.cover-corner.tl {
  top: 22px;
  left: 22px;
  border-width: 2px 0 0 2px;
}

.cover-corner.tr {
  top: 22px;
  right: 22px;
  border-width: 2px 2px 0 0;
}

.cover-corner.bl {
  bottom: 22px;
  left: 22px;
  border-width: 0 0 2px 2px;
}

.cover-corner.br {
  bottom: 22px;
  right: 22px;
  border-width: 0 2px 2px 0;
}

/* ── BACK COVER ── */
.back-cover {
  width: 100%;
  height: 100%;
  background: linear-gradient(200deg, #1a2810 0%, #2a3c1c 60%, #1a2810 100%);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 30px;
  position: relative;
}

.back-cover::before {
  content: '';
  position: absolute;
  inset: 12px;
  border: 1px solid rgba(200, 168, 75, 0.2);
  border-radius: 2px;
}

.back-cover-text {
  color: rgba(200, 168, 75, 0.4);
  font-size: 1.2rem;
  text-align: center;
  font-style: italic;
}

.back-cover-emblem {
  width: 60px;
  height: 60px;
  font-size: 1.8rem;
  background: radial-gradient(circle, rgba(200, 168, 75, 0.3) 0%, rgba(200, 168, 75, 0.05) 100%);
}

.back-cover-divider {
  width: 60%;
  height: 1px;
  background: linear-gradient(to right, transparent, rgba(200, 168, 75, 0.3), transparent);
  margin: 20px auto;
}

.back-cover-note {
  color: rgba(200, 168, 75, 0.3);
  font-size: 0.7rem;
  letter-spacing: 2px;
  text-align: center;
}

.blank-page {
  background: #e8dcc0;
}

/* ── DEPARTMENT TITLE PAGE ── */
.dept-title-page {
  background: linear-gradient(160deg, #1a2810 0%, #2a3c1c 40%, #1a2810 100%) !important;
  /* background-color: #ffffff; */
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 30px 20px;
  position: relative;
  overflow: hidden;
}

.dept-title-page-image-only {
  background: #000 !important;
  padding: 0;
}

.dept-title-page-image-only::before {
  content: none;
}

.dept-title-page::before {
  content: '';
  position: absolute;
  inset: 12px;
  border: 1px solid rgba(200, 168, 75, 0.3);
  border-radius: 2px;
  pointer-events: none;
}

.dept-emblem {
  width: 70px;
  height: 70px;
  background: radial-gradient(circle, var(--gold) 0%, #8a6a20 100%);
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 2rem;
  margin-bottom: 24px;
  box-shadow: 0 0 30px rgba(200, 168, 75, 0.4);
}

.dept-title {
  color: var(--gold);
  /* color: var(--red); */
  font-size: 1.3rem;
  text-align: center;
  letter-spacing: 3px;
  text-transform: uppercase;
  line-height: 1.4;
  text-shadow: 0 2px 20px rgba(200, 79, 75, 0.3);
  margin-bottom: 8px;
  padding: 0 20px;
}

.dept-divider {
  width: 60%;
  height: 1px;
  background: linear-gradient(to right, transparent, var(--gold), transparent);
  margin: 16px 0;
}

.dept-sub {
  color: rgba(200, 168, 75, 0.6);
  font-size: 0.8rem;
  letter-spacing: 4px;
  text-transform: uppercase;
  text-align: center;
}

/* ── CONTROLS ── */
.controls {
  display: flex;
  align-items: center;
  gap: 16px;
  margin-top: 24px;
  flex-wrap: wrap;
  justify-content: center;
}

.btn {
  font-weight: 700;
  font-size: 0.85rem;
  letter-spacing: 2px;
  text-transform: uppercase;
  padding: 10px 24px;
  border: 1px solid var(--gold);
  background: transparent;
  color: var(--gold);
  cursor: pointer;
  border-radius: 3px;
  transition: all 0.25s;
  display: flex;
  align-items: center;
  gap: 8px;
}

.btn:hover {
  background: var(--gold);
  color: #1a1a0a;
}

.btn:disabled {
  opacity: 0.3;
  cursor: not-allowed;
  pointer-events: none;
}

.page-indicator {
  color: rgba(200, 168, 75, 0.6);
  font-size: 0.8rem;
  letter-spacing: 2px;
  min-width: 100px;
  text-align: center;
}

/* ── SOUND / SLIDESHOW TOGGLE ── */
.sound-btn,
.slideshow-btn {
  font-weight: 600;
  font-size: 0.75rem;
  letter-spacing: 1px;
  padding: 6px 14px;
  border: 1px solid rgba(200, 168, 75, 0.3);
  background: transparent;
  color: rgba(200, 168, 75, 0.6);
  cursor: pointer;
  border-radius: 20px;
  transition: all 0.25s;
}

.sound-btn:hover,
.sound-btn.active,
.slideshow-btn:hover,
.slideshow-btn.active {
  border-color: var(--gold);
  color: var(--gold);
}

/* ── PAGINATION ── */
.pagination {
  display: flex;
  align-items: center;
  gap: 4px;
  margin-top: 16px;
  flex-wrap: wrap;
  justify-content: center;
  max-width: 900px;
}

.pg-btn {
  font-weight: 600;
  font-size: 0.8rem;
  letter-spacing: 1px;
  min-width: 34px;
  height: 34px;
  padding: 0 8px;
  border: 1px solid rgba(200, 168, 75, 0.3);
  background: transparent;
  color: rgba(200, 168, 75, 0.65);
  cursor: pointer;
  border-radius: 3px;
  transition: all 0.2s;
}

.pg-btn:hover:not(:disabled) {
  border-color: var(--gold);
  color: var(--gold);
  background: rgba(200, 168, 75, 0.08);
}

.pg-btn.active {
  border-color: var(--gold);
  background: var(--gold);
  color: #1a1a0a;
  pointer-events: none;
}

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

.pg-btn.pg-edge {
  font-size: 1rem;
  letter-spacing: 0;
}

.pg-ellipsis {
  color: rgba(200, 168, 75, 0.35);
  font-size: 1rem;
  padding: 0 4px;
  line-height: 34px;
}

/* ── TOAST / CALL POPUP ── */
.toast {
  position: fixed;
  bottom: 30px;
  left: 50%;
  transform: translateX(-50%) translateY(80px);
  background: var(--olive);
  border: 1px solid var(--gold);
  color: var(--gold);
  padding: 12px 24px;
  border-radius: 6px;
  font-size: 0.9rem;
  letter-spacing: 1px;
  transition: transform 0.3s ease;
  z-index: 1000;
  display: flex;
  align-items: center;
  gap: 10px;
  box-shadow: 0 8px 30px rgba(0, 0, 0, 0.5);
}

.toast.show {
  transform: translateX(-50%) translateY(0);
}

/* ── KEYBOARD HINT ── */
.keyboard-hint {
  color: rgba(200, 168, 75, 0.3);
  font-size: 0.7rem;
  letter-spacing: 1px;
  margin-top: 10px;
  text-align: center;
}

kbd {
  background: rgba(200, 168, 75, 0.1);
  border: 1px solid rgba(200, 168, 75, 0.2);
  border-radius: 3px;
  padding: 1px 5px;
}

/* Mobile */
@media (max-width: 900px) {
  :root {
    --page-w: 300px;
    --page-h: 440px;
  }

  body {
    padding: 10px 6px;
  }

  .header {
    margin-bottom: 12px;
  }

  .header h1 {
    font-size: 1.3rem;
  }

  td {
    font-size: 0.55rem;
    padding: 3px 4px;
  }

  .phone-link {
    font-size: 0.55rem;
  }

  .cover-title {
    font-size: 1rem;
  }
}

@media (max-width: 640px) {
  :root {
    --page-w: 240px;
    --page-h: 360px;
  }

  .header h1 {
    font-size: 1.1rem;
  }

  table {
    font-size: 0.5rem;
  }
}