/* MiloWow - Styles with Accessibility Features */
/* Inspired by MiloCam's sleek dark UI */

/* ============ CSS Variables ============ */
:root {
  /* Colors - High Contrast Dark Theme */
  --color-bg: #0f1115;
  --color-panel: #141a22;
  --color-surface: #1a2230;
  --color-surface-hover: #222a36;
  --color-btn: #222a36;
  --color-btn-hover: #2b3442;
  --color-border: rgba(255, 255, 255, 0.45);
  --color-border-soft: rgba(255, 255, 255, 0.30);

  --color-text: #e7e7e7;
  --color-text-muted: rgba(231, 231, 231, 0.8);
  --color-text-light: #ffffff;

  --color-primary: #6aa9ff;
  --color-primary-hover: #8ec0ff;
  --color-secondary: #3a4556;
  --color-secondary-hover: #4a5868;
  --color-success: #4ade80;
  --color-warning: #fbbf24;
  --color-danger: #f87171;
  --color-danger-hover: #fca5a5;

  /* Sizing */
  --ui-scale: 1;
  --text-scale: 1;
  --spacing-xs: calc(4px * var(--ui-scale));
  --spacing-sm: calc(8px * var(--ui-scale));
  --spacing-md: calc(16px * var(--ui-scale));
  --spacing-lg: calc(24px * var(--ui-scale));
  --spacing-xl: calc(32px * var(--ui-scale));

  --font-size-sm: calc(14px * var(--text-scale));
  --font-size-md: calc(16px * var(--text-scale));
  --font-size-lg: calc(20px * var(--text-scale));
  --font-size-xl: calc(24px * var(--text-scale));

  --border-radius: calc(10px * var(--ui-scale));
  --border-radius-lg: calc(12px * var(--ui-scale));

  /* Layout */
  --header-height: calc(60px * var(--ui-scale));
  --sidebar-width: 15%;
  --bottom-bar-height: calc(160px * var(--ui-scale));

  /* Transitions */
  --transition-fast: 150ms ease;
  --transition-normal: 250ms ease;
}

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

html, body {
  height: 100%;
  overflow: hidden;
}

body {
  /* Nunito - friendly rounded font, self-hosted */
  font-family: 'Nunito', -apple-system, 'Segoe UI', Roboto, sans-serif;
  font-size: var(--font-size-md);
  font-weight: 500;
  line-height: 1.5;
  color: var(--color-text);
  background-color: var(--color-bg);
  -webkit-tap-highlight-color: transparent;
  -webkit-touch-callout: none;
  user-select: none;
  letter-spacing: 0.02em;
}

#app {
  display: flex;
  flex-direction: column;
  height: 100%;
}

/* ============ Header & Tabs ============ */
.header {
  background: linear-gradient(180deg, var(--color-panel), rgba(20, 26, 34, 0.97));
  border-bottom: 1px solid var(--color-border-soft);
  height: var(--header-height);
  flex-shrink: 0;
}

.tabs {
  display: flex;
  height: 100%;
  justify-content: center;
  gap: var(--spacing-sm);
  padding: 0 var(--spacing-md);
}

.tab {
  display: flex;
  align-items: center;
  gap: var(--spacing-sm);
  padding: var(--spacing-sm) var(--spacing-lg);
  background: transparent;
  border: none;
  border-bottom: 3px solid transparent;
  color: var(--color-text-muted);
  font-size: var(--font-size-md);
  font-weight: 600;
  cursor: pointer;
  transition: all var(--transition-fast);
  min-width: calc(120px * var(--ui-scale));
}

.tab:hover {
  color: var(--color-text);
  background: var(--color-surface-hover);
}

.tab.active {
  color: var(--color-primary);
  border-bottom-color: var(--color-primary);
}

.tab-icon {
  font-size: var(--font-size-lg);
}

/* ============ Main Content ============ */
.main-content {
  flex: 1;
  overflow: hidden;
  position: relative;
}

.tab-content {
  display: none;
  height: 100%;
  overflow: hidden;
}

