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

:root {
  --keyboard-height: 0px;
}

html, body {
  width: 100%;
  height: 100%;
  min-height: 100vh;
  min-height: -webkit-fill-available;
  overflow: hidden;
  background: #000;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  color: #fff;
}

#app {
  position: relative;
  width: 100%;
  height: 100%;
}

/* ===== Camera & Canvas Layers ===== */
#camera-feed {
  position: fixed;
  top: 0;
  left: 0;
  width: 100vw;
  height: 100vh;
  min-width: 100vw;
  min-height: 100vh;
  object-fit: cover;
  z-index: 0;
  background: #000;
}

#ar-canvas {
  position: fixed;
  top: 0;
  left: 0;
  width: 100vw;
  height: 100vh;
  min-width: 100vw;
  min-height: 100vh;
  z-index: 1;
  pointer-events: none;
}

/* ===== UI Layer ===== */
#ui-layer {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  z-index: 6;
  pointer-events: none;
}

#ui-layer > * {
  pointer-events: auto;
}

.hidden {
  display: none !important;
}

/* ===== Status Badge ===== */
#status-badge {
  position: absolute;
  top: max(12px, env(safe-area-inset-top));
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 16px;
  background: rgba(255, 255, 255, 0.92);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border-radius: 9999px;
  font-size: 13px;
  font-weight: 600;
  color: #1A1A1A;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.08);
  transition: opacity 0.3s ease;
}

#status-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #F59E0B;
  animation: pulse 1.5s ease-in-out infinite;
}

#status-badge.tracking #status-dot {
  background: #22C55E;
  animation: none;
}

#status-badge.lost #status-dot {
  background: #EF4444;
  animation: pulse 0.8s ease-in-out infinite;
}

@keyframes pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.4; }
}

/* ===== Pin Grid ===== */
#pin-grid {
  position: absolute;
  transform: translate(-50%, -50%);
  pointer-events: none;
  z-index: 3;
}

.pin-grid-inner {
  display: grid;
  grid-template-columns: repeat(9, 1fr);
  grid-template-rows: repeat(9, 1fr);
  gap: 6px;
  width: 102px;
  height: 102px;
}

.pin-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.15);
  transition: background 0.15s ease;
  animation: dotPulse 1.6s ease-in-out infinite;
}

@keyframes dotPulse {
  0%, 100% { background: rgba(255, 255, 255, 0.15); }
  50% { background: rgba(255, 255, 255, 0.9); }
}

/* ===== Controls ===== */
#controls {
  position: absolute;
  bottom: max(20px, env(safe-area-inset-bottom) + 8px);
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  gap: 16px;
  z-index: 4;
}

/* Hide the bottom controls while the virtual keyboard is open. */
.keyboard-open #controls {
  display: none;
}

.control-btn {
  width: 64px;
  height: 64px;
  border-radius: 50%;
  border: none;
  background: rgba(255, 255, 255, 0.92);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  color: #1A1A1A;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.1);
  transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
  -webkit-appearance: none;
  appearance: none;
}

.control-btn:active {
  transform: scale(0.92);
  background: #FFFFFF;
}

.control-btn.recording {
  background: #EF4444;
  color: #FFFFFF;
  box-shadow: 0 0 0 0 rgba(239, 68, 68, 0.4);
  animation: recording-pulse 1.5s ease-in-out infinite;
}

.control-btn.active {
  background: #DCFCE7;
  color: #16A34A;
}

@keyframes recording-pulse {
  0%, 100% { box-shadow: 0 0 0 0 rgba(239, 68, 68, 0.4); }
  50% { box-shadow: 0 0 0 12px rgba(239, 68, 68, 0); }
}

/* ===== Text Input Panel ===== */
#text-input-panel {
  position: fixed;
  bottom: calc(var(--keyboard-height, 0px) + env(safe-area-inset-bottom));
  left: 16px;
  right: 16px;
  display: flex;
  gap: 10px;
  padding: 8px 12px;
  background: rgba(255, 255, 255, 0.9);
  backdrop-filter: blur(16px);
  border-radius: 16px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.12);
  z-index: 100;
}

