/**
 * FAL Digital - Shared UI Components
 * 
 * Reusable component classes for cards, buttons, panels, and base hotspot styles.
 * These components use theme variables and can be extended by app-specific CSS.
 * 
 * COMPONENT STRUCTURE:
 * 
 * 1. CARDS & PANELS
 *    - .card, .panel: Base container styles
 *    - .card-semi: Semi-transparent with backdrop blur
 *    - .card-dark: Dark theme variant
 * 
 * 2. BUTTONS
 *    - .btn: Base button class
 *    - .btn-primary: Primary action (blue, filled)
 *    - .btn-secondary: Secondary action
 *    - .btn-ghost: Transparent with border (for back buttons)
 *    - .btn-icon: Square icon button (34×34px)
 *    - .btn-circle: Circular icon button (36×36px)
 * 
 * 3. APP HEADER
 *    - .app-header: Unified header used in viewer and games
 *    - .app-header-left: Logo + brand name + back button
 *    - .app-header-center: Title (book name or game name)
 *    - .app-header-right: Controls (navigation, toggles, settings)
 * 
 * USAGE:
 * - Import this file after theme.css and before app-specific CSS
 * - Use component classes in HTML: <button class="btn btn-primary">
 * - Extend with app-specific classes if needed
 */

/* ========================================
   CARD / PANEL COMPONENTS
   ======================================== */

.card,
.panel {
  background: var(--bg-panel);
  border: 1px solid var(--border-color-lightest);
  border-radius: var(--radius-4xl);
  box-shadow: var(--shadow-soft);
  padding: var(--spacing-3xl);
  display: flex;
  flex-direction: column;
}

.card {
  /* Card-specific: typically used for content containers */
  gap: var(--spacing-xl);
}

.panel {
  /* Panel-specific: typically used for overlays, sidebars, toolbars */
  gap: var(--spacing-3xl);
}

/* Card variants */
.card-semi {
  background: var(--bg-panel-semi);
  backdrop-filter: blur(6px);
}

.card-dark {
  background: var(--bg-dark-card);
  border-color: var(--border-color-white-light);
  box-shadow: var(--shadow-3xl);
}

/* ========================================
   BUTTON COMPONENTS
   ======================================== */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--spacing-md);
  padding: var(--spacing-lg) var(--spacing-2xl);
  border: 1px solid transparent;
  border-radius: var(--radius-md);
  font-size: var(--font-size-base);
  font-weight: var(--font-weight-medium);
  font-family: var(--font-family-base);
  cursor: pointer;
  transition: background var(--duration-normal) var(--ease-default),
              border-color var(--duration-normal) var(--ease-default),
              color var(--duration-normal) var(--ease-default),
              transform var(--duration-fast) var(--ease-default),
              box-shadow var(--duration-fast) var(--ease-default);
  text-decoration: none;
  line-height: 1;
}

/* Button variants */
.btn-primary {
  background: var(--color-accent);
  color: var(--color-white);
  border-color: var(--color-accent);
}

.btn-primary:hover {
  background: var(--color-accent-dark);
  border-color: var(--color-accent-dark);
  box-shadow: var(--shadow-sm);
}

.btn-secondary {
  background: var(--color-accent-secondary);
  color: var(--color-ink-dark);
  border-color: var(--color-accent-secondary);
}

.btn-secondary:hover {
  transform: translateY(-2px);
  box-shadow: var(--shadow-sm);
}

.btn-ghost {
  background: transparent;
  border: 1px solid var(--border-color-dark);
  border-radius: var(--radius-full);
  color: var(--color-ink);
  padding: var(--spacing-md) var(--spacing-2xl);
  text-decoration: none;
}

.btn-ghost:hover {
  background: var(--bg-muted-light);
  border-color: var(--border-color-darker);
  box-shadow: var(--shadow-sm);
  text-decoration: none;
}

/* Icon buttons (square) */
.btn-icon {
  width: 34px;
  height: 34px;
  padding: 0;
  border-radius: var(--radius-md);
  border: 1px solid var(--color-muted-light);
  background: var(--color-white);
  font-size: var(--font-size-xl);
  font-family: var(--font-family-base);
}

.btn-icon:hover {
  background: var(--bg-muted-light);
  box-shadow: var(--shadow-sm);
}

/* Circular icon buttons */
.btn-circle {
  width: 36px;
  height: 36px;
  padding: 0;
  border-radius: var(--radius-circle);
  border: 1px solid rgba(15, 23, 42, 0.25);
  background: var(--color-white);
  font-size: var(--font-size-xl);
  box-shadow: var(--shadow-xs);
}