.tab-content.active {
  display: flex;
  flex-direction: column;
}

/* ============ Camera Tab ============ */
.camera-layout {
  display: flex;
  flex: 1;
  overflow: hidden;
}

.photo-sidebar {
  width: var(--sidebar-width);
  background: var(--color-panel);
  border-right: 1px solid var(--color-border-soft);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.sidebar-title {
  padding: var(--spacing-md);
  font-size: var(--font-size-lg);
  font-weight: 600;
  border-bottom: 1px solid var(--color-border-soft);
  flex-shrink: 0;
}

.photo-list {
  flex: 1;
  overflow-y: auto;
  padding: var(--spacing-sm);
  display: flex;
  flex-direction: column;
  gap: var(--spacing-sm);
}

.photo-item {
  position: relative;
  aspect-ratio: 4/3;
  border-radius: var(--border-radius);
  overflow: hidden;
  cursor: pointer;
  border: 1px solid var(--color-border);
  transition: all var(--transition-fast);
  flex-shrink: 0;
  background: var(--color-surface);
}

.photo-item:hover,
.photo-item:focus {
  border-color: var(--color-primary);
  outline: 2px solid var(--color-primary);
  transform: scale(1.02);
}

.photo-item img {
  width: 100%;
  height: 100%;
  object-fit: contain;
}

.photo-item .delete-btn {
  position: absolute;
  top: var(--spacing-xs);
  right: var(--spacing-xs);
  width: calc(28px * var(--ui-scale));
  height: calc(28px * var(--ui-scale));
  border-radius: var(--border-radius);
  background: var(--color-danger);
  color: var(--color-text-light);
  border: none;
  font-size: var(--font-size-md);
  cursor: pointer;
  opacity: 0;
  transition: opacity var(--transition-fast);
}

.photo-item:hover .delete-btn {
  opacity: 1;
}

.camera-main {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  background: #000;
  position: relative;
}

.camera-container {
  position: relative;
  width: 100%;
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
}

#video {
  max-width: 100%;
  max-height: 100%;
  object-fit: contain;
}

#detection-canvas {
  position: absolute;
  top: 50%;
  left: 50%;
  pointer-events: none;
  cursor: crosshair;
}

.camera-status {
  position: absolute;
  bottom: var(--spacing-lg);
  left: 50%;
  transform: translateX(-50%);
  background: rgba(0, 0, 0, 0.85);
  color: var(--color-text-light);
  padding: var(--spacing-sm) var(--spacing-md);
  border-radius: var(--border-radius);
  font-size: var(--font-size-sm);
  pointer-events: none;
  opacity: 0;
  transform: translateX(-50%) translateY(6px);
  transition: opacity 0.25s ease, transform 0.25s ease;
  min-width: 200px;
  text-align: center;
}