#text-input {
  flex: 1;
  padding: 12px 16px;
  border: 1.5px solid #E5E7EB;
  border-radius: 12px;
  background: #FFFFFF;
  color: #1A1A1A;
  font-size: 15px;
  outline: none;
  transition: border-color 0.2s ease;
}

#text-input:focus {
  border-color: #22C55E;
}

#text-input::placeholder {
  color: #9CA3AF;
}

.send-btn {
  padding: 12px 20px;
  border: none;
  border-radius: 12px;
  background: linear-gradient(135deg, #22C55E 0%, #16A34A 100%);
  color: #FFFFFF;
  font-size: 14px;
  font-weight: 700;
  cursor: pointer;
  transition: all 0.2s ease;
  -webkit-appearance: none;
  appearance: none;
}

.send-btn:active {
  transform: scale(0.95);
}

/* ===== Speech Indicator ===== */
#speech-indicator {
  position: fixed;
  bottom: max(100px, env(safe-area-inset-bottom) + 84px);
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
  padding: 20px 36px;
  background: rgba(255, 255, 255, 0.95);
  backdrop-filter: blur(16px);
  border-radius: 20px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.12);
  z-index: 10;
}

#speech-indicator p {
  color: #1A1A1A;
  font-size: 14px;
  font-weight: 600;
  letter-spacing: 0.2px;
  margin: 0;
}

.wave {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 4px;
  height: 32px;
}

.wave span {
  width: 4px;
  height: 16px;
  background: #22C55E;
  border-radius: 2px;
  animation: wave 1s ease-in-out infinite;
}

.wave span:nth-child(1) { animation-delay: 0s; }
.wave span:nth-child(2) { animation-delay: 0.1s; }
.wave span:nth-child(3) { animation-delay: 0.2s; }
.wave span:nth-child(4) { animation-delay: 0.3s; }
.wave span:nth-child(5) { animation-delay: 0.4s; }

@keyframes wave {
  0%, 100% { transform: scaleY(0.5); opacity: 0.5; }
  50% { transform: scaleY(1.2); opacity: 1; }
}

/* ===== Response Bubble ===== */
#response-bubble {
  position: absolute;
  top: max(60px, env(safe-area-inset-top) + 44px);
  left: 16px;
  right: 16px;
  padding: 18px 22px;
  background: rgba(255, 255, 255, 0.95);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  border-radius: 20px;
  color: #1A1A1A;
  font-size: 15px;
  line-height: 1.55;
  font-weight: 400;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.12);
  animation: slideDown 0.35s cubic-bezier(0.4, 0, 0.2, 1);
  z-index: 4;
  cursor: pointer;
}

#response-bubble.held::after {
  content: '🔊 Reading aloud...';
  display: block;
  margin-top: 10px;
  font-size: 11px;
  font-weight: 600;
  color: #22C55E;
  text-align: center;
  letter-spacing: 0.2px;
}

#response-text {
  margin: 0;
}

@keyframes slideDown {
  from { opacity: 0; transform: translateY(-10px); }
  to { opacity: 1; transform: translateY(0); }
}



/* ===== Pin Locking Indicator ===== */
#pin-locking {
  position: absolute;
  left: 50%;
  bottom: max(120px, env(safe-area-inset-bottom) + 100px);
  transform: translateX(-50%);
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 20px;
  border-radius: 9999px;
  background: rgba(255, 255, 255, 0.95);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  color: #1A1A1A;
  font-size: 14px;
  font-weight: 600;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.1);
  z-index: 3;
  pointer-events: none;
}

.pin-locking-spinner {
  width: 16px;
  height: 16px;
  border: 2px solid #E5E7EB;
  border-top-color: #22C55E;
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

/* ===== Pin Button ===== */
#pin-btn {
  position: absolute;
  left: 50%;
  bottom: max(120px, env(safe-area-inset-bottom) + 100px);
  transform: translateX(-50%);
  padding: 12px 24px;
  border-radius: 9999px;
  border: 1.5px solid #E5E7EB;
  background: rgba(255, 255, 255, 0.95);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  color: #1A1A1A;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.1);
  transition: all 0.2s ease;
  z-index: 3;
  -webkit-appearance: none;
  appearance: none;
}

