:root {
  --walnut: #3d2817;
  --walnut-deep: #2a1810;
  --navy: #1a2848;
  --brass: #c9a227;
  --persimmon: #c45c26;
  --moss: #4a6b4a;
  --grape: #5c3a5c;
  --paper: #f2ead8;
  --cream: #e8dcc8;
  --ink: #1a1520;
  --mint: #7fd4b8;
  --safe-x: max(12px, env(safe-area-inset-left));
  --safe-r: max(12px, env(safe-area-inset-right));
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

html {
  scroll-behavior: smooth;
}

body {
  margin: 0;
  min-height: 100dvh;
  font-family: "Hiragino Maru Gothic ProN", "Hiragino Sans", "Yu Gothic UI", sans-serif;
  color: var(--paper);
  background: var(--walnut-deep);
  line-height: 1.5;
}

.library-bg {
  position: fixed;
  inset: 0;
  background:
    radial-gradient(ellipse 120% 80% at 50% -10%, rgba(201, 162, 39, 0.12), transparent 55%),
    linear-gradient(165deg, #1a1210 0%, var(--walnut-deep) 40%, #120c08 100%);
  pointer-events: none;
}

.library-bg::after {
  content: "";
  position: absolute;
  inset: 0;
  opacity: 0.35;
  background: repeating-linear-gradient(
    90deg,
    transparent,
    transparent 48px,
    rgba(0, 0, 0, 0.15) 48px,
    rgba(0, 0, 0, 0.15) 52px
  );
}

.masthead {
  padding: 12px var(--safe-x);
}

.back {
  color: var(--mint);
  text-decoration: none;
  font-size: 0.9rem;
}

.back:focus-visible {
  outline: 2px solid var(--mint);
  outline-offset: 3px;
}

.library-app {
  position: relative;
  max-width: 440px;
  margin: 0 auto;
  padding: 0 var(--safe-x) 32px;
}

.hero {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 8px;
  align-items: end;
  margin-bottom: 16px;
}

.kicker {
  font-size: 0.65rem;
  letter-spacing: 0.12em;
  color: var(--brass);
  margin: 0 0 4px;
}

.hero h1 {
  margin: 0;
  font-size: 1.55rem;
  line-height: 1.25;
  color: var(--paper);
}

.hero h1 span {
  display: block;
  color: var(--mint);
}

.catch {
  margin: 8px 0 0;
  font-size: 0.92rem;
  color: var(--cream);
}

.burapi-wrap {
  position: relative;
  margin: 0;
}

.burapi-char {
  display: block;
  filter: drop-shadow(0 4px 8px rgba(0, 0, 0, 0.35));
}

.armband {
  position: absolute;
  bottom: 4px;
  right: -4px;
  font-size: 0.6rem;
  background: var(--moss);
  color: var(--paper);
  padding: 2px 6px;
  border-radius: 4px;
}

.start-panel {
  text-align: center;
  padding: 20px 16px;
  background: rgba(61, 40, 23, 0.85);
  border: 1px solid rgba(201, 162, 39, 0.35);
  border-radius: 12px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.35);
}

.rule-lead {
  margin: 0 0 16px;
  font-size: 0.95rem;
}

.btn-primary {
  font: inherit;
  font-weight: 700;
  cursor: pointer;
  border: none;
  border-radius: 999px;
  padding: 12px 28px;
  background: linear-gradient(180deg, var(--mint) 0%, #5bb89a 100%);
  color: var(--navy);
  box-shadow: 0 4px 0 #3a8a72;
}

.btn-primary:focus-visible {
  outline: 2px solid var(--paper);
  outline-offset: 3px;
}

.btn-ghost {
  font: inherit;
  cursor: pointer;
  border: 1px solid rgba(201, 162, 39, 0.5);
  border-radius: 8px;
  padding: 8px 12px;
  background: rgba(26, 40, 72, 0.5);
  color: var(--paper);
}

.btn-ghost.hint-idle {
  border-color: var(--persimmon);
  box-shadow: 0 0 0 2px rgba(196, 92, 38, 0.35);
}

.btn-text {
  font: inherit;
  cursor: pointer;
  background: none;
  border: none;
  color: var(--mint);
  text-decoration: underline;
  padding: 4px 8px;
}

.records {
  margin: 12px 0 0;
  font-size: 0.8rem;
  color: var(--cream);
  opacity: 0.85;
}

.play-panel {
  padding: 12px 0;
}

.shelf-head h2 {
  margin: 0;
  font-size: 1.15rem;
  color: var(--brass);
}

.shelf-head p {
  margin: 4px 0 12px;
  font-size: 0.88rem;
  color: var(--cream);
}

.vine-preview {
  display: flex;
  gap: 4px;
  justify-content: center;
  margin-bottom: 10px;
  padding: 6px;
  background: rgba(0, 0, 0, 0.2);
  border-radius: 8px;
}

.mini-spine {
  font-size: 0.55rem;
  width: 14px;
  height: 36px;
  background: var(--moss);
  border-radius: 2px 3px 2px 2px;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  padding-bottom: 2px;
  position: relative;
}

.shelf-stage {
  position: relative;
  padding: 16px 8px 28px;
  background: linear-gradient(180deg, rgba(61, 40, 23, 0.6) 0%, rgba(42, 24, 16, 0.95) 100%);
  border-radius: 10px;
  border: 1px solid rgba(201, 162, 39, 0.25);
}

.shelf-board {
  position: absolute;
  left: 4%;
  right: 4%;
  bottom: 8px;
  height: 10px;
  background: linear-gradient(180deg, #5c4030, #3d2817);
  border-radius: 2px;
  box-shadow: 0 4px 8px rgba(0, 0, 0, 0.4);
}

.book-row {
  display: flex;
  align-items: flex-end;
  justify-content: center;
  gap: 0;
  min-height: 120px;
  position: relative;
  z-index: 1;
}

.book-row.pulse-good {
  animation: shelf-pulse 0.28s ease;
}

@keyframes shelf-pulse {
  50% {
    filter: brightness(1.08);
  }
}

.book {
  --book-h: 72px;
  position: relative;
  flex: 0 0 auto;
  width: 46px;
  height: var(--book-h);
  padding: 0;
  border: none;
  cursor: grab;
  touch-action: none;
  background: transparent;
  transition: filter 0.15s ease;
}

.book:focus-visible {
  outline: 2px solid var(--mint);
  outline-offset: 3px;
}

.book.kb-focus {
  outline: 2px dashed var(--brass);
  outline-offset: 4px;
}

.book.dragging {
  cursor: grabbing;
  z-index: 5;
  filter: drop-shadow(0 12px 16px rgba(0, 0, 0, 0.45));
}

.book-body {
  display: block;
  width: 100%;
  height: 100%;
  border-radius: 3px 5px 4px 3px;
  background: linear-gradient(90deg, rgba(0, 0, 0, 0.15) 0%, transparent 12%, transparent 88%, rgba(255, 255, 255, 0.08) 100%);
  box-shadow:
    inset -3px 0 6px rgba(0, 0, 0, 0.25),
    inset 2px 0 4px rgba(255, 255, 255, 0.06),
    2px 2px 0 rgba(0, 0, 0, 0.2);
  position: relative;
}

.book-label {
  position: absolute;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%) rotate(-90deg);
  font-size: 0.72rem;
  font-weight: 700;
  color: var(--paper);
  text-shadow: 0 1px 2px rgba(0, 0, 0, 0.5);
  white-space: nowrap;
}

.book-pin {
  position: absolute;
  bottom: -6px;
  left: 50%;
  transform: translateX(-50%);
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--brass);
  opacity: 0;
  transition: opacity 0.15s;
}

.book.pos-ok .book-pin {
  opacity: 1;
}

.book.pos-ng::after {
  content: "";
  position: absolute;
  top: 4px;
  right: -4px;
  width: 10px;
  height: 10px;
  background: var(--persimmon);
  border-radius: 1px;
  transform: rotate(8deg);
  box-shadow: 0 1px 0 rgba(0, 0, 0, 0.3);
}

.vine-gap {
  flex: 0 0 6px;
  align-self: center;
  height: 4px;
  margin: 0 -1px;
  border-radius: 2px;
  background: transparent;
  position: relative;
}

.vine-gap.adj-ok::before {
  content: "";
  position: absolute;
  inset: -2px -4px;
  background: linear-gradient(90deg, var(--brass), #e8c547);
  border-radius: 2px;
  box-shadow: 0 0 6px rgba(201, 162, 39, 0.5);
}

.vine-gap.adj-ng::after {
  content: "×";
  position: absolute;
  top: -14px;
  left: 50%;
  transform: translateX(-50%);
  font-size: 0.55rem;
  color: var(--persimmon);
}

.book.hint-ghost .book-body {
  outline: 2px dashed var(--brass);
  outline-offset: 3px;
}

.spine-h1 .book-body {
  background-color: #6b5344;
}
.spine-h2 .book-body {
  background-color: #7a5f4a;
}
.spine-h3 .book-body {
  background-color: #8a6b52;
}
.spine-h4 .book-body {
  background-color: #9a7758;
}
.spine-h5 .book-body {
  background-color: #aa845e;
}

.spine-v1 .book-body {
  background: linear-gradient(180deg, var(--navy), #2a3860);
}
.spine-v2 .book-body {
  background: linear-gradient(180deg, #2a3860, var(--grape));
}
.spine-v3 .book-body {
  background: linear-gradient(180deg, var(--grape), #4a3050);
}
.spine-v4 .book-body {
  background: linear-gradient(180deg, #4a3050, var(--moss));
}
.spine-v5 .book-body {
  background: linear-gradient(180deg, var(--moss), #3a553a);
}
.spine-v6 .book-body {
  background: linear-gradient(180deg, #3a553a, #2a402a);
}

.spine-g1 .book-body {
  background: linear-gradient(180deg, var(--moss), #3d5c3d);
}
.spine-g2 .book-body {
  background: linear-gradient(180deg, #4a6b4a, var(--persimmon));
}
.spine-g3 .book-body {
  background: linear-gradient(180deg, var(--persimmon), #a84820);
}
.spine-g4 .book-body {
  background: linear-gradient(180deg, #a84820, var(--brass));
}
.spine-g5 .book-body {
  background: linear-gradient(180deg, var(--brass), #8a7020);
}
.spine-g6 .book-body {
  background: linear-gradient(180deg, #8a7020, var(--navy));
}

.shelf-done .book-body {
  animation: spine-glow 0.65s ease;
}

@keyframes spine-glow {
  50% {
    filter: brightness(1.15);
  }
}

.hud-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-top: 12px;
}

.progress {
  margin: 0;
  font-size: 0.9rem;
  font-weight: 700;
}

.hud-actions {
  display: flex;
  gap: 8px;
}

.live-msg {
  min-height: 1.4em;
  margin: 8px 0 0;
  font-size: 0.88rem;
  color: var(--mint);
}

.summary-panel {
  text-align: center;
  padding: 24px 16px;
  background: rgba(26, 40, 72, 0.75);
  border-radius: 12px;
  border: 1px solid rgba(127, 212, 184, 0.35);
}

.summary-panel h2 {
  margin: 0 0 8px;
  color: var(--brass);
  font-size: 1.35rem;
}

.cta-row {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  justify-content: center;
  margin-top: 16px;
}

.utility-row {
  display: flex;
  gap: 12px;
  justify-content: center;
  margin-top: 16px;
}

.disclaimer {
  font-size: 0.75rem;
  color: var(--cream);
  opacity: 0.75;
  margin-top: 12px;
}

.capture-only {
  display: none;
}

[data-capture="1"] .capture-hide,
[data-promoShot="1"] .promo-hide {
  display: none !important;
}

[data-capture="1"] .capture-only {
  display: block;
}

[data-capture="1"] .capture-hud {
  text-align: center;
  font-weight: 700;
  color: var(--brass);
  margin-bottom: 8px;
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}

@media (min-width: 720px) {
  .library-app {
    max-width: 520px;
  }
  .book {
    width: 52px;
  }
}