.camera-status.show {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

/* Loading state - pulsing animation */
.camera-status.loading {
  animation: status-pulse 1.5s ease-in-out infinite;
}

@keyframes status-pulse {
  0%, 100% { opacity: 0.8; }
  50% { opacity: 1; }
}

/* Ready state - green tint */
.camera-status.ready {
  background: rgba(74, 222, 128, 0.85);
  color: var(--color-bg);
}

/* Error state - red tint */
.camera-status.error {
  background: rgba(248, 113, 113, 0.9);
  color: var(--color-bg);
}

.mirror-btn {
  position: absolute;
  top: var(--spacing-md);
  right: var(--spacing-md);
  width: calc(44px * var(--ui-scale));
  height: calc(44px * var(--ui-scale));
  border-radius: var(--border-radius);
  background: var(--color-btn);
  color: var(--color-text);
  border: 1px solid var(--color-border);
  font-size: calc(20px * var(--ui-scale));
  cursor: pointer;
  transition: all var(--transition-fast);
  z-index: 10;
}

.mirror-btn:hover {
  background: var(--color-btn-hover);
}

.mirror-btn.active {
  outline: 2px solid var(--color-primary);
  background: var(--color-btn-hover);
}

/* Recent Pictos Bar */
.recent-pictos-bar {
  height: var(--bottom-bar-height);
  background: linear-gradient(180deg, rgba(20, 26, 34, 0.75), rgba(20, 26, 34, 0.97));
  border-top: 1px solid var(--color-border-soft);
  display: flex;
  flex-direction: row;
  flex-shrink: 0;
}

.bar-title {
  display: none;
}

.recent-pictos-scroll {
  flex: 1;
  overflow-x: auto;
  overflow-y: hidden;
  display: flex;
  gap: var(--spacing-sm);
  padding: var(--spacing-sm) var(--spacing-md);
  align-items: center;
}

.picto-item {
  flex-shrink: 0;
  width: calc(120px * var(--ui-scale));
  height: calc(140px * var(--ui-scale));
  border-radius: var(--border-radius);
  overflow: hidden;
  cursor: pointer;
  border: 1px solid var(--color-border);
  transition: all var(--transition-fast);
  background: var(--color-surface);
  position: relative;
  display: flex;
  flex-direction: column;
}

.picto-item:hover,
.picto-item:focus {
  border-color: var(--color-primary);
  outline: 2px solid var(--color-primary);
  transform: scale(1.05);
}

.picto-item img {
  width: 100%;
  flex: 1;
  min-height: 0; /* Allow image to shrink */
  object-fit: contain;
}

.picto-item .picto-label {
  flex-shrink: 0; /* Don't let the label shrink */
  background: rgba(0, 0, 0, 0.75);
  color: var(--color-text-light);
  font-size: clamp(8px, 1.5vw, calc(12px * var(--text-scale)));
  padding: 4px 2px;
  text-align: center;
  word-wrap: break-word;
  overflow-wrap: break-word;
  max-height: 35%;
  min-height: 20px; /* Ensure label is always visible */
  overflow: hidden;
  line-height: 1.2;
  display: flex;
  align-items: center;
  justify-content: center;
}

/* ============ Pictoboard Tab ============ */
#content-pictoboard {
  padding: var(--spacing-md);
  overflow: hidden;
}

#content-pictoboard.active {
  display: flex;
  flex-direction: column;
}

.pictoboard-header {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  padding: 6px;
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid var(--color-border-soft);
  border-radius: var(--border-radius-lg);
  margin-bottom: var(--spacing-md);
  flex-shrink: 0;
  align-items: center;
}

.pictoboard-grid {
  flex: 1;
  min-height: 0; /* Allow grid to shrink within flex container */
  display: grid;
  /* Columns and rows set dynamically by JS based on settings */
  grid-template-columns: repeat(10, 1fr);
  grid-template-rows: repeat(4, 1fr);
  gap: var(--spacing-xs);
  overflow: hidden; /* No scrolling - cells scale to fit */
  padding: var(--spacing-sm);
  background: var(--color-panel);
  border-radius: var(--border-radius-lg);
  border: 1px solid var(--color-border-soft);
}

.grid-cell {
  min-width: 0;
  min-height: 0;
  border-radius: var(--border-radius);
  overflow: hidden;
  cursor: pointer;
  border: 1px solid var(--color-border);
  transition: border-color 0.15s ease, outline 0.15s ease, box-shadow 0.15s ease;
  background: var(--color-surface);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  position: relative;
}

.grid-cell.empty {
  background: var(--color-surface-hover);
  border-style: dashed;
  border-color: var(--color-border);
  cursor: default;
}

.grid-cell.empty::before {
  content: '📷';
  font-size: calc(24px * var(--ui-scale));
  opacity: 0.2;
}

.grid-cell:not(.empty):hover,
.grid-cell:not(.empty):focus {
  border-color: var(--color-primary);
  outline: 2px solid var(--color-primary);
  outline-offset: -2px; /* Keep outline inside cell bounds */
}

.grid-cell.selected {
  border-color: var(--color-primary);
  outline: 3px solid var(--color-primary);
  outline-offset: -3px; /* Keep outline inside cell bounds */
  box-shadow: inset 0 0 0 2px rgba(106, 169, 255, 0.5);
}