#pin-btn::before {
  content: '📍 ';
}

#pin-btn:active {
  transform: translateX(-50%) scale(0.96);
  background: #FFFFFF;
  border-color: #22C55E;
  color: #16A34A;
}

/* ===== Permission Overlay ===== */
#permission-overlay {
  position: fixed;
  inset: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  background: #F0F4F1;
  transition: opacity 0.5s ease;
}

#permission-overlay.hidden {
  opacity: 0;
  pointer-events: none;
}

.permission-card {
  width: 100%;
  max-width: 340px;
  padding: 36px 28px 28px;
  background: #FFFFFF;
  border-radius: 24px;
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.08);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 20px;
  text-align: center;
}

.permission-card h1 {
  font-size: 28px;
  font-weight: 800;
  color: #1A1A1A;
  letter-spacing: -0.3px;
  margin: 0;
}

.permission-card > p {
  font-size: 15px;
  color: #6B7280;
  line-height: 1.5;
  margin: 0;
}

.permission-lead {
  font-size: 16px;
  color: #6B7280;
  line-height: 1.5;
  margin: 0;
}

.start-btn {
  width: 100%;
  padding: 16px 24px;
  border: none;
  border-radius: 9999px;
  background: linear-gradient(135deg, #22C55E 0%, #16A34A 100%);
  color: #FFFFFF;
  font-size: 17px;
  font-weight: 700;
  cursor: pointer;
  box-shadow: 0 4px 16px rgba(34, 197, 94, 0.3);
  transition: all 0.2s ease;
  -webkit-appearance: none;
  appearance: none;
}

.start-btn:active {
  transform: scale(0.97);
  box-shadow: 0 2px 10px rgba(34, 197, 94, 0.25);
}

.permission-note {
  font-size: 12px;
  color: #9CA3AF;
  text-align: center;
  margin: 0;
}

.permission-note.permission-error {
  color: #EF4444;
}

/* ===== Touch Fallback Target Layer ===== */
#app.tap-active::after {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  z-index: 4;
  pointer-events: none;
  background: radial-gradient(circle at center, rgba(34, 197, 94, 0.08) 0%, transparent 70%);
  animation: tap-pulse 2s ease-in-out infinite;
}

@keyframes tap-pulse {
  0%, 100% { opacity: 0.4; }
  50% { opacity: 0.8; }
}

.tap-target-layer {
  touch-action: manipulation;
}

/* ===== Loading Overlay ===== */
#loading-overlay {
  position: fixed;
  inset: 0;
  z-index: 11;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  background: #F0F4F1;
  transition: opacity 0.4s ease;
}

#loading-overlay.hidden {
  opacity: 0;
  pointer-events: none;
}

.loading-tree {
  font-size: 48px;
  margin-bottom: 24px;
  animation: mascotBounce 2s ease-in-out infinite;
}

@keyframes mascotBounce {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(-6px); }
}

.loading-progress {
  width: 100%;
  max-width: 240px;
  margin: 0 auto 16px;
}

.loading-progress-track {
  width: 100%;
  height: 6px;
  background: #E5E7EB;
  border-radius: 9999px;
  overflow: hidden;
}

.loading-progress-fill {
  height: 100%;
  background: linear-gradient(90deg, #22C55E, #16A34A);
  border-radius: 9999px;
  transition: width 0.4s ease;
}

.loading-step {
  font-size: 14px;
  color: #6B7280;
  font-weight: 500;
  min-height: 24px;
}

/* ============================================
   Edu-Game Redesign — New Styles
   ============================================ */

/* Portrait hint */
.portrait-hint {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 10px 14px;
  background: #F3F4F6;
  border-radius: 12px;
  font-size: 13px;
  color: #6B7280;
  width: 100%;
}

/* Permission status */
.permission-status {
  display: flex;
  justify-content: center;
  gap: 16px;
}

.perm-item {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 13px;
  color: #6B7280;
  font-weight: 500;
}

.perm-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #D1D5DB;
}

