/* ============================================================
   CSS Variables
   ============================================================ */
:root {
  --accent:        #ff6b8a;
  --accent-dark:   #cc3355;
  --accent-glow:   rgba(255, 107, 138, 0.4);
  --bg-app:        #0a0a0a;
  --bg-phone:      #111111;
  --bg-card:       #1c1c1c;
  --bg-card2:      #252525;
  --text-primary:  #ffffff;
  --text-secondary:#b0b0b0;
  --text-muted:    #666666;
  --border:        #333333;
  --ctrl-h:        68px;
}

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

html, body {
  width: 100%;
  height: 100%;
  overflow: hidden;
  background: var(--bg-app);
  color: var(--text-primary);
  font-family: 'Hiragino Kaku Gothic ProN', 'Hiragino Sans', Meiryo,
               'Helvetica Neue', Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
}

button { cursor: pointer; border: none; outline: none; }
img { display: block; max-width: 100%; }

/* ============================================================
   App wrapper & Phone Container (9:16)
   ============================================================ */
#app {
  width: 100vw;
  height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
}

#phone-container {
  position: relative;
  /* Maintain 9:16 aspect ratio */
  width:  min(100vw, calc(100vh * 9 / 16));
  height: min(100vh, calc(100vw * 16 / 9));
  background: var(--bg-phone);
  overflow: hidden;
  /* Phone frame on desktop */
  border-radius: 0;
}

@media (min-aspect-ratio: 9/16) {
  #phone-container {
    border-radius: 24px;
    box-shadow:
      0 0 0 6px #1e1e1e,
      0 0 0 10px #2a2a2a,
      0 30px 80px rgba(0,0,0,0.9);
  }
}

/* ============================================================
   Screen base
   ============================================================ */
.screen {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
}
.screen.hidden { display: none !important; }

/* ============================================================
   Utility
   ============================================================ */
.center-wrap {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 24px;
  gap: 12px;
}
.hidden { display: none !important; }

/* ============================================================
   Loading Screen
   ============================================================ */
#screen-loading {
  background: var(--bg-phone);
  justify-content: center;
}
.app-logo       { font-size: 52px; margin-bottom: 4px; }
.app-title-text { font-size: 26px; font-weight: 700; letter-spacing: 0.08em; color: var(--accent); }
.app-sub-text   { font-size: 13px; color: var(--text-secondary); margin-top: -4px; }

.loading-bar-wrap {
  width: 70%;
  height: 5px;
  background: rgba(255,255,255,0.12);
  border-radius: 3px;
  overflow: hidden;
  margin-top: 20px;
}
#loading-bar {
  height: 100%;
  width: 0%;
  background: linear-gradient(90deg, var(--accent-dark), var(--accent));
  border-radius: 3px;
  transition: width 0.25s ease;
}
.loading-label {
  font-size: 12px;
  color: var(--text-muted);
  margin-top: -4px;
}
.privacy-notice {
  font-size: 10px;
  color: var(--text-muted);
  text-align: center;
  line-height: 1.7;
  margin-top: 8px;
  padding: 10px 16px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: rgba(255,255,255,0.03);
}

/* ============================================================
   Title Screen
   ============================================================ */
