/* ==========================================================================
   OneWordly Tool Switcher (mobile only)
   Desktop (min-width: 769px) is unaffected: the button stays hidden and the
   original header tabs remain.
   ========================================================================== */

.ow-switcher-btn,
.ow-switcher-spacer {
  display: none;
}

@media (max-width: 768px) {
  /* Only hide the tabs once the switcher button actually exists. */
  .app-header.has-ow-switcher .header-mode-nav,
  .app-header:has(.ow-switcher-btn) .header-mode-nav {
    display: none !important;
  }

  /* Brand name moves into the switcher caption; keep the logo icon. */
  .app-header.has-ow-switcher .logo-text,
  .app-header:has(.ow-switcher-btn) .logo-text {
    display: none !important;
  }

  /* Balanced 3-column mobile header:
     - Col 1: Left-aligned Logo
     - Col 2: Center-aligned All Tools Switcher button
     - Col 3: Right-aligned Actions (or invisible spacer on Cube/Type) */
  .app-header.has-ow-switcher,
  .app-header:has(.ow-switcher-btn) {
    display: grid !important;
    grid-template-columns: minmax(0, 1fr) auto minmax(0, 1fr) !important;
    align-items: center !important;
    justify-content: stretch !important;
    padding: 8px 10px !important;
    gap: 8px !important;
    width: 100% !important;
    max-width: 100vw !important;
    box-sizing: border-box !important;
    overflow-x: visible !important;
  }

  .app-header.has-ow-switcher .logo-group,
  .app-header:has(.ow-switcher-btn) .logo-group {
    grid-column: 1 !important;
    justify-self: start !important;
    display: inline-flex !important;
    align-items: center !important;
    flex-shrink: 0 !important;
    gap: 0 !important;
    margin: 0 !important;
    padding: 0 !important;
  }

  .ow-switcher-btn {
    grid-column: 2 !important;
    justify-self: center !important;
    display: inline-flex;
    align-items: center;
    gap: 6px;
    min-width: 0;
    max-width: 100%;
    margin: 0 !important;
    min-height: 36px;
    padding: 4px 10px;
    border-radius: 10px;
    border: 1px solid rgba(148, 163, 184, 0.28);
    background: rgba(148, 163, 184, 0.1);
    color: inherit;
    font: inherit;
    text-align: left;
    cursor: pointer;
    -webkit-tap-highlight-color: transparent;
    transition: background-color 0.15s ease, border-color 0.15s ease, transform 0.1s ease;
  }

  .ow-switcher-btn:hover {
    background: rgba(148, 163, 184, 0.16);
    border-color: rgba(148, 163, 184, 0.38);
  }

  .ow-switcher-btn:active {
    transform: scale(0.97);
    background: rgba(148, 163, 184, 0.22);
  }

  .ow-switcher-btn:focus-visible {
    outline: 2px solid #3b82f6;
    outline-offset: 2px;
  }

  /* On mobile header, keep only primary mode switch & settings icons */
  #btnToggleContext,
  #btnFullscreen {
    display: none !important;
  }

  .app-header.has-ow-switcher .header-actions,
  .app-header:has(.ow-switcher-btn) .header-actions {
    grid-column: 3 !important;
    justify-self: end !important;
    display: inline-flex !important;
    align-items: center !important;
    flex-shrink: 0 !important;
    margin: 0 !important;
    gap: 4px !important;
  }

  .app-header.has-ow-switcher .header-actions .btn-icon-text,
  .app-header.has-ow-switcher .header-actions .btn-icon,
  .app-header:has(.ow-switcher-btn) .header-actions .btn-icon-text,
  .app-header:has(.ow-switcher-btn) .header-actions .btn-icon {
    width: 32px !important;
    height: 32px !important;
    min-width: 32px !important;
    padding: 6px !important;
    display: inline-flex !important;
    align-items: center !important;
    justify-content: center !important;
    gap: 0 !important;
    flex-shrink: 0 !important;
  }

  .ow-switcher-spacer {
    grid-column: 3 !important;
    justify-self: end !important;
    display: block !important;
    width: 0 !important;
    height: 0 !important;
    pointer-events: none !important;
    visibility: hidden !important;
  }

  .ow-switcher-text {
    display: flex;
    flex-direction: column;
    min-width: 0;
    line-height: 1.15;
  }

  .ow-switcher-caption {
    font-size: 0.58rem;
    font-weight: 600;
    letter-spacing: 0.04em;
    text-transform: uppercase;
    opacity: 0.65;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }

  .ow-switcher-name {
    font-size: 0.82rem;
    font-weight: 700;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }

  .ow-switcher-chevron {
    display: inline-flex;
    flex-shrink: 0;
    opacity: 0.75;
  }

  body.theme-light .ow-switcher-btn,
  [data-theme="light"] .ow-switcher-btn {
    border-color: rgba(15, 23, 42, 0.18);
    background: rgba(15, 23, 42, 0.05);
  }
}

/* ==========================================================================
   OneWordly Desktop Master Header (min-width: 769px)
   Enforces identical layout across all tools:
   - Col 1: Logo anchored to left
   - Col 2: Navigation mode tabs strictly dead-centered in the viewport
   - Col 3: Actions or spacer anchored to right
   ========================================================================== */