.perm-item.granted .perm-dot { background: #22C55E; }
.perm-item.denied .perm-dot { background: #EF4444; }
.perm-item.prompt .perm-dot { background: #F59E0B; }

/* Landscape overlay */
#landscape-overlay {
  position: fixed;
  inset: 0;
  background: rgba(240, 244, 241, 0.97);
  backdrop-filter: blur(8px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 200;
  transition: opacity 0.25s ease;
}

#landscape-overlay.hidden {
  opacity: 0;
  pointer-events: none;
}

.landscape-card {
  text-align: center;
  color: #1A1A1A;
  padding: 32px;
}

.landscape-card i {
  margin-bottom: 16px;
  color: #22C55E;
}

.landscape-card h2 {
  font-size: 22px;
  font-weight: 700;
  margin: 0 0 8px;
}

.landscape-card p {
  font-size: 15px;
  color: #6B7280;
  line-height: 1.5;
  margin: 0;
}

/* Log toggle */
.log-toggle {
  position: absolute;
  bottom: max(20px, env(safe-area-inset-bottom) + 8px);
  right: max(16px, env(safe-area-inset-right) + 8px);
  width: 48px;
  height: 48px;
  border-radius: 50%;
  border: none;
  background: rgba(255, 255, 255, 0.92);
  backdrop-filter: blur(12px);
  color: #22C55E;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.1);
  transition: all 0.2s ease;
  z-index: 4;
  -webkit-appearance: none;
  appearance: none;
}

.log-toggle:active {
  transform: scale(0.92);
  background: #FFFFFF;
}

.log-badge-count {
  position: absolute;
  top: -2px;
  right: -2px;
  min-width: 18px;
  height: 18px;
  padding: 0 5px;
  border-radius: 9999px;
  background: #EF4444;
  color: #FFFFFF;
  font-size: 10px;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
}

/* Bottom sheet */
.bottom-sheet {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 25;
  max-height: 80vh;
  background: #FFFFFF;
  border-radius: 24px 24px 0 0;
  box-shadow: 0 -8px 32px rgba(0, 0, 0, 0.1);
  transform: translateY(100%);
  transition: transform 0.35s cubic-bezier(0.4, 0, 0.2, 1);
  display: flex;
  flex-direction: column;
}

.bottom-sheet.open {
  transform: translateY(0);
}

.bottom-sheet-handle {
  padding: 12px 0 4px;
  display: flex;
  justify-content: center;
  cursor: grab;
}

.handle-bar {
  width: 36px;
  height: 4px;
  border-radius: 2px;
  background: rgba(0, 0, 0, 0.2);
}

.bottom-sheet-content {
  flex: 1;
  overflow-y: auto;
  padding: 8px 20px 32px;
  -webkit-overflow-scrolling: touch;
}

/* Log header */
.log-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 20px;
}

.log-header h2 {
  font-size: 22px;
  font-weight: 700;
  color: #1a1a1a;
  margin: 0;
}

/* Progress ring */
.progress-ring {
  position: relative;
  width: 52px;
  height: 52px;
}

.progress-ring svg {
  width: 100%;
  height: 100%;
  transform: rotate(-90deg);
}

.progress-ring-bg {
  fill: none;
  stroke: #e5e7eb;
  stroke-width: 3;
}

.progress-ring-fill {
  fill: none;
  stroke: #22c55e;
  stroke-width: 3;
  stroke-linecap: round;
  transition: stroke-dasharray 0.5s ease;
}

.progress-text {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  font-size: 12px;
  font-weight: 700;
  color: #374151;
}

/* Sections */
.log-section {
  margin-bottom: 24px;
}

.log-section h3 {
  font-size: 14px;
  font-weight: 600;
  color: #6b7280;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  margin: 0 0 12px;
}

/* Topics grid */
.topics-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 10px;
}

.topic-card {
  padding: 14px 12px;
  border-radius: 16px;
  background: #f3f4f6;
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  gap: 6px;
  transition: all 0.2s ease;
}