#screen-title {
  background: var(--bg-phone);
  overflow-y: auto;
}
.title-bg-deco {
  position: absolute;
  inset: 0;
  background:
    radial-gradient(ellipse at 50% 30%, rgba(255,107,138,0.08) 0%, transparent 60%),
    radial-gradient(ellipse at 80% 80%, rgba(180,80,110,0.06) 0%, transparent 50%);
  pointer-events: none;
}
.title-wrap {
  position: relative;
  z-index: 1;
  justify-content: flex-start;
  padding-top: 40px;
  padding-bottom: 24px;
  gap: 10px;
}
.dev-section {
  width: 100%;
  margin-top: 16px;
  border: 1px dashed var(--border);
  border-radius: 10px;
  padding: 12px;
  background: rgba(255,255,255,0.02);
}
.dev-label {
  font-size: 11px;
  color: var(--text-muted);
  margin-bottom: 8px;
  text-align: center;
}
.dev-buttons {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

/* ============================================================
   Buttons
   ============================================================ */
.btn-primary {
  background: linear-gradient(135deg, var(--accent-dark), var(--accent));
  color: #fff;
  font-size: 15px;
  font-weight: 700;
  letter-spacing: 0.05em;
  padding: 13px 28px;
  border-radius: 30px;
  box-shadow: 0 4px 20px var(--accent-glow);
  transition: transform 0.12s ease, box-shadow 0.12s ease;
  width: 100%;
  max-width: 280px;
}
.btn-primary:active { transform: scale(0.96); box-shadow: 0 2px 10px var(--accent-glow); }

.btn-large { font-size: 17px; padding: 16px 32px; }

.btn-dev {
  background: var(--bg-card2);
  color: var(--text-secondary);
  font-size: 12px;
  padding: 8px 10px;
  border-radius: 8px;
  border: 1px solid var(--border);
  transition: background 0.12s;
}
.btn-dev:active { background: #333; }
.btn-danger { color: #ff6060; border-color: #ff6060; }

.btn-small {
  background: var(--bg-card2);
  color: var(--text-secondary);
  font-size: 12px;
  padding: 6px 12px;
  border-radius: 6px;
  border: 1px solid var(--border);
  white-space: nowrap;
}

/* ============================================================
   Play Screen — Viewfinder
   ============================================================ */
#screen-play {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
}

#viewfinder {
  flex: 1;
  position: relative;
  overflow: hidden;
  background: #000;
  min-height: 0;
}

/* Camera video layer */
#camera-video {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  z-index: 2;
  display: none;
  background: #000;
}
#viewfinder.cam-active #camera-video { display: block; }
#viewfinder.cam-active #bg-layer { display: none; }

/* Background image layer */
#bg-layer {
  position: absolute;
  inset: 0;
  background-size: cover;
  background-position: center;
  background-repeat: no-repeat;
  z-index: 1;
}

/* Decorative frame overlay */
#overlay-frame {
  position: absolute;
  inset: 0;
  background-size: cover;
  background-position: center;
  background-repeat: no-repeat;
  pointer-events: none;
  z-index: 3;
}

/* Countdown number overlay */
#countdown-overlay {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 4;
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.15s ease;
}
#countdown-img {
  width: 38%;
  height: auto;
  filter: drop-shadow(0 0 24px rgba(255,255,255,0.9))
          drop-shadow(0 0 8px rgba(0,0,0,0.6));
}
#countdown-img.pop {
  animation: numPop 0.35s cubic-bezier(0.175, 0.885, 0.32, 1.275) forwards;
}
@keyframes numPop {
  from { transform: scale(1.7) rotate(-8deg); opacity: 0; }
  to   { transform: scale(1)   rotate(0deg);  opacity: 1; }
}

/* Flash overlay */
#flash-overlay {
  position: absolute;
  inset: 0;
  background: #ffffff;
  z-index: 5;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.25s ease;
}
#flash-overlay.flashing { opacity: 1; transition: none; }

/* ============================================================
   Seek Bar
   ============================================================ */
#seek-bar-row {
  flex-shrink: 0;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 4px 12px;
  background: rgba(10,10,10,0.95);
  border-top: 1px solid var(--border);
}

#seek-time-current,
#seek-time-duration {
  font-size: 11px;
  font-weight: 600;
  color: var(--text-muted);
  letter-spacing: 0.03em;
  min-width: 36px;
  text-align: center;
  flex-shrink: 0;
}

#seek-bar {
  flex: 1;
  -webkit-appearance: none;
  appearance: none;
  height: 4px;
  border-radius: 2px;
  background: var(--bg-card2);
  outline: none;
  cursor: pointer;
}
#seek-bar::-webkit-slider-runnable-track {
  height: 4px;
  border-radius: 2px;
  background: var(--bg-card2);
}
#seek-bar::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: var(--accent);
  box-shadow: 0 1px 4px var(--accent-glow);
  margin-top: -5px;
}
#seek-bar::-moz-range-track {
  height: 4px;
  border-radius: 2px;
  background: var(--bg-card2);
}
#seek-bar::-moz-range-thumb {
  width: 14px;
  height: 14px;
  border: none;
  border-radius: 50%;
  background: var(--accent);
  box-shadow: 0 1px 4px var(--accent-glow);
}