.grid-cell img {
  width: 100%;
  flex: 1;
  min-height: 0; /* Allow image to shrink */
  object-fit: contain;
}

.grid-cell .cell-label {
  width: 100%;
  flex-shrink: 0;
  background: rgba(0, 0, 0, 0.75);
  color: var(--color-text-light);
  font-size: clamp(6px, 0.8vw, calc(10px * var(--text-scale)));
  padding: 2px;
  text-align: center;
  word-wrap: break-word;
  overflow-wrap: break-word;
  overflow: hidden;
  line-height: 1.1;
  white-space: nowrap;
  text-overflow: ellipsis;
}

/* Edit Controls - inline in header */
.edit-controls {
  display: flex;
  gap: 4px;
  align-items: center;
  margin-left: auto; /* Push to right side of header */
}

.edit-controls.hidden {
  display: none !important;
}

/* Page Navigation */
.page-nav {
  display: flex;
  align-items: center;
  gap: 4px;
  margin-left: auto;
}

.page-nav.hidden {
  display: none !important;
}

.page-indicator {
  font-size: var(--font-size-sm);
  color: var(--color-text-muted);
  min-width: 50px;
  text-align: center;
  font-variant-numeric: tabular-nums;
}

.arrow-btn {
  width: calc(36px * var(--ui-scale));
  height: calc(36px * var(--ui-scale));
  min-width: 36px;
  min-height: 36px;
  border-radius: var(--border-radius);
  background: var(--color-btn);
  color: var(--color-text);
  border: 1px solid var(--color-border);
  font-size: var(--font-size-base);
  cursor: pointer;
  transition: background var(--transition-fast);
  display: flex;
  align-items: center;
  justify-content: center;
}

.arrow-btn:hover {
  background: var(--color-btn-hover);
}

/* ============ Settings Tab ============ */
#content-settings {
  overflow-y: auto;
}

.settings-container {
  max-width: 600px;
  margin: 0 auto;
  padding: var(--spacing-lg);
}

.setting-group {
  background: var(--color-panel);
  border-radius: var(--border-radius-lg);
  padding: var(--spacing-lg);
  margin-bottom: var(--spacing-md);
  border: 1px solid var(--color-border-soft);
}

.setting-group.danger-zone {
  border-color: var(--color-danger);
}

.setting-label {
  display: block;
  font-size: var(--font-size-lg);
  font-weight: 600;
  margin-bottom: var(--spacing-xs);
}

.setting-desc {
  color: var(--color-text-muted);
  font-size: var(--font-size-sm);
  margin-bottom: var(--spacing-md);
}

.setting-control {
  display: flex;
  flex-direction: column;
  gap: var(--spacing-sm);
}

.setting-status {
  font-size: var(--font-size-sm);
  color: var(--color-text-muted);
}

/* Form Inputs */
.select-input,
.text-input,
.textarea-input {
  appearance: none;
  width: 100%;
  padding: var(--spacing-sm) var(--spacing-md);
  font-size: var(--font-size-md);
  border: 1px solid var(--color-border);
  border-radius: var(--border-radius);
  background: var(--color-btn);
  color: var(--color-text);
  transition: all var(--transition-fast);
  height: calc(36px * var(--ui-scale));
  line-height: 1;
}

.select-input:hover,
.text-input:hover,
.textarea-input:hover {
  background: var(--color-btn-hover);
}

.select-input:focus,
.text-input:focus,
.textarea-input:focus {
  outline: 2px solid var(--color-primary);
  border-color: var(--color-primary);
}

.textarea-input {
  resize: vertical;
  min-height: calc(80px * var(--ui-scale));
  height: auto;
}

input[type="range"] {
  appearance: none;
  width: 100%;
  height: calc(6px * var(--ui-scale));
  border-radius: calc(3px * var(--ui-scale));
  background: var(--color-surface-hover);
  outline: none;
  cursor: pointer;
  accent-color: var(--color-primary);
}

