/* ==========================================================================
   REFINED LIQUID GLASS NAVIGATION, CONTROLS, SURFACES & MODALS
   ========================================================================== */

/* Frosted Liquid Glass (Nav, Sticky Exam Bar, Modal Controls) */
.glass-surface {
  background: var(--surface-glass-fallback);
  border: 1px solid var(--border-glass);
  box-shadow: var(--shadow-glass), var(--glass-highlight);
}

@supports (backdrop-filter: blur(1px)) or (-webkit-backdrop-filter: blur(1px)) {
  .glass-surface {
    background: var(--surface-glass);
    -webkit-backdrop-filter: blur(20px) saturate(140%);
    backdrop-filter: blur(20px) saturate(140%);
  }

  .glass-surface--strong {
    background: var(--surface-glass-strong);
  }
}

/* Quiet Editorial Surfaces */
.reading-surface {
  background: var(--surface-paper);
  border: 1px solid var(--border-hairline);
  border-radius: var(--radius-lg);
}

.soft-surface {
  background: var(--surface-muted);
  border: 1px solid var(--border-hairline);
  border-radius: var(--radius-md);
}

.hairline-divider {
  border: 0;
  border-top: 1px solid var(--border-hairline);
  margin: 0;
}

/* Top Floating Navigation */
.top-nav {
  position: sticky;
  top: 0;
  z-index: var(--z-nav);
  padding: calc(10px + env(safe-area-inset-top, 0px)) 16px 4px;
}

@media (min-width: 768px) {
  .top-nav {
    padding: 14px 32px 6px;
  }
}

.top-nav__inner {
  max-width: var(--max-width);
  margin: 0 auto;
  min-height: 48px;
  padding: 4px 6px 4px 14px;
  border-radius: var(--radius-pill);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

body.exam-focus-mode .top-nav,
body.exam-focus-mode .bottom-nav {
  display: none;
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: 9px;
  min-height: 40px;
}

.brand__mark {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--accent);
  box-shadow: 0 0 0 4px var(--accent-soft);
  flex-shrink: 0;
}

.brand__name {
  font-size: 14px;
  font-weight: 700;
  letter-spacing: -0.02em;
}

.desktop-nav {
  display: none;
  align-items: center;
  gap: 2px;
}

@media (min-width: 768px) {
  .desktop-nav {
    display: inline-flex;
  }
}

.nav-pill {
  min-height: 38px;
  padding: 0 15px;
  border-radius: var(--radius-pill);
  border: 0;
  background: transparent;
  color: var(--text-secondary);
  font-size: 13.5px;
  font-weight: 600;
  letter-spacing: -0.01em;
  transition: background-color var(--duration-fast) var(--ease-fluid),
              color var(--duration-fast) var(--ease-fluid);
}

.nav-pill:hover {
  color: var(--text-primary);
}

.nav-pill.is-active {
  background: var(--accent-soft);
  color: var(--accent-ink);
}

.top-nav__actions {
  display: flex;
  align-items: center;
}

.icon-btn {
  width: 40px;
  height: 40px;
  min-width: var(--tap-min);
  min-height: var(--tap-min);
  border-radius: var(--radius-pill);
  border: 1px solid transparent;
  background: transparent;
  color: var(--text-secondary);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  transition: background-color var(--duration-fast) var(--ease-fluid),
              color var(--duration-fast) var(--ease-fluid);
}

.icon-btn:hover {
  background: var(--surface-muted);
  color: var(--text-primary);
}

[data-theme="light"] .theme-icon-sun { display: none; }
[data-theme="dark"] .theme-icon-moon { display: none; }

/* Mobile Floating Liquid Glass Bottom Dock */
.bottom-nav {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: var(--z-nav);
  padding: 6px 14px calc(10px + env(safe-area-inset-bottom, 0px));
  pointer-events: none;
}

@media (min-width: 768px) {
  .bottom-nav {
    display: none;
  }
}

.bottom-nav__inner {
  pointer-events: auto;
  max-width: 390px;
  margin: 0 auto;
  padding: 4px;
  border-radius: 24px;
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 2px;
}

.bottom-nav__item {
  min-height: 48px;
  padding: 4px 2px;
  border: 0;
  border-radius: 19px;
  background: transparent;
  color: var(--text-secondary);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: -0.01em;
  transition: background-color var(--duration-fast) var(--ease-fluid),
              color var(--duration-fast) var(--ease-fluid),
              transform var(--duration-fast) var(--ease-fluid);
}

.bottom-nav__item:active {
  transform: scale(0.96);
}

.bottom-nav__item.is-active {
  background: var(--accent-soft);
  color: var(--accent-ink);
}

/* Crisp Editorial Buttons (>= 44px touch target) */
.btn {
  min-height: var(--tap-min);
  padding: 10px 18px;
  border-radius: var(--radius-sm);
  border: 1px solid transparent;
  font-size: 14px;
  font-weight: 600;
  letter-spacing: -0.01em;
  line-height: 1.2;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  text-align: center;
  transition: transform var(--duration-fast) var(--ease-fluid),
              background-color var(--duration-fast) var(--ease-fluid),
              border-color var(--duration-fast) var(--ease-fluid);
}

.btn:active:not(:disabled) {
  transform: scale(0.98);
}

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

.btn--primary {
  background: var(--accent);
  color: var(--text-on-accent);
}

.btn--primary:hover:not(:disabled) {
  background: var(--accent-hover);
}

.btn--soft {
  background: var(--accent-soft);
  color: var(--accent-ink);
}