/* ============================================================
   Scene Jump Row
   ============================================================ */
#scene-jump-row {
  flex-shrink: 0;
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  padding: 8px 12px;
  background: rgba(10,10,10,0.95);
  border-top: 1px solid var(--border);
}

.scene-jump-btn {
  flex: 1 1 auto;
  padding: 8px 6px;
  font-size: 12px;
  font-weight: 600;
  color: var(--text-muted);
  background: var(--bg-card2);
  border: 1px solid var(--border);
  border-radius: 8px;
  white-space: nowrap;
  transition: background 0.1s, color 0.1s, transform 0.1s;
}
.scene-jump-btn:active { transform: scale(0.95); }
.scene-jump-btn.active {
  background: var(--accent-dark);
  color: #fff;
  border-color: var(--accent);
}

/* ============================================================
   Controls Bar
   ============================================================ */
#controls-bar {
  height: var(--ctrl-h);
  flex-shrink: 0;
  background: rgba(10,10,10,0.95);
  border-top: 1px solid var(--border);
  display: flex;
  align-items: center;
  padding: 0 12px;
  gap: 10px;
}

#track-name {
  flex: 1;
  font-size: 13px;
  font-weight: 600;
  color: var(--accent);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  letter-spacing: 0.04em;
}

.ctrl-right { display: flex; gap: 8px; }

.ctrl-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 8px;
  font-size: 18px;
  transition: background 0.1s, transform 0.1s;
}
.ctrl-btn:active { transform: scale(0.88); }

.ctrl-main {
  width: 44px;
  height: 44px;
  background: var(--accent);
  color: #fff;
  font-size: 18px;
  border-radius: 50%;
  box-shadow: 0 2px 10px var(--accent-glow);
}
.ctrl-main:active { background: var(--accent-dark); }

.ctrl-debug {
  min-width: 38px;
  height: 38px;
  padding: 0 8px;
  background: var(--bg-card2);
  color: var(--text-muted);
  border: 1px solid var(--border);
  font-size: 13px;
  font-weight: 700;
  border-radius: 8px;
}
.ctrl-debug.active {
  background: var(--accent-dark);
  color: #fff;
  border-color: var(--accent);
}

/* ============================================================
   Album Ready Overlay
   ============================================================ */
#album-ready-overlay {
  position: absolute;
  inset: 0;
  background: rgba(0,0,0,0.88);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 50;
  backdrop-filter: blur(4px);
}
.album-ready-card {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
  padding: 32px 24px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 20px;
  text-align: center;
  box-shadow: 0 20px 60px rgba(0,0,0,0.6);
  width: 80%;
  max-width: 300px;
}
.album-ready-icon  { font-size: 48px; }
.album-ready-title { font-size: 22px; font-weight: 700; color: var(--accent); }
.album-ready-sub   { font-size: 13px; color: var(--text-secondary); }

/* ============================================================
   Branch Selection Screen
   ============================================================ */
#screen-branch {
  background: var(--bg-phone);
  overflow-y: auto;
}
.branch-wrap {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 20px;
  gap: 16px;
}
.branch-photo-frame {
  width: 65%;
  aspect-ratio: 9/16;
  border: 2px solid var(--accent);
  border-radius: 8px;
  overflow: hidden;
  box-shadow: 0 0 30px var(--accent-glow);
}
.branch-photo-frame img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}
.branch-title    { font-size: 19px; font-weight: 700; color: var(--text-primary); }
.branch-subtitle { font-size: 13px; color: var(--text-secondary); margin-top: -6px; }

.branch-buttons { display: flex; flex-direction: column; gap: 12px; width: 100%; max-width: 280px; }
.btn-branch {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  padding: 16px;
  border-radius: 14px;
  font-size: 17px;
  font-weight: 700;
  letter-spacing: 0.06em;
  transition: transform 0.12s, box-shadow 0.12s;
}
.btn-branch:active { transform: scale(0.97); }
.branch-icon { font-size: 22px; }
.btn-yes {
  background: linear-gradient(135deg, #cc3355, var(--accent));
  color: #fff;
  box-shadow: 0 4px 20px var(--accent-glow);
}
.btn-no {
  background: var(--bg-card2);
  color: var(--text-primary);
  border: 1px solid var(--border);
}

/* ============================================================
   Album Select Screen
   ============================================================ */
#screen-album {
  background: var(--bg-phone);
  display: flex;
  flex-direction: column;
}