@media (min-width: 769px) {
  .app-header {
    display: grid !important;
    grid-template-columns: minmax(0, 1fr) auto minmax(0, 1fr) !important;
    align-items: center !important;
    justify-content: stretch !important;
    padding: 14px 28px !important;
    box-sizing: border-box !important;
    gap: 12px !important;
    width: 100% !important;
    max-width: 100vw !important;
    overflow-x: visible !important;
  }

  .app-header .logo-group {
    grid-column: 1 !important;
    justify-self: start !important;
    display: inline-flex !important;
    align-items: center !important;
    min-width: 0 !important;
    white-space: nowrap !important;
    flex-shrink: 0 !important;
  }

  .app-header .logo-text {
    display: inline-flex !important;
    align-items: center !important;
    gap: 8px !important;
    white-space: nowrap !important;
    flex-shrink: 0 !important;
  }

  .app-header .logo-title {
    white-space: nowrap !important;
    flex-shrink: 0 !important;
  }

  .app-header .logo-badge {
    white-space: nowrap !important;
    flex-shrink: 0 !important;
    display: inline-flex !important;
    align-items: center !important;
    line-height: 1.2 !important;
  }

  .app-header .header-mode-nav {
    grid-column: 2 !important;
    justify-self: center !important;
    margin: 0 !important;
    display: flex !important;
    align-items: center !important;
    flex-shrink: 0 !important;
    white-space: nowrap !important;
  }

  .app-header .header-actions {
    grid-column: 3 !important;
    justify-self: end !important;
    display: inline-flex !important;
    align-items: center !important;
    min-width: 0 !important;
    white-space: nowrap !important;
  }

  .app-header .header-actions-spacer,
  .app-header .ow-switcher-spacer {
    grid-column: 3 !important;
    justify-self: end !important;
    display: block !important;
    width: 0 !important;
    height: 0 !important;
    visibility: hidden !important;
    pointer-events: none !important;
  }

  .app-header .tab-label-full {
    display: inline !important;
  }

  .app-header .tab-label-short {
    display: none !important;
  }
}

/* ==========================================================================
   Desktop Responsive Adapters (Resizing / Window Manipulation)
   Prevents badge wrapping, misalignment, and header crowding as the window shrinks
   ========================================================================== */

/* Tier A: Screens <= 1240px
   Gracefully hide the redundant tool badge so the brand logo stays clean ("OneWordly")
   and leaves ample space for the centered mode navigation tabs */
@media (min-width: 769px) and (max-width: 1240px) {
  .app-header {
    padding: 12px 20px !important;
  }

  .app-header .logo-badge {
    display: none !important;
  }
}

/* Tier B: Screens <= 1080px
   Compact the action buttons: hide "Edit Text" label, keeping clean icon button */
@media (min-width: 769px) and (max-width: 1080px) {
  .app-header {
    padding: 10px 16px !important;
    gap: 8px !important;
  }

  #switchViewLabel {
    display: none !important;
  }

  .app-header .header-actions .btn-icon-text {
    padding: 7px !important;
    width: 36px !important;
    height: 36px !important;
    min-width: 36px !important;
    gap: 0 !important;
  }
}

/* Tier C: Screens <= 980px down to 769px
   Switch mode navigation tabs to concise labels (Speed, Type, Dual, Cube)
   keeping the entire nav bar compact, spacious, and dead-center in the viewport */
@media (min-width: 769px) and (max-width: 980px) {
  .app-header {
    padding: 8px 12px !important;
    gap: 6px !important;
  }

  .app-header .tab-label-full {
    display: none !important;
  }

  .app-header .tab-label-short {
    display: inline !important;
  }

  .app-header .mode-tab {
    padding: 5px 8px !important;
    font-size: 0.78rem !important;
    gap: 4px !important;
  }

  .app-header .logo-title {
    font-size: 1.15rem !important;
  }

  .app-header .logo-icon {
    width: 32px !important;
    height: 32px !important;
  }

  #btnFullscreen {
    display: none !important;
  }
}

/* ==========================================================================
   Bottom sheet
   ========================================================================== */

.ow-sheet,
.ow-sheet * {
  box-sizing: border-box;
}

.ow-sheet {
  --ow-bg: #12151f;
  --ow-surface: rgba(255, 255, 255, 0.04);
  --ow-surface-active: rgba(255, 255, 255, 0.08);
  --ow-border: rgba(255, 255, 255, 0.08);
  --ow-text: #f0f4fc;
  --ow-muted: #94a3b8;

  position: fixed;
  top: auto;
  bottom: 0;
  left: 0;
  right: 0;
  width: 100%;
  max-width: min(560px, 100%);
  margin: 0 auto;
  max-height: 85vh;
  max-height: min(85dvh, 680px);
  padding: 0 16px calc(18px + env(safe-area-inset-bottom));
  border: 1px solid var(--ow-border);
  border-bottom: none;
  border-radius: 22px 22px 0 0;
  background: var(--ow-bg);
  color: var(--ow-text);
  box-shadow: 0 -12px 40px rgba(0, 0, 0, 0.45);
  overflow-y: auto;
  overscroll-behavior: contain;
  transition: transform 0.2s ease;
}