.topic-card.discovered {
  background: #ecfdf5;
  border: 1.5px solid #22c55e;
}

.topic-card.undiscovered {
  opacity: 0.5;
}

.topic-card .topic-icon {
  width: 32px;
  height: 32px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 10px;
  background: rgba(0, 0, 0, 0.06);
}

.topic-card.discovered .topic-icon {
  background: rgba(34, 197, 94, 0.12);
  color: #16a34a;
}

.topic-card .topic-name {
  font-size: 12px;
  font-weight: 600;
  color: #374151;
  line-height: 1.3;
}

.topic-card.undiscovered .topic-name {
  color: #9ca3af;
}

/* Badges grid */
.badges-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 12px;
}

.badge-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  gap: 6px;
}

.badge-item.locked {
  opacity: 0.35;
  filter: grayscale(1);
}

.badge-item .badge-icon-wrap {
  width: 56px;
  height: 56px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  background: #f3f4f6;
  border: 2px solid transparent;
  transition: all 0.2s ease;
}

.badge-item.unlocked .badge-icon-wrap {
  background: rgba(255, 255, 255, 0.9);
  border-color: currentColor;
  box-shadow: 0 2px 12px rgba(0, 0, 0, 0.08);
}

.badge-item .badge-name {
  font-size: 10px;
  font-weight: 600;
  color: #374151;
  line-height: 1.2;
}

/* Badge toast */
#badge-toast {
  position: absolute;
  top: max(160px, env(safe-area-inset-top) + 140px);
  left: 16px;
  right: 16px;
  z-index: 5;
  display: flex;
  justify-content: center;
  pointer-events: none;
  transform: translateY(-120%);
  opacity: 0;
  transition: all 0.5s cubic-bezier(0.34, 1.56, 0.64, 1);
}

#badge-toast.visible {
  transform: translateY(0);
  opacity: 1;
}

.badge-toast-content {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 16px 22px;
  background: #FFFFFF;
  border-radius: 20px;
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.12);
  pointer-events: auto;
}

.badge-toast-icon {
  width: 44px;
  height: 44px;
  border-radius: 14px;
  background: #DCFCE7;
  display: flex;
  align-items: center;
  justify-content: center;
  color: #16A34A;
  flex-shrink: 0;
}

.badge-toast-text {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.badge-toast-title {
  font-size: 12px;
  font-weight: 700;
  color: #22C55E;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  margin: 0;
}

.badge-toast-name {
  font-size: 15px;
  font-weight: 700;
  color: #1A1A1A;
  margin: 0;
}

/* ===== Home View ===== */
#home-view {
  position: fixed;
  inset: 0;
  z-index: 5;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  padding: 20px;
  padding-bottom: max(20px, env(safe-area-inset-bottom));
  background: #F0F4F1;
  overflow: hidden;
}

.home-content {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
}

.home-header {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  text-align: center;
}

.home-mascot {
  font-size: 80px;
  line-height: 1;
  animation: mascotBounce 2.5s ease-in-out infinite;
}

@keyframes mascotBounce {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(-8px); }
}

.home-header h1 {
  font-size: 34px;
  font-weight: 800;
  color: #1A1A1A;
  letter-spacing: -0.5px;
  margin: 0;
}

.home-subtitle {
  font-size: 16px;
  color: #6B7280;
  font-weight: 400;
  margin: 0;
}

.home-bottom-bar {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 24px;
  padding: 12px 24px 16px;
}

.home-nav-btn {
  width: 56px;
  height: 56px;
  border-radius: 50%;
  border: none;
  background: #FFFFFF;
  color: #6B7280;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.08);
  transition: all 0.2s ease;
  -webkit-appearance: none;
  appearance: none;
}

.home-nav-btn:active:not(:disabled) {
  transform: scale(0.94);
  color: #22C55E;
}

