#grammar-overlay {
  position: fixed;
  inset: 0;
  z-index: 1600;
  display: none;
  flex-direction: column;
  background: var(--color-bg);
}

#grammar-overlay.open { display: flex; }

.grammar-app-header {
  flex: none;
  min-height: calc(var(--header-h) + env(safe-area-inset-top, 0px));
  padding: env(safe-area-inset-top, 0px) 0.65rem 0;
  display: grid;
  grid-template-columns: 44px 1fr 44px;
  align-items: center;
  background: var(--brand);
  color: var(--color-bg);
  box-shadow: 0 1px 4px color-mix(in oklab, var(--color-text-primary) 18%, transparent);
}

.grammar-app-header strong {
  text-align: center;
  font-size: 1rem;
  font-weight: 700;
}

#grammar-close {
  width: 44px;
  height: 44px;
  display: grid;
  place-items: center;
  border: 0;
  border-radius: 8px;
  background: transparent;
  color: var(--color-bg);
  cursor: pointer;
}

#grammar-close:hover { background: color-mix(in oklab, var(--color-bg) 12%, transparent); }
#grammar-close:active { background: color-mix(in oklab, var(--color-bg) 20%, transparent); }
#grammar-close svg {
  width: 22px;
  height: 22px;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

#grammar-frame {
  flex: 1 1 auto;
  width: 100%;
  min-height: 0;
  border: 0;
  background: var(--color-bg);
}

.grammar-frame-state {
  flex: 1 1 auto;
  min-height: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  padding: 2rem;
  text-align: center;
  color: var(--color-text-secondary);
  font-size: 0.88rem;
}

.grammar-frame-state[hidden] { display: none; }
.grammar-frame-state strong { color: var(--color-text-primary); font-size: 1rem; }
.grammar-frame-state span { max-width: 32ch; }
#grammar-retry {
  margin-top: 0.75rem;
  padding: 0.6rem 1.1rem;
  border: 0;
  border-radius: 8px;
  background: var(--brand);
  color: var(--color-bg);
  font-weight: 700;
  cursor: pointer;
}