input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: calc(20px * var(--ui-scale));
  height: calc(20px * var(--ui-scale));
  border-radius: 50%;
  background: var(--color-primary);
  cursor: pointer;
  border: 2px solid var(--color-bg);
}

input[type="range"]::-moz-range-thumb {
  width: calc(20px * var(--ui-scale));
  height: calc(20px * var(--ui-scale));
  border-radius: 50%;
  background: var(--color-primary);
  cursor: pointer;
  border: 2px solid var(--color-bg);
}

input[type="number"] {
  appearance: none;
  width: calc(80px * var(--ui-scale));
  padding: var(--spacing-sm);
  font-size: var(--font-size-md);
  border: 1px solid var(--color-border);
  border-radius: var(--border-radius);
  background: var(--color-btn);
  color: var(--color-text);
  text-align: center;
}

input[type="number"]:focus {
  outline: 2px solid var(--color-primary);
}

.range-value {
  font-size: var(--font-size-sm);
  color: var(--color-text-muted);
  text-align: center;
  font-variant-numeric: tabular-nums;
}

.grid-size-control {
  flex-direction: row;
  align-items: center;
  justify-content: center;
}

.grid-input {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: var(--spacing-xs);
}

.grid-input label {
  font-size: var(--font-size-sm);
  color: var(--color-text-muted);
}

.grid-separator {
  font-size: var(--font-size-xl);
  color: var(--color-text-muted);
  margin: 0 var(--spacing-md);
}

/* Toggle Button */
.toggle-btn {
  appearance: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--spacing-sm);
  padding: var(--spacing-sm) var(--spacing-md);
  border: 1px solid var(--color-border);
  border-radius: var(--border-radius);
  background: var(--color-btn);
  color: var(--color-text);
  font-size: var(--font-size-md);
  cursor: pointer;
  transition: all var(--transition-fast);
  min-width: calc(150px * var(--ui-scale));
  height: calc(36px * var(--ui-scale));
  line-height: 1;
}

.toggle-btn:hover {
  background: var(--color-btn-hover);
}

.toggle-btn[aria-pressed="true"] {
  outline: 2px solid var(--color-primary);
  background: var(--color-btn-hover);
}

/* ============ Buttons ============ */
.btn {
  appearance: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--spacing-sm);
  padding: var(--spacing-sm) var(--spacing-md);
  font-size: var(--font-size-md);
  font-weight: 500;
  border: 1px solid var(--color-border);
  border-radius: var(--border-radius);
  background: var(--color-btn);
  color: var(--color-text);
  cursor: pointer;
  transition: all var(--transition-fast);
  min-height: calc(36px * var(--ui-scale));
  line-height: 1;
}

.btn:hover {
  background: var(--color-btn-hover);
}

.btn-primary {
  background: var(--color-primary);
  color: var(--color-bg);
  border-color: var(--color-primary);
}

.btn-primary:hover {
  background: var(--color-primary-hover);
  border-color: var(--color-primary-hover);
}

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

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

.btn-secondary:hover {
  background: var(--color-secondary-hover);
}

.btn-warning {
  background: var(--color-warning);
  color: var(--color-bg);
  border-color: var(--color-warning);
}

.btn-danger {
  background: var(--color-danger);
  color: var(--color-bg);
  border-color: var(--color-danger);
}

.btn-danger:hover {
  background: var(--color-danger-hover);
  border-color: var(--color-danger-hover);
}

.btn-small {
  padding: var(--spacing-xs) var(--spacing-sm);
  font-size: var(--font-size-sm);
  min-height: calc(32px * var(--ui-scale));
}

.btn.active {
  outline: 2px solid var(--color-primary);
}

/* Icon helper */
.icon {
  display: inline-block;
  width: 16px;
  height: 16px;
  text-align: center;
  line-height: 16px;
}

/* ============ Overlays ============ */
.overlay {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0, 0, 0, 0.8);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  padding: var(--spacing-lg);
}

.overlay.hidden {
  display: none;
}