.btn--soft:hover:not(:disabled) {
  filter: brightness(0.97);
}

.btn--ghost {
  background: var(--surface-paper);
  color: var(--text-primary);
  border-color: var(--border-strong);
}

.btn--ghost:hover:not(:disabled) {
  background: var(--surface-muted);
}

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

.btn--text {
  min-height: var(--tap-min);
  padding: 6px 2px;
  border: 0;
  background: transparent;
  color: var(--accent-ink);
  font-size: 13.5px;
  font-weight: 600;
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.btn--text:hover {
  text-decoration: underline;
  text-underline-offset: 3px;
}

.btn--sm {
  min-height: 44px;
  padding: 8px 14px;
  font-size: 13px;
}

.btn--block {
  width: 100%;
}

/* Restrained Editorial Tags (used sparingly) */
.tag {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 3px 9px;
  border-radius: 6px;
  font-size: 11.5px;
  font-weight: 700;
  letter-spacing: 0.03em;
  line-height: 1.35;
}

.tag--twk { background: var(--pastel-peach); color: var(--danger-text); }
.tag--tiu { background: var(--pastel-blue); color: var(--info-text); }
.tag--tkp { background: var(--pastel-mint); color: var(--success-text); }
.tag--success { background: var(--success-bg); color: var(--success-text); }
.tag--danger { background: var(--danger-bg); color: var(--danger-text); }
.tag--warning { background: var(--warning-bg); color: var(--warning-text); }
.tag--neutral { background: var(--surface-muted); color: var(--text-secondary); }

/* Underlined Editorial Filter Bar */
.tab-bar {
  display: flex;
  flex-wrap: wrap;
  gap: 4px 16px;
  border-bottom: 1px solid var(--border-hairline);
}

.tab-btn {
  position: relative;
  min-height: var(--tap-min);
  padding: 8px 2px;
  border: 0;
  background: transparent;
  color: var(--text-muted);
  font-size: 13.5px;
  font-weight: 600;
  transition: color var(--duration-fast) var(--ease-fluid);
}

.tab-btn:hover {
  color: var(--text-primary);
}

.tab-btn.is-active {
  color: var(--accent-ink);
}

.tab-btn.is-active::after {
  content: "";
  position: absolute;
  left: 0;
  right: 0;
  bottom: -1px;
  height: 2px;
  background: var(--accent);
}

/* Inputs */
.field-input {
  width: 100%;
  min-height: var(--tap-min);
  padding: 10px 14px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-strong);
  background: var(--surface-paper);
  color: var(--text-primary);
  font-size: 15px;
  transition: border-color var(--duration-fast) var(--ease-fluid),
              box-shadow var(--duration-fast) var(--ease-fluid);
}

.field-input:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-ring);
}

.field-line {
  width: 100%;
  min-height: var(--tap-min);
  padding: 8px 2px;
  border: 0;
  border-bottom: 1px solid var(--border-strong);
  border-radius: 0;
  background: transparent;
  color: var(--text-primary);
  font-size: 15px;
  transition: border-color var(--duration-fast) var(--ease-fluid);
}

.field-line:focus {
  outline: none;
  border-bottom-color: var(--accent);
}

/* Stimulus Boxes (pre / svg) */
.stimulus-box {
  margin: 14px 0;
  padding: 14px;
  border-radius: var(--radius-md);
  background: var(--surface-tint);
  border: 1px solid var(--border-hairline);
  overflow-x: auto;
}

.stimulus-pre {
  font-family: var(--font-mono);
  font-size: 13px;
  line-height: 1.55;
  white-space: pre-wrap;
  word-break: break-word;
  color: var(--text-primary);
}

.stimulus-svg {
  display: flex;
  justify-content: center;
  align-items: center;
}

.stimulus-svg svg {
  width: 100%;
  max-width: 440px;
  height: auto;
}

/* Modal & Sheet */
.modal-root {
  position: fixed;
  inset: 0;
  z-index: var(--z-modal);
  display: none;
  align-items: flex-end;
  justify-content: center;
  padding: 12px;
  background: rgba(22, 20, 28, 0.44);
}

.modal-root.is-open {
  display: flex;
}

@media (min-width: 640px) {
  .modal-root {
    align-items: center;
    padding: 20px;
  }
}

.modal-card {
  width: 100%;
  max-width: 500px;
  max-height: 92dvh;
  overflow-y: auto;
  border-radius: var(--radius-lg);
  padding: 20px;
  background: var(--surface-paper);
  border: 1px solid var(--border-hairline);
  box-shadow: var(--shadow-sheet);
  animation: sheetIn var(--duration-base) var(--ease-fluid);
}

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

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 14px;
}

.modal-title {
  font-size: 17px;
  font-weight: 700;
  letter-spacing: -0.02em;
}

/* Toast */
.toast-region {
  position: fixed;
  left: 50%;
  bottom: calc(82px + env(safe-area-inset-bottom, 0px));
  transform: translateX(-50%);
  z-index: var(--z-toast);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  width: calc(100% - 32px);
  max-width: 360px;
  pointer-events: none;
}

@media (min-width: 768px) {
  .toast-region {
    bottom: 24px;
  }
}

.toast {
  padding: 9px 16px;
  border-radius: var(--radius-pill);
  background: var(--text-primary);
  color: var(--bg-canvas);
  font-size: 13px;
  font-weight: 600;
  box-shadow: var(--shadow-glass);
  text-align: center;
}