.home-nav-btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.home-action-btn {
  width: 88px;
  height: 88px;
  border-radius: 50%;
  border: none;
  background: linear-gradient(135deg, #22C55E 0%, #16A34A 100%);
  color: #FFFFFF;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  box-shadow: 0 6px 24px rgba(34, 197, 94, 0.35);
  transition: all 0.2s ease;
  -webkit-appearance: none;
  appearance: none;
}

.home-action-btn:active {
  transform: scale(0.95);
  box-shadow: 0 4px 16px rgba(34, 197, 94, 0.3);
}

.home-action-icon {
  font-size: 40px;
  line-height: 1;
  filter: drop-shadow(0 2px 4px rgba(0, 0, 0, 0.15));
}

#home-view.hidden {
  display: none !important;
}

.diary-list {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.diary-card {
  background: #f8fafc;
  border: 1px solid #e2e8f0;
  border-radius: 14px;
  padding: 14px 16px;
}

.diary-card-header {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 6px;
  font-size: 12px;
  font-weight: 600;
  color: #15803d;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.diary-card-fact {
  font-size: 14px;
  line-height: 1.45;
  color: #1f2937;
}

/* Scan overlay */
.scan-panel {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  pointer-events: none;
}
.scan-panel.hidden { display: none; }

.scan-reticle {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  width: 64vw;
  height: 64vw;
  max-width: 300px;
  max-height: 300px;
  pointer-events: none;
}

.scan-reticle-ring,
.scan-reticle-track,
.scan-reticle-ticks,
.scan-reticle-inner,
.scan-reticle-center {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  border-radius: 50%;
}

/* Unused in the step-and-hold scan UI; keep the DOM elements for compatibility
   but hide them so the reticle is clean. */
.scan-reticle-overall,
.scan-reticle-milestone,
.scan-reticle-ghost,
.scan-reticle-ticks {
  display: none;
}

.scan-reticle-ring {
  width: 100%;
  height: 100%;
  border: 2px solid rgba(255, 255, 255, 0.35);
  animation: scan-pulse 2.2s ease-in-out infinite;
}
@keyframes scan-pulse {
  0%, 100% { transform: translate(-50%, -50%) scale(1); opacity: 0.55; }
  50% { transform: translate(-50%, -50%) scale(1.04); opacity: 0.9; }
}

.scan-reticle-track {
  width: 100%;
  height: 100%;
  background: conic-gradient(
    from 0deg,
    #7dd3c0 var(--scan-progress, 0deg),
    transparent var(--scan-progress, 0deg)
  );
  -webkit-mask: radial-gradient(circle, transparent 58%, black 59%);
  mask: radial-gradient(circle, transparent 58%, black 59%);
  opacity: 0.55;
  transition: background 0.25s ease-out;
}
.scan-reticle-track.flash {
  animation: reticle-flash 0.25s ease-out;
}
@keyframes reticle-flash {
  0% { opacity: 0.55; transform: translate(-50%, -50%) scale(1); }
  50% { opacity: 1; transform: translate(-50%, -50%) scale(1.06); }
  100% { opacity: 0.55; transform: translate(-50%, -50%) scale(1); }
}

.scan-reticle-overall {
  position: absolute;
  top: 50%; left: 50%;
  transform: translate(-50%, -50%);
  width: 100%; height: 100%;
  border-radius: 50%;
  background: conic-gradient(
    from 0deg,
    #7dd3c0 var(--scan-overall-progress, 0deg),
    transparent var(--scan-overall-progress, 0deg)
  );
  -webkit-mask: radial-gradient(circle, transparent 62%, black 63%);
  mask: radial-gradient(circle, transparent 62%, black 63%);
  opacity: 0.4;
  transition: background 0.25s ease-out;
  pointer-events: none;
}

.scan-reticle-milestone {
  position: absolute;
  top: 50%; left: 50%;
  transform: translate(-50%, -50%);
  width: 72%; height: 72%;
  border-radius: 50%;
  border: 2px solid rgba(125, 211, 192, 0.2);
  transition: border-color 0.15s ease, box-shadow 0.15s ease, border-width 0.15s ease;
  pointer-events: none;
}
.scan-reticle-milestone.near-capture {
  border-color: rgba(125, 211, 192, 0.9);
  box-shadow: 0 0 12px rgba(125, 211, 192, 0.3);
  border-width: 3px;
}

.scan-reticle-ghost {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  border-radius: 50%;
  width: 100%;
  height: 100%;
  background: conic-gradient(
    from 0deg,
    rgba(255, 255, 255, 0.35) 0deg,
    transparent 120deg
  );
  -webkit-mask: radial-gradient(circle, transparent 58%, black 59%);
  mask: radial-gradient(circle, transparent 58%, black 59%);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.3s ease;
}
.scan-reticle-ghost.active {
  opacity: 0.45;
  animation: ghost-arc 2.4s ease-in-out infinite;
}
@keyframes ghost-arc {
  0% { transform: translate(-50%, -50%) rotate(0deg); }
  50% { transform: translate(-50%, -50%) rotate(180deg); }
  100% { transform: translate(-50%, -50%) rotate(0deg); }
}

.scan-reticle-inner {
  width: 72%;
  height: 72%;
  border: 2px dashed rgba(255, 255, 255, 0.45);
  transition: opacity 0.2s ease, transform 0.2s ease;
}
.scan-reticle-inner.hold {
  border-color: #7dd3c0;
  background: rgba(125, 211, 192, 0.08);
  opacity: 1;
}
.scan-reticle-inner.pace-good { border-color: #7ee787; }
.scan-reticle-inner.pace-slow { border-color: #ffd166; }
.scan-reticle-inner.pace-fast { border-color: #ff6b6b; }

.scan-reticle-center {
  width: 6px;
  height: 6px;
  background: rgba(255, 255, 255, 0.7);
}

.scan-reticle-ticks {
  width: 100%;
  height: 100%;
}
.scan-reticle-tick {
  position: absolute;
  top: 50%;
  left: 50%;
  width: 4px;
  height: 10px;
  margin: -5px 0 0 -2px;
  border-radius: 2px;
  background: rgba(255, 255, 255, 0.5);
  transform-origin: 2px 50%;
  transition: background 0.2s ease;
}
.scan-reticle-tick.accepted {
  background: #7ee787;
}

.scan-hud {
  position: absolute;
  bottom: max(24px, env(safe-area-inset-bottom));
  left: 24px;
  right: 24px;
  text-align: center;
  color: #fff;
  text-shadow: 0 1px 3px rgba(0,0,0,0.5);
  pointer-events: none;
}
.scan-instruction {
  font-size: 18px;
  font-weight: 600;
  margin: 0 0 12px;
}
.scan-step-dots {
  display: flex;
  justify-content: center;
  gap: 10px;
  margin-bottom: 12px;
}
.scan-step-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.35);
  transition: background 0.2s ease, transform 0.2s ease;
}
.scan-step-dot.active {
  background: #7ee787;
  transform: scale(1.25);
}
.scan-progress-row {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  margin-bottom: 8px;
}
.scan-progress-track {
  width: 140px;
  height: 6px;
  background: rgba(255,255,255,0.25);
  border-radius: 3px;
  overflow: hidden;
}
.scan-progress-fill {
  width: 0%;
  height: 100%;
  background: #7dd3c0;
  border-radius: 3px;
  transition: width 0.25s ease-out;
}
.scan-counter {
  font-size: 14px;
  font-weight: 500;
  min-width: 52px;
  text-align: right;
}
.scan-status {
  font-size: 13px;
  opacity: 0.85;
  margin: 0;
}
.scan-error,
.scan-success {
  position: absolute;
  top: max(24px, env(safe-area-inset-top));
  left: 24px;
  right: 24px;
  padding: 14px 16px;
  border-radius: 12px;
  text-align: center;
  font-weight: 600;
  color: #fff;
  pointer-events: auto;
}
.scan-error { background: rgba(220, 60, 60, 0.92); }
.scan-success { background: rgba(40, 140, 100, 0.92); }
.scan-success-icon { margin-right: 8px; }

.scan-phase-title {
  position: absolute;
  top: max(24px, env(safe-area-inset-top));
  left: 50%;
  transform: translateX(-50%);
  margin: 0;
  font-size: 22px;
  font-weight: 700;
  color: #fff;
  text-shadow: 0 2px 4px rgba(0, 0, 0, 0.5);
  pointer-events: none;
}

.scan-quality {
  position: absolute;
  top: max(90px, calc(env(safe-area-inset-top) + 66px));
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  gap: 12px;
  pointer-events: none;
}
.scan-quality.hidden { display: none; }

.scan-quality-item {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 5px 10px;
  border-radius: 999px;
  background: rgba(0, 0, 0, 0.35);
  font-size: 12px;
  font-weight: 600;
  color: rgba(255, 255, 255, 0.7);
  transition: color 0.2s ease, background 0.2s ease;
}

.scan-quality-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.35);
  transition: background 0.2s ease;
}