/* Picto Wizard */
.wizard-container {
  background: var(--color-panel);
  border: 1px solid var(--color-border-soft);
  border-radius: var(--border-radius-lg);
  width: 100%;
  max-width: calc(600px * var(--ui-scale));
  max-height: 90vh;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  position: relative;
}

.wizard-close {
  position: absolute;
  top: var(--spacing-sm);
  right: var(--spacing-sm);
  width: calc(40px * var(--ui-scale));
  height: calc(40px * var(--ui-scale));
  border-radius: var(--border-radius);
  background: var(--color-btn);
  color: var(--color-text);
  border: 1px solid var(--color-border);
  font-size: var(--font-size-xl);
  cursor: pointer;
  z-index: 10;
  transition: all var(--transition-fast);
}

.wizard-close:hover {
  background: var(--color-btn-hover);
}

.wizard-title {
  padding: var(--spacing-lg);
  font-size: var(--font-size-xl);
  text-align: center;
  border-bottom: 1px solid var(--color-border-soft);
}

.wizard-content {
  flex: 1;
  overflow-y: auto;
  padding: var(--spacing-lg);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: var(--spacing-lg);
}

.wizard-image-container {
  width: 100%;
  max-width: calc(300px * var(--ui-scale));
  aspect-ratio: 4/3;
  border-radius: var(--border-radius);
  overflow: hidden;
  border: 1px solid var(--color-border);
  background: #000;
}

.wizard-image-container img {
  width: 100%;
  height: 100%;
  object-fit: contain;
}

.wizard-status {
  text-align: center;
  color: var(--color-text-muted);
  font-size: var(--font-size-md);
}

.wizard-words {
  display: flex;
  flex-wrap: wrap;
  gap: var(--spacing-sm);
  justify-content: center;
  width: 100%;
}

.word-btn {
  appearance: none;
  padding: var(--spacing-sm) var(--spacing-md);
  background: var(--color-btn);
  border: 1px solid var(--color-border);
  border-radius: var(--border-radius);
  font-size: var(--font-size-md);
  color: var(--color-text);
  cursor: pointer;
  transition: all var(--transition-fast);
}

.word-btn:hover {
  background: var(--color-btn-hover);
}

.word-btn.selected {
  outline: 2px solid var(--color-primary);
  background: var(--color-btn-hover);
}

.wizard-actions {
  display: inline-flex;
  gap: 6px;
  padding: 6px;
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid var(--color-border-soft);
  border-radius: var(--border-radius-lg);
  margin: var(--spacing-lg);
  justify-content: center;
}

/* Archive Overlay */
.archive-container {
  background: var(--color-panel);
  border: 1px solid var(--color-border-soft);
  border-radius: var(--border-radius-lg);
  width: 100%;
  max-width: calc(800px * var(--ui-scale));
  max-height: 90vh;
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

.archive-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: var(--spacing-lg);
  border-bottom: 1px solid var(--color-border-soft);
}

.archive-title {
  font-size: var(--font-size-xl);
}

.archive-grid {
  flex: 1;
  overflow-y: auto;
  padding: var(--spacing-lg);
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(calc(150px * var(--ui-scale)), 1fr));
  gap: var(--spacing-md);
}

.archive-item {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--border-radius);
  overflow: hidden;
}

.archive-item img {
  width: 100%;
  aspect-ratio: 1;
  object-fit: contain;
}

.archive-item-label {
  display: block;
  text-align: center;
  padding: var(--spacing-xs) var(--spacing-sm);
  font-size: var(--font-size-sm);
  color: var(--color-text);
  word-break: break-word;
  line-height: 1.3;
}

.archive-item-actions {
  display: flex;
  gap: var(--spacing-xs);
  padding: var(--spacing-sm);
}

.archive-item-actions .btn {
  flex: 1;
  font-size: var(--font-size-sm);
  padding: var(--spacing-xs);
}

/* Confirm Dialog */
.dialog-container {
  background: var(--color-panel);
  border: 1px solid var(--color-border-soft);
  border-radius: var(--border-radius-lg);
  padding: var(--spacing-xl);
  max-width: calc(400px * var(--ui-scale));
  text-align: center;
}