.btn-circle:hover {
  background: #eff6ff;
  box-shadow: var(--shadow-sm);
}

/* Chip/toggle buttons */
.btn-chip {
  width: 34px;
  height: 34px;
  padding: 0;
  border-radius: var(--radius-lg);
  border: 1px solid var(--color-muted-light);
  background: var(--bg-muted-light);
  font-size: var(--font-size-base);
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.btn-chip[aria-pressed="true"] {
  background: var(--color-accent);
  color: var(--color-white);
  border-color: var(--color-accent);
}

/* Accent circular buttons (for replay, fit, etc.) */
.btn-accent-circle {
  width: 36px;
  height: 36px;
  padding: 0;
  border-radius: var(--radius-circle);
  border: 1px solid rgba(59, 130, 246, 0.4);
  background: #eff6ff;
  color: var(--color-accent-dark);
  font-size: 1.4rem;
  font-weight: var(--font-weight-semibold);
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.btn-accent-circle:hover {
  background: #dbeafe;
}

.btn-accent-circle[aria-pressed="true"] {
  background: var(--color-accent-dark);
  color: var(--color-muted-light);
  border-color: var(--color-accent-dark);
}

/* ========================================
   APP HEADER COMPONENT
   ======================================== */

.app-header {
  position: sticky;
  top: 0;
  z-index: 9998;
  height: 56px;
  background: linear-gradient(to bottom, rgba(15, 23, 42, 0.95), rgba(15, 23, 42, 0.85));
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  border-bottom: 1px solid rgba(148, 163, 184, 0.4);
  color: var(--color-text-light);
  position: relative;
}

.app-header-inner {
  display: flex;
  justify-content: space-between;
  align-items: center;
  height: 100%;
  padding: 0 var(--spacing-xl);
}

.app-header-left {
  display: flex;
  align-items: center;
  gap: var(--spacing-lg);
  font-weight: var(--font-weight-semibold);
  font-size: var(--font-size-lg);
  color: var(--color-text-light);
}

.app-header-logo {
  width: 32px;
  height: 32px;
  object-fit: contain;
  display: block;
}

.app-header-center {
  flex: 1;
  text-align: center;
  font-size: var(--font-size-base);
  font-weight: var(--font-weight-medium);
  color: var(--color-text-light);
}

.app-header-right {
  display: flex;
  align-items: center;
  gap: var(--spacing-md);
  flex-wrap: nowrap;
  overflow: hidden;
}

/* Mobile portrait mode adjustments */
@media (max-width: 600px) and (orientation: portrait) {
  /* Hide single/dual page button on mobile portrait */
  #replayBtn {
    display: none !important;
  }
  
  /* Hide fit buttons on mobile portrait */
  #fitWidthBtn,
  #fitHeightBtn {
    display: none !important;
  }
  
  /* Hide FAL Digital text and book title on mobile portrait */
  .app-header-left span,
  .app-header-center {
    display: none !important;
  }
  
  /* Change back button to arrow icon only (square style like btn-icon) */
  .app-header-left .btn-ghost,
  .app-header-left .game-back-link {
    padding: 0;
    width: 34px;
    height: 34px;
    min-width: 34px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border-radius: var(--radius-md);
    border: 1px solid var(--color-muted-light);
    background: rgba(255, 255, 255, 0.1);
    border-color: rgba(255, 255, 255, 0.2);
    color: var(--color-text-light);
    font-size: var(--font-size-xl);
    text-decoration: none;
    font-size: 0;
    line-height: 1;
  }
  
  .app-header-left .btn-ghost::before,
  .app-header-left .game-back-link::before {
    content: "←";
    font-size: var(--font-size-xl);
    display: inline-block;
  }
  
  .app-header-left .btn-ghost:hover,
  .app-header-left .game-back-link:hover {
    background: rgba(255, 255, 255, 0.2);
    border-color: rgba(255, 255, 255, 0.3);
  }
  
  /* Reduce gap in header left on mobile */
  .app-header-left {
    gap: var(--spacing-md);
  }
  
  /* Ensure header doesn't overflow */
  .app-header-inner {
    padding: 0 var(--spacing-md);
    min-width: 0;
  }
  
  .app-header-right {
    gap: var(--spacing-sm);
    flex-shrink: 1;
  }
  
  /* Hide logo on very small screens if needed */
  @media (max-width: 400px) {
    .app-header-logo {
      display: none;
    }
  }
}