.scan-quality-item.ok {
  color: #fff;
  background: rgba(40, 140, 100, 0.55);
}
.scan-quality-item.ok .scan-quality-dot { background: #7ee787; }

.scan-quality-item.warn {
  color: #fff;
  background: rgba(200, 160, 40, 0.55);
}
.scan-quality-item.warn .scan-quality-dot { background: #ffd166; }

.scan-quality-item.bad {
  color: #fff;
  background: rgba(200, 60, 60, 0.55);
}
.scan-quality-item.bad .scan-quality-dot { background: #ff6b6b; }

.scan-actions {
  position: absolute;
  bottom: max(24px, env(safe-area-inset-bottom));
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  gap: 12px;
  pointer-events: auto;
}
.scan-actions.hidden { display: none; }

.scan-action-btn {
  padding: 12px 24px;
  border: none;
  border-radius: 999px;
  background: #fff;
  color: #1a3a1a;
  font-size: 16px;
  font-weight: 700;
  cursor: pointer;
}

.scan-action-btn.secondary {
  background: rgba(255, 255, 255, 0.2);
  color: #fff;
}

/* ===== Login Overlay ===== */
#login-overlay {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(180deg, #0b1d10 0%, #06130a 100%);
  padding: 24px;
}

#login-overlay.hidden {
  display: none !important;
}

.login-card {
  width: 100%;
  max-width: 360px;
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
}

.login-mascot {
  font-size: 64px;
  line-height: 1;
  margin-bottom: 16px;
}

.login-title {
  font-size: 28px;
  font-weight: 700;
  margin-bottom: 6px;
}

.login-subtitle {
  font-size: 15px;
  color: rgba(255, 255, 255, 0.72);
  margin-bottom: 28px;
}

.login-form {
  width: 100%;
  display: flex;
  flex-direction: column;
  gap: 12px;
  text-align: left;
}

.login-label {
  font-size: 13px;
  font-weight: 600;
  color: rgba(255, 255, 255, 0.9);
  margin-left: 2px;
}

.login-input {
  width: 100%;
  padding: 14px 16px;
  border: 1px solid rgba(255, 255, 255, 0.2);
  border-radius: 12px;
  background: rgba(255, 255, 255, 0.08);
  color: #fff;
  font-size: 16px;
  outline: none;
  -webkit-appearance: none;
  appearance: none;
}

.login-input::placeholder {
  color: rgba(255, 255, 255, 0.4);
}

.login-input:focus {
  border-color: rgba(255, 255, 255, 0.5);
  background: rgba(255, 255, 255, 0.12);
}

.login-error {
  color: #fca5a5;
  font-size: 13px;
  margin: 4px 0;
  min-height: 18px;
}

.login-error.hidden {
  display: none;
}

.login-submit {
  width: 100%;
  padding: 16px;
  margin-top: 8px;
  border: none;
  border-radius: 12px;
  background: #fff;
  color: #0b1d10;
  font-size: 16px;
  font-weight: 700;
  cursor: pointer;
  -webkit-appearance: none;
  appearance: none;
}

.login-submit:active {
  transform: scale(0.98);
}

.login-submit:disabled {
  opacity: 0.6;
  cursor: not-allowed;
}