.dialog-message {
  font-size: var(--font-size-lg);
  margin-bottom: var(--spacing-lg);
}

.dialog-actions {
  display: inline-flex;
  gap: 6px;
  padding: 6px;
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid var(--color-border-soft);
  border-radius: var(--border-radius-lg);
}

/* ============ Toast Notifications ============ */
.toast {
  position: fixed;
  right: var(--spacing-md);
  bottom: calc(var(--bottom-bar-height) + var(--spacing-md));
  background: rgba(0, 0, 0, 0.85);
  color: var(--color-text-light);
  padding: var(--spacing-sm) var(--spacing-md);
  border-radius: var(--border-radius);
  font-size: var(--font-size-sm);
  pointer-events: none;
  opacity: 0;
  transform: translateY(6px);
  transition: opacity 0.25s ease, transform 0.25s ease;
  z-index: 1000;
}

.toast.show {
  opacity: 1;
  transform: translateY(0);
}

/* TTS Visual Fallback Toast - larger and more prominent for accessibility */
.tts-toast {
  position: fixed;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%) scale(0.9);
  background: var(--color-primary);
  color: var(--color-bg);
  padding: var(--spacing-lg) var(--spacing-xl);
  border-radius: var(--border-radius-lg);
  font-size: var(--font-size-xl);
  font-weight: 600;
  text-align: center;
  max-width: 80vw;
  word-wrap: break-word;
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.3s ease, transform 0.3s ease;
  z-index: 2000;
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.5);
}

.tts-toast.show {
  opacity: 1;
  transform: translate(-50%, -50%) scale(1);
}

/* Storage Error Toast */
.storage-error-toast {
  position: fixed;
  bottom: var(--spacing-lg);
  left: 50%;
  transform: translateX(-50%) translateY(100%);
  background: var(--color-danger);
  color: white;
  padding: var(--spacing-md) var(--spacing-lg);
  border-radius: var(--border-radius);
  font-size: var(--font-size-md);
  text-align: center;
  max-width: 90vw;
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.3s ease, transform 0.3s ease;
  z-index: 2000;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.4);
}

.storage-error-toast strong {
  display: block;
  font-weight: 700;
}

.storage-error-toast p {
  margin-top: var(--spacing-xs);
  font-size: var(--font-size-sm);
}

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

/* ============ Dwell-Time Indicator ============ */
.dwell-indicator {
  position: absolute;
  inset: 0;
  pointer-events: none;
  z-index: 100;
  overflow: visible;
}

.dwell-indicator svg {
  width: 100%;
  height: 100%;
  overflow: visible;
}

@keyframes dwell-fill {
  from { stroke-dashoffset: var(--dwell-circumference); }
  to { stroke-dashoffset: 0; }
}

/* ============ Version Label ============ */
.version-footer {
  text-align: right;
  padding: var(--spacing-sm) 0;
}

.version-label {
  font-size: 11px;
  color: var(--color-text-muted);
  opacity: 0.6;
}

/* ============ Utility Classes ============ */
.hidden {
  display: none !important;
}

.empty-message {
  color: var(--color-text-muted);
  text-align: center;
  padding: var(--spacing-lg);
  font-style: italic;
}

/* ============ Responsive ============ */
@media (max-width: 768px) {
  .camera-layout {
    flex-direction: column;
  }

  .photo-sidebar {
    width: 100%;
    height: 30%;
    border-right: none;
    border-bottom: 1px solid var(--color-border-soft);
  }

  .photo-list {
    flex-direction: row;
    overflow-x: auto;
    overflow-y: hidden;
  }

  .photo-item {
    width: calc(120px * var(--ui-scale));
    aspect-ratio: 4/3;
  }

  .camera-main {
    flex: 1;
  }

  .tabs {
    justify-content: space-around;
    padding: 0;
  }

  .tab {
    flex: 1;
    justify-content: center;
    padding: var(--spacing-sm);
    min-width: auto;
  }

  .tab-label {
    display: none;
  }

  .tab-icon {
    font-size: var(--font-size-xl);
  }
}