#album-sel-header {
  flex-shrink: 0;
  height: 56px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 16px;
  background: rgba(0,0,0,0.5);
  border-bottom: 1px solid var(--border);
  backdrop-filter: blur(10px);
}

.album-sel-title {
  font-size: 17px;
  font-weight: 700;
  color: var(--accent);
  letter-spacing: 0.06em;
}

#album-sel-body {
  flex: 1;
  overflow-y: auto;
  padding: 16px 12px;
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 14px;
  align-content: start;
  -webkit-overflow-scrolling: touch;
}
#album-sel-body::-webkit-scrollbar { width: 4px; }
#album-sel-body::-webkit-scrollbar-thumb { background: var(--border); border-radius: 2px; }

.book-card {
  display: flex;
  flex-direction: column;
  gap: 8px;
  cursor: pointer;
  transition: transform 0.15s ease;
}
.book-card:active { transform: scale(0.96); }

.book-cover-wrap {
  position: relative;
  aspect-ratio: 9/16;
  border-radius: 8px;
  overflow: hidden;
  border: 1px solid var(--border);
  background: var(--bg-card2);
  transition: border-color 0.15s, box-shadow 0.15s;
}
.book-card:hover .book-cover-wrap {
  border-color: var(--accent);
  box-shadow: 0 4px 20px var(--accent-glow);
}

.book-cover-empty {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 6px;
  color: var(--text-muted);
}
.book-cover-empty-icon { font-size: 28px; opacity: 0.5; }
.book-cover-empty-text { font-size: 11px; }

.book-cover-photo {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: none;
}
.book-cover-photo.visible { display: block; }

.book-cover-logo {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: contain;
  display: none;
}
.book-cover-logo.visible { display: block; }

.book-info {
  display: flex;
  flex-direction: column;
  gap: 2px;
  padding: 0 2px;
}

.book-title-text {
  font-size: 12px;
  font-weight: 700;
  color: var(--text-primary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.book-count {
  font-size: 11px;
  color: var(--text-muted);
}

/* ============================================================
   Viewer Screen
   ============================================================ */
#screen-viewer {
  background: #000;
  display: flex;
  align-items: center;
  justify-content: center;
  position: absolute;
  inset: 0;
}

#viewer-photo {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: contain;
  display: block;
  max-width: none;
  opacity: 1;
  transition: opacity 0.15s ease;
}
#viewer-photo.fade { opacity: 0; }

#viewer-cover-wrap {
  position: absolute;
  inset: 0;
  z-index: 5;
  pointer-events: none;
}

#viewer-cover-logo {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: contain;
}

.viewer-tap {
  position: absolute;
  top: 0;
  bottom: 0;
  width: 40%;
  z-index: 10;
  cursor: pointer;
  /* Invisible but tappable */
  background: transparent;
}
#viewer-tap-prev { left: 0; }
#viewer-tap-next { right: 0; }

#viewer-topbar {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 52px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 14px;
  background: linear-gradient(to bottom, rgba(0,0,0,0.75) 0%, transparent 100%);
  z-index: 20;
}

#viewer-close {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: rgba(255,255,255,0.15);
  color: #fff;
  font-size: 16px;
  display: flex;
  align-items: center;
  justify-content: center;
  border: 1px solid rgba(255,255,255,0.25);
  transition: background 0.12s;
}
#viewer-close:active { background: rgba(255,255,255,0.3); }

#viewer-indicator {
  font-size: 13px;
  font-weight: 600;
  color: rgba(255,255,255,0.85);
  letter-spacing: 0.06em;
}

/* ============================================================
   Responsive helper — very narrow screens
   ============================================================ */
@media (max-height: 500px) {
  .title-wrap { padding-top: 16px; gap: 6px; }
  .app-logo { font-size: 36px; }
  .app-title-text { font-size: 20px; }
}