body.theme-light .ow-sheet,
[data-theme="light"] .ow-sheet {
  --ow-bg: #ffffff;
  --ow-surface: #f6f7fb;
  --ow-surface-active: #eceef5;
  --ow-border: rgba(15, 23, 42, 0.1);
  --ow-text: #0f172a;
  --ow-muted: #64748b;
  box-shadow: 0 -12px 40px rgba(15, 23, 42, 0.18);
}

.ow-sheet::backdrop {
  background: rgba(5, 7, 12, 0.6);
  backdrop-filter: blur(3px);
  -webkit-backdrop-filter: blur(3px);
}

/* Lock page scroll behind the open sheet */
html:has(.ow-sheet[open]) {
  overflow: hidden;
}

/* Open / close / drag motion */
.ow-sheet[open] {
  animation: ow-sheet-in 0.32s cubic-bezier(0.22, 1, 0.36, 1);
}

.ow-sheet[open]::backdrop {
  animation: ow-fade-in 0.25s ease;
}

.ow-sheet.is-closing {
  animation: ow-sheet-out 0.22s ease-in forwards;
}

.ow-sheet.is-closing::backdrop {
  animation: ow-fade-out 0.22s ease-in forwards;
}

.ow-sheet.is-dragging {
  transition: none;
}

@keyframes ow-sheet-in {
  from { transform: translateY(100%); }
}

@keyframes ow-sheet-out {
  to { transform: translateY(100%); }
}

@keyframes ow-fade-in {
  from { opacity: 0; }
}

@keyframes ow-fade-out {
  to { opacity: 0; }
}

@media (prefers-reduced-motion: reduce) {
  .ow-sheet,
  .ow-sheet::backdrop {
    animation: none !important;
    transition: none !important;
  }
}

/* Header area (also the swipe-down zone) */
.ow-sheet-drag {
  touch-action: none;
  cursor: grab;
}

.ow-sheet-grab {
  display: flex;
  justify-content: center;
  padding: 10px 0 4px;
}

.ow-sheet-grab span {
  width: 40px;
  height: 5px;
  border-radius: 999px;
  background: rgba(148, 163, 184, 0.4);
}

.ow-sheet-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  padding: 6px 4px 14px;
}

.ow-sheet-head h2 {
  margin: 0;
  font-size: 1.15rem;
  font-weight: 800;
  letter-spacing: -0.01em;
  color: var(--ow-text);
}

.ow-sheet-sub {
  margin: 3px 0 0;
  font-size: 0.8rem;
  color: var(--ow-muted);
}

.ow-sheet-close {
  display: grid;
  place-items: center;
  flex-shrink: 0;
  width: 36px;
  height: 36px;
  padding: 0;
  border-radius: 50%;
  border: 1px solid var(--ow-border);
  background: var(--ow-surface);
  color: var(--ow-muted);
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}

.ow-sheet-close:focus-visible {
  outline: 2px solid #3b82f6;
  outline-offset: 2px;
}

/* Tool cards */
.ow-tool-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.ow-tool-card {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 14px;
  border-radius: 16px;
  border: 1px solid var(--ow-border);
  background: var(--ow-surface);
  color: var(--ow-text);
  text-decoration: none;
  -webkit-tap-highlight-color: transparent;
  transition: background-color 0.15s ease, border-color 0.15s ease, transform 0.1s ease;
}

.ow-tool-card:active {
  transform: scale(0.985);
  background: var(--ow-surface-active);
}

.ow-tool-card:focus-visible {
  outline: 2px solid var(--tool-accent);
  outline-offset: 2px;
}

.ow-tool-card.is-current {
  border-color: var(--tool-accent);
  border-color: color-mix(in srgb, var(--tool-accent) 55%, transparent);
  background: color-mix(in srgb, var(--tool-accent) 12%, transparent);
}

.ow-tool-icon {
  display: grid;
  place-items: center;
  flex-shrink: 0;
  width: 46px;
  height: 46px;
  border-radius: 13px;
  color: #ffffff;
  background: var(--tool-accent);
  background: linear-gradient(135deg, var(--tool-accent), color-mix(in srgb, var(--tool-accent) 60%, #000000));
  box-shadow: 0 6px 16px -6px var(--tool-accent);
}

.ow-tool-body {
  display: flex;
  flex-direction: column;
  gap: 3px;
  flex: 1;
  min-width: 0;
}

.ow-tool-name {
  font-size: 1rem;
  font-weight: 700;
  line-height: 1.2;
}

.ow-tool-desc {
  font-size: 0.8rem;
  line-height: 1.35;
  color: var(--ow-muted);
}

.ow-tool-end {
  display: flex;
  align-items: center;
  flex-shrink: 0;
  color: var(--ow-muted);
}

.ow-tool-badge {
  padding: 3px 8px;
  border-radius: 999px;
  border: 1px solid currentColor;
  color: var(--tool-accent);
  font-size: 0.65rem;
  font-weight: 700;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  white-space: nowrap;
}