/* App header button variants (for dark header) */
.app-header .btn-icon,
.app-header .btn-circle {
  background: rgba(255, 255, 255, 0.1);
  border-color: rgba(255, 255, 255, 0.2);
  color: var(--color-text-light);
}

.app-header .btn-icon:hover,
.app-header .btn-circle:hover {
  background: rgba(255, 255, 255, 0.2);
  border-color: rgba(255, 255, 255, 0.3);
}

.app-header .btn-ghost {
  background: transparent;
  border-color: rgba(255, 255, 255, 0.3);
  color: var(--color-text-light);
  text-decoration: none;
}

.app-header .btn-ghost:hover {
  background: rgba(255, 255, 255, 0.1);
  border-color: rgba(255, 255, 255, 0.4);
  text-decoration: none;
}

.app-header .btn-primary {
  background: var(--color-accent);
  border-color: var(--color-accent);
  color: var(--color-white);
}

.app-header .btn-primary:hover {
  background: var(--color-accent-light);
  border-color: var(--color-accent-light);
}

/* App header select dropdown */
.app-header-select {
  padding: var(--spacing-sm) var(--spacing-lg);
  border: 1px solid rgba(255, 255, 255, 0.2);
  border-radius: var(--radius-lg);
  background: rgba(255, 255, 255, 0.1);
  color: var(--color-text-light);
  font-size: var(--font-size-sm);
  font-weight: var(--font-weight-medium);
  cursor: pointer;
  transition: background var(--duration-normal) var(--ease-default),
              border-color var(--duration-normal) var(--ease-default);
  min-width: 120px;
  max-width: 200px;
}

.app-header-select:hover {
  background: rgba(255, 255, 255, 0.15);
  border-color: rgba(255, 255, 255, 0.3);
}

.app-header-select:focus {
  outline: 2px solid rgba(59, 130, 246, 0.5);
  outline-offset: 2px;
}

.app-header-select option {
  background: var(--bg-dark-alt);
  color: var(--color-text-light);
}

/* Mobile responsive */
@media (max-width: 768px) {
  .app-header {
    height: 48px;
  }
  
  .app-header-inner {
    padding: 0 var(--spacing-lg);
  }
  
  .app-header-left {
    font-size: var(--font-size-base);
  }
  
  .app-header-center {
    font-size: var(--font-size-sm);
  }
}

/* ========================================
   BADGE / CHIP COMPONENTS
   ======================================== */

.badge {
  display: inline-flex;
  align-items: center;
  gap: var(--spacing-xs);
  padding: var(--spacing-xs) var(--spacing-xl);
  border: 1px dashed var(--border-color-dashed);
  border-radius: var(--radius-full);
  font-size: var(--font-size-sm);
  color: var(--color-ink-dark);
  background: rgba(15, 23, 42, 0.05);
}

.badge-active {
  background: var(--color-accent-dark);
  color: var(--color-muted-light);
  border-color: var(--color-accent-dark);
  border-style: solid;
}

/* ========================================
   BASE HOTSPOT STYLES
   ======================================== */

.hotspot-base {
  position: absolute;
  top: calc(var(--y, 0) * 1%);
  left: calc(var(--x, 0) * 1%);
  width: calc(var(--w, 0) * 1%);
  height: calc(var(--h, 0) * 1%);
  transform: translate(-50%, -50%) rotate(var(--rotation, 0deg));
  transform-origin: center;
  border-radius: var(--radius-lg);
  border: 0;
  cursor: pointer;
  background: var(--color-accent-soft);
  transition: background var(--duration-slow) var(--ease-default),
              outline var(--duration-slow) var(--ease-default);
}

.hotspot-base:hover {
  background: rgba(37, 99, 235, 0.25);
  outline: 1px solid rgba(37, 99, 235, 0.35);
}

.hotspot-base:focus-visible {
  outline: 3px solid var(--color-accent);
  outline-offset: 2px;
  border-radius: var(--radius-lg);
}

/* Hotspot shape variants */
.hotspot-base.shape-ellipse,
.hotspot-base.shape-pill {
  border-radius: var(--radius-full);
}

.hotspot-base.shape-circle {
  border-radius: var(--radius-circle);
}

.hotspot-base.shape-rect {
  border-radius: var(--radius-xs);
}

.hotspot-base.shape-diamond {
  border-radius: var(--radius-md);
  transform: translate(-50%, -50%) rotate(calc(45deg + var(--rotation, 0deg)));
}

.hotspot-base.shape-triangle,
.hotspot-base.shape-polygon {
  background: transparent;
  border: none;
}