/* Touch-friendly: larger tap targets */
@media (pointer: coarse) {
  .btn {
    min-height: calc(44px * var(--ui-scale));
    min-width: calc(44px * var(--ui-scale));
  }

  .word-btn {
    min-height: calc(44px * var(--ui-scale));
  }

  .arrow-btn {
    width: calc(44px * var(--ui-scale));
    height: calc(44px * var(--ui-scale));
  }
}

/* ============ WCAG Focus Indicators ============ */
/* Ensure all interactive elements have visible focus */
:focus-visible {
  outline: 3px solid var(--color-primary);
  outline-offset: 2px;
}

/* Remove default outline when using focus-visible */
:focus:not(:focus-visible) {
  outline: none;
}

/* Specific focus styles for buttons */
.btn:focus-visible,
.tab:focus-visible,
.toggle-btn:focus-visible,
.word-btn:focus-visible,
.arrow-btn:focus-visible,
.mirror-btn:focus-visible,
.wizard-close:focus-visible {
  outline: 3px solid var(--color-primary);
  outline-offset: 2px;
}

/* Focus for photo items and pictos */
.photo-item:focus-visible,
.picto-item:focus-visible,
.grid-cell:focus-visible {
  outline: 3px solid var(--color-primary);
  outline-offset: 2px;
  border-color: var(--color-primary);
}

/* Focus for form inputs */
.select-input:focus-visible,
.text-input:focus-visible,
.textarea-input:focus-visible,
input[type="number"]:focus-visible {
  outline: 3px solid var(--color-primary);
  outline-offset: 0;
}

/* ============ Theme: Yellow / Black ============ */
[data-theme="yellow-black"] {
  --color-bg: #000000;
  --color-panel: #0a0a00;
  --color-surface: #1a1a00;
  --color-surface-hover: #2a2a00;
  --color-btn: #2a2a00;
  --color-btn-hover: #3a3a00;
  --color-border: rgba(255, 214, 0, 0.6);
  --color-border-soft: rgba(255, 214, 0, 0.35);

  --color-text: #FFD600;
  --color-text-muted: rgba(255, 214, 0, 0.8);
  --color-text-light: #FFD600;

  --color-primary: #FFD600;
  --color-primary-hover: #FFE44D;
  --color-secondary: #3a3a00;
  --color-secondary-hover: #4a4a00;
  --color-success: #FFD600;
  --color-warning: #FFD600;
  --color-danger: #ff6b6b;
  --color-danger-hover: #ff8a8a;
}

/* ============ Theme: Light ============ */
[data-theme="light"] {
  --color-bg: #f5f5f5;
  --color-panel: #ffffff;
  --color-surface: #eeeeee;
  --color-surface-hover: #e0e0e0;
  --color-btn: #e0e0e0;
  --color-btn-hover: #d0d0d0;
  --color-border: rgba(0, 0, 0, 0.3);
  --color-border-soft: rgba(0, 0, 0, 0.15);

  --color-text: #1a1a1a;
  --color-text-muted: rgba(26, 26, 26, 0.7);
  --color-text-light: #000000;

  --color-primary: #2563eb;
  --color-primary-hover: #3b82f6;
  --color-secondary: #d0d0d0;
  --color-secondary-hover: #bdbdbd;
  --color-success: #16a34a;
  --color-warning: #ca8a04;
  --color-danger: #dc2626;
  --color-danger-hover: #ef4444;
}

/* ============ Mobile Notice ============ */
.mobile-notice {
  display: none;
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: var(--color-bg);
  z-index: 10000;
  justify-content: center;
  align-items: center;
  text-align: center;
}

.mobile-notice-content {
  padding: 2rem;
}

.mobile-notice-icon {
  font-size: 4rem;
  display: block;
  margin-bottom: 1rem;
}

.mobile-notice p {
  color: var(--color-text);
  font-size: 1.5rem;
  margin: 0.5rem 0;
}

@media (max-width: 600px) {
  .mobile-notice {
    display: flex;
  }
}
